ldj/wince/DeiNiuWmsWINCE/forms/StockReceive.cs

925 lines
28 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Tools.ServiceModel;
using DeiNiu.Wms.CE.Util;
namespace DeiNiu.Wms.CE
{
public partial class StockReceive : basicForm
{
string preInOrder,goodsId ,owner= "";
DataTable dtPreIn,dtBulks;
decimal bigCount, maxReceiveCnt ,maxValidCnt= 0;
int expiringDays =0;
bool canReceive, canValid;
decimal packCount = 0, bulkCount = 0;
public StockReceive()
{
InitializeComponent();
//client = new WmsOutPickRequestClient(WcfHelp.getBasicBinding(), WcfHelp.getEndpoint("WmsOutPickRequestService"));
}
private void StockReceive_Load(object sender, EventArgs e)
{
initialData();
}
void setDebug()
{
//#if Debug
// textPreInNo.Text = "PREIN2021072600000510";
// this.txtValidGdBarcod.Text = "0000100001";
// this.txtReceiveGdBarcod.Text = "0000100001";
// #endif
}
void initialData()
{
canReceive = WmsConstants.auths.Contains(WmsConstants.PERMISSION_RECEIVE);
canValid = WmsConstants.auths.Contains(WmsConstants.PERMISSION_VALID);
btnReceive.Enabled = canReceive;
btnValid.Enabled = canValid;
dtPreIn = null;
initialFirstTabData();
initialSecondTabData();
initialThirdTabData();
initialFourthTabData();
textPreInNo.Focus();
//tb1.SelectedIndex = 1;
dtpValidTo.Value = dtpProduct.Value.AddDays(expiringDays);
setDebug();
}
void initialFirstTabData()
{
textPreInNo.Focus();
lbvender.Text = lbVeNo.Text = lbPhone.Text = "";
}
void initialSecondTabData()
{
goodsId = "";
lbPackcnt2.Text = txtReceiveGdBarcod.Text = lbGoodsName1.Text = lbPackcnt.Text = lbUnit.Text = lbArriveNum.Text = lbNotReceived.Text = txtWendu.Text =
txtReceivePkgNum.Text = txtBulkCnt.Text = "";
chkZhitong.Checked = false;
chkNoQc.Checked = false;
btnReceive.Enabled = false;
rdReceive.Checked = true;
rdRefuse.Checked = false;
txtReceiveGdBarcod.Focus();
setDebug();
}
void initialThirdTabData()
{
packCount = bulkCount = 0;
btnValid.Enabled = false;
goodsId = "";
txtValidGdBarcod.Text= lbExpiryDays.Text = lbGoodsName2.Text = txtBatchBoxCnt.Text =
lbToValidCnt.Text = txtBatch.Text = txtSeedsNum.Text = lbSeedsCnt.Text = "";
rdValidPass.Checked = true;
rdValidFaild.Checked = false;
txtValidGdBarcod.SelectAll();
txtValidGdBarcod.Focus();
chkDouble.Checked = false;
setDebug();
}
void initialFourthTabData()
{
// btnInPlate.Enabled = false;
// txtPlateId.Focus();
// txtSkuId.Text = txtPlateId.Text = "";
dgResult.DataSource = null;
}
private void dg1_DoubleClick(object sender, EventArgs e)
{
if (dg1.DataSource == null || dg1.CurrentRowIndex < 0)
{
return;
}
// preInOrder = dg1[dg1.CurrentRowIndex, 0].ToString();
// showTranPickRequests();
}
/*
void showTranPickRequests()
{
if (dg1.DataSource == null)
{
return;
}
if (dg1.CurrentRowIndex < 0)
{
return;
}
if (string.IsNullOrEmpty(preInOrder))
{
return;
}
lbGoodsName1.Text = preInOrder;
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
try
{
dtBulks = client.getTransRequestsDetail(preInOrder,0);
Cursor.Current = System.Windows.Forms.Cursors.Default;
}
catch (Exception er)
{
Cursor.Current = System.Windows.Forms.Cursors.Default;
MessageBox.Show("发生错误:" + er.Message);
return;
}
bindBg2(dtBulks);
tb1.SelectedIndex = 1;
txtReceiveGdBarcod.Focus();
lbGoodsName1.Text = dtBulks.Rows.Count> 0 ? preInOrder :"";
}
*/
private void tb1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tb1.SelectedIndex == 0)
{
// bindBg1();
textPreInNo.Focus();
}
else if(tb1.SelectedIndex == 1)
{
txtReceiveGdBarcod.Focus();
}
else if (tb1.SelectedIndex == 2)
{
txtShelfNo.Focus();
}
else if (tb1.SelectedIndex == 3)
{
queryValidResult();
}
}
void queryValidResult()
{
if (dtPreIn != null && !String.IsNullOrEmpty(preInOrder))
{
DataTable dt;
try
{
bool canSeePartsTasks = WmsConstants.auths.Contains(WmsConstants.SPECIAL_ALL_PARTION_TASKS);
dt = client.getPreValidResult(preInOrder, "", LoginInfo.UserId, LoginInfo.Token,canSeePartsTasks);
dgResult.DataSource = dt;
}
catch (Exception er)
{
Cursor.Current = System.Windows.Forms.Cursors.Default;
showErrorMsg(er, "发生错误");
return;
}
Cursor.Current = System.Windows.Forms.Cursors.Default;
dgResult.TableStyles.Clear();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dt.TableName;
dgResult.TableStyles.Add(ts);
ts.GridColumnStyles[0].Width = 65;
ts.GridColumnStyles[1].Width = 85;
ts.GridColumnStyles[2].Width = 35;
ts.GridColumnStyles[3].Width = 35;
ts.GridColumnStyles[4].Width = 0;
ts.GridColumnStyles[5].Width = 0;
ts.GridColumnStyles[6].Width = 60;
ts.GridColumnStyles[7].Width = 0;
ts.GridColumnStyles[8].Width = 0;
}
}
private void dg1_CurrentCellChanged(object sender, EventArgs e)
{
}
private void bindPreIn(string preInNo)
{
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
initialData();
try
{
dtPreIn = client.getPreInDetail(preInNo,LoginInfo.UserId,LoginInfo.Token);
dg1.DataSource = dtPreIn;
if (dtPreIn.Rows.Count > 0)
{
lbvender.Text = dtPreIn.Rows[0]["供应商名称"].ToString();
lbVeNo.Text = dtPreIn.Rows[0]["车牌"].ToString();
lbPhone.Text = dtPreIn.Rows[0]["电话"].ToString();
}
}
catch (Exception er)
{
Cursor.Current = System.Windows.Forms.Cursors.Default;
// MessageBox.Show("发生错误:" +getExceptionMsg( er));
showErrorMsg(er, "发生错误");
return;
}
Cursor.Current = System.Windows.Forms.Cursors.Default;
dg1.TableStyles.Clear();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dtPreIn.TableName;
dg1.TableStyles.Add(ts);
// [商品名称] [上架数量] ,[预到数量] ,[验收数量] ,[温度],[车牌] ,[运单] ,[电话]
ts.GridColumnStyles[0].Width = 55;
ts.GridColumnStyles[1].Width = 35;
ts.GridColumnStyles[2].Width = 35;
ts.GridColumnStyles[3].Width = 35;
ts.GridColumnStyles[4].Width = 35;
/*ts.GridColumnStyles[5].Width = 0;
ts.GridColumnStyles[6].Width = 0;
ts.GridColumnStyles[9].Width = 80;
ts.GridColumnStyles[11].Width =70;
* */
}
private void textPreInNo_KeyUp(object sender, KeyEventArgs e)
{
preInOrder = textPreInNo.Text;
if (string.IsNullOrEmpty(preInOrder))
{
textPreInNo.Focus();
return;
}
if (e.KeyCode == Keys.Enter || e.KeyCode ==Keys.Space)
{
bindPreIn(preInOrder);
}
}
bool isPreInOrderOkay()
{
if (dtPreIn != null)
{
return true;
}
else
{
MessageBox.Show("请输入预到单");
tb1.SelectedIndex = 0;
initialFirstTabData();
return false;
}
}
private void textGdbarcode_KeyUp(object sender, KeyEventArgs e)
{
string goodBarcod = txtReceiveGdBarcod.Text;
if (e.KeyCode == Keys.Enter)
{
if (!isPreInOrderOkay())
{
return;
}
if (string.IsNullOrEmpty(goodBarcod))
{
// MessageBox.Show("请选择运单");
txtReceiveGdBarcod.Focus();
return;
}
getDataByGoodsBarcode(goodBarcod);
}
}
void getDataByGoodsBarcode(string goodsBarcod)
{
if (String.IsNullOrEmpty(preInOrder))
{
MessageBox.Show("请输入预到号码");
tb1.SelectedIndex = 0;
return;
}
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
DataTable dtPreDetail = client.getReceiveDetailByBarcode(preInOrder,goodsBarcod);
Cursor.Current = System.Windows.Forms.Cursors.Default;
if (dtPreDetail.Rows.Count == 0)
{
MessageBox.Show("没找到数据");
initialSecondTabData();
txtReceiveGdBarcod.SelectAll();
txtReceiveGdBarcod.Focus();
return;
}
string packQty = dtPreDetail.Rows[0]["packingQty"].ToString();
packQty = dtPreDetail.Rows[0]["bigCount"].ToString();
lbGoodsName1.Text = lbGoodsName2.Text = dtPreDetail.Rows[0]["goodsName"].ToString();
goodsId = dtPreDetail.Rows[0]["goodsId"].ToString();
string isQc = dtPreDetail.Rows[0]["isQc"].ToString();
string isZhitong = dtPreDetail.Rows[0]["isZhitong"].ToString();
lbUnit.Text = dtPreDetail.Rows[0]["unit"].ToString();
lbArriveNum.Text = dtPreDetail.Rows[0]["newArriveCount"].ToString();
lbNotReceived.Text = dtPreDetail.Rows[0]["newCount4Receive"].ToString();
lbToValidCnt.Text = dtPreDetail.Rows[0]["newCount4Valid"].ToString();
lbExpiryDays.Text = dtPreDetail.Rows[0]["expiryDays"].ToString();
chkDouble.Checked = dtPreDetail.Rows[0]["isDouChk"].ToString()=="Y";
owner = dtPreDetail.Rows[0]["entid"].ToString();
lbOwner.Text = dtPreDetail.Rows[0]["ORGNAME"].ToString();
if (dtPreDetail.Rows[0]["orderType"].ToString() == "1")
{
dtpProduct.Visible = false;
dtpValidTo.Visible = false;
txtBatch.Text = dtPreDetail.Rows[0]["batch"].ToString();
this.txtPrdDate.Text = dtPreDetail.Rows[0]["productDate"].ToString();
this.txtValidDate.Text = dtPreDetail.Rows[0]["validDate"].ToString();
txtValidDate.ReadOnly = true;
txtPrdDate.ReadOnly = true;
}
txtBatch.ReadOnly = !dtpProduct.Visible;
txtPrdDate.Visible = !dtpProduct.Visible;
txtValidDate.Visible = !dtpValidTo.Visible;
txtSeedsNum.ReadOnly = txtBatch.ReadOnly;
btnSeeds.Enabled = !txtBatch.ReadOnly;
try
{
chkNoQc.Checked = Convert.ToInt16(isQc) == 0;
chkZhitong.Checked = Convert.ToInt16(isZhitong) != 0;
expiringDays = Convert.ToInt16(lbExpiryDays.Text);
}
catch (Exception er)
{
}
try
{
bigCount = Convert.ToDecimal(packQty);
maxReceiveCnt = Convert.ToDecimal(lbNotReceived.Text);
maxValidCnt = Convert.ToDecimal(lbToValidCnt.Text);
if (this.tb1.SelectedIndex == 1)
{
btnReceive.Enabled = maxReceiveCnt > 0;
decimal bulkCnt = maxReceiveCnt % bigCount;
decimal boxCnt =( maxReceiveCnt - bulkCnt) / bigCount;
txtReceivePkgNum.Text = boxCnt + "";
txtBulkCnt.Text = bulkCnt + "";
}
else
{
btnValid.Enabled = maxValidCnt > 0;
decimal bulkCnt = maxValidCnt % bigCount;
decimal boxCnt = (maxValidCnt - bulkCnt) / bigCount;
txtBatchBoxCnt.Text = boxCnt + "";
txtBachCnt.Text = bulkCnt + "";
}
lbPackcnt2.Text= lbPackcnt.Text = bigCount + "";
}
catch (Exception er)
{
bigCount = 1;
}
}
decimal getReceiveCount()
{
string pkcnt = txtReceivePkgNum.Text.Trim();
string bulkcnt = txtBulkCnt.Text.Trim();
if (String.IsNullOrEmpty(pkcnt) && String.IsNullOrEmpty(bulkcnt))
{
MessageBox.Show("请输入收货数量");
txtReceivePkgNum.Focus();
return 0;
}
try
{
if (!String.IsNullOrEmpty(pkcnt))
{
packCount = Convert.ToDecimal(pkcnt);
}
}
catch (Exception er)
{
MessageBox.Show("请输入收货数量");
txtReceivePkgNum.SelectAll();
txtReceivePkgNum.Focus();
return 0;
}
try
{
if (!String.IsNullOrEmpty(bulkcnt))
{
bulkCount = Convert.ToDecimal(bulkcnt);
}
}
catch (Exception er)
{
MessageBox.Show("请输入收货数量");
txtBulkCnt.SelectAll();
txtBulkCnt.Focus();
return 0;
}
decimal count = packCount * bigCount + bulkCount;
if (count == 0)
{
MessageBox.Show("请输入收货数量");
txtReceivePkgNum.Focus();
return 0;
}
return count;
}
private void btnReceive_Click(object sender, EventArgs e)
{
string tmp = txtWendu.Text.Trim();
decimal temperature = -100;
try
{
if (!String.IsNullOrEmpty(tmp))
{
temperature = Convert.ToDecimal(tmp);
}
}
catch (Exception er)
{
MessageBox.Show("请输入温度");
txtWendu.SelectAll();
txtWendu.Focus();
return;
}
decimal count = getReceiveCount();
if (count > maxReceiveCnt)
{
MessageBox.Show("超过最大应收数量:" + maxReceiveCnt);
txtReceivePkgNum.SelectAll();
txtReceivePkgNum.Focus();
return;
}
if (count <= 0) { return; }
try
{
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
decimal arriveCnt = Convert.ToDecimal(lbArriveNum.Text);
int intype = rdReceive.Checked?0:1;//pass
bool rt = client.receiveDetail(preInOrder, goodsId, arriveCnt, count, intype, "", temperature, chkZhitong.Checked, 0, LoginInfo.UserId, LoginInfo.Token);
Cursor.Current = System.Windows.Forms.Cursors.Default;
if (rt)
{
MessageBox.Show("收货成功!");
initialSecondTabData();
if (chkValid.Checked)
{
tb1.SelectedIndex = 2;//验收
txtValidGdBarcod.Text = txtReceiveGdBarcod.Text;
lbGoodsName2.Text = lbGoodsName1.Text;
}
}
}
catch (Exception er)
{
//MessageBox.Show("收货失败!");
showErrorMsg(er, "收货失败");
Cursor.Current = System.Windows.Forms.Cursors.Default;
}
}
private void txtValidGdBarcod_KeyUp(object sender, KeyEventArgs e)
{
string goodBarcod = txtValidGdBarcod.Text;
if (e.KeyCode == Keys.Enter)
{
if (!isPreInOrderOkay())
{
return;
}
if (string.IsNullOrEmpty(goodBarcod))
{
// MessageBox.Show("请选择运单");
txtValidGdBarcod.Focus();
return;
}
getDataByGoodsBarcode(goodBarcod);
dtpValidTo.Value = dtpProduct.Value.AddDays(expiringDays);
// txtBatchBoxCnt.Text = maxValidCnt+"";
// txtBatchBoxCnt.Focus();
}
}
private void btnSeeds_Click(object sender, EventArgs e)
{
decimal batchCnt = getValidCount();;
if(batchCnt<=0){
return;
}
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
decimal seedsNum = client.getValidSeedsCnt(goodsId,batchCnt );
Cursor.Current = System.Windows.Forms.Cursors.Default;
lbSeedsCnt.Text = seedsNum + "";
txtSeedsNum.Text = seedsNum+"";
}
decimal getValidCount()
{
string batchBoxCnt = txtBatchBoxCnt.Text.Trim();
string batchCnt = txtBachCnt.Text.Trim();
decimal packCount=0, bulkCount=0 ;
if (String.IsNullOrEmpty(batchBoxCnt) && String.IsNullOrEmpty(batchCnt))
{
MessageBox.Show("请输入验收数量");
txtBatchBoxCnt.Focus();
return 0;
}
try
{
if (!String.IsNullOrEmpty(batchBoxCnt))
{
packCount = Convert.ToDecimal(batchBoxCnt);
}
}
catch (Exception er)
{
MessageBox.Show("请输入验收数量");
txtBatchBoxCnt.Focus();
return 0;
}
try
{
if (!String.IsNullOrEmpty(batchCnt))
{
bulkCount = Convert.ToDecimal(batchCnt);
}
}
catch (Exception er)
{
MessageBox.Show("请输入验收数量");
txtBachCnt.Focus();
return 0;
}
decimal count = packCount * bigCount + bulkCount;
if (count == 0)
{
MessageBox.Show("请输入验收数量");
txtReceivePkgNum.Focus();
return 0;
}
return count;
}
private void btnValid_Click(object sender, EventArgs e)
{
// chkDouble.Checked = true;
if (chkDouble.Checked)
{
validLogin vl = new validLogin();
vl.setRole(WmsConstants.PERMISSION_VALID);
vl.ShowDialog();
}
if (chkDouble.Checked)
{
if (WmsConstants.SECOND_VALID_ER ==LoginInfo.UserId || WmsConstants.SECOND_VALID_ER <= 0)
{
MessageBox.Show("非法的第二验收人,验收失败");
return;
}
}
if (txtSeedsNum.ReadOnly)
{
txtSeedsNum.Text = txtBatchBoxCnt.Text;
}
string batch = txtBatch.Text.Trim();
string flowNo ="";
string seedsCnt = txtSeedsNum.Text.Trim();
decimal seedsCount = -100;
decimal count = getValidCount();
if (count <= 0 )
{
return;
}
if (count > maxValidCnt)
{
getDataByGoodsBarcode(this.txtValidGdBarcod.Text.Trim());//refresh data from svr.
if (count > maxValidCnt)
{
return;
}
}
try
{
if (!String.IsNullOrEmpty(seedsCnt))
{
seedsCount = Convert.ToDecimal(seedsCnt);
}
if (seedsCount <= 0 || seedsCount > count)
{
if(!txtSeedsNum.ReadOnly)
throw new Exception();
}
}
catch (Exception er)
{
if (packCount > 0)
{
MessageBox.Show("请输入正确抽样数量");
txtSeedsNum.Focus();
return;
}
}
try
{
flowNo = txtShelfNo.Text.Trim(); ;
if (String.IsNullOrEmpty(flowNo ) )
{
throw new Exception();
}
}
catch (Exception er)
{
MessageBox.Show("请输入正确上架流水号");
txtShelfNo.SelectAll();
txtShelfNo.Focus();
return;
}
DateTime dtProd = dtpProduct.Value;
DateTime dtValidTo = dtpValidTo.Value;
if (dtProd.Equals(dtValidTo))
{
dtpValidTo.Value = dtpProduct.Value.AddDays(expiringDays);
dtValidTo = dtpValidTo.Value;
}
/*
if (dtProd.AddDays(expiringDays) != dtValidTo)
{
DialogResult dr = MessageBox.Show("警告:日期输入和商品保质期天数不匹配! 是否继续?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
if (dr == DialogResult.No)
{
return;
}
}*/
if (DateTime.Now.AddDays(expiringDays/3) > dtValidTo)
{
DialogResult dr= MessageBox.Show("警告商品剩余保质期已不足1/3是否继续","警告",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
if (dr == DialogResult.No)
{
return;
}
}
if (dtProd > dtValidTo || dtProd > DateTime.Now)
{
MessageBox.Show("日期输入错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
return;
}
string prdDate =dtpProduct.Visible? dtProd.ToShortDateString():txtPrdDate.Text;
string valDate = dtpValidTo.Visible ? dtValidTo.ToShortDateString() :this.txtValidDate.Text;
seedsCount = dtpProduct.Visible ? seedsCount : count;
if (String.IsNullOrEmpty( batch))
{
batch = prdDate;
}
string[] skuKeys = { "生产日期", "到期日期", "厂家批次" ,"货主"};
string[] skuValues = { prdDate, valDate, batch, owner };
try
{
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
bool issueLocations = true; //按流水号入库,并分配货位
enumValidInResult result =(enumValidInResult) client.validIn(preInOrder, flowNo, goodsId, count, seedsCount, skuKeys, skuValues,
rdValidPass.Checked, issueLocations,WmsConstants.SECOND_VALID_ER , LoginInfo.UserId, LoginInfo.Token);
Cursor.Current = System.Windows.Forms.Cursors.Default;
if (result == enumValidInResult.)
{
MessageBox.Show("验收成功");
initialThirdTabData();
//TODO: print sku info for into plate operation
}
else
{
MessageBox.Show("验收失败: " + result.ToString());
}
}
catch (Exception er)
{
Cursor.Current = System.Windows.Forms.Cursors.Default;
showErrorMsg(er, "验收失败");
}
WmsConstants.SECOND_VALID_ER = 0;
}
private void txtSkuId_KeyUp(object sender, KeyEventArgs e)
{
}
private void rdValidFaild_Click(object sender, EventArgs e)
{
rdValidPass.Checked = !rdValidFaild.Checked;
}
private void rdValidPass_Click(object sender, EventArgs e)
{
rdValidFaild.Checked = !rdValidPass.Checked;
}
private void dtpProduct_ValueChanged(object sender, EventArgs e)
{
dtpValidTo.Value = dtpProduct.Value.AddDays(expiringDays);
}
private void rdReceive_Click(object sender, EventArgs e)
{
rdRefuse.Checked = !rdReceive.Checked;
}
private void rdRefuse_Click(object sender, EventArgs e)
{
rdReceive.Checked = !rdRefuse.Checked;
}
private void txtShelfNo_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (!isPreInOrderOkay())
{
return;
}
txtValidGdBarcod.SelectAll();
txtValidGdBarcod.Focus();
}
}
private void textPreInNo_GotFocus(object sender, EventArgs e)
{
textPreInNo.SelectAll();
}
private void txtReceiveGdBarcod_GotFocus(object sender, EventArgs e)
{
txtReceiveGdBarcod.SelectAll();
}
private void txtShelfNo_GotFocus(object sender, EventArgs e)
{
txtShelfNo.SelectAll();
}
private void txtValidGdBarcod_GotFocus(object sender, EventArgs e)
{
txtValidGdBarcod.SelectAll();
}
}
}