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

530 lines
19 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 FormStockBarCodeCreates : DevExpress.XtraEditors.XtraForm
{
private FormICSBarCodeModel BarCodeInfo;
private string AutoID;
private string Code;
#region 构造函数
public FormStockBarCodeCreates(string ID,string cCode)
{
InitializeComponent();
chkBtnAll.Checked = false;
chkBtnAll.Checked = true;
AutoID = ID;
Code = cCode;
GetRecInfo();
if (BarCodeInfo == 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()
{
DataTable dt = ICSStockBarCodeBLL.FindDataByID(AutoID,Code, AppConfig.AppConnectString);
if (dt != null && dt.Rows.Count > 0)
{
BarCodeInfo = new FormICSBarCodeModel();
BarCodeInfo.Qty = dt.Rows[0]["INVCARTONQTY"].ToString();
BarCodeInfo.sumQty = dt.Rows[0]["sumQty"].ToString();
BarCodeInfo.packCount = dt.Rows[0]["cont"].ToString();
BarCodeInfo.packQty = dt.Rows[0]["PackQty"].ToString();
BarCodeInfo.maxLot = int.Parse(dt.Rows[0]["maxLot"].ToString() == "" ? "0" : dt.Rows[0]["maxLot"].ToString());
BarCodeInfo.Free1 = dt.Rows[0]["Free1"].ToString();
BarCodeInfo.Free2 = dt.Rows[0]["Free2"].ToString();
BarCodeInfo.Free3 = dt.Rows[0]["Free3"].ToString();
BarCodeInfo.cCode = dt.Rows[0]["cCode"].ToString();
BarCodeInfo.cInvCode = dt.Rows[0]["cInvCode"].ToString();
BarCodeInfo.count = dt.Rows[0]["INVCARTONQTY"].ToString();
}
init();
}
private void init()
{
txtSumNo.Text = "";
txtNowNo.Text = "";
txtNowQty.Text = "";
txtSumQty.Text = "";
txtAllQty.Text = "";
btnLabelCreate.Enabled = true;
if (BarCodeInfo == 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 = BarCodeInfo.count == "0" ? BarCodeInfo.sumQty : BarCodeInfo.count;
txtNowPackQty.Properties.ReadOnly = false;
//chkBtnPack.Checked = false;
//chkBtnPack.Checked = true;
chkBtnAll.Enabled = true;
chkBtnNo.Enabled = true;
chkBtnPack.Enabled = true;
//}
//}
txtSumQty.Text = BarCodeInfo.packQty.ToString();
txtSumNo.Text = BarCodeInfo.packCount.ToString() == "" ? "0" : BarCodeInfo.packCount.ToString();
txtNowQty.Text = BarCodeInfo.sumQty;
txtNowNo.Text = (decimal.Parse(txtNowQty.Text.Trim()) / decimal.Parse(txtNowPackQty.Text.Trim())).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 (BarCodeInfo == null)
{
ICSBaseSimpleCode.AppshowMessageBox("入库单信息取得失败");
return;
}
if (string.IsNullOrWhiteSpace(BarCodeInfo.cCode) || string.IsNullOrWhiteSpace(BarCodeInfo.Free1))
{
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<PrintPara> parasList = new List<PrintPara>();
List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
List<ICSITEMLot> InfoLists = new List<ICSITEMLot>();
int count = Convert.ToInt32(BarCodeInfo.maxLot);
DateTime time = AppConfig.GetSeverDateTime("yyyy-MM-dd");
string timeStr=time.ToString("yyMMdd");
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 = BarCodeInfo.cCode + BarCodeInfo.Free1 + (count + i + 1).ToString().PadLeft(5, '0');
Info.ID = AppConfig.GetGuid();
Info.ItemCode = BarCodeInfo.cInvCode;
Info.TransNO = BarCodeInfo.Free2;
//Info.TransLine = int.Parse(BarCodeInfo.Free3);
Info.TransLine = BarCodeInfo.Free3;
Info.PRODUCTDATE = time;
Info.ACTIVE = "Y";
Info.Exdate = Convert.ToDateTime("2999-12-31");
Info.TYPE = "原材料";
Info.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
InfoLists.Add(Info);
PrintPara para = new PrintPara();
para.PrintKey = "LOTNO";
para.PrintValues = new object[] { Info.LotNO };
parasList.Add(para);
ICSITEMLot Infos = new ICSITEMLot();
Infos.LotNO = Info.LotNO;
Infos.lastPrintUSERID = AppConfig.UserId;
Infos.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
Infos.WorkPoint = AppConfig.WorkPointCode;
InfoList.Add(Infos);
}
_wait.Caption = "条码生成成功,正在上传数据";
_wait.Refresh();
ICSStockBarCodeBLL.CreatebarCode(InfoLists, AppConfig.AppConnectString);
_wait.Close();
if (ICSBaseSimpleCode.AppshowMessageBoxRepose("保存成功,是否打印?") == DialogResult.OK)
{
FormPrintDialog f = new FormPrintDialog("006", this.Text, parasList, false, null);
f.ShowDialog();
//更新打印信息
ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
}
//_wait.Caption = "数据上传完成,正在打开条码打印";
//_wait.Refresh();
//GetRecInfo();
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.TryParse(txtNowNo.Text, out No);
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
if (txtNowNo.Properties.ReadOnly == true)
{
Qty = No * Pack;
txtNowQty.Text = Qty.ToString();
}
if (txtNowQty.Properties.ReadOnly == true)
{
if (Pack != 0)
{
No = Math.Ceiling(Qty / Pack);
txtNowNo.Text = No.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.TryParse(txtNowNo.Text, out No);
decimal.TryParse(txtNowQty.Text, out Qty);
decimal.TryParse(txtNowPackQty.Text, out Pack);
if (txtNowPackQty.Properties.ReadOnly == true)
{
Qty = No * Pack;
txtNowQty.Text = Qty.ToString();
}
if (txtNowQty.Properties.ReadOnly == true)
{
if (No != 0)
{
Pack = Math.Ceiling(Qty / No);
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.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)
{
No = Math.Ceiling(Qty / Pack);
txtNowNo.Text = No.ToString();
}
}
if (txtNowNo.Properties.ReadOnly == true)
{
if (No != 0)
{
Pack = Math.Ceiling(Qty / No);
txtNowPackQty.Text = Pack.ToString();
}
}
}
}
}