using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Windows.Forms; using DevExpress.XtraBars; using DevExpress.XtraGrid.Views.Base; //using DeiNiu.wms.Logical; using DeiNiu.wms.Data; using DevExpress.XtraGrid.Columns; using DeiNiu.wms.win.utils; using System.Threading; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraEditors.DXErrorProvider; using DeiNiu.wms.Data.Model; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; using DeiNiu.Utils; using DeiNiu.wms.win.utils.print; using DeiNiu.wms.win.ServiceReferenceStockLocation; namespace DeiNiu.wms.win { public partial class LocationmgrForm : BasicRibbonForm { WmsLocation loc = new WmsLocation(); // lWmslocation lgt = new lWmslocation(); private string fieldName = WmsLocation.fields.locationId.ToString(); private string fieldGoodType = WmsLocation.fields.whGoodsType.ToString(); private string lastQuery = ""; // private DataTable dt; private int selectedRowIndex = -1; private bool isAdding = true; private Structs locs; // private List selectedLocations; private List selectedIds; public LocationmgrForm() { InitializeComponent(); try { initialControls(); }catch (Exception er) { showErrorMsg(er); } // loadData(); } #region initialControls private void initialControls() { initialComboBoxes(); initialPagerControls(); initialDataGrid(); initialQueryInput(); swithOperationType(); setValidationRule(); // this.lcgSetup.Expanded = false; } private void initialComboBoxes() { //initial combobox of port this.comport.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; ComboBoxItemCollection coll = comport.Properties.Items; coll.BeginUpdate(); try { for (int i = 1; i <= 20; i++) { coll.Add(i); } } finally { coll.EndUpdate(); } comport.SelectedIndex = 0; this.comPortQuery.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; ComboBoxItemCollection col2 = comPortQuery.Properties.Items; col2.BeginUpdate(); col2.Add("全部"); try { for (int i = 1; i <= 20; i++) { col2.Add(i); } } finally { col2.EndUpdate(); } comPortQuery.SelectedIndex = 0; //initial comboboxedits with dic Node[] nds = { }; DataRow[] drs = Park.getDictionary(true).Select("flag >0"); foreach (DataRow dr in drs) { int flag = Convert.ToInt32(dr["flag"].ToString()); int parentId = Convert.ToInt32(dr["id"].ToString()); DataRow[] drss = Park.getDictionary(false).Select("parentId =" + parentId); switch (flag) { case 1001: initialComboBoxs(this.comGoodType, drss, true); //商品类型 initialComboBoxs(this.comGoodTypeQuery, drss); //商品类型 break; case 2001: initialComboBoxs(this.comWarehouse, drss, false);//库房 initialComboBoxs(this.comWarehouseQuery, drss);//库房 break; case 2005: initialComboBoxs(this.comPart, drss, false);//分区 initialComboBoxs(this.comPartQuery, drss);//分区 break; case 3001: initialComboBoxs(this.comboLines, drss, true);//线路 initialComboBoxs(this.comboLinesQuery, drss);//线路 break; case 2014: initialComboBoxs(this.comABC, drss, true);//abc initialComboBoxs(this.comABCQ, drss);//abc break; /* case 2018: initialComboBoxs(this.comBatch, drss, true);//abc initialComboBoxs(this.comBatchQ, drss);//abc break;*/ } } initialComboBoxs(comBatch, enWhLocBatch, false); initialComboBoxs(comBatchQ, enWhLocBatch, true); initialComboBoxs(comWhType, whType, false); // initialComboBoxs(comWhVoType, whVlo, false); initialComboBoxs(comLocationVolType, locVolType, false); initialComboBoxs(comState, stockState, false); initialComboBoxs(comWhTypeQuery, whType); // initialComboBoxs(comWhVoTypeQuery, whVlo); initialComboBoxs(comLocationVolTypeQuery, locVolType); initialComboBoxs(comStateQuery, stockState); initialComboBoxs(comboOwner, getOwners()); initialComboBoxs(comboOwnerQ, getOwners()); comGoodType.SelectedIndex = 0; comWarehouse.SelectedIndex = 0; comPart.SelectedIndex = 0; // comWhVoType.SelectedIndex = 0; comLocationVolType.SelectedIndex = 0; comGoodTypeQuery.SelectedIndex = 0; comWarehouseQuery.SelectedIndex = 0; comPartQuery.SelectedIndex = 0; // comWhVoTypeQuery.SelectedIndex = 0; comLocationVolTypeQuery.SelectedIndex = 0; comboOwner.SelectedIndex = 0; comboOwnerQ.SelectedIndex = 0; } private void setValidationRule() { dxValidationProvider1.SetValidationRule(comWarehouseQuery, ValidationRules.notEmptyValidationRule); //txtGoodType.Properties.MaxLength = 40; //txtGoodDesc.Properties.MaxLength = 250; //textEdit1.Properties.MaxLength = txtGoodType.Properties.MaxLength; } private void initialQueryInput() { } private void initialPagerControls() { pager1.MaximumSize = new Size(0, 20); pager1.EventPaging += new DeiNiu.Controls.pager.EventPagingHandler(pager_EventPaging); #region DataGridView与Pager控件绑定 this.pager1.PageCurrent = 1;//当前页为第一页 pager1.PageSize = Utils.WmsConstants.PAGER_SIZE;//每页行数 this.pager1.Bind();//绑定 #endregion } private void initialDataGrid() { this.gridView1.OptionsBehavior.AutoPopulateColumns = false; this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus; this.gridView1.OptionsBehavior.Editable = false; this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false; this.gridView1.FocusedRowObjectChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventHandler(this.gridView1_FocusedRowObjectChanged); this.gridView1.DataSourceChanged += new System.EventHandler(this.gridView1_DataSourceChanged); //show line number this.gridView1.IndicatorWidth = 40; this.gridView1.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView1_CustomDrawRowIndicator); gridView1.CustomColumnDisplayText += gridView_CustomColumnDisplayText; this.gridView2.IndicatorWidth = 30; this.gridView2.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(gridView1_CustomDrawRowIndicator); gridView2.CustomColumnDisplayText += gridView_CustomColumnDisplayText; initialDataGridColumns(); GridCheckEdit(gridView1, CheckBoxField, 50); } //显示行的序号 private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } private void initialDataGridColumns() { setupGridView(gridView1, true); // gridviewGoodsType.PopulateColumns(); gridView1.Columns.Clear(); // gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]); GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" }; myCol0.Visible = false; this.gridView1.Columns.Add(myCol0); GridColumn colChk = new GridColumn() { Caption = CheckBoxField, Visible = true, FieldName = CheckBoxField }; this.gridView1.Columns.Add(colChk); GridColumn myCol1 = new GridColumn() { Caption = "货位编码", Visible = true, FieldName = fieldName, MinWidth = 120 }; GridColumn myCol3 = new GridColumn() { Caption = "长cm", Visible = true, FieldName = WmsLocation.fields.length.ToString(), MaxWidth = 80 }; GridColumn myCol4 = new GridColumn() { Caption = "宽cm", Visible = true, FieldName = WmsLocation.fields.width.ToString(), MaxWidth = 80 }; GridColumn myCol5 = new GridColumn() { Caption = "高cm", Visible = true, FieldName = WmsLocation.fields.height.ToString(), MaxWidth = 80 }; GridColumn myCol12 = new GridColumn() { Caption = "重kg", Visible = true, FieldName = WmsLocation.fields.weight.ToString(), MaxWidth = 80 }; GridColumn myCol2 = new GridColumn() { Caption = "货物类别", Visible = true, FieldName = WmsLocation.fields.goodsType.ToString() + "Name" }; GridColumn myCol6 = new GridColumn() { Caption = "库房分类", Visible = true, FieldName = WmsLocation.fields.whType.ToString() }; GridColumn myCol7 = new GridColumn() { Caption = "库房容积", Visible = true, FieldName = WmsLocation.fields.whVolType.ToString() }; GridColumn myCol71 = new GridColumn() { Caption = "货位容积", Visible = true, FieldName = WmsLocation.fields.volType.ToString() }; GridColumn myCol8 = new GridColumn() { Caption = "电子标签", Visible = true, FieldName = WmsLocation.fields.elabId.ToString() }; GridColumn myCol9 = new GridColumn() { Caption = "标签货位", Visible = true, FieldName = WmsLocation.fields.elabAddress.ToString() }; GridColumn myCol10 = new GridColumn() { Caption = "端口", Visible = true, FieldName = WmsLocation.fields.port.ToString(), MinWidth = 20 }; GridColumn myCol111 = new GridColumn() { Caption = "库房分区", Visible = true, FieldName = "whouseName" }; GridColumn myCol11 = new GridColumn() { Caption = "货位分区", Visible = true, FieldName = WmsLocation.fields.part.ToString() + "Name2" }; GridColumn myCol13 = new GridColumn() { Caption = "状态", Visible = true, FieldName = WmsLocation.fields.state.ToString() }; GridColumn myCol14 = new GridColumn() { Caption = "线路", Visible = true, FieldName = WmsLocation.fields.transLine.ToString() + "Name" }; GridColumn myCol15 = new GridColumn() { Caption = "ABC", Visible = true, FieldName = WmsLocation.fields.ABC.ToString() + "Name" }; GridColumn myCol16 = new GridColumn() { Caption = "负责人", Visible = true, FieldName = "em_name" }; GridColumn myCol17 = new GridColumn() { Caption = "仓储策略", Visible = true, FieldName = WmsLocation.fields.storeType.ToString() }; GridColumn myCol161 = new GridColumn() { Caption = "库容放大倍数", Visible = true, FieldName = WmsLocation.fields.scaleFactor.ToString() }; GridColumn myCol18 = new GridColumn() { Caption = "称重出库", Visible = true, FieldName = WmsLocation.fields.isWeightSeeds.ToString() }; this.gridView1.Columns.Add(myCol111); this.gridView1.Columns.Add(myCol11); this.gridView1.Columns.Add(myCol1); this.gridView1.Columns.Add(myCol13); this.gridView1.Columns.Add(myCol8); this.gridView1.Columns.Add(myCol9); this.gridView1.Columns.Add(myCol10); this.gridView1.Columns.Add(myCol2); this.gridView1.Columns.Add(myCol17); this.gridView1.Columns.Add(myCol6); this.gridView1.Columns.Add(myCol7); this.gridView1.Columns.Add(myCol71); this.gridView1.Columns.Add(myCol3); this.gridView1.Columns.Add(myCol4); this.gridView1.Columns.Add(myCol5); this.gridView1.Columns.Add(myCol12); this.gridView1.Columns.Add(myCol14); this.gridView1.Columns.Add(myCol15); this.gridView1.Columns.Add(myCol16); this.gridView1.Columns.Add(myCol161); this.gridView1.Columns.Add(myCol18); // gridView1.OptionsView.ColumnAutoWidth = false; gridView1.BestFitColumns(); myCol1 = new GridColumn() { Caption = "商品类型", Visible = true, FieldName = WmsLocation.fields.goodsType.ToString(), MinWidth = 80 }; myCol2 = new GridColumn() { Caption = "货位", Visible = true, FieldName = WmsLocation.fields.volType.ToString() }; myCol3 = new GridColumn() { Caption = "分类", Visible = true, FieldName = WmsLocation.fields.whType.ToString() }; myCol4 = new GridColumn() { Caption = "库房", Visible = true, FieldName = WmsLocation.fields.warehouse.ToString() }; myCol5 = new GridColumn() { Caption = "状态", Visible = true, FieldName = WmsLocation.fields.state.ToString() }; myCol6 = new GridColumn() { Caption = "已用", Visible = true, FieldName = "usedCount" }; myCol7 = new GridColumn() { Caption = "总量", Visible = true, FieldName = "totalCnt" }; myCol8 = new GridColumn() { Caption = "百分比", Visible = true, FieldName = "usedPercent" }; setupGridView(gridView2, true); gridView2.Columns.Clear(); this.gridView2.Columns.Add(myCol1); this.gridView2.Columns.Add(myCol2); this.gridView2.Columns.Add(myCol3); this.gridView2.Columns.Add(myCol4); this.gridView2.Columns.Add(myCol5); this.gridView2.Columns.Add(myCol6); this.gridView2.Columns.Add(myCol7); this.gridView2.Columns.Add(myCol8); gridView2.BestFitColumns(); gridView1.Focus(); //自动列宽 //gridView1.OptionsView.ColumnAutoWidth = false; //this.gridView1.BestFitColumns(); //this.gridView1.Columns[2].MinWidth = 500; //this.gridView1.Columns[1].BestFit(); //for (int I = 0; I < gridView1.Columns.Count; I++) //{ // this.gridView1.Columns[I].BestFit() //} } #endregion /// /// loading data /// private int loadData() { //this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView; try { showWaitForm(); string query = ""; if (isNewLocationQuery) { query = (this.comWarehouse.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.warehouse.ToString(), ((Node)this.comWarehouse.SelectedItem).ID)) + (this.comState.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.state.ToString(), ((Colitem)this.comState.SelectedItem).key)) + (this.comWhType.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.whType.ToString(), ((Colitem)this.comWhType.SelectedItem).key)) // + (this.comWhVoType.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", Wmslocation.fields.whVolType.ToString(), ((Colitem)this.comWhVoType.SelectedItem).key)) + (this.comLocationVolType.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.volType.ToString(), ((Colitem)this.comLocationVolType.SelectedItem).key)) + (this.comGoodType.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.goodsType.ToString(), ((Node)this.comGoodType.SelectedItem).ID)) + (this.comPart.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.part.ToString(), ((Node)this.comPart.SelectedItem).ID)) + (this.comboLines.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.transLine.ToString(), ((Node)this.comboLines.SelectedItem).ID)) // + (this.comport.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.port.ToString(), this.comport.SelectedIndex)) + (txtChannelFrom.Text.Trim().Length == -1 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.channel.ToString(), filtRiskChar(txtChannelFrom.Text.Trim()))) + (txtChannelTo.Text.Trim().Length == -1 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.channel.ToString(), filtRiskChar(txtChannelTo.Text.Trim()))) + (txtShelfFrom.Text.Trim().Length == -1 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.shelf.ToString(), filtRiskChar(txtShelfFrom.Text.Trim()))) + (txtShelfTo.Text.Trim().Length == -1 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.shelf.ToString(), filtRiskChar(txtShelfTo.Text.Trim()))) + (txtLayerFrom.Text.Trim().Length == -1 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.layer.ToString(), filtRiskChar(txtLayerFrom.Text.Trim()))) + (txtLayerTo.Text.Trim().Length == -1 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.layer.ToString(), filtRiskChar(txtLayerTo.Text.Trim()))) + (txtColumFrom.Text.Trim().Length == -1 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.col.ToString(), filtRiskChar(txtColumFrom.Text.Trim()))) + (txtColumTo.Text.Trim().Length == -1 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.col.ToString(), filtRiskChar(txtColumTo.Text.Trim()))) + (this.comABC.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.ABC.ToString(), ((Node)this.comABC.SelectedItem).ID)) + (this.comboOwner.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.ownerCode.ToString(), ((Colitem)this.comboOwner.SelectedItem).key)) + (this.comBatch.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.storeType.ToString(), ((Colitem)this.comBatch.SelectedItem).key)) + (txtScale.Text.Trim().Length ==0 ? "" : string.Format("{0} =# {1};", WmsLocation.fields.scaleFactor.ToString(), filtRiskChar(txtScale.Text.Trim()))) + ( string.Format("{0} =# {1};", WmsLocation.fields.isWeightSeeds.ToString(), chkJobCross.Checked?1:0)) ; } else query = txtLocationId.Text.Trim().Length > 6 ? string.Format("{0} =#'{1}';", WmsLocation.fields.locationId.ToString(), filtRiskChar(txtLocationId.Text)) : (this.comWarehouseQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.warehouse.ToString(), ((Node)this.comWarehouseQuery.SelectedItem).ID)) + (this.comStateQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.state.ToString(), ((Colitem)this.comStateQuery.SelectedItem).key)) + (this.comWhTypeQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.whType.ToString(), ((Colitem)this.comWhTypeQuery.SelectedItem).key)) // + (this.comWhVoTypeQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", Wmslocation.fields.whVolType.ToString(), ((Colitem)this.comWhVoTypeQuery.SelectedItem).key)) + (this.comLocationVolTypeQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.volType.ToString(), ((Colitem)this.comLocationVolTypeQuery.SelectedItem).key)) + (this.comGoodTypeQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.goodsType.ToString(), ((Node)this.comGoodTypeQuery.SelectedItem).ID)) + (this.comPartQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.part.ToString(), ((Node)this.comPartQuery.SelectedItem).ID)) + (this.comboLinesQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.transLine.ToString(), ((Node)this.comboLinesQuery.SelectedItem).ID)) + (this.comPortQuery.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.port.ToString(), this.comPortQuery.SelectedIndex)) + (txtChannelFromQ.Text.Trim().Length == 0 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.channel.ToString(), filtRiskChar(txtChannelFromQ.Text.Trim()))) + (txtChannelToQ.Text.Trim().Length == 0 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.channel.ToString(), filtRiskChar(txtChannelToQ.Text.Trim()))) + (txtShelfFromQ.Text.Trim().Length == 0 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.shelf.ToString(), filtRiskChar(txtShelfFromQ.Text.Trim()))) + (txtShelfToQ.Text.Trim().Length == 0 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.shelf.ToString(), filtRiskChar(txtShelfToQ.Text.Trim()))) + (txtLayerFromQ.Text.Trim().Length == 0 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.layer.ToString(), filtRiskChar(txtLayerFromQ.Text.Trim()))) + (txtLayerToQ.Text.Trim().Length == 0 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.layer.ToString(), filtRiskChar(txtLayerToQ.Text.Trim()))) + (txtColumFromQ.Text.Trim().Length == 0 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.col.ToString(), filtRiskChar(txtColumFromQ.Text.Trim()))) + (txtColumToQ.Text.Trim().Length == 0 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.col.ToString(), filtRiskChar(txtColumToQ.Text.Trim()))) + (txtScaleQ.Text.Trim().Length == 0 ? "" : string.Format("{0} =# {1};", WmsLocation.fields.scaleFactor.ToString(), filtRiskChar(txtScaleQ.Text.Trim()))) + (this.txtLbStartIdQuery.Text.Trim().Length == 0 ? "" : string.Format("{0} >=#'{1}';", WmsLocation.fields.elabId.ToString(), filtRiskChar(txtLbStartIdQuery.Text.Trim()))) + (txtLbToIdQuery.Text.Trim().Length == 0 ? "" : string.Format("{0} <=#'{1}';", WmsLocation.fields.elabId.ToString(), filtRiskChar(txtLbToIdQuery.Text.Trim()))) + (this.comABCQ.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.ABC.ToString(), ((Node)this.comABCQ.SelectedItem).ID)) + (this.comboOwnerQ.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.ownerCode.ToString(), ((Colitem)this.comboOwnerQ.SelectedItem).key)) + (this.comBatchQ.SelectedIndex == 0 ? "" : string.Format("{0} =#'{1}';", WmsLocation.fields.storeType.ToString(), ((Colitem)this.comBatchQ.SelectedItem).key)) // + (string.Format("{0} =# {1};", WmsLocation.fields.isWeightSeeds.ToString(), chkJobCrossQ.Checked ? 1 : 0)) ; this.pager1.PageCurrent = lastQuery.Equals(query) ? this.pager1.PageCurrent : 1; //根据查询条件的变化给pager赋值 int start = (pager1.PageSize * (pager1.PageCurrent - 1) + 1); int end = (pager1.PageSize * pager1.PageCurrent); lastQuery = query; DataSet ds = stkLocClient.QueryNodes(Park.getDictionary(false), query, start, end); closeClient();; DtGv = ds.Tables[0]; addCheckField(DtGv);//add checkbox int cnt = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString()); //dt = lgt.Query(query, start, end); //string.IsNullOrEmpty(query) ? lgt.GetGoodType.getAllData(start, end) : lgt.g; DtGv.PrimaryKey = new DataColumn[] { DtGv.Columns["ID"] }; this.gridControl1.DataSource = DtGv.DefaultView; gridView1.BestFitColumns(); DataTable dtPercent = stkLocClient.getLocationsUsedPercent(); gridControl2.DataSource = dtPercent.DefaultView; //update selected row index to the last updated one. if (loc.ID > 0) { DataRow dr = DtGv.Rows.Find(loc.ID); if (dr != null) { selectedRowIndex = DtGv.Rows.IndexOf(dr); } if (selectedRowIndex > 0 && DtGv.Rows.Count > selectedRowIndex) { // gridView1.SelectRow(selectedRowIndex); gridView1.FocusedRowHandle = selectedRowIndex; // gridView1.MakeRowVisible(selectedRowIndex); } //gridView1.FocusedRowHandle = selectedRowIndex; } closeWaitForm(); return cnt;// lgt.getRowCount(query); // return lgt.GetGoodType.QueryCount(); } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } return 0; } /// /// 分页控件产生的事件 /// private int pager_EventPaging(DeiNiu.Controls.pager.EventPagingArg e) { selectedRowIndex = 0; //reset currentRowIndex return loadData(); } private void gridView_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.Column.FieldName == WmsLocation.fields.volType.ToString()) { if (!locVolType.ContainsValue(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = locVolType[display]; } catch { return; } } // e.DisplayText = locVolType.ContainsKey(display) ? locVolType[display] : display+""; } /* else if (e.Column.FieldName == Wmslocation.fields.whVolType.ToString()) { if (!whVlo.ContainsValue(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = whVlo[display]; } catch { return; } } }*/ else if (e.Column.FieldName == WmsLocation.fields.whType.ToString()) { if (!whType.ContainsValue(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = whType[display]; } catch { return; } } } else if (e.Column.FieldName == WmsLocation.fields.state.ToString()) { if (!stockState.ContainsValue(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = stockState[display]; } catch { return; } } } else if (e.Column.FieldName == WmsLocation.fields.storeType.ToString()) { if (!this.enWhLocBatch.ContainsValue(e.DisplayText)) { int display = -100; string disTxt = e.DisplayText; try { display = Convert.ToInt16(e.DisplayText); e.DisplayText = enWhLocBatch[display]; } catch { return; } } } } private void bindDetail() { } private void setDataBack() { } private bool validData() { bool isvalid = dxValidationProvider1.Validate(); // MessageBox.Show("goodtype is " + txtGoodType.Text +", is valid ? " + isvalid); return isvalid; //String gdtype = txtGoodType.Text.Trim(); //if (gdtype.Length == 0) //{ // dxValidationProvider.Validate(); // return false; //} //return true; } private void btnSave_Click(object sender, EventArgs e) { if (!getCurrentObject()) { return; } if (!validData()) { return; } if (true) { MessageBox.Show("没有数据更新"); return; } Thread th = new Thread(new ThreadStart(this.updateLocations)); th.Start(); // btnSave.Enabled = false; } private void updateLocations() { showWaitForm(); //WaitFormService.Show(this); try { //update the goodtype setDataBack(); // lgt.GetGoodType.Update(); //get updated data query();// loadData(); } catch (Exception e) { showErrorMsg(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); // btnSave.Enabled = true; } } private void gridView1_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e) { //clearInputs(); //int a = gridView1.FocusedRowHandle ; //if (a < 0 || gridView1.GetSelectedRows().Length ==0) //{ // return; //} // int selectedHandle; //selectedRowIndex = this.gridView1.GetSelectedRows()[0]; ////MessageBox.Show(this.gridView1.GetRowCellValue(selectedHandle, "id").ToString()); //if (selectedRowIndex < 0) //{ // return; //} //if (isAdding) //{ // return; //} // txtGoodType.Text = this.gridView1.GetRowCellValue(selectedRowIndex, fieldName).ToString(); // txtGoodDesc.Text = this.gridView1.GetRowCellValue(selectedRowIndex, fieldDesc).ToString(); } private void clearInputs() { } private bool getCurrentObject() { if (selectedRowIndex < 0 || DtGv.Rows.Count <= selectedRowIndex) { MessageBox.Show("请在列表里选择数据"); return false; } // DataRow currentRow = DtGv.Rows[selectedRowIndex]; DataRowView dr = (DataRowView)(GetGridViewFilteredAndSortedData(gridView1)[selectedRowIndex]); loc.getModel(dr.Row); return true; } private void gridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) { } private void gridView1_DataSourceChanged(object sender, EventArgs e) { if (selectedRowIndex > 0 && DtGv.Rows.Count > selectedRowIndex) { gridView1.FocusedRowHandle = selectedRowIndex; gridView1.MakeRowVisible(selectedRowIndex); } } private void btnDelete_Click(object sender, EventArgs e) { //if (!getCurrentObject()) //{ // return; //} //MessageBoxButtons messButton = MessageBoxButtons.OKCancel; //DialogResult dr = MessageBox.Show(String.Format("确定要删除 {0} 吗?",lgt.GetGoodType.goodsName), "删除记录", messButton); //if (dr == DialogResult.OK) //{ // lgt.GetGoodType.Delete() ; // lgt.Initialize(); // query();//loadData(); //} } protected void query() { pager1.Bind(); } private void startQuery() { showWaitForm(); try { query();// loadData(); } catch (Exception e) { MessageBox.Show(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); bbQuery.Enabled = true; btnQuery.Enabled = true; } } private void txtQuery_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { query(); } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { swithOperationType(); } private void swithOperationType() { /* isAdding = tabControl1.SelectedIndex == 0; if (isAdding) { clearInputs(); } else { gridView1_FocusedRowObjectChanged(null, null); } btnNew.Enabled = isAdding; btnSave.Enabled = !isAdding; btnDelete.Enabled = !isAdding; }*/ } private void bbQuery_ItemClick(object sender, ItemClickEventArgs e) { //Thread th = new Thread(new ThreadStart(this.queryGoodType)); //th.Start(); this.bbQuery.Enabled = false; startQuery(); } private void bbCreateLocations_ItemClick(object sender, ItemClickEventArgs e) { startLocations(); } void startLocations() { if (!validNewLocations()) { return; } //Thread th = new Thread(new ThreadStart(this.newLocations)); //th.Start(); this.bbCreateLocations.Enabled = false; newLocations(); } bool isNewLocationQuery = false; private void newLocations() { showWaitForm(); try { // setLocs(); stkLocClient.addLocations(locs); closeClient();; // lgt.addLocations(locs); isNewLocationQuery = true; query();// loadData(); isNewLocationQuery = false; // initialize and clear object and inputs, prepare for adding more. // lgt.initialize(); // clearInputs(); } catch (Exception e) { showErrorMsg(e.Message); } finally { // WaitFormService.Close(); closeWaitForm(); this.bbCreateLocations.Enabled = true; } } private bool setLocs() { try { locs = new Structs(); locs.warehouse = ((Node)comWarehouse.SelectedItem).ID; locs.channel1 = Convert.ToInt32(txtChannelFrom.Text); locs.channel2 = Convert.ToInt32(txtChannelTo.Text); locs.shelf1 = Convert.ToInt32(this.txtShelfFrom.Text); locs.shelf2 = Convert.ToInt32(txtShelfTo.Text); locs.layer1 = Convert.ToInt32(this.txtLayerFrom.Text); locs.layer2 = Convert.ToInt32(txtLayerTo.Text); locs.col1 = Convert.ToInt32(this.txtColumFrom.Text); locs.col2 = Convert.ToInt32(txtColumTo.Text); // locs.eleid2 = Convert.ToInt32(this.txtLabelTo.Text); locs.port = this.comport.SelectedIndex + 1; locs.whType = ((Colitem)this.comWhType.SelectedItem).key; // ((Node)this.comWhType.SelectedItem).ID; //locs.whGoodsType = ((Node)this.comw.SelectedItem).ID; if (comGoodType.SelectedIndex > 0) { locs.goodsType = ((Node)this.comGoodType.SelectedItem).ID; } //locs.whVolume= ((Node)this.comWhVoType.SelectedItem).ID; locs.whVoltype = 0;// this.comWhVoType.SelectedIndex; locs.volType = this.comLocationVolType.SelectedIndex; if (comboLines.SelectedIndex > 0) { locs.transLine = ((Node)this.comboLines.SelectedItem).ID; } locs.whVoltype = locs.whVoltype > 0 ? locs.whVoltype : 0; locs.volType = locs.volType > 0 ? locs.volType : 0; locs.part = ((Node)this.comPart.SelectedItem).ID; locs.partCode = ((Node)this.comPart.SelectedItem).value; //货位货区编码 locs.operater = LoginInfo.UserId; locs.warehouseName = ((Node)comWarehouse.SelectedItem).name; locs.state = ((Colitem)this.comState.SelectedItem).key; locs.elecol = Convert.ToInt32(this.txtLabelColum.Text); locs.elelayer = Convert.ToInt32(this.txtLabelLayer.Text); locs.eleid1 = Convert.ToInt32(this.txtLbStartId.Text); locs.height = txtHeight.Text.Length > 0 ? Convert.ToDecimal(txtHeight.Text) : 0; locs.width = txtWidth.Text.Length > 0 ? Convert.ToDecimal(txtWidth.Text) : 0; locs.length = txtLength.Text.Length > 0 ? Convert.ToDecimal(txtLength.Text) : 0; locs.weight = txtWeight.Text.Length > 0 ? Convert.ToDecimal(txtWeight.Text) : 0; if (comABC.SelectedIndex > 0) { locs.ABC = ((Node)this.comABC.SelectedItem).ID; } if (comboOwner.SelectedIndex > 0) { locs.ownerCode = ((Colitem)this.comboOwner.SelectedItem).key+""; } if (comBatch.SelectedIndex > 0) { locs.storeType = ((Colitem)this.comBatch.SelectedItem).key; } } catch { showErrorMsg("请检查输入的数字是否正确"); return false; } return true; } private bool validNewLocations() { return setLocs(); } private void comWarehouse_Properties_CustomDisplayText(object sender, CustomDisplayTextEventArgs e) { } private void simpleButton5_Click(object sender, EventArgs e) { } private void btnQuery_Click(object sender, EventArgs e) { this.btnQuery.Enabled = false; startQuery(); } private void btnCreate_Click(object sender, EventArgs e) { startLocations(); } private void btnLock_Click(object sender, EventArgs e) { } private void bbLock_ItemClick(object sender, ItemClickEventArgs e) { } private void simpleButton1_Click(object sender, EventArgs e) { } private void btnPrint_Click(object sender, EventArgs e) { printLocations(DtGv); } void printLocations(DataTable dt) { if (dt == null || dt.Rows.Count == 0) { showErrorMsg("请先查询需要打印的数据,然后才能打印。"); return; } if (string.IsNullOrEmpty(WmsConstants.PRINTER_NAME_CODE)) { showErrorMsg("请先定义本地条码打印机,然后才能打印。"); } MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show(String.Format("确定要打印 {0}个标签吗?", selectedIds.Count), "删除记录", messButton); if (dr == DialogResult.OK) { //lgt.printLocations(dt); string reportName = "wmsLocationCode.rdlc"; DataView dv = dt.DefaultView; string filter = "id in("; foreach (int id in selectedIds) { filter += id + ","; } filter = filter.Substring(0,filter.Length - 1) + ")"; //showErrorMsg(filter); dv.RowFilter = filter; DataTable dt1 = dv.ToTable("dtprint"); /* foreach (DataRow dr1 in dt1.Rows) { dr1["locationId128"] = Util.CreateQRcode(dr1["locationId"].ToString()); } */ BillPrint.Run(dt1, reportName, PrinterType.code); dv.RowFilter = ""; } } private void bbPrint_ItemClick(object sender, ItemClickEventArgs e) { if (!getSelectedLocations()) { return ; } printLocations(DtGv); } private void LocationmgrForm_FormClosing(object sender, FormClosingEventArgs e) { // closeClient();; } private bool getSelectedLocations() { selectedIds = new List(); foreach (DataRow dr in DtGv.Rows) { string v = dr[CheckBoxField].ToString(); bool b = String.IsNullOrEmpty(v) ? false : Convert.ToBoolean(v); if (b) { selectedIds.Add(Convert.ToInt32(dr["ID"].ToString())); } } if (selectedIds.Count == 0) { showErrorMsg("请至少选择一条数据"); return false; } return true; } private bool getCurrentObjects() { if (!getSelectedLocations()) { return false; } DialogResult r = MessageBox.Show(string.Format("确定要更新选中的{0}条货位信息吗?", selectedIds.Count), "确认修改", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); return r == DialogResult.Yes; } private void btnUpdateWh_Click(object sender, EventArgs e) { if (getCurrentObjects() && setWh()) { showWaitForm(); try { if (stkLocClient.updateWhLocations(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } private void btnUpdateSize_Click(object sender, EventArgs e) { if (getCurrentObjects() && setSize()) { showWaitForm(); try { if (stkLocClient.updateSizeLocations(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } bool setWh() { locs = new Structs(); locs.whType = ((Colitem)this.comWhType.SelectedItem).key; // ((Node)this.comWhType.SelectedItem).ID; if (comGoodType.SelectedIndex > 0) { locs.goodsType = ((Node)this.comGoodType.SelectedItem).ID; } // locs.whVoltype = this.comWhVoType.SelectedIndex; locs.volType = this.comLocationVolType.SelectedIndex; locs.part = ((Node)this.comPart.SelectedItem).ID; // locs.whVoltype = locs.whVoltype > 0 ? locs.whVoltype : 0; // locs.volType = locs.volType > 0 ? locs.volType : 0; locs.operater = LoginInfo.UserId; return true; } bool setSize() { locs = new Structs(); try { locs.height = txtHeight.Text.Length > 0 ? Convert.ToDecimal(txtHeight.Text) : 0; locs.width = txtWidth.Text.Length > 0 ? Convert.ToDecimal(txtWidth.Text) : 0; locs.length = txtLength.Text.Length > 0 ? Convert.ToDecimal(txtLength.Text) : 0; locs.weight = txtWeight.Text.Length > 0 ? Convert.ToDecimal(txtWeight.Text) : 0; } catch { showErrorMsg("请设置正确的大小数据"); return false; } locs.operater = LoginInfo.UserId; return true; } private void btnUpdateStatus_Click(object sender, EventArgs e) { if (getCurrentObjects()) { showWaitForm(); try { int status = ((Colitem)this.comState.SelectedItem).key; if (stkLocClient.updateLocationStatus(selectedIds.ToArray(), status)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } //closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } bool setTransLine() { locs = new Structs(); locs.transLine = comboLines.SelectedIndex == 0 ? 0 : ((Node)this.comboLines.SelectedItem).ID; locs.operater = LoginInfo.UserId; return true; } private void btnSaveLine_Click(object sender, EventArgs e) { if (getCurrentObjects() && setTransLine()) { showWaitForm(); try { if (stkLocClient.updateLocationTranLines(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } private void lcgQuery_Showing(object sender, EventArgs e) { } private void lcgSetup_Showing(object sender, EventArgs e) { } private void lcgQuery_CustomButtonChecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { } private void lcgSetup_CustomButtonChecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { } private void lcgQuery_CustomButtonUnchecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { } private void lcgSetup_CustomButtonUnchecked(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e) { try { // lcgQuery.Expanded = false; } catch (Exception er) { showErrorMsg(er.Message); } } private void btnUpdateLable_Click(object sender, EventArgs e) { if (getCurrentObjects()) { showWaitForm(); try { int labelId = Convert.ToInt16(txtLabelId.Text); if (labelId <= 0 || labelId > 9999) { showErrorMsg("标签编号应该在1-9999之间的整数"); return; } int address = Convert.ToInt16(txtPosition.Text); if (address <= 0 || address > 200) { showErrorMsg("标签地址编号应该在1-200之间的整数"); return; } locs = new Structs(); locs.elabId = labelId; locs.elabAddress = address; locs.operater = LoginInfo.UserId; if (stkLocClient.updateLocationLabelId(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er, er.Message); } finally { closeClient();; closeWaitForm(); } } } private void btnUpdateBianhao_Click(object sender, EventArgs e) { if (getCurrentObjects() && setTransLine()) { showWaitForm(); try { if (stkLocClient.updateLocationTranLines(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e) { this.exportExcel(this.gridView1); } bool setABC() { locs = new Structs(); locs.ABC = comABC.SelectedIndex == 0 ? 0 : ((Node)this.comABC.SelectedItem).ID; locs.operater = LoginInfo.UserId; return true; } private void btnUpdateABC_Click(object sender, EventArgs e) { if (getCurrentObjects() && setABC()) { showWaitForm(); try { if (stkLocClient.updateLocationABC(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } bool setOwner() { locs = new Structs(); if (this.comboOwner.SelectedIndex > 0) //插入null or code { locs.ownerCode = ((Colitem)this.comboOwner.SelectedItem).code; } else //插入null or code { locs.ownerCode = string.Empty; } locs.operater = LoginInfo.UserId; return true; } private void btnUpdateOwner_Click(object sender, EventArgs e) { if (getCurrentObjects() && setOwner()) { showWaitForm(); try { if (stkLocClient.updateLocationOwner(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } bool setStoreType() { locs = new Structs(); locs.storeType = ((Colitem)this.comBatch.SelectedItem).key; locs.operater = LoginInfo.UserId; return true; } private void btnUpdteBatch_Click(object sender, EventArgs e) { if (getCurrentObjects() && setStoreType()) { showWaitForm(); try { if (stkLocClient.updateLocationStoreType(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient();; closeWaitForm(); } } } private void btnScale_Click(object sender, EventArgs e) { if (getCurrentObjects() && setScale()) { showWaitForm(); try { if (stkLocClient.updateLocScale(selectedIds.ToArray(), locs)) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient(); ; closeWaitForm(); } } } bool setScale() { locs = new Structs(); try { locs.scale = Convert.ToInt32(txtScale.Text.Trim()); if (locs.scale <= 0) { throw new Exception(); } } catch { showErrorMsg("请输入正整数"); return false; } locs.operater = LoginInfo.UserId; return true; } private void checkEdit1_CheckedChanged(object sender, EventArgs e) { } private void btnPartCross_Click(object sender, EventArgs e) { if (getCurrentObjects() ) { showWaitForm(); try { if (stkLocClient.updateJobCross(selectedIds.ToArray(), chkJobCross.Checked)>0) { MessageBox.Show("更新成功!"); query(); } else { closeWaitForm(); showErrorMsg("更新失败!"); } // closeClient();; } catch (Exception er) { closeWaitForm(); showErrorMsg(er.Message); } finally { closeClient(); ; closeWaitForm(); } } } } }