读取txt文件修改数据库

public void DealEfileReturn(FileInfo file)
{
long totalRecords = 0;
IList<EfileList> list = Baosight.BPMS.Core.Adapter.BPMSDocUtil.QueryEfileList(0, -1, new SqlFilter("projectNo='090410'and BusinessKey1='13CNSHG3200019A0' "), new SqlSort("order by BusinessKey1"), out totalRecords);
if (list.Count > 0)
{
//预存字符串的变量
string str = "";

if (file.Exists)
{
using (StreamReader streamReader = new StreamReader(file.FullName, Encoding.Default))
{
while (streamReader.Peek() >= 0)
{
str = streamReader.ReadLine();
if (str.Length > 0)
{
//调用事务处理
using (DbTransactionWrapper wrapper = new DbTransactionWrapper())
{
string[] data = Regex.Split(str, "&&");
#region MyRegion

//foreach (string item in data)
//{
EfileList entity = new EfileList();

entity.ProjectNo = StringFormat(data[0].Trim());
entity.BusinessKey1 = StringFormat(data[1].Trim());
entity.BusinessKey2 = StringFormat(data[2].Trim());

string flas = StringFormat(data[3].Trim());

entity.EfileConfirmDate = DateTimeFormat(data[4]);

if (flas == "1")
{
Database db = DatabaseFactory.CreateDatabase(DATABASE_INSTANCE_NAME);

string sql = string.Format(@"UPDATE T_SYS_EFILE_LIST SET EfileStatus='02',EfileConfirmDate='" + entity.EfileConfirmDate + "' WHERE projectNo='" + entity.ProjectNo + "'and BusinessKey1='" + entity.BusinessKey1 + "' and BusinessKey2='" + entity.BusinessKey2 + "'");

int i = db.ExecuteNonQuery(CommandType.Text, sql);
}

else if (flas == "0")
{
Database db = DatabaseFactory.CreateDatabase(DATABASE_INSTANCE_NAME);

string sql = string.Format(@"UPDATE T_SYS_EFILE_LIST SET EfileStatus='11',EfileConfirmDate='" + entity.EfileConfirmDate + "' WHERE projectNo='" + entity.ProjectNo + "'and BusinessKey1='" + entity.BusinessKey1 + "' and BusinessKey2='" + entity.BusinessKey2 + "'");

int i = db.ExecuteNonQuery(CommandType.Text, sql);
}
//}
#endregion
wrapper.Commit();


}
}
}
streamReader.Close();
}
}
else
{
throw (new Exception());
}

}

}

posted on 2014-07-30 13:41  zmmlczy  阅读(180)  评论(0编辑  收藏  举报

导航