You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
513 lines
20 KiB
513 lines
20 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using ICSSoft.Frame.User.BLL;
|
|
using ICSSoft.Base.Language.Tool;
|
|
using ICSSoft.Base.UserControl.MessageControl;
|
|
using System.Data.SqlClient;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Base.Report.Filter;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.UserControl.FormControl;
|
|
using ICSSoft.Base.ReferForm.AppReferForm;
|
|
using ICSSoft.Base.Lable.PrintTool;
|
|
using ICSSoft.Frame.Data.BLL;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using System.Collections;
|
|
|
|
namespace ICSSoft.Frame.APP
|
|
{
|
|
public partial class FormICSPOArriveLOTCreate : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
private FormICSRdrecord2LOTUIModelX RecInfo;
|
|
private string cCode;
|
|
private string irowno;
|
|
private string cInvCode;
|
|
private string Batch;
|
|
private bool isVenBatch = false;//判断是否要有供应商炉批号
|
|
private bool isBatch = false;//判断是否要有批次号
|
|
private bool isCheck = false;//判断是否需要检验
|
|
public string[] Codes = { "4101", "4102", "4701", "4301", "4302", "4702", "4703", "111301", "4201", "4202", "43", "46" };
|
|
|
|
#region 构造函数
|
|
public FormICSPOArriveLOTCreate()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public FormICSPOArriveLOTCreate(string _cCode, string _irowno, string _cInvCode, string _Batch)
|
|
{
|
|
InitializeComponent();
|
|
chkBtnAll.Checked = false;
|
|
chkBtnAll.Checked = true;
|
|
|
|
cCode = _cCode;
|
|
irowno = _irowno;
|
|
cInvCode = _cInvCode;
|
|
Batch = _Batch;
|
|
if (Batch != "")
|
|
{
|
|
txtBatch.Text = Batch;
|
|
}
|
|
|
|
CheckData();
|
|
GetRecInfo();
|
|
if (RecInfo == null)
|
|
{
|
|
throw new Exception("到货单信息取得失败");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 移动窗体
|
|
private const int WM_NCHITTEST = 0x84;
|
|
private const int HTCLIENT = 0x1;
|
|
private const int HTCAPTION = 0x2;
|
|
//首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
|
|
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
|
|
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
|
|
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
|
|
|
|
//重写窗体,使窗体可以不通过自带标题栏实现移动
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
//当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
|
|
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
|
|
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
|
|
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
|
|
switch (m.Msg)
|
|
{
|
|
case WM_NCHITTEST:
|
|
base.WndProc(ref m);
|
|
if ((int)m.Result == HTCLIENT)
|
|
m.Result = (IntPtr)HTCAPTION;
|
|
return;
|
|
}
|
|
//拦截双击标题栏、移动窗体的系统消息
|
|
if (m.Msg != 0xA3)
|
|
{
|
|
base.WndProc(ref m);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 退出
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
#endregion
|
|
|
|
private void CheckData()
|
|
{
|
|
#region 判断是否要有批次号
|
|
DataTable dt = ICSPOArriveBLL.GetBatch(cInvCode, AppConfig.WorkPointCode, AppConfig.AppConnectString);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Rows[0]["INVCONTROLTYPE"].ToString().Trim().ToUpper() == "TRUE")
|
|
{
|
|
isBatch = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("物料存货信息取得失败");
|
|
}
|
|
#endregion
|
|
#region 判断是否要有供应商炉批号
|
|
dt = ICSPOArriveBLL.GetVen(cInvCode, AppConfig.WorkPointCode, AppConfig.AppConnectString);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
isVenBatch = true;
|
|
}
|
|
else
|
|
{
|
|
isVenBatch = false;
|
|
}
|
|
#endregion
|
|
#region //判断是否需要检验
|
|
dt = ICSPOArriveBLL.GetCheck(cInvCode, AppConfig.WorkPointCode, AppConfig.AppConnectString);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
isCheck = true;
|
|
}
|
|
#region 测试时屏蔽
|
|
//else
|
|
//{
|
|
// throw new Exception("U8物料存货信息取得失败");
|
|
// this.Close();
|
|
//}
|
|
#endregion
|
|
#endregion
|
|
}
|
|
|
|
private void GetRecInfo()
|
|
{
|
|
RecInfo = ICSPOArriveBLL.Search_Info(cCode, irowno.ToString(), AppConfig.AppConnectString);
|
|
init();
|
|
}
|
|
|
|
private void init()
|
|
{
|
|
txtVenBatch.Text = RecInfo.Arr.cBatchProperty6;
|
|
txtSumNo.Text = "";
|
|
txtNowNo.Text = "";
|
|
txtNowQty.Text = "";
|
|
txtSumQty.Text = "";
|
|
txtAllQty.Text = "";
|
|
btnLabelCreate.Enabled = true;
|
|
if (RecInfo == null)
|
|
{
|
|
return;
|
|
}
|
|
chkBtnAll.Enabled = true;
|
|
chkBtnNo.Enabled = true;
|
|
chkBtnPack.Enabled = true;
|
|
txtSumQty.Text = RecInfo.SumQty.ToString();
|
|
txtSumNo.Text = RecInfo.SumNo.ToString();
|
|
try
|
|
{
|
|
string sql = @"SELECT COUNT(C.ItemCode) AS NUM, C.ItemCode, C.LOTQTY FROM ICSPOArrive A
|
|
LEFT JOIN ICSITEMLot C ON A.cInvCode = C.ItemCode AND A.cCode = C.TransNO AND A.irowno = CONVERT(int, C.TransLine)
|
|
LEFT JOIN ICSWareHouseLotInfo D ON C.LotNO = D.LotNO WHERE A.cCode = '{0}' AND A.irowno = '{1}' AND C.ItemCode = '{2}'
|
|
GROUP BY C.ItemCode, C.LOTQTY ";
|
|
sql = string.Format(sql, cCode, irowno, RecInfo.Arr.cInvCode);
|
|
DataTable ds = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (ds.Rows.Count == 0 || ds == null)
|
|
{
|
|
txtNowQty.Text = RecInfo.SumQty.ToString();
|
|
txtNowPackQty.Text = RecInfo.SumQty.ToString();
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow dr in ds.Rows)
|
|
{
|
|
RecInfo.SumQty = RecInfo.SumQty - Decimal.Parse(dr["NUM"].ToString()) * Decimal.Parse(dr["LOTQTY"].ToString());
|
|
//txtNowQty.Text = (RecInfo.SumQty - Decimal.Parse(dr["NUM"].ToString()) * Decimal.Parse(dr["LOTQTY"].ToString())).ToString();
|
|
}
|
|
txtNowQty.Text = RecInfo.SumQty.ToString();
|
|
txtNowPackQty.Text = RecInfo.SumQty.ToString();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
//txtNowPackQty.Text = "1";
|
|
if (txtNowPackQty.Text == "0")
|
|
{
|
|
txtNowNo.Text = "0";
|
|
}
|
|
else
|
|
{
|
|
txtNowNo.Text = (Math.Ceiling(decimal.Parse(txtNowQty.Text)) / Math.Ceiling(decimal.Parse(txtNowPackQty.Text))).ToString();
|
|
}
|
|
txtAllQty.Text = (decimal.Parse(txtSumQty.Text) + decimal.Parse(txtNowQty.Text)).ToString();
|
|
txtAllNo.Text = (decimal.Parse(txtSumNo.Text) + decimal.Parse(txtNowNo.Text)).ToString();
|
|
}
|
|
|
|
private void btnLabelCreate_Click(object sender, EventArgs e)
|
|
{
|
|
if (isVenBatch)
|
|
{
|
|
if (txtVenBatch.Text.ToString().Trim() == "")
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("存货分类4101和4701,请输入供应商炉批号");
|
|
return;
|
|
}
|
|
}
|
|
string LotNO = "";
|
|
if (RecInfo == null)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("到货单信息取得失败");
|
|
return;
|
|
}
|
|
if (string.IsNullOrWhiteSpace(cCode) || string.IsNullOrWhiteSpace(irowno.ToString()))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("到货单号或到货单行号不能为空!");
|
|
return;
|
|
}
|
|
DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……");
|
|
try
|
|
{
|
|
_wait.Show();
|
|
Decimal totalQty = decimal.Parse(txtNowQty.Text);
|
|
decimal pieceQty = decimal.Parse(txtNowPackQty.Text);
|
|
int Num = int.Parse(txtNowNo.Text);
|
|
if (pieceQty * Num < totalQty || pieceQty * (Num - 1) >= totalQty)
|
|
{
|
|
throw new Exception("条码数量计算出错,请重新计算");
|
|
}
|
|
decimal Qty = decimal.Parse(txtNowPackQty.Text);
|
|
if (Num <= 0)
|
|
{
|
|
throw new Exception("条码张数不能为0");
|
|
}
|
|
if (Qty <= 0)
|
|
{
|
|
throw new Exception("条码数量不能为0");
|
|
}
|
|
List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
|
|
int count = Convert.ToInt32(RecInfo.MaxNo);
|
|
DateTime time = DateTime.Now;
|
|
string timeStr = time.ToString("yyMMdd");
|
|
int NO = 0;
|
|
string subTime = "7" + time.ToString("yyyyMMdd");
|
|
string sql = @"SELECT MAX(A.LotNO) AS LOTNO FROM ICSITEMLot A WHERE 1=1 AND A.LotNO LIKE '{0}%' ";
|
|
sql = string.Format(sql, subTime);
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["LotNO"].ToString()))
|
|
{
|
|
LotNO = dt.Rows[0]["LOTNO"].ToString();
|
|
NO = int.Parse(LotNO.Substring(LotNO.Length - 4, 4));
|
|
}
|
|
for (int i = 0; i < Num; i++)
|
|
{
|
|
//int b = NO + i + 1;
|
|
_wait.Caption = "正在生成条码……" + " " + i.ToString() + "/" + Num.ToString();
|
|
_wait.Refresh();
|
|
ICSITEMLot Info = new ICSITEMLot();
|
|
Info.ID = "";
|
|
if (Qty < totalQty - Qty * i)
|
|
{
|
|
Info.LOTQTY = Qty;
|
|
}
|
|
else
|
|
{
|
|
Info.LOTQTY = totalQty - Qty * i;
|
|
}
|
|
Info.LotNO = subTime + (NO + i + 1).ToString().PadLeft(4, '0');
|
|
Info.ItemCode = RecInfo.Arr.cInvCode;
|
|
if (RecInfo.icsitems == null)
|
|
{
|
|
Info.TransNO = RecInfo.Arr.cCode;
|
|
}
|
|
else
|
|
{
|
|
Info.TransNO = RecInfo.icsitems.TransNO;
|
|
}
|
|
if (RecInfo.icsitems == null)
|
|
{
|
|
Info.TransLine = RecInfo.Arr.irowno.ToString();
|
|
}
|
|
else
|
|
{
|
|
Info.TransLine = RecInfo.icsitems.TransLine;
|
|
}
|
|
if (isBatch)
|
|
{
|
|
if (txtBatch.Text.ToString().Trim() == "")
|
|
{
|
|
_wait.Close();
|
|
ICSBaseSimpleCode.AppshowMessageBox("物料启用了批次管理,请输入批次号");
|
|
return;
|
|
}
|
|
sql = @"SELECT * FROM Sys_EnumValues A INNER JOIN ICSINVENTORY B ON A.EnumText = B.INVCLASS
|
|
WHERE 1=1 AND A.EnumKey = '00012' AND B.INVCODE = '{0}' ";
|
|
sql = string.Format(sql, RecInfo.Arr.cInvCode);
|
|
DataTable dts = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (dts.Rows.Count > 0 && dts != null)
|
|
{
|
|
sql = @"SELECT * FROM ICSITEMLot WHERE 1=1 AND VenderLotNO = '{0}' AND type = '到货' ";
|
|
sql = string.Format(sql, txtBatch.Text.Trim());
|
|
dts = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (dts.Rows.Count > 0 && dts != null)
|
|
{
|
|
_wait.Close();
|
|
throw new Exception("此零件号重复,请确认");
|
|
}
|
|
//Info.VenderLotNO = timeStr.Substring(timeStr.Length - 6) + (RecInfo.TodayMOCount + 1).ToString().PadLeft(3, '0'); //生产批号,每个工单一个
|
|
Info.VenderLotNO = txtBatch.Text.Trim(); //批号
|
|
}
|
|
else
|
|
{
|
|
Info.VenderLotNO = txtBatch.Text.Trim(); //批号
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (txtBatch.Text.ToString().Trim() != "")
|
|
{
|
|
_wait.Close();
|
|
ICSBaseSimpleCode.AppshowMessageBox("物料未启用批次管理,请不要输入批次号");
|
|
return;
|
|
}
|
|
Info.VenderLotNO = RecInfo.VenderLotNO;
|
|
}
|
|
Info.PRODUCTDATE = time;
|
|
Info.ACTIVE = "Y";
|
|
Info.Exdate = Convert.ToDateTime("2999-12-31");
|
|
Info.TYPE = "到货";
|
|
Info.VenBatch = txtVenBatch.Text.Trim();
|
|
if (isCheck)
|
|
{
|
|
Info.EATTRIBUTE2 = "合格";
|
|
Info.EATTRIBUTE5 = "已检";
|
|
}
|
|
else
|
|
{
|
|
Info.EATTRIBUTE2 = "";
|
|
}
|
|
if (RecInfo.Arr.iNum == 0)
|
|
{
|
|
Info.EATTRIBUTE3 = 0;
|
|
}
|
|
else
|
|
{
|
|
Info.EATTRIBUTE3 = RecInfo.Arr.iNum / RecInfo.Arr.iQuantity;
|
|
}
|
|
InfoList.Add(Info);
|
|
}
|
|
_wait.Caption = "条码生成成功,正在上传数据";
|
|
_wait.Refresh();
|
|
ICSPOArriveBLL.Add(InfoList, AppConfig.AppConnectString);
|
|
_wait.Close();
|
|
this.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_wait.Close();
|
|
ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void chkBtnAll_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chkBtnAll.Checked == true)
|
|
{
|
|
chkBtnAll.Checked = true;
|
|
chkBtnNo.Checked = false;
|
|
chkBtnPack.Checked = false;
|
|
chkBtnCheckedCharge();
|
|
}
|
|
}
|
|
|
|
private void chkBtnNo_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chkBtnNo.Checked == true)
|
|
{
|
|
chkBtnAll.Checked = false;
|
|
chkBtnNo.Checked = true;
|
|
chkBtnPack.Checked = false;
|
|
chkBtnCheckedCharge();
|
|
}
|
|
}
|
|
|
|
private void chkBtnPack_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chkBtnPack.Checked == true)
|
|
{
|
|
chkBtnAll.Checked = false;
|
|
chkBtnNo.Checked = false;
|
|
chkBtnPack.Checked = true;
|
|
chkBtnCheckedCharge();
|
|
}
|
|
}
|
|
|
|
private void chkBtnCheckedCharge()
|
|
{
|
|
if (chkBtnAll.Checked == true)
|
|
{
|
|
chkBtnAll.Checked = true;
|
|
chkBtnNo.Checked = false;
|
|
chkBtnPack.Checked = false;
|
|
|
|
this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
|
|
this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
|
|
this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
|
|
}
|
|
else if (chkBtnNo.Checked == true)
|
|
{
|
|
chkBtnAll.Checked = false;
|
|
chkBtnNo.Checked = true;
|
|
chkBtnPack.Checked = false;
|
|
|
|
this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
|
|
this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
|
|
this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
|
|
}
|
|
else if (chkBtnPack.Checked == true)
|
|
{
|
|
chkBtnAll.Checked = false;
|
|
chkBtnNo.Checked = false;
|
|
chkBtnPack.Checked = true;
|
|
|
|
this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
|
|
this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit;
|
|
this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete;
|
|
}
|
|
}
|
|
|
|
private void txtNowPackQty_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
|
|
return;
|
|
}
|
|
txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
|
|
}
|
|
}
|
|
|
|
private void txtNowQty_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
|
|
return;
|
|
}
|
|
txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
|
|
}
|
|
}
|
|
|
|
private void txtNowPackQty_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (txtNowQty.Text == "")
|
|
{
|
|
return;
|
|
}
|
|
if (txtNowPackQty.Text == "")
|
|
{
|
|
return;
|
|
}
|
|
if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
|
|
return;
|
|
}
|
|
txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
|
|
}
|
|
|
|
private void txtNowQty_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (txtNowQty.Text == "")
|
|
{
|
|
return;
|
|
}
|
|
if (txtNowPackQty.Text == "")
|
|
{
|
|
return;
|
|
}
|
|
if (Decimal.Parse(txtSumQty.Text) < (Decimal.Parse(txtSumNo.Text) + Decimal.Parse(txtNowQty.Text)))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("条码生成总数不能超过条码总数");
|
|
return;
|
|
}
|
|
txtNowNo.Text = Math.Ceiling(Decimal.Parse(txtNowQty.Text) / Decimal.Parse(txtNowPackQty.Text)).ToString();
|
|
}
|
|
}
|
|
}
|