private void button1_Click(object sender, EventArgs e) { if (tB_Serial.Text == "") { MessageBox.Show("产品序列号不能为空!"); return; } pi.sn = tB_Serial.Text; pi.type = tB_Type.Text; pi.time = DateTime.Now.ToString(); if (cb_UpLoad.Checked) { try { string path = App_Configure.Cnfgs.Path_Rpt_Pim + "\\" + "pdf\\" + pi.sn + "_" + pi.device + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".pdf"; if (!del_SavePdf(path)) { MessageBox.Show("save faile"); return; } FtpWeb ftp = new FtpWeb(si.ftpaddr, "", si.ftpuser, si.ftppw); ftp.Upload(path); pi.savepdf = "True"; } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } try { SqlConnection conn = new SqlConnection(); //conn.ConnectionString = "Data Source=SAN-PC;Initial Catalog=Jointcom;User Id=sa;Password=sa"; conn.ConnectionString = "Data Source=" + si.sqladdr + ";Initial Catalog=" + si.sqlname + ";User Id=" + si.sqluser + ";Password="******"insert into " + pi.device + " (SN,Type,Op,Pim,Result,Fpim,\"Power\",Mode,\"Order\",Band,Limit,Time,Remark) " + "values('" + pi.sn + "','" + pi.type + "','" + pi.tester + "','" + pi.pim + "','" + pi.result + "','" + pi.fpim + "','" + pi.power + "','" + pi.mode + "','" + pi.order + "','" + band + "','" + pi.limit + "','" + pi.time + "','" + pi.savepdf + "')"; SqlCommand cmd = new SqlCommand(sql, conn); int n = cmd.ExecuteNonQuery(); conn.Close(); MessageBox.Show("Success!"); this.DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show("数据库连接失败:" + ex.Message); } }