/// <summary>
/// 轉換數據,從Text文本中導入到數據庫中
/// </summary>
private void ChangeTextToDb()
{
if(File.Exists("Storage Card/Zyk.txt"))
{
try
{
this.RecNum.Visible=true;
SqlCeCommand sqlCreateTable = Mc.gConn.CreateCommand();
StreamReader reader = new StreamReader("Storage Card/Zyk.txt", System.Text.Encoding.Default);
int i=0;
while (reader.Peek() > 0)
{
string oneLine = reader.ReadLine();
string ztm = this.MySubstring(oneLine,0,100).Trim().Replace("''","’");
string date = this.MySubstring(oneLine,100,8).Trim().Replace("''","’");
string isbn = this.MySubstring(oneLine,108,20).Trim().Replace("''","’");
string fbs = this.MySubstring(oneLine,128,10).Trim().Replace("''","’");
if(fbs=="0"||fbs==null||fbs==""||isbn==""||isbn==null)
{
}
else
{
isbn=NcIsbn.Format(isbn,13).Replace("-","");
sqlCreateTable.CommandText = "insert into ZYK(Title,RDate,ISBN,BookNum) values(''"+ztm +"'',''"+date+"'',''"+isbn+"'',"+ fbs+")";
sqlCreateTable.ExecuteNonQuery();
i+
=1;
if(i%100==0)
{
this.RecNum.Text=i.ToString();
this.RecNum.Refresh();
}
}
}
reader.Close();
MessageBox.Show("館藏數據成功導入"+i.ToString().Trim()+"條!");
this.RecNum.Visible=false;
}
catch
{
MessageBox.Show("館藏數據導入失敗請檢查格式!");
this.RecNum.Visible=false;
}
}
else
{
MessageBox.Show("沒有Zyk.txt文件!");
}
}