Skip to content

Instantly share code, notes, and snippets.

@sedj601
Last active July 7, 2016 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sedj601/736036dadb968f09bc8af2736f13a874 to your computer and use it in GitHub Desktop.
Save sedj601/736036dadb968f09bc8af2736f13a874 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BatchCat;/*Make sure you added BatchCat to your references!*/
namespace BCHandler
{
class BatchCatHandler
{
/*Some of the BatchCat methods/functions are not implemented*/
private ClassBatchCat batch;
private static int CATLOCATIONID = -1; //Put your catalog location id here!
private static int HOLDINGLOCATIONID = -1; //Pur your holding location id here!
private static int LIBRARYID = -1; //Put your library id here!
private static string voyagerPath = @"path/to/your/voyager/folder"; //Put the path to your Voyager folder here
private long bibRecordIDAdded = -1; //Don't touch
private long holdingRecordIDAdded = -1; //Don't touch
private long authorityRecordIDAdded = -1; //Don't touch
private long itemRecordIDAdded = -1; //Don't touch
public BatchCatHandler()
{
batch = new ClassBatchCat();
}
public Boolean AddAuthorityRecord(string marcRecord)
{
AddAuthorityReturnCode result = AddAuthorityReturnCode.aaCouldNotAddRecord;
try
{
result = batch.AddAuthorityRecord(marcRecord, CATLOCATIONID);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
if(result == AddAuthorityReturnCode.aaSuccess)
{
authorityRecordIDAdded = batch.RecordIDAdded;
Console.WriteLine("Bib record added successfully!");
return true;
}
else
{
Console.WriteLine("Authority record failed to add!");
Console.WriteLine("update code: " + result);
return false;
}
}
public Boolean AddBibRecord(string marcRecord)
{
// BuildMarc bm = new BuildMarc(marcRecord);//used here to handle COPYRIGHT symbol
AddBibReturnCode result = AddBibReturnCode.abCouldNotAddRecord;
try
{
result = batch.AddBibRecord(bm.getMarcRecord(), LIBRARYID, CATLOCATIONID, false);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == AddBibReturnCode.abSuccess)
{
bibRecordIDAdded = batch.RecordIDAdded;
Console.WriteLine("Bib record added successfully!");
return true;
}
else
{
Console.WriteLine("Bib record failed to add!");
Console.WriteLine("update code: " + result);
return false;
}
}
public Boolean AddHoldingRecord(string marcRecord, string relatedRecordID)
{
AddHoldingReturnCode result = AddHoldingReturnCode.ahCouldNotAddRecord;
try
{
int tempRelatedRecordID = Int32.Parse(relatedRecordID);
result = this.batch.AddHoldingRecord(marcRecord, tempRelatedRecordID, CATLOCATIONID, false, HOLDINGLOCATIONID);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == AddHoldingReturnCode.ahSuccess)
{
holdingRecordIDAdded = batch.RecordIDAdded;
Console.WriteLine("Bib record id: " + relatedRecordID + " holding record added successfully!");
return true;
}
else
{
Console.WriteLine("Bib record id: " + relatedRecordID + " holding record failed to add!");
Console.WriteLine("Add Holding code: " + result);
return false;
}
}
public Boolean AddItemBarCode(int itemID, string barCode)
{
AddItemBarCodeReturnCode result = AddItemBarCodeReturnCode.aibCouldNotUpdateBarcode;
try
{
result = batch.AddItemBarCode(itemID, barCode);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
if(result == AddItemBarCodeReturnCode.aibSuccess)
{
Console.WriteLine("Item id: " + itemID + " barcode added successfully!");
return true;
}
else
{
Console.WriteLine("Item id: " + itemID + " barcode was not added!");
Console.WriteLine("Add item barcode code: " + result);
return false;
}
}
/*Not complete
public Boolean AddItemData(int holdingID, int itemID, int itemTypeID, int permLocatoinID)
{
AddItemReturnCode result = AddItemReturnCode.aiCouldNotAddItemRecord;
batch.cItem.HoldingID = holdingID;
batch.cItem.ItemID = itemID;
batch.cItem.ItemTypeID = itemTypeID;
batch.cItem.PermLocationID = permLocatoinID;
try
{
result = batch.AddItemData(CATLOCATIONID);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == AddItemReturnCode.aiSuccess)
{
itemRecordIDAdded = batch.RecordIDAdded;
Console.WriteLine("Item record: " + itemID + " added successfully!");
return true;
}
else
{
Console.WriteLine("Item record: " + itemID + " was not added!");
Console.WriteLine("Add item barcode code: " + result);
return false;
}
}
*/
public Boolean Connect(string username, string password)
{
ConnectReturnCodes result = 0;
try
{
result = this.batch.Connect(voyagerPath, username, password);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == ConnectReturnCodes.crSuccess)
{
Console.WriteLine("Connection established.");
return true;
}
else
{
Console.WriteLine("Connection failed to establish.");
return false;
}
}
public Boolean DeleteBibRecord(string bibID)
{
DeleteBibReturnCode result = DeleteBibReturnCode.dbUnknownError;
try
{
int tempBibID = Int32.Parse(bibID);
result = this.batch.DeleteBibRecord(tempBibID);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == DeleteBibReturnCode.dbSuccess)
{
Console.WriteLine("Bib record id: " + bibID + " Bib record deleted successfully!");
return true;
}
else
{
Console.WriteLine("Bib record id: " + bibID + " bib record failed to delete!");
Console.WriteLine("Delete Bib code: " + result);
return false;
}
}
public Boolean DeleteHoldingRecord(string bibID)
{
DeleteHoldingReturnCode result = DeleteHoldingReturnCode.dhUnknownError;
try
{
int tempBibID = Int32.Parse(bibID);
result = this.batch.DeleteHoldingRecord(tempBibID);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == DeleteHoldingReturnCode.dhSuccess)
{
Console.WriteLine("Bib record id: " + bibID + " holding record deleted successfully!");
return true;
}
else
{
Console.WriteLine("Bib record id: " + bibID + " holding record failed to delete!");
Console.WriteLine("Delete holding code: " + result);
return false;
}
}
public long getBibRecordIDAdded()
{
return bibRecordIDAdded;
}
public long getHoldingRecordIDAdded()
{
return holdingRecordIDAdded;
}
public Boolean UpdateBibRecord(string marcRecord, string recordBibID, DateTime timeStamp)
{
UpdateBibReturnCode result = UpdateBibReturnCode.ubCouldNotUpdateRecord;
try
{
int tempRecordBibID = Int32.Parse(recordBibID);
result = batch.UpdateBibRecord(tempRecordBibID, marcRecord, timeStamp, LIBRARYID, CATLOCATIONID, false);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == UpdateBibReturnCode.ubSuccess)
{
Console.WriteLine("Bib record id: " + recordBibID + " updated successfully!");
return true;
}
else
{
Console.WriteLine("Bib record id: " + recordBibID + " failed to update!");
Console.WriteLine("update code: " + result);
return false;
}
}
public Boolean UpdateHoldingRecord(string marcRecord, string recordBibID, string holdingLocationID, DateTime timeStamp)
{
UpdateHoldingReturnCode result = UpdateHoldingReturnCode.uhCouldNotUpdateRecord;
try
{
int tempRecordBibID = Int32.Parse(recordBibID);
int tempHoldingLocationID = Int32.Parse(holdingLocationID);
result = batch.UpdateHoldingRecord(tempRecordBibID, marcRecord, timeStamp, LIBRARYID, CATLOCATIONID, tempHoldingLocationID, false);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
if (result == UpdateHoldingReturnCode.uhSuccess)
{
Console.WriteLine("Bib record id: " + recordBibID + " holding record updated successfully!");
return true;
}
else
{
Console.WriteLine("Bib record id: " + recordBibID + " holding record failed to update!");
Console.WriteLine("update holding code: " + result);
return false;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace addBibRecord
{
class Program
{
static void Main(string[] args)
{
//Example use of BatchCatHandler
//I have not tested this code. If you have problems feel freee to contact me.
BatchCatHandler bch = new BatchCatHandler();
string text = @"path/to/your/marc/file.mrc";//The path to the marc file to add to database. This file must have one marc record in it.
string marcString = File.ReadAllText(text);
if(bch.Connect("username", "password"))
{
if (bch.AddBibRecord(marcString))
{
long tempBibRecordIDAdded = bch.getBibRecordIDAdded();
Console.WriteLine(tempBibRecordIDAdded + " was added successfully!");
Console.WriteLine("press enter to delete record from DB");
Console.ReadLine();
if (bch.DeleteBibRecord(tempBibRecordIDAdded.ToString()))
{
Console.WriteLine(tempBibRecordIDAdded + " deleted!");
Console.ReadLine();
}
else
{
Console.WriteLine(tempBibRecordIDAdded + " did not deleted!");
Console.ReadLine();
}
}
else
{
Console.ReadLine();
}
}
else
{
Console.WriteLine("Could not connect to database!");
Console.ReadLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment