using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WMS.Frm.Base; using WMS.Model.Base; using WMS.Common; using WMS.Ctrl; using WMS.Business; using WMS.Business.Base; namespace WMS.FrmBaseData { /// /// 窗体:仓库信息编辑 /// public partial class FrmStorageInfoHandle : FormBase { #region 变量 private StorageInfoModel storageInfoModel = new StorageInfoModel(); private List storageOrderList = new List(); private int flag = -1;//0:新增;1:修改 #endregion #region 初始化 /// /// 构造函数 用于新增 /// public FrmStorageInfoHandle() { InitializeComponent(); storageInfoModel.STATUS = "正常"; storageInfoModel.BATCHFLAG = "否"; storageInfoModel.GOODSFLAG = "否"; storageInfoModel.RFMODEL = "否"; // storageInfoModel.VERSION = "Version 1.0"; flag = 0; } /// /// 构造函数 用于修改 /// /// public FrmStorageInfoHandle(StorageInfoModel storageInfo, List list) { InitializeComponent(); flag = 1; storageInfoModel = storageInfo; storageOrderList = list; } /// /// load /// /// /// private void FrmStorageInfoHandle_Load(object sender, EventArgs e) { // lookUpEditDicType.LoadData(); luePro.LoadData(); lueCity.LoadData(); lueTown.LoadData(); if (string.IsNullOrEmpty(storageInfoModel.STORAGE_ID)) { luePro.Text = storageInfoModel.PROVINCE_NAME; lueCity.Text = storageInfoModel.CITY_NAME; } if(storageInfoModel!=null) bsStorageInfo.DataSource = storageInfoModel; if (storageOrderList != null) bsStorageOrder.DataSource = storageOrderList; // GVStorageOrder.RefreshData(); } #endregion #region 按钮事件 /// /// 确定按钮 /// /// /// private void ctrlButtons1_Click(object sender, EventArgs e) { btnConfirm.Focus(); //非空验证 if (string.IsNullOrEmpty(txtStorageName.Text.Trim())) { SystemCommon.ShowInfoMessageBox("仓库名称不能为空"); txtStorageName.Focus(); return; } if (string.IsNullOrEmpty(luePro.Text.Trim())) { SystemCommon.ShowInfoMessageBox("请选择省份"); luePro.Focus(); return; } if (string.IsNullOrEmpty(lueCity.Text.Trim())) { SystemCommon.ShowInfoMessageBox("请选择城市"); lueCity.Focus(); return; } if (string.IsNullOrEmpty(lueTown.Text.Trim())) { SystemCommon.ShowInfoMessageBox("请选择县/市/区"); lueTown.Focus(); return; } //if (string.IsNullOrEmpty(txtAddress.Text.Trim())) //{ // SystemCommon.ShowInfoMessageBox("地址不能为空"); // txtAddress.Focus(); // return; //} //if (storageOrderList.Count == 0) //{ // SystemCommon.ShowInfoMessageBox("请选择订单范围"); // ctrlDicStoOrder.Focus(); // return; //} StorageInfoModel model = storageInfoModel; if (rgStatus.Text == "正常") { model.STATUS = "0"; } else { model.STATUS = "1"; } if (rgRFMODEL.Text == "否") { model.RFMODEL = "0"; } else { model.RFMODEL = "1"; } if (rgGOODSFLAG.Text == "否") { model.GOODSFLAG = "0"; } else { model.GOODSFLAG = "1"; } if (rgBATCHFLAG.Text == "否") { model.BATCHFLAG = "0"; } else { model.BATCHFLAG = "1"; } model.OPERATORID = userData.USER_ID;//操作人 if (flag == 1)//修改 { model.AUTOSTS = checkBox1.Checked; UpdateStorage(model); } else if (flag == 0)//新增 { model.AUTOSTS = checkBox1.Checked; AddStorage(model); } } public void UpdateStorage(StorageInfoModel model) { string errText = string.Empty; try { errText = IBussFactory.Instance().InsOrUpdStorageInfo(model, 1, storageOrderList); if (string.IsNullOrEmpty(errText)) { errText = string.Empty; try { errText = IBussFactory.Instance().CloseLocationInfoByStorageInfoID(model.STORAGE_ID, int.Parse(model.STATUS)); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("根据仓库停用或启用库位出错了CloseLocationInfoByStorageInfoID:" + ex.Message); return; } if (!string.IsNullOrEmpty(errText)) { SystemCommon.ShowInfoMessageBox("根据仓库停用或启用库位失败" + errText); return; } errText = string.Empty; try { errText = IBussFactory.Instance().CloseAreaInfoByStorageInfoID(model.STORAGE_ID, int.Parse(model.STATUS)); if (!string.IsNullOrEmpty(errText)) { SystemCommon.ShowInfoMessageBox("根据仓库停用或启用库区失败" + errText); return; } SystemCommon.ShowInfoMessageBox("修改成功"); this.Close(); this.Dispose(); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("根据仓库停用或启用库区出错了:" + ex.Message); return; } } else { if (errText == "ORA-00001: unique constraint (WMS.STORAGE_ORDER) violated") { SystemCommon.ShowInfoMessageBox("所选订单配送区域已被其它仓库占有,请重新选择"); } else { SystemCommon.ShowInfoMessageBox("修改失败" + errText); } } } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("出错了:" + ex.Message); } } private void AddStorage(StorageInfoModel model) { string errText = string.Empty; try { errText = IBussFactory.Instance().InsOrUpdStorageInfo(model, 0, storageOrderList); if (string.IsNullOrEmpty(errText)) { SystemCommon.ShowInfoMessageBox("新增成功"); this.Close(); this.Dispose(); } } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("新增仓库出错了InsOrUpdStorageInfo:" + ex.Message); } } /// /// 退出按钮 /// /// /// private void ctrlButtons2_Click(object sender, EventArgs e) { if (DialogResult.OK != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?")) { return; } this.Close(); this.Dispose(); } #endregion #region 改变省份后 城市只显示该省份的所有城市 /// /// 改变省份后 城市只显示该省份的所有城市 /// /// /// private void luePro_EditValueChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(luePro.EditValue.ToString())) { //绑定城市数据 string errText = string.Empty; AddressAreaModel addressAreaModel = new AddressAreaModel(); try { addressAreaModel.Add_pid = luePro.EditValue.ToString(); DataTable tb = IBussFactory.Instance().GetAddressArea(addressAreaModel); if(tb!=null) { lueCity.Properties.DataSource = tb; } } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("查询城市出错了:" + ex.Message); } } } #endregion #region 改变城市后 区县只显示该城市的所有区县 /// /// 改变城市后 区县只显示该城市的所有区县 /// /// /// private void lueCity_EditValueChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(lueCity.EditValue.ToString()) ) { //绑定区县数据 string errText = string.Empty; AddressAreaModel addressAreaModel = new AddressAreaModel(); addressAreaModel.Add_pid = lueCity.EditValue.ToString(); try { DataTable tab = IBussFactory.Instance().GetAddressArea(addressAreaModel); lueTown.Properties.DataSource = tab; } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("出错了:" + ex.Message); } } } #endregion /// /// //通过地址区域编号得名称 /// /// 地址区域编号 /// 父编号 /// 地址区域名称 private string getAddressAreaNameByID(string id, ref string p_id) { string proName = string.Empty; AddressAreaModel tempModel = new AddressAreaModel(); tempModel.Add_id = id; List tResultList = new List(); try { DataTable tab = IBussFactory.Instance().GetAddressArea(tempModel); tResultList = ConvertHelper.ConvertToList(tab); } catch (Exception ex) { SystemCommon.ShowInfoMessageBox("出错了:" + ex.Message); } if (tResultList.Count > 0) { p_id = tResultList[0].Add_pid; return tResultList[0].Add_name; } else { return string.Empty; } } } }