UAS_出货标签管理.cs 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Diagnostics;
  10. using LabelManager2;
  11. using UAS_LabelMachine.PublicMethod;
  12. using UAS_LabelMachine.Entity;
  13. using UAS_LabelMachine.PublicForm;
  14. using System.Threading;
  15. using System.IO;
  16. using System.Globalization;
  17. using System.Reflection;
  18. using Seagull.BarTender.Print;
  19. namespace UAS_LabelMachine
  20. {
  21. public partial class UAS_出货标签打印 : Form
  22. {
  23. //自适应屏幕
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. SqliteDBHelper sdh;
  27. DataTable dt;
  28. /// <summary>
  29. /// 已经打印过的Vivo外箱号
  30. /// </summary>
  31. List<string> PrintedVivoOutboxCode = new List<string>();
  32. StringBuilder sql = new StringBuilder();
  33. /// <summary>
  34. /// CodeSoft新建打印机引擎
  35. /// </summary>
  36. ApplicationClass lbl;
  37. /// <summary>
  38. /// CodeSoft单盘打印文件
  39. /// </summary>
  40. Document SingleDoc;
  41. /// <summary>
  42. /// CodeSoft中盒打印文件
  43. /// </summary>
  44. Document MidDoc;
  45. /// <summary>
  46. /// CodeSoft外箱打印文件
  47. /// </summary>
  48. Document OutBoxDoc;
  49. /// <summary>
  50. /// Loading窗口
  51. /// </summary>
  52. SetLoadingWindow stw;
  53. /// <summary>
  54. /// 弹窗线程
  55. /// </summary>
  56. Thread thread;
  57. /// <summary>
  58. /// 当前品牌
  59. /// </summary>
  60. string Brand;
  61. string PI_ID;
  62. /// <summary>
  63. /// 当前扫描的项目
  64. /// </summary>
  65. int CurrentItemIndex = 0;
  66. /// <summary>
  67. /// 当前扫描的所在行
  68. /// </summary>
  69. int CurrentRowIndex = 0;
  70. /// <summary>
  71. /// 最大的出入口单号
  72. /// </summary>
  73. int MaxOutBoxCode = 1;
  74. /// <summary>
  75. /// 正则表达式用于项目匹配
  76. /// </summary>
  77. Regex reg;
  78. /*标识供应商物料编号采集是否通过*/
  79. bool CollectVeProdCodePass = true;
  80. bool CollectQTYPass = true;
  81. bool logout = false;
  82. //每个不同序号存在的
  83. object[] ItemData;
  84. DataTable SingleLabelParam;
  85. DataTable MidLabelParam;
  86. DataTable OutLabelParam;
  87. /// <summary>
  88. /// BarTender引擎
  89. /// </summary>
  90. Engine engine;
  91. LabelFormatDocument EmptySingleFormat;
  92. LabelFormatDocument EmptyOutFormat;
  93. /// <summary>
  94. /// BarTender单盘
  95. /// </summary>
  96. LabelFormatDocument SingleFormat;
  97. /// <summary>
  98. /// BarTender中盒
  99. /// </summary>
  100. LabelFormatDocument MidFormat;
  101. /// <summary>
  102. /// BarTender外箱
  103. /// </summary>
  104. LabelFormatDocument OutFormat;
  105. Dictionary<string, string> CollectData;
  106. //缓存单盘数据数据的DataTable
  107. /// <summary>
  108. /// 存放单盘的ID
  109. /// </summary>
  110. List<string> SingleID = new List<string>();
  111. /// <summary>
  112. /// 单盘的打印参数
  113. /// </summary>
  114. List<string> SingleBoxArgument = new List<string>();
  115. /// <summary>
  116. /// 中盒缓存数据
  117. /// </summary>
  118. /// <summary>
  119. /// 存放中盒的ID和盒号
  120. /// </summary>
  121. Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
  122. /// <summary>
  123. /// 中盒的打印参数
  124. /// </summary>
  125. List<string> MidBoxArgument = new List<string>();
  126. /// <summary>
  127. /// 全部采集
  128. /// </summary>
  129. bool AllCollect = false;
  130. /// <summary>
  131. /// 是否获取过箱号
  132. /// </summary>
  133. bool GetPackingCode = false;
  134. /*用于存放采集项目的Grid信息*/
  135. Dictionary<string, Dictionary<string, string>> SiItem;
  136. int CloumnCount = 0;
  137. //使用二维数组进行排序
  138. ArrayList<ArrayList<string>> ScanData;
  139. ArrayList<string> GetData;
  140. /// <summary>
  141. /// 是否通过选择Combox来改变打开的文件
  142. /// </summary>
  143. bool ComBoxClickChangeLabelDoc = false;
  144. List<string> MidParam = new List<string>();
  145. List<string> OutParam = new List<string>();
  146. public static DataTable Attach;
  147. public string PrintMethod = "CodeSoft";
  148. /// <summary>
  149. /// 用于记录外箱号和当前的箱号进行比对,判断当前行和上一行是否是同一个箱号,从而判断是否要打印空白页
  150. /// </summary>
  151. public string Last_OutboxCode = "";
  152. public UAS_出货标签打印(string Master)
  153. {
  154. //设置窗体的双缓冲
  155. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  156. this.UpdateStyles();
  157. InitializeComponent();
  158. //利用反射设置DataGridView的双缓冲
  159. Type dgvType = this.LabelInf.GetType();
  160. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  161. pi.SetValue(this.LabelInf, true, null);
  162. Text = Text + "-" + Master;
  163. }
  164. protected override void WndProc(ref System.Windows.Forms.Message m)
  165. {
  166. //拦截双击标题栏、移动窗体的系统消息
  167. if (m.Msg != 0xA3)
  168. {
  169. base.WndProc(ref m);
  170. }
  171. }
  172. private void 贴标机条码打印_Load(object sender, EventArgs e)
  173. {
  174. //杀死之前全部未关闭的进程
  175. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  176. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  177. for (int i = 0; i < processes1.Length; i++)
  178. {
  179. processes1[i].Kill();
  180. }
  181. for (int i = 0; i < processes.Length; i++)
  182. {
  183. processes[i].Kill();
  184. }
  185. //用计时器重置数据库链接
  186. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  187. dh = SystemInf.dh;
  188. sdh = SystemInf.sdh;
  189. sdh.ExecuteZip();
  190. CheckForIllegalCrossThreadCalls = false;
  191. CloumnCount = LabelInf.Columns.Count;
  192. pi_inoutno.TableName = "prodinout";
  193. pi_inoutno.Field = "pi_inoutno";
  194. pi_inoutno.ValueField = "pi_inoutno";
  195. pi_inoutno.Condition = "pi_class in('出货单','拨出单')";
  196. pi_inoutno.Focus();
  197. //将本地读取的打印机设置进Combox,并选中默认打印机
  198. sg_code.FormName = Name;
  199. sg_code.SetValueField = new string[] { "sg_code" };
  200. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  201. sg_code.TableName = "scangroup";
  202. sg_code.DbChange += Sg_code_DbChange;
  203. pr_code.FormName = Name;
  204. pr_code.SetValueField = new string[] { "pr_code" };
  205. pr_code.TableName = "prodiodetail left join product on pd_prodcode=pr_code";
  206. pr_code.SelectField = "pd_pdno # 行号,pr_code # 物料编号";
  207. cu_code.FormName = Name;
  208. cu_code.SetValueField = new string[] { "cu_code" };
  209. cu_code.TableName = "customer";
  210. cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  211. CollectionUnit.Text = "盘";
  212. Point pt = new Point();
  213. //禁止所有列的排序
  214. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  215. {
  216. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  217. }
  218. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  219. //设置获取当前屏幕大小自动全屏但是保留任务栏
  220. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  221. Top = 0;
  222. Left = 0;
  223. Width = ScreenArea.Width;
  224. Height = ScreenArea.Height;
  225. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  226. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  227. SingleLabelPrinter.Text = Properties.Settings.Default.SinglePrinter;
  228. MidLabelPrinter.Text = Properties.Settings.Default.MidPrinter;
  229. OutBoxPrinter.Text = Properties.Settings.Default.OutPrinter;
  230. asc.controllInitializeSize(this);
  231. asc.controlAutoSize(this);
  232. string Code = dh.GetConfig("PrintMethod", "CodeOrBar").ToString();
  233. SystemInf.CheckDcAndLotNo = dh.GetConfig("PrintCheck", "CheckDcAndLotNo").ToString() == "" ? false : true;
  234. if (dh.GetConfig("isSpeac", "LabelSpace").ToString() == "" ? false : true)
  235. {
  236. LabelSpace.Visible = true;
  237. LabelSpace.Checked = true;
  238. }
  239. if (Code == "")
  240. {
  241. try
  242. {
  243. lbl = new ApplicationClass();
  244. }
  245. catch (Exception)
  246. {
  247. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  248. }
  249. }
  250. else
  251. {
  252. engine = new Engine(true);
  253. PrintMethod = "BarTender";
  254. }
  255. pi_inoutno.BringToFront();
  256. }
  257. private void Sg_code_DbChange(object sender, EventArgs e)
  258. {
  259. DataTable dt = sg_code.ReturnData;
  260. BaseUtil.SetFormValue(this.Controls, dt);
  261. }
  262. //只执行一次窗体自适应
  263. bool AutoSized = false;
  264. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  265. {
  266. if (!AutoSized)
  267. {
  268. asc.controlAutoSize(this);
  269. AutoSized = true;
  270. }
  271. }
  272. private void GenerateBarCode_Click(object sender, EventArgs e)
  273. {
  274. 生成条码 form = new 生成条码(pi_inoutno.Text);
  275. form.FormClosed += LoadGridData;
  276. BaseUtil.SetFormCenter(form);
  277. form.ShowDialog();
  278. }
  279. private void LabelFormClose(object sender, EventArgs e)
  280. {
  281. if (GetGridOnly.Checked)
  282. GetInOutInfAndLabelFile();
  283. else
  284. {
  285. GetInOutInfAndLabelFile();
  286. }
  287. }
  288. /// <summary>
  289. /// 保存明细
  290. /// </summary>
  291. /// <param name="sender"></param>
  292. /// <param name="e"></param>
  293. private void SaveGrid_Click(object sender, EventArgs e)
  294. {
  295. DataTable dt = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_ifpick=-1 ", "select");
  296. if (dt.Rows.Count > 0)
  297. {
  298. dh.CallProcedure("sp_uploadbarcode", dt);
  299. MessageBox.Show("保存成功!");
  300. }
  301. }
  302. //放大镜选择后出发的事件
  303. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  304. {
  305. //取已启用的的按照采集次序排序
  306. dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_expressionitem,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where sg_code='" + sg_code.Text + "' and si_enable<>0 order by si_detno,si_innerdetno", "select");
  307. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  308. if (dt.Rows.Count > 0)
  309. {
  310. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  311. }
  312. //按DetNo排列之后的采集项
  313. ScanData = new ArrayList<ArrayList<string>>();
  314. //每个采集项目的子项
  315. GetData = new ArrayList<string>();
  316. //将数据添加进一个List的二维数组中
  317. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  318. {
  319. //如果不包含这个则添加进数组
  320. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  321. {
  322. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  323. }
  324. //如果和后一个的采集次序相同
  325. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  326. {
  327. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  328. }
  329. else
  330. {
  331. ScanData.Add(GetData);
  332. //添加完一次数据需要一个新的List
  333. GetData = new ArrayList<string>();
  334. }
  335. }
  336. RemindUser();
  337. if (ScanData.ToArray().Length > 0)
  338. {
  339. object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).ToArray();
  340. if (arr.Contains("MPN"))
  341. {
  342. AutoMatch.CheckState = CheckState.Checked;
  343. AutoMatch.Enabled = true;
  344. }
  345. else
  346. {
  347. AutoMatch.CheckState = CheckState.Unchecked;
  348. AutoMatch.Enabled = false;
  349. }
  350. }
  351. }
  352. //输入框Enter事件
  353. private void Input_KeyDown(object sender, KeyEventArgs e)
  354. {
  355. if (e.KeyCode == Keys.Enter)
  356. {
  357. if (Input.Text == "")
  358. {
  359. MessageBox.Show("采集的数据不能为空");
  360. return;
  361. }
  362. if (Si_ItemDGV.Rows.Count == 0)
  363. {
  364. MessageBox.Show("未维护采集策略");
  365. return;
  366. }
  367. CollectInputData();
  368. }
  369. }
  370. /// <summary>
  371. /// 设置自动匹配的数据的行号
  372. /// </summary>
  373. /// <returns></returns>
  374. private void SetAutoMatchRow()
  375. {
  376. //采集策略的第一组数据
  377. string[] arr = new string[ItemData.Length];
  378. if (sg_separator.Text == "")
  379. {
  380. for (int i = 0; i < arr.Length; i++)
  381. {
  382. arr[i] = Input.Text;
  383. }
  384. }
  385. else
  386. {
  387. arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray();
  388. }
  389. bool FindAutoMatch = false;
  390. for (int i = 0; i < LabelInf.RowCount; i++)
  391. {
  392. for (int j = 0; j < arr.Length; j++)
  393. {
  394. if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  395. {
  396. CurrentRowIndex = i;
  397. FindAutoMatch = true;
  398. break;
  399. }
  400. }
  401. if (FindAutoMatch)
  402. break;
  403. }
  404. }
  405. /// <summary>
  406. /// 采集数据
  407. /// </summary>
  408. private void CollectInputData()
  409. {
  410. LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
  411. //按DetNo排列之后的采集项
  412. ScanData = new ArrayList<ArrayList<string>>();
  413. //每个采集项目的子项
  414. GetData = new ArrayList<string>();
  415. //用于保存采集策略的具体信息
  416. SiItem = new Dictionary<string, Dictionary<string, string>>();
  417. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  418. {
  419. //如果不包含这个则添加进数组
  420. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  421. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  422. //如果和后一个的采集次序相同
  423. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  424. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  425. else
  426. {
  427. ScanData.Add(GetData);
  428. //添加完一次数据需要一个新的List
  429. GetData = new ArrayList<string>();
  430. }
  431. Dictionary<string, string> item = new Dictionary<string, string>();
  432. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  433. {
  434. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  435. }
  436. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  437. }
  438. //采集项目的数组
  439. ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  440. //分隔符不为空的时候 //采集的项和Grid的数目不等
  441. //用户采集的数据的分割数组
  442. CollectData = new Dictionary<string, string>();
  443. if (sg_separator.Text == "")
  444. {
  445. for (int i = 0; i < ItemData.Length; i++)
  446. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  447. }
  448. else
  449. {
  450. int DataCount = Input.Text.Split(sg_separator.Text.ToCharArray()).Length;
  451. if (DataCount > ItemData.Length)
  452. {
  453. MessageBox.Show("采集数据大于采集项次");
  454. return;
  455. }
  456. else if (DataCount < ItemData.Length)
  457. {
  458. MessageBox.Show("采集数据小于采集项次");
  459. return;
  460. }
  461. for (int i = 0; i < DataCount; i++)
  462. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text.Split(sg_separator.Text.ToCharArray())[i]);
  463. }
  464. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  465. if (ItemData.Length > 0)
  466. {
  467. //CollectData.Clear();
  468. //for (int i = 0; i < ItemData.Length; i++)
  469. //{
  470. // CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  471. //}
  472. //勾选了自动匹配调用该函数
  473. if (AutoMatch.Checked)
  474. SetAutoMatchRow();
  475. //将筛选之后的值赋给Cell
  476. SetDataToCell(ref CollectData);
  477. }
  478. else
  479. {
  480. MessageBox.Show("所采集的数据个数和采集项目不符");
  481. return;
  482. }
  483. //采集项目的索引+1
  484. CurrentItemIndex = CurrentItemIndex + 1;
  485. //如果已经采集完了最后一个
  486. if (CurrentItemIndex == ScanData.ToArray().Length)
  487. {
  488. //数据校验均已通过则勾选上已采集
  489. if (CollectVeProdCodePass && CollectQTYPass)
  490. {
  491. //如果按盒号采集,所有的此盒的均更新为
  492. DataTable dt = (DataTable)LabelInf.DataSource;
  493. StringBuilder pibid1 = new StringBuilder();
  494. string year = "0";
  495. string month = "0";
  496. string day = "0";
  497. string date = "";
  498. string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  499. string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  500. string pr_brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString();
  501. LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  502. if (CollectionUnit.Text == "盒")
  503. {
  504. for (int i = 0; i < LabelInf.RowCount; i++)
  505. {
  506. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  507. {
  508. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  509. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  510. dt.Rows[i]["pib_lotno"] = lotno;
  511. dt.Rows[i]["pib_datecode"] = datecode;
  512. dt.Rows[i]["pib_year"] = year;
  513. dt.Rows[i]["pib_month"] = month;
  514. dt.Rows[i]["pib_day"] = day;
  515. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  516. LabelInf.Rows[i].Cells["Choose"].Value = true;
  517. pibid1.Append(pibid + ",");
  518. LabelInf.Invalidate();
  519. //当前行的索引随循环增长
  520. CurrentRowIndex = i;
  521. if (SingleLabelAutoPrint.Checked)
  522. {
  523. AutoPrintSingleLabel(pibid, outboxcode);
  524. }
  525. if (MidLabelAutoPrint.Checked)
  526. AutoPrintMidLabel();
  527. SetOutBoxCode2(true);
  528. }
  529. }
  530. pibid1.Append("1");
  531. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  532. Last_OutboxCode = "";
  533. }
  534. else if (CollectionUnit.Text == "全部")
  535. {
  536. for (int i = 0; i < LabelInf.RowCount; i++)
  537. {
  538. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  539. dt.Rows[i]["pib_lotno"] = lotno;
  540. dt.Rows[i]["pib_datecode"] = datecode;
  541. dt.Rows[i]["pib_year"] = year;
  542. dt.Rows[i]["pib_month"] = month;
  543. dt.Rows[i]["pib_day"] = day;
  544. CurrentRowIndex = i;
  545. LabelInf.Refresh();
  546. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  547. LabelInf.Rows[i].Cells["Choose"].Value = true;
  548. pibid1.Append(pibid + ",");
  549. LabelInf.Invalidate();
  550. SetOutBoxCode2(true);
  551. }
  552. pibid1.Append("1");
  553. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  554. }
  555. else
  556. {
  557. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  558. LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
  559. LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
  560. LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
  561. LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
  562. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  563. LabelInf.Invalidate();
  564. //勾选了单盘自动打印
  565. if (SingleLabelAutoPrint.Checked)
  566. {
  567. if (SingleLabelCombox.SelectedValue != null)
  568. {
  569. AutoPrintSingleLabel(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString());
  570. Last_OutboxCode = "";
  571. }
  572. else
  573. {
  574. MessageBox.Show("未维护单盘标签");
  575. return;
  576. }
  577. }
  578. //勾选了中盒自动打印
  579. if (MidLabelAutoPrint.Checked)
  580. AutoPrintMidLabel();
  581. }
  582. }
  583. //采集未通过的时候
  584. else
  585. {
  586. //如果自动采集采集未成功需要移动到下一行
  587. if (!AutoMatch.Checked)
  588. SetRowIndexToCollectRow();
  589. }
  590. //当前项目已采集完成,重置采集项目
  591. CurrentItemIndex = 0;
  592. //未勾选自动匹配,设置到下一个未采集的行
  593. if (!AutoMatch.Checked)
  594. SetRowIndexToCollectRow();
  595. }
  596. //提醒用户需要采集的数据
  597. RemindUser();
  598. RefreshProcessData();
  599. MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue);
  600. //如果所采集的行的物料不一样的话,重新计算箱内容量
  601. if (CurrentRowIndex - 1 > 0)
  602. {
  603. string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
  604. string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
  605. //如果两行的物料资料不相等的话
  606. if (LastRowProd != CurrentRowProd)
  607. SetOutBoxCapacity(CurrentRowProd);
  608. }
  609. if (CleanInputAfterCollect.Checked)
  610. Input.Text = "";
  611. }
  612. /// <summary>
  613. /// 根据物料资料的参数设置外箱容量
  614. /// </summary>
  615. /// <param name="pr_code"></param>
  616. private void SetOutBoxCapacity(string pr_code)
  617. {
  618. DataTable temp = (DataTable)dh.ExecuteSql("select pr_qtyperplace,pr_zxbzs from product where pr_code='" + pr_code + "'", "select");
  619. if (temp.Rows.Count > 0)
  620. {
  621. //try { OutboxCapacity.Value = (decimal)temp.Rows[0]["pr_qtyperplace"] / (decimal)temp.Rows[0]["pr_zxbzs"]; }
  622. //catch (Exception) { }
  623. }
  624. }
  625. //设置行的索引到当前需要采集的行
  626. private void SetRowIndexToCollectRow()
  627. {
  628. //获取当前需要采集的行
  629. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  630. {
  631. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  632. {
  633. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  634. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  635. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  636. break;
  637. }
  638. }
  639. }
  640. private void AutoPrintSingleLabel(string pib_id, string outboxcode)
  641. {
  642. bool PrintBlankLabel = false;
  643. if (PrintMethod == "CodeSoft")
  644. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pib_id);
  645. else
  646. {
  647. //第一箱不打印空标签
  648. if (outboxcode != "" && Last_OutboxCode == "")
  649. {
  650. PrintBlankLabel = false;
  651. }
  652. //如果外箱不相等
  653. else if (outboxcode != "" && Last_OutboxCode != "" && outboxcode != Last_OutboxCode)
  654. {
  655. PrintBlankLabel = true;
  656. }
  657. Last_OutboxCode = outboxcode;
  658. //打印一张空白标签
  659. if (LabelSpace.Checked && PrintBlankLabel)
  660. {
  661. Print.BarTender.SinglePrint(EmptySingleFormat, SingleLabelParam, pib_id);
  662. }
  663. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pib_id);
  664. }
  665. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  666. sdh.ExecuteSql("update prodiobarcode set pib_ifprint=-1 where pib_id='" + pib_id + "'", "update");
  667. }
  668. /// <summary>
  669. /// 提醒用户当前采集的项目
  670. /// </summary>
  671. private void RemindUser()
  672. {
  673. SetRowIndexToCollectRow();
  674. if (ScanData.ToArray().Length > 0)
  675. {
  676. object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  677. string Inf = "";
  678. for (int i = 0; i < arr.Length; i++)
  679. {
  680. Inf += arr[i] + " ";
  681. }
  682. MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
  683. }
  684. }
  685. /// <summary>
  686. /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
  687. /// </summary>
  688. /// <param name="data"></param>
  689. /// <param name="kind"></param>
  690. private void SetDataToCell(ref Dictionary<string, string> setdata)
  691. {
  692. int length = setdata.Count;
  693. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  694. string LotNo = "";
  695. string DateCode = "";
  696. foreach (var item in setdata)
  697. {
  698. string[] data = new string[setdata.Count];
  699. for (int i = 0; i < length; i++)
  700. {
  701. data[i] = setdata[item.Key];
  702. }
  703. DataGridViewCell cell = null;
  704. string Matchstr = "";
  705. switch (item.Key)
  706. {
  707. case "DATECODE":
  708. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"];
  709. Matchstr = MatchStr(item.Value, "DATECODE");
  710. DateCode = Matchstr;
  711. length--;
  712. break;
  713. case "LOTNO":
  714. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
  715. Matchstr = MatchStr(item.Value, "LOTNO");
  716. LotNo = Matchstr;
  717. length--;
  718. break;
  719. case "MPN":
  720. cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"];
  721. Matchstr = MatchStr(item.Value, "MPN");
  722. //采集的供应商号不匹配的话
  723. if (cell.Value.ToString() != Matchstr)
  724. {
  725. CollectVeProdCodePass = false;
  726. //添加需要重绘的Cell
  727. LabelInf.Refresh();
  728. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  729. }
  730. else
  731. {
  732. LabelInf.Refresh();
  733. CollectVeProdCodePass = true;
  734. }
  735. length--;
  736. break;
  737. case "QTY":
  738. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"];
  739. Matchstr = MatchStr(item.Value, "QTY");
  740. //如果采集的数量不相等的话
  741. if (cell.Value.ToString() != Matchstr)
  742. {
  743. CollectQTYPass = false;
  744. LabelInf.Refresh();
  745. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  746. }
  747. else
  748. {
  749. LabelInf.Refresh();
  750. CollectQTYPass = true;
  751. }
  752. length--;
  753. break;
  754. case "品牌":
  755. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"];
  756. Matchstr = MatchStr(item.Value, "品牌");
  757. //如果采集的数量不相等的话
  758. if (cell.Value.ToString() != Matchstr)
  759. {
  760. CollectQTYPass = false;
  761. LabelInf.Refresh();
  762. MessageLog.AppendText(">>品牌不匹配\n", Color.Red);
  763. }
  764. else
  765. {
  766. LabelInf.Refresh();
  767. CollectQTYPass = true;
  768. }
  769. length--;
  770. break;
  771. default:
  772. break;
  773. }
  774. //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
  775. //MPN和QTY只做比较不需要赋值
  776. if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
  777. {
  778. string MatchResult = "";
  779. if (item.Key != "MPN" && item.Key != "QTY" && item.Key != "品牌")
  780. {
  781. DataTable dt = (DataTable)LabelInf.DataSource;
  782. cell.Value = Matchstr;
  783. MatchResult = "成功";
  784. }
  785. else
  786. MatchResult = "失败";
  787. switch (SiItem[item.Key]["si_kind"])
  788. {
  789. case "索引字符":
  790. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",使用字符" + SiItem[item.Key]["si_indexstring"] + ",匹配后字符串" + Matchstr);
  791. break;
  792. case "起始位置":
  793. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",从第" + SiItem[item.Key]["si_index"] + "位开始匹配,匹配后字符串" + Matchstr);
  794. break;
  795. case "二次解析":
  796. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",匹配后字符串" + Matchstr);
  797. break;
  798. case "全部":
  799. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",匹配后字符串" + Matchstr);
  800. break;
  801. default:
  802. break;
  803. }
  804. }
  805. else
  806. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【成功】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",,匹配后字符串" + Matchstr);
  807. }
  808. sql.Clear();
  809. sql.Append("update prodiobarcode set pib_ifpick=-1");
  810. if (LotNo != "")
  811. {
  812. sql.Append(",pib_lotno='" + LotNo + "'");
  813. }
  814. if (DateCode != "")
  815. {
  816. string year = "";
  817. string month = "";
  818. string day = "";
  819. string date = "";
  820. string pr_brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString();
  821. LogicHandler.GetTimeFromDatecode(DateCode, pr_brand, out year, out month, out day, out date);
  822. sql.Append(",pib_datecode='" + DateCode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' ");
  823. }
  824. sql.Append("where pib_id='" + pib_id + "'");
  825. sdh.ExecuteSql(sql.ToString(), "update");
  826. //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
  827. SetOutBoxCode2(false);
  828. }
  829. //
  830. /// <summary>
  831. /// 设置外箱号
  832. /// </summary>
  833. /// <param name="BatchCollect">是否批量采集</param>
  834. private void SetOutBoxCode2(bool BatchCollect)
  835. {
  836. if (OutboxCapacity.Value != 0)
  837. {
  838. //获取当前出入口单最大的外箱号
  839. for (int i = 0; i < LabelInf.RowCount; i++)
  840. {
  841. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  842. if (outboxcode.Contains("-"))
  843. {
  844. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  845. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  846. }
  847. else
  848. {
  849. if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
  850. MaxOutBoxCode = int.Parse(outboxcode);
  851. }
  852. }
  853. //统计最大的箱号存在多少
  854. int MaxOutBoxCodeCount = 0;
  855. for (int i = 0; i < LabelInf.RowCount; i++)
  856. {
  857. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  858. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  859. }
  860. //如果是获取过包装单的话则不再继续追加箱号
  861. if (!GetPackingCode)
  862. {
  863. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  864. if (BatchCollect)
  865. {
  866. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  867. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  868. else
  869. {
  870. MaxOutBoxCode = MaxOutBoxCode + 1;
  871. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  872. }
  873. }
  874. else
  875. {
  876. if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
  877. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  878. else
  879. {
  880. MaxOutBoxCode = MaxOutBoxCode + 1;
  881. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  882. }
  883. }
  884. }
  885. }
  886. }
  887. /// <summary>
  888. /// 自定义函数 根据匹配规则
  889. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  890. /// </summary>
  891. /// <param name="SiItem"></param>
  892. /// <param name="str"></param>
  893. /// <param name="item"></param>
  894. /// <returns></returns>
  895. private string MatchStr(string str, string item)
  896. {
  897. string kind = SiItem[item]["si_kind"];
  898. //起始字符不为空的时候
  899. switch (kind)
  900. {
  901. case "起始位置":
  902. if (SiItem[item]["si_index"] != "")
  903. {
  904. try
  905. {
  906. //长度不为空的时候按照指定的长度去取数据
  907. if (SiItem[item]["si_length"] != "")
  908. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  909. //长度为空的时候取index之后的全部数据
  910. else
  911. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  912. }
  913. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  914. }
  915. break;
  916. case "索引字符":
  917. try
  918. {
  919. if (SiItem[item]["si_indexstring"] != "")
  920. {
  921. //长度不为空的时候按照指定的长度去取数据
  922. if (SiItem[item]["si_length"] != "")
  923. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  924. //长度为空的时候取index之后的全部数据
  925. else
  926. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
  927. }
  928. }
  929. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  930. break;
  931. case "全部":
  932. break;
  933. default:
  934. break;
  935. }
  936. if (SiItem[item]["si_expression"] != "")
  937. {
  938. string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str;
  939. reg = new Regex(SiItem[item]["si_expression"]);
  940. try
  941. {
  942. str = reg.Matches(str)[int.Parse(SiItem[item]["si_expressionitem"].ToString()) - 1].Value;
  943. }
  944. catch (Exception)
  945. {
  946. }
  947. log += ",匹配后数据" + str;
  948. LogManager.DoLog(log);
  949. }
  950. return str;
  951. }
  952. //关闭窗口前提示用户确认
  953. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  954. {
  955. //如果不是注销的话
  956. if (!logout)
  957. {
  958. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  959. if (close.ToString() != "Yes")
  960. e.Cancel = true;
  961. else
  962. {
  963. if (lbl != null)
  964. lbl.Quit();
  965. if (engine != null)
  966. engine.Dispose();
  967. LogManager.DoLog("关闭程序");
  968. }
  969. }
  970. }
  971. /// <summary>
  972. /// 获取打印标签
  973. /// </summary>
  974. private void GetInOutInfAndLabelFile()
  975. {
  976. ComBoxClickChangeLabelDoc = false;
  977. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  978. sql.Clear();
  979. 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') ");
  980. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  981. sql.Append(" or cl_custcode is null) and cl_labeltype='单盘' order by cl_custcode");
  982. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  983. SingleLabelCombox.DisplayMember = "cl_labelname";
  984. SingleLabelCombox.ValueMember = "la_id";
  985. SingleLabelCombox.DataSource = dt;
  986. if (SingleDoc != null)
  987. SingleDoc.Close();
  988. if (!GetGridOnly.Checked)
  989. for (int i = 0; i < dt.Rows.Count; i++)
  990. {
  991. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  992. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  993. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  994. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  995. if (time.ToString() != file.LastWriteTime.ToString())
  996. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  997. }
  998. if (SingleLabelCombox.Text != "")
  999. {
  1000. if (PrintMethod == "CodeSoft")
  1001. {
  1002. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  1003. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  1004. }
  1005. else
  1006. {
  1007. if (SingleFormat != null)
  1008. {
  1009. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  1010. }
  1011. SingleFormat = engine.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  1012. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1013. }
  1014. SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  1015. }
  1016. sql.Clear();
  1017. 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') ");
  1018. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  1019. sql.Append(" or cl_custcode is null) and cl_labeltype='中盒' order by cl_custcode");
  1020. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1021. MidLabelCombox.DisplayMember = "cl_labelname";
  1022. MidLabelCombox.ValueMember = "la_id";
  1023. MidLabelCombox.DataSource = dt;
  1024. if (MidDoc != null)
  1025. MidDoc.Close();
  1026. if (!GetGridOnly.Checked)
  1027. for (int i = 0; i < dt.Rows.Count; i++)
  1028. {
  1029. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  1030. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  1031. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1032. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1033. if (time.ToString() != file.LastWriteTime.ToString())
  1034. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1035. }
  1036. if (MidLabelCombox.Text != "")
  1037. {
  1038. if (PrintMethod == "CodeSoft")
  1039. {
  1040. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1041. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1042. }
  1043. else
  1044. {
  1045. if (MidFormat != null)
  1046. {
  1047. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  1048. }
  1049. MidFormat = engine.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1050. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1051. }
  1052. MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  1053. }
  1054. //缓存中盒参数
  1055. sql.Clear();
  1056. 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') ");
  1057. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  1058. sql.Append(" or cl_custcode is null) and cl_labeltype='外箱' order by cl_custcode");
  1059. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1060. OutBoxCombox.DisplayMember = "cl_labelname";
  1061. OutBoxCombox.ValueMember = "la_id";
  1062. OutBoxCombox.DataSource = dt;
  1063. if (OutBoxDoc != null)
  1064. OutBoxDoc.Close();
  1065. if (!GetGridOnly.Checked)
  1066. for (int i = 0; i < dt.Rows.Count; i++)
  1067. {
  1068. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  1069. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  1070. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1071. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1072. if (time.ToString() != file.LastWriteTime.ToString())
  1073. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1074. }
  1075. if (OutBoxCombox.Text != "")
  1076. {
  1077. if (PrintMethod == "CodeSoft")
  1078. {
  1079. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1080. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1081. }
  1082. else
  1083. {
  1084. if (OutFormat != null)
  1085. {
  1086. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  1087. }
  1088. OutFormat = engine.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1089. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1090. }
  1091. 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");
  1092. }
  1093. try
  1094. {
  1095. //打开空标签文件
  1096. if (EmptySingleFormat == null)
  1097. {
  1098. EmptySingleFormat = engine.Documents.Open("Empty.btw");
  1099. EmptySingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1100. }
  1101. if (EmptyOutFormat == null)
  1102. {
  1103. EmptyOutFormat = engine.Documents.Open("Empty.btw");
  1104. EmptyOutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1105. }
  1106. }
  1107. catch (Exception)
  1108. {
  1109. }
  1110. //缓存外箱参数
  1111. ComBoxClickChangeLabelDoc = true;
  1112. }
  1113. bool InitGetLabel = true;
  1114. /// <summary>
  1115. /// 出入库单录入框的回车事件
  1116. /// </summary>
  1117. /// <param name="sender"></param>
  1118. /// <param name="e"></param>
  1119. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  1120. {
  1121. if (e.KeyCode == Keys.Enter)
  1122. {
  1123. sql.Clear();
  1124. sql.Append("select pi_id,pi_cardcode,pi_class,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  1125. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1126. if (dt.Rows.Count > 0)
  1127. {
  1128. InitGetLabel = true;
  1129. cu_code.Text = dt.Rows[0]["pi_cardcode"].ToString();
  1130. InitGetLabel = false;
  1131. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  1132. pi_class.Text = dt.Rows[0]["pi_class"].ToString();
  1133. PI_ID = dt.Rows[0]["pi_id"].ToString();
  1134. if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  1135. {
  1136. string[] param = new string[] { PI_ID, "" };
  1137. dh.CallProcedure("GetCustBarcode", ref param);
  1138. }
  1139. CurrentItemIndex = 0;
  1140. CurrentRowIndex = 0;
  1141. LoadGridData(sender, e);
  1142. //重新输入单号后清除缓存
  1143. MidBoxArgument.Clear();
  1144. SingleBoxArgument.Clear();
  1145. MidIDAndOutboxcode.Clear();
  1146. SingleID.Clear();
  1147. //刷新采集进度
  1148. RefreshProcessData();
  1149. //设置当前的最大箱号
  1150. for (int i = 0; i < LabelInf.RowCount; i++)
  1151. {
  1152. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1153. //如果包含有-,则需要解析
  1154. if (outboxcode.Contains("-"))
  1155. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  1156. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  1157. //else
  1158. //if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  1159. // MaxOutBoxCode = int.Parse(outboxcode);
  1160. }
  1161. thread = new Thread(GetInOutInfAndLabelFile);
  1162. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  1163. BaseUtil.SetFormCenter(stw);
  1164. stw.ShowDialog();
  1165. //重置采集项次
  1166. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  1167. }
  1168. else
  1169. MessageBox.Show("当前出入库单号不存在!");
  1170. }
  1171. }
  1172. private void SingleBoxPrint()
  1173. {
  1174. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  1175. {
  1176. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  1177. MidIDAndOutboxcode.Clear();
  1178. SingleID.Clear();
  1179. //获取全部的中盒号
  1180. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  1181. //判断所有盒号为该盒的是否勾选已采集
  1182. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  1183. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1184. {
  1185. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  1186. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1187. 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")
  1188. {
  1189. //如果不存在中盒号则进行添加
  1190. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1191. {
  1192. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1193. }
  1194. }
  1195. }
  1196. if (SingleID.ToArray().Length == 0)
  1197. {
  1198. MessageBox.Show("选择的行未勾选采集或者已打印");
  1199. return;
  1200. }
  1201. for (int i = 0; i < LabelInf.RowCount; i++)
  1202. {
  1203. if (i + 1 < LabelInf.RowCount)
  1204. {
  1205. //如果本行的中盒号和下一行不相等的话
  1206. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1207. {
  1208. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1209. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  1210. }
  1211. }
  1212. //只要有一行没有采集满就不打印
  1213. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1214. {
  1215. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1216. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1217. }
  1218. }
  1219. //用于判断用户是否勾选了行
  1220. int CheckedRowCount = 0;
  1221. string[] arg = SingleBoxArgument.ToArray();
  1222. for (int i = 0; i < LabelInf.RowCount; i++)
  1223. {
  1224. //勾选了并且未打印
  1225. 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")
  1226. {
  1227. CheckedRowCount = CheckedRowCount + 1;
  1228. CurrentRowIndex = i;
  1229. //以标签模板的参数为基准,循环取数
  1230. try
  1231. {
  1232. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  1233. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1234. AutoPrintSingleLabel(pib_id, outboxcode);
  1235. if (MidLabelAutoPrint.Checked)
  1236. {
  1237. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1238. 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())
  1239. {
  1240. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1241. {
  1242. if (MidLabelCombox.SelectedValue != null)
  1243. {
  1244. MidBoxCodePrint(CurrentRowIndex);
  1245. }
  1246. }
  1247. }
  1248. }
  1249. //勾选为已打印
  1250. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1251. sdh.ExecuteSql("update prodiobarcode set pib_ifprint=-1 where pib_id='" + pib_id + "'", "update");
  1252. }
  1253. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  1254. }
  1255. }
  1256. Last_OutboxCode = "";
  1257. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  1258. if (CheckedRowCount == 0)
  1259. MessageBox.Show("未勾选打印明细!");
  1260. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  1261. CurrentRowIndex = CurrentRowIndex + 1;
  1262. outboxcode1.Clear();
  1263. }
  1264. else
  1265. {
  1266. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  1267. return;
  1268. }
  1269. }
  1270. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1271. {
  1272. if (SingleLabelCombox.Text != "")
  1273. {
  1274. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1275. {
  1276. try
  1277. {
  1278. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1279. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1280. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1281. {
  1282. for (int i = begin - 1; i < end; i++)
  1283. {
  1284. LabelInf.Rows[i].Cells["Choose"].Value = true;
  1285. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1286. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1287. }
  1288. }
  1289. else
  1290. {
  1291. MessageBox.Show("单盘打印范围错误");
  1292. return;
  1293. }
  1294. LabelInf.Invalidate();
  1295. }
  1296. catch (Exception)
  1297. {
  1298. MessageBox.Show("单盘打印范围错误");
  1299. return;
  1300. }
  1301. }
  1302. thread = new Thread(SingleBoxPrint);
  1303. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1304. BaseUtil.SetFormCenter(stw);
  1305. stw.ShowDialog();
  1306. }
  1307. else
  1308. MessageBox.Show("未维护单盘标签");
  1309. }
  1310. private void MidBoxLabelPrint()
  1311. {
  1312. if (MidLabelNum.Text == "")
  1313. {
  1314. int begin = 0;
  1315. int end = 0;
  1316. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1317. {
  1318. try
  1319. {
  1320. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1321. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1322. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1323. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1324. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1325. {
  1326. //设置中盒打印范围的行号
  1327. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1328. {
  1329. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1330. if (outboxcode1 != "")
  1331. {
  1332. if (int.Parse(outboxcode1) == begin)
  1333. {
  1334. begin = i;
  1335. }
  1336. if (int.Parse(outboxcode1) == end)
  1337. {
  1338. end = i;
  1339. }
  1340. }
  1341. }
  1342. }
  1343. else
  1344. {
  1345. MessageBox.Show("中盒打印范围错误");
  1346. return;
  1347. }
  1348. }
  1349. catch (Exception)
  1350. {
  1351. MessageBox.Show("中盒打印范围错误");
  1352. return;
  1353. }
  1354. }
  1355. else
  1356. {
  1357. end = LabelInf.Rows.Count - 1;
  1358. }
  1359. MidBoxArgument.Clear();
  1360. List<int> MidOutBoxCode = new List<int>();
  1361. List<int> MidOutBoxCodeIndex = new List<int>();
  1362. for (int i = (begin == 0 ? 0 : begin); i <= (end - begin); i++)
  1363. {
  1364. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1365. if (outboxcode1 != "")
  1366. {
  1367. if (!MidIDAndOutboxcode.ContainsValue(outboxcode1))
  1368. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), outboxcode1);
  1369. if (!MidOutBoxCode.Contains(int.Parse(outboxcode1)))
  1370. {
  1371. MidOutBoxCode.Add(int.Parse(outboxcode1));
  1372. MidOutBoxCodeIndex.Add(i);
  1373. }
  1374. }
  1375. }
  1376. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  1377. {
  1378. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  1379. }
  1380. MidBoxArgument.Clear();
  1381. return;
  1382. }
  1383. bool FindMidLabel = false;
  1384. if (MidLabelCombox.SelectedValue != null)
  1385. {
  1386. //中盒号所在的行
  1387. int MidLabelRowIndex = 0;
  1388. //查找是否存在该中盒号
  1389. List<int> MidRowIndex = new List<int>();
  1390. //缓存中盒数据
  1391. for (int i = 0; i < LabelInf.RowCount; i++)
  1392. {
  1393. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1394. {
  1395. //找到了输入的中盒号停止循环
  1396. FindMidLabel = true;
  1397. MidLabelRowIndex = i;
  1398. MidRowIndex.Add(i);
  1399. }
  1400. }
  1401. //找到了指定的盒号
  1402. if (FindMidLabel)
  1403. MidBoxCodePrint(MidLabelRowIndex);
  1404. else
  1405. MessageBox.Show("该出入库单未找到该中盒号!");
  1406. }
  1407. else
  1408. MessageBox.Show("未维护中盒模板");
  1409. }
  1410. private void MidLabelPrint_Click(object sender, EventArgs e)
  1411. {
  1412. if (MidLabelCombox.Text != "")
  1413. {
  1414. thread = new Thread(MidBoxLabelPrint);
  1415. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1416. BaseUtil.SetFormCenter(stw);
  1417. stw.ShowDialog();
  1418. }
  1419. else
  1420. MessageBox.Show("未维护中盒标签");
  1421. }
  1422. private void OutBoxPrint()
  1423. {
  1424. List<string> Outboxcode = new List<string>();
  1425. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1426. if (OutBoxNum.Text == "")
  1427. {
  1428. for (int i = 0; i < LabelInf.RowCount; i++)
  1429. {
  1430. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1431. {
  1432. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1433. //富为使用包装单的逻辑
  1434. //如果不包含该箱号则进行添加
  1435. if (!Outboxcode.Contains(outboxcode2))
  1436. Outboxcode.Add(outboxcode2);
  1437. }
  1438. }
  1439. //按获取到的箱号列表进行打印
  1440. if (Outboxcode.ToArray().Length > 0)
  1441. {
  1442. try
  1443. {
  1444. // 循环打印外箱号
  1445. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1446. {
  1447. for (int h = 0; h < LabelInf.RowCount; h++)
  1448. {
  1449. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1450. {
  1451. OutBoxCodePrint(h);
  1452. break;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. catch { }
  1458. }
  1459. else
  1460. {
  1461. MessageBox.Show("请勾选需要打印的外箱");
  1462. }
  1463. }
  1464. else
  1465. {
  1466. bool FindMidLabel = false;
  1467. try
  1468. {
  1469. int OutBoxLabelRowIndex = 0;
  1470. //查找是否存在该中盒号
  1471. for (int i = 0; i < LabelInf.RowCount; i++)
  1472. {
  1473. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1474. {
  1475. //找到了输入的中盒号停止循环
  1476. FindMidLabel = true;
  1477. OutBoxLabelRowIndex = i;
  1478. break;
  1479. }
  1480. }
  1481. //找到了指定的盒号
  1482. if (FindMidLabel)
  1483. OutBoxCodePrint(OutBoxLabelRowIndex);
  1484. else
  1485. MessageBox.Show("该出入库单未找到该外箱号!");
  1486. }
  1487. catch (Exception) { }
  1488. }
  1489. Outboxcode.Clear();
  1490. }
  1491. private void MidBoxCodePrint(int rowindex)
  1492. {
  1493. //获取对应行的pib_id
  1494. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1495. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  1496. if (PrintMethod == "CodeSoft")
  1497. Print.CodeSoft.MidPrint(MidDoc, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1498. else
  1499. Print.BarTender.MidPrint(MidFormat, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1500. }
  1501. private void OutBoxCodePrint(int rowindex)
  1502. {
  1503. //获取对应行的pib_id
  1504. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1505. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1506. if (PrintMethod == "CodeSoft")
  1507. Print.CodeSoft.OutPrint(OutBoxDoc, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked);
  1508. else
  1509. {
  1510. Print.BarTender.OutPrint(OutFormat, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked);
  1511. if (LabelSpace.Checked)
  1512. {
  1513. Print.BarTender.OutPrint(EmptyOutFormat, OutLabelParam, pi_inoutno.Text, pib_id, "-1", cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked, cu_print_ordercode.Checked);
  1514. }
  1515. }
  1516. }
  1517. private void CleanDetail_Click(object sender, EventArgs e)
  1518. {
  1519. ArrayList<string> DeleteID = new ArrayList<string>();
  1520. StringBuilder pibid = new StringBuilder();
  1521. for (int i = 0; i < LabelInf.RowCount; i++)
  1522. {
  1523. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1524. {
  1525. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1526. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",");
  1527. }
  1528. }
  1529. //勾选了删除的明细之后
  1530. if (DeleteID.ToArray().Length > 0)
  1531. {
  1532. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1533. if (close.ToString() == "Yes")
  1534. {
  1535. pibid.Append("1");
  1536. sdh.ExecuteSql("delete from prodiobarcode where pib_id in(" + pibid + ")", "delete");
  1537. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1538. MessageBox.Show("删除成功");
  1539. LoadGridData(sender, e);
  1540. RefreshProcessData();
  1541. }
  1542. }
  1543. else
  1544. MessageBox.Show("尚未勾选需要删除的明细");
  1545. }
  1546. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1547. {
  1548. if (OutBoxCombox.Text != "")
  1549. {
  1550. thread = new Thread(OutBoxPrint);
  1551. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1552. BaseUtil.SetFormCenter(stw);
  1553. stw.ShowDialog();
  1554. }
  1555. else
  1556. MessageBox.Show("未维护外箱标签");
  1557. }
  1558. /// <summary>
  1559. /// 刷新采集进度
  1560. /// </summary>
  1561. private void RefreshProcessData()
  1562. {
  1563. if (LabelInf.Rows.Count > 0)
  1564. {
  1565. //设置初始化的采集进度
  1566. int Count = 0;
  1567. int CurrentMidBoxCollectedCount = 0;
  1568. //当前盒号的总盘数
  1569. int CurrentMidBoxTotalCount = 0;
  1570. //未超出当前范围的时候
  1571. for (int i = 0; i < LabelInf.RowCount; i++)
  1572. {
  1573. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1574. Count++;
  1575. //和当前编辑箱号相等行
  1576. 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())
  1577. CurrentMidBoxCollectedCount++;
  1578. //当前盒号一共有几盘
  1579. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1580. CurrentMidBoxTotalCount++;
  1581. }
  1582. Capacity.Text = "可装" + CurrentMidBoxTotalCount + "盘";
  1583. Installed.Text = "已装" + CurrentMidBoxCollectedCount + "盘";
  1584. //设置当前的箱号和盒号
  1585. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1586. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1587. //设置当前总数和已采集数量
  1588. TotalCount.Text = LabelInf.RowCount.ToString();
  1589. CollectedCount.Text = Count.ToString();
  1590. }
  1591. }
  1592. private void LoadGridData()
  1593. {
  1594. LoadGridData(new object(), new EventArgs());
  1595. }
  1596. DataTable LabelInfDataTable;
  1597. /// <summary>
  1598. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1599. /// </summary>
  1600. /// <param name="sender"></param>
  1601. /// <param name="e"></param>
  1602. private void LoadGridData(object sender, EventArgs e)
  1603. {
  1604. AllCollect = false;
  1605. //查询Oracle数据库
  1606. sql.Clear();
  1607. sql.Append("select t.*,rownum from prodiobarcode_view t where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_id)");
  1608. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1609. //查询本地数据库
  1610. sql.Clear();
  1611. sql.Append("select count(1) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'");
  1612. DataTable dt = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1613. int rowcount = int.Parse(dt.Rows[0][0].ToString());
  1614. //如果本地没有缓存过
  1615. if (rowcount == 0 || rowcount != LabelInfDataTable.Rows.Count)
  1616. {
  1617. if (rowcount != LabelInfDataTable.Rows.Count && rowcount != 0)
  1618. {
  1619. string close = MessageBox.Show(this.ParentForm, "本地条码和服务器条码数量不一致,覆盖本地条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1620. if (close == "Yes")
  1621. {
  1622. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1623. //检验查询的字段和本地数据库字段是否匹配
  1624. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1625. //将数据保存在本地数据库
  1626. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1627. }
  1628. }
  1629. else
  1630. {
  1631. //检验查询的字段和本地数据库字段是否匹配
  1632. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1633. //将数据保存在本地数据库
  1634. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1635. }
  1636. }
  1637. else if (LabelInfDataTable.Columns.Count != dt.Columns.Count)
  1638. {
  1639. //检验查询的字段和本地数据库字段是否匹配
  1640. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1641. sdh.BatchInsert("prodiobarcode", LabelInfDataTable);
  1642. }
  1643. sql.Clear();
  1644. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_id ");
  1645. LabelInfDataTable = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1646. bindingsource(LabelInf, LabelInfDataTable);
  1647. //有数据的话默认取第一条的品牌去取采集策略
  1648. TotalCount.Text = LabelInf.RowCount.ToString();
  1649. if (LabelInf.RowCount > 0)
  1650. {
  1651. Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
  1652. if (Brand != "")
  1653. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString();
  1654. SetOutBoxCapacity(LabelInf.Rows[0].Cells["pib_prodcode"].Value.ToString());
  1655. }
  1656. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1657. for (int i = 0; i < LabelInf.RowCount; i++)
  1658. {
  1659. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1660. {
  1661. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1662. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  1663. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1664. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1665. break;
  1666. }
  1667. }
  1668. }
  1669. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  1670. void bindingsource(DataGridView dgv, DataTable dt)
  1671. {
  1672. if (dgv.InvokeRequired)
  1673. {
  1674. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  1675. }
  1676. else
  1677. {
  1678. dgv.AutoGenerateColumns = false;
  1679. dgv.DataSource = dt;
  1680. }
  1681. }
  1682. /// <summary>
  1683. /// 重绘Cell的颜色
  1684. /// </summary>
  1685. /// <param name="sender"></param>
  1686. /// <param name="e"></param>
  1687. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1688. {
  1689. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1690. if (e.ColumnIndex > 0)
  1691. {
  1692. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" || LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode1" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode2" || LabelInf.Columns[e.ColumnIndex].Name == "pr_brand")
  1693. {
  1694. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1695. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1696. Rectangle border = e.CellBounds;
  1697. border.Width -= 1;
  1698. e.Graphics.DrawRectangle(Pens.White, border);
  1699. e.PaintContent(e.CellBounds);
  1700. e.Handled = true;
  1701. }
  1702. if (e.RowIndex >= 0)
  1703. {
  1704. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1705. {
  1706. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1707. {
  1708. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1709. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  1710. Rectangle border = e.CellBounds;
  1711. border.Width -= 1;
  1712. e.Graphics.DrawRectangle(Pens.Black, border);
  1713. e.PaintContent(e.CellBounds);
  1714. e.Handled = true;
  1715. }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. private void pr_code_SearchIconClick(object sender, EventArgs e)
  1721. {
  1722. pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'";
  1723. }
  1724. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  1725. {
  1726. //用户在重新勾选后重置采集项目的索引
  1727. CurrentItemIndex = 0;
  1728. for (int i = 0; i < LabelInf.RowCount; i++)
  1729. {
  1730. if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1731. {
  1732. CurrentRowIndex = i;
  1733. break;
  1734. }
  1735. }
  1736. }
  1737. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1738. {
  1739. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1740. pi_inoutno_KeyDown(sender, e2);
  1741. }
  1742. /// <summary>
  1743. /// 采集明细切换
  1744. /// </summary>
  1745. /// <param name="sender"></param>
  1746. /// <param name="e"></param>
  1747. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1748. {
  1749. if (Keys.Enter == e.KeyData)
  1750. {
  1751. bool FindDetno = false;
  1752. for (int i = 0; i < LabelInf.RowCount; i++)
  1753. {
  1754. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1755. {
  1756. FindDetno = true;
  1757. CurrentItemIndex = 0;
  1758. CurrentRowIndex = i;
  1759. RemindUser();
  1760. break;
  1761. }
  1762. }
  1763. if (!FindDetno)
  1764. {
  1765. MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
  1766. return;
  1767. }
  1768. }
  1769. }
  1770. private void AutoPrintMidLabel()
  1771. {
  1772. bool FullBox = true;
  1773. //判断所有盒号未该盒的是否勾选已采集
  1774. for (int i = 0; i < LabelInf.RowCount; i++)
  1775. {
  1776. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1777. {
  1778. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1779. FullBox = false;
  1780. }
  1781. }
  1782. //如果当前箱号已经装满了
  1783. if (FullBox)
  1784. {
  1785. if (MidLabelCombox.SelectedValue != null)
  1786. {
  1787. MidBoxCodePrint(CurrentRowIndex);
  1788. }
  1789. else
  1790. MessageBox.Show("未维护中盒模板");
  1791. }
  1792. }
  1793. /// <summary>
  1794. /// 勾选的时候自动打印
  1795. /// </summary>
  1796. /// <param name="sender"></param>
  1797. /// <param name="e"></param>
  1798. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1799. {
  1800. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1801. {
  1802. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1803. try
  1804. {
  1805. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1806. GregorianCalendar gc = new GregorianCalendar();
  1807. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1808. if (weekOfYear < 10)
  1809. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1810. else
  1811. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1812. }
  1813. catch (Exception) { }
  1814. }
  1815. }
  1816. private void AllCollected_Click(object sender, EventArgs e)
  1817. {
  1818. if (AllCollect == false)
  1819. {
  1820. foreach (DataGridViewRow dr in LabelInf.Rows)
  1821. dr.Cells[1].Value = true;
  1822. AllCollect = true;
  1823. }
  1824. else
  1825. {
  1826. foreach (DataGridViewRow dr in LabelInf.Rows)
  1827. dr.Cells[1].Value = false;
  1828. AllCollect = false;
  1829. }
  1830. }
  1831. private void GetOutBoxCode_Click(object sender, EventArgs e)
  1832. {
  1833. if (dh.GetConfig("UsingPacking", "ProdInOut!Sale").ToString() != "")
  1834. {
  1835. int Current = 0;
  1836. sql.Clear();
  1837. sql.Append("select pr_qtyperplace,pd_qty,packingdetail.pd_cartonno,pr_zxbzs,packingdetail.pd_cartons from packingdetail left join packing on pd_piid=pi_id left join prodinout on ");
  1838. sql.Append("pi_packingcode=packing.pi_code left join product on pd_prodcode=pr_code where pi_inoutno='" + pi_inoutno.Text + "' order by pr_code,pd_detno");
  1839. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1840. if (dt.Rows.Count > 0)
  1841. {
  1842. try { OutboxCapacity.Value = (decimal)dt.Rows[0]["pr_qtyperplace"] / (decimal)dt.Rows[0]["pr_zxbzs"]; }
  1843. catch (Exception) { }
  1844. }
  1845. try
  1846. {
  1847. for (int i = 0; i < dt.Rows.Count; i++)
  1848. {
  1849. int pd_qty = int.Parse(dt.Rows[i]["pd_qty"].ToString());
  1850. int pr_zxbzs = int.Parse(dt.Rows[i]["pr_zxbzs"].ToString());
  1851. int pd_cartons = int.Parse(dt.Rows[i]["pd_cartons"].ToString());
  1852. for (int j = 0; j < pd_qty * pd_cartons / pr_zxbzs; j++)
  1853. {
  1854. LabelInf.Rows[Current].Cells["pib_outboxcode2"].Value = dt.Rows[i]["pd_cartonno"].ToString();
  1855. Current++;
  1856. }
  1857. }
  1858. GetPackingCode = true;
  1859. }
  1860. catch (Exception)
  1861. {
  1862. }
  1863. }
  1864. else
  1865. {
  1866. int BoxCode = 1;
  1867. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1868. {
  1869. LabelInf.Rows[i].Cells["pib_outboxcode2"].Value = BoxCode;
  1870. if (i + 1 < LabelInf.Rows.Count)
  1871. {
  1872. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) % OutboxCapacity.Value == 0 && (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1873. {
  1874. BoxCode = BoxCode + 1;
  1875. }
  1876. else if (cu_print_outdc.Checked)
  1877. {
  1878. if (LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString())
  1879. {
  1880. BoxCode = BoxCode + 1;
  1881. }
  1882. }
  1883. else if (cu_print_outlotno.Checked)
  1884. {
  1885. if (LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString())
  1886. {
  1887. BoxCode = BoxCode + 1;
  1888. }
  1889. }
  1890. else if (cu_print_outpo.Checked)
  1891. {
  1892. if (LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString())
  1893. {
  1894. BoxCode = BoxCode + 1;
  1895. }
  1896. }
  1897. else if (cu_print_outprod.Checked)
  1898. {
  1899. if (LabelInf.Rows[i].Cells["pib_custprodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_custprodcode"].Value.ToString())
  1900. {
  1901. BoxCode = BoxCode + 1;
  1902. }
  1903. }
  1904. }
  1905. }
  1906. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  1907. }
  1908. DataTable dt1 = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' ", "select");
  1909. if (dt1.Rows.Count > 0)
  1910. {
  1911. dh.CallProcedure("sp_uploadbarcode", dt1);
  1912. }
  1913. }
  1914. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1915. {
  1916. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1917. if (close.ToString() == "Yes")
  1918. {
  1919. Login login = new Login();
  1920. //注销的时候需要将拼接的连接字符串置空
  1921. DataHelper.DBConnectionString = null;
  1922. logout = true;
  1923. if (lbl != null)
  1924. lbl.Quit();
  1925. if (engine != null)
  1926. engine.Dispose();
  1927. this.Hide();
  1928. login.ShowDialog();
  1929. this.Close();
  1930. }
  1931. }
  1932. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1933. /// <summary>
  1934. /// 切换打开的单盘文件
  1935. /// </summary>
  1936. /// <param name="sender"></param>
  1937. /// <param name="e"></param>
  1938. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1939. {
  1940. try
  1941. {
  1942. if (ComBoxClickChangeLabelDoc)
  1943. {
  1944. if (SingleDoc != null)
  1945. SingleDoc.Close();
  1946. if (SingleFormat != null)
  1947. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  1948. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1949. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1950. {
  1951. if (PrintMethod == "CodeSoft")
  1952. {
  1953. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1954. SingleDoc.Printer.Name = SingleLabelPrinter.Text;
  1955. }
  1956. else
  1957. {
  1958. SingleFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1959. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1960. EmptySingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1961. }
  1962. }
  1963. }
  1964. }
  1965. catch (Exception) { }
  1966. }
  1967. /// <summary>
  1968. /// 切换打开的中盒文件
  1969. /// </summary>
  1970. /// <param name="sender"></param>
  1971. /// <param name="e"></param>
  1972. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1973. {
  1974. try
  1975. {
  1976. if (ComBoxClickChangeLabelDoc)
  1977. {
  1978. if (MidDoc != null)
  1979. MidDoc.Close();
  1980. if (MidFormat != null)
  1981. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  1982. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1983. {
  1984. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1985. if (PrintMethod == "CodeSoft")
  1986. {
  1987. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1988. MidDoc.Printer.Name = MidLabelPrinter.Text;
  1989. }
  1990. else
  1991. {
  1992. MidFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1993. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1994. }
  1995. }
  1996. }
  1997. }
  1998. catch (Exception) { }
  1999. }
  2000. /// <summary>
  2001. /// 切换打开的外箱文件
  2002. /// </summary>
  2003. /// <param name="sender"></param>
  2004. /// <param name="e"></param>
  2005. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  2006. {
  2007. try
  2008. {
  2009. if (ComBoxClickChangeLabelDoc)
  2010. {
  2011. if (OutBoxDoc != null)
  2012. OutBoxDoc.Close();
  2013. if (OutFormat != null)
  2014. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2015. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2016. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2017. {
  2018. if (PrintMethod == "CodeSoft")
  2019. {
  2020. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2021. OutBoxDoc.Printer.Name = OutBoxPrinter.Text;
  2022. }
  2023. else
  2024. {
  2025. OutFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2026. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2027. EmptyOutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2028. }
  2029. }
  2030. }
  2031. }
  2032. catch (Exception) { }
  2033. }
  2034. private void ChooseAll_Click(object sender, EventArgs e)
  2035. {
  2036. if (LabelInf.Rows.Count > 0)
  2037. {
  2038. if (LabelInf.Rows.Count > 0)
  2039. {
  2040. if (LabelInf.Rows[0].Cells["Choose"].FormattedValue.ToString() == "True")
  2041. {
  2042. foreach (DataGridViewRow dr in LabelInf.Rows)
  2043. dr.Cells[0].Value = false;
  2044. }
  2045. else
  2046. {
  2047. foreach (DataGridViewRow dr in LabelInf.Rows)
  2048. dr.Cells[0].Value = true;
  2049. }
  2050. }
  2051. }
  2052. }
  2053. private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2054. {
  2055. if (e.RowIndex > 0)
  2056. {
  2057. if (LabelInf.Columns[e.ColumnIndex].Name == "pin_madein")
  2058. {
  2059. StringBuilder pibid = new StringBuilder();
  2060. string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
  2061. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "盒")
  2062. {
  2063. string midbox = LabelInf.Rows[e.RowIndex].Cells["pib_outboxcode1"].Value.ToString();
  2064. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2065. {
  2066. if (midbox == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  2067. {
  2068. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  2069. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  2070. }
  2071. }
  2072. }
  2073. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "全部")
  2074. {
  2075. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2076. {
  2077. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  2078. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  2079. }
  2080. }
  2081. pibid.Append("1");
  2082. sdh.ExecuteSql("update prodiobarcode set pib_madein='" + madein + "' where pib_id in (" + pibid + ")", "update");
  2083. }
  2084. }
  2085. }
  2086. private void ExportData_Click(object sender, EventArgs e)
  2087. {
  2088. }
  2089. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  2090. {
  2091. NumericUpDown nup = (NumericUpDown)sender;
  2092. switch (nup.Name)
  2093. {
  2094. case "MidBoxCapacity":
  2095. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  2096. Properties.Settings.Default.Save();
  2097. break;
  2098. case "OutboxCapacity":
  2099. Properties.Settings.Default.OutboxCapacity = nup.Value;
  2100. Properties.Settings.Default.Save();
  2101. break;
  2102. default:
  2103. break;
  2104. }
  2105. }
  2106. private void CleanBarCode_Click(object sender, EventArgs e)
  2107. {
  2108. string close = MessageBox.Show(this.ParentForm, "是否清除该出货单条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2109. if (close.ToString() == "Yes")
  2110. {
  2111. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2112. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2113. LoadGridData(sender, e);
  2114. }
  2115. }
  2116. private void LabelPrinter_UserOnSelectIndexChange(object sender, EventArgs e)
  2117. {
  2118. switch ((sender as Control).Parent.Name)
  2119. {
  2120. case "SingleLabelPrinter":
  2121. if (PrintMethod == "CodeSoft")
  2122. {
  2123. if (SingleDoc != null)
  2124. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  2125. }
  2126. else
  2127. {
  2128. if (SingleFormat != null)
  2129. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  2130. }
  2131. Properties.Settings.Default.SinglePrinter = SingleLabelPrinter.Text;
  2132. break;
  2133. case "MidLabelPrinter":
  2134. if (PrintMethod == "CodeSoft")
  2135. {
  2136. if (MidDoc != null)
  2137. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  2138. }
  2139. else
  2140. {
  2141. if (MidFormat != null)
  2142. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  2143. }
  2144. Properties.Settings.Default.MidPrinter = MidLabelPrinter.Text;
  2145. break;
  2146. case "OutBoxPrinter":
  2147. if (PrintMethod == "CodeSoft")
  2148. {
  2149. if (OutBoxDoc != null)
  2150. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  2151. }
  2152. else
  2153. {
  2154. if (OutFormat != null)
  2155. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2156. }
  2157. Properties.Settings.Default.OutPrinter = OutBoxPrinter.Text;
  2158. break;
  2159. default:
  2160. break;
  2161. }
  2162. Properties.Settings.Default.Save();
  2163. }
  2164. private void DocRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2165. {
  2166. switch ((sender as Control).Name)
  2167. {
  2168. case "SingleDocRefresh":
  2169. if (SingleDoc != null)
  2170. SingleDoc.Close();
  2171. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2172. {
  2173. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2174. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2175. }
  2176. break;
  2177. case "MidDocRefresh":
  2178. if (MidDoc != null)
  2179. MidDoc.Close();
  2180. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2181. {
  2182. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2183. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2184. }
  2185. break;
  2186. case "OutDocRefresh":
  2187. if (OutBoxDoc != null)
  2188. OutBoxDoc.Close();
  2189. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2190. {
  2191. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2192. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2193. }
  2194. break;
  2195. default:
  2196. break;
  2197. }
  2198. }
  2199. private void cu_code_UserControlTextChanged(object sender, EventArgs e)
  2200. {
  2201. if (!InitGetLabel)
  2202. GetInOutInfAndLabelFile();
  2203. }
  2204. private void MenuSetting_Click(object sender, EventArgs e)
  2205. {
  2206. Menu.Show(new Point(MenuSetting.Location.X, MenuSetting.Location.Y + 20));
  2207. }
  2208. private void Menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2209. {
  2210. Menu.Close();
  2211. DataTable dt;
  2212. DialogResult result;
  2213. switch (e.ClickedItem.Text)
  2214. {
  2215. case "采集策略设置":
  2216. 采集策略 form = new 采集策略(sg_code.Text);
  2217. form.FormClosed += sg_code_UserControlTextChanged;
  2218. BaseUtil.SetFormCenter(form);
  2219. form.ShowDialog();
  2220. break;
  2221. case "附加信息设置":
  2222. if (cu_code.Text != "")
  2223. {
  2224. 附件内容打印 att = new 附件内容打印(cu_code.Text);
  2225. att.FormClosed += Att_FormClosed;
  2226. att.ShowDialog();
  2227. }
  2228. else MessageBox.Show("请先获取出库单信息");
  2229. break;
  2230. case "标签维护":
  2231. 客户标签维护 form1 = new 客户标签维护();
  2232. BaseUtil.SetFormCenter(form1);
  2233. if (SingleDoc != null)
  2234. SingleDoc.Close();
  2235. if (MidDoc != null)
  2236. MidDoc.Close();
  2237. if (OutBoxDoc != null)
  2238. OutBoxDoc.Close();
  2239. //if (SingleFormat != null)
  2240. // SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  2241. //if (MidFormat != null)
  2242. // MidFormat.Close(SaveOptions.DoNotSaveChanges);
  2243. //if (OutFormat != null)
  2244. // OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2245. form1.FormClosed += LabelFormClose;
  2246. form1.ShowDialog();
  2247. break;
  2248. case "导出数据":
  2249. ExportFileDialog.Description = "选择导出的路径";
  2250. result = ExportFileDialog.ShowDialog();
  2251. if (result == DialogResult.OK)
  2252. {
  2253. ExcelHandler eh = new ExcelHandler();
  2254. dt = ((DataTable)LabelInf.DataSource).Copy();
  2255. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  2256. {
  2257. for (int j = 0; j < LabelInf.Columns.Count; j++)
  2258. {
  2259. //去除ID列
  2260. 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")
  2261. {
  2262. dt.Columns.RemoveAt(i);
  2263. break;
  2264. }
  2265. switch (dt.Columns[i].ColumnName.ToLower())
  2266. {
  2267. case "pib_lotno":
  2268. dt.Columns[i].ColumnName = "批次号";
  2269. break;
  2270. case "pib_datecode":
  2271. dt.Columns[i].ColumnName = "生产日期";
  2272. break;
  2273. case "pib_custbarcode":
  2274. dt.Columns[i].ColumnName = "最小产品包装条码";
  2275. break;
  2276. default:
  2277. break;
  2278. }
  2279. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  2280. {
  2281. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  2282. break;
  2283. }
  2284. }
  2285. }
  2286. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  2287. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2288. if (close.ToString() == "Yes")
  2289. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  2290. }
  2291. break;
  2292. case "权限设置":
  2293. PowerSetting pw = new PowerSetting();
  2294. BaseUtil.SetFormCenter(pw);
  2295. pw.ShowDialog();
  2296. break;
  2297. case "条码导入生成":
  2298. ImportExcel.Filter = "(*.xls)|*.xlsx;*.xls";
  2299. result = ImportExcel.ShowDialog();
  2300. if (result == DialogResult.OK)
  2301. {
  2302. thread = new Thread(ImportBarcode);
  2303. stw = new SetLoadingWindow(thread, "正在生成条码");
  2304. BaseUtil.SetFormCenter(stw);
  2305. stw.ShowDialog();
  2306. }
  2307. break;
  2308. case "下载模板":
  2309. ExportFileDialog.Description = "选择导出的路径";
  2310. result = ExportFileDialog.ShowDialog();
  2311. if (result == DialogResult.OK)
  2312. {
  2313. File.Copy(System.Windows.Forms.Application.StartupPath + "\\导入模板.xls", ExportFileDialog.SelectedPath + "\\导入模板.xls", true);
  2314. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\导入模板.xls");
  2315. }
  2316. break;
  2317. case "客户合并规则":
  2318. CustomerRule cust = new CustomerRule();
  2319. BaseUtil.SetFormCenter(cust);
  2320. cust.ShowDialog();
  2321. break;
  2322. case "流水调整":
  2323. if (cu_code.Text != "")
  2324. {
  2325. ReSetMaxNum reset = new ReSetMaxNum(cu_code.Text, pi_inoutno.Text);
  2326. BaseUtil.SetFormCenter(reset);
  2327. reset.ShowDialog();
  2328. }
  2329. else
  2330. {
  2331. MessageBox.Show("请先输入出货单号");
  2332. }
  2333. break;
  2334. default:
  2335. break;
  2336. }
  2337. }
  2338. private void Att_FormClosed(object sender, FormClosedEventArgs e)
  2339. {
  2340. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  2341. }
  2342. //生成客户条码
  2343. public string BarcodeMethod1(string Prefix, string Suffix, int Index, int Length, int radix)
  2344. {
  2345. string str = Prefix;
  2346. //如果是流水则需要在前面加0
  2347. string serialcode = BaseUtil.DToAny(custserialnum, radix);
  2348. for (int j = serialcode.ToString().Length; j < Length; j++)
  2349. {
  2350. serialcode = "0" + serialcode;
  2351. }
  2352. str += serialcode;
  2353. str += Suffix;
  2354. custserialnum = custserialnum + 1;
  2355. return str;
  2356. }
  2357. //前缀
  2358. string Prefix = "";
  2359. //后缀
  2360. string Suffix = "";
  2361. //编码规则编号
  2362. string NrCode = "";
  2363. string PrefixFixed = "";
  2364. //流水号的索引
  2365. int SerialNumIndex = 0;
  2366. //流水长度
  2367. int SerialNumLength = 0;
  2368. //存放键值对
  2369. int Radix = 10;
  2370. //客户的流水号
  2371. int custserialnum = 0;
  2372. public void GetCustRule()
  2373. {
  2374. //前缀
  2375. Prefix = "";
  2376. //后缀
  2377. Suffix = "";
  2378. //编码规则编号
  2379. NrCode = "";
  2380. PrefixFixed = "";
  2381. //流水号的索引
  2382. SerialNumIndex = 0;
  2383. //流水长度
  2384. SerialNumLength = 0;
  2385. //存放键值对
  2386. Radix = 10;
  2387. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + cu_code.Text + "' order by nrd_detno", "select");
  2388. //如果没有则取公共规则
  2389. if (Nr.Rows.Count == 0)
  2390. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  2391. //用于过滤参数的正则表达式
  2392. if (Nr.Rows.Count > 0)
  2393. {
  2394. NrCode = Nr.Rows[0]["nr_code"].ToString();
  2395. }
  2396. Regex match = new Regex("{\\w+}");
  2397. //用于存放每一项的明细的数据
  2398. string[] NrData = new string[Nr.Rows.Count];
  2399. for (int m = 0; m < Nr.Rows.Count; m++)
  2400. {
  2401. switch (Nr.Rows[m]["nrd_type"].ToString())
  2402. {
  2403. //常量直接进行拼接
  2404. case "常量":
  2405. NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
  2406. Prefix += NrData[m];
  2407. Suffix += NrData[m];
  2408. break;
  2409. case "SQL":
  2410. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  2411. DataTable Temp;
  2412. //如果不包含参数替换
  2413. if (SQL.IndexOf("{") == 0)
  2414. {
  2415. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2416. }
  2417. else
  2418. {
  2419. //替换参数后重新执行SQL
  2420. foreach (Match mch in match.Matches(SQL))
  2421. {
  2422. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  2423. }
  2424. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2425. }
  2426. if (Temp.Rows.Count > 0)
  2427. {
  2428. NrData[m] = Temp.Rows[0][0].ToString();
  2429. Prefix += NrData[m];
  2430. Suffix += NrData[m];
  2431. }
  2432. else
  2433. {
  2434. NrData[m] = "";
  2435. Prefix += NrData[m];
  2436. Suffix += NrData[m];
  2437. }
  2438. break;
  2439. //流水需要通过MaxNumber去取
  2440. case "流水":
  2441. NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
  2442. Suffix = "";
  2443. PrefixFixed = Prefix;
  2444. //设置当前流水
  2445. custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
  2446. SerialNumIndex = m;
  2447. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  2448. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  2449. break;
  2450. default:
  2451. break;
  2452. }
  2453. }
  2454. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  2455. if (maxnum == "")
  2456. {
  2457. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
  2458. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  2459. custserialnum = int.Parse(maxnum);
  2460. }//如果流水号不为空则取当前流水
  2461. else
  2462. {
  2463. custserialnum = int.Parse(maxnum);
  2464. }
  2465. }
  2466. public void ImportBarcode()
  2467. {
  2468. try
  2469. {
  2470. GetCustRule();
  2471. //获取最大的流水号
  2472. DataTable dt = ExcelHandler.ExcelToDataTable(ImportExcel.FileName, true);
  2473. if (dt == null)
  2474. {
  2475. MessageBox.Show("文件" + ImportExcel.FileName + "被占用或者格式不正确");
  2476. return;
  2477. }
  2478. string outsql = "";
  2479. LogicHandler.GenerateBarCode(PI_ID, cu_code.Text, out outsql);
  2480. sql.Clear();
  2481. sql.Append(outsql);
  2482. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  2483. //需要插入的参数
  2484. ArrayList<string> barcode = new ArrayList<string>();
  2485. ArrayList<string> custbarcode = new ArrayList<string>();
  2486. ArrayList<string> datecode = new ArrayList<string>();
  2487. ArrayList<string> lotno = new ArrayList<string>();
  2488. ArrayList<string> pib_inqty = new ArrayList<string>();
  2489. ArrayList<string> piboutboxcode2 = new ArrayList<string>();
  2490. ArrayList<string> pdordercode = new ArrayList<string>();
  2491. ArrayList<string> pdorderdetno = new ArrayList<string>();
  2492. ArrayList<string> pdpdno = new ArrayList<string>();
  2493. ArrayList<string> pdid = new ArrayList<string>();
  2494. ArrayList<string> prbrand = new ArrayList<string>();
  2495. ArrayList<string> pdprodcode = new ArrayList<string>();
  2496. ArrayList<string> pib_custoutboxcode = new ArrayList<string>();
  2497. ArrayList<string> brand = new ArrayList<string>();
  2498. ArrayList<string> madein = new ArrayList<string>();
  2499. ArrayList<string> prdetail = new ArrayList<string>();
  2500. ArrayList<string> ordercode = new ArrayList<string>();
  2501. ArrayList<string> size = new ArrayList<string>();
  2502. ArrayList<string> weight = new ArrayList<string>();
  2503. //用于数量的校验
  2504. Dictionary<string, decimal> sumqty = new Dictionary<string, decimal>();
  2505. Dictionary<string, Dictionary<string, decimal>> outsumqty = new Dictionary<string, Dictionary<string, decimal>>();
  2506. for (int i = 0; i < dt.Rows.Count; i++)
  2507. {
  2508. string pr_spec = dt.Rows[i]["规格型号"].ToString().Trim();
  2509. if (pr_spec.Trim() == "")
  2510. {
  2511. break;
  2512. }
  2513. string qty = Regex.Replace(dt.Rows[i]["数量"].ToString(), @"[^\d]*", ""); ;
  2514. //累计Excel该型号的数量
  2515. if (!sumqty.ContainsKey(pr_spec))
  2516. {
  2517. sumqty.Add(pr_spec, 0);
  2518. }
  2519. //累计Excel该型号的数量
  2520. sumqty[pr_spec] += decimal.Parse(qty);
  2521. }
  2522. for (int i = 0; i < dt1.Rows.Count; i++)
  2523. {
  2524. //不包含型号则进行添加
  2525. string pr_spec = dt1.Rows[i]["pr_spec"].ToString().Trim();
  2526. string pd_pdno = dt1.Rows[i]["pd_pdno"].ToString();
  2527. decimal pd_outqty = decimal.Parse(dt1.Rows[i]["pd_outqty"].ToString());
  2528. if (!outsumqty.ContainsKey(pr_spec))
  2529. {
  2530. Dictionary<string, decimal> dic = new Dictionary<string, decimal>();
  2531. dic.Add(pd_pdno, pd_outqty);
  2532. outsumqty.Add(pr_spec, dic);
  2533. }
  2534. else
  2535. {
  2536. outsumqty[pr_spec].Add(pd_pdno, pd_outqty);
  2537. }
  2538. }
  2539. //上一个的最小外箱号,如果箱号没有发生变化则外箱条码也不变化
  2540. for (int i = 0; i < dt.Rows.Count; i++)
  2541. {
  2542. string pr_spec = dt.Rows[i]["规格型号"].ToString().Trim();
  2543. string 品牌 = dt.Rows[i]["品牌"].ToString().Trim();
  2544. string 产地 = dt.Rows[i]["产地"].ToString().Trim();
  2545. string 尺寸 = dt.Rows[i]["尺寸"].ToString().Trim();
  2546. string 重量 = dt.Rows[i]["重量"].ToString().Trim();
  2547. string 产品名称 = dt.Rows[i]["产品名称"].ToString().Trim();
  2548. string 订单编号 = dt.Rows[i]["订单编号"].ToString().Trim();
  2549. if (pr_spec.Trim() == "")
  2550. {
  2551. break;
  2552. }
  2553. string qty = dt.Rows[i]["数量"].ToString();
  2554. string DateCode = "";
  2555. string LotNo = "";
  2556. if (dt.Columns.Contains("DC/LOT NO"))
  2557. {
  2558. if (dt.Rows[i]["DC/LOT NO"].ToString().IndexOf("-") > 0)
  2559. {
  2560. DateCode = dt.Rows[i]["DC/LOT NO"].ToString().Split('-')[0];
  2561. LotNo = dt.Rows[i]["DC/LOT NO"].ToString().Split('-')[1];
  2562. }
  2563. else if (dt.Rows[i]["DC/LOT NO"].ToString().IndexOf(" ") > 0)
  2564. {
  2565. DateCode = dt.Rows[i]["DC/LOT NO"].ToString().Split(' ')[0];
  2566. LotNo = dt.Rows[i]["DC/LOT NO"].ToString().Split(' ')[1];
  2567. }
  2568. }
  2569. if (dt.Columns.Contains("DC") && DateCode == "")
  2570. {
  2571. DateCode = dt.Rows[i]["DC"].ToString();
  2572. }
  2573. if (dt.Columns.Contains("LOT NO") && LotNo == "")
  2574. {
  2575. LotNo = dt.Rows[i]["LOT NO"].ToString();
  2576. }
  2577. string pib_outboxcode2 = dt.Rows[i]["箱号"].ToString();
  2578. DataRow[] dr = dt1.Select("pr_spec='" + pr_spec + "'");
  2579. if (dr.Length == 0)
  2580. {
  2581. LogicHandler.FilterData(cu_code.Text, "FUDAN", pr_spec, qty, DateCode, LotNo, out pr_spec, out qty, out DateCode, out LotNo);
  2582. dr = dt1.Select("pr_spec='" + pr_spec + "'");
  2583. }
  2584. else
  2585. {
  2586. LogicHandler.FilterData(cu_code.Text, dr[0]["pr_brand"].ToString(), pr_spec, qty, DateCode, LotNo, out pr_spec, out qty, out DateCode, out LotNo);
  2587. }
  2588. if (dr.Length == 0)
  2589. {
  2590. MessageBox.Show("出货单" + pi_inoutno.Text + "不包含型号" + pr_spec);
  2591. return;
  2592. }
  2593. decimal outqty = decimal.Parse(Regex.Replace(qty, @"[^\d]*", ""));
  2594. for (int k = 0; k < dr.Length; k++)
  2595. {
  2596. string pd_orderdetno = dr[k]["pd_orderdetno"].ToString();
  2597. string pd_prodcode = dr[k]["pd_prodcode"].ToString();
  2598. string pd_ordercode = dr[k]["pd_ordercode"].ToString();
  2599. string pd_piid = dr[k]["pd_piid"].ToString();
  2600. string pr_brand = dr[k]["pr_brand"].ToString();
  2601. string pd_pdno = dr[k]["pd_pdno"].ToString();
  2602. string pd_id = dr[k]["pd_id"].ToString();
  2603. string pd_piclass = dr[k]["pd_piclass"].ToString();
  2604. string pr_id = dr[k]["pr_id"].ToString();
  2605. string pr_madein = dr[k]["pr_madein"].ToString();
  2606. //已导入数量
  2607. decimal zxbzs = decimal.Parse(dr[k]["pr_zxbzs"].ToString());
  2608. decimal pd_outqty = 0;
  2609. decimal barcodenum = 0;
  2610. if (outsumqty[pr_spec][pd_pdno] == 0)
  2611. {
  2612. continue;
  2613. }
  2614. //如果导入行的数量小于改明细的出货数量
  2615. if (outsumqty[pr_spec][pd_pdno] >= outqty)
  2616. {
  2617. //使用导入明细行数量
  2618. pd_outqty = outqty;
  2619. }
  2620. else
  2621. {
  2622. ////使用该出货单明细行数量,并且数量置为0
  2623. pd_outqty = outsumqty[pr_spec][pd_pdno];
  2624. }
  2625. string pib_barcode = dh.getFieldDataByCondition("prodiobarcode", "max(pib_barcode)", "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
  2626. if (pd_outqty % zxbzs != 0)
  2627. {
  2628. barcodenum = Math.Floor(pd_outqty / zxbzs) + 1;
  2629. //如果有余数先加上所有最小包最后加尾数
  2630. for (int j = 0; j < barcodenum - 1; j++)
  2631. {
  2632. barcode.Add(BaseUtil.BarcodeMethod1(pd_id, pr_id, pib_barcode));
  2633. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  2634. pib_custoutboxcode.Add(pib_outboxcode2);
  2635. piboutboxcode2.Add(pib_outboxcode2);
  2636. pib_inqty.Add(zxbzs);
  2637. datecode.Add(DateCode);
  2638. lotno.Add(LotNo);
  2639. pdordercode.Add(订单编号 == "" ? pd_ordercode : 订单编号);
  2640. pdorderdetno.Add(pd_orderdetno);
  2641. pdpdno.Add(pd_pdno);
  2642. pdid.Add(pd_id);
  2643. prbrand.Add(品牌 == "" ? pr_brand : 品牌);
  2644. madein.Add(产地 == "" ? pr_madein : 产地);
  2645. size.Add(尺寸);
  2646. weight.Add(重量);
  2647. prdetail.Add(产品名称);
  2648. ordercode.Add(订单编号);
  2649. pdprodcode.Add(pd_prodcode);
  2650. }
  2651. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  2652. pib_custoutboxcode.Add(pib_outboxcode2);
  2653. barcode.Add(BaseUtil.BarcodeMethod1(pd_id, pr_id, pib_barcode));
  2654. pib_inqty.Add(pd_outqty % zxbzs);
  2655. piboutboxcode2.Add(pib_outboxcode2);
  2656. datecode.Add(DateCode);
  2657. lotno.Add(LotNo);
  2658. pdordercode.Add(订单编号 == "" ? pd_ordercode : 订单编号);
  2659. pdorderdetno.Add(pd_orderdetno);
  2660. pdpdno.Add(pd_pdno);
  2661. pdid.Add(pd_id);
  2662. prbrand.Add(品牌 == "" ? pr_brand : 品牌);
  2663. madein.Add(产地 == "" ? pr_madein : 产地);
  2664. size.Add(尺寸);
  2665. weight.Add(重量);
  2666. prdetail.Add(产品名称);
  2667. ordercode.Add(订单编号);
  2668. pdprodcode.Add(pd_prodcode);
  2669. }
  2670. else
  2671. {
  2672. barcodenum = pd_outqty / zxbzs;
  2673. for (int j = 0; j < barcodenum; j++)
  2674. {
  2675. barcode.Add(BaseUtil.BarcodeMethod1(pd_id, pr_id, pib_barcode));
  2676. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  2677. pib_custoutboxcode.Add(pib_outboxcode2);
  2678. pib_inqty.Add(zxbzs);
  2679. piboutboxcode2.Add(pib_outboxcode2);
  2680. datecode.Add(DateCode);
  2681. lotno.Add(LotNo);
  2682. pdordercode.Add(订单编号 == "" ? pd_ordercode : 订单编号);
  2683. pdorderdetno.Add(pd_orderdetno);
  2684. pdpdno.Add(pd_pdno);
  2685. pdid.Add(pd_id);
  2686. prbrand.Add(品牌 == "" ? pr_brand : 品牌);
  2687. madein.Add(产地 == "" ? pr_madein : 产地);
  2688. size.Add(尺寸);
  2689. weight.Add(重量);
  2690. prdetail.Add(产品名称);
  2691. pdprodcode.Add(pd_prodcode);
  2692. }
  2693. }
  2694. outqty -= outsumqty[pr_spec][pd_pdno];
  2695. outsumqty[pr_spec][pd_pdno] -= pd_outqty;
  2696. }
  2697. }
  2698. string Lastoutbox = "";
  2699. string Lastoutboxcode = "";
  2700. List<string> custoutboxcode = new List<string>();
  2701. //根据记录的箱号,在料盘的流水之后拼接外箱的流水
  2702. for (int i = 0; i < pib_custoutboxcode.Count; i++)
  2703. {
  2704. if (Lastoutbox != pib_custoutboxcode[i].ToString())
  2705. {
  2706. Lastoutboxcode = BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix);
  2707. custoutboxcode.Add(Lastoutboxcode);
  2708. Lastoutbox = pib_custoutboxcode[i].ToString();
  2709. }
  2710. else
  2711. {
  2712. custoutboxcode.Add(Lastoutboxcode);
  2713. }
  2714. }
  2715. //插叙所有的统计数量
  2716. string ErrMsg = "";
  2717. foreach (var item in sumqty)
  2718. {
  2719. dt = (DataTable)dh.ExecuteSql("select nvl(sum(pd_outqty),0)pd_outqty,pr_spec from prodiodetail left join product on pr_code=pd_prodcode where pd_piid='" + PI_ID + "' group by pr_spec", "select");
  2720. dt1 = (DataTable)dh.ExecuteSql("select nvl(sum(pib_qty),0)pib_qty,pr_spec from prodiobarcode left join product on pib_prodcode=pr_code where pib_piid='" + PI_ID + "' group by pr_spec", "select");
  2721. DataRow[] dr = dt.Select("pr_spec='" + item.Key + "'");
  2722. DataRow[] dr1 = dt1.Select("pr_spec='" + item.Key + "'");
  2723. if (dr.Length > 0)
  2724. {
  2725. decimal pd_outqty = decimal.Parse(dr[0]["pd_outqty"].ToString());
  2726. decimal pib_qty = 0;
  2727. //如果有已导入的数量
  2728. if (dr1.Length > 0)
  2729. {
  2730. pib_qty = decimal.Parse(dr1[0]["pib_qty"].ToString());
  2731. }
  2732. //本次导入的数量和原有导入数量累加和出库数量做对比
  2733. if (pd_outqty < item.Value + pib_qty)
  2734. {
  2735. ErrMsg += "型号" + dr[0]["pr_spec"].ToString() + "出货数量" + pd_outqty + ",已导入数量" + pib_qty + ",本次导入" + item.Value + ",超出数量" + (item.Value + pib_qty - pd_outqty) + "\n";
  2736. }
  2737. }
  2738. }
  2739. if (ErrMsg == "")
  2740. {
  2741. if (pdprodcode.Count > 0)
  2742. {
  2743. sql.Clear();
  2744. sql.Append("insert into prodiobarcode (PIB_ID,PIB_PRODCODE,pib_inman,PIB_INDATE,PIB_INOUTNO,PIB_PIID,pib_brand,PIB_BARCODE,PIB_PDNO,");
  2745. sql.Append("PIB_PDID,PIB_PICLASS,PIB_QTY,pib_datecode,pib_lotno,PIB_IFPRINT,PIB_IFPICK,PIB_ORDERCODE,pib_orderdetno,");
  2746. sql.Append("pib_outboxcode2,pib_custbarcode,pib_custoutboxcode,pib_madein,pib_size,pib_weight,pib_prdetail)values(prodiobarcode_seq.nextval,:pd_prodcode,'" + User.UserName + "',sysdate,");
  2747. sql.Append("'" + pi_inoutno.Text + "'," + PI_ID + ",:pr_brand,:barcode,:pd_pdno,:pd_id,'" + pi_class.Text + "',:pib_inqty,");
  2748. sql.Append(":pib_datecode,:pib_lotno,0,-1,:pd_ordercode,:pd_orderdetno,:outboxcode,:custbarcode,:pib_custoutboxcode,:pib_madein,:pib_size,:pib_weight,:pib_prdetail)");
  2749. dh.BatchInsert(sql.ToString(), new string[] { "pd_prodcode", "pr_brand", "barcode", "pd_pdno", "pd_id", "pib_inqty", "pib_datecode", "pib_lotno", "pd_ordercode", "pd_orderdetno", "outboxcode", "custbarcode", "pib_custoutboxcode", "pib_madein", "pib_size", "pib_weight", "pib_prdetail" }, pdprodcode.ToArray(), prbrand.ToArray(), barcode.ToArray(), pdpdno.ToArray(), pdid.ToArray(), pib_inqty.ToArray(), datecode.ToArray(), lotno.ToArray(), pdordercode.ToArray(), pdorderdetno.ToArray(), piboutboxcode2.ToArray(), custbarcode.ToArray(), custoutboxcode.ToArray(), madein.ToArray(), size.ToArray(), weight.ToArray(), prdetail.ToArray());
  2750. //更新流水
  2751. dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + custserialnum + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
  2752. LoadGridData();
  2753. }
  2754. else
  2755. {
  2756. MessageBox.Show("解析数据不包含出货单数据,请重新导入", "提示");
  2757. }
  2758. }
  2759. else
  2760. {
  2761. MessageBox.Show(ErrMsg, "超出数量提醒");
  2762. }
  2763. }
  2764. catch (Exception ex)
  2765. {
  2766. LogManager.DoLog(ex.StackTrace);
  2767. MessageBox.Show(ex.Message);
  2768. }
  2769. }
  2770. int rowindex = 0;
  2771. private void LabelInf_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  2772. {
  2773. if (e.Button == MouseButtons.Right)
  2774. {
  2775. rowindex = e.RowIndex;
  2776. DateCodeSetAndPrint date = new DateCodeSetAndPrint();
  2777. date.Controls["SetValue"].Click += SetValue_ButtonClick;
  2778. date.Controls["SetValueAndPrint"].Click += SetValueAndPrint_ButtonClick;
  2779. date.ShowDialog();
  2780. }
  2781. }
  2782. private void SetValue_ButtonClick(object sender, EventArgs e)
  2783. {
  2784. Button setvalue = sender as Button;
  2785. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2786. string pr_brand = LabelInf.Rows[rowindex].Cells["pib_brand"].Value.ToString();
  2787. string datecode = setvalue.FindForm().Controls["datecode"].Text;
  2788. string lotno = setvalue.FindForm().Controls["lotno"].Text;
  2789. string nums = setvalue.FindForm().Controls["Nums"].Text;
  2790. string year = "0";
  2791. string month = "0";
  2792. string day = "0";
  2793. string date = "";
  2794. string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2795. if (datecode != "")
  2796. {
  2797. LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  2798. sql += " and (pib_datecode='' or pib_datecode is null) ";
  2799. }
  2800. if (lotno != "")
  2801. {
  2802. sql += " and (pib_lotno='' or pib_lotno is null) ";
  2803. }
  2804. if (nums == "")
  2805. {
  2806. sql += ")";
  2807. }
  2808. else
  2809. {
  2810. sql += " limit 0," + nums + ")";
  2811. }
  2812. sdh.ExecuteSql(sql, "update");
  2813. LoadGridData();
  2814. setvalue.FindForm().Close();
  2815. }
  2816. private void SetValueAndPrint_ButtonClick(object sender, EventArgs e)
  2817. {
  2818. Button setvalueandprint = sender as Button;
  2819. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2820. string pr_brand = LabelInf.Rows[rowindex].Cells["pib_brand"].Value.ToString();
  2821. string datecode = setvalueandprint.FindForm().Controls["datecode"].Text;
  2822. string lotno = setvalueandprint.FindForm().Controls["lotno"].Text;
  2823. string nums = setvalueandprint.FindForm().Controls["Nums"].Text;
  2824. string year = "0";
  2825. string month = "0";
  2826. string day = "0";
  2827. string date = "";
  2828. string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2829. string PrintSQL = "select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2830. if (datecode != "")
  2831. {
  2832. LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  2833. sql += " and (pib_datecode='' or pib_datecode is null) ";
  2834. PrintSQL += " and (pib_datecode='' or pib_datecode is null) ";
  2835. }
  2836. if (lotno != "")
  2837. {
  2838. sql += " and (pib_lotno='' or pib_lotno is null) ";
  2839. PrintSQL += " and (pib_lotno='' or pib_lotno is null) ";
  2840. }
  2841. if (nums == "")
  2842. {
  2843. sql += ")";
  2844. }
  2845. else
  2846. {
  2847. sql += " limit 0," + nums + ")";
  2848. PrintSQL += " limit 0," + nums;
  2849. }
  2850. DataTable pibid_dt = (DataTable)sdh.ExecuteSql(PrintSQL, "select");
  2851. sdh.ExecuteSql(sql, "update");
  2852. for (int i = 0; i < pibid_dt.Rows.Count; i++)
  2853. {
  2854. if (PrintMethod == "CodeSoft")
  2855. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pibid_dt.Rows[i]["pib_id"].ToString());
  2856. else
  2857. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pibid_dt.Rows[i]["pib_id"].ToString());
  2858. }
  2859. setvalueandprint.FindForm().Close();
  2860. }
  2861. /// <summary>
  2862. /// 特殊业务逻辑
  2863. /// </summary>
  2864. /// <param name="sender"></param>
  2865. /// <param name="e"></param>
  2866. private void CustBarCode_Click(object sender, EventArgs e)
  2867. {
  2868. string SQL = "";
  2869. LogicHandler.CustBarCode(pi_inoutno.Text, out SQL);
  2870. sdh.ExecuteSql(SQL, "update");
  2871. LoadGridData();
  2872. }
  2873. private void GetMidBoxCode_Click(object sender, EventArgs e)
  2874. {
  2875. int BoxCode = 1;
  2876. int innerboxcount = 1;
  2877. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2878. {
  2879. string midcapa = LabelInf.Rows[i].Cells["pr_midboxcapacity_user"].Value.ToString();
  2880. if (!(midcapa == "" || midcapa == "0"))
  2881. {
  2882. //如果出现值为空或者0默认界面上填写的值
  2883. MidBoxCapacity.Value = decimal.Parse((midcapa == "" || midcapa == "0") ? MidBoxCapacity.Value.ToString() : midcapa);
  2884. LabelInf.Rows[i].Cells["pib_outboxcode1"].Value = BoxCode;
  2885. if (i + 1 < LabelInf.Rows.Count)
  2886. {
  2887. if (innerboxcount == MidBoxCapacity.Value)
  2888. {
  2889. BoxCode = BoxCode + 1;
  2890. innerboxcount = 1;
  2891. }
  2892. else if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString())
  2893. {
  2894. BoxCode = BoxCode + 1;
  2895. innerboxcount = 1;
  2896. }
  2897. else
  2898. {
  2899. innerboxcount = innerboxcount + 1;
  2900. }
  2901. }
  2902. }
  2903. }
  2904. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  2905. DataTable dt1 = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' ", "select");
  2906. if (dt1.Rows.Count > 0)
  2907. {
  2908. dh.CallProcedure("sp_uploadbarcode", dt1);
  2909. }
  2910. }
  2911. }
  2912. }