123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- using NPOI.SS.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using UAS_LabelMachine.Entity;
- using UAS_LabelMachine.PublicMethod;
- namespace UAS_LabelMachine
- {
- public partial class 生成条码 : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- DataTable dt;
- StringBuilder sql = new StringBuilder();
- string pi_id;
-
- Dictionary<string, string> NotPass = new Dictionary<string, string>();
-
- string Prefix = "";
-
- int serialnum = 0;
-
- int custserialnum = 0;
-
- bool FirstCode = false;
-
- string CustCode = "";
-
- string NrCode = "";
- public 生成条码(string PI_INOUTNO)
- {
- InitializeComponent();
- pi_inoutno.Text = PI_INOUTNO;
- }
- private void 生成条码_Load(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- ChooseAll.ChooseAll(ProdIoInfDGV);
-
- if (pi_inoutno.Text != "")
- {
- bi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
- }
- pr_kind.Text = "全部";
- asc.controllInitializeSize(this);
- Width = Width - 1;
- }
- private void bi_inoutno_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- LoadData();
- }
- }
- private void 生成条码_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
-
-
-
-
-
- private void Screen_Click(object sender, EventArgs e)
- {
- bi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
- }
-
-
-
-
-
- private void GenerateBarCode_Click(object sender, EventArgs e)
- {
-
- DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + CustCode + "' and nr_type='Single' order by nrd_detno", "select");
-
- if (Nr.Rows.Count == 0)
- Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_type='Single' and nr_isdefault <> 0 order by nrd_detno", "select");
-
- Regex match = new Regex("{\\w+}");
-
- string[] NrData = new string[Nr.Rows.Count];
-
- int SerialNumIndex = 0;
-
- int SerialNumLength = 0;
-
- int Radix = 10;
- Dictionary<int, string> NrDic = new Dictionary<int, string>();
- for (int m = 0; m < Nr.Rows.Count; m++)
- {
- switch (Nr.Rows[m]["nrd_type"].ToString())
- {
-
- case "常量":
- NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
- NrDic.Add(m, NrData[m]);
- break;
- case "SQL":
- string SQL = Nr.Rows[m]["nrd_sql"].ToString();
- DataTable Temp;
-
- if (SQL.IndexOf("{") == 0)
- {
- Temp = (DataTable)dh.ExecuteSql(SQL, "select");
- }
- else
- {
-
- foreach (Match mch in match.Matches(SQL))
- {
- SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
- }
- Temp = (DataTable)dh.ExecuteSql(SQL, "select");
- }
- if (Temp.Rows.Count > 0)
- {
- NrData[m] = Temp.Rows[0][0].ToString();
- NrDic.Add(m, NrData[m]);
- }
- else
- {
- NrData[m] = "";
- NrDic.Add(m, NrData[m]);
- }
- break;
-
- case "流水":
- NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + CustCode + "'").ToString();
- NrDic.Add(m, NrData[m]);
-
- custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
- SerialNumIndex = m;
- SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
- Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
- break;
- default:
- break;
- }
- }
- Prefix = "";
- for (int i = 0; i < NrDic.Count; i++)
- {
-
- if (i != SerialNumIndex)
- {
- Prefix += NrDic[i];
- }
- else
- {
-
- string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
-
- if (maxnum == "")
- {
- dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
- custserialnum = 1;
- }
-
- else
- {
- custserialnum = int.Parse(maxnum);
- }
- break;
- }
- }
-
- int CheckedRowCount = 0;
- string ErrRowIndex = "";
-
- for (int i = 0; i < ProdIoInfDGV.RowCount; i++)
- {
- if (ProdIoInfDGV.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
- {
- CheckedRowCount++;
- List<string> pib_inqty = new List<string>();
- string pd_id = ProdIoInfDGV.Rows[i].Cells["pd_id"].FormattedValue.ToString();
- string pd_prodcode = ProdIoInfDGV.Rows[i].Cells["pd_prodcode"].FormattedValue.ToString();
- string pr_id = ProdIoInfDGV.Rows[i].Cells["pr_id"].FormattedValue.ToString();
- string pd_ordercode = ProdIoInfDGV.Rows[i].Cells["pd_ordercode"].FormattedValue.ToString();
- string pd_pdno = ProdIoInfDGV.Rows[i].Cells["pd_pdno"].FormattedValue.ToString();
- string pd_orderdetno = ProdIoInfDGV.Rows[i].Cells["pd_orderdetno"].FormattedValue.ToString();
-
- int pd_totalqty = int.Parse(ProdIoInfDGV.Rows[i].Cells["pd_totalqty"].FormattedValue.ToString());
-
- int pd_qty = int.Parse(ProdIoInfDGV.Rows[i].Cells["pd_qty"].FormattedValue.ToString());
-
- int pr_zxbzs = int.Parse(ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].FormattedValue.ToString());
-
- int mid_qty;
- try
- {
- mid_qty = int.Parse(ProdIoInfDGV.Rows[i].Cells["mid_qty"].FormattedValue.ToString());
- }
- catch (Exception)
- {
- MessageBox.Show("请检查中盒容量");
- return;
- }
-
- int mid_num = int.Parse(ProdIoInfDGV.Rows[i].Cells["mid_num"].FormattedValue.ToString());
-
- int mid_remain = int.Parse(ProdIoInfDGV.Rows[i].Cells["mid_remain"].FormattedValue.ToString());
- string pib_barcode = dh.getFieldDataByCondition("prodiobarcode", "max(pib_barcode)", "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
-
- ArrayList<string> midcode = new ArrayList<string>();
- ArrayList<string> barcode = new ArrayList<string>();
- ArrayList<string> custbarcode = new ArrayList<string>();
-
- for (int j = 0; j < mid_num; j++)
- {
-
- string mid_code = dh.getFieldDataByCondition("PRODIOBARCODE", "nvl(max(to_number(PIB_OUTBOXCODE1)),0)+" + (j + 1), "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
-
- int count = 0;
- int AddNum = pr_zxbzs;
- if (mid_remain != 0 && j + 1 == mid_num)
- {
-
- count = mid_remain % pr_zxbzs == 0 ? mid_remain / pr_zxbzs : (mid_remain / pr_zxbzs) + 1;
- }
- else
- {
-
- count = mid_qty;
- }
- for (int k = 0; k < count; k++)
- {
-
- barcode.Add(BarcodeMethod1(pd_id, pr_id, pib_barcode));
- custbarcode.Add(BarcodeMethod1(NrDic, SerialNumIndex, SerialNumLength, Radix));
- midcode.Add(mid_code);
- if (mid_remain % pr_zxbzs != 0 && k + 1 == count && j + 1 == mid_num)
- AddNum = mid_remain % pr_zxbzs;
- pib_inqty.Add(AddNum.ToString());
- }
- }
- if (barcode.Count > 0)
- {
-
- sql.Clear();
- sql.Append("insert into prodiobarcode (PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_BARCODE,PIB_CUSTBARCODE,PIB_PDNO,");
- sql.Append("PIB_PDID,PIB_PICLASS,PIB_QTY,PIB_PRODID,PIB_OUTBOXCODE1,PIB_IFPRINT,PIB_IFPICK,PIB_ORDERCODE,PIB_CUSTPO,pib_orderdetno)");
- sql.Append(" values (prodiobarcode_seq.nextval,'" + pd_prodcode + "',sysdate,'" + pi_inoutno.Text + "'," + pi_id + ",:barcode,:custbarcode,'" + pd_pdno + "','" + pd_id + "',");
- sql.Append("'" + pi_class.Text + "',:pib_inqty,'" + pr_id + "',:midcode,0,0,'" + pd_ordercode + "','','" + pd_orderdetno + "')");
- dh.BatchInsert(sql.ToString(), new string[] { "barcode", "custbarcode", "pib_inqty", "midcode" }, barcode.ToArray(), custbarcode.ToArray(), pib_inqty.ToArray(), midcode.ToArray());
-
- dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + custserialnum + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
- }
- else
- {
- ErrRowIndex += (i + 1) + ",";
- }
- }
- }
- if (ErrRowIndex != "")
- {
- MessageBox.Show(ErrRowIndex + "行无可用条码,请检查本次数量");
- return;
- }
- if (CheckedRowCount > 0)
- {
- LoadData();
- MessageBox.Show("生成条码成功!");
- }
- else
- {
- MessageBox.Show("未勾选需要生成的明细!");
- }
-
- string str = "";
- foreach (string ss in NotPass.Values)
- {
- str += ss + "\n";
- }
- if (str != "")
- MessageBox.Show(str);
- }
-
- public string BarcodeMethod1(string pd_id, string pr_id, string pib_barcode)
- {
- if (pib_barcode != "")
- {
- if (FirstCode)
- {
- serialnum = serialnum + 1;
- }
-
- else
- {
- serialnum = int.Parse(pib_barcode.Substring(pib_barcode.Length - 4)) + 1;
- FirstCode = true;
- }
- }
- else
- {
- serialnum = serialnum + 1;
- }
- string serialcode = serialnum.ToString();
- for (int i = serialnum.ToString().Length; i < 4; i++)
- {
- serialcode = "0" + serialcode;
- }
- return pd_id + "-" + pr_id + "-" + serialcode;
- }
-
- public string BarcodeMethod1(Dictionary<int, string> Dic, int Index, int Length, int radix)
- {
- string str = "";
- for (int i = 0; i < Dic.Count; i++)
- {
-
- if (i != Index)
- {
- str += Dic[i];
- }
- else
- {
-
- string serialcode = BaseUtil.DToAny(custserialnum, radix);
- for (int j = serialcode.ToString().Length; j < Length; j++)
- {
- serialcode = "0" + serialcode;
- }
- str += serialcode;
- }
- }
- custserialnum = custserialnum + 1;
- return str;
- }
- private static string lpad(int length, string number)
- {
- while (number.Length < length)
- {
- number = "0" + number;
- }
- number = number.Substring(number.Length - length, length);
- return number;
- }
-
-
-
-
-
- private void ProdIoInfDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
- {
- bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
- if (e.ColumnIndex > 0)
- if (ProdIoInfDGV.Columns[e.ColumnIndex].Name == "pr_zxbzs" || ProdIoInfDGV.Columns[e.ColumnIndex].Name == "pd_qty" || ProdIoInfDGV.Columns[e.ColumnIndex].Name == "mid_qty")
- {
- SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
- e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
- Rectangle border = e.CellBounds;
- border.Width -= 1;
- e.Graphics.DrawRectangle(Pens.White, border);
- e.PaintContent(e.CellBounds);
- e.Handled = true;
- }
- }
-
-
-
-
-
- private void ProdIoInfDGV_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- object pr_zxbzs = ProdIoInfDGV.Rows[e.RowIndex].Cells["pr_zxbzs"].Value;
- object pd_qty = ProdIoInfDGV.Rows[e.RowIndex].Cells["pd_qty"].Value;
- object mid_qty = ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_qty"].Value;
- object pd_totalqty = ProdIoInfDGV.Rows[e.RowIndex].Cells["pd_totalqty"].Value;
- if (pr_zxbzs != null && pd_qty != null && mid_qty != null)
- {
- int 最小包装量 = int.Parse(pr_zxbzs.ToString());
- int 中盘容量 = int.Parse(mid_qty.ToString());
- int 本次数量 = int.Parse(pd_qty.ToString());
- int 总数 = int.Parse(pd_totalqty.ToString());
- if (最小包装量 > 0)
- {
- if (本次数量 > 总数)
- {
- MessageBox.Show("本次数量不能大于总数");
- return;
- }
- if (中盘容量 <= 0 || 最小包装量 <= 0)
- {
- MessageBox.Show("中盘容量和单盘数量必须是正整数");
- return;
- }
-
- int mid_num = 本次数量 / (最小包装量 * 中盘容量);
-
- if (本次数量 % (最小包装量 * 中盘容量) == 0)
- ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_num"].Value = mid_num;
- else
- ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_num"].Value = mid_num + 1;
- ProdIoInfDGV.Rows[e.RowIndex].Cells["mid_remain"].Value = 本次数量 - mid_num * 最小包装量 * 中盘容量;
- }
- }
- }
-
- private void SetMidCapacity_Click(object sender, EventArgs e)
- {
- for (int i = 0; i < ProdIoInfDGV.Rows.Count; i++)
- {
- ProdIoInfDGV.Rows[i].Cells["mid_qty"].Value = MidCapacity.Text;
- if (ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].Value.ToString() != "" && ProdIoInfDGV.Rows[i].Cells["pd_qty"].Value.ToString() != "" && ProdIoInfDGV.Rows[i].Cells["mid_qty"].Value.ToString() != "" && ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].Value.ToString() != "0")
- {
- object pr_zxbzs = ProdIoInfDGV.Rows[i].Cells["pr_zxbzs"].Value;
- object pd_qty = ProdIoInfDGV.Rows[i].Cells["pd_qty"].Value;
- object mid_qty = ProdIoInfDGV.Rows[i].Cells["mid_qty"].Value;
- object pd_totalqty = ProdIoInfDGV.Rows[i].Cells["pd_totalqty"].Value;
- if (pr_zxbzs != null && pd_qty != null && mid_qty != null)
- {
- int 最小包装量 = int.Parse(pr_zxbzs.ToString());
- int 中盘容量 = int.Parse(mid_qty.ToString());
- int 本次数量 = int.Parse(pd_qty.ToString());
- int 总数 = int.Parse(pd_totalqty.ToString());
-
- int mid_num = 本次数量 / (最小包装量 * 中盘容量);
-
- if (本次数量 % (最小包装量 * 中盘容量) == 0)
- ProdIoInfDGV.Rows[i].Cells["mid_num"].Value = mid_num;
- else
- ProdIoInfDGV.Rows[i].Cells["mid_num"].Value = mid_num + 1;
- ProdIoInfDGV.Rows[i].Cells["mid_remain"].Value = 本次数量 - mid_num * 最小包装量 * 中盘容量;
- }
- }
- }
- }
- private void LoadData()
- {
-
- CustCode = dh.getFieldDataByCondition("ProdInOut", "pi_cardcode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString();
-
- NrCode = dh.getFieldDataByCondition("NoRule", "nr_code", "nr_custcode='" + CustCode + "'").ToString();
-
- DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + CustCode + "' order by nrd_detno", "select");
-
- Regex match = new Regex("{\\w+}");
-
- string[] NrData = new string[Nr.Rows.Count];
-
- int SerialNumIndex = 0;
-
- int SerialNumLength = 0;
-
- Dictionary<int, string> NrDic = new Dictionary<int, string>();
- for (int m = 0; m < Nr.Rows.Count; m++)
- {
- switch (Nr.Rows[m]["nrd_type"].ToString())
- {
-
- case "常量":
- NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
- NrDic.Add(m, NrData[m]);
- break;
- case "SQL":
- string SQL = Nr.Rows[m]["nrd_sql"].ToString();
- DataTable Temp;
-
- if (SQL.IndexOf("{") == 0)
- {
- Temp = (DataTable)dh.ExecuteSql(SQL, "select");
- }
- else
- {
-
- foreach (Match mch in match.Matches(SQL))
- {
- SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
- }
- Temp = (DataTable)dh.ExecuteSql(SQL, "select");
- }
- if (Temp.Rows.Count > 0)
- {
- NrData[m] = Temp.Rows[0][0].ToString();
- NrDic.Add(m, NrData[m]);
- }
- else
- {
- NrDic.Add(m, "");
- }
- break;
-
- case "流水":
- NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
- NrDic.Add(m, NrData[m]);
-
- custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
- SerialNumIndex = m;
- SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
- break;
- default:
- break;
- }
- }
-
- Prefix = "";
- for (int i = 0; i < NrDic.Count; i++)
- {
-
- if (i != SerialNumIndex)
- {
- Prefix += NrDic[i];
- }
- else
- {
-
- string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
-
- if (maxnum == "")
- {
- dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
- custserialnum = 1;
- }
-
- else
- {
- custserialnum = int.Parse(maxnum);
- }
- break;
- }
- }
- dt = (DataTable)dh.ExecuteSql("select pi_class,pi_id from prodinout where pi_inoutno='" + pi_inoutno.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- pi_id = dt.Rows[0]["pi_id"].ToString();
- BaseUtil.SetFormValue(this.Controls, dt);
-
- dt = (DataTable)dh.ExecuteSql("select ds_inorout from documentsetup where ds_name='" + pi_class.Text + "'", "select");
- sql.Clear();
- sql.Append("select * from prodiobarcode_view where pd_piid='" + pi_id + "'");
- dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
- BaseUtil.FillDgvWithDataTable(ProdIoInfDGV, dt);
- }
- else
- {
- MessageBox.Show("当前单据不存在");
- pi_inoutno.Text = "";
- }
- }
- private void ResetSerialNum_Click(object sender, EventArgs e)
- {
- dt = (DataTable)dh.ExecuteSql("select pi_class,pi_id from prodinout where pi_inoutno='" + pi_inoutno.Text + "'", "select");
- if (dt.Rows.Count > 0)
- {
- if (NrCode != "")
- {
- dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber=1", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
- MessageBox.Show("流水重置成功");
- }
- else
- MessageBox.Show("当前客户无对应条码规则");
- }
- else
- {
- MessageBox.Show("当前单据不存在");
- pi_inoutno.Text = "";
- }
- }
- }
- }
|