123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using UAS_LabelMachine.Entity;
- namespace UAS_LabelMachine
- {
- public partial class ReSetMaxNum : Form
- {
- DataHelper dh = SystemInf.dh;
- string custcode;
- string inoutno;
- public ReSetMaxNum(string iCustCode,string iInoutno)
- {
- custcode = iCustCode;
- inoutno = iInoutno;
- InitializeComponent();
- }
- //前缀
- string Prefix = "";
- //后缀
- string Suffix = "";
- //编码规则编号
- string NrCode = "";
- string PrefixFixed = "";
- //流水号的索引
- int SerialNumIndex = 0;
- //流水长度
- int SerialNumLength = 0;
- //存放键值对
- int Radix = 10;
- //客户的流水号
- int custserialnum = 0;
- private void ReSetMaxNum_Load(object sender, EventArgs e)
- {
- 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='" + custcode + "' 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,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");
- //用于过滤参数的正则表达式
- if (Nr.Rows.Count > 0)
- {
- NrCode = Nr.Rows[0]["nr_code"].ToString();
- }
- Regex match = new Regex("{\\w+}");
- //用于存放每一项的明细的数据
- string[] NrData = new string[Nr.Rows.Count];
- 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();
- Prefix += NrData[m];
- Suffix += 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
- {
- //替换参数后重新执行SQL
- foreach (Match mch in match.Matches(SQL))
- {
- SQL = SQL.Replace(mch.Value.Trim(), "'"+ inoutno + "'");
- }
- Temp = (DataTable)dh.ExecuteSql(SQL, "select");
- }
- if (Temp.Rows.Count > 0)
- {
- NrData[m] = Temp.Rows[0][0].ToString();
- Prefix += NrData[m];
- Suffix += NrData[m];
- }
- else
- {
- NrData[m] = "";
- Prefix += NrData[m];
- Suffix += NrData[m];
- }
- break;
- //流水需要通过MaxNumber去取
- case "流水":
- NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
- Suffix = "";
- PrefixFixed = Prefix;
- //设置当前流水
- 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;
- }
- }
- 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");
- maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
- custserialnum = int.Parse(maxnum);
- }//如果流水号不为空则取当前流水
- else
- {
- custserialnum = int.Parse(maxnum);
- }
- Number.Text = custserialnum.ToString();
- }
- private void SingleLabelPrint_Click(object sender, EventArgs e)
- {
- int num = 0;
- if (int.TryParse(Number.Text, out num))
- {
- dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + num + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
- MessageBox.Show("流水修改成功");
- Close();
- }
- else
- {
- MessageBox.Show("请填写正确的数字");
- }
- }
- }
- }
|