989 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			989 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | 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.Logical; | |||
|  | 
 | |||
|  | 
 | |||
|  | namespace DeiNiu.wms.win | |||
|  | { | |||
|  |     public partial class LocationmgrForm : BasicRibbonForm | |||
|  |     { | |||
|  | 
 | |||
|  |         lWmslocation lwmsLoc = new lWmslocation(); | |||
|  |         Wmslocation loc = new Wmslocation(); | |||
|  |         //  lWmslocation lgt = new lWmslocation(); | |||
|  |         private string fieldName = Wmslocation.fields.locationId.ToString(); | |||
|  |         | |||
|  |         private string lastQuery = ""; | |||
|  |         private DataTable dt; | |||
|  |         private int selectedRowIndex = -1; | |||
|  |         private bool isAdding = true; | |||
|  |         private LocStructs locs; | |||
|  |         //    private List<Wmslocation> selectedLocations; | |||
|  |         private List<int> selectedIds; | |||
|  |         public LocationmgrForm() | |||
|  |         { | |||
|  |             InitializeComponent(); | |||
|  |             initialControls(); | |||
|  |             //    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 = { }; | |||
|  | 
 | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         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 = 200;//每页行数   | |||
|  |             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; | |||
|  |         } | |||
|  |         //显示行的序号     | |||
|  |         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 myCol1 = new GridColumn() { Caption = "货位编码", Visible = true, FieldName = fieldName, MinWidth = 100 }; | |||
|  |             //  GridColumn myCol3 = new GridColumn() { Caption = "长", Visible = true, FieldName = Wmslocation.fields.length.ToString(), MaxWidth = 80 }; | |||
|  |             //GridColumn myCol4 = new GridColumn() { Caption = "宽", Visible = true, FieldName = Wmslocation.fields.width.ToString(), MaxWidth = 80 }; | |||
|  |             // GridColumn myCol5 = new GridColumn() { Caption = "高", Visible = true, FieldName = Wmslocation.fields.height.ToString(), MaxWidth = 80 }; | |||
|  |             // GridColumn myCol12 = new GridColumn() { Caption = "重", 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 myCol11 = new GridColumn() { Caption = "分区", Visible = true, FieldName = Wmslocation.fields.part.ToString() + "Name" }; | |||
|  |             // 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" }; | |||
|  | 
 | |||
|  | 
 | |||
|  |             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(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(myCol11); | |||
|  |             this.gridView1.Columns.Add(myCol14); | |||
|  |              * */ | |||
|  |             // gridView1.OptionsView.ColumnAutoWidth = false; | |||
|  |             gridView1.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 | |||
|  | 
 | |||
|  |         /// <summary>   | |||
|  |         /// loading data | |||
|  |         /// </summary>   | |||
|  |         private int loadData() | |||
|  |         { | |||
|  |             //this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView; | |||
|  |             try | |||
|  |             { | |||
|  | 
 | |||
|  | 
 | |||
|  |                 showWaitForm(); | |||
|  |                 string query = ""; | |||
|  | 
 | |||
|  | 
 | |||
|  |                 if (isNewLocationQuery) | |||
|  |                 { | |||
|  |                     query = (this.txtWarehouseQuery.Text.Trim().Length == 0 ? "" : string.Format("{0} =#'{1}';", Wmslocation.fields.warehouse.ToString(), txtWarehouseQuery.Text.Trim())) | |||
|  |                              | |||
|  |                              + (this.comport.SelectedIndex == -1 ? "" : string.Format("{0} =#'{1}';", Wmslocation.fields.port.ToString(), this.comport.SelectedIndex + 1)) | |||
|  | 
 | |||
|  |                              + (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()))) | |||
|  | 
 | |||
|  |                              ; | |||
|  |                 } | |||
|  |                 else | |||
|  | 
 | |||
|  | 
 | |||
|  |                     query = txtLocationId.Text.Trim().Length > 6 ? string.Format("{0} =#'{1}';", Wmslocation.fields.locationId.ToString(), filtRiskChar(txtLocationId.Text)) : | |||
|  | 
 | |||
|  |                                  (this.txtWarehouseQuery.Text.Trim().Length == 0 ? "" : string.Format("{0} =#'{1}';", Wmslocation.fields.warehouse.ToString(), txtWarehouseQuery.Text.Trim())) | |||
|  | 
 | |||
|  |                                   + (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()))) | |||
|  | 
 | |||
|  |                                   + (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.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 = lwmsLoc.Query(null, query, start, end); | |||
|  | 
 | |||
|  |                 dt = ds.Tables[0]; | |||
|  |                 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; | |||
|  | 
 | |||
|  |                 dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; | |||
|  |                 this.gridControl1.DataSource = dt.DefaultView; | |||
|  |                 initialDataGridColumns(); | |||
|  |                 //update selected row index to the last updated one. | |||
|  |                 if (loc.ID > 0) | |||
|  |                 { | |||
|  | 
 | |||
|  |                     DataRow dr = dt.Rows.Find(loc.ID); | |||
|  |                     if (dr != null) | |||
|  |                     { | |||
|  |                         selectedRowIndex = dt.Rows.IndexOf(dr); | |||
|  |                     } | |||
|  | 
 | |||
|  |                     if (selectedRowIndex > 0 && dt.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; | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         /// <summary>   | |||
|  |         /// 分页控件产生的事件   | |||
|  |         /// </summary>   | |||
|  |         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) | |||
|  |         { | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |         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 || dt.Rows.Count <= selectedRowIndex) | |||
|  |             { | |||
|  |                 MessageBox.Show("请在列表里选择数据"); | |||
|  |                 return false; | |||
|  |             } | |||
|  |             // DataRow currentRow = dt.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 && dt.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(); | |||
|  | 
 | |||
|  |                 lwmsLoc.addLocations(locs); | |||
|  | 
 | |||
|  |                 // 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 LocStructs(); | |||
|  |                 //   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; | |||
|  |                 locs.goodsType = ((Node)this.comGoodType.SelectedItem).ID; | |||
|  |                 //locs.whVolume= ((Node)this.comWhVoType.SelectedItem).ID; | |||
|  |                 locs.whVoltype = 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.operater = LoginInfo.UserId; | |||
|  |                 //    locs.warehouseName = ((Node)comWarehouse.SelectedItem).name; | |||
|  | 
 | |||
|  |                 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; | |||
|  |                 */ | |||
|  |             } | |||
|  |             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(dt); | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         void printLocations(DataTable dt) | |||
|  |         {  | |||
|  |         } | |||
|  | 
 | |||
|  |         private void bbPrint_ItemClick(object sender, ItemClickEventArgs e) | |||
|  |         { | |||
|  |             printLocations(dt); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void LocationmgrForm_FormClosing(object sender, FormClosingEventArgs e) | |||
|  |         { | |||
|  |             //  client.Close(); | |||
|  |         } | |||
|  | 
 | |||
|  |         private bool getCurrentObjects() | |||
|  |         { | |||
|  |             int[] selectedRows = gridView1.GetSelectedRows(); | |||
|  |             // selectedLocations = new List<Wmslocation>(); | |||
|  | 
 | |||
|  |             selectedIds = new List<int>(); | |||
|  | 
 | |||
|  |             foreach (int i in selectedRows) | |||
|  |             { | |||
|  |                 DataRow currentRow = dt.Rows[i]; | |||
|  | 
 | |||
|  |                 selectedIds.Add(Convert.ToInt32(currentRow["ID"].ToString())); | |||
|  | 
 | |||
|  |             } | |||
|  |             if (selectedRows.Length == 0) | |||
|  |             { | |||
|  |                 showErrorMsg("请至少选择一条数据"); | |||
|  |                 return false; | |||
|  |             } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |             DialogResult r = MessageBox.Show(string.Format("确定要更新选中的{0}条货位信息吗?", selectedRows.Length), "确认修改", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); | |||
|  | 
 | |||
|  |             return r == DialogResult.Yes; | |||
|  | 
 | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |          | |||
|  | 
 | |||
|  | 
 | |||
|  |          | |||
|  | 
 | |||
|  |         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) | |||
|  |         { | |||
|  |             try | |||
|  |             { | |||
|  |                 // lcgSetup.Expanded = false; | |||
|  |             } | |||
|  |             catch (Exception er) | |||
|  |             { | |||
|  |                 showErrorMsg(er.Message); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         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-81之间的整数"); | |||
|  |                         return; | |||
|  |                     } | |||
|  | 
 | |||
|  |                     locs = new LocStructs(); | |||
|  |                     locs.elabId = labelId; | |||
|  |                     locs.elabAddress = address; | |||
|  |                     locs.operater = LoginInfo.UserId; | |||
|  | 
 | |||
|  | 
 | |||
|  |                     if (lwmsLoc.updateLocationLabelId(selectedIds.ToArray(), locs)) | |||
|  |                     { | |||
|  |                         MessageBox.Show("更新成功!"); | |||
|  |                         query(); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         closeWaitForm(); | |||
|  |                         showErrorMsg("更新失败!"); | |||
|  |                     } | |||
|  |                     //  client.Close(); | |||
|  |                 } | |||
|  |                 catch (Exception er) | |||
|  |                 { | |||
|  |                     closeWaitForm(); | |||
|  |                     showErrorMsg(er.Message); | |||
|  |                 } | |||
|  |                 finally | |||
|  |                 { | |||
|  | 
 | |||
|  |                     closeWaitForm(); | |||
|  | 
 | |||
|  |                 } | |||
|  | 
 | |||
|  | 
 | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void bbiExport_ItemClick(object sender, ItemClickEventArgs e) | |||
|  |         { | |||
|  |             exportExcel("" ,gridView1); | |||
|  |         } | |||
|  | 
 | |||
|  |         private void bbiImport_ItemClick(object sender, ItemClickEventArgs e) | |||
|  |         { | |||
|  |             importExcel(); | |||
|  |             query(); | |||
|  |         } | |||
|  | 
 | |||
|  |         protected override void FillDataToDs(DataRow dr) //string itemid, string itemplu, string itemName) | |||
|  |         { | |||
|  |             string locationId = string.Empty; | |||
|  |             string labelId = string.Empty; | |||
|  |             string address = string.Empty; | |||
|  |             string port = string.Empty; | |||
|  | 
 | |||
|  |             if (dr["货位"].ToString().Trim() != string.Empty) | |||
|  |                 locationId = dr["货位"].ToString().Trim(); | |||
|  |             if (dr["标签ID"].ToString().Trim() != string.Empty) | |||
|  |                 labelId = dr["标签ID"].ToString().Trim(); | |||
|  |             else | |||
|  |                 labelId = " "; | |||
|  |             if (dr["坐标"].ToString().Trim() != string.Empty) | |||
|  |                 address = dr["坐标"].ToString().Trim(); | |||
|  |             if (dr["端口"].ToString().Trim() != string.Empty) | |||
|  |                 port = dr["端口"].ToString().Trim(); | |||
|  | 
 | |||
|  |             DataRow[] rows = dt.Select(string.Format("locationId='{0}'", locationId)); | |||
|  |             if (rows.Length == 0) | |||
|  |             { | |||
|  |                 if (locationId.Trim() != string.Empty && labelId.Trim() != string.Empty && address != string.Empty) | |||
|  |                 { | |||
|  | 
 | |||
|  |                     Wmslocation loc = new Wmslocation(); | |||
|  |                     loc.locationId = locationId; | |||
|  |                     loc.elabId = Convert.ToInt16(labelId); | |||
|  |                     loc.elabAddress = Convert.ToInt16(address); | |||
|  |                     loc.port = Convert.ToInt16(port); | |||
|  |                     loc.Add(); | |||
|  | 
 | |||
|  |                 } | |||
|  |             } | |||
|  |                 else if (rows.Length > 0) | |||
|  |                 { | |||
|  |                     Wmslocation loc = new Wmslocation(rows[0]); | |||
|  |                     loc.elabId = Convert.ToInt16(labelId); | |||
|  |                     loc.elabAddress = Convert.ToInt16(address); | |||
|  |                     loc.port = Convert.ToInt16(port); | |||
|  |                     loc.Update(); | |||
|  | 
 | |||
|  | 
 | |||
|  |                 } | |||
|  |              | |||
|  |         } | |||
|  | 
 | |||
|  |         private void btnDel_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (getCurrentObjects()) | |||
|  |             { | |||
|  |                 showWaitForm(); | |||
|  |                 try | |||
|  |                 { | |||
|  |                     int cnt = lwmsLoc.deleteLocations(selectedIds.ToArray()); | |||
|  | 
 | |||
|  |                     if (cnt > 0) | |||
|  |                     { | |||
|  |                         MessageBox.Show(string.Format("成功删除{0}条记录", cnt)); | |||
|  |                         query(); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         closeWaitForm(); | |||
|  |                         showErrorMsg("删除失败!"); | |||
|  |                     } | |||
|  |                     //client.Close(); | |||
|  | 
 | |||
|  |                 } | |||
|  |                 catch (Exception er) | |||
|  |                 { | |||
|  |                     closeWaitForm(); | |||
|  |                     showErrorMsg(er.Message); | |||
|  |                 } | |||
|  |                 finally | |||
|  |                 { | |||
|  | 
 | |||
|  |                     closeWaitForm(); | |||
|  | 
 | |||
|  |                 } | |||
|  | 
 | |||
|  |             } | |||
|  |         } | |||
|  |     } | |||
|  | } |