ldj/wince/DeiNiuWmsWINCE2/forms/RepStockIn.cs

601 lines
17 KiB
C#
Raw Normal View History

2023-05-23 16:13:17 +08:00
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 flowNo = "";
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();
focusOn(txtFlow,"下架容器码");
}
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()
{
flowNo = txtFlow.Text;
dtIns = null;
if (String.IsNullOrEmpty(flowNo))
{
focusOn(txtFlow, "下架容器码");
return;
}
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
try
{
dtIns = client.repInDetailsByFlowNo(flowNo);
}
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();
if (dtIns.Rows.Count > 0)
{
focusOn(txtGoodId, "商品主条码");
}
else
{
focusOn(txtFlow, "下架容器码");
}
}
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;
showErrorMsg(e);
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)
{
if (rbAuto.Checked)
{
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;
}
DataView dv = dtIns.DefaultView;
if (dg1.CurrentRowIndex < 0 || dv.Count <= 0 || dg1.CurrentRowIndex >= dv.Count)
{
return;
}
if (dv.Count > 0)
{
orderNo = dv[dg1.CurrentRowIndex]["pickOrderNo"].ToString();
goodsId = dv[dg1.CurrentRowIndex]["goodsId"].ToString();// dg1[dg1.CurrentRowIndex, 14].ToString();
goodsName = dv[dg1.CurrentRowIndex]["商品"].ToString();// dg1[dg1.CurrentRowIndex, 0].ToString();
batch = dv[dg1.CurrentRowIndex]["批号"].ToString();// dg1[dg1.CurrentRowIndex, 4].ToString();
skuId = Convert.ToInt16(dv[dg1.CurrentRowIndex]["skuId"].ToString());
count = Convert.ToDecimal(dv[dg1.CurrentRowIndex]["数量"].ToString()); //Convert.ToDecimal(dg1[dg1.CurrentRowIndex, 1].ToString());
goodsType = dv[dg1.CurrentRowIndex]["商品类别"].ToString(); //dg1[dg1.CurrentRowIndex, 6].ToString();
id = Convert.ToInt32(dv[dg1.CurrentRowIndex]["id"].ToString());
}
lbGoods.Text = goodsName;
lbBatch.Text = batch;
lbCount.Text = count+"";
lbType.Text = goodsType;
txtLocation.Text = "";
txtLocation.Focus();
}
void clear()
{
orderNo =
goodsId =
batch = "";
goodsName = "";
skuId = 0;
count = 0;
lbGoods.Text = goodsId;
lbBatch.Text = batch;
lbType.Text=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
{
focusOn(textBoxNum, "正确的上架数量");
return;
}
string locId = txtLocation.Text;
if (string.IsNullOrEmpty(locId))
{
focusOn(txtLocation, "目标货位码");
txtLocation.Focus();
return;
}
if (putIn(locId, skuId,goodsId, batch, inCount, id))
{
count -= inCount;
if (count <= 0)
{
tb1.SelectedIndex = 0;
return;
}
lbCount.Text = count + "";
// setDetail();
txtLocation.Text = "";
textBoxNum.Text = "";
}
focusOn(txtLocation, "目标货位码");
}
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("条件不符,不能入库");
focusOn(txtLocation,"目标货位码");
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;
showErrorMsg(e);
return false;
}
Cursor.Current = Cursors.Default;
if (result != enumRepResult.)
{
MessageBox.Show("入库失败:" + result.ToString());
focusOn(txtLocation, "目标货位码");
return false;
}
return true;
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (!isAuto)
{
return;
}
if (e.KeyCode == Keys.Enter)
{
string locId = txtLocation.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 ="";
focusOn(txtLocation );
}
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();
txtLocation.Text = dg2[dg2.CurrentRowIndex, 0].ToString();
}
private void button1_Click(object sender, EventArgs e)
{
bindBg1();
}
private void textBoxGoods_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
flowNo = txtFlow.Text.Trim();
bindBg1();
}
}
private void btnComplete_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(goodsId))
{
return;
}
Message me = new Message();
me.title = "您确认此条补货已完成入库 ";
if (me.ShowDialog() == DialogResult.Cancel)
{
focusOn(txtLocation);
return;
}
Cursor.Current = Cursors.WaitCursor;
try
{
//int i =0;
//while(i<50){
// i++;
client.finishBatchValidateItem(orderNo, id, LoginInfo.UserId,0, 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)
{
if (e.KeyCode == Keys.Enter)
{
if (isAuto)
{
return;
}
repIn();
}
}
private void txtGoodId_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string goodsBarcode = txtGoodId.Text;
if (string.IsNullOrEmpty(goodsBarcode))
{
txtGoodId.Focus();
return;
}
DataView dv = dtIns.DefaultView;
dv.RowFilter = string.Format("barcode='{0}'", goodsBarcode);
if (dv.Count >= 1)
{
tb1.SelectedIndex = 1;
focusOn(txtLocation,"目标货位码");
}
//dv.RowFilter = "";
txtGoodId.Text = "";
}
}
}
}