735 lines
		
	
	
		
			27 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			735 lines
		
	
	
		
			27 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 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.ServiceReferenceGoods;
 | |
| 
 | |
| 
 | |
| namespace DeiNiu.wms.win
 | |
| {
 | |
|     public partial class GoodsStockAutoRepForm : BasicRibbonForm
 | |
|     {
 | |
|         
 | |
|      
 | |
|       //  lWmsGoods lgt = new lWmsGoods();
 | |
|         private string fieldName = WmsLocation.fields.locationId.ToString();
 | |
|         private string fieldGoodType = WmsLocation.fields.whGoodsType.ToString();
 | |
|         private string lastQuery = "";
 | |
|      
 | |
|         string queryStr = ""; 
 | |
|         private DataTable dtDetail;
 | |
|         private int selectedRowIndex = -1;
 | |
|         private string selectedGoodsId;
 | |
|         private int selectedSkuId;
 | |
|         private List<string> selectedGoods = new List<string>();
 | |
| 
 | |
|         public GoodsStockAutoRepForm()
 | |
|         {
 | |
|             InitializeComponent();
 | |
|             initialControls();
 | |
|             //    loadData();
 | |
|         }
 | |
|         #region initialControls
 | |
|         private void initialControls()
 | |
|         { 
 | |
|             layoutControlWaitting.Expanded = true;
 | |
|             initialComboBoxes();
 | |
|             initialPagerControls();
 | |
|             initialDataGrid();
 | |
|             initialQueryInput(); 
 | |
|             setValidationRule();
 | |
|             switchRepPercent();
 | |
|             spRepCnt.Enabled = !chkRecnt.Checked;
 | |
|            
 | |
|         }
 | |
|         private void initialComboBoxes()
 | |
|         {
 | |
|             //initialComboBoxe(comboType, this.stkdiff);
 | |
| 
 | |
|             this.comboState.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
 | |
|  
 | |
|             initialComboBoxs(comboState, this.stockState); 
 | |
|           
 | |
|             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.comboBoGoodsType, drss); //商品类型
 | |
|                         break;
 | |
| 
 | |
|                     case 2001:
 | |
|                         initialComboBoxs(this.comboRep, drss);//库房
 | |
|                         break; 
 | |
|  
 | |
|                     case 2005:
 | |
|                         initialComboBoxs(this.comboBoPart, drss);//分区
 | |
|                         break;
 | |
|                     case 2009:
 | |
|                         initialComboBoxs(this.comboRep, drss);//分区
 | |
|                         break;
 | |
|                 }
 | |
| 
 | |
|             }
 | |
| 
 | |
|           //  initialComboBoxe(this.comboStkType, whType, false);
 | |
| 
 | |
|         
 | |
|    
 | |
|         }
 | |
|       
 | |
|         private void setValidationRule()
 | |
|         {
 | |
|           //  dxValidationProvider.SetValidationRule(comWarehouse, ValidationRules.notEmptyValidationRule);
 | |
|             //txtGoodType.Properties.MaxLength = 40;
 | |
|             //txtGoodDesc.Properties.MaxLength = 250;
 | |
|             //textEdit1.Properties.MaxLength = txtGoodType.Properties.MaxLength;
 | |
|         }
 | |
| 
 | |
|         private void initialQueryInput()
 | |
|         {
 | |
| 
 | |
|         }
 | |
|       
 | |
|         private void initialDataGridColumns(GridView gridview)
 | |
|         {
 | |
|             setupGridView(gridview, true);
 | |
|             //   gridviewGoodsType.PopulateColumns();
 | |
|             gridview.Columns.Clear();
 | |
|             // gridviewGoodsType.Columns.Remove(gridviewGoodsType.Columns["DealerPrice"]); 
 | |
|             GridColumn myCol0 = new GridColumn() { Caption = "ID", Visible = true, FieldName = "id" };
 | |
|             myCol0.Visible = false;
 | |
|             GridColumn colChk = new GridColumn() { Caption = CheckBoxField, Visible = true, FieldName = CheckBoxField };
 | |
|             gridview.Columns.Add(colChk);
 | |
|             GridColumn myCol1 = new GridColumn() { Caption = "商品编码", Visible = true, FieldName = WmsGoods.fields.goodsId.ToString()};
 | |
|             GridColumn myCol2 = new GridColumn() { Caption = "商品名称", Visible = true, FieldName = WmsGoods.exfields.goodsName.ToString() };
 | |
|             GridColumn myCol3 = new GridColumn() { Caption = "厂家", Visible = true, FieldName = WmsGoods.exfields.manufacturer.ToString() };
 | |
|             GridColumn myCol4 = new GridColumn() { Caption = "规格", Visible = true, FieldName = WmsGoods.exfields.spec.ToString(),Width=100 };
 | |
|             GridColumn myCol5 = new GridColumn() { Caption = "单位", Visible = true, FieldName = WmsGoods.exfields.unit.ToString() };
 | |
|             GridColumn myCol6 = new GridColumn() { Caption = "大包装数量", Visible = true, FieldName = WmsGoods.exfields.bigCount.ToString()};
 | |
|             GridColumn myCol7 = new GridColumn() { Caption = "剂型", Visible = true, FieldName = WmsGoods.exfields.type.ToString() };
 | |
|             GridColumn myCol8 = new GridColumn() { Caption = "商品类型", Visible = true, FieldName = WmsGoods.exfields.goodsTypeName.ToString() };
 | |
|             /*  GridColumn myCol9 = new GridColumn() { Caption = "大零", Visible = true, FieldName = WmsGoods.fields.bulkMax.ToString() };
 | |
|             GridColumn myCol10 = new GridColumn() { Caption = "小整", Visible = true, FieldName = WmsGoods.fields.batchMax1.ToString()};
 | |
|             GridColumn myCol11 = new GridColumn() { Caption = "大整", Visible = true, FieldName = WmsGoods.fields.batchMax2.ToString() };*/
 | |
|             GridColumn myCol12 = new GridColumn() { Caption = "批号", Visible = true, FieldName = "batch" };
 | |
|           //  GridColumn myCol13 = new GridColumn() { Caption = "拼音简码", Visible = true, FiemcldName ="pinYin" };
 | |
|             GridColumn myCol14 = new GridColumn() { Caption = "货位", Visible = true, FieldName = "locationId" };          
 | |
|             
 | |
|             GridColumn myCol20 = new GridColumn() { Caption = "零库数量", Visible = true, FieldName = "avCount" };
 | |
|             GridColumn myCol201 = new GridColumn() { Caption = "数量", Visible = true, FieldName = "avCount" };
 | |
|             GridColumn myCol21 = new GridColumn() { Caption = "国药准字", Visible = true, FieldName = WmsGoods.exfields.regeditCode.ToString() };
 | |
|          GridColumn myCol10 = new GridColumn() { Caption = "生产日期", Visible = true, FieldName = WmsStock.fields.productDate.ToString()};
 | |
|          GridColumn myCol11 = new GridColumn() { Caption = "有效期", Visible = true, FieldName = WmsStock.fields.validDate.ToString() };
 | |
| 
 | |
|          GridColumn myCol22 = new GridColumn() { Caption = "零库件数", Visible = true, FieldName = "boxcnt" };
 | |
|          GridColumn myCol221 = new GridColumn() { Caption = "件数", Visible = true, FieldName = "boxcnt" };
 | |
|          GridColumn myCol123 = new GridColumn() { Caption = "货位状态", Visible = true, FieldName = "locState" };
 | |
|          GridColumn myCol124 = new GridColumn() { Caption = "状态", Visible = true, FieldName = "state" };
 | |
|          GridColumn myCol125 = new GridColumn() { Caption = "补货策略", Visible = true, FieldName = "repTypeName" };
 | |
|          GridColumn myCol9 = new GridColumn() { Caption = "零货库容量", Visible = true, FieldName = WmsGoods.fields.bulkMax.ToString() };
 | |
|          GridColumn myCol126 = new GridColumn() { Caption = "安全库存", Visible = true, FieldName = "repBalance" };
 | |
|          GridColumn myCol127 = new GridColumn() { Caption = "库存/库容%", Visible = true, FieldName = "leftPercent" };
 | |
|          GridColumn myCol128 = new GridColumn() { Caption = "在补数量", Visible = true, FieldName = "repCount" };
 | |
| 
 | |
|          GridColumn myCol129 = new GridColumn() { Caption = "整库数量", Visible = true, FieldName = "batchCount" };
 | |
| 
 | |
|          GridColumn myCol130 = new GridColumn() { Caption = "skuId", Visible = true, FieldName = "skuId" };
 | |
|          GridColumn myCol131 = new GridColumn() { Caption = "sku", Visible = true, FieldName = "skuCode" };
 | |
|          GridColumn myCol132 = new GridColumn() { Caption = "货主", Visible = true, FieldName = "ownerName" };
 | |
|         
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|        //  GridColumn myCol126 = new GridColumn() { Caption = "策略比例", Visible = true, FieldName = "repPercent" }; 
 | |
|          if (gridview == gridView2)
 | |
|          {
 | |
| 
 | |
|              gridview.Columns.Add(myCol14);
 | |
|              gridview.Columns.Add(myCol201);
 | |
|              gridview.Columns.Add(myCol5);   
 | |
|              gridview.Columns.Add(myCol221);
 | |
|              gridview.Columns.Add(myCol123); 
 | |
| 
 | |
|          }
 | |
|          else
 | |
|          {
 | |
| 
 | |
|              gridview.Columns.Add(myCol2);
 | |
|              gridview.Columns.Add(myCol130);
 | |
|              gridview.Columns.Add(myCol132);
 | |
|              gridview.Columns.Add(myCol12); 
 | |
| 
 | |
|              gridview.Columns.Add(myCol20);
 | |
|              gridview.Columns.Add(myCol5);
 | |
|              gridview.Columns.Add(myCol22);
 | |
|              gridview.Columns.Add(myCol127);
 | |
|              gridview.Columns.Add(myCol128);
 | |
|              gridview.Columns.Add(myCol129);
 | |
|              gridview.Columns.Add(myCol125);
 | |
|              gridview.Columns.Add(myCol126);
 | |
|              gridview.Columns.Add(myCol9);
 | |
|     
 | |
|              gridview.Columns.Add(myCol10);
 | |
|              gridview.Columns.Add(myCol11);
 | |
|              gridview.Columns.Add(myCol6);
 | |
|              gridview.Columns.Add(myCol22);
 | |
|              gridview.Columns.Add(myCol8);
 | |
|              gridview.Columns.Add(myCol4);
 | |
| 
 | |
| 
 | |
|              gridview.Columns.Add(myCol21);
 | |
|              gridview.Columns.Add(myCol1);
 | |
|              gridview.Columns.Add(myCol3);
 | |
|              gridview.Columns.Add(myCol124);
 | |
|          }
 | |
| 
 | |
|             //to show bottom scroll bar
 | |
|             gridview.OptionsView.ColumnAutoWidth = false;
 | |
|             gridview.BestFitColumns();
 | |
|            // gridview.Focus();
 | |
| 
 | |
|         }
 | |
| 
 | |
|        
 | |
|         #endregion
 | |
| 
 | |
|         /// <summary>  
 | |
|         /// loading data
 | |
|         /// </summary>  
 | |
|         private int loadData()
 | |
|         {
 | |
|             //this.gridviewGoodsType.DataSource = lgt.GetAllActiveData().Tables[0].DefaultView;
 | |
|             gridControl1.DataSource = null;
 | |
|             gridControl2.DataSource = null;
 | |
|             showWaitForm();
 | |
|             try
 | |
|             { 
 | |
|                 // this.splashScreenManager1.ShowWaitForm(); 
 | |
|                 string strPercent = "(repPercent > 0 AND avCount  < repPercent * bulkMax - repCount OR repPercent = 0);";
 | |
|                 strPercent = (checkEdit1.Checked ? (string.Format("{0} < # bulkMax*{1}/100 -repCount ;", "avCount", spinEdit1.Value)) :
 | |
|                                   strPercent + (this.comboRep.SelectedIndex <= 0 ? "" : string.Format("{0} = #{1};", WmsGoods.fields.repType.ToString(), ((Node)this.comboRep.SelectedItem).ID))
 | |
|                               );
 | |
| 
 | |
|                 queryStr = (this.txtGoodsId.Text.Trim().Length == 0 ? "" : string.Format("{0} = # '{1}';", WmsStock.fields.goodsId.ToString(), filtRiskChar(txtGoodsId.Text.Trim())))       
 | |
|                             + (this.comboBoPart.SelectedIndex <= 0 ? "" : string.Format("{0} = #{1};", WmsLocation.fields.part.ToString() ,  ((Node)this.comboBoPart.SelectedItem).ID))
 | |
|                             + (this.comboState.SelectedIndex <= 0 ? "" : string.Format("{0} = #{1};", WmsLocation.fields.state.ToString(), ((Colitem)this.comboState.SelectedItem).key))
 | |
|                             + (this.comboBoGoodsType.SelectedIndex <= 0 ? "" : string.Format("{0} = #{1};", WmsLocation.fields.goodsType.ToString(), ((Node)this.comboBoGoodsType.SelectedItem).ID))
 | |
|                             + (this.txtGoodName.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '%{1}%';", WmsGoods.exfields.goodsName.ToString(), filtRiskChar(txtGoodName.Text.Trim())))
 | |
|                             + (this.txtpinyin.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '%{1}%';", WmsGoods.exfields.pinYin.ToString(), filtRiskChar(txtpinyin.Text.Trim())))
 | |
|                             + (this.textBatch.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '%{1}%';", WmsStock.fields.batch.ToString(), filtRiskChar(textBatch.Text.Trim())))
 | |
|                             + (this.txtValid.Text.Trim().Length == 0 ? "" : string.Format("{0} like # '{1}%';", WmsStock.fields.validDate.ToString(), filtRiskChar(txtValid.Text.Trim())))
 | |
|                             + (this.txtSkuId.Text.Trim().Length == 0 ? "" : string.Format("{0} =#{1};", "SKUID", filtRiskChar(txtSkuId.Text.Trim())))
 | |
|                
 | |
|                             ;
 | |
|                 string repQuery = strPercent + queryStr;
 | |
| 
 | |
| 
 | |
|                 this.pager1.PageCurrent = lastQuery.Equals(repQuery) ? this.pager1.PageCurrent : 1; //根据查询条件的变化给pager赋值
 | |
|                 int start = (pager1.PageSize * (pager1.PageCurrent - 1) + 1);
 | |
|                 int end = (pager1.PageSize * pager1.PageCurrent);
 | |
|                 lastQuery = repQuery;
 | |
|                 DataSet ds = stkLocClient.queryBulkRep(repQuery, start, end);
 | |
|                 
 | |
|                 closeClient();
 | |
|                 DtGv = ds.Tables[0];
 | |
|                 addCheckField(DtGv);
 | |
|                 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["goodsId"], DtGv.Columns["batch"] };
 | |
|                 this.gridControl1.DataSource = DtGv.DefaultView;
 | |
|                //  gridView1.OptionsView.ColumnAutoWidth = true;
 | |
|                //  initialDataGridColumns(this.gridView1);
 | |
|                 //update selected row index to the last updated one.
 | |
| 
 | |
|                  if (!string.IsNullOrEmpty(selectedGoodsId))
 | |
|                  {
 | |
| 
 | |
|                      DataRow[] drs = DtGv.Select(string.Format("goodsId='{0}' and skuId ='{1}'", selectedGoodsId, selectedSkuId));
 | |
| 
 | |
|                      DataRow dr = null;
 | |
|                      if (drs.Length > 0)
 | |
|                      {
 | |
|                          dr = drs[0];
 | |
|                      }
 | |
| 
 | |
|                      if (dr != null)
 | |
|                      {
 | |
|                          selectedRowIndex = DtGv.Rows.IndexOf(dr);
 | |
|                          if (selectedRowIndex > 0 && DtGv.Rows.Count > selectedRowIndex)
 | |
|                          {
 | |
|                              // gridView1.SelectRow(selectedRowIndex);
 | |
|                              gridView1.FocusedRowHandle = selectedRowIndex;
 | |
|                              //  gridView1.MakeRowVisible(selectedRowIndex);
 | |
|                              
 | |
|                          }
 | |
|                      }
 | |
|                      else
 | |
|                      {
 | |
|                          gridView1.FocusedRowHandle = 0;
 | |
|                          gridView1.SelectRow(0);
 | |
|                        
 | |
|                      }
 | |
| 
 | |
| 
 | |
| 
 | |
|                      //gridView1.FocusedRowHandle = selectedRowIndex;
 | |
|                  }
 | |
|                  else
 | |
|                  {
 | |
|                      gridView1.FocusedRowHandle = 0;
 | |
|                      gridView1.SelectRow(0);
 | |
| 
 | |
|                  }
 | |
|                 if (DtGv.Rows.Count > 0 && selectedRowIndex ==-1)
 | |
|                  {
 | |
|                      selectedRowIndex = 0;
 | |
|                  }
 | |
|                  setCurrentRequestDetail();
 | |
|                 closeWaitForm();
 | |
|                 return cnt;// lgt.getRowCount(query);
 | |
|                 // return lgt.GetGoodType.QueryCount(); 
 | |
|             }
 | |
|             catch (Exception er)
 | |
|             {
 | |
|                 showErrorMsg(er.Message);
 | |
|             }
 | |
| 
 | |
|             return 0;
 | |
| 
 | |
|         }
 | |
|           
 | |
|         /// <summary>  
 | |
|         /// 分页控件产生的事件  
 | |
|         /// </summary>  
 | |
|         private int pager_EventPaging(DeiNiu.Controls.pager.EventPagingArg e)
 | |
|         {
 | |
|         //  selectedRowIndex = 0; //reset currentRowIndex
 | |
|             return loadData();
 | |
|         }
 | |
| 
 | |
|         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()
 | |
|         {
 | |
|             gridView1.OptionsSelection.MultiSelect = true;//按shift / control 多选
 | |
|             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 += gridView1_CustomColumnDisplayText;
 | |
|             gridView2.CustomColumnDisplayText += gridView1_CustomColumnDisplayText;
 | |
| 
 | |
|             initialDataGridColumns(gridView1);
 | |
|          
 | |
|             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();
 | |
|             }
 | |
|         }
 | |
|     
 | |
|         
 | |
| 
 | |
|         protected void query()
 | |
|         {
 | |
|             pager1.Bind();
 | |
|         }
 | |
| 
 | |
| 
 | |
|         private void queryGoods()
 | |
|         {
 | |
| 
 | |
|             showWaitForm();
 | |
|             try
 | |
|             {
 | |
|                 query();// loadData();  
 | |
|             }
 | |
|             catch (Exception e)
 | |
|             {
 | |
|                 showErrorMsg(e.Message);
 | |
|             }
 | |
|             finally
 | |
|             {
 | |
|                 // WaitFormService.Close();
 | |
|                 closeWaitForm();
 | |
|                 bbQuery.Enabled = true;
 | |
|             }
 | |
| 
 | |
|         }
 | |
|          
 | |
|         private void bbQuery_ItemClick_1(object sender, ItemClickEventArgs e)
 | |
|         {
 | |
|             this.bbQuery.Enabled = false;
 | |
|             queryGoods();
 | |
|         }
 | |
| 
 | |
|        
 | |
| 
 | |
|         private void updateObjects(List<WmsGoods> goods)
 | |
|         { 
 | |
|             showWaitForm();
 | |
|             //WaitFormService.Show(this); 
 | |
|             try
 | |
|             { 
 | |
|                
 | |
|                // lgt.update(wgoods);
 | |
| 
 | |
|                 //get updated data 
 | |
|                 query();
 | |
| 
 | |
|             }
 | |
|             catch (Exception e)
 | |
|             {
 | |
|                 showErrorMsg(e,e.Message);
 | |
|             }
 | |
|             finally
 | |
|             {
 | |
|                 // WaitFormService.Close();
 | |
|                 closeWaitForm();
 | |
|              
 | |
|             }
 | |
|              
 | |
| 
 | |
|         }
 | |
| 
 | |
|       
 | |
|  
 | |
| 
 | |
|         private void btnQuery_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             this.query();
 | |
|         }
 | |
| 
 | |
|        
 | |
| 
 | |
| 
 | |
|        
 | |
| 
 | |
|         private void txtpinyin_KeyUp(object sender, KeyEventArgs e)
 | |
|         {
 | |
|             if (e.KeyCode == Keys.Enter)
 | |
|             {
 | |
|                 loadData();
 | |
|             }
 | |
|         }
 | |
| 
 | |
| 
 | |
|       
 | |
|         private void bbQuery_ItemClick(object sender, ItemClickEventArgs e)
 | |
|         {
 | |
|             query();
 | |
|         }
 | |
| 
 | |
|        
 | |
| 
 | |
|         private void btnQuery_Click_1(object sender, EventArgs e)
 | |
|         {
 | |
|             query();
 | |
|         }
 | |
| 
 | |
|         private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
 | |
|         {
 | |
| 
 | |
|         
 | |
|                 if (e.Column.FieldName == "state")
 | |
|                 {
 | |
| 
 | |
|                     if (!stockState.ContainsValue(e.DisplayText))
 | |
|                     {
 | |
| 
 | |
|                         int display = -100;
 | |
|                         string disTxt = e.DisplayText;
 | |
| 
 | |
|                         try
 | |
|                         {
 | |
|                             display = Convert.ToInt32(e.DisplayText);
 | |
| 
 | |
|                             e.DisplayText = stockState[display];
 | |
| 
 | |
|                         }
 | |
|                         catch
 | |
|                         {
 | |
|                             return;
 | |
|                         }
 | |
|                     }
 | |
| 
 | |
|                 }
 | |
|                 else if (e.Column.FieldName == "locState")
 | |
|                 {
 | |
| 
 | |
|                     if (!stockState.ContainsValue(e.DisplayText))
 | |
|                     {
 | |
| 
 | |
|                         int display = -100;
 | |
|                         string disTxt = e.DisplayText;
 | |
| 
 | |
|                         try
 | |
|                         {
 | |
|                             display = Convert.ToInt32(e.DisplayText);
 | |
| 
 | |
|                             e.DisplayText = stockState[display];
 | |
| 
 | |
|                         }
 | |
|                         catch
 | |
|                         {
 | |
|                             return;
 | |
|                         }
 | |
|                     }
 | |
| 
 | |
|                 }
 | |
|  
 | |
|         }
 | |
| 
 | |
| 
 | |
|        
 | |
|         bool isDataSourceChanged = false;
 | |
|         private void gridView1_DataSourceChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             isDataSourceChanged = true;
 | |
|             if (selectedRowIndex > 0 && DtGv.Rows.Count > selectedRowIndex)
 | |
|             {
 | |
|                 gridView1.FocusedRowHandle = selectedRowIndex;
 | |
|                 gridView1.MakeRowVisible(selectedRowIndex);
 | |
| 
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void gridView1_FocusedRowObjectChanged(object sender, FocusedRowObjectChangedEventArgs e)
 | |
|         {
 | |
| 
 | |
|             if (gridView1.FocusedRowHandle < 0 || gridView1.FocusedRowHandle == selectedRowIndex || isDataSourceChanged)
 | |
|             {
 | |
|                 isDataSourceChanged = false;
 | |
|                 if (gridView1.IsGroupRow(e.RowHandle)) //set first row of group selected
 | |
|                 {
 | |
|                     selectedRowIndex = gridView1.GetChildRowHandle(e.RowHandle, 0);
 | |
|                     setCurrentRequestDetail();
 | |
|                 }
 | |
| 
 | |
|                 return;
 | |
| 
 | |
|             }
 | |
|             selectedRowIndex = gridView1.FocusedRowHandle;
 | |
|             // showErrorMsg("selection:"+ selectedRowIndex);
 | |
|             this.gridControl2.DataSource = null;
 | |
|             clearInputs();
 | |
|             setCurrentRequestDetail();
 | |
| 
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void clearInputs()
 | |
|         {
 | |
|             gridControl2.DataSource = null;
 | |
|         }
 | |
| 
 | |
|         private void setCurrentRequestDetail()
 | |
|         {
 | |
| 
 | |
|             if (!getCurrentObject() || string.IsNullOrEmpty(selectedGoodsId))
 | |
|             {
 | |
|                 return;
 | |
|             }
 | |
| 
 | |
|             showWaitForm();
 | |
| 
 | |
|             try
 | |
|             {
 | |
| 
 | |
|                 dtDetail = stkLocClient.getWmsStockDetails(selectedGoodsId,selectedSkuId, queryStr);
 | |
|                 closeClient(); 
 | |
|              
 | |
|                 clearInputs();
 | |
|                 this.gridControl2.DataSource = dtDetail;
 | |
|                 initialDataGridColumns(gridView2);
 | |
|              
 | |
| 
 | |
|             }
 | |
|             catch (Exception e)
 | |
|             {
 | |
|                 showErrorMsg(e.Message);
 | |
|             }
 | |
|             closeWaitForm();
 | |
|         }
 | |
| 
 | |
|         private bool getCurrentObject()
 | |
|         {
 | |
|             if (selectedRowIndex < 0 || selectedRowIndex >= DtGv.Rows.Count)
 | |
|             {
 | |
|                 return false;
 | |
|             }
 | |
| 
 | |
|             //  DataRow currentRow = dt.Rows[selectedRowIndex];
 | |
|             DataRowView dr = (DataRowView)(GetGridViewFilteredAndSortedData(gridView1)[selectedRowIndex]);
 | |
|             selectedGoodsId = dr["goodsId"].ToString(); ;
 | |
|             selectedSkuId = Convert.ToInt32( dr["skuId"].ToString());
 | |
|             this.gridControl2.DataSource = null;
 | |
| 
 | |
|             return true;
 | |
|         }
 | |
| 
 | |
|         private void checkEdit1_CheckedChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             switchRepPercent();
 | |
|         }
 | |
| 
 | |
|         void switchRepPercent()
 | |
|         {
 | |
|             spinEdit1.Enabled = checkEdit1.Checked;
 | |
|             comboRep.Enabled = !checkEdit1.Checked;
 | |
|              
 | |
|         }
 | |
| 
 | |
|         private void chkRecnt_CheckedChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             spRepCnt.Enabled = !chkRecnt.Checked;
 | |
|         }
 | |
| 
 | |
|         private void btnRep_Click(object sender, EventArgs e)
 | |
|         {
 | |
| 
 | |
|             try
 | |
|             {
 | |
|                 if (getCurrentObjects())
 | |
|                 {
 | |
|                     showWaitForm();
 | |
|                     // to create rep orders
 | |
|                     if (stkLocClient.createGoodsRepOrder(selectedGoods.ToArray()))
 | |
|                     {
 | |
|                         closeWaitForm();
 | |
|                         MessageBox.Show("补库单创建成功!");
 | |
|                         query();
 | |
|                     }
 | |
|                     else
 | |
|                     { 
 | |
|                         closeWaitForm();
 | |
|                         showErrorMsg("补货失败,请确保所有补货商品整库库存充足");
 | |
|                     }
 | |
| 
 | |
|                     closeClient();
 | |
|                    
 | |
|                 }
 | |
|             }
 | |
|             catch (Exception er)
 | |
|             {
 | |
|                 closeWaitForm();
 | |
|                 showErrorMsg(er.Message);
 | |
|             }
 | |
| 
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private bool getCurrentObjects()
 | |
|         {
 | |
|             int repBox = chkRecnt.Checked ? 0: Convert.ToInt32( spRepCnt.Value)  ;
 | |
|             int[] selectedRows = gridView1.GetSelectedRows();
 | |
|          //   selectedGoods = new List<WmsGoods>();
 | |
|             selectedGoods.Clear(); 
 | |
| 
 | |
|             foreach (DataRow row in this.DtGv.Rows)
 | |
|             {
 | |
|                 string v = row[CheckBoxField].ToString();
 | |
|                 bool b = String.IsNullOrEmpty(v) ? false : Convert.ToBoolean(v);
 | |
|                 if (b)
 | |
|                 {
 | |
|                     int boxCnt = 0;
 | |
|                     decimal repCnt = 0m;
 | |
|                     decimal bigCount = Convert.ToDecimal(row["bigCount"].ToString());
 | |
|                     if (repBox == 0)
 | |
|                     {
 | |
|                         repCnt = Convert.ToDecimal(row["repBalance"].ToString()) - Convert.ToDecimal(row["avCount"].ToString());
 | |
|                         boxCnt = (int)Math.Ceiling(repCnt / bigCount);
 | |
|                         boxCnt = boxCnt > 0 ? boxCnt : 1;
 | |
|                     }
 | |
|                     else
 | |
|                     {
 | |
|                         boxCnt = repBox;
 | |
|                     }
 | |
|                     repCnt = boxCnt * bigCount;
 | |
| 
 | |
|                     string goodsId = row["goodsId"].ToString();
 | |
|                     string batch = row["batch"].ToString();
 | |
|                     string prdDate = row[WmsStock.fields.productDate.ToString()].ToString();
 | |
|                     string validDate = row["validDate"].ToString();
 | |
|                     string skuId = row["skuId"].ToString();
 | |
|                     string skuCode = row["skuCode"].ToString();
 | |
|                     //   G1WADY9BDEN|*|160720|*|1000|*|20160730|*|
 | |
|                     selectedGoods.Add(string.Format("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}",
 | |
|                         goodsId, WmsConstants.SPLIT, batch, WmsConstants.SPLIT, repCnt, WmsConstants.SPLIT,
 | |
|                         prdDate, WmsConstants.SPLIT, validDate, WmsConstants.SPLIT, skuId, WmsConstants.SPLIT,
 | |
|                         skuCode)); 
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             /*
 | |
|             foreach (int i in selectedRows)
 | |
|             {
 | |
|                 DataRowView row = (DataRowView)(GetGridViewFilteredAndSortedData(gridView1)[i]);// dt.Rows[i];
 | |
|                 
 | |
| 
 | |
|               //  selectedGoods.Add(new WmsGoods(currentRow));
 | |
|             }
 | |
|             */
 | |
|             if (selectedGoods.Count == 0)
 | |
|             {
 | |
|                 showErrorMsg("请至少选择一条数据");
 | |
|                 return false;
 | |
|             }
 | |
|             return true;
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void btnExport_ItemClick(object sender, ItemClickEventArgs e)
 | |
|         {
 | |
|             exportExcel(gridView1);
 | |
|         }
 | |
| 
 | |
|     }
 | |
| } |