/// <summary> /// 确定保存数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void labelOK_Click(object sender, EventArgs e) { Global.AddItem = addsavedata(); clsSaveResult resultdata = new clsSaveResult(); int isave = 0; string chk = ""; string err = string.Empty; try { if (CheckDatas.Rows.Count > 0) { for (int i = 0; i < CheckDatas.Rows.Count; i++) { if (CheckDatas.Rows[i].Cells[0].Value.ToString() != "是" && CheckDatas.Rows[i].Cells[6].Value.ToString() != "") { resultdata.Save = "是"; resultdata.Gridnum = CheckDatas.Rows[i].Cells[1].Value.ToString(); resultdata.Checkitem = CheckDatas.Rows[i].Cells[2].Value.ToString(); resultdata.CheckData = CheckDatas.Rows[i].Cells[3].Value.ToString(); resultdata.Unit = CheckDatas.Rows[i].Cells[4].Value.ToString(); resultdata.Result = CheckDatas.Rows[i].Cells[5].Value.ToString(); chk = CheckDatas.Rows[i].Cells[6].Value.ToString().Replace("-", "/"); resultdata.CheckTime = DateTime.Parse(chk); resultdata.CheckUnit = CheckDatas.Rows[i].Cells[7].Value.ToString(); resultdata.SampleName = CheckDatas.Rows[i].Cells[8].Value.ToString(); resultdata.Gettime = CheckDatas.Rows[i].Cells[9].Value.ToString(); resultdata.Getplace = CheckDatas.Rows[i].Cells[10].Value.ToString(); resultdata.sampleNum = CheckDatas.Rows[i].Cells[11].Value.ToString(); resultdata.quantityin = CheckDatas.Rows[i].Cells[12].Value.ToString(); resultdata.Testbase = CheckDatas.Rows[i].Cells[13].Value.ToString(); resultdata.Tester = CheckDatas.Rows[i].Cells[14].Value.ToString(); sql.ResuInsert(resultdata, out err); isave = isave + 1; } } if (isave == 0) { MessageBox.Show("数据已成功保存过!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据保存成功,共保存" + isave + "条数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } this.Close(); }
/// <summary> /// 保存数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected override void btnDatsave_Click(object sender, EventArgs e) { clsSaveResult resultdata = new clsSaveResult(); int isave = 0; string chk = ""; //string err = string.Empty; try { if (CheckDatas.Rows.Count > 0) { for (int i = 0; i < CheckDatas.Rows.Count; i++) { if (CheckDatas.Rows[i].Cells["已保存"].Value.ToString() != "是") { resultdata.Save = "是"; //resultdata.Gridnum = CheckDatas.Rows[i].Cells[1].Value.ToString(); resultdata.SampleName = CheckDatas.Rows[i].Cells["样品名称"].Value.ToString().Trim(); resultdata.Checkitem = CheckDatas.Rows[i].Cells["检测项目"].Value.ToString().Trim(); resultdata.CheckData = CheckDatas.Rows[i].Cells["检测结果"].Value.ToString().Trim(); resultdata.Unit = CheckDatas.Rows[i].Cells["单位"].Value.ToString().Trim(); resultdata.Testbase = CheckDatas.Rows[i].Cells["检测依据"].Value.ToString().Trim(); resultdata.LimitData = CheckDatas.Rows[i].Cells["标准值"].Value.ToString().Trim(); //标准值 resultdata.Instrument = CheckDatas.Rows[i].Cells["检测仪器"].Value.ToString().Trim(); //检测仪器 resultdata.Result = CheckDatas.Rows[i].Cells["结论"].Value.ToString().Trim().Trim(); resultdata.detectunit = CheckDatas.Rows[i].Cells["检测单位"].Value.ToString().Trim(); //检测单位 resultdata.Gettime = CheckDatas.Rows[i].Cells["采样时间"].Value.ToString().Trim(); //采样时间 resultdata.Getplace = CheckDatas.Rows[i].Cells["采样地点"].Value.ToString().Trim(); resultdata.CheckUnit = CheckDatas.Rows[i].Cells["被检单位"].Value.ToString().Trim(); resultdata.Tester = CheckDatas.Rows[i].Cells["检测员"].Value.ToString().Trim(); chk = CheckDatas.Rows[i].Cells["检测时间"].Value.ToString().Replace("-", "/").Trim(); resultdata.CheckTime = DateTime.Parse(chk); sqlset.ResuInsert(resultdata, out err); isave = isave + 1; } } if (isave == 0) { MessageBox.Show("数据已成功保存过!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("数据保存成功,共保存" + isave + "条数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
public int ResuInsert(clsSaveResult result, out string errMsg) { int rtn = 0; _strBd.Length = 0; errMsg = string.Empty; try { _strBd.Append("INSERT INTO CheckResult "); _strBd.Append("(GridNum,Checkitem,SampleName,CheckData,Unit,"); _strBd.Append("CheckTime,CheckUnit)"); _strBd.Append("VALUES('"); _strBd.Append(result.Gridnum); _strBd.Append("','"); _strBd.Append(result.Checkitem); _strBd.Append("','"); _strBd.Append(result.SampleName); _strBd.Append("','"); _strBd.Append(result.CheckData); _strBd.Append("','"); _strBd.Append(result.Unit); _strBd.Append("','"); _strBd.Append(result.CheckTime); _strBd.Append("','"); _strBd.Append(result.CheckUnit); _strBd.Append("')"); DataBase.ExecuteCommand(_strBd.ToString(), out errMsg); rtn = 1; } catch (Exception e) { errMsg = e.Message; } return(rtn); }