//private void dgv_Container_CellValueChanged(object sender, DataGridViewCellEventArgs e) //{ // if (dgv_Container.Columns[e.ColumnIndex].Name == checkId.Name & e.RowIndex >= 0) // { // string container_type = dgv_Container.Rows[e.RowIndex].Cells[DICT_VALUE.Name].Value.ToString(); // DataRow[] drs = _dt_container.Select(string.Format("DICT_VALUE='{0}'", container_type)); // if (drs.Length > 0) // { // bool isCheck = SqlInput.ChangeBoolToValue(dgv_Container.Rows[e.RowIndex].Cells[checkId.Name].Value, false); // if (isCheck == true) // { // switch (drs[0]["flag"].ToString()) // { // case "0": // drs[0]["flag"] = "2";//新增(只有状态0才能变成2) // break; // case "3": // drs[0]["flag"] = "1";//有( 只有状态3才能变成1)(状态0和1都不对数据库进行操作) // break; // } // } // else // { // switch (drs[0]["flag"].ToString()) // { // case "2": // drs[0]["flag"] = "0";//无(只有状态2才能变成0)(状态0和1都不对数据库进行操作) // break; // case "1": // drs[0]["flag"] = "3";//删除(只有状态1才能变成3) // break; // } // } // dgv_Container.DataSource = _dt_container; // } // } // else if (dgv_Container.Columns[e.ColumnIndex].Name == QTY.Name & e.RowIndex >= 0)//输入数量 // { // string container_type = dgv_Container.Rows[e.RowIndex].Cells[DICT_VALUE.Name].Value.ToString(); // DataRow[] drs = _dt_container.Select(string.Format("DICT_VALUE='{0}'", container_type)); // if (drs.Length > 0) // { // int res = 1; // if (int.TryParse(dgv_Container.Rows[e.RowIndex].Cells[QTY.Name].Value.ToString(), out res)) // { // if (res <= 0) // { // MessageBox.Show("请输入大于0的整数"); // } // } // else // { // MessageBox.Show("请输入大于0的整数"); // } // } // } //} private void btn_ok_Click(object sender, EventArgs e) { if (txt_Begin_LocationSN.Text.Trim() == string.Empty) { MessageBox.Show("请输入开始库位SN"); return; } else if (txt_End_LocationSN.Text.Trim() == string.Empty) { MessageBox.Show("请输入结束库位SN"); return; } //else if (txt_Begin_LocationSN.Text.Trim().Length != txt_End_LocationSN.Text.Trim().Length) //{ // MessageBox.Show("开始库位SN与结束库位SN长度不一致"); // return; //} int begin = 0; int end = 0; try { begin = int.Parse(txt_Begin_LocationSN.Text.Trim()); end = int.Parse(txt_End_LocationSN.Text.Trim()); if (begin > end) { MessageBox.Show("开始库位SN必须小于或者等于结束库位SN"); return; } } catch { MessageBox.Show("开始库位SN与结束库位SN必须是数字"); return; } #region MyRegion //if (_dt_container != null) //{ // DataRow[] drs = _dt_container.Select("flag='2'"); // if (drs.Length == 0) // { // MessageBox.Show("请选择可存放的容器"); // return; // } // foreach (DataRow dr in drs) // { // int res = 1; // if (int.TryParse(dr[QTY.Name].ToString(), out res)) // { // if (res == 0) // { // MessageBox.Show("请输入大于0的整数"); // return; // } // } // else // { // MessageBox.Show("请输入大于0的整数"); // return; // } // } //} #endregion while (begin <= end) { #region 库位数据操作 Model.T_Bllb_StorageLocation_tbsl tbsl = new Model.T_Bllb_StorageLocation_tbsl(); //tbsl.Location_SN = lbl_Begin_LocationSN.Text.Trim() + begin.ToString("00"); //tbsl.Location_Name = "库位" + lbl_Begin_LocationSN.Text.Trim() + begin.ToString("00"); tbsl.Location_SN = string.Format("{0}{1}", txt_fixChar.Text.Trim(), begin.ToString("00")); tbsl.Location_Name = string.Format("库位{0}{1}", txt_fixChar.Text.Trim(), begin.ToString("00")); tbsl.Area_SN = cbo_ParentStorage.SelectedValue.ToString(); tbsl.Enable_Flag = "Y"; if (BLL.Bll_Bllb_StorageLocation_tbsl.IsExist(tbsl.Location_SN)) { MessageBox.Show("库位" + tbsl.Location_SN + "已存在"); return; } BLL.Bll_Bllb_StorageLocation_tbsl.Insert(tbsl); #endregion #region 库位容器信息 //Model.T_Bllb_LocationContainer_tblc obj = new Model.T_Bllb_LocationContainer_tblc(); //foreach (DataRow dr in _dt_container.Rows) //{ // if (dr["flag"].ToString() == "2")//新增库位容器信息 // { // obj.Location_SN = tbsl.Location_SN; // obj.Container_Type = dr["DICT_CODE"].ToString(); // obj.QTY = SqlInput.ChangeNullToInt(dr["QTY"], 1); // BLL.Bll_Bllb_LocationContainer_tblc.Insert(obj); // } //} #endregion begin++; } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_ok_Click(object sender, EventArgs e) { ShowMsg(string.Empty, true); //dgv_Container.EndEdit(); #region 校验 if (_opreateFlag == "1")//新增 { if (txt_StorageSN.Text.Trim() == string.Empty) { ShowMsg(lbl_SN.Text + "不能为空", false); return; } else if (txt_StorageName.Text.Trim() == string.Empty) { ShowMsg(lbl_Name.Text + "不能为空", false); return; } DataRow[] dr = _dt_storage.Select(string.Format("Storage_SN='{0}' OR Area_SN='{0}' OR Location_SN='{0}'", txt_StorageSN.Text.Trim())); if (dr.Length > 0) { ShowMsg("储位SN已存在", false); return; } dr = _dt_storage.Select(string.Format("Storage_Name='{0}' OR Area_Name='{0}' OR Location_Name='{0}'", txt_StorageName.Text.Trim())); if (dr.Length > 0) { ShowMsg("储位已存在", false); return; } } else if (_opreateFlag == "2")//编辑 { if (txt_StorageName.Text.Trim() == string.Empty) { ShowMsg(lbl_Name.Text + "不能为空", false); return; } DataRow[] dr = _dt_storage.Select(string.Format("Storage_Name='{0}' OR Area_Name='{0}' OR Location_Name='{0}'", txt_StorageName.Text.Trim() /*, txt_StorageSN.Text.Trim()*/)); if (dr.Length > 0) { if (dr[0]["Storage_SN"].ToString() != txt_StorageSN.Text.Trim() & dr[0]["Area_SN"].ToString() != txt_StorageSN.Text.Trim() & dr[0]["Location_SN"].ToString() != txt_StorageSN.Text.Trim()) { ShowMsg(lbl_Name.Text + "已存在", false); return; } } } #region MyRegion //if (_dt_container != null) //{ // //获取库位现在存放的容器数量及类型 // DataTable dt_LocationContainer = Bll_Bllb_StorageLocation_tbsl.GetListOfLocationContainer(txt_StorageSN.Text.Trim()); // foreach (DataRow dr in _dt_container.Rows) // { // int res = 1; // //if (int.TryParse(dr[QTY.Name].ToString(), out res)) // //{ // // if (res == 0) // // { // // ShowMsg("请输入大于0的整数", false); // // return; // // } // //} // //else // //{ // // ShowMsg("请输入大于0的整数", false); // // return; // //} // if (dt_LocationContainer.Rows.Count > 0) // { // if (dr["flag"].ToString() == "3")//删除库位容器信息 // { // if (dt_LocationContainer.Rows[0]["Container_Type"].ToString() == dr["DICT_CODE"].ToString()) // { // ShowMsg(string.Format("库位上有[{0}]不能进行取消", dt_LocationContainer.Rows[0]["DICT_VALUE"]), false); // return; // } // } // else if (dr["flag"].ToString() == "4")//修改库位容器信息 // { // int Container_Qty = int.Parse(dt_LocationContainer.Rows[0]["Container_Qty"].ToString()); // //if (Container_Qty > int.Parse(dr[QTY.Name].ToString())) // //{ // // ShowMsg(string.Format("库位上有[{0}]数量{1}", dt_LocationContainer.Rows[0]["DICT_VALUE"], Container_Qty), false); // // return; // //} // } // } // } //} #endregion if (cbo_Type.SelectedValue.ToString() == "1")//仓库操作 { if (string.IsNullOrEmpty(cbo_Person.Text.Trim())) { ShowMsg("仓库负责人必填", false); return; } try { string sqlCheckUser = string.Format("select * from SysDatUser where UserID='{0}'", cbo_Person.Text.Trim().Substring(cbo_Person.Text.IndexOf('@') + 1)); if (CIT.Wcf.Utils.NMS.QueryDataTable(CIT.MES.PubUtils.uContext, sqlCheckUser).Rows.Count == 0) { ShowMsg("仓库负责人不存在", false); return; } } catch (Exception) { ShowMsg("仓库负责人不存在", false); return; } } #endregion #region 保存数据 //保存数据 if (cbo_Type.SelectedValue.ToString() == "1")//仓库 { #region 仓库数据操作 Model.T_Bllb_Storage_tbs tbs = new Model.T_Bllb_Storage_tbs(); tbs.Storage_SN = txt_StorageSN.Text.Trim(); tbs.Storage_Name = txt_StorageName.Text.Trim(); tbs.Storage_Type = cbo_ParentStorage.SelectedValue.ToString(); tbs.Respons_Person = cbo_Person.Text.Trim().Substring(cbo_Person.Text.Trim().IndexOf('@') + 1); //tbs.Step = cbo_Step.SelectedValue.ToString(); if (_opreateFlag == "1")//新增 { BLL.Bll_Bllb_Storage_tbs.Insert(tbs); } else if (_opreateFlag == "2")//修改 { BLL.Bll_Bllb_Storage_tbs.Update(tbs); } #endregion } else if (cbo_Type.SelectedValue.ToString() == "2")//库区 { #region 库区数据操作 Model.T_Bllb_StorageArea_tbsa tbsa = new Model.T_Bllb_StorageArea_tbsa(); tbsa.Area_SN = txt_StorageSN.Text.Trim(); tbsa.Area_Name = txt_StorageName.Text.Trim(); tbsa.Storage_SN = cbo_ParentStorage.SelectedValue.ToString(); if (_opreateFlag == "1")//新增 { BLL.Bll_Bllb_StorageArea_tbsa.Insert(tbsa); } else if (_opreateFlag == "2")//修改 { BLL.Bll_Bllb_StorageArea_tbsa.Update(tbsa); } #endregion } else if (cbo_Type.SelectedValue.ToString() == "3")//库位 { #region 库位数据操作 Model.T_Bllb_StorageLocation_tbsl tbsl = new Model.T_Bllb_StorageLocation_tbsl(); tbsl.Location_SN = txt_StorageSN.Text.Trim(); tbsl.Location_Name = txt_StorageName.Text.Trim(); tbsl.Area_SN = cbo_ParentStorage.SelectedValue.ToString(); tbsl.Enable_Flag = chk_Enable_Flag.Checked ? "Y" : "N"; if (_opreateFlag == "1")//新增 { BLL.Bll_Bllb_StorageLocation_tbsl.Insert(tbsl); } else if (_opreateFlag == "2")//修改 { BLL.Bll_Bllb_StorageLocation_tbsl.Update(tbsl); } #endregion #region 库位容器信息 //foreach (DataRow dr in _dt_container.Rows) //{ // Model.T_Bllb_LocationContainer_tblc obj = new Model.T_Bllb_LocationContainer_tblc(); // obj.Location_SN = txt_StorageSN.Text.Trim(); // obj.Container_Type = dr["DICT_CODE"].ToString(); // obj.QTY = SqlInput.ChangeNullToInt(dr["QTY"], 1); // if (dr["flag"].ToString() == "2")//新增库位容器信息 // { // BLL.Bll_Bllb_LocationContainer_tblc.Insert(obj); // } // else if (dr["flag"].ToString() == "3")//删除库位容器信息 // { // BLL.Bll_Bllb_LocationContainer_tblc.Delete(obj); // } // else if (dr["flag"].ToString() == "4")//修改库位容器信息 // { // BLL.Bll_Bllb_LocationContainer_tblc.Update(obj); // } //} #endregion } #endregion EnableControl(false); cbo_Type.Enabled = false; cbo_ParentStorage.Enabled = false; txt_StorageName.ReadOnly = true; txt_StorageSN.ReadOnly = true; //checkId.ReadOnly = true; //QTY.ReadOnly = true; tv_Storage.Enabled = true; chk_Enable_Flag.Enabled = false; InitTreeData();//重新加载数据 tv_Storage.Refresh(); ShowMsg("保存成功", true); }