Pārlūkot izejas kodu

添加流水可自定义调整

章政 5 gadi atpakaļ
vecāks
revīzija
5f6e72215b

+ 92 - 0
UAS-出货标签管理(贸易版)/ReSetMaxNum.Designer.cs

@@ -0,0 +1,92 @@
+namespace UAS_LabelMachine
+{
+    partial class ReSetMaxNum
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.pi_inoutno_label = new System.Windows.Forms.Label();
+            this.SingleLabelPrint = new System.Windows.Forms.Button();
+            this.Number = new UAS_LabelMachine.CustomControl.EnterTextBox();
+            this.SuspendLayout();
+            // 
+            // pi_inoutno_label
+            // 
+            this.pi_inoutno_label.AutoSize = true;
+            this.pi_inoutno_label.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.pi_inoutno_label.Location = new System.Drawing.Point(52, 64);
+            this.pi_inoutno_label.Name = "pi_inoutno_label";
+            this.pi_inoutno_label.Size = new System.Drawing.Size(65, 20);
+            this.pi_inoutno_label.TabIndex = 5;
+            this.pi_inoutno_label.Text = "当前流水";
+            // 
+            // SingleLabelPrint
+            // 
+            this.SingleLabelPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+            this.SingleLabelPrint.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.SingleLabelPrint.Location = new System.Drawing.Point(136, 108);
+            this.SingleLabelPrint.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.SingleLabelPrint.Name = "SingleLabelPrint";
+            this.SingleLabelPrint.Size = new System.Drawing.Size(53, 26);
+            this.SingleLabelPrint.TabIndex = 37;
+            this.SingleLabelPrint.Text = "确认";
+            this.SingleLabelPrint.UseVisualStyleBackColor = true;
+            this.SingleLabelPrint.Click += new System.EventHandler(this.SingleLabelPrint_Click);
+            // 
+            // Number
+            // 
+            this.Number.ID = null;
+            this.Number.Location = new System.Drawing.Point(123, 64);
+            this.Number.Name = "Number";
+            this.Number.Size = new System.Drawing.Size(83, 21);
+            this.Number.Str = null;
+            this.Number.Str1 = null;
+            this.Number.Str2 = null;
+            this.Number.TabIndex = 38;
+            // 
+            // ReSetMaxNum
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(320, 163);
+            this.Controls.Add(this.Number);
+            this.Controls.Add(this.SingleLabelPrint);
+            this.Controls.Add(this.pi_inoutno_label);
+            this.Name = "ReSetMaxNum";
+            this.Text = "流水设置";
+            this.Load += new System.EventHandler(this.ReSetMaxNum_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label pi_inoutno_label;
+        private System.Windows.Forms.Button SingleLabelPrint;
+        private CustomControl.EnterTextBox Number;
+    }
+}

+ 142 - 0
UAS-出货标签管理(贸易版)/ReSetMaxNum.cs

@@ -0,0 +1,142 @@
+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;
+
+        public ReSetMaxNum(string iCustCode)
+        {
+            custcode = iCustCode;
+            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(), "'" + this.Number.Text + "'");
+                            }
+                            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("请填写正确的数字");
+            }
+        }
+    }
+}

+ 120 - 0
UAS-出货标签管理(贸易版)/ReSetMaxNum.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 9 - 0
UAS-出货标签管理(贸易版)/UAS-出货标签管理(贸易版).csproj

@@ -270,6 +270,12 @@
     <Compile Include="PublicMethod\LogManager.cs" />
     <Compile Include="PublicMethod\Print.cs" />
     <Compile Include="PublicMethod\SqliteDBHelper.cs" />
+    <Compile Include="ReSetMaxNum.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="ReSetMaxNum.Designer.cs">
+      <DependentUpon>ReSetMaxNum.cs</DependentUpon>
+    </Compile>
     <Compile Include="Service References\Vivo_BoxReelRelation\Reference.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
@@ -361,6 +367,9 @@
     <EmbeddedResource Include="PowerSetting.resx">
       <DependentUpon>PowerSetting.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="ReSetMaxNum.resx">
+      <DependentUpon>ReSetMaxNum.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="SetLoadingWindow.resx">
       <DependentUpon>SetLoadingWindow.cs</DependentUpon>
     </EmbeddedResource>

+ 11 - 2
UAS-出货标签管理(贸易版)/UAS_出货标签管理.Designer.cs

@@ -196,6 +196,7 @@
             this.OutBoxLabelPrint = new System.Windows.Forms.Button();
             this.OutBoxLabelAutoPrint = new System.Windows.Forms.CheckBox();
             this.OutBoxCombox = new System.Windows.Forms.ComboBox();
+            this.流水调整ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             ((System.ComponentModel.ISupportInitialize)(this.Si_ItemDGV)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MidSource)).BeginInit();
             this.Menu.SuspendLayout();
@@ -773,10 +774,11 @@
             this.toolStripMenuItem5,
             this.toolStripMenuItem6,
             this.下载模板ToolStripMenuItem,
-            this.客户合并规则ToolStripMenuItem});
+            this.客户合并规则ToolStripMenuItem,
+            this.流水调整ToolStripMenuItem});
             this.Menu.Name = "Menu";
             this.Menu.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
-            this.Menu.Size = new System.Drawing.Size(149, 180);
+            this.Menu.Size = new System.Drawing.Size(149, 202);
             this.Menu.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.Menu_ItemClicked);
             // 
             // toolStripMenuItem1
@@ -1926,6 +1928,12 @@
             this.OutBoxCombox.TabIndex = 78;
             this.OutBoxCombox.SelectedIndexChanged += new System.EventHandler(this.OutBoxCombox_SelectedIndexChanged);
             // 
+            // 流水调整ToolStripMenuItem
+            // 
+            this.流水调整ToolStripMenuItem.Name = "流水调整ToolStripMenuItem";
+            this.流水调整ToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
+            this.流水调整ToolStripMenuItem.Text = "流水调整";
+            // 
             // UAS_出货标签打印
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -2172,5 +2180,6 @@
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode1;
         private System.Windows.Forms.DataGridViewTextBoxColumn pib_outboxcode2;
         private System.Windows.Forms.Button CustBarCode;
+        private System.Windows.Forms.ToolStripMenuItem 流水调整ToolStripMenuItem;
     }
 }

+ 129 - 92
UAS-出货标签管理(贸易版)/UAS_出货标签管理.cs

@@ -2186,8 +2186,7 @@ namespace UAS_LabelMachine
         {
             Menu.Show(new Point(MenuSetting.Location.X, MenuSetting.Location.Y + 20));
         }
-        //客户的流水号
-        int custserialnum = 0;
+
         private void Menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
         {
             Menu.Close();
@@ -2301,6 +2300,18 @@ namespace UAS_LabelMachine
                     BaseUtil.SetFormCenter(cust);
                     cust.ShowDialog();
                     break;
+                case "流水调整":
+                    if (cu_code.Text != "")
+                    {
+                        ReSetMaxNum reset = new ReSetMaxNum(cu_code.Text);
+                        BaseUtil.SetFormCenter(reset);
+                        reset.ShowDialog();
+                    }
+                    else
+                    {
+                        MessageBox.Show("请先输入出货单号");
+                    }
+                    break;
                 default:
                     break;
             }
@@ -2322,101 +2333,127 @@ namespace UAS_LabelMachine
             return str;
         }
 
+        //前缀
+        string Prefix = "";
+        //后缀
+        string Suffix = "";
+        //编码规则编号
+        string NrCode = "";
+
+        string PrefixFixed = "";
+        //流水号的索引
+        int SerialNumIndex = 0;
+        //流水长度
+        int SerialNumLength = 0;
+        //存放键值对
+        int Radix = 10;
+        //客户的流水号
+        int custserialnum = 0;
+
+        public void GetCustRule()
+        {
+            //前缀
+            Prefix = "";
+            //后缀
+            Suffix = "";
+            //编码规则编号
+            NrCode = "";
+
+            PrefixFixed = "";
+            //流水号的索引
+            SerialNumIndex = 0;
+            //流水长度
+            SerialNumLength = 0;
+            //存放键值对
+            Radix = 10;
+            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");
+            //如果没有则取公共规则
+            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(), "'" + pi_inoutno.Text + "'");
+                            }
+                            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);
+            }
+        }
+
         public void ImportBarcode()
         {
             try
             {
-                string Prefix = "";
-
-                string Suffix = "";
-                //编码规则编号
-                string NrCode = "";
-                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");
-                //如果没有则取公共规则
-                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];
-                //流水号的索引
-                int SerialNumIndex = 0;
-                //流水长度
-                int SerialNumLength = 0;
-                //存放键值对
-                int Radix = 10;
-                string PrefixFixed = "";
-                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(), "'" + pi_inoutno.Text + "'");
-                                }
-                                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;
-                    }
-                }
+                GetCustRule();
                 //获取最大的流水号
-                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);
-                }
+
                 DataTable dt = ExcelHandler.ExcelToDataTable(ImportExcel.FileName, true);
                 if (dt == null)
                 {