| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889 |
- 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;
- 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;
- string PI_ID;
- /// <summary>
- /// 当前扫描的所在行
- /// </summary>
- int CurrentRowIndex = 0;
- /// <summary>
- /// 正则表达式用于项目匹配
- /// </summary>
- Regex reg;
- bool logout = false;
- string SplitChar = ",@#| &";
- 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>
- int UploadNum = 100;
- /*需要重绘的Cell*/
- Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
- /// <summary>
- /// 是否通过选择Combox来改变打开的文件
- /// </summary>
- bool ComBoxClickChangeLabelDoc = false;
- /// <summary>
- /// 附加信息DataTable
- /// </summary>
- DataTable Attach;
- /// <summary>
- /// 采集策略DataTable
- /// </summary>
- DataTable ScanGroup;
- /// <summary>
- /// 采集明细DataTable
- /// </summary>
- DataTable ScanItem;
- 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();
- 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);
- //实例化打印进程
- 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();
- }
- }
- string LotNo = "";
- string DateCode = "";
- string Order = "";
- string QTY = "";
- string PN = "";
- string OutBox = "";
- //获取串口数据
- 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 pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- 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":
- break;
- case "PLC2":
- break;
- case "FrontendCheck":
- //比对当前箱数量和容量
- FrontCollect.Text = msg;
- string ErrorMsg = "";
- if (!FrontCheckFunction(msg, out ErrorMsg))
- {
- MessageLog.AppendText(">>" + ErrorMsg + "\n", Color.Red);
- }
- else
- {
- //勾选了单盘自动打印
- if (SingleLabelAutoPrint.Checked)
- {
- if (SingleLabelCombox.SelectedValue != null)
- {
- AutoPrintSingleLabel();
- }
- else
- {
- MessageBox.Show("未维护单盘标签");
- return;
- }
- }
- //勾选了中盒自动打印
- if (MidLabelAutoPrint.Checked)
- AutoPrintMidLabel();
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_ifpick"] = true;
- LabelInf.Refresh();
- }
- break;
- case "BackendCheck":
- BackCheck.Text = msg;
- BackendCheckFunction(msg, pib_id);
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- LogManager.DoLog(ex.StackTrace);
- MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message, "提示信息");
- }
- }
- private bool FrontCheckFunction(string msg, out string ErrorMsg)
- {
- int GroupCount = 0;
- ErrorMsg = "";
- 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);
- int index = 0;
- //自动获取分隔符号,分割解析到的数据
- char Splitor = BaseUtil.GetSplitChar(matchs1.Value.ToString());
- string[] sgarr = sg_script.Split(Splitor);
- string[] arr = matchs1.Value.Split(Splitor);
- DataTable dt = BaseUtil.filterDataTable(ScanItem, "sg_id=" + sg_id);
- List<int> ItemIndex = new List<int>();
- for (int j = 0; j < sgarr.Length; j++)
- {
- for (int k = 0; k < dt.Rows.Count; k++)
- {
- if (sgarr[j].Contains(dt.Rows[k]["si_name"].ToString()))
- {
- ItemIndex.Add(j);
- }
- }
- }
- //成功获取到了分隔符号并且匹配的项次相等, 如果不包含分隔符只需要一项
- if (matchs1.Value.ToString() != "" && ((SplitChar.Contains(Splitor.ToString()) && ItemIndex.Count == dt.Rows.Count) || (!SplitChar.Contains(Splitor.ToString()) && ItemIndex.Count == 1 && arr.Length == 1)))
- {
- string ItemStr = "";
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- 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);
- DateCode = si_exp.Match(arr[ItemIndex[j]]).Value;
- }
- else
- {
- DateCode = arr[ItemIndex[j]];
- }
- break;
- case "LotNo":
- LotNo = arr[ItemIndex[j]];
- break;
- case "PN":
- PN = arr[ItemIndex[j]];
- //自动匹配客户PN
- DataTable pndt = BaseUtil.filterDataTable(LabelInfDataTable, "pr_orispeccode='" + PN + "' and pib_ifpick=0 ");
- int rownum = 0;
- if (pndt.Rows.Count > 0)
- {
- rownum = int.Parse(pndt.Rows[0]["rownum"].ToString());
- CurrentRowIndex = rownum - 1;
- }
- else
- {
- ErrorMsg = "未能匹配到合适的原厂型号";
- }
- break;
- case "Order":
- Order = arr[ItemIndex[j]];
- if (LabelInfDataTable.Rows[CurrentRowIndex]["pd_pocode"].ToString() != Order)
- {
- ErrorMsg = "订单号不匹配";
- }
- break;
- case "QTY":
- if (si_expression != "")
- {
- si_exp = new Regex(si_expression);
- QTY = si_exp.Match(arr[ItemIndex[j]]).Value;
- }
- else
- {
- QTY = arr[ItemIndex[j]];
- }
- break;
- case "OutBox":
- OutBox = arr[ItemIndex[j]];
- break;
- default:
- break;
- }
- index = index + 1;
- }
- if (ErrorMsg == "" && ItemStr.Contains("QTY") && LabelInfDataTable.Rows[CurrentRowIndex]["pib_qty"].ToString() != QTY.ToString())
- {
- ErrorMsg = "数量不匹配";
- }
- if (ErrorMsg == "" && ItemStr.Contains("PO") && LabelInfDataTable.Rows[CurrentRowIndex]["pd_pocode"].ToString() != Order)
- {
- ErrorMsg = "订单号不匹配";
- }
- //如果品牌不对应的话则不能使用本次的匹配规则
- if (LabelInfDataTable.Rows[CurrentRowIndex]["pib_brand"].ToString() != sg_brand)
- {
- break;
- }
- }
- else
- {
- GroupCount = GroupCount + 1;
- }
- }
- if (GroupCount == ScanGroup.Rows.Count)
- {
- ErrorMsg = "未匹配到合适的采集策略";
- }
- if (ErrorMsg != "")
- {
- return false;
- }
- else
- {
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_datecode"] = DateCode;
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_lotno"] = LotNo;
- return true;
- }
- }
- //外箱条码号
- string OutBoxBarCode = "";
- //中盒条码号
- string MidBoxBarCode = "";
- private void BackendCheckFunction(string msg, string pib_id)
- {
- DataTable dtt = LabelInf.DataSource as DataTable;
- string[] msgArr = msg.Split(back_sg_separator.Text.ToCharArray());
- //需要校验2项数据,完成校验后此项的值需要为2则表示校验成功
- int checkItemCount = 0;
- for (int i = 0; i < msgArr.Length; i++)
- {
- if (RecheckCuprodcode.Checked)
- {
- //直接验证两个值相等
- if (Equal.Checked)
- {
- if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
- {
- checkItemCount = checkItemCount + 1;
- }
- }
- //验证正则匹配过之后相等
- else if (Expression.Checked)
- {
- Regex re = new Regex(cu_print_regexpression.Text);
- if (re.Match(msgArr[i]).Value == LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
- {
- checkItemCount = checkItemCount + 1;
- }
- }
- if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pr_orispeccode"].Value.ToString())
- {
- checkItemCount = checkItemCount + 1;
- }
- }
- else if (RecheckBarcode.Checked)
- {
- if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pib_custbarcode"].Value.ToString())
- {
- checkItemCount = checkItemCount + 1;
- }
- if (msgArr[i] == LabelInf.Rows[CurrentRowIndex].Cells["pr_orispeccode"].Value.ToString())
- {
- checkItemCount = checkItemCount + 1;
- }
- }
- }
- if (checkItemCount != 2)
- {
- MessageBox.Show("复核不通过");
- return;
- }
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_ifrecheck"] = true;
- adh.ExecuteSql("update prodiobarcode set pib_ifrecheck=-1 where pib_id=" + pib_id, "update");
- LabelInf.Refresh();
- //获取当前最大的箱号
- string boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
- int outboxcode1 = int.Parse(boxcode == "" ? "1" : boxcode);
- boxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
- int outboxcode2 = int.Parse(boxcode == "" ? "1" : boxcode);
- string pd_id = LabelInf.Rows[CurrentRowIndex].Cells["pd_id"].Value.ToString();
- //超过中盒容量中盒号+1
- if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + outboxcode1) >= MidBoxCapacity.Value)
- {
- outboxcode1 = outboxcode1 + 1;
- }
- else if (CurrentRowIndex - 1 >= 0)
- {
- //或者不符合合并条件中盒号+1
- if (cu_print_midlotno.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custmidboxcode"] = MidBoxBarCode;
- outboxcode1 = outboxcode1 + 1;
- }
- }
- else if (cu_print_midpo.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custmidboxcode"] = MidBoxBarCode;
- outboxcode1 = outboxcode1 + 1;
- }
- }
- else if (cu_print_midprod.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pr_orispeccode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custmidboxcode"] = MidBoxBarCode;
- outboxcode1 = outboxcode1 + 1;
- }
- }
- else if (cu_print_midspec.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_custprodspec"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custmidboxcode"] = MidBoxBarCode;
- outboxcode1 = outboxcode1 + 1;
- }
- }
- else if (cu_print_middc.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custmidboxcode"] = MidBoxBarCode;
- outboxcode1 = outboxcode1 + 1;
- }
- }
- if (MidBoxBarCode == "")
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- }
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custmidboxcode"] = MidBoxBarCode;
- }
- if (adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + outboxcode2) >= OutBoxCapacity.Value)
- {
- outboxcode2 = outboxcode2 + 1;
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- else if (CurrentRowIndex - 1 >= 0)
- {
- //或者不符合合并条件中盒号+1
- if (cu_print_outlotno.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- }
- else if (cu_print_outpo.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_pocode"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- }
- else if (cu_print_outprod.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pr_orispeccode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodcode"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- }
- else if (cu_print_outspec.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pd_custprodspec"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pd_custprodspec"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- }
- else if (cu_print_outdc.Checked)
- {
- if (LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString())
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out MidBoxBarCode);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- }
- if (OutBoxBarCode == "")
- {
- LogicHandler.GetBarCode(PI_ID, pd_id, 1, out OutBoxBarCode);
- }
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_custoutboxcode"] = OutBoxBarCode;
- }
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_outboxcode1"] = outboxcode1;
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_outboxcode2"] = outboxcode2;
- adh.ExecuteSql("update prodiobarcode set pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1 where pib_id=" + pib_id, "update");
- LabelInf.Refresh();
- if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
- CurrentRowIndex = CurrentRowIndex + 1;
- RefreshProcessData();
- if (CurrentRowIndex - 10 > 0)
- LabelInf.FirstDisplayedScrollingRowIndex = CurrentRowIndex - 10;
- //如果成功上传了数据
- 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;
- }
- }
- }
- }
- //只执行一次窗体自适应
- 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;
- }
- }
- private void AutoPrintSingleLabel()
- {
- //用标签本身的变量作为最外层的循环条件去匹配;
- string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- sql.Clear();
- for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
- {
- DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- sql.Append(dr1[0]["lp_sql"].ToString() + ",");
- }
- }
- DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
- for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
- {
- DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(i + 1).Value == "")
- {
- 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);
- LabelInfDataTable.Rows[CurrentRowIndex]["pib_ifprint"] = 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("关闭程序");
- }
- }
- }
- /// <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)
- {
- 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 + "'");
- 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);
- }
- //获取客户自定义设置
- sql.Clear();
- sql.Append("select cu_print_middc,cu_print_outdc,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 + "'");
- 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;
- }
- }
- //查询所有的采集策略
- 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(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["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")
- {
- CheckedRowCount = CheckedRowCount + 1;
- CurrentRowIndex = i;
- //以标签模板的参数为基准,循环取数
- try
- {
- string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
- sql.Clear();
- for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
- {
- DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- sql.Append(dr1[0]["lp_sql"].ToString() + ",");
- }
- }
- 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.FreeVariables.Count; j++)
- {
- DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
- }
- if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
- {
- 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);
- }
- }
- }
- }
- //勾选为已打印
- LabelInfDataTable.Rows[i]["pib_ifprint"] = 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++)
- {
- LabelInfDataTable.Rows[i]["pib_ifpick"] = true;
- LabelInfDataTable.Rows[i]["pib_ifprint"] = 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());
- string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
- if (!MidOutBoxCode.Contains(int.Parse(outboxcode1 == "" ? "0" : 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<string> Outboxcode = new List<string>();
- //如果未勾选箱号则对勾选的数据的箱号进行整合
- 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)
- {
- //获取对应行的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.FreeVariables.Count; j++)
- {
- DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- sql.Append(dr1[0]["lp_sql"].ToString() + ",");
- }
- }
- DataTable dt = (DataTable)adh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + "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.FreeVariables.Count; j++)
- {
- DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- MidDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
- }
- if (MidDoc.Variables.FreeVariables.Item(j + 1).Value == "")
- {
- dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- MidDoc.Variables.FreeVariables.Item(j + 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();
- for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
- {
- DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- sql.Append(dr1[0]["lp_sql"].ToString() + ",");
- }
- }
- 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.FreeVariables.Count; j++)
- {
- DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- {
- OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
- }
- if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value == "")
- {
- dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
- if (dr1.Length > 0)
- OutBoxDoc.Variables.FreeVariables.Item(j + 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 = Count = adh.getRowCount("prodiobarcode", "pib_ifrecheck=-1");
- string midboxcode = "";
- string outboxcode = "";
- if (CurrentRowIndex - 1 >= 0)
- {
- outboxcode = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_outboxcode2"].Value.ToString();
- midboxcode = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_outboxcode1"].Value.ToString();
- }
- //未超出当前范围的时候
- int midboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (midboxcode == "" ? "0" : midboxcode));
- int outboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (outboxcode == "" ? "0" : outboxcode));
- midboxProcess.Text = midboxcount + "/" + MidBoxCapacity.Value;
- outboxProcess.Text = outboxcount + "/" + OutBoxCapacity.Value;
- //设置当前的箱号和盒号
- Process_midboxcode.Text = midboxcode;
- Process_outboxcode.Text = outboxcode;
- //设置当前总数和已采集数量
- CollectedCount.Text = Count + "/" + PageNum.Text.Replace("总数", "");
- }
- }
- private void LoadGridData()
- {
- LoadGridData(new object(), new EventArgs());
- }
- int CurrentPage = 1;
- int PageSize = 1000;
- int DataSize = 0;
- int MaxPageSize = 0;
- DataTable LabelInfDataTable;
- /// <summary>
- /// 自定义函数 加载明细行的数据,多处使用添加进函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void LoadGridData(object sender, EventArgs e)
- {
- 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)
- {
- //嵌套查询重置RowNum
- sql.Clear();
- sql.Append("select t.*,rownum from (select pr_detail,pib_custoutboxcode,pib_custmidboxcode,pr_orispeccode,pd_id,pd_custprodcode,pib_indate,pi_date,pib_inoutno,pd_custprodspec,");
- sql.Append("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_id,pib_pdid,pib_piid,");
- sql.Append("pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand, pr_vendprodcode,pib_lotno,pib_datecode,pib_qty,pr_spec,pi_title,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,");
- sql.Append("pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join prodinout on pib_piid=pi_id left join prodiodetail on pib_piid=pd_piid and ");
- sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode where pib_piid='" + PI_ID + "' order by to_number(pib_id))t");
- 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);
- }
- }
- //获取数据总条数
- 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;
- BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
- //获取系统设置的上传数量,如参数异常则默认为100
- dt = (DataTable)adh.ExecuteSql("select uploadnum,splitback,splitfront 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();
- }
- //获取所有的匹配脚本
- ScanGroup = (DataTable)dh.ExecuteSql("select distinct sg_brand,sg_id,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 and nvl(sg_autolabel,0)=0", "select");
- //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
- for (int i = 0; i < LabelInf.RowCount; i++)
- {
- if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
- {
- 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)
- {
- 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_custbarcode")
- {
- 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<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);
- }
- 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("未维护中盒模板");
- }
- }
- 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 ExportData_Click(object sender, EventArgs e)
- {
- ExportFileDialog.Description = "选择导出的路径";
- DialogResult result = ExportFileDialog.ShowDialog();
- if (result == DialogResult.OK)
- {
- ExcelHandler eh = new ExcelHandler();
- DataTable dt = LabelInfDataTable;
- 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;
- case "权限管理":
- PowerSetting pws = new PowerSetting();
- BaseUtil.SetFormCenter(pws);
- pws.ShowDialog();
- break;
- default:
- break;
- }
- }
- 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
- {
- DetailRange1.Enabled = true;
- DetailRange2.Enabled = true;
- }
- }
- private void PLCStart_Click(object sender, EventArgs e)
- {
- //查询前端检验的端口号
- DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
- DataRow[] dr = dt.Select("comtype='PLC1'");
- if (dr.Length > 0)
- {
- if (!PLC1.IsOpen)
- {
- PLC1.PortName = dr[0]["COM"].ToString();
- PLC1.Tag = "FrontendCheck";
- PLC1.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
- PLC1.DataReceived += Serial_DataReceived;
- PLC1.Open();
- }
- LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart);
- MessageLog.AppendText("PLC启动成功",Color.Blue);
- }
- }
- private void PLCStop_Click(object sender, EventArgs e)
- {
- LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStop);
- MessageLog.AppendText("PLC暂停成功", Color.Blue);
- }
- private void ButtonCollectPass_Click(object sender, EventArgs e)
- {
- string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- 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 pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
- int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
- BackendCheckFunction("", pib_id);
- }
- 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;
- }
- 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();
- }
- }
- }
|