C # implements the Library program import ISO-2709 format (MARC) feature

Source: Internet
Author: User

1. Import

//<summary>
//import ISO2709
//</summary>
//<param name= "Sender" ></param>
//<param name= "E" ></PARAM>
private void Import Iso2709toolstripmenuitem_click (object sender, EventArgs e)
{
Try
{
OpenFileDialog ofd = new OpenFileDialog ();
Ofd. Filter = "ISO2709 file |*. ISO ";
Ofd. MultiSelect = false;
Ofd. Title = "Please select the ISO2709 file to import.";
if (ofd. ShowDialog ()! = DialogResult.OK)
{
return;
}
if (MessageBox.Show ("to be" + OFD. FileName + "mount" + TOOLSTRIPCMB_SMK. Text + "" In the library to choose?, "Top Confirmation", Messageboxbuttons.yesno, messageboxicon.question)! = Dialogresult.yes)
{
return;
}
StreamReader objreader = new StreamReader (OFD. FileName, System.Text.Encoding.Default);
String sline = "";
ArrayList _arrtext = new ArrayList ();
while (sline! = null)
{
sline = objReader.ReadLine ();
if (sline! = null)
_arrtext.add (sline);
}
Objreader.close ();

Dbutility.squery sq;
foreach (String marc in _arrtext)
{
sortedlist<string, string> Li = GetData (Marc);
The Marc to insert
String Insert_marc = Marc. Substring (5, 4) + (char) 30;//header Area
for (int i = 0; i < Li.count; i++)
{
Stitching the Marc field to be inserted
Insert_marc + = Li.keys[i] + li.values[i] + (char) 30;//cannot get rid of (char) 31, remove (char) 30 Add (char) 30 (Identify the contents of the content of the reference)
}
Sq = DBUtility.SQuery.Create (
@ "INSERT into pending library (key code, standard code, title, Responsible person, edition, publisher, publication year, Unit Price, MARC, operator, date of entry, library key code, subscription number) VALUES
(@ Library key code, @ Standard Code, @ Title, @ Responsibility, @ Edition, @ Publisher, @ publication year, @ Unit price, @MARC, @ operator, GETDATE (), @ Library key, @ subscription number) ");
Parsing Marc
Sq. Params.add ("@ Library Key Code", SYSTEMSTATE.GJM);
Sq. Params.add ("@ Standard Code", Li.Keys.Contains ("010")? Getmarcvalue (li["010"], "Standard Code"): "");
Sq. Params.add ("@ title", Li.Keys.Contains ("200")? Getmarcvalue (li["200"], "title"): "");
Sq. Params.add ("@ Responsible person", Li.Keys.Contains ("200")? Getmarcvalue (li["200"], "responsible person"): "");
Sq. Params.add ("@ edition", Li.Keys.Contains ("205")? Getmarcvalue (li["205"], "edition"): "");
Sq. Params.add ("@ publisher", Li.Keys.Contains ("210")? Getmarcvalue (li["210"], "publisher"): "");
Sq. Params.add ("@ publication Year", Li.Keys.Contains ("210")? Getmarcvalue (li["210"], "publication year"): "");
Sq. Params.add ("@ Unit Price", Li.Keys.Contains ("010")? Getmarcvalue (li["010"], "unit price"): "");
Sq. Params.add ("@marc", Insert_marc);
Sq. Params.add ("@ operator", Common.SystemState.UserID);
Sq. Params.add ("@ Library Key Code", ToolStripcmb_SMK.ComboBox.SelectedValue);
Sq. Params.add ("@ subscription Number", Li.Keys.Contains ("092")? Getmarcvalue (li["092"], "subscription number"): "");
Sq. ExecuteNonQuery ();
Success + = Sq. ExecuteNonQuery () > 0? 1:0;
}
MessageBox.Show ("Data is finished", "system hint", MessageBoxButtons.OK, messageboxicon.warning);
Refresh
Toolstripbtn_query_click (sender, E);
}
catch (Exception ex)
{
MessageBox.Show (ex. Message, "", MessageBoxButtons.OK, Messageboxicon.error);
}
}

Parses the specified Marc data and returns sortedlist<>
Private sortedlist<string, string> GetData (string marctext)
{
int marctextlength = Convert.ToInt32 (marctext.substring (0, 5))//marc record text total length, 00931
int _conpos = Convert.ToInt32 (marctext.substring (12, 5));//Data field area start address, 00253

int _count = (_conpos-24)/12;//number of fields, 19
String _address = Marctext.substring (_conpos-24-1);//Address Catalog area string
String _contents = Marctext.substring (_conpos);//data field area string

---------Start parsing field data

string[] _keys = new string[_count];//Field number
string[] _values = new string[_count];//field value
string[] Values = _contents.split ((char) 30);//With (char) 30 partition data field string for the corresponding field contents of the subsequent _keys
for (int i = 0; i < _count; i++)
{
String _num = _address.substring (i * 12, 3);//Field number
int _len = Int. Parse (_address.substring (i * 12 + 3, 4));//Data area length for field
int _pos = Int. Parse (_address.substring (i * 12 + 7, 5));//Data area start position for field

_keys[i] = _address.substring (i * 12, 3);//Fill field number

_values[i] = values[i];//Fill field value

}

sortedlist<string, string> _sl = new sortedlist<string, string> ();
for (int i = 0; i < _count; i++)
{
if (_SL. ContainsKey (_keys[i]))
{
_sl[_keys[i]] + = (char) x + _values[i];//If there are 2 701 then separate with (Char) 31
}
Else
{
_sl. ADD (_keys[i], _values[i]);
}
}

return _SL;
}

<summary>
Get a positive title
</summary>
private string Getmarcvalue (String str, string item)
{
string[] Subarray = str. Substring (str. IndexOf ((char) 31)). Trim (). Split (New char[] {(char) to}, stringsplitoptions.removeemptyentries);

foreach (String subStr in Subarray)
{
Switch (item)
{
Case "title":
Case "Language":
Case "Publishing Place":
Case "Standard Code":
if (substr.substring (0, 1) = = "a")
{
return substr.substring (1);
}
Break
Case "title abbreviation":
if (substr.substring (0, 1) = = "9")
{
return substr.substring (1);
}
Break
Case "Responsible person":
if (substr.substring (0, 1) = = "F")
{
return substr.substring (1);
}
Break
Case "publisher":
if (substr.substring (0, 1) = = "C")
{
return substr.substring (1);
}
Break
Case "Edition":
if (substr.substring (0, 1) = = "a")
{
return substr.substring (1);
}
Break
Case "Unit Price":
if (substr.substring (0, 1) = = "D")
{
return substr.substring (1);
}
Break
Case "Publication Year":
if (substr.substring (0, 1) = = "D")
{
return substr.substring (1);
}
Break
Case "Call ISBN":
if (substr.substring (0, 1) = = "D")
{
String val = "";
val = substr.substring (1);
foreach (String subStr2 in Subarray)
{
if (substr.substring (0, 1) = = "E")
{
Val + = "/" + substr2.substring (1);
Break
}
}
return Val;
}
Break
Case "Subscription Number":
if (substr.substring (0, 1) = = "B")
{
return substr.substring (1);
}
Break
}

}
Return "";
}

C # implements the Library program import ISO-2709 format (MARC) feature

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.