| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587 |
- 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.Linq;
- using System.Diagnostics;
- using LabelManager2;
- using UAS_LabelMachine.PublicMethod;
- using UAS_LabelMachine.Entity;
- using UAS_特殊解析规则;
- using UAS_LabelMachine.PublicForm;
- using System.Threading;
- using System.IO;
- using System.Globalization;
- using System.IO.Ports;
- using UAS_LabelMachine.CustomControl;
- namespace UAS_LabelMachine
- {
- public partial class UAS_出货标签打印 : Form
- {
- //自适应屏幕
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- AccessDBHelper adh;
- DataTable dt;
- StringBuilder sql = new StringBuilder();
- /// <summary>
- /// CodeSoft新建打印机引擎
- /// </summary>
- ApplicationClass lbl;
- /// <summary>
- /// 单盘打印文件
- /// </summary>
- Document SingleDoc;
- /// <summary>
- /// 中盒打印文件
- /// </summary>
- Document MidDoc;
- /// <summary>
- /// 外箱打印文件
- /// </summary>
- Document OutBoxDoc;
- /// <summary>
- /// Loading窗口
- /// </summary>
- SetLoadingWindow stw;
- /// <summary>
- /// 弹窗线程
- /// </summary>
- Thread thread;
- /// <summary>
- /// 当前品牌
- /// </summary>
- string Brand;
- string PI_ID;
- /// <summary>
- /// 当前扫描的所在行
- /// </summary>
- int CurrentRowIndex = 0;
- /// <summary>
- /// 最大的出入口单号
- /// </summary>
- int MaxOutBoxCode = 1;
- /// <summary>
- /// 正则表达式用于项目匹配
- /// </summary>
- Regex reg;
- /*标识供应商物料编号采集是否通过*/
- bool CollectVeProdCodePass = true;
- bool CollectQTYPass = true;
- bool logout = false;
- DataTable SingleLabelParam;
- DataTable MidLabelParam;
- DataTable OutLabelParam;
- /// <summary>
- /// 存放单盘的ID
- /// </summary>
- List<string> SingleID = new List<string>();
- /// <summary>
- /// 单盘的打印参数
- /// </summary>
- List<string> SingleBoxArgument = new List<string>();
- /// <summary>
- /// 存放中盒的ID和盒号
- /// </summary>
- Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
- /// <summary>
- /// 中盒的打印参数
- /// </summary>
- List<string> MidBoxArgument = new List<string>();
- /// <summary>
- /// 全部采集
- /// </summary>
- bool AllCollect = false;
- /// <summary>
- /// 是否全选
- /// </summary>
- bool AllChecked = false;
- /// <summary>
- /// 默认采集了指定的数据上传
- /// </summary>
- int UploadNum = 100;
- /// <summary>
- /// 是否获取过箱号
- /// </summary>
- bool GetPackingCode = false;
- string SG_Script;
- Dictionary<int, string> Si_Item = new Dictionary<int, string>();
- /*需要重绘的Cell*/
- Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
- /// <summary>
- /// 是否通过选择Combox来改变打开的文件
- /// </summary>
- bool ComBoxClickChangeLabelDoc = false;
- DataTable Attach;
- public UAS_出货标签打印(string Master)
- {
- InitializeComponent();
- 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;
- adh = SystemInf.adh;
- CheckForIllegalCrossThreadCalls = false;
- pi_inoutno.Focus();
- sg_code.FormName = Name;
- sg_code.SetValueField = new string[] { "sg_code" };
- sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
- sg_code.TableName = "scangroup";
- sg_code.DbChange += Sg_code_DbChange;
- Point pt = new Point();
- //禁止所有列的排序
- foreach (DataGridViewColumn dgv in LabelInf.Columns)
- {
- dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
- }
- 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);
- //实例化打印进程
- try
- {
- lbl = new ApplicationClass();
- }
- catch (Exception)
- {
- MessageBox.Show("未安装CodeSoft软件或者版本不正确");
- }
- RefreshDBConnect.Interval = 60000;
- RefreshDBConnect.Start();
- DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
- DataRow[] dr = dt.Select("comtype='FrontendCheck'");
- if (dr.Length > 0)
- {
- FrontendCheck.PortName = dr[0]["COM"].ToString();
- FrontendCheck.Tag = "FrontendCheck";
- FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
- FrontendCheck.DataReceived += Serial_DataReceived;
- FrontendCheck.Open();
- }
- dr = dt.Select("comtype='BackendCheck'");
- if (dr.Length > 0)
- {
- BackendCheck.PortName = dr[0]["COM"].ToString();
- BackendCheck.Tag = "BackendCheck";
- BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
- BackendCheck.DataReceived += Serial_DataReceived;
- BackendCheck.Open();
- }
- }
- //获取串口数据
- private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
- {
- try
- {
- SerialPortWithTag port = sender as SerialPortWithTag;
- int len = port.BytesToRead;
- byte[] readBuffer = new byte[len];
- port.Read(readBuffer, 0, len); //将数据读入缓存
- string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号
- string LotNo = "";
- string DateCode = "";
- string Order = "";
- string QTY = "";
- string PN = "";
- string OutBox = "";
- string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- switch (port.Tag)
- {
- case "FrontendCheck":
- FrontCollect.Text = msg;
- MatchCollection matchs = reg.Matches(msg);
- int index = 0;
- foreach (var item in Si_Item)
- {
- switch (item.Value)
- {
- case "DateCode":
- DateCode = matchs[index].Value;
- break;
- case "LotNo":
- LotNo = matchs[index].Value;
- break;
- case "PN":
- PN = matchs[index].Value;
- break;
- case "Order":
- Order = matchs[index].Value;
- break;
- case "QTY":
- QTY = matchs[index].Value;
- break;
- case "OutBox":
- OutBox = matchs[index].Value;
- break;
- default:
- break;
- }
- index = index + 1;
- }
- adh.ExecuteSql("update prodiobarcode set pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "' where pib_id=" + pib_id, "update");
- break;
- case "BackendCheck":
- BackCheck.Text = msg;
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message, "提示信息");
- }
- }
- private void Sg_code_DbChange(object sender, EventArgs e)
- {
- DataTable dt = sg_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, dt);
- }
- //只执行一次窗体自适应
- bool AutoSized = false;
- private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
- {
- if (!AutoSized)
- {
- asc.controlAutoSize(this);
- AutoSized = true;
- }
- }
- private void LabelMaintain_Click(object sender, EventArgs e)
- {
- 客户标签维护 form = new 客户标签维护();
- BaseUtil.SetFormCenter(form);
- if (SingleDoc != null)
- SingleDoc.Close();
- if (MidDoc != null)
- MidDoc.Close();
- if (OutBoxDoc != null)
- OutBoxDoc.Close();
- form.FormClosed += LabelFormClose;
- form.ShowDialog();
- }
- private void LabelFormClose(object sender, EventArgs e)
- {
- if (GetGridOnly.Checked)
- GetInOutInfAndLabelFile();
- else
- {
- GetGridOnly.Checked = true;
- GetInOutInfAndLabelFile();
- GetGridOnly.Checked = false;
- }
- }
- //输入框Enter事件
- private void Input_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (BackCheck.Text == "")
- {
- MessageBox.Show("采集的数据不能为空");
- return;
- }
- if (Si_ItemDGV.Rows.Count == 0)
- {
- MessageBox.Show("未维护采集策略");
- return;
- }
- CollectInputData();
- }
- }
- /// <summary>
- /// 采集数据
- /// </summary>
- private void CollectInputData()
- {
- LogManager.DoLog("采集数据【" + BackCheck.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
- {
- //数据校验均已通过则勾选上已采集
- if (CollectVeProdCodePass && CollectQTYPass)
- {
- //如果按盒号采集,所有的此盒的均更新为
- DataTable dt = (DataTable)MidSource.DataSource;
- LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
- LogicHandler.UpdateRowPicked(LabelInf.Rows[CurrentRowIndex].Cells["pib_id"].Value);
- LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
- //勾选了单盘自动打印
- if (SingleLabelAutoPrint.Checked)
- {
- if (SingleLabelCombox.SelectedValue != null)
- {
- AutoPrintSingleLabel();
- }
- else
- {
- MessageBox.Show("未维护单盘标签");
- return;
- }
- }
- //勾选了中盒自动打印
- if (MidLabelAutoPrint.Checked)
- AutoPrintMidLabel();
- }
- //采集未通过的时候
- else
- {
- //如果自动采集采集未成功需要移动到下一行
- if (!AutoMatch.Checked)
- SetRowIndexToCollectRow();
- }
- //未勾选自动匹配,设置到下一个未采集的行
- if (!AutoMatch.Checked)
- SetRowIndexToCollectRow();
- }
- //提醒用户需要采集的数据
- RemindUser();
- RefreshProcessData();
- MessageLog.AppendText(">>扫描到数据" + BackCheck.Text + "\n", Color.Blue);
- //如果所采集的行的物料不一样的话,重新计算箱内容量
- if (CurrentRowIndex - 1 > 0)
- {
- string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
- string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
- }
- }
- //设置行的索引到当前需要采集的行
- private void SetRowIndexToCollectRow()
- {
- //获取当前需要采集的行
- for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
- {
- griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
- CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
- break;
- }
- }
- }
- private void AutoPrintSingleLabel()
- {
- //用标签本身的变量作为最外层的循环条件去匹配;
- string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- StringBuilder ParamLog = new StringBuilder();
- sql.Clear();
- sql.Append("select * from ");
- for (int i = 0; i < SingleLabelParam.Rows.Count; i++)
- {
- if (i != SingleLabelParam.Rows.Count - 1)
- sql.Append("(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + "),");
- else
- sql.Append("(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + ")");
- }
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id), "select");
- for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
- {
- if (dt.Columns.Contains(SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()))
- SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString();
- if (SingleDoc.Variables.FreeVariables.Item(i + 1).Value == "")
- {
- DataRow[] dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
- }
- }
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- LogicHandler.UpdateRowPrinted(pib_id);
- LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
- }
- /// <summary>
- /// 提醒用户当前采集的项目
- /// </summary>
- private void RemindUser()
- {
- SetRowIndexToCollectRow();
- }
- //
- /// <summary>
- /// 设置外箱号
- /// </summary>
- /// <param name="BatchCollect">是否批量采集</param>
- private void SetOutBoxCode2(bool BatchCollect)
- {
- if (OutboxCapacity.Value != 0)
- {
- //获取当前出入口单最大的外箱号
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
- if (outboxcode.Contains("-"))
- {
- if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
- MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
- }
- else
- {
- if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
- MaxOutBoxCode = int.Parse(outboxcode);
- }
- }
- //统计最大的箱号存在多少
- int MaxOutBoxCodeCount = 0;
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
- MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
- }
- //如果是获取过包装单的话则不再继续追加箱号
- if (!GetPackingCode)
- {
- //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
- if (BatchCollect)
- {
- if (MaxOutBoxCodeCount < OutboxCapacity.Value)
- LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
- else
- {
- MaxOutBoxCode = MaxOutBoxCode + 1;
- LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
- }
- }
- else
- {
- if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
- LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
- else
- {
- MaxOutBoxCode = MaxOutBoxCode + 1;
- LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
- }
- }
- }
- }
- }
- //关闭窗口前提示用户确认
- 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("关闭程序");
- }
- }
- }
- /// <summary>
- /// 获取打印标签
- /// </summary>
- 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);
- SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql 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);
- MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql 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);
- 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;
- }
- /// <summary>
- /// 出入库单录入框的回车事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- sql.Clear();
- sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
- 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", param);
- }
- LoadGridData(sender, e);
- //重新输入单号后清除缓存
- MidBoxArgument.Clear();
- SingleBoxArgument.Clear();
- MidIDAndOutboxcode.Clear();
- SingleID.Clear();
- //刷新采集进度
- RefreshProcessData();
- thread = new Thread(GetInOutInfAndLabelFile);
- stw = new SetLoadingWindow(thread, "正在获取打印标签");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
- }
- else
- MessageBox.Show("当前出入库单号不存在!");
- }
- }
- private void SingleBoxPrint()
- {
- try
- {
- if (SingleDoc.Variables.FreeVariables.Count == 0) { }
- }
- catch (Exception)
- {
- MessageBox.Show("单盘标签未维护参数");
- }
- if (MidLabelAutoPrint.Checked)
- {
- try
- {
- if (MidDoc.Variables.FreeVariables.Count == 0) { }
- }
- catch (Exception)
- {
- MessageBox.Show("中盘标签未维护参数");
- }
- }
- if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
- {
- //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
- MidIDAndOutboxcode.Clear();
- SingleID.Clear();
- //获取全部的中盒号
- Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
- //判断所有盒号为该盒的是否勾选已采集
- 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["Choose"].FormattedValue.ToString() == "True" && 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["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
- {
- CheckedRowCount = CheckedRowCount + 1;
- CurrentRowIndex = i;
- //以标签模板的参数为基准,循环取数
- try
- {
- string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
- sql.Clear();
- sql.Append("select * from ");
- for (int j = 0; j < SingleLabelParam.Rows.Count; j++)
- {
- if (j != SingleLabelParam.Rows.Count - 1)
- sql.Append("(" + SingleLabelParam.Rows[j]["lp_sql"].ToString() + "),");
- else
- sql.Append("(" + SingleLabelParam.Rows[j]["lp_sql"].ToString() + ")");
- }
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id), "select");
- for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
- {
- if (dt.Columns.Contains(SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower()))
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower()].ToString();
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
- {
- DataRow[] dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
- }
- }
- SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
- SingleDoc.PrintDocument();
- LogicHandler.UpdateRowPrinted(pib_id);
- 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); }
- }
- }
- dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
- 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["Choose"].Value = true;
- 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<int> MidOutBoxCode = new List<int>();
- List<int> MidOutBoxCodeIndex = new List<int>();
- 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()))
- MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
- if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
- {
- MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
- 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<string> Outboxcode = new List<string>();
- //如果未勾选箱号则对勾选的数据的箱号进行整合
- if (OutBoxNum.Text == "")
- {
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
- {
- 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)
- {
- //获取对应行的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();
- sql.Append("select * from ");
- for (int i = 0; i < MidLabelParam.Rows.Count; i++)
- {
- if (i != MidLabelParam.Rows.Count - 1)
- sql.Append("(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + "),");
- else
- sql.Append("(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + ")");
- }
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode1}", pib_outboxcode1), "select");
- for (int i = 0; i < MidDoc.Variables.FreeVariables.Count; i++)
- {
- if (dt.Columns.Contains(MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()))
- MidDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString();
- if (MidDoc.Variables.FreeVariables.Item(i + 1).Value == "")
- {
- DataRow[] dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- MidDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
- }
- }
- MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
- MidDoc.PrintDocument();
- }
- /// <summary>
- /// 执行打印外箱号
- /// </summary>
- private void OutBoxCodePrint(int rowindex)
- {
- //获取对应行的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();
- sql.Append("select * from ");
- for (int i = 0; i < OutLabelParam.Rows.Count; i++)
- {
- if (i != OutLabelParam.Rows.Count - 1)
- sql.Append("(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + "),");
- else
- sql.Append("(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + ")");
- }
- DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode2}", pib_outboxcode2), "select");
- for (int i = 0; i < OutBoxDoc.Variables.FreeVariables.Count; i++)
- {
- if (dt.Columns.Contains(OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()))
- OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString();
- if (OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value == "")
- {
- DataRow[] dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
- }
- }
- OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
- 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("未维护外箱标签");
- }
- /// <summary>
- /// 刷新采集进度
- /// </summary>
- private void RefreshProcessData()
- {
- if (LabelInf.Rows.Count > 0)
- {
- //设置初始化的采集进度
- int Count = 0;
- int CurrentMidBoxCollectedCount = 0;
- //当前盒号的总盘数
- int CurrentMidBoxTotalCount = 0;
- //未超出当前范围的时候
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
- Count++;
- //和当前编辑箱号相等行
- if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
- CurrentMidBoxCollectedCount++;
- //当前盒号一共有几盘
- if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
- CurrentMidBoxTotalCount++;
- }
- Capacity.Text = "可装" + CurrentMidBoxTotalCount + "盘";
- Installed.Text = "已装" + CurrentMidBoxCollectedCount + "盘";
- //设置当前的箱号和盒号
- Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
- Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
- //设置当前总数和已采集数量
- TotalCount.Text = LabelInf.RowCount.ToString();
- CollectedCount.Text = Count.ToString();
- }
- }
- private void LoadGridData()
- {
- LoadGridData(new object(), new EventArgs());
- }
- /// <summary>
- /// 自定义函数 加载明细行的数据,多处使用添加进函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LoadGridData(object sender, EventArgs e)
- {
- AllCollect = false;
- dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select");
- if (dt.Rows.Count == 0)
- {
- sql.Clear();
- sql.Append("select pd_custprodcode,pib_inoutno,pd_custprodspec,nvl(pib_ifrecheck,0)pib_ifrecheck,nvl(pib_ifupload,0)pib_ifupload,nvl(pib_ifmodify,0)pib_ifmodify,pd_pocode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand, pr_vendprodcode,");
- sql.Append("pib_lotno,pib_datecode,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl(pib_ifprint,0)pib_ifprint");
- sql.Append(" from prodiobarcode left join prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and ");
- sql.Append(" pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode ");
- sql.Append("where pib_piid='" + PI_ID + "' order by to_number(pib_outboxcode1),pib_id,pd_prodcode");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- adh.SaveDataTable(dt, "prodiobarcode");
- }
- //获取系统设置的上传数量,如参数异常则默认为100
- if (!int.TryParse(adh.getFieldDataByCondition("dataextra", "uploadnum", "id=1").ToString(), out UploadNum))
- {
- UploadNum = 100;
- }
- MidSource.DataSource = dt;
- BaseUtil.FillDgvWithDataTable(LabelInf, (DataTable)MidSource.DataSource);
- //有数据的话默认取第一条的品牌去取采集策略
- TotalCount.Text = LabelInf.RowCount.ToString();
- if (LabelInf.RowCount > 0)
- {
- Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
- if (Brand != "")
- {
- dt = (DataTable)dh.ExecuteSql("select sg_script,sg_id from scangroup where sg_brand='" + Brand + "'", "select");
- if (dt.Rows.Count > 0)
- {
- string sgid = dt.Rows[0]["sg_id"].ToString();
- SG_Script = dt.Rows[0]["sg_script"].ToString();
- reg = new Regex(SG_Script);
- DataTable dt1 = (DataTable)dh.ExecuteSql("select si_name,si_item,si_expression from scanitem where si_sgid='" + sgid + "' and si_enable<>0", "select");
- for (int i = 0; i < dt1.Rows.Count; i++)
- {
- if (SG_Script.IndexOf(dt1.Rows[i]["si_name"].ToString()) >= 0)
- {
- Si_Item.Add(SG_Script.IndexOf(dt1.Rows[i]["si_name"].ToString()), dt1.Rows[i]["si_item"].ToString());
- }
- }
- //根据索引进行排序
- Si_Item = (from entry in Si_Item orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
- }
- }
- }
- //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
- {
- griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
- pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
- CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
- break;
- }
- }
- }
- /// <summary>
- /// 重绘Cell的颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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)
- {
- //重绘制定的Cell,表示采集的数量不匹配
- if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_qty"]))
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_qty"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.Black, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- //表示采集的供应商物料编号不匹配
- if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]))
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.Black, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- //表示采集的供应商物料编号不匹配
- if (LabelInf.Columns[e.ColumnIndex].Name == "pib_brand" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_brand"]))
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_brand"]] ? Brushes.ForestGreen : Brushes.Red, 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<int> CusOutBoxCode = new List<int>();
- //统计客户外箱号
- 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);
- }
- /// <summary>
- /// 采集明细切换
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void griddetno_KeyDown(object sender, KeyEventArgs e)
- {
- if (Keys.Enter == e.KeyData)
- {
- bool FindDetno = false;
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
- {
- FindDetno = true;
- CurrentRowIndex = i;
- RemindUser();
- break;
- }
- }
- if (!FindDetno)
- {
- MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
- return;
- }
- }
- }
- private void AutoPrintMidLabel()
- {
- bool FullBox = true;
- //判断所有盒号未该盒的是否勾选已采集
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- 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")
- FullBox = false;
- }
- }
- //如果当前箱号已经装满了
- if (FullBox)
- {
- if (MidLabelCombox.SelectedValue != null)
- {
- MidBoxCodePrint(CurrentRowIndex);
- }
- else
- MessageBox.Show("未维护中盒模板");
- }
- }
- /// <summary>
- /// 勾选的时候自动打印
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
- {
- string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
- try
- {
- System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
- GregorianCalendar gc = new GregorianCalendar();
- int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
- if (weekOfYear < 10)
- LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
- else
- LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
- }
- catch (Exception) { }
- }
- }
- private void AllCollected_Click(object sender, EventArgs e)
- {
- if (AllCollect == false)
- {
- foreach (DataGridViewRow dr in LabelInf.Rows)
- dr.Cells[1].Value = true;
- AllCollect = true;
- }
- else
- {
- foreach (DataGridViewRow dr in LabelInf.Rows)
- dr.Cells[1].Value = false;
- AllCollect = false;
- }
- }
- private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (close.ToString() == "Yes")
- {
- 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) { }
- /// <summary>
- /// 切换打开的单盘文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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) { }
- }
- /// <summary>
- /// 切换打开的中盒文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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) { }
- }
- /// <summary>
- /// 切换打开的外箱文件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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 ChooseAll_Click(object sender, EventArgs e)
- {
- if (AllChecked)
- {
- foreach (DataGridViewRow dr in LabelInf.Rows)
- dr.Cells[0].Value = false;
- AllChecked = false;
- }
- else
- {
- foreach (DataGridViewRow dr in LabelInf.Rows)
- dr.Cells[0].Value = true;
- AllChecked = true;
- }
- }
- private void ExportData_Click(object sender, EventArgs e)
- {
- ExportFileDialog.Description = "选择导出的路径";
- DialogResult result = ExportFileDialog.ShowDialog();
- if (result == DialogResult.OK)
- {
- ExcelHandler eh = new ExcelHandler();
- DataTable dt = ((DataTable)MidSource.DataSource).Copy();
- 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.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifpick" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
- {
- dt.Columns.RemoveAt(i);
- break;
- }
- switch (dt.Columns[i].ColumnName.ToLower())
- {
- 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.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
- {
- 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)
- {
- dh.getRowCount("employee", "1=1");
- }
- private void ButtonSetting_Click(object sender, EventArgs e)
- {
- ListButtonMenu.BringToFront();
- ListButtonMenu.Visible = true;
- }
- private void ListButtonMenu_SelectedIndexChanged(object sender, EventArgs e)
- {
- ListButtonMenu.Visible = false;
- switch (ListButtonMenu.SelectedItem.ToString())
- {
- case "采集策略设置":
- 采集策略_NEW form = new 采集策略_NEW();
- BaseUtil.SetFormCenter(form);
- form.ShowDialog();
- break;
- case "附加信息设置":
- if (pi_cardcode.Text != "")
- {
- 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
- att.ShowDialog();
- }
- else MessageBox.Show("请先获取出库单信息");
- break;
- case "客户标签维护":
- 客户标签维护 form1 = new 客户标签维护();
- 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();
- BaseUtil.SetFormCenter(cust);
- cust.ShowDialog();
- break;
- case "参数配置":
- ParamSetting form2 = new ParamSetting();
- BaseUtil.SetFormCenter(form2);
- form2.ShowDialog();
- break;
- default:
- break;
- }
- }
- }
- }
|