565 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			565 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | ||
| 
 | ||
| using System.Collections.Generic;
 | ||
| using System.ComponentModel;
 | ||
| using System.Data;
 | ||
| using System.Drawing;
 | ||
| using System.Text;
 | ||
| using System.Windows.Forms;
 | ||
| using System.Threading;
 | ||
|  
 | ||
| 
 | ||
| namespace DeiNiu.Wms.CE
 | ||
| {
 | ||
|     public partial class RepStockIn : basicForm 
 | ||
|     {
 | ||
|        //  // WmsOutPickRequestClient client { get; set; }
 | ||
|          // WmsInRequestClient client { get; set; }
 | ||
|           //v_stockOutBatchPickOrder4Wince
 | ||
|           //v_stockOutBatchPickDetail4Wince
 | ||
|           public RepStockIn()
 | ||
|         {
 | ||
|             setTitle();
 | ||
|             InitializeComponent();
 | ||
|           //  client = new WmsOutPickRequestClient(WcfHelp.getBasicBinding(), WcfHelp.getEndpoint("WmsOutPickRequestService"));
 | ||
|          //   client = new WmsInRequestClient(WcfHelp.getBasicBinding(), WcfHelp.getEndpoint("WmsInRequestService"));
 | ||
|         }
 | ||
|   
 | ||
|         bool isAuto =false;
 | ||
| 
 | ||
|         string goodsId = "";
 | ||
|         string goodsName = "";
 | ||
|         string batch = "";
 | ||
|         int skuId = 0;
 | ||
|         string goodsType = "";
 | ||
|         decimal count = 0m;
 | ||
|         DataTable dtIns;
 | ||
|         DataTable dtLocs;
 | ||
|         int id;
 | ||
|         string orderNo = "";
 | ||
|         private void RepStockIn_Load(object sender, EventArgs e)
 | ||
|         {
 | ||
|             isAuto = rbAuto.Checked;
 | ||
|             bindBg1();
 | ||
|             
 | ||
| 
 | ||
|             
 | ||
|         }
 | ||
| 
 | ||
|          
 | ||
| 
 | ||
| 
 | ||
|         private void dg1_DoubleClick(object sender, EventArgs e)
 | ||
|         {
 | ||
|             clear();
 | ||
|             if (dg1.DataSource==null)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
|             if(dg1.CurrentRowIndex<0)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             //string sale_order = dg1[dg1.CurrentRowIndex, 0].ToString();
 | ||
| 
 | ||
|             //string custor_name = dg1[dg1.CurrentRowIndex, 1].ToString();
 | ||
|             lbGoods.Text = dg1[dg1.CurrentRowIndex, 3].ToString();
 | ||
|             lbCount.Text = dg1[dg1.CurrentRowIndex, 0].ToString(); 
 | ||
|             tb1.SelectedIndex = 1;
 | ||
| 
 | ||
|            
 | ||
|                   
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         private void tb1_SelectedIndexChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
| 
 | ||
|             if (tb1.SelectedIndex == 0)
 | ||
|             {
 | ||
|                bindBg1();
 | ||
|                 /*
 | ||
|                   dg1.TableStyles[0].GridColumnStyles["出库单"].Width = 80;
 | ||
|                   dg1.TableStyles[0].GridColumnStyles["客户"].Width = 140;
 | ||
|                   dg1.TableStyles[0].GridColumnStyles["状态"].Width = 60;
 | ||
|                  */
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 setDetail(); 
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void dg1_CurrentCellChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         private void bindBg1()
 | ||
|         {
 | ||
|             textBoxGoods.Text = "";
 | ||
|           
 | ||
|             Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
 | ||
|             try
 | ||
|             {
 | ||
|                 dtIns = client.repTodayDetails4In();
 | ||
| 
 | ||
|             }
 | ||
|             catch (Exception er)
 | ||
|             {
 | ||
|                 Cursor.Current = System.Windows.Forms.Cursors.Default;
 | ||
|                 MessageBox.Show("发生错误:" + er.Message);
 | ||
| 
 | ||
| 
 | ||
|             }
 | ||
|             Cursor.Current = System.Windows.Forms.Cursors.Default;
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|             DataGridTableStyle dgts = new DataGridTableStyle();
 | ||
|             dgts.MappingName = dtIns.TableName;// dt.TableName; // 必须用 ds.TableName, dt.TableSpace 不行!!!! 
 | ||
|             dg1.DataSource = dtIns;
 | ||
|             /*
 | ||
|             for (int i = 0; i < dtIns.Columns.Count; i++)
 | ||
|             {
 | ||
|                 DataGridColumnStyle ColStyle = new DataGridTextBoxColumn();
 | ||
|                 ColStyle.MappingName = dtIns.Columns[i].ColumnName.ToString();
 | ||
|                 ColStyle.HeaderText = dtIns.Columns[i].ColumnName.ToString();
 | ||
|                 ColStyle.Width = dtIns.Rows[0][i].ToString().Length * 7 - 1;
 | ||
| 
 | ||
|                 if (ColStyle.Width <25)
 | ||
|                 {
 | ||
|                      ColStyle.Width = 25;//设置列宽
 | ||
|                 }
 | ||
|                 if (i >= 7) //如果某个条件满足就执行该列是否隐藏
 | ||
|                 {
 | ||
|                     //  ColStyle.Width = 0;//当宽度等于0的时候就可以隐藏这列
 | ||
|                 }
 | ||
|                 dgts.GridColumnStyles.Add(ColStyle);
 | ||
| 
 | ||
|             }   
 | ||
|             */
 | ||
|             dg1.TableStyles.Clear(); 
 | ||
|             dg1.TableStyles.Add(dgts);
 | ||
|             dg1.TableStyles[0].GridColumnStyles["商品"].Width = 80;
 | ||
|             dg1.TableStyles[0].GridColumnStyles["数量"].Width = 30;
 | ||
|             dg1.TableStyles[0].GridColumnStyles["件"].Width = 20;
 | ||
|             dg1.TableStyles[0].GridColumnStyles["商品类别"].Width = 50;
 | ||
|            // dg1.TableStyles[0].GridColumnStyles["状态"].Width = 0;
 | ||
|            // dg1.TableStyles[0].GridColumnStyles["货位"].Width = 0;
 | ||
|              
 | ||
|             dgts = null;
 | ||
|             GC.Collect();
 | ||
|  
 | ||
|         }
 | ||
| 
 | ||
|         private void bindBg2()
 | ||
|         {
 | ||
|             if (string.IsNullOrEmpty(goodsId))
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             Cursor.Current = Cursors.WaitCursor;
 | ||
|             try
 | ||
|             {
 | ||
|                 dtLocs = client.getLocations( skuId,"",goodsId, batch, count);
 | ||
| 
 | ||
|             }
 | ||
|             catch (Exception e)
 | ||
|             {
 | ||
|                 Cursor.Current = Cursors.Default;
 | ||
|                 MessageBox.Show("出错了:" +e.Message);
 | ||
|                 return;
 | ||
|             }
 | ||
|             Cursor.Current = Cursors.Default;
 | ||
| 
 | ||
|             if (dtLocs.Rows.Count == 0)
 | ||
|             {
 | ||
|                 MessageBox.Show("没有发现空货位");
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
| 
 | ||
|             DataGridTableStyle dgts = new DataGridTableStyle();
 | ||
|             dgts.MappingName = dtLocs.TableName;// dt.TableName; // 必须用 ds.TableName, dt.TableSpace 不行!!!!
 | ||
| 
 | ||
|             for (int i = 0; i < dtLocs.Columns.Count; i++)
 | ||
|             {
 | ||
|                 DataGridColumnStyle ColStyle = new DataGridTextBoxColumn();
 | ||
|                 ColStyle.MappingName = dtLocs.Columns[i].ColumnName.ToString();
 | ||
|                 ColStyle.HeaderText = dtLocs.Columns[i].ColumnName.ToString();
 | ||
|                 ColStyle.Width = dtLocs.Rows[0][i].ToString().Length * 7 - 1;
 | ||
| 
 | ||
|                 if (ColStyle.Width < 50)
 | ||
|                 {
 | ||
|                    ColStyle.Width = 50;//设置列宽
 | ||
|                 }
 | ||
|                 if (i == 1) //如果某个条件满足就执行该列是否隐藏
 | ||
|                 {
 | ||
|                   //  ColStyle.Width = 0;//当宽度等于0的时候就可以隐藏这列
 | ||
|                 }
 | ||
|                 dgts.GridColumnStyles.Add(ColStyle);
 | ||
|             }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|            
 | ||
|             dg2.TableStyles.Clear();
 | ||
|            
 | ||
|             dg2.TableStyles.Add(dgts);
 | ||
|             dg2.DataSource = dtLocs;
 | ||
|             dgts = null;
 | ||
|             GC.Collect();
 | ||
| 
 | ||
|              
 | ||
|             //dgts.GridColumnStyles[0].Width = 100;
 | ||
|             //dgts.GridColumnStyles[1].Width = 100;
 | ||
|           
 | ||
|   
 | ||
|         }
 | ||
| 
 | ||
|         private void rbAuto_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             setAuto();
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         void setAuto()
 | ||
|         {
 | ||
|             if (string.IsNullOrEmpty(goodsId))
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             isAuto = rbAuto.Checked; 
 | ||
|             textBoxNum.Enabled = !isAuto;
 | ||
|             btnOkay.Enabled = !isAuto;
 | ||
|             textBoxNum.Text =  "";
 | ||
|             if (isAuto)
 | ||
|             {
 | ||
|                
 | ||
|                 bindBg2();
 | ||
| 
 | ||
|             }
 | ||
|             else
 | ||
|             {
 | ||
|                 textBoxNum.Text = count + "";
 | ||
|                 dg2.DataSource = null;
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void dg1_DoubleClick_1(object sender, EventArgs e)
 | ||
|         {
 | ||
| 
 | ||
|            // setDetail();
 | ||
|             tb1.SelectedIndex = 1;
 | ||
|               
 | ||
|         }
 | ||
| 
 | ||
|         void setDetail()
 | ||
|         {
 | ||
|             clear();
 | ||
| 
 | ||
|             if (dg1.DataSource == null)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
|             if (dg1.CurrentRowIndex < 0)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             orderNo = dtIns.Rows[dg1.CurrentRowIndex]["pickOrderNo"].ToString(); 
 | ||
|             goodsId = dtIns.Rows[dg1.CurrentRowIndex]["goodsId"].ToString();// dg1[dg1.CurrentRowIndex, 14].ToString();
 | ||
|             goodsName = dtIns.Rows[dg1.CurrentRowIndex]["商品"].ToString();// dg1[dg1.CurrentRowIndex, 0].ToString();
 | ||
|             batch = dtIns.Rows[dg1.CurrentRowIndex]["批号"].ToString();// dg1[dg1.CurrentRowIndex, 4].ToString();
 | ||
|             skuId =Convert.ToInt16(  dtIns.Rows[dg1.CurrentRowIndex]["skuId"].ToString());
 | ||
|             count = Convert.ToDecimal(dtIns.Rows[dg1.CurrentRowIndex]["数量"].ToString()); //Convert.ToDecimal(dg1[dg1.CurrentRowIndex, 1].ToString());
 | ||
|             goodsType = dtIns.Rows[dg1.CurrentRowIndex]["商品类别"].ToString(); //dg1[dg1.CurrentRowIndex, 6].ToString();
 | ||
|             lbGoods.Text = goodsName;
 | ||
|             lbBatch.Text = batch;
 | ||
|             lbCount.Text = count+"";
 | ||
|             lbType.Text = goodsType;
 | ||
|             id = Convert.ToInt32(dtIns.Rows[dg1.CurrentRowIndex]["id"].ToString());
 | ||
|             textBox1.Text = "";
 | ||
|             textBox1.Focus();
 | ||
| 
 | ||
| 
 | ||
|         }
 | ||
|         void clear()
 | ||
|         {
 | ||
|             orderNo = 
 | ||
|             goodsId =
 | ||
|             batch = "";
 | ||
|             goodsName = "";
 | ||
|             skuId = 0;
 | ||
|             count = 0;
 | ||
|             lbGoods.Text = goodsId;
 | ||
|             lbBatch.Text = batch;
 | ||
|             lbCount.Text = "";
 | ||
|             dg2.DataSource = null;
 | ||
|             rbAuto.Checked = false;
 | ||
|             radioButton2.Checked = true;
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         private void radioButton2_CheckedChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
|             setAuto();
 | ||
|         }
 | ||
| 
 | ||
|         private void btnOkay_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             repIn();
 | ||
| 
 | ||
|         }
 | ||
|         void repIn()
 | ||
|         {
 | ||
|             decimal inCount = 0;
 | ||
|             try
 | ||
|             {
 | ||
|                 inCount = Convert.ToDecimal(textBoxNum.Text.Trim());
 | ||
| 
 | ||
|                 if (inCount > count)
 | ||
|                 {
 | ||
|                     throw new Exception();
 | ||
|                 }
 | ||
|             }
 | ||
|             catch
 | ||
|             {
 | ||
| 
 | ||
|                 MessageBox.Show("请输入正确的上架数量");
 | ||
|                 textBoxNum.Focus();
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             string locId = textBox1.Text;
 | ||
|             if (string.IsNullOrEmpty(locId))
 | ||
|             {
 | ||
| 
 | ||
|                 MessageBox.Show("请扫描货架条码");
 | ||
|                 textBox1.Focus();
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             if (putIn(locId, skuId,goodsId, batch, inCount, id))
 | ||
|             {
 | ||
|                 count -= inCount;
 | ||
|                 if (count <= 0)
 | ||
|                 {
 | ||
|                     tb1.SelectedIndex = 0;
 | ||
|                     return;
 | ||
|                 }
 | ||
|                 lbCount.Text = count + "";
 | ||
|                 //  setDetail();
 | ||
| 
 | ||
|                 textBox1.Text = "";
 | ||
|                 textBoxNum.Text = "";
 | ||
|             }
 | ||
| 
 | ||
|             textBox1.Focus();
 | ||
|         }
 | ||
| 
 | ||
|         bool putIn(string locId, int skuId, string goodsId, string batch, decimal count, int portId)
 | ||
|         {
 | ||
| 
 | ||
|             if (string.IsNullOrEmpty(goodsId) || string.IsNullOrEmpty(locId) || string.IsNullOrEmpty(batch) || count <= 0 || portId <= 0)
 | ||
|             {
 | ||
|                 MessageBox.Show("条件不符,不能入库");
 | ||
|                 textBox1.Focus();
 | ||
|                 return false;
 | ||
|             }
 | ||
|             enumRepResult result = enumRepResult.成功;
 | ||
|            Cursor.Current = Cursors.WaitCursor;
 | ||
|             try
 | ||
|             {                  
 | ||
|                  result = (enumRepResult)client.repItemIn(locId, goodsId,skuId, batch, count, portId, LoginInfo.UserId, LoginInfo.Token);
 | ||
|             }
 | ||
|             catch (Exception e)
 | ||
|             {
 | ||
|                 Cursor.Current = Cursors.Default;
 | ||
|                 MessageBox.Show(e.Message);
 | ||
|                 return false;
 | ||
|             }
 | ||
|             Cursor.Current = Cursors.Default;
 | ||
| 
 | ||
|             if (result != enumRepResult.成功)
 | ||
|             {
 | ||
|                 MessageBox.Show("入库失败:" + result);
 | ||
|                 textBox1.Focus();
 | ||
|                 return false;
 | ||
|             }
 | ||
|             return true;
 | ||
| 
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         private void textBox1_KeyUp(object sender, KeyEventArgs e)
 | ||
|         {
 | ||
|             if (!isAuto)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
| 
 | ||
|             if (e.KeyCode == Keys.Enter)
 | ||
|             {
 | ||
| 
 | ||
|                 string locId = textBox1.Text;
 | ||
| 
 | ||
|                 DataView dv = dtLocs.DefaultView;
 | ||
|                 dv.RowFilter = string.Format("推荐货位='{0}'", locId);
 | ||
|                 bool result = false;
 | ||
|                 decimal inCount = 0m;
 | ||
|                 if (dv.Count > 0)
 | ||
|                 {
 | ||
|                     foreach (DataRowView dr in dv)
 | ||
|                     {
 | ||
|                         inCount = Convert.ToDecimal(dr[1].ToString());
 | ||
| 
 | ||
| 
 | ||
|                         result = putIn(locId, skuId,goodsId, batch, inCount, id);
 | ||
| 
 | ||
| 
 | ||
|                         break;
 | ||
|                     }
 | ||
| 
 | ||
|                 }
 | ||
|                 else
 | ||
|                 {
 | ||
|                     MessageBox.Show(locId + "不是推荐货位或改货位已经扫描入库了,请扫描其它货位");
 | ||
|                     dv.RowFilter ="";
 | ||
|                     textBox1.SelectAll();
 | ||
|                 }
 | ||
| 
 | ||
|                 if (result)
 | ||
|                 {
 | ||
|                     count -= inCount;
 | ||
|                     if (count <= 0) //入库完毕
 | ||
|                     {
 | ||
|                         tb1.SelectedIndex = 0;
 | ||
|                         return;
 | ||
|                     }
 | ||
|                     dv.RowFilter = string.Format("推荐货位<>'{0}'", locId);
 | ||
| 
 | ||
|                    dtLocs = dv.ToTable("locs");
 | ||
|                    dg2.DataSource = dtLocs;
 | ||
| 
 | ||
|                    lbCount.Text = count + "";
 | ||
|                    // bindBg2();
 | ||
|                 }
 | ||
|                 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void dg2_DoubleClick(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (dg2.DataSource == null)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
|             if (dg2.CurrentRowIndex < 0)
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
| 
 | ||
|             //string sale_order = dg1[dg1.CurrentRowIndex, 0].ToString();
 | ||
| 
 | ||
|             //string custor_name = dg1[dg1.CurrentRowIndex, 1].ToString();
 | ||
|            textBox1.Text = dg2[dg2.CurrentRowIndex, 0].ToString(); 
 | ||
|              
 | ||
|         }
 | ||
| 
 | ||
|         private void button1_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             bindBg1();
 | ||
|         }
 | ||
| 
 | ||
|         private void textBoxGoods_KeyUp(object sender, KeyEventArgs e)
 | ||
|         {
 | ||
|                 string goodsBarcode = textBoxGoods.Text;
 | ||
| 
 | ||
| 
 | ||
|                 if (string.IsNullOrEmpty(goodsBarcode))
 | ||
|                 {
 | ||
|                     textBoxGoods.Focus();
 | ||
|                     return;
 | ||
|                 }
 | ||
| 
 | ||
|             if (e.KeyCode == Keys.Enter)
 | ||
|             {
 | ||
| 
 | ||
| 
 | ||
|                 DataView dv = dtIns.DefaultView;
 | ||
| 
 | ||
| 
 | ||
|                 dv.RowFilter = string.Format("barcode='{0}'", goodsBarcode);
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
|                 if (dv.Count ==1)
 | ||
|                 {
 | ||
|                     tb1.SelectedIndex = 1;
 | ||
|                 }
 | ||
| 
 | ||
|                 dv.RowFilter = "";
 | ||
|                 textBoxGoods.Text = "";
 | ||
| 
 | ||
| 
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private void btnComplete_Click(object sender, EventArgs e)
 | ||
|         {
 | ||
|             if (string.IsNullOrEmpty(goodsId))
 | ||
|             {
 | ||
|                 return;
 | ||
|             }
 | ||
|             Message me = new Message();
 | ||
|             me.title = "您确认此条补货已完成入库 ?";
 | ||
|             if (me.ShowDialog() == DialogResult.Cancel)
 | ||
|             {
 | ||
|                 textBox1.Focus();
 | ||
|                 return;
 | ||
|             }
 | ||
|             Cursor.Current = Cursors.WaitCursor;
 | ||
|             try
 | ||
|             {
 | ||
|                 //int i =0;
 | ||
|                 //while(i<50){
 | ||
|                 //    i++;
 | ||
|                 client.finishBatchValidateItem(orderNo, id, LoginInfo.UserId, LoginInfo.Token);
 | ||
| 
 | ||
|                 //  Thread.CurrentThread.Join(10);
 | ||
|                 //}
 | ||
| 
 | ||
| 
 | ||
|             }
 | ||
|             catch (Exception er)
 | ||
|             {
 | ||
|                
 | ||
|                 MessageBox.Show("出错了:" +er.Message);
 | ||
|             }
 | ||
|             Cursor.Current = Cursors.Default;
 | ||
| 
 | ||
|             tb1.SelectedIndex = 0;
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|         private void textBoxNum_KeyUp(object sender, KeyEventArgs e)
 | ||
|         {
 | ||
|             repIn();
 | ||
|         }
 | ||
| 
 | ||
|         private void textBoxGoods_TextChanged(object sender, EventArgs e)
 | ||
|         {
 | ||
| 
 | ||
|         }
 | ||
| 
 | ||
|     }
 | ||
| } |