ldj/wince/DeiNiuWmsWINCE/forms/StockIn.cs

465 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 DeiNiu.Wms.CE.Util;
namespace DeiNiu.Wms.CE
{
public partial class StockIn : basicForm
{
// WmsOutPickRequestClient client { get; set; }
string id = string.Empty;
int state = 1;
string location = string.Empty;
decimal count = 0m;
bool canUp;
string flowNo = string.Empty;
bool showFinished = true;
DataView dv1 =null;
string hint ="";
enumStockRecordType recType = enumStockRecordType.;
public StockIn()
{
InitializeComponent();
initialComBoxes();
setTitle();
focusOn(txtShelfId, hint);
// client = new WmsOutPickRequestClient(WcfHelp.getBasicBinding(), WcfHelp.getEndpoint("WmsOutPickRequestService"));
}
//先扫出库码,再扫货位
private void goodscode_txt_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
// if (state == 1) //已出库的自动清空数据,继续扫下一个出库码
//{
// clear();
// }
string barCode = barcode_txt.Text;
if (string.IsNullOrEmpty(barCode))
return;
//判断货位号是否不为空
if ((canUp) && !string.IsNullOrEmpty(locationid_lab.Text))
{
//扫描货位时,比较是否相同
if (location.ToUpper().Equals((barCode + "x").ToUpper()))
{
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
enumRepResult result ;
try
{
result = (enumRepResult)client.finishUpShelfItem(flowNo, Convert.ToInt32(id), count,
barCode.ToUpper(), "", LoginInfo.UserId, LoginInfo.Token);
Cursor.Current = System.Windows.Forms.Cursors.Default;
if (result != enumRepResult.)
{
MessageBox.Show("入库失败:" + result);
barcode_txt.Text = "";
// return ;
}
getTasks(flowNo);
barcode_txt.Text = "";
//MessageBox.Show("!");
if (dv1!=null && dv1.Count == 1)
{
this.GetGoodsData(dg1[0, 8].ToString());
}else
clear();
}
catch(Exception er)
{
showErrorMsg(er, "上架失败!");
Cursor.Current = System.Windows.Forms.Cursors.Default;
}
}
else
{
barcode_txt.Text = "";
MessageBox.Show("货位不符合");
}
}
else//为空,说明是扫描的出库码
{
barcode_txt.Text = "";
//条件扫描的条码值 获取货位、商品信息
GetGoodsData(barCode);
}
focusOn(barcode_txt, hint);
}
}
private void GetGoodsData(string portId)
{
try
{
Convert.ToInt32(portId);
}
catch
{
MessageBox.Show("请先扫描输入上架流水号");
return;
}
try
{
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
DataTable dt = client.getStockInPortDetail(Convert.ToInt32(portId));
Cursor.Current = System.Windows.Forms.Cursors.Default;
if (dt.Rows.Count > 0)
{
name_lab.Text = dt.Rows[0]["goodsName"].ToString();
spec_lab.Text = dt.Rows[0]["spec"].ToString();
unit_lab.Text = dt.Rows[0]["unit"].ToString();
PCompany_lab.Text = dt.Rows[0]["manufacturer"].ToString();
owner.Text = dt.Rows[0]["owner"].ToString();
Stocknum_lab.Text = ""+(Convert.ToInt32(dt.Rows[0]["count"].ToString()) - Convert.ToInt32(dt.Rows[0]["upCount"].ToString()));
count = Convert.ToDecimal(Stocknum_lab.Text);
locationid_lab.Text = dt.Rows[0]["locationId"].ToString();
location = locationid_lab.Text + "x";
batch_lab.Text = dt.Rows[0]["batch"].ToString();
product_date_lab.Text = dt.Rows[0]["productdate"].ToString();
save_date_lab.Text = dt.Rows[0]["validDate"].ToString();
order_id_lab.Text = dt.Rows[0]["orderNo"].ToString();
lbVender.Text = dt.Rows[0]["vender"].ToString();
id = dt.Rows[0]["id"].ToString();
state = Convert.ToInt16(dt.Rows[0]["state"].ToString());
enumInStockDetailStatus status = (enumInStockDetailStatus)state;
recType = (enumStockRecordType)Convert.ToInt16(dt.Rows[0]["recType"].ToString());
// label12.Text = state == 1 ? "待上架" : state == 5 ? "已上架" : state == 6 ? "部分上架" :"其它";
bigcount_lab.Text = dt.Rows[0]["bigcount"].ToString();
// double intnum = Convert.ToDouble(Convert.ToDouble(dt.Rows[0]["count"].ToString()) / Convert.ToDouble(dt.Rows[0]["bigcount"].ToString()));
// int_lab.Text = intnum.ToString();
int_lab.Text = dt.Rows[0]["box"].ToString();
canUp = status == enumInStockDetailStatus. || status == enumInStockDetailStatus.;
if (recType == enumStockRecordType.)
{
canUp = true;
status = enumInStockDetailStatus.;
}
label12.Text = status + "";
barcode_txt.Enabled = canUp;
txt_loc.Text = "";
if (canUp)
{
tabControl1.SelectedIndex = 1;
}
lbRecommand.Text = locationid_lab.Text;
lbstatus.Text = label12.Text;
btnUp.Enabled = canUp;
txtCount.Text = count+"";
}
else
{
clear();
//code = "";
//row_lab.Text = "";
barcode_txt.Focus();
}
#if DEBUG
barcode_txt.Text = locationid_lab.Text;
#endif
}
catch (Exception er)
{
showErrorMsg(er, "获取数据失败!");
// MessageBox.Show("获取数据失败!" + er.Message);
}
}
/// <summary>
/// 清除界面数据
/// </summary>
private void clear()
{
name_lab.Text =
spec_lab.Text =
unit_lab.Text =
PCompany_lab.Text =
owner.Text =
Stocknum_lab.Text =
locationid_lab.Text =
batch_lab.Text =
product_date_lab.Text =
save_date_lab.Text =
int_lab.Text =
order_id_lab.Text =
bigcount_lab.Text =
id = "";
state = 1;
label12.Text = "";
location = "";
this.comboBox1.SelectedIndex = 0;
txt_loc.Text = "";
txtCount.Text = "";
lbVender.Text = "";
lbstatus.Text = "无";
lbRecommand.Text = "";
btnUp.Enabled = barcode_txt.Enabled = false;
chkNotfinished.Checked = showFinished;
}
private void initialComBoxes()
{
Utils.buildCombox(5003, this.comboBox1);
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string locID = this.txt_loc.Text.ToString();
if (String.IsNullOrEmpty(locID))
{
MessageBox.Show("请输入货位!");
txt_loc.Focus();
return;
}
decimal count = 0m;
try
{
count = Convert.ToDecimal(txtCount.Text.ToString());
}
catch
{
MessageBox.Show("请输入数量!");
txtCount.Focus();
return;
}
if (this.comboBox1.SelectedIndex == 0)
{
MessageBox.Show("请选择原因!");
comboBox1.Focus();
return;
}
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
enumRepResult result ;
try
{
result = (enumRepResult)client.finishUpShelfItem(flowNo, Convert.ToInt32(id), count, locID, this.comboBox1.Text, LoginInfo.UserId, LoginInfo.Token);
Cursor.Current = System.Windows.Forms.Cursors.Default;
if (result != enumRepResult.)
{
Cursor.Current = System.Windows.Forms.Cursors.Default;
MessageBox.Show( result.ToString());
Cursor.Current = System.Windows.Forms.Cursors.Default;
return ;
}else
{
getTasks(flowNo);
if (dv1 != null && dv1.Count == 1)
{
this.GetGoodsData(dg1[0, 8].ToString());
}
else
clear();
}
}
catch (Exception er)
{
showErrorMsg(er, "上架失败!");
//MessageBox.Show("上架失败!" + er.Message);
}
Cursor.Current = System.Windows.Forms.Cursors.Default;
}
catch (Exception er)
{
showErrorMsg(er, "出错了");
}
Cursor.Current = System.Windows.Forms.Cursors.Default;
}
private void dg1_DoubleClick(object sender, EventArgs e)
{
}
private void dg1_CurrentCellChanged(object sender, EventArgs e)
{
}
private void txtShelfId_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string barCode = this.txtShelfId .Text;
if (string.IsNullOrEmpty(barCode))
{
// return;
}
try
{
flowNo = barCode ;
getTasks( flowNo);
}
catch (Exception er)
{
MessageBox.Show("请输入正确的上架流水号");
txtShelfId.SelectAll();
txtShelfId.Focus();
return;
}
}
}
void getTasks(string flowNo)
{
//判断货位号是否不为空
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
try
{
DataTable dt;
bool canSeePartsTasks = WmsConstants.auths.Contains(WmsConstants.SPECIAL_ALL_PARTION_TASKS);
dt = client.getPreValidResult("", flowNo, LoginInfo.UserId, LoginInfo.Token, canSeePartsTasks);
dv1 = dt.DefaultView;
// dv1.RowFilter = "diffCount>0";
setRowfilter();
dv1.Sort = "diffCount desc";
dg1.DataSource = dv1;
// DataView dv2 = dt.DefaultView;
// dv2.RowFilter = "diffCount=0";
// dg2.DataSource = dv2;
Cursor.Current = System.Windows.Forms.Cursors.Default;
dg1.TableStyles.Clear();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dt.TableName;
dg1.TableStyles.Add(ts);
// dg2. TableStyles.Add(ts);
// [商品名称] [上架数量] ,[预到数量] ,[验收数量] ,[温度],[车牌] ,[运单] ,[电话]
ts.GridColumnStyles[0].Width = 40;
ts.GridColumnStyles[1].Width = 65;
ts.GridColumnStyles[2].Width = 85;
ts.GridColumnStyles[3].Width = 35;
ts.GridColumnStyles[4].Width = 35;
ts.GridColumnStyles[5].Width = 0;
ts.GridColumnStyles[6].Width = 0;
ts.GridColumnStyles[7].Width = 0;
ts.GridColumnStyles[8].Width = 0;
clear();
tabControl1.SelectedIndex = 0;
// if (dv1.Count == 1)
{
// this.GetGoodsData(dg1[0, 8].ToString());
}
}
catch (Exception er)
{
showErrorMsg(er);
}
Cursor.Current = System.Windows.Forms.Cursors.Default;
}
private void dg1_DoubleClick_1(object sender, EventArgs e)
{
if (dg1.DataSource == null || dg1.CurrentRowIndex < 0)
{
return;
}
this.GetGoodsData(dg1[dg1.CurrentRowIndex, 9].ToString());
this.tabControl1.SelectedIndex = 1;
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 0)
{
txtShelfId.SelectAll();
txtShelfId.Focus();
}
else if (tabControl1.SelectedIndex == 1)
{
barcode_txt.SelectAll();
barcode_txt.Focus();
}
else if (tabControl1.SelectedIndex == 2)
{
txt_loc.SelectAll();
txt_loc.Focus();
}
}
private void chkNotfinished_Click(object sender, EventArgs e)
{
showFinished = chkNotfinished.Checked;
setRowfilter();
}
void setRowfilter()
{
if (dv1 != null)
{
dv1.RowFilter = showFinished ? "diffCount>0" : "";
}
}
}
}