锐腾搅拌上料功能
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.

562 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;
namespace ICSSoft.Frame.APP
{
public partial class FormICSMbarcodeCreate : DevExpress.XtraEditors.XtraForm
{
private FormICSRdrecord2LOTUIModel RecInfo;
private string CODE;
private string RowNo;
private string invStd;
private string type;
#region 构造函数
public FormICSMbarcodeCreate(string code,string rowNO,string InvStd,string Type)
{
InitializeComponent();
chkBtnAll.Checked = false;
chkBtnNo.Checked = true;
type = Type;
CODE = code;
RowNo = rowNO;
invStd = InvStd;
GetRecInfo();
if (RecInfo == null)
{
throw new Exception("入库单信息取得失败");
}
//if (RecInfo.item.ItemCtrType == null || RecInfo.item.ItemCtrType.ItemCtrTypeCode == "")
//{
// 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)
{
AppConfig.CloseFormShow(this.Text);
this.Close();
}
private void btnExit_Click(object sender, EventArgs e)
{
AppConfig.CloseFormShow(this.Text);
this.Close();
}
#endregion
private void GetRecInfo()
{
RecInfo = ICSMbarcodeLOTBLL.SearchInfo(CODE, RowNo, AppConfig.AppConnectString);
init();
}
private void init()
{
txtSumNo.Text = "";
txtNowNo.Text = "";
txtNowQty.Text = "";
txtSumQty.Text = "";
txtAllQty.Text = "";
btnLabelCreate.Enabled = true;
if (RecInfo == null)
{
return;
}
//if (RecInfo.item != null)
//{
// if (RecInfo.item.ItemCtrType == null)
// {
// btnLabelCreate.Enabled = false;
// }
//if (RecInfo.item.ItemCtrType.ItemCtrTypeCode == ATVControlParam.ItemCtrlEnum.PieceCtrl.Code)
//{
// txtNowPackQty.Text = "1";
// txtNowPackQty.Properties.ReadOnly = true;
// chkBtnPack.Checked = false;
// chkBtnPack.Checked = true;
// chkBtnAll.Enabled = false;
// chkBtnNo.Enabled = false;
// chkBtnPack.Enabled = false;
//}
//else
//{
//txtNowPackQty.Text = "1";
txtNowPackQty.Properties.ReadOnly = false;
//chkBtnPack.Checked = false;
//chkBtnPack.Checked = true;
chkBtnAll.Enabled = true;
chkBtnNo.Enabled = true;
chkBtnPack.Enabled = true;
//}
//}
txtSumQty.Text = RecInfo.SumQty.ToString();
txtSumNo.Text = RecInfo.SumNo.ToString();
txtNowQty.Text = (RecInfo.rdrecords.MOPLANQTY - RecInfo.SumQty > 0 ? RecInfo.rdrecords.MOPLANQTY - RecInfo.SumQty : 0).ToString();
//txtNowNo.Text = Math.Ceiling(decimal.Parse(txtNowQty.Text)).ToString();
if (string.IsNullOrWhiteSpace(RecInfo.inventory.INVCARTONQTY.ToString()))
{
txtNowPackQty.Text = "1";
txtNowNo.Text = Math.Ceiling(decimal.Parse(txtNowQty.Text)).ToString();
}
else
{
if (RecInfo.inventory.INVCARTONQTY == 0)
{
txtNowPackQty.Text = "1";
txtNowNo.Text = txtNowQty.Text;
}
else
{
txtNowPackQty.Text = RecInfo.inventory.INVCARTONQTY.ToString();
txtNowNo.Text = Math.Ceiling(decimal.Parse(txtNowQty.Text) / decimal.Parse(RecInfo.inventory.INVCARTONQTY.ToString())).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)
{
String VLotNo = "";
if (RecInfo == null)
{
ICSBaseSimpleCode.AppshowMessageBox("入库单信息取得失败");
return;
}
if (string.IsNullOrWhiteSpace(RecInfo.rdrecords.MOCODE) || string.IsNullOrWhiteSpace(RecInfo.rdrecords.MOSEQ.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 = AppConfig.GetSeverDateTime("yyyy-MM-dd");
string timeStr=time.ToString("yyMMdd");
string sql = @"SELECT A.VenderLotNO AS VenderLotNO FROM ICSITEMLot A WHERE TransNO ='{0}' AND TransLine='{1}' ORDER BY A.VenderLotNO desc";
sql = string.Format(sql, CODE, RowNo);
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
if (dt == null || dt.Rows.Count <= 0)
{
if (type.Equals("I02"))//半成品
{
VLotNo = "SFG" + RecInfo.rdrecords.MOCODE + (RecInfo.TodayMOCount + 1).ToString().PadLeft(2, '0');
}
//else if (type.Equals("I05"))//成品
//{
// VLotNo = "FG" + RecInfo.rdrecords.MOCODE + (RecInfo.TodayMOCount + 1).ToString().PadLeft(2, '0');
//}
else
{
VLotNo = "FG" + RecInfo.rdrecords.MOCODE + (RecInfo.TodayMOCount + 1).ToString().PadLeft(2, '0');
}
}
else if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["VenderLotNO"].ToString()))
{
VLotNo = (dt.Rows[0][0].ToString().Substring(0, dt.Rows[0][0].ToString().Length - 2)).ToString() + (Convert.ToInt32(dt.Rows[0][0].ToString().Substring(dt.Rows[0][0].ToString().Length - 2)) + 1).ToString().PadLeft(2, '0');
}
for (int i = 0; i < Num; i++)
{
_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 = RecInfo.rdrecords.MOCODE + RecInfo.rdrecords.MOSEQ + (count + i + 1).ToString().PadLeft(5, '0');
Info.ItemCode = RecInfo.rdrecords.ITEMCODE;
Info.TransNO = RecInfo.rdrecords.MOCODE;
Info.TransLine = RecInfo.rdrecords.MOSEQ;
//if (!string.IsNullOrWhiteSpace(RecInfo.VenderLotNO))
// Info.VenderLotNO = RecInfo.VenderLotNO;
//else
// Info.VenderLotNO = timeStr.Substring(timeStr.Length-6) + (RecInfo.TodayMOCount+1).ToString().PadLeft(3,'0'); //生产批号,每个工单一个
Info.VenderLotNO = VLotNo;
Info.PRODUCTDATE = time;
Info.ACTIVE = "Y";
Info.Exdate = Convert.ToDateTime("2999-12-31");
Info.TYPE = type;
InfoList.Add(Info);
}
_wait.Caption = "条码生成成功,正在上传数据";
_wait.Refresh();
ICSMbarcodeLOTBLL.Add(InfoList,AppConfig.AppConnectString);
//_wait.Caption = "数据上传完成,正在打开条码打印";
//_wait.Refresh();
//GetRecInfo();
_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;
txtNowQty.Properties.ReadOnly = true;
txtNowNo.Properties.ReadOnly = false;
txtNowPackQty.Properties.ReadOnly = false;
}
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;
txtNowQty.Properties.ReadOnly = false;
txtNowNo.Properties.ReadOnly = true;
txtNowPackQty.Properties.ReadOnly = false;
}
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;
txtNowQty.Properties.ReadOnly = false;
txtNowNo.Properties.ReadOnly = false;
txtNowPackQty.Properties.ReadOnly = true;
}
}
private void txtNowPackQty_TextChanged(object sender, EventArgs e)
{
}
private void txtDocOrg_EditValueChanged(object sender, EventArgs e)
{
}
private void txtNowPackQty_EditValueChanged(object sender, EventArgs e)
{
bool isOK = false;
if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox))
{
DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox;
if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name)
{
isOK = true;
}
}
if (!isOK)
{
return;
}
decimal No = 0;
decimal Qty = 0;
decimal Pack = 0;
decimal Sqty = 0;
decimal.TryParse(txtNowNo.Text, out No);
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
if (txtNowNo.Properties.ReadOnly == true)
{
if (Pack == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0");
return;
}
Sqty = Math.Ceiling(Qty / Pack);
txtNowNo.Text = Sqty.ToString();
txtNowQty.Text = Qty.ToString();
txtNowPackQty.Text = Pack.ToString();
}
if (txtNowQty.Properties.ReadOnly == true)
{
if (Pack != 0)
{
Sqty = Math.Ceiling(Qty / Pack);
txtNowNo.Text = Sqty.ToString();
txtNowQty.Text = Qty.ToString();
txtNowPackQty.Text = Pack.ToString();
}
else
{
No = 0;
}
}
}
private void txtNowNo_EditValueChanged(object sender, EventArgs e)
{
bool isOK = false;
if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox))
{
DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox;
if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name)
{
isOK = true;
}
}
if (!isOK)
{
return;
}
decimal No;
decimal Qty;
decimal Pack;
decimal Sqty = 0;
decimal.TryParse(txtNowNo.Text, out No);
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
if (txtNowPackQty.Properties.ReadOnly == true)
{
Sqty = Math.Ceiling(Qty / Pack);
txtNowNo.Text = Sqty.ToString();
txtNowQty.Text = Qty.ToString();
txtNowPackQty.Text = Pack.ToString();
}
if (txtNowQty.Properties.ReadOnly == true)
{
if (No != 0)
{
Sqty = Math.Ceiling(Qty / Pack);
txtNowNo.Text = Sqty.ToString();
txtNowQty.Text = Qty.ToString();
txtNowPackQty.Text = Pack.ToString();
}
else
{
Pack = 0;
}
}
}
private void txtNowQty_EditValueChanged(object sender, EventArgs e)
{
bool isOK = false;
if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox))
{
DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox;
if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name)
{
isOK = true;
}
}
if (!isOK)
{
return;
}
decimal No = 0;
decimal Qty = 0;
decimal Pack = 0;
decimal Sqty = 0;
decimal.TryParse(txtNowNo.Text, out No);
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
if (txtNowPackQty.Properties.ReadOnly == true)
{
if (Pack != 0)
{
if (Pack == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0");
return;
}
Sqty = Math.Ceiling(Qty / Pack);
txtNowNo.Text = Sqty.ToString();
txtNowQty.Text = Qty.ToString();
txtNowPackQty.Text = Pack.ToString();
}
}
if (txtNowNo.Properties.ReadOnly == true)
{
if (Pack == 0)
{
ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0");
return;
}
Sqty = Math.Ceiling(Qty / Pack);
txtNowNo.Text = Sqty.ToString();
txtNowQty.Text = Qty.ToString();
txtNowPackQty.Text = Pack.ToString();
}
}
}
}