using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using LabelManager2;
using UAS_LabelMachine.PublicMethod;
using UAS_LabelMachine.Entity;
using UAS_LabelMachine.PublicForm;
using System.Threading;
using System.IO;
using System.IO.Ports;
using UAS_LabelMachine.CustomControl;
using System.Reflection;
namespace UAS_LabelMachine
{
public partial class UAS_出货标签打印 : Form
{
//自适应屏幕
AutoSizeFormClass asc = new AutoSizeFormClass();
DataHelper dh;
DataHelper dh1;
SqliteDBHelper adh;
SqliteDBHelper back_adh;
DataTable dt;
StringBuilder sql = new StringBuilder();
///
/// CodeSoft新建打印机引擎
///
ApplicationClass lbl;
///
/// 单盘打印文件
///
Document SingleDoc;
///
/// 中盒打印文件
///
Document MidDoc;
///
/// 外箱打印文件
///
Document OutBoxDoc;
///
/// Loading窗口
///
SetLoadingWindow stw;
///
/// 弹窗线程
///
Thread thread;
string PI_ID;
///
/// 当前扫描的所在行
///
int CurrentRowIndex = 0;
///
/// 正则表达式用于项目匹配
///
Regex reg;
bool logout = false;
DataTable SingleLabelParam;
DataTable MidLabelParam;
DataTable OutLabelParam;
///
/// 存放单盘的ID
///
List SingleID = new List();
///
/// 单盘的打印参数
///
List SingleBoxArgument = new List();
///
/// 存放中盒的ID和盒号
///
Dictionary MidIDAndOutboxcode = new Dictionary();
///
/// 中盒的打印参数
///
List MidBoxArgument = new List();
///
/// 默认采集了指定的数据上传
///
int UploadNum = 100;
/*需要重绘的Cell*/
Dictionary PaintCell = new Dictionary();
///
/// 是否通过选择Combox来改变打开的文件
///
bool ComBoxClickChangeLabelDoc = false;
///
/// 附加信息DataTable
///
DataTable Attach;
///
/// 采集策略DataTable
///
DataTable ScanGroup;
///
/// 采集明细DataTable
///
DataTable ScanItem;
public UAS_出货标签打印(string Master)
{
//设置窗体的双缓冲
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
InitializeComponent();
//利用反射设置DataGridView的双缓冲
Type dgvType = this.LabelInf.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(this.LabelInf, true, null);
Text = Text + "-" + Master;
}
protected override void WndProc(ref Message m)
{
//拦截双击标题栏、移动窗体的系统消息
if (m.Msg != 0xA3)
{
base.WndProc(ref m);
}
}
private void 贴标机条码打印_Load(object sender, EventArgs e)
{
//杀死之前全部未关闭的进程
Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
for (int i = 0; i < processes.Length; i++)
{
processes[i].Kill();
}
//用计时器重置数据库链接
LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
dh = SystemInf.dh;
dh1 = SystemInf.dh1;
adh = SystemInf.adh;
back_adh = SystemInf.back_adh;
CheckForIllegalCrossThreadCalls = false;
pi_inoutno.TableName = "prodinout";
pi_inoutno.Field = "pi_inoutno";
pi_inoutno.ValueField = "pi_inoutno";
pi_inoutno.Condition = "pi_class in('出货单','拨出单')";
pi_inoutno.Focus();
Point pt = new Point();
//禁止所有列的排序
foreach (DataGridViewColumn dgv in LabelInf.Columns)
{
dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
}
AutoCollection.Checked = true;
int ScreenWidth = Screen.GetWorkingArea(pt).Width;
//设置获取当前屏幕大小自动全屏但是保留任务栏
Rectangle ScreenArea = Screen.GetWorkingArea(this);
Top = 0;
Left = 0;
Width = ScreenArea.Width;
Height = ScreenArea.Height;
MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
OutBoxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
asc.controllInitializeSize(this);
asc.controlAutoSize(this);
pi_inoutno.BringToFront();
//实例化打印进程
try
{
lbl = new ApplicationClass();
SystemInf.lbl = lbl;
}
catch (Exception)
{
MessageBox.Show("未安装CodeSoft软件或者版本不正确");
}
RefreshDBConnect.Interval = 60000;
RefreshDBConnect.Start();
DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
DataRow[] dr;
try
{
dr = dt.Select("comtype='FrontendCheck'");
if (dr.Length > 0)
{
FrontendCheck.PortName = dr[0]["COM"].ToString();
int sleeptime = 0;
if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
{
FrontendCheck.SleepTime = sleeptime;
}
FrontendCheck.Tag = "FrontendCheck";
FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
FrontendCheck.DataReceived += Serial_DataReceived;
FrontendCheck.Open();
}
}
catch (Exception ex)
{
MessageLog.AppendText("前端扫描" + ex.Message + "\n");
}
try
{
dr = dt.Select("comtype='BackendCheck'");
if (dr.Length > 0)
{
BackendCheck.PortName = dr[0]["COM"].ToString();
BackendCheck.Tag = "BackendCheck";
int sleeptime = 0;
if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
{
BackendCheck.SleepTime = sleeptime;
}
BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
BackendCheck.DataReceived += Serial_DataReceived;
BackendCheck.Open();
}
}
catch (Exception ex)
{
MessageLog.AppendText("后端扫描" + ex.Message + "\n");
}
try
{
dr = dt.Select("comtype='PLC1'");
if (dr.Length > 0)
{
if (!PLC1.IsOpen)
{
PLC1.PortName = dr[0]["COM"].ToString();
PLC1.Tag = "PLC1";
int sleeptime = 0;
if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
{
PLC1.SleepTime = sleeptime;
}
PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
PLC1.DataReceived += Serial_DataReceived;
PLC1.Open();
}
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
MessageLog.AppendText("PLC启动成功\n", Color.Blue);
}
}
catch (Exception ex)
{
MessageLog.AppendText("自动贴标机" + ex.Message + "\n");
}
try
{
dr = dt.Select("comtype='ManBackendCheck'");
if (dr.Length > 0)
{
if (!ManBackendCheck.IsOpen)
{
ManBackendCheck.PortName = dr[0]["COM"].ToString();
ManBackendCheck.Tag = "ManBackendCheck";
int sleeptime = 0;
if (int.TryParse(dr[0]["DATAWAIT"].ToString(), out sleeptime))
{
ManBackendCheck.SleepTime = sleeptime;
}
ManBackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
ManBackendCheck.DataReceived += Serial_DataReceived;
ManBackendCheck.Open();
}
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
MessageLog.AppendText("PLC启动成功\n", Color.Blue);
}
}
catch (Exception ex)
{
MessageLog.AppendText("手动后端复核" + ex.Message + "\n");
}
RefreshPLCInstruct();
}
string LotNo = "";
string DateCode = "";
string Order = "";
string QTY = "";
string PN = "";
string OutBox = "";
List ManualCheckCount = new List();
//获取串口数据
private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
string ErrorMsg = "";
SerialPortWithTag port = sender as SerialPortWithTag;
Thread.Sleep(port.SleepTime);
int len = port.BytesToRead;
byte[] readBuffer = new byte[len];
port.Read(readBuffer, 0, len); //将数据读入缓存
string msg = Encoding.ASCII.GetString(readBuffer, 0, len).Replace("\n", "").Replace("\r", "").Replace("\t", ""); //获取出入库产品编号
if (LabelInf.Rows.Count == 0)
return;
int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
if (DetailRange.Checked)
{
//不在范围内的不进行处理
if (!(pib_pdno >= DetailRange1.Value && pib_pdno <= DetailRange2.Value))
{
return;
}
}
switch (port.Tag)
{
case "PLC1":
ScanGroup = BaseUtil.filterDataTable(ScanGroup, "sg_autolabel<>0");
//MessageLog.AppendText(msg + "\n", Color.Blue);
////返回的指令和设备执行的动作对应
//foreach (var item in instruct)
//{
// //接收到的数据和指令的对应则
// if (item.Value == msg)
// {
// }
//}
break;
case "PLC2":
ScanGroup = BaseUtil.filterDataTable(ScanGroup, "sg_autolabel<>0");
break;
case "FrontendCheck":
ScanGroup = BaseUtil.filterDataTable(ScanGroup, "sg_autolabel<>0");
//比对当前箱数量和容量
FrontCollect.Text = msg;
if (!FrontCheckFunction(msg, out ErrorMsg))
{
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataDelete, adh);
BaseUtil.PlaySound("Scan.Error.wav");
MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
}
else
{
if (cu_print_checkdatecode.Checked)
{
string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
if (datecode == "" || lotno == "")
{
MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
return;
}
}
//勾选了单盘自动打印
if (SingleLabelAutoPrint.Checked)
{
if (SingleLabelCombox.SelectedValue != null)
{
AutoPrintSingleLabel();
}
else
{
MessageBox.Show("未维护单盘标签");
return;
}
}
LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
BaseUtil.PlaySound("Scan.Finish.wav");
//勾选了中盒自动打印
if (MidLabelAutoPrint.Checked)
AutoPrintMidLabel();
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.FrontDataPass, adh);
LabelInf.Invalidate();
RefreshProcessData();
}
break;
case "BackendCheck":
ScanGroup = BaseUtil.filterDataTable(ScanGroup, "sg_autolabel<>0");
BackCheck.Text = msg;
if (BackendCheckFunction(msg, "Auto", out ErrorMsg))
{
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass, adh);
BaseUtil.PlaySound("Confirm.Finish.wav");
}
else
{
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataDelete, adh);
BaseUtil.PlaySound("Confirm.Error.wav");
MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
}
break;
case "ManBackendCheck":
if (ManualBackCheck.Checked)
{
BackCheck.Text = msg;
if (BackendCheckFunction(msg, "Manual", out ErrorMsg))
{
ManualCheckCount.Add(1);
}
else
{
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataDelete, adh);
BaseUtil.PlaySound("Confirm.Error.wav");
MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
}
if (ManualCheckCount.Count == 2)
{
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.BackDataPass, adh);
BaseUtil.PlaySound("Confirm.Finish.wav");
ManualCheckCount.Clear();
}
}
else
{
MessageLog.AppendText(">>该串口为手动复核串口,请选择手动后端复核模式\n", Color.Red);
}
break;
default:
break;
}
}
catch (Exception ex)
{
LogManager.DoLog(ex.Message + ex.StackTrace);
MessageLog.AppendText("接收返回消息异常!具体原因:" + ex.Message + ex.StackTrace, Color.Red);
}
}
string year = "";
string month = "";
string day = "";
string date = "";
private bool RegexMatch(string CheckType, string msg, out string ErrorMsg)
{
ErrorMsg = "";
bool Matched = false;
for (int i = 0; i < ScanGroup.Rows.Count; i++)
{
string sg_name = ScanGroup.Rows[i]["sg_name"].ToString();
string sg_brand = ScanGroup.Rows[i]["sg_brand"].ToString();
string sg_script = ScanGroup.Rows[i]["sg_script"].ToString();
string sg_id = ScanGroup.Rows[i]["sg_id"].ToString();
reg = new Regex(sg_script);
Match matchs1 = reg.Match(msg);
DataTable dt = BaseUtil.filterDataTable(ScanItem, "sg_id=" + sg_id);
if (matchs1.Success)
{
int rownum = 0;
Matched = true;
string ItemStr = "";
foreach (var groupName in reg.GetGroupNames())
{
for (int j = 0; j < dt.Rows.Count; j++)
{
//如果组别名称相等的话
if (groupName == dt.Rows[j]["si_name"].ToString())
{
ItemStr += dt.Rows[j]["si_item"].ToString() + ",";
string si_expression = dt.Rows[j]["si_expression"].ToString();
Regex si_exp;
switch (dt.Rows[j]["si_item"].ToString())
{
case "DateCode":
if (si_expression != "")
{
si_exp = new Regex(si_expression);
Match mat = si_exp.Match(matchs1.Groups[reg.GroupNumberFromName(groupName)].Value);
foreach (var dtgroup in si_exp.GetGroupNames())
{
if (dtgroup == dt.Rows[j]["si_name"].ToString())
DateCode = mat.Groups[si_exp.GroupNumberFromName(dtgroup)].Value;
}
}
else
{
DateCode = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
}
LogicHandler.GetTimeFromDatecode(dh, DateCode, pi_cardcode.Text, out year, out month, out day, out date);
System.DateTime dtime;
//有效期比对
if (System.DateTime.TryParseExact(date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime))
{
if ((System.DateTime.Now - dtime).Days > cu_print_limiteddate.Value)
{
MessageLog.AppendText(">>超出有效期\n", Color.Red);
}
}
break;
case "LotNo":
LotNo = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
break;
case "PN":
PN = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
//自动匹配客户PN
string sql = "select min(rownum) as rn from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'";
if (CheckType == "FrontCheck")
{
sql += " and pib_ifpick=0 and " + (prodcodefront.Text == "" ? "pr_orispeccode" : prodcodefront.Text) + "='" + PN + "'";
}
else if (CheckType == "BackCheck")
{
sql += " and pib_ifrecheck=0 and " + (prodcodeback.Text == "" ? "pr_orispeccode" : prodcodeback.Text) + "='" + PN + "'";
}
DataTable pndt = (DataTable)adh.ExecuteSql(sql, "select");
if (pndt.Rows[0][0].ToString() != "")
{
rownum = int.Parse(pndt.Rows[0]["rn"].ToString());
//如果需要翻页的话
if (!(rownum >= (PageSize * (CurrentPage - 1) + 1) && rownum <= PageSize * CurrentPage))
{
CurrentPage = rownum / PageSize + 1;
LoadGridData();
CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
if (CurrentRowIndex - 5 > 0)
LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
else
LabelInf.FirstDisplayedScrollingRowIndex = 0;
}
else
{
CurrentRowIndex = rownum % PageSize == 0 ? PageSize - 1 : rownum % PageSize - 1;
if (CurrentRowIndex - 5 > 0)
LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
else
LabelInf.FirstDisplayedScrollingRowIndex = 0;
}
}
else
{
ErrorMsg = "未能匹配到合适的原厂型号";
}
break;
case "Order":
Order = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
if (LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() != Order)
{
ErrorMsg = "订单号不匹配";
}
break;
case "QTY":
if (si_expression != "")
{
si_exp = new Regex(si_expression);
Match mat = si_exp.Match(matchs1.Groups[reg.GroupNumberFromName(groupName)].Value);
foreach (var dtgroup in si_exp.GetGroupNames())
{
if (dtgroup == dt.Rows[j]["si_name"].ToString())
{
QTY = mat.Groups[si_exp.GroupNumberFromName(dtgroup)].Value;
}
}
}
else
{
QTY = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
}
break;
case "OutBox":
OutBox = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
break;
default:
break;
}
}
}
}
//如果品牌不对应的话则不能使用本次的匹配规则
if (ErrorMsg == "" && ItemStr.Contains("QTY") && LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Value.ToString() != QTY.ToString())
{
ErrorMsg = "数量不匹配";
}
if (ErrorMsg == "" && ItemStr.Contains("PO") && LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() != Order)
{
ErrorMsg = "订单号不匹配";
}
//如果匹配到的行的品牌和当前正则的品牌不相等结束本次循环
if (LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString() == sg_brand)
{
break;
}
}
}
if (!Matched)
{
ErrorMsg = "未匹配到合适的采集策略";
}
if (ErrorMsg == "")
{
return true;
}
else
{
return false;
}
}
private bool FrontCheckFunction(string msg, out string ErrorMsg)
{
ErrorMsg = "";
//调用正则验证
RegexMatch("FrontCheck", msg, out ErrorMsg);
if (ErrorMsg != "")
{
return false;
}
else
{
//获取当前最大的箱号
LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = DateCode;
LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = LotNo;
LabelInf.Rows[CurrentRowIndex].Cells["pib_ifmodify"].Value = true;
SetOutboxBarcode();
return true;
}
}
//外箱条码号
string OutBoxBarCode = "";
//中盒条码号
string MidBoxBarCode = "";
string pibid1 = "";
private bool BackendCheckFunction(string msg, string type, out string ErrorMsg)
{
ErrorMsg = "";
DataTable dtt = LabelInf.DataSource as DataTable;
MessageLog.AppendText(msg + "\n");
string[] msgArr = msg.Split(back_sg_separator.Text.ToCharArray());
//如果包含则分隔符则需要解析,如果不包含则直接前端解析
if (!cu_print_checkonly.Checked)
{
//需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
List CheckItem = new List();
string pibid = "";
for (int i = 0; i < msgArr.Length; i++)
{
if (RecheckCuprodcode.Checked)
{
if (!CheckItem.Contains("客户料号") && !CheckItem.Contains("原厂型号"))
{
CheckItem.Add("客户料号");
CheckItem.Add("原厂型号");
}
//直接验证两个值相等
if (Equal.Checked)
{
pibid = back_adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and " + (guestlabeldata.Text == "" ? "pd_custprodcode" : guestlabeldata.Text) + "='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
if (pibid != "")
{
pibid1 = pibid;
CheckItem.Remove("客户料号");
}
}
//验证正则匹配过之后相等
else if (Expression.Checked)
{
Regex re = new Regex(cu_print_regexpression.Text);
Match matchs1 = re.Match(msgArr[i]);
foreach (var groupName in re.GetGroupNames())
{
if (groupName == "custPN")
{
if (LabelInf.Rows[CurrentRowIndex].Cells[(guestlabeldata.Text == "" ? "pd_custprodcode" : guestlabeldata.Text)].Value.ToString() == matchs1.Groups[re.GroupNumberFromName(groupName)].Value)
{
pibid = back_adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and " + (guestlabeldata.Text == "" ? "pd_custprodcode" : guestlabeldata.Text) + "='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
if (pibid != "")
{
pibid1 = pibid;
CheckItem.Remove("客户料号");
}
}
}
}
}
if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg))
{
CheckItem.Remove("原厂型号");
}
}
else if (RecheckBarcode.Checked)
{
if (!CheckItem.Contains("唯一条码") && !CheckItem.Contains("原厂型号"))
{
CheckItem.Add("唯一条码");
CheckItem.Add("原厂型号");
}
pibid = back_adh.getFieldDataByCondition("prodiobarcode", "min(pib_id)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_barcode='" + msgArr[i] + "' and pib_ifrecheck=0").ToString();
if (pibid != "")
{
pibid1 = pibid;
CheckItem.Remove("唯一条码");
}
else
{
if (RegexMatch("BackCheck", msgArr[i], out ErrorMsg))
{
CheckItem.Remove("原厂型号");
}
}
}
}
//如果是自动复核或者手动复核扫描了两次数据的话
if (CheckItem.Count == 0 || (type == "Manual" && CheckItem.Count == 1))
{
if (CheckItem.Count == 0 || (ManualCheckCount.Count == 1 && CheckItem.Count == 1))
{
string year = "0";
string month = "0";
string day = "0";
string date = "";
DataRow[] dr = LabelInfDataTable.Select("pib_id=" + pibid1 + " and pr_orispeccode='" + PN + "'");
if (dr.Length > 0)
{
dr[0]["pib_ifrecheck"] = -1;
dr[0]["pib_lotno"] = LotNo;
dr[0]["pib_datecode"] = DateCode;
try
{
LogicHandler.GetTimeFromDatecode(dh1, DateCode, pi_cardcode.Text, out year, out month, out day, out date);
dr[0]["pib_year"] = year;
dr[0]["pib_month"] = month;
dr[0]["pib_day"] = day;
}
catch (Exception)
{
}
}
else
{
ErrorMsg = "未匹配到合适的原厂型号";
return false;
}
back_adh.ExecuteSql("update prodiobarcode set pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "',pib_ifrecheck=-1,pib_datecode='" + DateCode + "',pib_lotno='" + LotNo + "' where pib_id=" + pibid1 + " and pr_orispeccode='" + PN + "'", "update");
}
}
else
{
string Item = "";
for (int i = 0; i < CheckItem.Count; i++)
{
Item += CheckItem[i].ToString() + " ";
}
//如果通过正则校验,则不需要传递出来的错误信息了
if (!CheckItem.Contains("原厂型号"))
{
ErrorMsg = "";
}
else
{
ErrorMsg = "【" + ErrorMsg + "】";
}
ErrorMsg += Item + "复核不通过";
return false;
}
if (CheckItem.Count == 0 || (ManualCheckCount.Count == 1 && CheckItem.Count == 1))
{
LabelInf.Invalidate();
RefreshProcessData();
if (CurrentRowIndex - 5 > 0)
LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 5;
else
LabelInf.FirstDisplayedScrollingRowIndex = 0;
//如果成功上传了数据
if (LogicHandler.CheckUploadData(pi_inoutno.Text, UploadNum))
{
for (int i = 0; i < dtt.Rows.Count; i++)
{
if (dtt.Rows[i]["pib_ifrecheck"].ToString() != "0" && dtt.Rows[i]["pib_ifupload"].ToString() == "0")
{
dtt.Rows[i]["pib_ifupload"] = -1;
}
}
}
return true;
}
else
{
if (type == "Manual" && CheckItem.Count == 1)
return true;
else
return false;
}
}
else
{
if (RegexMatch("BackCheck", msg, out ErrorMsg))
{
string year = "0";
string month = "0";
string day = "0";
string date = "";
LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = DateCode;
//解析DateCode,将值设置到年月日
try
{
LogicHandler.GetTimeFromDatecode(dh1, DateCode, pi_cardcode.Text, out year, out month, out day, out date);
LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
}
catch (Exception) { }
LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = LotNo;
LabelInf.Rows[CurrentRowIndex].Cells["pib_ifmodify"].Value = true;
LabelInf.Rows[CurrentRowIndex].Cells["pib_ifrecheck"].Value = true;
LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
adh.ExecuteSQLTran("update prodiobarcode set pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1,pib_ifrecheck=-1 where pib_id=" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value);
LogicHandler.CheckUploadData(pi_inoutno.Text, UploadNum);
LabelInf.Invalidate();
return true;
}
return false;
}
}
//只执行一次窗体自适应
bool AutoSized = false;
private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
{
if (!AutoSized)
{
asc.controlAutoSize(this);
AutoSized = true;
}
}
private void LabelFormClose(object sender, EventArgs e)
{
if (GetGridOnly.Checked)
GetInOutInfAndLabelFile();
else
{
GetGridOnly.Checked = true;
GetInOutInfAndLabelFile();
GetGridOnly.Checked = false;
}
}
private bool AutoPrintSingleLabel()
{
//用标签本身的变量作为最外层的循环条件去匹配;
SinglePrint(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
return true;
}
//关闭窗口前提示用户确认
private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
{
//如果不是注销的话
if (!logout)
{
string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (close.ToString() != "Yes")
e.Cancel = true;
else
{
lbl.Quit();
LogManager.DoLog("关闭程序");
}
}
}
///
/// 获取打印标签
///
private void GetInOutInfAndLabelFile()
{
ComBoxClickChangeLabelDoc = false;
Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
sql.Clear();
sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode");
dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
SingleLabelCombox.DisplayMember = "cl_labelname";
SingleLabelCombox.ValueMember = "la_id";
SingleLabelCombox.DataSource = dt;
if (SingleDoc != null)
SingleDoc.Close();
if (!GetGridOnly.Checked)
for (int i = 0; i < dt.Rows.Count; i++)
{
string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
string LabelName = dt.Rows[i]["cl_labelname"].ToString();
System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
if (time.ToString() != file.LastWriteTime.ToString())
BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
}
if (SingleLabelCombox.Text != "")
{
SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
}
sql.Clear();
sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode");
dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
MidLabelCombox.DisplayMember = "cl_labelname";
MidLabelCombox.ValueMember = "la_id";
MidLabelCombox.DataSource = dt;
if (MidDoc != null)
MidDoc.Close();
if (!GetGridOnly.Checked)
for (int i = 0; i < dt.Rows.Count; i++)
{
string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
string LabelName = dt.Rows[i]["cl_labelname"].ToString();
System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
if (time.ToString() != file.LastWriteTime.ToString())
BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
}
if (MidLabelCombox.Text != "")
{
MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
}
//缓存中盒参数
sql.Clear();
sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode");
dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
OutBoxCombox.DisplayMember = "cl_labelname";
OutBoxCombox.ValueMember = "la_id";
OutBoxCombox.DataSource = dt;
if (OutBoxDoc != null)
OutBoxDoc.Close();
if (!GetGridOnly.Checked)
for (int i = 0; i < dt.Rows.Count; i++)
{
string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
string LabelName = dt.Rows[i]["cl_labelname"].ToString();
System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
if (time.ToString() != file.LastWriteTime.ToString())
BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
}
if (OutBoxCombox.Text != "")
{
OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0], "select");
}
//缓存外箱参数
ComBoxClickChangeLabelDoc = true;
}
///
/// 出入库单录入框的回车事件
///
///
///
private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
CurrentPage = 1;
sql.Clear();
sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "' and pi_pdastatus in('已捡料','已复核')");
dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
if (dt.Rows.Count > 0)
{
pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
pi_date.Text = dt.Rows[0]["pi_date"].ToString();
PI_ID = dt.Rows[0]["pi_id"].ToString();
//if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
//{
string[] param = new string[] { PI_ID, "" };
dh.CallProcedure("GetCustBarcode", ref param);
//}
RefreshParamData();
//查询所有的采集策略
sql.Clear();
sql.Append("select sg_id,sg_brand,si_item ,sg_script,max(si_expression)si_expression,instr(sg_name,si_name)itemindex,sg_name,si_name,sg_step from prodiodetail left join ");
sql.Append("product on pd_prodcode=pr_code left join scangroup on nvl(pd_brand,pr_brand) =sg_brand left join scanitem on sg_id=si_sgid ");
sql.Append("where pd_inoutno='" + pi_inoutno.Text + "' and si_enable=-1 group by sg_id,sg_script,sg_brand,si_item,sg_name,si_name,sg_step order by sg_step,itemindex ");
ScanItem = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
sql.Clear();
sql.Append("select distinct sg_brand from prodiodetail left join product on pd_prodcode=pr_code left join scangroup ");
sql.Append("on nvl(pd_brand,pr_brand)=sg_brand where pd_inoutno='" + pi_inoutno.Text + "' and sg_brand is not null");
DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
FrontCombo.DataSource = dt1;
FrontCombo.DisplayMember = "sg_brand";
FrontCombo.ValueMember = "sg_brand";
BackCombo.DataSource = dt1;
BackCombo.DisplayMember = "sg_brand";
BackCombo.ValueMember = "sg_brand";
LoadGridData();
//重新输入单号后清除缓存
MidBoxArgument.Clear();
SingleBoxArgument.Clear();
MidIDAndOutboxcode.Clear();
SingleID.Clear();
thread = new Thread(GetInOutInfAndLabelFile);
stw = new SetLoadingWindow(thread, "正在获取打印标签");
BaseUtil.SetFormCenter(stw);
stw.ShowDialog();
LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
}
else
MessageBox.Show("当前出入库单号" + pi_inoutno.Text + "不存在或未完成捡料!");
}
}
private void SingleBoxPrint()
{
try
{
if (SingleDoc.Variables.FormVariables.Count == 0) { }
}
catch (Exception)
{
MessageBox.Show("单盘标签未维护参数");
}
if (MidLabelAutoPrint.Checked)
{
try
{
if (MidDoc.Variables.FormVariables.Count == 0) { }
}
catch (Exception)
{
MessageBox.Show("中盘标签未维护参数");
}
}
if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
{
//每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
MidIDAndOutboxcode.Clear();
SingleID.Clear();
//获取全部的中盒号
Dictionary outboxcode1 = new Dictionary();
//判断所有盒号为该盒的是否勾选已采集
outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
for (int i = 0; i < LabelInf.Rows.Count; i++)
{
if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
{
//如果不存在中盒号则进行添加
if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
{
MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
}
}
}
if (SingleID.ToArray().Length == 0)
{
MessageBox.Show("选择的行未勾选采集或者已打印");
return;
}
for (int i = 0; i < LabelInf.RowCount; i++)
{
if (i + 1 < LabelInf.RowCount)
{
//如果本行的中盒号和下一行不相等的话
if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
{
if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
}
}
//只要有一行没有采集满就不打印
if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
{
if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
}
}
//用于判断用户是否勾选了行
int CheckedRowCount = 0;
for (int i = 0; i < LabelInf.RowCount; i++)
{
//勾选了并且未打印
if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
{
if (cu_print_checkdatecode.Checked)
{
string datecode = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
string lotno = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
if (datecode == "" || lotno == "")
{
MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
return;
}
}
CheckedRowCount = CheckedRowCount + 1;
CurrentRowIndex = i;
//以标签模板的参数为基准,循环取数
try
{
SinglePrint(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
if (MidLabelAutoPrint.Checked)
{
//判断当前行的盒号和下一行不相等或者已经是最后一行了
if (i + 1 == LabelInf.RowCount || LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1 == LabelInf.RowCount ? i : i + 1].Cells["pib_outboxcode1"].Value.ToString())
{
if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
{
if (MidLabelCombox.SelectedValue != null)
{
MidBoxCodePrint(CurrentRowIndex);
}
}
}
}
//勾选为已打印
LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
}
catch (Exception ex) { LogManager.DoLog(ex.Message); }
}
}
if (CheckedRowCount == 0)
MessageBox.Show("未勾选打印明细!");
else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
CurrentRowIndex = CurrentRowIndex + 1;
outboxcode1.Clear();
}
else
{
MessageBox.Show("此模板尚未维护参数或不存在打印明细");
return;
}
}
private void SingleLabelPrint_Click(object sender, EventArgs e)
{
if (SingleLabelCombox.Text != "")
{
if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
{
try
{
int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
{
for (int i = begin - 1; i < end; i++)
{
LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
}
}
else
{
MessageBox.Show("单盘打印范围错误");
return;
}
}
catch (Exception)
{
MessageBox.Show("单盘打印范围错误");
return;
}
}
thread = new Thread(SingleBoxPrint);
stw = new SetLoadingWindow(thread, "正在打印单盘");
BaseUtil.SetFormCenter(stw);
stw.ShowDialog();
}
else
MessageBox.Show("未维护单盘标签");
}
private void MidBoxLabelPrint()
{
//未输入内容打印全部中盒
if (MidLabelNum.Text == "")
{
int begin = 0;
int end = 0;
if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
{
try
{
begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
if (begin >= minmidbox && end <= maxmidbox && begin <= end)
{
//设置中盒打印范围的行号
for (int i = 0; i < LabelInf.Rows.Count; i++)
{
if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
{
begin = i;
}
if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
{
end = i;
}
}
}
else
{
MessageBox.Show("中盒打印范围错误");
return;
}
}
catch (Exception)
{
MessageBox.Show("中盒打印范围错误");
return;
}
}
MidBoxArgument.Clear();
List MidOutBoxCode = new List();
List MidOutBoxCodeIndex = new List();
string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
{
if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) && LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != "")
MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
if (!MidOutBoxCode.Contains(int.Parse(outboxcode1 == "" ? "0" : outboxcode1)) && outboxcode1 != "")
{
MidOutBoxCode.Add(int.Parse(outboxcode1 == "" ? "0" : outboxcode1));
MidOutBoxCodeIndex.Add(i);
}
}
for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
{
MidBoxCodePrint(MidOutBoxCodeIndex[i]);
}
MidBoxArgument.Clear();
return;
}
bool FindMidLabel = false;
if (MidLabelCombox.SelectedValue != null)
{
//中盒号所在的行
int MidLabelRowIndex = 0;
//缓存中盒数据
for (int i = 0; i < LabelInf.RowCount; i++)
{
if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
{
//找到了输入的中盒号停止循环
FindMidLabel = true;
MidLabelRowIndex = i;
}
}
//找到了指定的盒号
if (FindMidLabel)
MidBoxCodePrint(MidLabelRowIndex);
else
MessageBox.Show("该出入库单未找到该中盒号!");
}
else
MessageBox.Show("未维护中盒模板");
}
private void MidLabelPrint_Click(object sender, EventArgs e)
{
if (MidLabelCombox.Text != "")
{
thread = new Thread(MidBoxLabelPrint);
stw = new SetLoadingWindow(thread, "正在打印中盒");
BaseUtil.SetFormCenter(stw);
stw.ShowDialog();
}
else
MessageBox.Show("未维护中盒标签");
}
private void OutBoxPrint()
{
List Outboxcode = new List();
//如果未勾选箱号则对勾选的数据的箱号进行整合
if (OutBoxNum.Text == "")
{
for (int i = 0; i < LabelInf.RowCount; i++)
{
string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
//如果不包含该箱号则进行添加
if (!Outboxcode.Contains(outboxcode2))
Outboxcode.Add(outboxcode2);
}
//按获取到的箱号列表进行打印
if (Outboxcode.ToArray().Length > 0)
{
try
{
// 循环打印外箱号
for (int i = 0; i < Outboxcode.ToArray().Length; i++)
{
for (int h = 0; h < LabelInf.RowCount; h++)
{
if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
{
OutBoxCodePrint(h);
break;
}
}
}
}
catch { }
}
else
{
MessageBox.Show("请勾选需要打印的外箱");
}
}
else
{
bool FindMidLabel = false;
try
{
int OutBoxLabelRowIndex = 0;
//查找是否存在该中盒号
for (int i = 0; i < LabelInf.RowCount; i++)
{
if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
{
//找到了输入的中盒号停止循环
FindMidLabel = true;
OutBoxLabelRowIndex = i;
break;
}
}
//找到了指定的盒号
if (FindMidLabel)
OutBoxCodePrint(OutBoxLabelRowIndex);
else
MessageBox.Show("该出入库单未找到该外箱号!");
}
catch (Exception) { }
}
Outboxcode.Clear();
}
private void MidBoxCodePrint(int rowindex)
{
if (cu_print_checkdatecode.Checked)
{
string datecode = LabelInf.Rows[rowindex].Cells["pib_datecode"].Value.ToString();
string lotno = LabelInf.Rows[rowindex].Cells["pib_lotno"].Value.ToString();
if (datecode == "" || lotno == "")
{
MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
return;
}
}
//获取对应行的pib_id
string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
sql.Clear();
//设置最少打印盘数
if (OnlyPrint.Checked)
{
if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + pib_outboxcode1) < LeastPrintNum.Value)
{
return;
}
}
//查询参数名称相同的获取到取值字段
for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
{
DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
{
sql.Append(dr1[0]["lp_sql"].ToString() + ",");
}
}
sql.Append("1,");
DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (pib_outboxcode1 == "" ? "0" : pib_outboxcode1), "select");
for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
{
DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length == 0)
dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
{
MidDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
}
//SQL判断多个值的时候
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
{
DataTable dt1 = (DataTable)adh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno.Text + "'").Replace("{2}", pib_outboxcode1), "select");
for (int i = 0; i < dt1.Rows.Count; i++)
{
for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++)
{
if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
{
MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
}
//使用SN开头的参数赋值SN1,SN2,SN3等参数
if (MidDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
{
MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
}
if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
{
string date = dt1.Rows[0][0].ToString();
System.DateTime dtime;
if (System.DateTime.TryParseExact(date, "yyyymmdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime))
{
try
{
date = dtime.ToString(cu_print_dateformat.Text);
}
catch (Exception)
{
date = dtime.ToString("yyyymmdd");
}
MidDoc.Variables.FormVariables.Item(k + 1).Value = date;
}
}
}
}
}
if (MidDoc.Variables.FormVariables.Item(j + 1).Value == "")
{
dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0)
MidDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
}
}
MidDoc.PrintDocument();
}
///
/// 执行打印外箱号
///
private void OutBoxCodePrint(int rowindex)
{
if (cu_print_checkdatecode.Checked)
{
string datecode = LabelInf.Rows[rowindex].Cells["pib_datecode"].Value.ToString();
string lotno = LabelInf.Rows[rowindex].Cells["pib_lotno"].Value.ToString();
if (datecode == "" || lotno == "")
{
MessageLog.AppendText(">>设定必须采集DateCode内容,请先采集再打印\n", Color.Red);
return;
}
}
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
//获取对应行的pib_id
string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
sql.Clear();
for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
{
DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
{
sql.Append(dr1[0]["lp_sql"].ToString() + ",");
}
}
sql.Append("1,");
DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2), "select");
if (dt.Rows.Count > 0)
{
for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
{
DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
//多参数命名
if (dr1.Length == 0)
dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
{
OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
}
//SQL判断多个值的时候
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
{
DataTable dt1 = (DataTable)adh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno.Text + "'").Replace("{2}", pib_outboxcode2), "select");
for (int i = 0; i < dt1.Rows.Count; i++)
{
for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++)
{
if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
{
OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
}
//使用SN开头的参数赋值SN1,SN2,SN3等参数
if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
{
OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
}
if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
{
string date = dt1.Rows[0][0].ToString();
System.DateTime dtime;
if (System.DateTime.TryParseExact(date, "yyyymmdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime))
{
try
{
date = dtime.ToString(cu_print_dateformat.Text);
}
catch (Exception)
{
date = dtime.ToString("yyyymmdd");
}
OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = date;
}
}
}
}
}
if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "")
{
dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0)
OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
}
}
OutBoxDoc.PrintDocument();
}
}
private void OutBoxLabelPrint_Click(object sender, EventArgs e)
{
if (OutBoxCombox.Text != "")
{
thread = new Thread(OutBoxPrint);
stw = new SetLoadingWindow(thread, "正在打印外箱");
BaseUtil.SetFormCenter(stw);
stw.ShowDialog();
}
else
MessageBox.Show("未维护外箱标签");
}
///
/// 刷新采集进度
///
private void RefreshProcessData()
{
if (LabelInf.Rows.Count > 0)
{
//设置初始化的采集进度
int Count = Count = back_adh.getRowCount("prodiobarcode", "pib_ifrecheck=-1 and pib_inoutno='" + pi_inoutno.Text + "'");
string midboxcode = back_adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
string outboxcode = back_adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
//未超出当前范围的时候
int midboxcount = back_adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (midboxcode == "" ? "1" : midboxcode));
int outboxcount = back_adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (outboxcode == "" ? "1" : outboxcode));
midboxProcess.Text = midboxcount + "/" + MidBoxCapacity.Value;
outboxProcess.Text = outboxcount + "/" + OutBoxCapacity.Value;
//设置当前的箱号和盒号
Process_midboxcode.Text = midboxcode == "" ? "1" : midboxcode;
Process_outboxcode.Text = outboxcode == "" ? "1" : outboxcode;
//设置当前总数和已采集数量
CollectedCount.Text = Count + "/" + PageNum.Text.Replace("总数", "");
}
}
private void LoadGridData()
{
thread = new Thread(LoadGridData1);
stw = new SetLoadingWindow(thread, "正在获取条码");
BaseUtil.SetFormCenter(stw);
stw.ShowDialog();
}
private void LoadGridData1()
{
LoadGridData(new object(), new EventArgs());
}
int CurrentPage = 1;
int PageSize = 10000;
int DataSize = 0;
int MaxPageSize = 0;
DataTable LabelInfDataTable;
///
/// 自定义函数 加载明细行的数据,多处使用添加进函数
///
///
///
private void LoadGridData(object sender, EventArgs e)
{
ManualCheckCount.Clear();
sql.Clear();
sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum ");
sql.Append("between " + ((CurrentPage - 1) * PageSize + 1) + " and " + CurrentPage * PageSize + " ");
if (DetailRange.Checked)
{
sql.Append(" and pib_pdno between " + DetailRange1.Value + " and " + DetailRange2.Value);
}
sql.Append(" order by rownum");
LabelInfDataTable = (DataTable)adh.ExecuteSql(sql.ToString(), "select");
if (LabelInfDataTable.Rows.Count == 0)
{
//查询Oracle数据库
sql.Clear();
sql.Append("select t.*,rownum from prodiobarcode_view t where pib_inoutno='" + pi_inoutno.Text + "'");
LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
//检验查询的字段和本地数据库字段是否匹配
adh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
//将数据保存在本地数据库
adh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
if (!DetailRange.Checked)
{
LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize);
}
else
{
LabelInfDataTable = BaseUtil.filterDataTable(LabelInfDataTable, "rownum <=" + PageSize + " and pib_pdno >= " + DetailRange1.Value + " and pib_pdno<=" + DetailRange2.Value);
}
}
bindingsource(LabelInf, LabelInfDataTable);
//LabelInf.DataSource = null;
BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
//获取数据总条数
if (!DetailRange.Checked)
{
DataSize = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "'");
}
else
{
DataSize = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno between " + DetailRange1.Value + " and " + DetailRange2.Value);
}
PageNum.Text = "总数" + DataSize;
MaxPageSize = DataSize % PageSize == 0 ? DataSize / PageSize : (DataSize / PageSize) + 1;
PageInf.Text = CurrentPage + "/" + MaxPageSize;
//获取系统设置的上传数量,如参数异常则默认为100
dt = (DataTable)adh.ExecuteSql("select * from dataextra", "select");
if (dt.Rows.Count > 0)
{
if (!int.TryParse(dt.Rows[0]["uploadnum"].ToString(), out UploadNum))
{
UploadNum = 100;
}
front_sg_separator.Text = dt.Rows[0]["splitfront"].ToString();
back_sg_separator.Text = dt.Rows[0]["splitback"].ToString();
prodcodeback.Text = dt.Rows[0]["prodcodeback"].ToString();
prodcodefront.Text = dt.Rows[0]["prodcodefront"].ToString();
primarydata.Text = dt.Rows[0]["primarydata"].ToString();
guestlabeldata.Text = dt.Rows[0]["guestlabeldata"].ToString();
}
//获取所有的匹配脚本
ScanGroup = (DataTable)dh.ExecuteSql("select distinct sg_brand,sg_id,sg_autolabel,sg_name,sg_script from prodiobarcode left join scangroup on pib_brand=sg_brand where pib_inoutno='" + pi_inoutno.Text + "' and sg_id is not null", "select");
RefreshProcessData();
}
delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
void bindingsource(DataGridView dgv, DataTable dt)
{
if (dgv.InvokeRequired)
{
dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
}
else
{
dgv.AutoGenerateColumns = false;
dgv.DataSource = dt;
}
}
///
/// 重绘Cell的颜色
///
///
///
private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
if (e.ColumnIndex > 0)
{
if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
{
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
Rectangle border = e.CellBounds;
border.Width -= 1;
e.Graphics.DrawRectangle(Pens.White, border);
e.PaintContent(e.CellBounds);
e.Handled = true;
}
if (e.RowIndex >= 0)
{
if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
{
if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
{
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
Rectangle border = e.CellBounds;
border.Width -= 1;
e.Graphics.DrawRectangle(Pens.Black, border);
e.PaintContent(e.CellBounds);
e.Handled = true;
}
}
if (LabelInf.Rows[e.RowIndex].Cells["pib_ifrecheck"].FormattedValue.ToString() == "True")
{
if (LabelInf.Columns[e.ColumnIndex].Name == "pib_barcode")
{
SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
e.Graphics.FillRectangle(Brushes.CadetBlue, e.CellBounds);
Rectangle border = e.CellBounds;
border.Width -= 1;
e.Graphics.DrawRectangle(Pens.Black, border);
e.PaintContent(e.CellBounds);
e.Handled = true;
}
}
}
}
}
private void CusLabelPrint()
{
//MaxOutBoxCode = MaxOutBoxCode + 1;
List CusOutBoxCode = new List();
//统计客户外箱号
if (LabelInf.Rows.Count > 0)
CusOutBoxCode.Add(0);
for (int i = 0; i < LabelInf.Rows.Count; i++)
{
if (i - 1 > 0 && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() == "True")
{
string cutboxcode = LabelInf.Rows[i].Cells["pib_cusoutboxcode"].Value.ToString();
string nextcutboxcode = LabelInf.Rows[i - 1].Cells["pib_cusoutboxcode"].Value.ToString();
if (cutboxcode != nextcutboxcode)
CusOutBoxCode.Add(i);
}
}
}
private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
pi_inoutno_KeyDown(sender, e2);
}
private void AutoPrintMidLabel()
{
if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value) == MidBoxCapacity.Value)
{
if (MidLabelCombox.SelectedValue != null)
{
MidBoxCodePrint(CurrentRowIndex);
}
else
MessageBox.Show("未维护中盒模板");
}
}
private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (close.ToString() == "Yes")
{
if (FrontendCheck.IsOpen)
FrontendCheck.Close();
if (BackendCheck.IsOpen)
BackendCheck.Close();
if (PLC1.IsOpen)
PLC1.Close();
if (ManBackendCheck.IsOpen)
ManBackendCheck.Close();
Login login = new Login();
//注销的时候需要将拼接的连接字符串置空
DataHelper.DBConnectionString = null;
logout = true;
lbl.Quit();
this.Hide();
login.ShowDialog();
this.Close();
}
}
private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
///
/// 切换打开的单盘文件
///
///
///
private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (ComBoxClickChangeLabelDoc)
{
if (SingleDoc != null)
SingleDoc.Close();
if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
{
System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
}
}
}
catch (Exception) { }
}
///
/// 切换打开的中盒文件
///
///
///
private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (ComBoxClickChangeLabelDoc)
{
if (MidDoc != null)
MidDoc.Close();
if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
{
System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
}
}
}
catch (Exception) { }
}
///
/// 切换打开的外箱文件
///
///
///
private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (ComBoxClickChangeLabelDoc)
{
if (OutBoxDoc != null)
OutBoxDoc.Close();
if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
{
System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
}
}
}
catch (Exception) { }
}
private void ExportData_Click(object sender, EventArgs e)
{
ExportFileDialog.Description = "选择导出的路径";
DialogResult result = ExportFileDialog.ShowDialog();
DataTable dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select");
if (result == DialogResult.OK)
{
ExcelHandler eh = new ExcelHandler();
for (int i = dt.Columns.Count - 1; i >= 0; i--)
{
for (int j = 0; j < LabelInf.Columns.Count; j++)
{
//去除ID列
if (dt.Columns[i].ColumnName.Contains("id") || dt.Columns[i].ColumnName == "pib_barcode" || dt.Columns[i].ColumnName == "pib_pdno" || dt.Columns[i].ColumnName == "pib_ifpick" || dt.Columns[i].ColumnName == "pib_ifprint" || dt.Columns[i].ColumnName == "pib_datecode1" || dt.Columns[i].ColumnName == "pr_vendprodcode")
{
dt.Columns.RemoveAt(i);
break;
}
switch (dt.Columns[i].ColumnName)
{
case "pib_lotno":
dt.Columns[i].ColumnName = "批次号";
break;
case "pib_datecode":
dt.Columns[i].ColumnName = "生产日期";
break;
case "pib_custbarcode":
dt.Columns[i].ColumnName = "最小产品包装条码";
break;
default:
break;
}
if (dt.Columns[i].ColumnName == LabelInf.Columns[j].DataPropertyName)
{
dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
break;
}
}
}
eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (close.ToString() == "Yes")
System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
}
}
private void MidBoxCapacity_Leave(object sender, EventArgs e)
{
NumericUpDown nup = (NumericUpDown)sender;
switch (nup.Name)
{
case "MidBoxCapacity":
Properties.Settings.Default.MidBoxCapacity = nup.Value;
Properties.Settings.Default.Save();
break;
case "OutBoxCapacity":
Properties.Settings.Default.OutboxCapacity = nup.Value;
Properties.Settings.Default.Save();
break;
default:
break;
}
}
private void RefreshDBConnect_Tick(object sender, EventArgs e)
{
}
private void ButtonSetting_Click(object sender, EventArgs e)
{
LogMenu.Show(new Point(ButtonSetting.Location.X, ButtonSetting.Location.Y + 20));
}
private void Form_FormClosed(object sender, FormClosedEventArgs e)
{
RefreshParamData();
}
private void Attach_Closed(object sender, FormClosedEventArgs e)
{
RefreshAttachData();
}
private void DetailRange_CheckedChanged(object sender, EventArgs e)
{
if (DetailRange.Checked)
{
if (DetailRange1.Value > DetailRange2.Value)
{
MessageBox.Show("请输入正确的范围");
DetailRange.Checked = false;
return;
}
if (DetailRange1.Value == DetailRange2.Value)
{
if (dh.getRowCount("prodiodetail", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno in(" + DetailRange1.Value + ")") != 1)
{
MessageBox.Show("出货单" + pi_inoutno.Text + "不存在明细序号" + DetailRange1.Value);
DetailRange.Checked = false;
return;
}
}
else
{
if (dh.getRowCount("prodiodetail", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno in(" + DetailRange1.Value + "," + DetailRange2.Value + ")") != 2)
{
MessageBox.Show("出货单" + pi_inoutno.Text + "不存在明细序号" + DetailRange1.Value + "或" + DetailRange2.Value);
DetailRange.Checked = false;
return;
}
}
DetailRange1.Enabled = false;
DetailRange2.Enabled = false;
LoadGridData();
}
else
{
LoadGridData();
DetailRange1.Enabled = true;
DetailRange2.Enabled = true;
}
}
private void PLCStart_Click(object sender, EventArgs e)
{
//查询前端检验的端口号
DataTable dt = (DataTable)adh.ExecuteSql("select comtype,BaudRate,com,datawait,outtime from cominfo", "select");
DataRow[] dr = dt.Select("comtype='PLC1'");
if (dr.Length > 0)
{
if (!PLC1.IsOpen)
{
PLC1.PortName = dr[0]["COM"].ToString();
PLC1.Tag = "PLC1";
PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
PLC1.DataReceived += Serial_DataReceived;
PLC1.Open();
}
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
MessageLog.AppendText("PLC启动成功\n", Color.Blue);
}
}
private void PLCStop_Click(object sender, EventArgs e)
{
LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStop, adh);
MessageLog.AppendText("PLC暂停成功\n", Color.Blue);
}
private void ButtonCollectPass_Click(object sender, EventArgs e)
{
int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
string ErrorMsg = "";
FrontCheckFunction("", out ErrorMsg);
}
private void ButtonRecheckPass_Click(object sender, EventArgs e)
{
string ErrorMsg = "";
int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
BackendCheckFunction("", "Auto", out ErrorMsg);
}
private void ButtonSetMidBox_Click(object sender, EventArgs e)
{
Process_midboxcode.Text = SetMidBox.Text;
}
private void ButtonSetOutBox_Click(object sender, EventArgs e)
{
Process_outboxcode.Text = SetOutBox.Text;
}
private void Collection_CheckedChanged(object sender, EventArgs e)
{
ButtonCollectPass.Enabled = ManualCollection.Checked;
ButtonRecheckPass.Enabled = ManualCollection.Checked;
ButtonSetMidBox.Enabled = ManualCollection.Checked;
ButtonSetOutBox.Enabled = ManualCollection.Checked;
ManualFrontCheck.Enabled = ManualCollection.Checked;
ManualBackCheck.Enabled = ManualCollection.Checked;
ManualAutoCheck.Enabled = ManualCollection.Checked;
if (AutoCollection.Checked)
{
ManualFrontCheck.Checked = false;
ManualBackCheck.Checked = false;
ManualAutoCheck.Checked = false;
}
}
private void AddCutBox_Click(object sender, EventArgs e)
{
Button button = sender as Button;
switch (button.Name)
{
case "AddMidBox":
Process_midboxcode.Text = (int.Parse(Process_midboxcode.Text) + 1).ToString();
break;
case "CutMidBox":
if (int.Parse(Process_midboxcode.Text) > 1)
Process_midboxcode.Text = (int.Parse(Process_midboxcode.Text) - 1).ToString();
break;
case "AddOutBox":
Process_outboxcode.Text = (int.Parse(Process_outboxcode.Text) + 1).ToString();
break;
case "CutOutBox":
if (int.Parse(Process_outboxcode.Text) > 1)
Process_outboxcode.Text = (int.Parse(Process_outboxcode.Text) - 1).ToString();
break;
default:
break;
}
}
private void Page_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
switch ((sender as LinkLabel).Name)
{
case "FirstPage":
CurrentPage = 1;
break;
case "LastPage":
CurrentPage = MaxPageSize;
break;
case "BeforePage":
if (CurrentPage == 1)
{
MessageBox.Show("已经是第一页了", "提示");
return;
}
CurrentPage = CurrentPage - 1;
break;
case "NextPage":
if (CurrentPage == MaxPageSize)
{
MessageBox.Show("已经是最后一页了", "提示");
return;
}
CurrentPage = CurrentPage + 1;
break;
default:
break;
}
PageInf.Text = CurrentPage + "/" + MaxPageSize;
LoadGridData();
}
Dictionary instruct = new Dictionary();
private void RefreshPLCInstruct()
{
//查询所有的PLC指令
DataTable dtPLCInstruct = (DataTable)adh.ExecuteSql("select * from PLCInstruct", "select");
instruct.Clear();
//如果存在指令参数的话则全部添加到键值对当中
if (dtPLCInstruct.Rows.Count > 0)
{
for (int i = 0; i < dtPLCInstruct.Columns.Count; i++)
{
instruct.Add(dtPLCInstruct.Columns[i].ColumnName, dtPLCInstruct.Rows[0][dtPLCInstruct.Columns[i].ColumnName].ToString());
}
}
}
private void MessageLog_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
LogMenu.Show(new Point(MessageLog.Location.X + 100, MessageLog.Location.Y + 20));
}
}
private void UploadData_Click(object sender, EventArgs e)
{
adh.ExecuteSql("update prodiobarcode set pib_ifpick=0,pib_ifprint=0,pib_ifmodify=0 where pib_inoutno='" + pi_inoutno.Text + "' and pib_ifrecheck=0", "update");
if (LogicHandler.CheckUploadData(pi_inoutno.Text))
{
DataTable dtt = LabelInf.DataSource as DataTable;
for (int i = 0; i < dtt.Rows.Count; i++)
{
if (dtt.Rows[i]["pib_ifrecheck"].ToString() != "0" && dtt.Rows[i]["pib_ifupload"].ToString() == "0")
{
dtt.Rows[i]["pib_ifupload"] = -1;
}
}
MessageLog.AppendText(">>上传数据成功\n", Color.Green);
}
else
{
MessageLog.AppendText(">>无可上传数据\n", Color.Red);
}
LoadGridData();
}
private void DocRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
switch ((sender as Control).Name)
{
case "SingleDocRefresh":
if (SingleDoc != null)
SingleDoc.Close();
if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
{
System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
}
break;
case "MidDocRefresh":
if (MidDoc != null)
MidDoc.Close();
if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
{
System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
}
break;
case "OutDocRefresh":
if (OutBoxDoc != null)
OutBoxDoc.Close();
if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
{
System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
}
break;
default:
break;
}
}
private void PageSizeNum_ValueChanged(object sender, EventArgs e)
{
PageSize = int.Parse(PageSizeNum.Value.ToString());
LoadGridData();
}
private void button1_Click(object sender, EventArgs e)
{
string close = MessageBox.Show(this.ParentForm, "是否重新下载服务端条码,将会覆盖本地记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (close.ToString() == "Yes")
{
adh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
LoadGridData();
}
}
private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string columnname = LabelInf.Columns[e.ColumnIndex].Name;
if (columnname == "pib_lotno" || columnname == "pib_datecode")
{
string data = LabelInf.Rows[e.RowIndex].Cells[columnname].Value.ToString();
if (data != "")
{
string close = MessageBox.Show(this.ParentForm, "确认修改该出货明细行" + columnname.Replace("pib_", ""), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (close.ToString() == "Yes")
{
string pib_pdno = LabelInf.Rows[e.RowIndex].Cells["pib_pdno"].Value.ToString();
DataRow[] dr = (LabelInf.DataSource as DataTable).Select("pib_pdno=" + pib_pdno);
for (int i = 0; i < dr.Length; i++)
{
dr[i][columnname] = data;
dr[i]["pib_ifmodify"] = -1;
dr[i]["pib_ifpick"] = -1;
}
adh.UpdateByCondition("prodiobarcode", columnname + "='" + data + "',pib_ifmodify=-1,pib_ifpick=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pib_pdno + "");
LabelInf.Invalidate();
}
}
}
}
private void ManualCheck_CheckedChanged(object sender, EventArgs e)
{
RadioButton ctl = sender as RadioButton;
if (ctl.Checked)
{
switch (ctl.Name)
{
case "ManualBackCheck":
MessageLog.AppendText(">>切换为手动复核模式,需扫描两段数据\n", Color.Blue);
break;
default:
break;
}
}
}
int rowindex = 0;
private void LabelInf_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
rowindex = e.RowIndex;
DateCodeSetAndPrint date = new DateCodeSetAndPrint();
date.Controls["SetValue"].Click += SetValue_ButtonClick;
date.Controls["SetValueAndPrint"].Click += SetValueAndPrint_ButtonClick;
date.ShowDialog();
}
}
private void SetValue_ButtonClick(object sender, EventArgs e)
{
Button setvalue = sender as Button;
string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
string datecode = setvalue.FindForm().Controls["datecode"].Text;
string lotno = setvalue.FindForm().Controls["lotno"].Text;
string nums = setvalue.FindForm().Controls["Nums"].Text;
string year = "0";
string month = "0";
string day = "0";
string date = "";
LogicHandler.GetTimeFromDatecode(dh1, datecode, pi_cardcode.Text, out year, out month, out day, out date);
string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
if (datecode != "")
{
sql += " and (pib_datecode='' or pib_datecode is null) ";
}
if (lotno != "")
{
sql += " and (pib_lotno='' or pib_lotno is null) ";
}
if (nums == "")
{
sql += ")";
}
else
{
sql += " limit 0," + nums + ")";
}
adh.ExecuteSql(sql, "update");
LoadGridData();
setvalue.FindForm().Close();
}
private void SetValueAndPrint_ButtonClick(object sender, EventArgs e)
{
Button setvalueandprint = sender as Button;
string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
string datecode = setvalueandprint.FindForm().Controls["datecode"].Text;
string lotno = setvalueandprint.FindForm().Controls["lotno"].Text;
string nums = setvalueandprint.FindForm().Controls["Nums"].Text;
string year = "0";
string month = "0";
string day = "0";
string date = "";
LogicHandler.GetTimeFromDatecode(dh1, datecode, pi_cardcode.Text, out year, out month, out day, out date);
string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
string PrintSQL = "select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
if (datecode != "")
{
sql += " and (pib_datecode='' or pib_datecode is null) ";
}
if (lotno != "")
{
sql += " and (pib_lotno='' or pib_lotno is null) ";
}
if (nums == "")
{
sql += ")";
}
else
{
sql += " limit 0," + nums + ")";
PrintSQL += " limit 0," + nums;
}
DataTable pibid_dt = (DataTable)adh.ExecuteSql(PrintSQL, "select");
adh.ExecuteSql(sql, "update");
LoadGridData();
for (int i = 0; i < pibid_dt.Rows.Count; i++)
{
SinglePrint(pibid_dt.Rows[i]["pib_id"].ToString());
}
setvalueandprint.FindForm().Close();
}
private void ResetBarcode_Click(object sender, EventArgs e)
{
string close = MessageBox.Show(this.ParentForm, "是否重置本单据条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
if (close == "Yes")
{
dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
adh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
LoadGridData();
}
}
private void SetOutboxBarcode()
{
string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
//解析DateCode,将值设置到年月日
try
{
DataRow[] dr = LabelInfDataTable.Select("pib_id=" + pib_id);
if (dr.Length > 0)
{
try
{
dr[0]["pib_year"] = year;
dr[0]["pib_month"] = month;
dr[0]["pib_day"] = day;
}
catch { }
}
}
catch (Exception) { }
int outboxcode1 = Outbox1;
int outboxcode2 = Outbox2;
string pd_id = LabelInf.Rows[CurrentRowIndex].Cells["pd_id"].Value.ToString();
//如果满容量获取过箱号就不再重复获取了
//bool GetBarcode = false;
//获取当前的行号
decimal CurrentRowNum = decimal.Parse(LabelInf.Rows[CurrentRowIndex].Cells["rownum"].Value.ToString());
//超过中盒容量中盒号+1
if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + outboxcode1) >= MidBoxCapacity.Value)
{
outboxcode1 = outboxcode1 + 1;
//GetBarcode = true;
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
//LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
}
else if (CurrentRowNum - 1 >= 0)
{
//获取上一行的数据
DataTable LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum == 1 ? 1 : CurrentRowNum - 1), "select");
//string custmidboxcode = LastRowData.Rows[0]["pib_custmidboxcode"].ToString();
//if (custmidboxcode == "")
//{
// LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
// LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
//}
//或者不符合合并条件中盒号+1
if (cu_print_midlotno.Checked)
{
string TempData = LastRowData.Rows[0]["pib_lotno"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString()/* /* && !GetBarcode/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
outboxcode1 = outboxcode1 + 1;
}
}
else if (cu_print_midpo.Checked)
{
string TempData = LastRowData.Rows[0]["pd_pocode"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
outboxcode1 = outboxcode1 + 1;
}
}
else if (cu_print_midprod.Checked)
{
string TempData = LastRowData.Rows[0]["pd_custprodcode"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
outboxcode1 = outboxcode1 + 1;
}
}
else if (cu_print_midspec.Checked)
{
string TempData = LastRowData.Rows[0]["pd_custprodspec"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
outboxcode1 = outboxcode1 + 1;
}
}
else if (cu_print_middc.Checked)
{
string TempData = LastRowData.Rows[0]["pib_datecode"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LogicHandler.SendDataToPLC(PLC1, PLCInstruct.MaterialTray, adh);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
outboxcode1 = outboxcode1 + 1;
}
}
//if (LastRowData.Rows[0]["pib_custmidboxcode"].ToString() == MidBoxBarCode)
// LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = LastRowData.Rows[0]["pib_custmidboxcode"].ToString();
//else
// LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
}
else
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custmidboxcode"].Value = MidBoxBarCode;
}
//GetBarcode = false;
if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + outboxcode2) >= OutBoxCapacity.Value)
{
//GetBarcode = true;
outboxcode2 = outboxcode2 + 1;
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
}
else if (CurrentRowNum - 1 >= 0)
{
//获取上一行数据
DataTable LastRowData = (DataTable)adh.ExecuteSql("select pib_lotno,pib_custmidboxcode,pib_custoutboxcode,pd_pocode,pd_custprodcode,pd_custprodspec,pib_datecode from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and rownum=" + (CurrentRowNum == 1 ? 1 : CurrentRowNum - 1), "select");
//string custoutboxcode = LastRowData.Rows[0]["pib_custoutboxcode"].ToString();
//if (custoutboxcode == "")
//{
// LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
// LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
//}
//或者不符合合并条件中盒号+1
if (cu_print_outlotno.Checked)
{
string TempData = LastRowData.Rows[0]["pib_lotno"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
outboxcode2 = outboxcode2 + 1;
}
}
else if (cu_print_outpo.Checked)
{
string TempData = LastRowData.Rows[0]["pd_pocode"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
outboxcode2 = outboxcode2 + 1;
}
}
else if (cu_print_outprod.Checked)
{
string TempData = LastRowData.Rows[0]["pd_custprodcode"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
outboxcode2 = outboxcode2 + 1;
}
}
else if (cu_print_outspec.Checked)
{
string TempData = LastRowData.Rows[0]["pd_custprodspec"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
outboxcode2 = outboxcode2 + 1;
}
}
else if (cu_print_outdc.Checked)
{
string TempData = LastRowData.Rows[0]["pib_datecode"].ToString();
if (TempData != "" && TempData != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString() /* && !GetBarcode*/)
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
outboxcode2 = outboxcode2 + 1;
}
}
//if (OutBoxBarCode == LastRowData.Rows[0]["pib_custoutboxcode"].ToString())
// LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = LastRowData.Rows[0]["pib_custoutboxcode"].ToString();
//else
// LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
}
else
{
//LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
//LabelInf.Rows[CurrentRowIndex].Cells["pib_custoutboxcode"].Value = OutBoxBarCode;
}
//设置中盒外箱号
LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value = outboxcode1;
LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = outboxcode2;
if (SingleLabelAutoPrint.Checked)
adh.ExecuteSql("update prodiobarcode set pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "',pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1 where pib_id=" + pib_id, "update");
else
adh.ExecuteSql("update prodiobarcode set pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "',pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1 where pib_id=" + pib_id, "update");
LabelInf.Invalidate();
}
private void SinglePrint(string pib_id)
{
StringBuilder sql = new StringBuilder();
sql.Clear();
for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
{
DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
{
sql.Append(dr1[0]["lp_sql"].ToString() + ",");
}
}
sql.Append("1,");
DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
{
DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
{
DataTable dt1 = (DataTable)adh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
if (dt1.Rows.Count > 0)
{
SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt1.Rows[0][0].ToString();
if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
{
string date = dt1.Rows[0][0].ToString();
System.DateTime dtime;
if (System.DateTime.TryParseExact(date, "yyyymmdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime))
{
try
{
date = dtime.ToString(cu_print_dateformat.Text);
}
catch (Exception)
{
date = dtime.ToString("yyyymmdd");
}
SingleDoc.Variables.FormVariables.Item(j + 1).Value = date;
}
}
}
}
else if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
{
SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
}
if (SingleDoc.Variables.FormVariables.Item(j + 1).Value == "")
{
dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
if (dr1.Length > 0)
SingleDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
}
}
SingleDoc.PrintDocument();
LogicHandler.UpdateRowPrinted(pib_id);
}
private void RefreshAttachData()
{
Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
}
private void RefreshParamData()
{
//获取客户自定义设置
sql.Clear();
sql.Append("select cu_print_middc,cu_print_limiteddate,cu_print_outdc,cu_print_dateformat,cu_print_checkdatecode,cu_print_midlotno,nvl(cu_print_custprodmatchmodel,'Equal')cu_print_custprodmatchmodel,cu_print_midspec,cu_print_midpo,cu_print_midprod,cu_print_outlotno,cu_print_outspec,cu_print_outpo");
sql.Append(",cu_print_outprod,cu_print_checkonly,nvl(cu_print_papercount,0)cu_print_papercount,cu_print_regexpression,cu_print_recheck from customer where cu_code='" + pi_cardcode.Text + "'");
DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
if (dt.Rows.Count > 0)
{
BaseUtil.SetFormValue(this.Controls, dt);
switch (dt.Rows[0]["cu_print_custprodmatchmodel"].ToString())
{
case "Equal":
Equal.Checked = true;
break;
case "Expression":
Expression.Checked = true;
break;
default:
Equal.Checked = true;
break;
}
switch (dt.Rows[0]["cu_print_recheck"].ToString())
{
case "CP":
RecheckCuprodcode.Checked = true;
break;
case "BR":
RecheckBarcode.Checked = true;
break;
default:
RecheckCuprodcode.Checked = true;
break;
}
}
ScanGroup = (DataTable)dh.ExecuteSql("select distinct sg_brand,sg_id,sg_autolabel,sg_name,sg_script from prodiobarcode left join scangroup on pib_brand=sg_brand where pib_inoutno='" + pi_inoutno.Text + "' and sg_id is not null", "select");
}
int Outbox1;
int Outbox2;
private void Process_midboxcode_TextChanged(object sender, EventArgs e)
{
int.TryParse(Process_midboxcode.Text, out Outbox1);
}
private void Process_outboxcode_TextChanged(object sender, EventArgs e)
{
int.TryParse(Process_outboxcode.Text, out Outbox2);
}
private void LabelPrinter_UserOnSelectIndexChange(object sender, EventArgs e)
{
switch ((sender as Control).Parent.Name)
{
case "SingleLabelPrinter":
if (SingleDoc != null)
SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
break;
case "MidLabelPrinter":
if (MidDoc != null)
MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
break;
case "OutBoxPrinter":
if (OutBoxDoc != null)
OutBoxDoc.Printer.SwitchTo(OutBoxLabelPrint.Text);
break;
default:
break;
}
}
private void LogMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
switch (e.ClickedItem.Text)
{
case "采集策略设置":
采集策略_NEW form = new 采集策略_NEW();
form.FormClosed += Form_FormClosed;
BaseUtil.SetFormCenter(form);
form.ShowDialog();
break;
case "生成条码":
生成条码 form3 = new 生成条码(pi_inoutno.Text);
form3.FormClosed += Form_FormClosed;
BaseUtil.SetFormCenter(form3);
form3.ShowDialog();
break;
case "附加信息设置":
if (pi_cardcode.Text != "")
{
附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
att.FormClosed += Attach_Closed;
att.ShowDialog();
}
else MessageBox.Show("请先获取出库单信息");
break;
case "客户标签维护":
客户标签维护 form1 = new 客户标签维护();
form1.FormClosed += Form_FormClosed;
BaseUtil.SetFormCenter(form1);
if (SingleDoc != null)
SingleDoc.Close();
if (MidDoc != null)
MidDoc.Close();
if (OutBoxDoc != null)
OutBoxDoc.Close();
form1.FormClosed += LabelFormClose;
form1.ShowDialog();
break;
case "客户采集规则":
CustomerRule cust = new CustomerRule();
cust.FormClosed += Form_FormClosed;
BaseUtil.SetFormCenter(cust);
cust.ShowDialog();
break;
case "参数配置":
ParamSetting form2 = new ParamSetting();
form2.FormClosed += Form_FormClosed;
BaseUtil.SetFormCenter(form2);
form2.ShowDialog();
break;
case "权限管理":
PowerSetting pws = new PowerSetting();
BaseUtil.SetFormCenter(pws);
pws.ShowDialog();
break;
default:
break;
}
}
private void MessageLog_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.I)
{
adh.ExecuteSql(MessageLog.Text, "update");
}
}
}
}