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.Strategy; using WMS.Common; using DevExpress.XtraEditors.Repository; using WMS.Business; using WMS.Business.Strategy; using WMS.Business.Common; namespace WMS.FrmStrategy { public partial class FrmDownStrategyDet : FormBase { #region 变量 private DownStrategyModel downStrategyModel = new DownStrategyModel(); private List listDownStycts = new List(); private DownStyctsModel downStycts = new DownStyctsModel(); private int flag = -1;//0:新增;1:修改; private DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit lueAreas = new RepositoryItemLookUpEdit(); #endregion #region 初始化 /// /// 构造函数 用于新增 /// public FrmDownStrategyDet() { Inti(); flag = 0; } /// /// 构造函数 用于修改 /// /// public FrmDownStrategyDet(DownStrategyModel downStrategy) { Inti(); flag = 1; downStrategyModel = downStrategy; this.Text = "下架策略信息-" + downStrategyModel.DOWNSTRATEGY_ID; } private void FrmDownStrategyDet_Load(object sender, EventArgs e) { if (flag == 1) { //绑明细 string errText = string.Empty; string strDataSet = string.Empty; DownStyctsModel queryDownStycts = new DownStyctsModel(); queryDownStycts.DOWNSTRATEGY_ID = downStrategyModel.DOWNSTRATEGY_ID; try { listDownStycts = IBussFactory.Instance().GetDownStyctsList(queryDownStycts); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (errText .Trim().Length >0) { SystemCommon.ShowInfoMessageBox(errText); } downStrategyModel.UPDATE_MAN = userData.USER_ID; } else if (flag == 0) { downStrategyModel.ADDED_FLAG = "0"; downStrategyModel.NULL_FLAG = "0"; downStrategyModel.PRODUCE_FLAG = "0"; downStrategyModel.DOWNSTRATEGY_STATE = "0"; downStrategyModel.CREATE_MAN = userData.USER_ID; listDownStycts.Add(new DownStyctsModel()); } bsDownStrategy.DataSource = downStrategyModel; bsDownStycts.DataSource = listDownStycts; GVDownStycts.RefreshData(); } private void Inti() { InitializeComponent(); lueStorage.NullText = ""; lueStorage.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("STORAGE_NAME", "仓库")); lueStorage.ValueMember = "STORAGE_ID"; lueStorage.DisplayMember = "STORAGE_NAME"; try { DataTable strResult = IBussFactory.Instance().GetCustomCtrlData("T_BASE_STORAGEINFO", "STORAGE_ID", "STORAGE_NAME", "", ""); if (strResult != null) { lueStorage.DataSource = strResult; } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } lueArea.NullText = ""; lueArea.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("STORAGE_AREA_NAME", "库区")); lueArea.ValueMember = "STORAGE_AREA_ID"; lueArea.DisplayMember = "STORAGE_AREA_NAME"; try { DataTable strResult = IBussFactory.Instance().GetCustomCtrlData("T_BASE_STORAGE_AREA", "STORAGE_AREA_ID", "STORAGE_AREA_NAME", "", ""); if(strResult!=null) lueArea.DataSource = strResult; } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } lueAreas.NullText = ""; lueAreas.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("STORAGE_AREA_NAME", "库区")); lueAreas.ValueMember = "STORAGE_AREA_ID"; lueAreas.DisplayMember = "STORAGE_AREA_NAME"; } #endregion private void btnAddTab_Click(object sender, EventArgs e) { DownStyctsModel model = new DownStyctsModel(); model.DOWNSTRATEGY_ID = downStrategyModel.DOWNSTRATEGY_ID; listDownStycts.Add(model); bsDownStycts.DataSource = listDownStycts; GVDownStycts.RefreshData(); } private void btnDelTab_Click(object sender, EventArgs e) { downStycts = GVDownStycts.GetFocusedRow() as DownStyctsModel; listDownStycts.Remove(downStycts); bsDownStycts.DataSource = listDownStycts; GVDownStycts.RefreshData(); } private void btnSave_Click(object sender, EventArgs e) { /*验证*/ if (string.IsNullOrEmpty(txtStartegyName.Text)) { SystemCommon.ShowInfoMessageBox("请输入策略名称"); txtStartegyName.Focus(); return; } List listAllDownStycts = new List(); string errText = string.Empty; string strDataSet = string.Empty; DownStyctsModel queryDownStycts = new DownStyctsModel(); try { listAllDownStycts = IBussFactory.Instance().GetDownStyctsList(queryDownStycts); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } if (errText.Trim().Length>0) { SystemCommon.ShowInfoMessageBox(errText); } foreach (var item in listDownStycts) { if (string.IsNullOrEmpty(item.STORAGE_ID)) { SystemCommon.ShowInfoMessageBox("请选择仓库"); GVDownStycts.Focus(); return; } if (string.IsNullOrEmpty(item.STORAGE_AREA_ID)) { SystemCommon.ShowInfoMessageBox("请选择库区"); GVDownStycts.Focus(); return; } if (listDownStycts.FindAll(p => p.STORAGE_ID == item.STORAGE_ID && p.STORAGE_AREA_ID == item.STORAGE_AREA_ID).Count>1) { SystemCommon.ShowInfoMessageBox("所选仓库库区不能重复"); GVDownStycts.Focus(); return; } if (listAllDownStycts.Exists(p => p.STORAGE_ID == item.STORAGE_ID && p.STORAGE_AREA_ID == item.STORAGE_AREA_ID && p.DOWNSTRATEGY_ID != item.DOWNSTRATEGY_ID)) { SystemCommon.ShowInfoMessageBox("所选仓库库区已存在于其它下架策略"); GVDownStycts.Focus(); return; } } if (flag == 0) { //增加 errText = string.Empty; try { errText = IBussFactory.Instance().InsertDownStrategyAndTab(downStrategyModel, listDownStycts); if (string.IsNullOrEmpty(errText))//如果增加成功 { SystemCommon.ShowInfoMessageBox("增加成功"); } else { SystemCommon.ShowInfoMessageBox("增加失败" + errText); return; } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } } else if (flag == 1)//修改 { errText = string.Empty; try { errText = IBussFactory.Instance().UpdateDownStrategyAndTab(downStrategyModel, listDownStycts); if (string.IsNullOrEmpty(errText))//如果修改成功 { SystemCommon.ShowInfoMessageBox("修改成功"); } else { SystemCommon.ShowInfoMessageBox("修改失败" + errText); return; } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } } this.Close(); this.Dispose(); } private void btnClose_Click(object sender, EventArgs e) { if (DialogResult.Yes != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?")) { return; } this.Close(); this.Dispose(); } private void GVDownStycts_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) { if (e.RowHandle < 0 || flag == -1) { return; } if (e.Column.Name == "colSTORAGE_AREA_ID") { try { DataTable strResult = IBussFactory.Instance().GetCustomCtrlData("T_BASE_STORAGE_AREA", "STORAGE_AREA_ID", "STORAGE_AREA_NAME", " STORAGE_ID = '" + GVDownStycts.GetFocusedRowCellValue("STORAGE_ID").ToString() + "'", ""); if (strResult != null) { lueAreas.DataSource = strResult; } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } e.RepositoryItem = lueAreas;//当前单元格绑定控件 } } } }