private void button1_Click_1(object sender, EventArgs e)
{ string connections = "Server=localhost;User ID=root;Password=wencui2006;Persist Security Info=True;DataBase=ken;charset=utf8";
MySqlConnection conn = new MySqlConnection(connections);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
} int machineID;
string IP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
string[] array = IP.Split('.');
machineID = Convert.ToInt32(array[3].ToString());//获取IP最后一位作为机器号
//string FileName = Application.StartupPath + "\\Data\\" + "H" + DateTime.Now.ToString("yyyyMMdd") + "S." + machineID;
string FileName = Application.StartupPath + "\\456.123";
if (!File.Exists(FileName))
{
MessageBox.Show(FileName + "\n" + " 文件丢失");
}
else
{
/
ckd ckd1 = new ckd();
ckdsp ckdsp1 = new ckdsp();
FileStream fs1 = new FileStream(FileName,FileMode.Open,FileAccess.Read);
byte[] byteckd1=new byte[Marshal.SizeOf(typeof(ckd))];
byte[] byteckdsp1=new byte[Marshal.SizeOf(typeof(ckdsp))];
while (fs1.Read(byteckd1, 0, byteckd1.Length) == byteckd1.Length)
{
ckd1 = (ckd)BytesToStuct(byteckd1,typeof(ckd));
//MessageBox.Show(ckd1.lsh64.ToString());
for (int i = 0; i < ckd1.wLength; i++) //ckd1.wLength记录项目数(记录ckdsp1结构体中有多少条记录 )
{
if (fs1.Read(byteckdsp1, 0, byteckdsp1.Length) == byteckdsp1.Length)
{
ckdsp1 = (ckdsp)BytesToStuct(byteckdsp1,typeof(ckdsp));
//MessageBox.Show(ckdsp1.iGoodsID.ToString());
}
}
}
string createtime = new string(ckd1.rq).Trim();
fs1.Flush();
fs1.Close();
string sqlLSH = string.Format("select a.FCreateTime from ShoprecentSalesM a,ShoprecentSalesD b where a.FID={0} and a.FID=b.FID", ckd1.lsh64);
MySqlCommand sqlLSHCmd = new MySqlCommand(sqlLSH, conn); /
try
{
string gets = sqlLSHCmd.ExecuteScalar().ToString();
DateTime dt = Convert.ToDateTime(gets);
string CreateTimes = dt.ToString("yyyyMMddHHmmss");
// MessageBox.Show(CreateTimes);
if (string.Compare(createtime, CreateTimes) == 0) /
{
MessageBox.Show("该文件已上传");
}
else
{
MessageBox.Show("该文件没有上传过");
} }
catch
{
int SuccessOrFailed = 0;
int countsStopDupWriteToDb2 ;
int countStopDupWreteToDb2D;
ckd ckd2 = new ckd();
ckdsp ckdsp2 = new ckdsp();
byte[] bytedatacdk2=new byte[Marshal.SizeOf(typeof(ckd))];
byte[] bytedatacdksp2 = new byte[Marshal.SizeOf(typeof(ckdsp))];
FileStream fs2=new FileStream(FileName,FileMode.Open,FileAccess.Read);
while (fs2.Read(bytedatacdk2, 0, bytedatacdk2.Length) == bytedatacdk2.Length)
{
ckd2 = (ckd)BytesToStuct(bytedatacdk2, typeof(ckd));
string RQ = new string(ckd2.rq).Trim();
float ReturnMoney2 = ckd2.fXj - ckd2.fYs; string StopDupWriteToDb2 = string.Format("select count(*) FROM shoprecentsalesm m WHERE m.FID={0} ", ckd2.lsh64); //---------- FID主键
MySqlCommand StopDupWriteToDb2Cmd = new MySqlCommand(StopDupWriteToDb2, conn);
countsStopDupWriteToDb2 = Convert.ToInt32(StopDupWriteToDb2Cmd.ExecuteScalar());
if (countsStopDupWriteToDb2 > 0)
{
MessageBox.Show("OK");
//continue;
}
else
{
//string InertIntoShoprecentsalesm2 = string.Format("INSERT INTO shoprecentsalesm VALUES ({0},0,{1}, {2},{3}, null,{4}, null, {5}, {6}, {7}, {8}, 0, {9}, {10}, 0, {11}, {12}, {13}, 0, null, {14}, {15}, {16}, '{17}')", ckd2.lsh64, ckd2.iShopID, ckd2.iShopID, machineID, ckd2.iMemberID, ckd2.fRes, ckd2.fYs, ckd2.fSs, ReturnMoney2, ckd2.fQt, ckd2.fXj, ckd2.fCk, ckd2.fZp, ckd2.fXy, ckd2.IDoperator, RQ, ckd2.IDgrantor, DateTime.Now.ToString());
//MySqlCommand InertIntoShoprecentsalesm2Cmd = new MySqlCommand(InertIntoShoprecentsalesm2, conn);
//InertIntoShoprecentsalesm2Cmd.ExecuteNonQuery(); //for (int j = 0; j < ckd2.wLength; j++)
//{
// if (fs2.Read(bytedatacdksp2, 0, bytedatacdksp2.Length) == bytedatacdksp2.Length)
// {
// ckdsp2 = (ckdsp)BytesToStuct(bytedatacdksp2, typeof(ckdsp)); // }
//}
MessageBox.Show("ERRor");
}
}
}
}
}
在防止重复插入数据这里不起作用,是代码写错了?还是哪出问题了!!!!
{ string connections = "Server=localhost;User ID=root;Password=wencui2006;Persist Security Info=True;DataBase=ken;charset=utf8";
MySqlConnection conn = new MySqlConnection(connections);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
} int machineID;
string IP = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
string[] array = IP.Split('.');
machineID = Convert.ToInt32(array[3].ToString());//获取IP最后一位作为机器号
//string FileName = Application.StartupPath + "\\Data\\" + "H" + DateTime.Now.ToString("yyyyMMdd") + "S." + machineID;
string FileName = Application.StartupPath + "\\456.123";
if (!File.Exists(FileName))
{
MessageBox.Show(FileName + "\n" + " 文件丢失");
}
else
{
/
ckd ckd1 = new ckd();
ckdsp ckdsp1 = new ckdsp();
FileStream fs1 = new FileStream(FileName,FileMode.Open,FileAccess.Read);
byte[] byteckd1=new byte[Marshal.SizeOf(typeof(ckd))];
byte[] byteckdsp1=new byte[Marshal.SizeOf(typeof(ckdsp))];
while (fs1.Read(byteckd1, 0, byteckd1.Length) == byteckd1.Length)
{
ckd1 = (ckd)BytesToStuct(byteckd1,typeof(ckd));
//MessageBox.Show(ckd1.lsh64.ToString());
for (int i = 0; i < ckd1.wLength; i++) //ckd1.wLength记录项目数(记录ckdsp1结构体中有多少条记录 )
{
if (fs1.Read(byteckdsp1, 0, byteckdsp1.Length) == byteckdsp1.Length)
{
ckdsp1 = (ckdsp)BytesToStuct(byteckdsp1,typeof(ckdsp));
//MessageBox.Show(ckdsp1.iGoodsID.ToString());
}
}
}
string createtime = new string(ckd1.rq).Trim();
fs1.Flush();
fs1.Close();
string sqlLSH = string.Format("select a.FCreateTime from ShoprecentSalesM a,ShoprecentSalesD b where a.FID={0} and a.FID=b.FID", ckd1.lsh64);
MySqlCommand sqlLSHCmd = new MySqlCommand(sqlLSH, conn); /
try
{
string gets = sqlLSHCmd.ExecuteScalar().ToString();
DateTime dt = Convert.ToDateTime(gets);
string CreateTimes = dt.ToString("yyyyMMddHHmmss");
// MessageBox.Show(CreateTimes);
if (string.Compare(createtime, CreateTimes) == 0) /
{
MessageBox.Show("该文件已上传");
}
else
{
MessageBox.Show("该文件没有上传过");
} }
catch
{
int SuccessOrFailed = 0;
int countsStopDupWriteToDb2 ;
int countStopDupWreteToDb2D;
ckd ckd2 = new ckd();
ckdsp ckdsp2 = new ckdsp();
byte[] bytedatacdk2=new byte[Marshal.SizeOf(typeof(ckd))];
byte[] bytedatacdksp2 = new byte[Marshal.SizeOf(typeof(ckdsp))];
FileStream fs2=new FileStream(FileName,FileMode.Open,FileAccess.Read);
while (fs2.Read(bytedatacdk2, 0, bytedatacdk2.Length) == bytedatacdk2.Length)
{
ckd2 = (ckd)BytesToStuct(bytedatacdk2, typeof(ckd));
string RQ = new string(ckd2.rq).Trim();
float ReturnMoney2 = ckd2.fXj - ckd2.fYs; string StopDupWriteToDb2 = string.Format("select count(*) FROM shoprecentsalesm m WHERE m.FID={0} ", ckd2.lsh64); //---------- FID主键
MySqlCommand StopDupWriteToDb2Cmd = new MySqlCommand(StopDupWriteToDb2, conn);
countsStopDupWriteToDb2 = Convert.ToInt32(StopDupWriteToDb2Cmd.ExecuteScalar());
if (countsStopDupWriteToDb2 > 0)
{
MessageBox.Show("OK");
//continue;
}
else
{
//string InertIntoShoprecentsalesm2 = string.Format("INSERT INTO shoprecentsalesm VALUES ({0},0,{1}, {2},{3}, null,{4}, null, {5}, {6}, {7}, {8}, 0, {9}, {10}, 0, {11}, {12}, {13}, 0, null, {14}, {15}, {16}, '{17}')", ckd2.lsh64, ckd2.iShopID, ckd2.iShopID, machineID, ckd2.iMemberID, ckd2.fRes, ckd2.fYs, ckd2.fSs, ReturnMoney2, ckd2.fQt, ckd2.fXj, ckd2.fCk, ckd2.fZp, ckd2.fXy, ckd2.IDoperator, RQ, ckd2.IDgrantor, DateTime.Now.ToString());
//MySqlCommand InertIntoShoprecentsalesm2Cmd = new MySqlCommand(InertIntoShoprecentsalesm2, conn);
//InertIntoShoprecentsalesm2Cmd.ExecuteNonQuery(); //for (int j = 0; j < ckd2.wLength; j++)
//{
// if (fs2.Read(bytedatacdksp2, 0, bytedatacdksp2.Length) == bytedatacdksp2.Length)
// {
// ckdsp2 = (ckdsp)BytesToStuct(bytedatacdksp2, typeof(ckdsp)); // }
//}
MessageBox.Show("ERRor");
}
}
}
}
}
在防止重复插入数据这里不起作用,是代码写错了?还是哪出问题了!!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货