/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_ok_Click(object sender, EventArgs e) { bool isSuccess = false; T_Bllb_SecondClass_tbsc SC = new T_Bllb_SecondClass_tbsc(); lstInsert.Clear(); foreach (DataGridViewRow row in dgv_SencondClass.Rows) { if (!ValidataInput(row)) { return; } if (cbo_Type.SelectedValue.ToString() != string.Empty)//类型 { SC.Type = cbo_Type.Text.ToString(); } if (txt_Class.Text.Trim() != string.Empty)//等级 { SC.Class = txt_Class.Text.Trim(); } if (row.Cells["OrderNum"].Value != null)//序号 { SC.OrderNum = SqlInput.ChangeNullToString(row.Cells["OrderNum"].Value); } if (row.Cells["Condition"].Value != null)//条件 { SC.Condition = SqlInput.ChangeNullToString(row.Cells["Condition"].Value); } if (row.Cells["TemperatureMaxTime"].Value != null)//最大回温时间 { SC.TemperatureMaxTime = SqlInput.ChangeNullToInt(row.Cells["TemperatureMaxTime"].Value, 0); } if (row.Cells["TemperatureMinTime"].Value != null)//最小回温时间 { SC.TemperatureMinTime = SqlInput.ChangeNullToInt(row.Cells["TemperatureMinTime"].Value, 0); } if (row.Cells["ExposeTime"].Value != null)//暴露时间 { SC.ExposeTime = SqlInput.ChangeNullToInt(row.Cells["ExposeTime"].Value, 0); } if (row.Cells["InHouseTime"].Value != null)//冷藏时间 { SC.InHouseTime = SqlInput.ChangeNullToInt(row.Cells["InHouseTime"].Value, 0); } if (row.Cells["SplitTime"].Value != null)//拆分次数 { SC.SplitTime = SqlInput.ChangeNullToString(row.Cells["SplitTime"].Value); } if (row.Cells["RoastMaxTemperature"].Value != null)//最大烘烤温度 { SC.RoastMaxTemperature = SqlInput.ChangeNullToDecimal(row.Cells["RoastMaxTemperature"].Value, 0); } if (row.Cells["RoastMinTemperature"].Value != null)//最小烘烤温度 { SC.RoastMinTemperature = SqlInput.ChangeNullToDecimal(row.Cells["RoastMinTemperature"].Value, 0); } if (row.Cells["RoastTime"].Value != null)//烘烤时间 { SC.RoastTime = SqlInput.ChangeNullToInt(row.Cells["RoastTime"].Value, 0); } if (row.Cells["Remark"].Value != null)//备注 { //SC.Remark = row.Cells["Remark"].Value.ToString(); SC.Remark = SqlInput.ChangeNullToString(row.Cells["Remark"].Value); } lstInsert.Add(SC); SC = new T_Bllb_SecondClass_tbsc(); } if (lstInsert.Count > 0) { isSuccess = T_Bllb_SecondClass_tbsc_DAL.Insert(lstInsert); } if (isSuccess) { new PubUtils().ShowNoteOKMsg("保存成功!"); this.result = DialogResult.OK; this.Close(); } }
private bool ValidataInput(DataGridViewRow row) { string msg = string.Empty; if (txt_Class.Text == string.Empty) { new PubUtils().ShowNoteNGMsg("等级不能为空", 2, grade.RepeatedError); return(false); } string sqlcmd = string.Format("SELECT * FROM T_Bllb_SecondClass_tbsc WHERE Type='{0}' AND Class='{1}'", cbo_Type.Text, txt_Class.Text.Trim()); if (NMS.QueryDataTable(PubUtils.uContext, sqlcmd).Rows.Count > 0) { new PubUtils().ShowNoteNGMsg("该类型的等级已存在", 2, grade.RepeatedError); return(false); } //if (/*row.Cells["TemperatureMaxTime"].Value == null && row.Cells["TemperatureMinTime"].Value == null &&*/ /*row.Cells["ExposeTime"].Value == null && */row.Cells["InHouseTime"].Value == null && row.Cells["SplitTime"].Value == null/* && row.Cells["RoastMaxTemperature"].Value == null && row.Cells["RoastMinTemperature"].Value == null && row.Cells["RoastTime"].Value == null */&& row.Cells["Remark"].Value == null) // continue; if (cbo_Type.SelectedValue.ToString() == "2") { if (!CheckTime(row, out msg)) { MsgBox.Error(msg); return(false); } } if (cbo_Type.SelectedValue.ToString() == "0" || cbo_Type.SelectedValue.ToString() == "1") { if (row.Cells["TemperatureMinTime"].Value == null) { new PubUtils().ShowNoteNGMsg("最小回温时间不能为空", 2, grade.RepeatedError); return(false); } if (row.Cells["TemperatureMaxTime"].Value == null) { new PubUtils().ShowNoteNGMsg("最大回温时间不能为空", 2, grade.RepeatedError); return(false); } } if (cbo_Type.SelectedValue.ToString() == "2") { if (row.Cells["RoastMinTemperature"].Value == null) { new PubUtils().ShowNoteNGMsg("最小烘烤温度不能为空", 2, grade.RepeatedError); return(false); } if (row.Cells["RoastMaxTemperature"].Value == null) { new PubUtils().ShowNoteNGMsg("最大烘烤温度不能为空", 2, grade.RepeatedError); return(false); } if (row.Cells["RoastTime"].Value == null) { new PubUtils().ShowNoteNGMsg("烘烤时间不能为空", 2, grade.RepeatedError); return(false); } if (row.Cells["ExposeTime"].Value == null || SqlInput.ChangeNullToInt(row.Cells["ExposeTime"].Value, 0) == 0) { new PubUtils().ShowNoteNGMsg("暴露时间不能为空", 2, grade.RepeatedError); return(false); } } if ((row.Cells["TemperatureMinTime"].Value != null && row.Cells["TemperatureMaxTime"].Value != null) && SqlInput.ChangeNullToInt(row.Cells["TemperatureMinTime"].Value, 0) >= SqlInput.ChangeNullToInt(row.Cells["TemperatureMaxTime"].Value, 0)) { new PubUtils().ShowNoteNGMsg("最小回温时间必须小于最大回温时间", 2, grade.RepeatedError); return(false); } if ((row.Cells["RoastMinTemperature"].Value != null && row.Cells["RoastMaxTemperature"].Value != null) && SqlInput.ChangeNullToDecimal(row.Cells["RoastMinTemperature"].Value, 0) >= SqlInput.ChangeNullToDecimal(row.Cells["RoastMaxTemperature"].Value, 0)) { new PubUtils().ShowNoteNGMsg("最小烘烤温度必须小于最大烘烤温度", 2, grade.RepeatedError); return(false); } return(true); }