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.
368 lines
15 KiB
368 lines
15 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.Base.Language.Tool;
|
|
using ICSSoft.Base.UserControl.MessageControl;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.Report.Filter;
|
|
using ICSSoft.Base.UserControl.FormControl;
|
|
using ICSSoft.Base.ReferForm.AppReferForm;
|
|
using System.Text.RegularExpressions;
|
|
using ICSSoft.Frame.APP;
|
|
using ICSSoft.Frame.Data.BLL;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Lable.PrintTool;
|
|
|
|
|
|
namespace ICSSoft.Frame.APP
|
|
{
|
|
public partial class FormStockBarCodeCreate : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
List<Dictionary<string, object>> _Rows = new List<Dictionary<string, object>>();
|
|
bool isCreateOK = false;
|
|
decimal d = 0;
|
|
|
|
public FormStockBarCodeCreate()
|
|
{
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
public FormStockBarCodeCreate(List<Dictionary<string, object>> Rows)
|
|
{
|
|
InitializeComponent();
|
|
_Rows = Rows;
|
|
OnCreateControl();
|
|
|
|
|
|
}
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
protected override void OnCreateControl()
|
|
{
|
|
base.OnCreateControl();
|
|
grdDetail.DataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FormStockBarCodeSelect.searchSQl() + "and 1=2").Tables[0];
|
|
InsertIntoGrvDetail(_Rows);
|
|
}
|
|
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
btnExit_Click(null, null);
|
|
}
|
|
|
|
private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
|
|
{
|
|
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
|
|
e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
|
}
|
|
|
|
|
|
|
|
private void btnDel_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnQuit_Click(object sender, EventArgs e)
|
|
{
|
|
if (grvDetail.RowCount > 0)
|
|
{
|
|
if (ICSBaseSimpleCode.AppshowMessageBoxRepose("有待生成条码的数据,是否放弃") == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
grdDetail.DataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FormStockBarCodeSelect.searchSQl() + " and 1=2 ").Tables[0];
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
if (grvDetail.RowCount > 0)
|
|
{
|
|
if (ICSBaseSimpleCode.AppshowMessageBoxRepose("有待生成条码的数据,是否退出") == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
}
|
|
|
|
#region 生成
|
|
private void btnFilter_Click(object sender, EventArgs e)
|
|
{
|
|
grvDetail.PostEditor();
|
|
this.Validate();
|
|
decimal suming = 0;
|
|
decimal PQty = 0;//批次数量
|
|
|
|
if (grvDetail.RowCount == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("没有数据,无法生成");
|
|
return;
|
|
}
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (Convert.ToInt32(grvDetail.GetRowCellValue(i, BarCodeCount)) == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("条码个数不能为空!!");
|
|
return;
|
|
}
|
|
if (Convert.ToInt32(grvDetail.GetRowCellValue(i, BarCodeqty)) == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("条码规格不能为空!!");
|
|
return;
|
|
}
|
|
//if (Convert.ToInt32(grvDetail.GetRowCellValue(i, BatchCode)) == 0)
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox("批次不能为空!!");
|
|
// return;
|
|
//}
|
|
}
|
|
try
|
|
{
|
|
string CartonNo = "";
|
|
string PCode = "";
|
|
string PRow = "0";
|
|
String PID = "";
|
|
List<PrintPara> parasList = new List<PrintPara>();
|
|
List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
|
|
List<ICSITEMLot> Listguid = new List<ICSITEMLot>();
|
|
for (int i = 0; i < grvDetail.RowCount;i++ )
|
|
{
|
|
decimal BarQty = 0;//条码规格
|
|
decimal packQty = 0;//已包装数量
|
|
string PoCode = grvDetail.GetRowCellValue(i,Code).ToString();
|
|
PCode = grvDetail.GetRowCellValue(i, cCode).ToString();
|
|
//PRow = int.Parse(grvDetail.GetRowCellValue(i, row).ToString());
|
|
PRow = grvDetail.GetRowCellValue(i, row).ToString();
|
|
PID = grvDetail.GetRowCellValue(i, ERPAutoid).ToString();
|
|
int BarCount = 0;//条码个数
|
|
decimal.TryParse(grvDetail.GetRowCellValue(i, iQuantity).ToString(), out PQty);
|
|
decimal.TryParse(grvDetail.GetRowCellValue(i, BarCodeqty).ToString(), out BarQty);
|
|
decimal.TryParse(grvDetail.GetRowCellValue(i, PackQty).ToString(), out packQty);
|
|
int.TryParse(grvDetail.GetRowCellValue(i, BarCodeCount).ToString(), out BarCount);
|
|
suming += BarQty * BarCount;
|
|
decimal sumQty = suming + packQty;
|
|
if (sumQty > PQty)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("生成条码数量大于到货总数,");
|
|
return;
|
|
}
|
|
for (int j = 0; j < BarCount; j++)
|
|
{
|
|
ICSITEMLot line = new ICSITEMLot();
|
|
line.ID = AppConfig.GetGuid();
|
|
CartonNo = AppConfig.GetSerialCode(AppConfig.FrameConnectString,AppConfig.WorkPointCode,
|
|
"ICSITEMLot", "LotNO", PoCode, 5);
|
|
line.LotNO = CartonNo;
|
|
line.TransNO = PCode;
|
|
line.TransLine = PRow;
|
|
line.ItemCode = grvDetail.GetRowCellValue(i, cInvCode).ToString();
|
|
line.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
line.LOTQTY = BarQty;
|
|
line.ACTIVE = "Y";
|
|
line.Exdate = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
line.TYPE = "原材料";
|
|
line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
|
|
line.MUSER = AppConfig.UserId;
|
|
line.MUSERName = AppConfig.UserName;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
Listguid.Add(line);
|
|
|
|
PrintPara para = new PrintPara();
|
|
para.PrintKey = "LOTNO";
|
|
para.PrintValues = new object[] { CartonNo };
|
|
parasList.Add(para);
|
|
|
|
ICSITEMLot Info = new ICSITEMLot();
|
|
Info.LotNO = CartonNo;
|
|
Info.lastPrintUSERID = AppConfig.UserId;
|
|
Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
|
|
Info.WorkPoint = AppConfig.WorkPointCode;
|
|
InfoList.Add(Info);
|
|
}
|
|
}
|
|
//ICSStockBarCodeBLL.CreatebarCode(Listguid, AppConfig.AppConnectString, PID, suming);
|
|
grdDetail.DataSource = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FormStockBarCodeSelect.searchSQl() + " and 1=2 ").Tables[0];
|
|
grvDetail.BestFitColumns();
|
|
if (ICSBaseSimpleCode.AppshowMessageBoxRepose("保存成功,是否打印?") == DialogResult.OK)
|
|
{
|
|
FormPrintDialog f = new FormPrintDialog("006", this.Text, parasList, false, null);
|
|
f.ShowDialog();
|
|
|
|
//更新打印信息
|
|
ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
|
|
}
|
|
isCreateOK = true;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox(1, "保存失败\r\n" + ex.Message);
|
|
}
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
#endregion
|
|
|
|
private void FormProductBarCodeCreate_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (isCreateOK)
|
|
{
|
|
this.DialogResult = DialogResult.OK;
|
|
}
|
|
}
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void InsertIntoGrvDetail(List<Dictionary<string, object>> Rows)
|
|
{
|
|
List<string> serialList = new List<string>();
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
serialList.Add(grvDetail.GetRowCellValue(i, ERPAutoid).ToString());
|
|
}
|
|
|
|
foreach (Dictionary<string, object> dr in Rows)
|
|
{
|
|
if (serialList.Contains(dr["ERPAutoid"].ToString()))
|
|
{
|
|
continue;
|
|
}
|
|
grvDetail.AddNewRow();
|
|
for (int i = 0; i < grvDetail.Columns.Count; i++)
|
|
{
|
|
string FieldName = grvDetail.Columns[i].FieldName;
|
|
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, FieldName, dr[FieldName]);
|
|
}
|
|
}
|
|
grvDetail.AddNewRow();
|
|
grvDetail.DeleteRow(grvDetail.FocusedRowHandle);
|
|
//for (int j = 0; j < grvDetail.RowCount;j++ )
|
|
//{
|
|
// double PackingSpec = 0;
|
|
// double.TryParse(grvDetail.GetRowCellValue(j, BQuantity).ToString(), out PackingSpec);
|
|
// if(PackingSpec<=0)
|
|
// {
|
|
// ICSBaseSimpleCode.AppshowMessageBox(2,"包装规格(除数不能小于等于0!)");
|
|
// return;
|
|
// }
|
|
// int Lotqty = 0;
|
|
// int.TryParse(grvDetail.GetRowCellValue(j, PQuantity).ToString(), out Lotqty);
|
|
// int count = (int)Math.Ceiling((double)Lotqty / (double)PackingSpec);
|
|
// grvDetail.SetRowCellValue(j,BarCodeqty,count);
|
|
//}
|
|
|
|
}
|
|
bool b = false;
|
|
private void FormCartonProtectCreate_Load(object sender, EventArgs e)
|
|
{
|
|
LanguageConvert.ChangeLanguage(this, "1");
|
|
Application.DoEvents();
|
|
OnCreateControl();
|
|
b = true;
|
|
}
|
|
|
|
private void grvDetail_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
|
|
{
|
|
if (e.Column.FieldName == "BQuantity" || e.Column.FieldName == "BarCodeqty")
|
|
{
|
|
e.Appearance.BackColor = Color.YellowGreen;
|
|
}
|
|
}
|
|
|
|
private void btnAdd_Click_1(object sender, EventArgs e)
|
|
{
|
|
grvDetail.FocusedRowHandle = 0;
|
|
|
|
decimal sum = decimal.Parse(grvDetail.GetRowCellValue(grvDetail.RowCount - 1, iQuantity).ToString() == "" ? "0" : grvDetail.GetRowCellValue(grvDetail.RowCount - 1, iQuantity).ToString());
|
|
decimal count = decimal.Parse(grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeCount).ToString() == "" ? "0" : grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeCount).ToString());
|
|
decimal Spec = decimal.Parse(grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeqty).ToString() == "" ? "0" : grvDetail.GetRowCellValue(grvDetail.RowCount - 1, BarCodeqty).ToString());
|
|
d = sum - (count * Spec);
|
|
|
|
foreach (Dictionary<string, object> dr in _Rows)
|
|
{
|
|
grvDetail.AddNewRow();
|
|
for (int j = 0; j < grvDetail.Columns.Count; j++)
|
|
{
|
|
string FieldName = grvDetail.Columns[j].FieldName;
|
|
if (FieldName == "PQuantity")
|
|
{
|
|
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, FieldName, d);
|
|
}
|
|
else
|
|
{
|
|
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, FieldName, dr[FieldName]);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnDel_Click_1(object sender, EventArgs e)
|
|
{
|
|
grvDetail.PostEditor();
|
|
this.Validate();
|
|
if (grvDetail.FocusedRowHandle < 0)
|
|
{
|
|
return;
|
|
}
|
|
if (grvDetail.RowCount <= 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
grvDetail.DeleteRow(grvDetail.FocusedRowHandle);
|
|
}
|
|
|
|
}
|
|
}
|