using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data; using SiaSun.LMS.Model; namespace SiaSun.LMS.WPFClient.TASK { /// /// /// public partial class ManageBindIn : AvalonDock.DocumentContent { Model.MANAGE_TYPE mMANAGE_TYPE = null; #region 构造函数 public ManageBindIn(string MANAGE_TYPE_CODE) { InitializeComponent(); this.mMANAGE_TYPE = (Model.MANAGE_TYPE)MainApp._I_BaseService.GetModel("MANAGE_TYPE_SELECT_BY_MANAGE_TYPE_CODE", MANAGE_TYPE_CODE).RequestObject; this.ucQueryGoods.U_Query += new UC.ucQuickQuery.U_QueryEventHandler(ucQueryGoods_U_Query); this.gridGoods.gridApp.MouseDoubleClick += new MouseButtonEventHandler(gridApp_MouseDoubleClick); } #endregion #region 系统方法 private void DocumentContent_Loaded(object sender, RoutedEventArgs e) { try { this.InitQueryControl(); this.GoodsBind(string.Empty); this.InitManagePosition(); this.ucManagePosition.U_StockBarcodeKeyDown += new UC.ucManagePosition.U_StockBarcodeKeyDownHandler (() => { this.BindListBind(); } ); Area_Bind(); Plan_Type_Bind(); ManageListBind(); Register_DataTable_Event(); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } private void cbbAREA_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.Source == null) return; this.cbbCELL.DisplayMemberPath = "CELL_NAME"; this.cbbCELL.SelectedValuePath = "CELL_ID"; try { string strSQL = string.Empty; // string strSQL = string.Format(@"SELECT CELL_ID, // CELL_NAME // FROM WH_CELL // WHERE CELL_TYPE = 'Cell' // AND CELL_INOUT != 'Out' // AND AREA_ID = {0} // ORDER BY CELL_ID", this.cbbAREA.SelectedValue,string.IsNullOrEmpty() ? string.Empty : string.Format(" AND CELL_Z = '{0}'", CELL_Z.ToString()); if (this.cbbAREA.SelectedValue == null) { strSQL = string.Format(@"SELECT CELL_ID, CELL_NAME FROM WH_CELL WHERE CELL_TYPE = 'Cell' AND CELL_INOUT != 'Out' AND AREA_ID = {0} ORDER BY CELL_ID", 1); } else { strSQL = string.Format(@"SELECT CELL_ID, CELL_NAME FROM WH_CELL WHERE CELL_TYPE = 'Cell' AND CELL_INOUT != 'Out' AND AREA_ID = {0} ORDER BY CELL_ID", this.cbbAREA.SelectedValue); } this.cbbCELL.ItemsSource = MainApp._I_BaseService.GetList(strSQL).DefaultView; if (this.cbbCELL.Items.Count > 0) { this.cbbCELL.SelectedIndex = this.cbbCELL.SelectedIndex < 0 ? 0 : this.cbbCELL.SelectedIndex; } } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } #endregion #region 自定义方法 private void InitQueryControl() { this.ucQueryGoods.U_WindowName = this.GetType().Name; this.ucQueryGoods.U_XmlTableName = "GOODS_MAIN"; this.ucQueryGoods.U_InitControl(); } private void GoodsBind(string QueryWhere) { try { this.gridGoods.U_WindowName = this.GetType().Name; this.gridGoods.U_TableName = "V_GOODS"; this.gridGoods.U_XmlTableName = "GOODS_MAIN"; this.gridGoods.U_OrderField = "GOODS_CODE DESC"; //this.gridGoods.U_Where = string.Format("{0} AND GOODS_FLAG=1 ", string.IsNullOrEmpty(QueryWhere) ? "1=1" : QueryWhere); this.gridGoods.U_Where = string.Format("GOODS_TYPE_ID!=2 and GOODS_FLAG=1 and {0}", string.IsNullOrEmpty(QueryWhere) ? "1=1" : QueryWhere); this.gridGoods.U_AllowOperatData = false; this.gridGoods.U_AllowChecked = false; this.gridGoods.U_InitControl(); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } private void InitManagePosition() { try { this.ucManagePosition.U_InitControl(mMANAGE_TYPE.MANAGE_TYPE_ID); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } private void Area_Bind() { this.cbbAREA.DisplayMemberPath = "AREA_NAME"; this.cbbAREA.SelectedValuePath = "AREA_ID"; try { this.cbbAREA.ItemsSource = MainApp._I_CellService.AREA_GetList(0, "XuNiKu").DefaultView; if (this.cbbAREA.Items.Count > 0) { this.cbbAREA.SelectedIndex = this.cbbAREA.SelectedIndex < 0 ? 0 : this.cbbAREA.SelectedIndex; } } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } private void Plan_Type_Bind() { this.cbbPLAN_TYPE.DisplayMemberPath = "PLAN_TYPE_NAME"; this.cbbPLAN_TYPE.SelectedValuePath = "PLAN_TYPE_CODE"; try { string strSQL = string.Format(@"SELECT PLAN_TYPE_CODE, PLAN_TYPE_NAME FROM PLAN_TYPE WHERE PLAN_TYPE_INOUT = '1' AND PLAN_TYPE_FLAG= '1' ORDER BY PLAN_TYPE_ORDER"); this.cbbPLAN_TYPE.ItemsSource = MainApp._I_BaseService.GetList(strSQL).DefaultView; if (this.cbbPLAN_TYPE.Items.Count > 0) { this.cbbPLAN_TYPE.SelectedIndex = this.cbbPLAN_TYPE.SelectedIndex < 0 ? 0 : this.cbbPLAN_TYPE.SelectedIndex; } } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } void ucQueryGoods_U_Query(string QueryWhere) { this.GoodsBind(QueryWhere); } void gridApp_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (gridGoods.gridApp.SelectedItem == null) return; //获得物料记录 DataRowView rowViewGoods = this.gridGoods.gridApp.SelectedItem as DataRowView; //获得添加行 DataTable tableManageList = this.Manage_LIST_Add_By_GOODS(0, new string[] { rowViewGoods["GOODS_ID"].ToString() }); //添加行数据 this.gridManageList.U_AddTabPageRows(tableManageList.Rows.Cast().ToArray()); } /// /// 添加列表信息返回表单集合 /// public DataTable Manage_LIST_Add_By_GOODS(int STORAGE_ID, IList listGOODS_ID) { //创建集合 string strSql = string.Format("SELECT * FROM V_STORAGE_LIST WHERE STORAGE_ID={0}", 0); using (DataTable tableStorageList = MainApp._I_BaseService.GetList(strSql)) { foreach (string strGoodsID in listGOODS_ID) { //获得物料实体 SiaSun.LMS.Model.GOODS_MAIN mGOODS_MAIN = MainApp._I_GoodsService.GoodsGetModelGoodsID(Convert.ToInt32(strGoodsID)); SiaSun.LMS.Model.GOODS_CLASS mGOODS_CLASS = MainApp._I_GoodsService.GoodsClassGetModelGoodsClassID(mGOODS_MAIN.GOODS_CLASS_ID); if (mGOODS_MAIN != null && mGOODS_CLASS != null) { DataRow rowStorageList = tableStorageList.NewRow(); rowStorageList["GOODS_ID"] = mGOODS_MAIN.GOODS_ID; rowStorageList["GOODS_CODE"] = mGOODS_MAIN.GOODS_CODE; rowStorageList["GOODS_NAME"] = mGOODS_MAIN.GOODS_NAME; rowStorageList["GOODS_TYPE_ID"] = mGOODS_CLASS.GOODS_TYPE_ID; rowStorageList["GOODS_UNITS"] = mGOODS_MAIN.GOODS_UNITS; rowStorageList["GOODS_STATUS"] = mGOODS_MAIN.GOODS_CONST_PROPERTY1; rowStorageList["MANU_NAME"] = mGOODS_MAIN.GOODS_CONST_PROPERTY2; rowStorageList["SUP_NAME"] = mGOODS_MAIN.GOODS_CONST_PROPERTY3; rowStorageList["GOODS_STAND"] = mGOODS_MAIN.GOODS_CONST_PROPERTY4; rowStorageList["GOODS_VERSION"] = mGOODS_MAIN.GOODS_CONST_PROPERTY5; rowStorageList["FAC_TIME"] = mGOODS_MAIN.GOODS_CONST_PROPERTY6; rowStorageList["GOODS_PRICE"] = mGOODS_MAIN.GOODS_CONST_PROPERTY7; //rowStorageList["GOODS_NUM"] = mGOODS_MAIN.GOODS_CONST_PROPERTY8; rowStorageList["MANAGE_LIST_QUANTITY"] = 0; tableStorageList.Rows.Add(rowStorageList); } } return tableStorageList; } } /// /// 注册表单事件 /// private void Register_DataTable_Event() { //当输入列值改变后验证数据是否合法 foreach (TabItem tabItem in this.gridManageList.tabSplitProperty.Items) { if (tabItem.HasContent) { DataTable tableSource = (tabItem.Content as UC.ucCommonDataGrid).U_DataSource.Table; tableSource.RowChanged -= new DataRowChangeEventHandler(tableSource_RowChanged); tableSource.RowChanged += new DataRowChangeEventHandler(tableSource_RowChanged); tableSource.ColumnChanged -= new DataColumnChangeEventHandler(table_ColumnChanged); tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChanged); } } } /// /// 表单数据校验 /// void tableSource_RowChanged(object sender, DataRowChangeEventArgs e) { if (e.Row.RowState == DataRowState.Added || e.Row.RowState == DataRowState.Modified) { //判断数量 if (e.Row.IsNull("MANAGE_LIST_QUANTITY") || Convert.ToDecimal(e.Row["MANAGE_LIST_QUANTITY"]) <= 0 || string.IsNullOrEmpty(e.Row["MANAGE_LIST_QUANTITY"].ToString())) { e.Row.RowError = string.Format("请检查数量是否合法!"); } } } /// /// 表单数据校验 /// private void table_ColumnChanged(object sender, DataColumnChangeEventArgs e) { bool bResult = true; string sResult = string.Empty; //判断列 switch (e.Column.ColumnName) { case "MANAGE_LIST_QUANTITY": bResult = (!string.IsNullOrEmpty(e.ProposedValue.ToString()) && Convert.ToDecimal(e.ProposedValue) > 0); sResult = string.Format("请输入大于0的数量"); break; } if (bResult) { e.Row.RowError = null; e.Row.SetColumnError(e.Column, null); } else { e.Row.RowError = "数据校验失败"; e.Row.SetColumnError(e.Column, sResult); } } /// /// 现配盘明细 /// private void ManageListBind() { this.gridManageList.U_Clear(); this.gridManageList.U_WindowName = this.GetType().Name; this.gridManageList.U_TableName = "V_STORAGE_LIST"; this.gridManageList.U_XmlTableName = "V_STORAGE_LIST_LOCAL"; this.gridManageList.U_TotalColumnName = "MANAGE_LIST_QUANTITY"; this.gridManageList.U_OrderField = "STORAGE_LIST_ID"; this.gridManageList.U_Where = string.Format(" STOCK_BARCODE='*'"); this.gridManageList.U_AllowOperatData = true; this.gridManageList.U_AllowChecked = false; this.gridManageList.U_AllowShowPage = false; this.gridManageList.U_AllowAdd = System.Windows.Visibility.Collapsed; this.gridManageList.U_AllowEdit = System.Windows.Visibility.Collapsed; this.gridManageList.U_AllowSave = System.Windows.Visibility.Collapsed; //拆分列属性 this.gridManageList.U_SplitPropertyType = "GOODS_TYPE"; this.gridManageList.U_SplitGroupColumn = "GOODS_TYPE_ID"; this.gridManageList.U_SplitPropertyColumn = "GOODS_PROPERTY"; this.gridManageList.U_SplitGroupHeader = "GOODS_TYPE.GOODS_TYPE_NAME"; this.gridManageList.U_InitControl(); } /// /// 原配盘明细 /// private void BindListBind() { string STOCK_BARCODE = this.ucManagePosition.U_STOCK_BARCODE.ToUpper(); this.gridBindList.U_WindowName = this.GetType().Name; this.gridBindList.U_TableName = "V_STORAGE_LIST"; this.gridBindList.U_XmlTableName = "V_STORAGE_LIST"; this.gridBindList.U_TotalColumnName = "STORAGE_LIST_QUANTITY"; this.gridBindList.U_OrderField = "STORAGE_LIST_ID DESC"; this.gridBindList.U_Where = string.Format(@" AREA_TYPE='XuNiKu' AND {0}", string.IsNullOrEmpty(STOCK_BARCODE) ? "1=1" : string.Format("STOCK_BARCODE = '{0}'", STOCK_BARCODE)); this.gridBindList.U_AllowOperatData = false; this.gridBindList.U_AllowChecked = false; this.gridBindList.U_AllowShowPage = false; this.gridBindList.U_AllowAdd = System.Windows.Visibility.Collapsed; this.gridBindList.U_AllowEdit = System.Windows.Visibility.Collapsed; this.gridBindList.U_AllowSave = System.Windows.Visibility.Collapsed; //拆分列属性 this.gridBindList.U_SplitPropertyType = "GOODS_TYPE"; this.gridBindList.U_SplitGroupColumn = "GOODS_TYPE_ID"; this.gridBindList.U_SplitPropertyColumn = "GOODS_PROPERTY"; this.gridBindList.U_SplitGroupHeader = "GOODS_TYPE.GOODS_TYPE_NAME"; this.gridBindList.U_InitControl(); } #endregion #region 按钮事件 private void Button_Click(object sender, RoutedEventArgs e) { Button btn = e.OriginalSource as Button; if (btn != null) { switch (btn.Name) { case "btnIN": this.CreateTaskIN(); break; case "btnBindIn": this.CreateTaskBindIn(); break; case "btnRefresh": this.Refresh(); break; default: break; } } } /// /// 入库-直接入库 /// private void CreateTaskIN() { bool bResult = true; string sResult = string.Empty; try { MainWindow.mainWin.Cursor = Cursors.Wait; //结束当前编辑操作 this.gridManageList.U_EndCurrentEdit(); #region 校验数据表单 //检验数据是否合法 DataTable tableSource = this.gridManageList.U_DataSource; //根据数据源获得数据列表 List lsMANAGE_LISTall = new SiaSun.LMS.Common.CloneObjectValues().GetListFromDataTable(tableSource, null); var list = from v in lsMANAGE_LISTall where v.MANAGE_LIST_QUANTITY > 0 select v; List lsMANAGE_LIST = list.ToList(); #region ------校验合法性 //判断是否填写数据 if (lsMANAGE_LIST.Count <= 0) { bResult = false; MainApp._MessageDialog.Show(bResult, "请填写数据表单"); return; } if (lsMANAGE_LISTall.Count > lsMANAGE_LIST.Count) { bResult = false; MainApp._MessageDialog.Show(bResult, "【入库数量】不能为0"); return; } //判断数据是否合法 if (tableSource.HasErrors) { bResult = false; MainApp._MessageDialog.Show(bResult, "表单存在不合法的数据"); return; } //判断拆分属性是否填写正确 if (!this.gridManageList.U_Check_Split_Property("GOODS_PROPERTY", out sResult)) { MainApp._MessageDialog.ShowException(sResult); return; } #endregion #endregion #region 校验接收库区 if (this.cbbAREA.SelectedValue == null) { bResult = false; sResult = string.Format("请选择接收库区"); MainApp._MessageDialog.Show(bResult, sResult); return; } #endregion #region 校验接收地点 if (this.cbbCELL.SelectedValue == null) { bResult = false; sResult = string.Format("请选择接收地点"); MainApp._MessageDialog.Show(bResult, sResult); return; } #endregion #region 校验接收类型 if (this.cbbPLAN_TYPE.SelectedValue == null) { bResult = false; sResult = string.Format("请选择接收类型"); MainApp._MessageDialog.Show(bResult, sResult); return; } #endregion if (MainApp._MessageDialog.ShowDialog("确认不配盘,仅接收入库?") == Sid.Windows.Controls.TaskDialogResult.Cancel) { return; } #region 生成MANAGE_MAIN MANAGE_MAIN mMANAGE_MAIN = new Model.MANAGE_MAIN(); mMANAGE_MAIN.PLAN_ID = 0; mMANAGE_MAIN.PLAN_TYPE_CODE = string.Empty; mMANAGE_MAIN.MANAGE_TYPE_CODE = mMANAGE_TYPE.MANAGE_TYPE_CODE.TrimEnd(); mMANAGE_MAIN.STOCK_BARCODE = string.Empty; mMANAGE_MAIN.CELL_MODEL = string.Empty; mMANAGE_MAIN.FULL_FLAG = string.Empty; mMANAGE_MAIN.START_CELL_ID = Convert.ToInt32(this.cbbCELL.SelectedValue); mMANAGE_MAIN.END_CELL_ID = Convert.ToInt32(this.cbbCELL.SelectedValue); mMANAGE_MAIN.MANAGE_OPERATOR = MainApp._USER.USER_NAME; mMANAGE_MAIN.MANAGE_BEGIN_TIME = SiaSun.LMS.Common.StringUtil.GetDateTime(); mMANAGE_MAIN.MANAGE_STATUS = SiaSun.LMS.Enum.MANAGE_STATUS.Waiting.ToString(); mMANAGE_MAIN.MANAGE_LEVEL = string.Empty; mMANAGE_MAIN.MANAGE_REMARK = string.Empty; #endregion bResult = MainApp._I_BaseService.Invoke(mMANAGE_TYPE.MANAGE_TYPE_CLASS.TrimEnd(), "ManageCreate", new object[] { mMANAGE_MAIN, lsMANAGE_LIST}, out sResult); //检验执行结果 if (bResult) { this.gridManageList.U_Update(); BindListBind(); } MainApp._MessageDialog.Show(bResult, sResult); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } finally { MainWindow.mainWin.Cursor = Cursors.Arrow; } } /// /// 入库-配盘入库 /// private void CreateTaskBindIn() { bool bResult = true; string sResult = string.Empty; try { MainWindow.mainWin.Cursor = Cursors.Wait; //结束当前编辑操作 this.gridManageList.U_EndCurrentEdit(); #region 校验数据表单 //检验数据是否合法 DataTable tableSource = this.gridManageList.U_DataSource; if (tableSource == null) { bResult = false; MainApp._MessageDialog.Show(bResult, "请填写数据表单"); return; } //根据数据源获得数据列表 List lsMANAGE_LIST = new SiaSun.LMS.Common.CloneObjectValues().GetListFromDataTable(tableSource, null); var list = from v in lsMANAGE_LIST where v.MANAGE_LIST_QUANTITY > 0 select v; lsMANAGE_LIST = list.ToList(); #region ------校验合法性 //判断是否填写数据 if (lsMANAGE_LIST.Count <= 0) { bResult = false; MainApp._MessageDialog.Show(bResult, "请填写【入库数量】"); return; } //判断数据是否合法 if (tableSource.HasErrors) { bResult = false; MainApp._MessageDialog.Show(bResult, "表单存在不合法的数据"); return; } //判断拆分属性是否填写正确 if (!this.gridManageList.U_Check_Split_Property("GOODS_PROPERTY", out sResult)) { MainApp._MessageDialog.ShowException(sResult); return; } #endregion #endregion #region 校验接收库区 if (this.cbbAREA.SelectedValue == null) { bResult = false; sResult = string.Format("请选择接收库区"); MainApp._MessageDialog.Show(bResult, sResult); return; } #endregion #region 校验接收地点 if (this.cbbCELL.SelectedValue == null) { bResult = false; sResult = string.Format("请选择接收地点"); MainApp._MessageDialog.Show(bResult, sResult); return; } #endregion #region 校验接收类型 if (this.cbbPLAN_TYPE.SelectedValue == null) { bResult = false; sResult = string.Format("请选择接收类型"); MainApp._MessageDialog.Show(bResult, sResult); return; } #endregion //校验填写仓库信息是否合法 if (!this.ucManagePosition.U_CHECK_WAREHOUSE()) return; #region 校验容器条码 string STOCK_BARCODE = this.ucManagePosition.U_STOCK_BARCODE.ToUpper(); if (MainApp._MessageDialog.ShowDialog(string.Format("确认[{0}]配盘入库?", STOCK_BARCODE)) == Sid.Windows.Controls.TaskDialogResult.Cancel) { return; } #endregion #region 生成MANAGE_MAIN MANAGE_MAIN mMANAGE_MAIN = new Model.MANAGE_MAIN(); mMANAGE_MAIN.PLAN_ID = 0; mMANAGE_MAIN.PLAN_TYPE_CODE = string.Empty; mMANAGE_MAIN.MANAGE_TYPE_CODE = mMANAGE_TYPE.MANAGE_TYPE_CODE.TrimEnd(); mMANAGE_MAIN.STOCK_BARCODE = STOCK_BARCODE; mMANAGE_MAIN.CELL_MODEL = string.Empty; mMANAGE_MAIN.FULL_FLAG = this.ucManagePosition.U_OCCUPY_PERCENT; mMANAGE_MAIN.START_CELL_ID = Convert.ToInt32(this.cbbCELL.SelectedValue); mMANAGE_MAIN.END_CELL_ID = Convert.ToInt32(this.cbbCELL.SelectedValue); mMANAGE_MAIN.MANAGE_OPERATOR = MainApp._USER.USER_NAME; mMANAGE_MAIN.MANAGE_BEGIN_TIME = SiaSun.LMS.Common.StringUtil.GetDateTime(); mMANAGE_MAIN.MANAGE_STATUS = SiaSun.LMS.Enum.MANAGE_STATUS.Waiting.ToString(); mMANAGE_MAIN.MANAGE_LEVEL = string.Empty; mMANAGE_MAIN.MANAGE_REMARK = string.Empty; #endregion bResult = MainApp._I_BaseService.Invoke(mMANAGE_TYPE.MANAGE_TYPE_CLASS.TrimEnd(), "ManageCreate", new object[] { mMANAGE_MAIN, lsMANAGE_LIST}, out sResult); //检验执行结果 if (bResult) { this.gridManageList.U_Update(); BindListBind(); } MainApp._MessageDialog.Show(bResult, sResult); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } finally { MainWindow.mainWin.Cursor = Cursors.Arrow; } } /// /// 刷新 /// private void Refresh() { this.ucManagePosition.U_Update(); this.gridManageList.U_Update(); BindListBind(); } #endregion } }