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; namespace SiaSun.LMS.WPFClient.MANAGE { public partial class MANAGE_PLAN_OUT : AvalonDock.DocumentContent { int intPlanID = 0; Model.MANAGE_TYPE mMANAGE_TYPE = null; DataRowView[] listDataRowView = null; string STORAGE_AREA_TYPE = string.Empty; string sWHERE = string.Empty; /// /// 构造函数 /// public MANAGE_PLAN_OUT(int PLAN_ID, string MANAGE_TYPE_CODE, string AREA_TYPE) { InitializeComponent(); intPlanID = PLAN_ID; STORAGE_AREA_TYPE = AREA_TYPE; this.mMANAGE_TYPE = (Model.MANAGE_TYPE)MainApp._I_BaseService.GetModel("MANAGE_TYPE_SELECT_BY_MANAGE_TYPE_CODE", MANAGE_TYPE_CODE).RequestObject; } private void DocumentContent_Loaded(object sender, RoutedEventArgs e) { this.InitManagePosotion(); this.PLAN_LIST_Bind(intPlanID); } private void InitManagePosotion() { this.ucManagePosition.U_InitControl(mMANAGE_TYPE.MANAGE_TYPE_ID); } private void Register_DataTable_Event() { //当输入列值改变后验证数据是否合法 foreach (TabItem tabItem in this.ucStorageGroup.tabSplitProperty.Items) { if (tabItem.HasContent) { DataTable tableSource = (tabItem.Content as UC.ucCommonDataGrid).U_DataSource.Table; tableSource.ColumnChanged -= new DataColumnChangeEventHandler(table_ColumnChanged); tableSource.ColumnChanged += new DataColumnChangeEventHandler(table_ColumnChanged); } } } /// /// 表单数据校验 /// private void table_ColumnChanged(object sender, DataColumnChangeEventArgs e) { bool bResult = true; string sResult = string.Empty; //判断列 switch (e.Column.ColumnName) { case "MANAGE_LIST_QUANTITY": bResult = ( Convert.ToDecimal(e.ProposedValue) <= Convert.ToDecimal(e.Row["STORAGE_LIST_QUANTITY"])); sResult = string.Format("出库数量不能大于库存数量!"); e.Row.ClearErrors(); if (bResult) { e.Row.SetColumnError(e.Column, null); } else { e.Row.SetColumnError(e.Column, sResult); } break; } } private void PLAN_LIST_Bind(int PLAN_ID) { //数据源属性 this.gridPlanList.U_Clear(); this.gridPlanList.U_WindowName = this.GetType().Name; this.gridPlanList.U_TableName = "V_PLAN_LIST"; this.gridPlanList.U_XmlTableName = "V_PLAN_LIST"; this.gridPlanList.U_Fields = "*"; this.gridPlanList.U_Where = string.Format("PLAN_ID ={0}", PLAN_ID); this.gridPlanList.U_OrderField = "PLAN_LIST_ID"; this.gridPlanList.U_AllowChecked = true; this.gridPlanList.U_AllowOperatData = false; this.gridPlanList.U_AllowShowPage = false; //拆分列属性 this.gridPlanList.U_SplitPropertyType = "GOODS_TYPE"; this.gridPlanList.U_SplitGroupColumn = "GOODS_TYPE_ID"; this.gridPlanList.U_SplitPropertyColumn = "GOODS_PROPERTY"; this.gridPlanList.U_SplitGroupHeader = "GOODS_TYPE.GOODS_TYPE_NAME"; //明细属性 //this.gridPlanList.U_DetailTableName = "PLAN_DETAIL"; //this.gridPlanList.U_DetailRelatvieColumn = "PLAN_LIST_ID"; try { this.gridPlanList.U_InitControl(); } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } private void StorageListBind(string QueryWhere) { this.ucStorageGroup.U_WindowName = this.GetType().Name; this.ucStorageGroup.U_TableName = "V_STORAGE_LIST"; this.ucStorageGroup.U_XmlTableName = "V_STORAGE_LIST"; //this.ucStorageGroup.U_AppendFieldStyles = this.GetColumnDescriptionList(); this.ucStorageGroup.U_TotalColumnName = "STORAGE_LIST_QUANTITY"; this.ucStorageGroup.U_OrderField = "STORAGE_LIST_ID"; this.ucStorageGroup.U_Where = QueryWhere; //this.ucStorageGroup.U_Where = string.Format("STOCK_BARCODE='{0}' AND AREA_TYPE= 'XuNiKu'", txtStockBarCode.Text); this.ucStorageGroup.U_AllowOperatData = false; this.ucStorageGroup.U_AllowChecked = true; this.ucStorageGroup.U_AllowShowPage = true; //拆分列属性 this.ucStorageGroup.U_SplitPropertyType = "GOODS_TYPE"; this.ucStorageGroup.U_SplitGroupColumn = "GOODS_TYPE_ID"; this.ucStorageGroup.U_SplitGroupHeader = "GOODS_TYPE.GOODS_TYPE_NAME"; this.ucStorageGroup.U_SplitPropertyColumn = "GOODS_PROPERTY"; this.ucStorageGroup.U_InitControl(); this.Register_DataTable_Event(); } private void WrapPanel_Click(object sender, RoutedEventArgs e) { Button btn = e.OriginalSource as Button; if (btn != null) { switch (btn.Name) { case "btnConfirm": this.CreateTask(); break; case "btnQuery": this.Query(); break; } } } /// /// 创建输送任务 /// private void CreateTask() { bool boolResult = true; string strResult = string.Empty; List listMANAGE_LIST = null; try { if (!this.ucManagePosition.U_CHECK_WAREHOUSE()) return; listDataRowView = this.ucStorageGroup.U_GetCheckedDataRows(); if (listDataRowView.Length == 0) { MainApp._MessageDialog.Show(Enum.MessageConverter.SelectCount); return; } this.ucStorageGroup.U_EndCurrentEdit(); //判断数据是否合法 if (this.ucStorageGroup.U_DataSource.HasErrors) { MainApp._MessageDialog.Show(Enum.MessageConverter.Data); return; } //获得列表 IDictionary dicStack = this.GetPalletKeyValuePair(listDataRowView); //判断是否选中移库记录 if (dicStack.Count == 0) { MainApp._MessageDialog.Show(Enum.MessageConverter.CheckStack); return; } DataRowView[] drvPLAN_LIST = this.gridPlanList.U_GetCheckedDataRows(); if (drvPLAN_LIST.Length == 0) { MainApp._MessageDialog.Show(Enum.MessageConverter.SelectCount); return; } List listPLAN_LIST = new SiaSun.LMS.Common.CloneObjectValues().GetListFromDataTable(gridPlanList.U_DataSource, null); //List listMANAGE_LIST = new SiaSun.LMS.Common.CloneObjectValues().GetListFromDataTable(listDataRowView.Cast().ToArray(), null); if (MainApp._MessageDialog.ShowDialog(Enum.MessageConverter.ConfirmCreateTask, this.Title) == Sid.Windows.Controls.TaskDialogResult.Ok) { //获得所有的选定的条码 foreach (KeyValuePair stackCell in dicStack) { //获得起始位置 int intStartPositionID = stackCell.Value; var value_ceLl_id = from v in listDataRowView where v["CELL_ID"].ToString() ==stackCell.Value.ToString() && Convert.ToUInt32(v["MANAGE_LIST_QUANTITY"]) >0 select v; boolResult = MainApp._I_ManageService.MANAGE_LIST_CREATE(intStartPositionID, out listMANAGE_LIST, out strResult); SiaSun.LMS.Model.MANAGE_MAIN mMANAGE_MAIN = new Model.MANAGE_MAIN(); mMANAGE_MAIN.MANAGE_TYPE_CODE = mMANAGE_TYPE.MANAGE_TYPE_CODE.TrimEnd(); mMANAGE_MAIN.PLAN_ID = intPlanID; mMANAGE_MAIN.STOCK_BARCODE = this.ucManagePosition.U_STOCK_BARCODE; mMANAGE_MAIN.CELL_MODEL = this.ucManagePosition.U_CELL_MODEL; mMANAGE_MAIN.START_CELL_ID = intStartPositionID; mMANAGE_MAIN.END_CELL_ID = this.ucManagePosition.U_END_POSITION_ID; 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.WaitingSend.ToString(); mMANAGE_MAIN.MANAGE_LEVEL = string.Empty; mMANAGE_MAIN.MANAGE_REMARK = string.Empty; boolResult = MainApp._I_BaseService.Invoke(mMANAGE_TYPE.MANAGE_TYPE_CLASS.TrimEnd(), "ManageCreate", new object[] { mMANAGE_MAIN, listPLAN_LIST, listMANAGE_LIST, true, this.ucManagePosition.U_AutoDownloadControlTask, this.ucManagePosition.U_AutoCompleteTask }, out strResult); //判断结果 if (!boolResult) { break; } else { ucStorageGroup.U_Update(); gridPlanList.U_Update(); } } MainApp._MessageDialog.ShowResult(boolResult, strResult); this.ucManagePosition.U_Refresh(); } } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } ///// ///// 获得托盘集合列表 ///// private IDictionary GetPalletKeyValuePair(DataRowView[] listDataRowView) { IDictionary dicStack = new Dictionary(); foreach (DataRowView rowView in listDataRowView) { string stack = rowView["STOCK_BARCODE"].ToString(); if (stack != string.Empty) { //获得货位编号 //SiaSun.LMS.Model.WH_CELL mWH_CELL = (Model.WH_CELL)MainApp._I_BaseService.GetModel("WH_CELL_SELECT_BY_ID", Convert.ToInt32(rowView["CELL_ID"])).RequestObject; if (!dicStack.ContainsKey(stack)) { dicStack.Add(stack, Convert.ToInt32(rowView["CELL_ID"])); } } } return dicStack; } private void Query() { DataRowView[] checkDataRowView = this.gridPlanList.U_GetCheckedDataRows(); if (checkDataRowView.Length == 0) { MainApp._MessageDialog.Show(Enum.MessageConverter.SelectCount); return; } this.ucManagePosition.U_Refresh(); string sPLAN_LIST_ID = string.Empty; string poNo = string.Empty;//批次 foreach (DataRowView drv in checkDataRowView) { sPLAN_LIST_ID += drv["PLAN_LIST_ID"].ToString() + ","; poNo += drv["GOODS_PROPERTY1"].ToString() + ","; } sPLAN_LIST_ID = sPLAN_LIST_ID.TrimEnd(','); poNo = poNo.TrimEnd(','); string[] strs = poNo.Split(','); string sBATCH_NO = string.Empty; for (int i = 0; i < strs.Length; i++) { if (sBATCH_NO == "") { sBATCH_NO += "'" + strs[i] + "'"; } else { sBATCH_NO += ",'" + strs[i] + "'"; } } string GOODS_PROPERTY = string.Empty; IList lsGOODS_PROPERTY = MainApp._I_GoodsService.GoodsPropertyGetListGoodsTypeID(this.gridPlanList.U_GetSelectedGoodsTypeID()); foreach (SiaSun.LMS.Model.GOODS_PROPERTY mGOODS_PROPERTY in lsGOODS_PROPERTY) { GOODS_PROPERTY += string.Format(" AND ISNULL({0}.{1},{2}.{1}) = {2}.{1}", "PLAN_LIST", mGOODS_PROPERTY.GOODS_PROPERTY_FIELD, "V_STORAGE_LIST"); } string sPLAN = string.Empty; if (this.STORAGE_AREA_TYPE == "XuNiKu") { sPLAN = " (SELECT count(0) FROM PLAN_LIST WHERE V_STORAGE_LIST.GOODS_ID= PLAN_LIST.GOODS_ID {2} {0} AND PLAN_LIST_ID in ({1}))>0"; } else { sPLAN = " (SELECT count(0) FROM PLAN_LIST WHERE V_STORAGE_LIST.GOODS_ID= PLAN_LIST.GOODS_ID {2} {0} AND PLAN_LIST_ID in ({1}) AND V_STORAGE_LIST.GOODS_PROPERTY1 in ({3}) AND V_STORAGE_LIST.RUN_STATUS='Enable' AND V_STORAGE_LIST.CELL_STATUS='Full')>0"; } sWHERE = string.Format(sPLAN, GOODS_PROPERTY, sPLAN_LIST_ID, this.STORAGE_AREA_TYPE == string.Empty ? string.Empty : string.Format(" AND V_STORAGE_LIST.AREA_TYPE = '{0}'", this.STORAGE_AREA_TYPE), sBATCH_NO); this.StorageListBind(sWHERE); } //批量出库 //private void BatchOut() //{ // bool boolResult = true; // string strResult = string.Empty; // decimal OutNum = 0; // try // { // if (this.ucManagePosition.U_END_POSITION_ID == 0) // { // this.ucManagePosition.U_END_POSITION_ID = 190720; // } // //校验填写仓库信息是否合法 // if (!this.ucManagePosition.U_CHECK_WAREHOUSE()) // return; // DataRowView[] checkDataRowView = this.gridPlanList.U_GetCheckedDataRows(); // if (checkDataRowView.Length != 1) // { // strResult = "请先选择一条计划明细!"; // MainApp._MessageDialog.ShowResult(false, strResult); // return; // } // int GoodsTypeID = Convert.ToInt32(checkDataRowView[0].Row["GOODS_ID"]); // int intPLAN_LIST_ID = 0; // intPLAN_LIST_ID = Convert.ToInt32(checkDataRowView[0].Row["PLAN_LIST_ID"].ToString()); // OutNum = Convert.ToInt32(checkDataRowView[0].Row["PLAN_LIST_QUANTITY"]); // string goods_property1 = checkDataRowView[0].Row["GOODS_PROPERTY1"].ToString();//批次 // //检索投料区站台的状态 // DataTable Station = MainApp._I_BaseService.GetList(string.Format(@"select cell_id,cell_code from wh_cell where belong_area ='PutArea' and cell_status ='Nohave' and run_status='Enable'")); // if (Station.Rows.Count == 0) // { // return; // } // EndStationId = Convert.ToInt32(Station.Rows[0]["CELL_ID"]); // EndStationCode = Station.Rows[0]["CELL_CODE"].ToString(); // GoodsTypeID = Convert.ToInt32(dtPlanList.Rows[0]["GOODS_ID"]); // intPLAN_LIST_ID = Convert.ToInt32(dtPlanList.Rows[0]["PLAN_LIST_ID"]); // //OutNum = Convert.ToInt32(dtPlanList.Rows[0]["PLAN_LIST_QUANTITY"]); // string goods_property1 = dtPlanList.Rows[0]["GOODS_PROPERTY1"].ToString();//批次 // DataTable StorageList = this.GetList(string.Format(@"select top 1 * from v_storage_list where goods_id={0} // and goods_property1='{1}' and cell_status='Full' and run_status='Enable' // and device_code in (select start_device from IO_CONTROL_ROUTE where // end_device='{2}' and control_route_type=2 and control_route_status=1) // order by cell_fork_type desc, entry_time", // GoodsTypeID, goods_property1, EndStationCode)); // if (StorageList.Rows.Count == 0) // { // return bResult; // } // //Model.SYS_USER mSYS_USER = new SYS_USER(); // //mSYS_USER.USER_NAME = "Auto"; // int START_CELL_ID = Convert.ToInt32(StorageList.Rows[0]["CELL_ID"]); // string STOCK_BARCODE = StorageList.Rows[0]["STOCK_BARCODE"].ToString(); // bResult = this.ManageCreate(null, intPLAN_LIST_ID, "ManageOut", STOCK_BARCODE, START_CELL_ID, EndStationId, false, true, false, out sResult); // if (bResult) // { // Model.WH_CELL wH_CELL = this._P_WH_CELL.GetModel(EndStationId); // if (wH_CELL != null) // { // wH_CELL.RUN_STATUS = "Seleted"; // this._P_WH_CELL.Update(wH_CELL); // } // sResult = string.Format("自动下达到投料区的任务成功") + sResult; // AddLog(sResult); // } // else // { // sResult = "自动下达到投料区的任务失败" + sResult; // } // if (boolResult) // { // MainApp._MessageDialog.ShowResult(boolResult, strResult); // this.ucStorageGroup.U_InitControl(); // } // else // { // MainApp._MessageDialog.ShowResult(boolResult, strResult); // } // //boolResult = MainApp._I_CellService.CellOutBantch(intPlanID, sWHERE, OutNum, MainApp._USER.USER_NAME, out strResult); // } // catch (Exception ex) // { // MainApp._MessageDialog.ShowException(ex); // } //} } }