callm 1 год назад
Родитель
Сommit
ce6edd0fae

+ 117 - 0
UAS_BARCODEIO/AutoSizeFormClass.cs

@@ -0,0 +1,117 @@
+using System.Collections.Generic;
+using System.Windows.Forms;
+
+namespace UAS_BARCODEIO
+{
+    class AutoSizeFormClass
+    {
+        //(1).声明结构,只记录窗体和其控件的初始位置和大小。
+        public struct controlRect
+        {
+            public int Left;
+            public int Top;
+            public int Width;
+            public int Height;
+        }
+        //(2).声明 1个对象
+        //注意这里不能使用控件列表记录 List nCtrl;,因为控件的关联性,记录的始终是当前的大小。
+        //      public List oldCtrl= new List();//这里将西文的大于小于号都过滤掉了,只能改为中文的,使用中要改回西文
+        public List<controlRect> oldCtrl = new List<controlRect>();
+        int ctrlNo = 0;//1;
+        //(3). 创建两个函数
+        //(3.1)记录窗体和其控件的初始位置和大小,
+        public void controllInitializeSize(Control mForm)
+        {
+            controlRect cR;
+            cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height;
+            oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可
+            AddControl(mForm);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
+                              //this.WindowState = (FormWindowState)(2);//记录完控件的初始位置和大小后,再最大化
+                              //0 - Normalize , 1 - Minimize,2- Maximize
+
+        }
+
+        private void AddControl(Control ctl)
+        {
+            foreach (Control c in ctl.Controls)
+            {  //**放在这里,是先记录控件的子控件,后记录控件本身
+               //if (c.Controls.Count > 0)
+               //    AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
+                controlRect objCtrl;
+                objCtrl.Left = c.Left; objCtrl.Top = c.Top; objCtrl.Width = c.Width; objCtrl.Height = c.Height;
+                oldCtrl.Add(objCtrl);
+                //**放在这里,是先记录控件本身,后记录控件的子控件
+                if (c.Controls.Count > 0)
+                    AddControl(c);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
+            }
+        }
+        //(3.2)控件自适应大小,
+        public void controlAutoSize(Control mForm)
+        {
+            if (ctrlNo == 0)
+            { //*如果在窗体的Form1_Load中,记录控件原始的大小和位置,正常没有问题,但要加入皮肤就会出现问题,因为有些控件如dataGridView的的子控件还没有完成,个数少
+              //*要在窗体的Form1_SizeChanged中,第一次改变大小时,记录控件原始的大小和位置,这里所有控件的子控件都已经形成
+                controlRect cR;
+                //  cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height;
+                cR.Left = 0; cR.Top = 0; cR.Width = mForm.PreferredSize.Width; cR.Height = mForm.PreferredSize.Height;
+                oldCtrl.Add(cR);//第一个为"窗体本身",只加入一次即可
+                AddControl(mForm);//窗体内其余控件可能嵌套其它控件(比如panel),故单独抽出以便递归调用
+            }
+
+            float wScale = (float)mForm.Width / (float)oldCtrl[0].Width;//新旧窗体之间的比例,与最早的旧窗体
+            float hScale = (float)mForm.Height / (float)oldCtrl[0].Height;//.Height;
+            ctrlNo = 1;//进入=1,第0个为窗体本身,窗体内的控件,从序号1开始
+            AutoScaleControl(mForm, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
+
+        }
+
+        private void AutoScaleControl(Control ctl, float wScale, float hScale)
+        {
+            int ctrLeft0, ctrTop0, ctrWidth0, ctrHeight0;
+            //int ctrlNo = 1;//第1个是窗体自身的 Left,Top,Width,Height,所以窗体控件从ctrlNo=1开始
+            foreach (Control c in ctl.Controls)
+            {
+                //**放在这里,是先缩放控件的子控件,后缩放控件本身
+                //if (c.Controls.Count > 0)
+                //AutoScaleControl(c, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
+                ctrLeft0 = oldCtrl[ctrlNo].Left;
+                ctrTop0 = oldCtrl[ctrlNo].Top;
+                ctrWidth0 = oldCtrl[ctrlNo].Width;
+                ctrHeight0 = oldCtrl[ctrlNo].Height;
+                //c.Left = (int)((ctrLeft0 - wLeft0) * wScale) + wLeft1;//新旧控件之间的线性比例
+                //c.Top = (int)((ctrTop0 - wTop0) * h) + wTop1;
+
+                c.Left = (int)((ctrLeft0) * wScale);//新旧控件之间的线性比例。控件位置只相对于窗体,所以不能加 + wLeft1
+                c.Top = (int)((ctrTop0) * hScale);//
+                //设置指定的类型不进行宽高的变化
+                if (!(c is Button ||c is Pagination))
+                {
+                    c.Width = (int)(ctrWidth0 * wScale);//只与最初的大小相关,所以不能与现在的宽度相乘 (int)(c.Width * w);
+                    c.Height = (int)(ctrHeight0 * hScale);//
+                }
+                ctrlNo++;//累加序号
+                //**放在这里,是先缩放控件本身,后缩放控件的子控件
+                if (c.Controls.Count > 0)
+                {
+                    AutoScaleControl(c, wScale, hScale);//窗体内其余控件还可能嵌套控件(比如panel),要单独抽出,因为要递归调用
+                }
+            }
+            if (ctl is DataGridView)
+            {
+                DataGridView dgv = ctl as DataGridView;
+                Cursor.Current = Cursors.WaitCursor;
+                int widths = 0;
+                for (int i = 0; i < dgv.Columns.Count; i++)
+                {
+                    dgv.AutoResizeColumn(i, DataGridViewAutoSizeColumnMode.AllCells);  // 自动调整列宽  
+                    widths += dgv.Columns[i].Width;   // 计算调整列后单元列的宽度和                       
+                }
+                if (widths >= ctl.Size.Width)  // 如果调整列的宽度大于设定列宽  
+                    dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;  // 调整列的模式 自动  
+                else
+                    dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;  // 如果小于 则填充  
+                Cursor.Current = Cursors.Default;
+            }
+        }
+    }
+}

+ 47 - 0
UAS_BARCODEIO/DataGridViewWithSerialNum.Designer.cs

@@ -0,0 +1,47 @@
+using System.Windows.Forms;
+
+namespace UAS_BARCODEIO
+{
+    partial class DataGridViewWithSerialNum
+    {
+       // private AutoScaleMode AutoScaleMode;
+
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // DataGridViewWithSerialNum
+            // 
+            this.RowTemplate.Height = 23;
+            this.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.DataGridViewWithSerialNum_CellPainting);
+            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
+            this.ResumeLayout(true);
+        }
+        #endregion
+    }
+}

+ 37 - 0
UAS_BARCODEIO/DataGridViewWithSerialNum.cs

@@ -0,0 +1,37 @@
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace UAS_BARCODEIO
+{
+    public partial class DataGridViewWithSerialNum : DataGridView
+    {
+        SolidBrush solidBrush;
+
+        public DataGridViewWithSerialNum()
+        {
+            InitializeComponent();
+            solidBrush = new SolidBrush(RowHeadersDefaultCellStyle.ForeColor);
+        }
+
+        protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
+        {
+            e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, solidBrush, e.RowBounds.Location.X + 5, e.RowBounds.Location.Y);
+            base.OnRowPostPaint(e);
+        }
+
+        private void DataGridViewWithSerialNum_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
+        {
+            //bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
+            //if (e.RowIndex % 2 != 0 || e.ColumnIndex == -1)
+            //{
+            //    solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
+            //    e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightGray, e.CellBounds);
+            //    Rectangle border = e.CellBounds;
+            //    border.Width -= 1;
+            //    e.Graphics.DrawRectangle(Pens.White, border);
+            //    e.PaintContent(e.CellBounds);
+            //    e.Handled = true;
+            //}
+        }
+    }
+}

+ 123 - 0
UAS_BARCODEIO/DataGridViewWithSerialNum.resx

@@ -0,0 +1,123 @@
+<?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>
+  <metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+</root>

+ 1101 - 0
UAS_BARCODEIO/LogicHandler.cs

@@ -0,0 +1,1101 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows;
+using System.Windows.Forms;
+
+
+namespace UAS_BARCODEIO
+{
+    class LogicHandler
+    {
+        public LogicHandler() { }
+
+        static DataHelper dh = SystemInf.dh;
+        //用于拼接SQL
+        static StringBuilder sql = new StringBuilder();
+        //用于存放批量执行的SQL
+        static List<string> sqls = new List<string>();
+        /// <summary>
+        /// 记录复判记录
+        /// </summary>
+        /// <param name="iSN"></param>
+        /// <param name="iMakeCode"></param>
+        /// <param name="iSource"></param>
+        /// <param name="iFileName"></param>
+        /// <param name="iLineCode"></param>
+        /// <param name="iCombine"></param>
+    
+
+        /// <summary>
+        /// 判断工单是否已经下放
+        /// </summary>
+        /// <param name="iMaCode"></param>
+        /// <returns></returns>
+        public static bool CheckMakeStatus(string iMaCode, out string ErrorMessage)
+        {
+            string ma_statuscode = dh.getFieldDataByCondition(" make ", "ma_statuscode", "Lower(ma_code)='" + iMaCode.ToLower() + "' ").ToString();
+            ErrorMessage = "";
+            if (ma_statuscode == "")
+            {
+                ErrorMessage = "工单号" + iMaCode + "不存在";
+                return false;
+            }
+            if (ma_statuscode == "STARTED" || ma_statuscode == "FINISH")
+                return true;
+            else
+            {
+                ErrorMessage = "工单必须是已下放状态";
+                return false;
+            }
+        }
+
+        public static void GetSerialNumByCaller(string iCaller, out string SerialNum)
+        {
+            SerialNum = "";
+            string[] param = new string[] { iCaller, "2", SerialNum };
+            dh.CallProcedure("SP_GETMAXNUMBER", ref param);
+            SerialNum = param[2];
+        }
+
+        /// <summary>
+        /// 验证用户身份信息
+        /// </summary>
+        /// <param name="iUserCode"></param>
+        /// <param name="oErrorMessage"></param>
+        /// <returns></returns>
+        public static bool CheckUserLogin(string iUserCode, string iPassWord, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string SQL = "select em_code from employee where (upper(em_code)=:UserName or em_mobile=:UserName) and em_password =:PassWord";
+            DataTable dt;
+            dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode.ToUpper(), iUserCode.ToUpper(), iPassWord);
+            if (dt.Rows.Count > 0)
+                return true;
+            else
+            {
+                oErrorMessage = "用户名或者密码不正确!";
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 记录登陆信息
+        /// </summary>
+        public static void RecordLogInfo(string iUserCode, string iUserName, string iVersion, string iType, string iIP)
+        {
+            dh.ExecuteSql("insert into LogInfo(id,sip,usname,indate,uscode,versioncode,terminaltype) values (LogInfo_seq.nextval,'" + iIP + "','" + iUserName + "',sysdate,'" + iUserCode + "','" + iVersion + "','" + iType + "')", "insert");
+        }
+
+        /// <summary>
+        /// 验证用户身份信息和岗位资源
+        /// </summary>
+        /// <param name="iUserCode"></param>
+        /// <param name="iPassWord"></param>
+        /// <param name="oErrorMessage"></param>
+        /// <returns></returns>
+        public static bool CheckUserAndResourcePassed(string iUserCode, string iSourceCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            iUserCode = iUserCode.ToUpper();
+            iSourceCode = iSourceCode.ToUpper();
+            string SQL = "select em_code,em_type from employee where upper(em_code)=:UserName or em_mobile=:UserName";
+            DataTable dt;
+            dt = (DataTable)dh.ExecuteSql(SQL, "select", iUserCode, iUserCode);
+            if (dt.Rows.Count > 0)
+            {
+                iUserCode = dt.Rows[0]["em_code"].ToString();
+                string em_type = dt.Rows[0]["em_type"].ToString();
+                if (iSourceCode == "")
+                {
+                    oErrorMessage = "岗位资源不允许为空";
+                    return false;
+                }
+                if (em_type == "admin")
+                {
+                    if (dh.CheckExist("Source", "upper(sc_code)='" + iSourceCode + "' and sc_statuscode='AUDITED'"))
+                    {
+                        return true;
+                    }
+                    else
+                    {
+                        oErrorMessage = "岗位资源编号错误或者未审核!";
+                        return false;
+                    }
+                }
+                else
+                {
+                    dt = dh.getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "upper(ur_resourcecode) ur_resourcecode" }, "upper(eg_emcode)= '" + iUserCode + "' and sc_statuscode='AUDITED'");
+                    //如果存在该编号
+                    if (dt.Rows.Count > 0)
+                    {
+                        //判断如果多个岗位资源存在,用户输入的只要在其中就行
+                        for (int i = 0; i < dt.Rows.Count; i++)
+                        {
+                            if (dt.Rows[i]["ur_resourcecode"].ToString() == iSourceCode)
+                                return true;
+                        }
+                        oErrorMessage = "用户不处于当前资源所属分组!";
+                    }
+                    else
+                        oErrorMessage = "岗位资源编号错误或者未审核!";
+                }
+            }
+            else
+                oErrorMessage = "用户不存在!";
+            return false;
+        }
+
+        public static bool CheckStepAttribute(string iCaller, string iSourceCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iCaller, iSourceCode, oErrorMessage };
+            dh.CallProcedure("CS_CHECKSTEPATTRIBUTE", ref param);
+            oErrorMessage = param[2];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+
+
+        public static void GetQuerySql(string iCondition, out string v_sql, out string v_sql1)
+        {
+            v_sql = "";
+            v_sql1 = "";
+            string[] param = new string[] { iCondition, v_sql, v_sql1 };
+            dh.CallProcedure("GetQuerySQL", ref param);
+            v_sql = param[1];
+            v_sql1 = param[2];
+        }
+
+        public static void DoCommandLog(string iCaller, string iUserCode, string iMakeCode, string iLineCode, string iSourceCode, string iOperate, string iResult, string iSncode, string iCheckno)
+        {
+            sql.Clear();
+            sql.Append("insert into commandlog(cl_id,cl_caller,cl_man,cl_date,cl_linecode,cl_sourcecode,cl_makecode,cl_operate,");
+            sql.Append("cl_result,cl_sncode,cl_code) values( commandlog_seq.nextval,:cl_caller,:iUserCode,sysdate,:iLineCode ,");
+            sql.Append(":iSourceCode ,:iMakeCode,:iOperate,:iResult,:iSncode,:iCheckno)");
+            dh.ExecuteSql(sql.ToString(), "insert", iCaller, iUserCode, iLineCode, iSourceCode, iMakeCode, iOperate, iResult, iSncode, iCheckno);
+        }
+
+      
+
+        /// <summary>
+        /// 获取送检批次,根据不同的iOQCStep执行不同的操作,查询到有具体的信息时返回Form和Detail的两个DataTable
+        ///  iOQCStep 有四个固定参数
+        ///  OQCSENDCHECK 生成送检批
+        ///  OQCPLANMAINTAIN 抽样计划维护
+        ///  OQCDATACOLLECTION 抽样数据采集
+        ///  OQCRESULTDETERMINE 批结果判定
+        /// </summary>
+        /// <returns></returns>
+        public static DataTable[] GetOQCBatch(string iSnCode, string iOutBoxCode, string iCheckNo, string iOQCStep, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string SQL = "";
+            string ms_checkno = "";
+            DataTable dt = new DataTable();
+            if (iCheckNo != "")
+                return GetBatch(iCheckNo, iOQCStep, out oErrorMessage);
+            else if (iSnCode != "")
+            {
+                //如果返工批次为空则获取当前的批次
+                SQL = "select nvl(MS_REWORKCHECKNO,ms_checkno)ms_checkno from makeserial where ms_id=(select max(ms_id) from makeserial where  ms_sncode='" + iSnCode + "' or ms_psn='" + iSnCode + "')";
+                dt = (DataTable)dh.ExecuteSql(SQL, "select");
+                if (dt.Rows.Count == 0)
+                {
+                    oErrorMessage = "序列号" + iSnCode + "不存在";
+                    return null;
+                }
+                else
+                {
+                    if (dt.Rows[0]["ms_checkno"].ToString() == "")
+                    {
+                        oErrorMessage = "该序列号没有送检批次号";
+                        return null;
+                    }
+                    else
+                        ms_checkno = dt.Rows[0]["ms_checkno"].ToString();
+                }
+            }
+            else if (iOutBoxCode != "")
+            {
+                SQL = "select ms_checkno from MES_PACKAGE_VIEW left join makeserial on v_barcode=ms_sncode where  v_outboxcode='" + iOutBoxCode + "' ";
+                dt = (DataTable)dh.ExecuteSql(SQL, "select");
+                if (dt.Rows.Count == 0)
+                {
+                    oErrorMessage = "该箱号不存在";
+                    return null;
+                }
+                else
+                {
+                    if (dt.Rows[0]["ms_checkno"].ToString() == "")
+                    {
+                        oErrorMessage = "该箱号没有送检批次号";
+                        return null;
+                    }
+                    else
+                        ms_checkno = dt.Rows[0]["ms_checkno"].ToString();
+                }
+            }
+            if (ms_checkno != "")
+            {
+                return GetBatch(ms_checkno, iOQCStep, out oErrorMessage);
+            }
+            else
+            {
+                oErrorMessage = "送检批次不存在";
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 第一个是Form的主表信息,第二个是Grid的信息
+        /// </summary>
+        /// <param name="iCheckNo"></param>
+        /// <returns></returns>
+        private static DataTable[] GetBatch(string iCheckNo, string iOQCStep, out string oErrorMessage)
+        {
+            DataTable Form = new DataTable();
+            DataTable Grid = new DataTable();
+            oErrorMessage = "";
+            switch (iOQCStep.ToUpper())
+            {
+                case "OQCSENDCHECK":
+                    sql.Clear();
+                    sql.Append("select obd_outboxcode,obd_id,obd_makecode,obd_sncode from OQCBatchdetail where obd_checkno = '" + iCheckNo + "' order by obd_sncode");
+                    Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    Form = (DataTable)dh.ExecuteSql("select ob_id,ob_status,ob_prodcode,ob_batchqty,ob_source,ob_checkno from OQCBatch where ob_checkno='" + iCheckNo + "'", "select");
+                    if (Form.Rows.Count > 0)
+                    {
+                        if (/*Form.Rows[0]["ob_source"].ToString() == "新增" &&*/ Form.Rows[0]["ob_status"].ToString() == "ENTERING")
+                        {
+                            sql.Clear();
+                            sql.Append("select ob_id,ob_status,ob_prodcode ma_prodcode,ob_batchqty,ob_source,ob_checkno,obd_id,obd_outboxcode,obd_makecode ma_code,count(1) cn from OQCBatch left join OQCBatchdetail ");
+                            sql.Append("on obd_obid = ob_id  where ob_checkno ='" + iCheckNo + "' group by ob_id,ob_status,ob_prodcode,ob_batchqty,ob_source,ob_checkno,obd_outboxcode,obd_makecode,obd_id");
+                            Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                        }
+                        else oErrorMessage = "自动生成的抽检批次号不允许在该页面操作,或者该抽检批次号不是在录入状态";
+                    }
+                    else oErrorMessage = "抽检批次" + iCheckNo + "不存在";
+                    break;
+                case "OQCPLANMAINTAIN":
+                    sql.Clear();
+                    sql.Append("select ob_reworkcode,ob_prodcode,ob_maxngacceptqty,ob_id,ob_checkno,ob_projectcode,ob_nowcheckqty,ob_source,ob_remark,");
+                    sql.Append("ob_status,pr_id,pr_detail,pr_kind,pr_manutype,pr_qualmethod,nvl(ob_aqlcode,pr_aql)ob_aqlcode from OQCBatch left join product on ");
+                    sql.Append("pr_code=ob_prodcode where ob_checkno='" + iCheckNo + "'");
+                    Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    sql.Clear();
+                    if (Form.Rows.Count > 0)
+                    {
+                        string pr_id;
+                        //判断状态是否是待检验
+                        if (Form.Rows[0]["ob_status"].ToString() == "UNCHECK")
+                        {
+                            //判断送检方案是否为空
+                            string qualmethod = "";
+                            //第一原则送检方案为空
+                            if (Form.Rows[0]["pr_qualmethod"].ToString() == "")
+                            {
+                                //判读第二原则送检方案为空
+                                qualmethod = dh.getFieldDataByCondition("product left join productkind on pr_kind=pk_name", "pk_qualmethod", "pr_code='" + Form.Rows[0]["ob_prodcode"] + "'").ToString();
+                            }
+                            //第一原则送检方案不为空
+                            else
+                            {
+                                qualmethod = Form.Rows[0]["pr_qualmethod"].ToString();
+                            }
+                            Form.Rows[0]["ob_projectcode"] = qualmethod;
+                            pr_id = dh.getFieldDataByCondition("QUA_Project", "pr_id", "pr_code = '" + qualmethod + "'").ToString();
+                            sql.Clear();
+                            sql.Append("select  1 choose,nvl(max(oi_id),0)oi_id, ci_kind,nvl(max(oi_sampleqty),0) oi_sampleqty from QUA_PROJECT left join ");
+                            sql.Append(" QUA_ProjectDetail on pd_prid=pr_id  left join QUA_CheckItem on pd_ciid=ci_id ");
+                            sql.Append("left join OQCITEMS on oi_checkno ='" + iCheckNo + "' and oi_projectcode='" + qualmethod + "' ");
+                            sql.Append("and oi_projectcode = pr_code and oi_checkkind = ci_kind where  pr_code='" + qualmethod + "'  group by ci_kind");
+                            Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                        }
+                        else
+                            oErrorMessage = "只有待检验的批次才允许维护抽样计划";
+                    }
+                    else
+                        oErrorMessage = "抽检批次" + iCheckNo + "不存在";
+                    break;
+                case "OQCDATACOLLECTION":
+                    sql.Clear();
+                    sql.Append("select ob_checkno,ob_makecode,ob_prodcode,ob_nowcheckqty,pr_detail,ob_ngqty,ob_okqty,");
+                    sql.Append("ob_remark,ob_makecode,ob_status,ob_projectcode,ob_aqlcode,ob_maxngacceptqty from OQCBatch left join product on ");
+                    sql.Append("pr_code=ob_prodcode left join oqcitems on oi_checkno =ob_checkno and oi_projectcode =ob_projectcode where ob_checkno='" + iCheckNo + "'");
+                    Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    //状态为UNCHECK或者CHECKING并且有抽样计划的才能操作
+                    if (Form.Rows.Count > 0)
+                    {
+                        if (Form.Rows[0]["ob_projectcode"].ToString() == "" || !(Form.Rows[0]["ob_status"].ToString() != "UNCHECK" || Form.Rows[0]["ob_status"].ToString() != "CHECKING"))
+                            oErrorMessage = "状态为未检验或者送检中并且有抽样计划的才能操作";
+                    }
+                    else
+                    {
+                        oErrorMessage = "抽检批次" + iCheckNo + "不存在";
+                    }
+                    break;
+                case "OQCRESULTDETERMINE":
+                    sql.Clear();
+                    sql.Append("select ob_remark Remark,ob_id,ob_aqlcode,ob_makecode,ob_status,ob_prodcode,(select max(oi_checkqty)from OQCItems where oi_checkno='" + iCheckNo + "') oi_checkqty,");
+                    sql.Append("ob_nowcheckqty,nvl(ob_okqty,0) ob_okqty,nvl(ob_ngqty,0) ob_ngqty,ob_maxngacceptqty,ob_source,ob_checkno,ob_result from OQCBatch where ob_checkno='" + iCheckNo + "'");
+                    Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    if (Form.Rows.Count == 0)
+                    {
+                        oErrorMessage = "抽检批次" + iCheckNo + "不存在";
+                    }
+                    break;
+                case "OQCCHECKNOSPLIT":
+                    sql.Clear();
+                    sql.Append("select ob_checkno,ob_makecode,ob_prodcode,ob_nowcheckqty,pr_detail,ob_ngqty,ob_okqty,");
+                    sql.Append("ob_remark,ob_makecode,ob_status,ob_projectcode,ob_aqlcode,ob_maxngacceptqty from OQCBatch left join product on ");
+                    sql.Append("pr_code=ob_prodcode left join oqcitems on oi_checkno =ob_checkno and oi_projectcode =ob_projectcode where ob_checkno='" + iCheckNo + "' and ob_status='UNCHECK'");
+                    Form = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    //状态为UNCHECK或者CHECKING并且有抽样计划的才能操作
+                    if (Form.Rows.Count > 0)
+                    {
+                        sql.Clear();
+                        sql.Append("select obd_outboxcode,obd_builddate,obd_makecode,obd_sncode from oqcbatchdetail where obd_checkno='" + Form.Rows[0]["ob_checkno"].ToString() + "'");
+                        Grid = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    }
+                    else oErrorMessage = "抽检批次" + iCheckNo + "不存在或者状态不处于待检验";
+                    break;
+                default:
+                    break;
+            }
+            return new DataTable[] { Form, Grid };
+        }
+
+        public static bool CartonBoxStepPass(string iMakeCode, string iSourceCode, string iCartonBox, string iUserCode, string iResult, out string oErrorMessage)
+        {
+            DataTable dt = (DataTable)dh.ExecuteSql("select ms_status,V_BARCODE,V_MAKECODE,ms_craftcode,ms_prodcode from mes_package_view left join makeserial on V_MAKECODE=ms_makecode and  v_barcode = ms_sncode where V_OUTBOXCODE='" + iCartonBox + "'", "select");
+            //获取当前资源的工序
+            string stepcode = dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + iSourceCode + "'").ToString();
+            string Prcode = dt.Rows[0]["ms_prodcode"].ToString();
+            string Craftcode = dt.Rows[0]["ms_craftcode"].ToString();
+            string ifoqc = dh.getFieldDataByCondition("craft left join craftdetail on cd_crid=cr_id", "nvl(cd_ifoqc,0) cd_ifoqc", "cr_prodcode='" + Prcode + "' and cr_code='" + Craftcode + "' and cd_stepcode='" + stepcode + "'").ToString();
+            oErrorMessage = "";
+            if (ifoqc == "0")
+            {
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    string ms_status = dt.Rows[i]["ms_status"].ToString();
+                    string sn = dt.Rows[i]["V_BARCODE"].ToString();
+                    string makecode = dt.Rows[i]["V_MAKECODE"].ToString();
+                    if (ms_status != "2")
+                    {
+                        CS_SetResult(makecode, iSourceCode, sn, iUserCode, iResult, out oErrorMessage);
+                    }
+                }
+            }
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
+                return true;
+            else
+                return false;
+        }
+
+        /// <summary>
+        /// 箱号过站的公用方法
+        /// </summary>
+        /// <param name="iOutBoxCode"></param>
+        /// <param name="iSourceCode"></param>
+        /// <param name="iUserCode"></param>
+        /// <param name="iResult"></param>
+        /// <param name="iBoxType"></param>
+        public static bool OutBoxStepPass(string iOutBoxCode, string iMakeCode, string iSourceCode, string iUserCode, string iResult, string iBoxType, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iOutBoxCode, iMakeCode, iSourceCode, iUserCode, iResult, iBoxType, oErrorMessage };
+            dh.CallProcedure("CS_CARTONBOXSTEPRESULT", ref param);
+            oErrorMessage = param[6];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+
+     
+
+        /// <summary>
+        /// 记录操作日志
+        /// </summary>
+        /// <param name="iSnCode"></param>
+        /// <param name="iMakeCode"></param>
+        /// <param name="iMPKind"></param>
+        /// <param name="result"></param>
+        /// <param name="iUserCode"></param>
+        public static void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string result, string iUserCode)
+        {
+            string CurrentStep = "";
+            string LineCode = "";
+            string CurrentStepName = "";
+            GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
+            sql.Clear();
+            sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
+            sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode,mp_snstatus,mp_sncheckno,mp_snoutboxcode)");
+            sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,'" + CurrentStep + "','" + CurrentStepName + "',");
+            sql.Append("ms_craftcode,cr_name,'" + iMPKind + "','" + result + "',sysdate,'" + iUserCode + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
+            sql.Append("ms_status,ms_checkno,ms_outboxcode from make left join makeserial on ms_makecode=ma_code left join step on st_code=ms_stepcode left join craft on ms_craftcode=cr_code and cr_prodcode=ma_prodcode ");
+            sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and st_code='" + CurrentStep + "'");
+            dh.ExecuteSql(sql.ToString(), "insert");
+        }
+
+        /// <summary>
+        /// 校验方法之后的检测
+        /// </summary>
+        /// <param name="iSNMakecode"></param>
+        /// <param name="iMakeCode"></param>
+        /// <param name="iChangeMakeCodeNote"></param>
+        /// <param name="NoteAlready"></param>
+        public static bool CheckDiffMakeCodeAfterStepCheck(string iSN, string iSNMakecode, bool iChangeMakeCodeNote, bool NoteAlready, Control ctl, out string oErrMessage)
+        {
+            oErrMessage = "";
+            if (iChangeMakeCodeNote && !NoteAlready)
+            {
+                if (iSNMakecode != ctl.Text && ctl.Text != "")
+                {
+                    string ChangeMakeCode = System.Windows.Forms.MessageBox.Show("序列号" + iSN + "所属工单不同,是否切换?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
+                    //如果选择不切换赋值当前界面工单
+                    if (ChangeMakeCode == "Yes")
+                    {
+                        ctl.Text = iSNMakecode;
+                    }
+                    else
+                    {
+                        oErrMessage = "请重新采集序列号";
+                    }
+                }
+            }
+            return (oErrMessage == "" || oErrMessage == null);
+        }
+
+        public static bool OQCBatchJudge(string iCheckno, string iSourceCode, string iResult, string iRework, string iUserCode, string iRemark, out string oReworkCode, out string oErrorMessage)
+        {
+            oReworkCode = "";
+            oErrorMessage = "";
+            string[] param = new string[] { iCheckno, iSourceCode, iResult, iRework, iUserCode, iRemark, oReworkCode, oErrorMessage };
+            dh.CallProcedure("CS_OQCRESULTJUDGE", ref param);
+            oReworkCode = param[6];
+            oErrorMessage = param[7];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+
+        public static String GetNextStep(string iCraftCode, string iStepCode, string iPrCode)
+        {
+            sql.Clear();
+            sql.Append("select cd_nextstepcode from craft left join craftdetail on cr_id =cd_crid where ");
+            sql.Append("cr_code='" + iCraftCode + "' and cr_prodcode='" + iPrCode + "' and cd_stepcode='" + iStepCode + "'");
+            DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+            if (dt.Rows.Count > 0)
+            {
+                return dt.Rows[0][0].ToString();
+            }
+            return "";
+        }
+
+        public static bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string StepCode = dh.getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "' and ms_makecode='" + iMakeCode + "'").ToString();
+            string CurrentStep = GetStepCodeBySource(iSourceCode);
+            if (StepCode == CurrentStep)
+            {
+                InsertMakeProcess(iSN, iMakeCode, iSourceCode, iMPKind, iResult, iUserCode);
+                return true;
+            }
+            else
+            {
+                return CS_SetResult(iMakeCode, iSourceCode, iSN, iUserCode, iResult, out oErrorMessage);
+            }
+        }
+
+        public static bool CS_SetResult(string iMakeCode, string iSourceCode, string iSN, string iUserCode, string iResult, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, iResult, oErrorMessage };
+            dh.CallProcedure("CS_SETSTEPRESULT", ref param);
+            oErrorMessage = param[5];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
+                return true;
+            else
+                return false;
+        }
+        /// <summary>
+        /// 设置测试结果
+        /// </summary>
+        /// <param name="iMakeCode"></param>
+        /// <param name="iSourceCode"></param>
+        /// <param name="iSN"></param>
+        /// <param name="iMPKind"></param>
+        /// <param name="iResult"></param>
+        /// <param name="iUserCode"></param>
+        /// <param name="oErrorMessage"></param>
+        /// <returns></returns>
+        public static bool SetTestResult(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
+        {
+            return SetStepFinish(iMakeCode, iSourceCode, iSN, iMPKind, iResult, iUserCode, out oErrorMessage);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns></returns>
+        public static string GetPiInoutCode(string iCaller, string iType)
+        {
+            string Code = "";
+            string[] param = new string[] { iCaller, iType, Code };
+            dh.CallProcedure("SP_GETMAXNUMBER", ref param);
+            return param[2];
+        }
+
+        /// <summary>
+        /// 判断是否扣料工序,执行扣料,执行上料表记录
+        /// </summary>
+        /// <param name="iSnCode"></param>
+        /// <param name="iMakeCode"></param>
+        /// <param name="iUserName"></param>
+        /// <param name="iSourceCode"></param>
+        public static bool SetCollectionFinish(string iSnCode, string iMakeCode, string iUserName, string iSourceCode, out string oErrorMessage)
+        {
+            string StepCode = "";
+            string StepName = "";
+            string LineCode = "";
+            oErrorMessage = "";
+            GetStepCodeAndNameAndLineBySource(iSourceCode, ref StepCode, ref StepName, ref LineCode);
+            if (StepCode == "" && StepName == "")
+            {
+                oErrorMessage = "当前岗位资源找不到对应工序,请先进行维护";
+                return false;
+            }
+            sql.Clear();
+            sql.Append("select nvl(cd_ifreduce,0) cd_ifreduce from craft left join craftdetail on cd_crid=cr_id ");
+            sql.Append("where cr_code=(select ma_craftcode  from makeserial left join make on ma_code = ms_makecode ");
+            sql.Append("where ms_sncode = '" + iSnCode + "' and ms_makecode='" + iMakeCode + "') and cd_stepcode='" + StepCode + "'");
+            DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+            sql.Clear();
+            if (dt.Rows.Count > 0)
+            {
+                string cd_ifreduce = dt.Rows[0][0].ToString();
+                if (cd_ifreduce == "-1")
+                {
+                    sql.Clear();
+                    sql.Append("select dsl_location,dsl_table,max(dsl_baseqty) baseqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and ");
+                    sql.Append("dsl_linecode='" + LineCode + "' and dsl_status=0 and dsl_remainqty>0 and dsl_invalidtime is null group by dsl_location,dsl_table");
+                    dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                    for (int i = 0; i < dt.Rows.Count; i++)
+                    {
+                        sql.Clear();
+                        sql.Append("select dsl_id,dsl_remainqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and dsl_linecode='" + LineCode + "' ");
+                        sql.Append("and dsl_status=0 and dsl_remainqty>0 and dsl_invalidtime is null and rownum<3 order by dsl_id asc ");
+                        DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+                        for (int j = 0; j < dt1.Rows.Count; j++)
+                        {
+                            //外层循环的值dt
+                            double baseqty = (double)dt.Rows[i]["baseqty"];
+                            //内层循环的值dt1
+                            double dsl_remainqty = (double)dt1.Rows[j]["dsl_remainqty"];
+                            string dsl_id = dt1.Rows[j]["dsl_id"].ToString();
+                            if (baseqty > 0)
+                            {
+                                if (dsl_remainqty <= baseqty)
+                                {
+                                    sql.Clear();
+                                    sql.Append("update devsmtlocation set dsl_remainqty=0,dsl_invalidtime =sysdate, dsl_validtime =(case when dsl_validtime ");
+                                    sql.Append("is null then sysdate else  dsl_validtime end),dsl_status=-1 where dsl_id=" + dsl_id);
+                                    dh.ExecuteSql(sql.ToString(), "update");
+                                    baseqty -= dsl_remainqty;
+                                }
+                                else
+                                {
+                                    sql.Clear();
+                                    sql.Append("update devsmtlocation set dsl_remainqty=dsl_remainqty-NVL(dsl_baseqty,0),DSL_INVALIDTIME=(case when");
+                                    sql.Append("dsl_validtime is null then sysdate else dsl_validtime end) where dsl_id=" + dsl_id);
+                                    dh.ExecuteSql(sql.ToString(), "update");
+                                    baseqty = 0;
+                                }
+                            }
+                            else
+                                dh.ExecuteSql("update devsmtlocation set DSL_INVALIDTIME=sysdate where dsl_id=" + dsl_id, "update");
+                        }
+                    }
+                    sql.Clear();
+                    sql.Append("insert into ReduceStepRecord (rsd_id,rsd_macode,rsd_maprodcode,rsd_table,rsd_sncode,rsd_linecode,rsd_sourcecode) select ");
+                    sql.Append("ReduceStepRecord_SEQ.nextval,'" + iMakeCode + "',ma_prodcode,'','" + iSnCode + "','" + LineCode + "','" + iSourceCode + "' ");
+                    sql.Append("from make where ma_code='" + iMakeCode + "'");
+                    dh.ExecuteSql(sql.ToString(), "insert");
+                }
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 执行下料操作
+        /// </summary>
+        /// <param name="iSnCode"></param>
+        /// <param name="iBarCode"></param>
+        /// <param name="iCurrentStep"></param>
+        /// <param name="iUserName"></param>
+        /// <param name="oErrorMessage"></param>
+        /// <returns></returns>
+        public static bool SetMaterialDown(string iSnCode, string iBarCode, string iSourceCode, string iCurrentStep, string iUserName, out string oErrorMessage)
+        {
+            //序列号不为空的时候
+            oErrorMessage = "";
+            DataTable dt;
+            //对序列号进行验证
+            dt = (DataTable)dh.ExecuteSql("select  ms_status,ms_stepcode,ms_nextstepcode  from  makeserial  where  ms_sncode='" + iBarCode + "'", "select");
+            if (dt.Rows.Count > 0)
+            {
+                string ms_status = dt.Rows[0]["ms_status"].ToString();
+                string ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
+                string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
+                if (ms_status == "1" && ms_stepcode != iCurrentStep)
+                    oErrorMessage = "当前工序不是" + iCurrentStep + "";
+                else if (ms_status == "0" && ms_stepcode != iCurrentStep)
+                    oErrorMessage = "当前工序不是" + iCurrentStep + "";
+                else if (ms_status == "2" && ms_nextstepcode != iCurrentStep)
+                    oErrorMessage = "该序列号已经包装";
+                else
+                {
+                    dt = (DataTable)dh.ExecuteSql("select * from craftmaterial where cm_sncode='" + iSnCode + "'", "select");
+                    if (dt.Rows.Count > 0)
+                        oErrorMessage = "请采集需要下料的序列号";
+                    else
+                        oErrorMessage = "该序列号未上料,无需下料";
+                }
+            }
+
+            if (oErrorMessage == "")
+            {
+                dt = (DataTable)dh.ExecuteSql("select cm_id,cm_stepcode,ms_makecode,cm_mccode from craftmaterial left join makeserial on cm_makecode=ms_makecode and cm_sncode=ms_sncode where ms_sncode='" + iSnCode + "' and cm_barcode='" + iBarCode + "'", "select");
+                if (dt.Rows.Count > 0)
+                {
+                    string cm_id = dt.Rows[0]["cm_id"].ToString();
+                    string ms_macode = dt.Rows[0]["ms_makecode"].ToString();
+                    string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
+                    string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
+                    dh.ExecuteSql("delete from Craftmaterial where cm_id=" + cm_id, "delete");
+                    InsertMakeProcess(ms_macode, iSnCode, iSourceCode, "下料操作", "下料成功", iUserName);
+                    int count = dh.getRowCount("craftMaterial", "cm_mccode='" + cm_mccode + "' and cm_stepcode='" + cm_stepcode + "' and cm_sncode='" + iSnCode + "'");
+                    if (count == 0)
+                        dh.UpdateByCondition("makecraftdetail ", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty = mcd_okqty - 1", "mcd_mccode='" + cm_mccode + "' and mcd_stepcode='" + cm_stepcode + "'");
+                }
+                return true;
+            }
+            else
+                return false;
+        }
+
+        /// <summary>
+        /// 获取执行步骤代码,名称和线别
+        /// </summary>
+        /// <param name="Source"></param>
+        /// <param name="StepCode"></param>
+        /// <param name="StepName"></param>
+        /// <param name="LineCode"></param>
+        private static void GetStepCodeAndNameAndLineBySource(string Source, ref string StepCode, ref string StepName, ref string LineCode)
+        {
+            DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
+            if (dt.Rows.Count > 0)
+            {
+                StepCode = dt.Rows[0]["sc_stepcode"].ToString();
+                StepName = dt.Rows[0]["sc_stepname"].ToString();
+                LineCode = dt.Rows[0]["sc_linecode"].ToString();
+            }
+        }
+
+        /// <summary>
+        /// 获取步骤代码和名称
+        /// </summary>
+        /// <param name="Source"></param>
+        /// <param name="StepCode"></param>
+        /// <param name="StepName"></param>
+        private static void GetStepCodeAndNameAndTypAndLineCodeBySource(string Source, ref string StepCode, ref string StepName, ref string ScanType, ref string LineCode)
+        {
+            DataTable dt = dh.getFieldsDataByCondition("source", new string[] { "sc_scantype", "sc_stepcode", "sc_stepname", "sc_linecode" }, "sc_code='" + Source + "'");
+            if (dt.Rows.Count > 0)
+            {
+                StepCode = dt.Rows[0]["sc_stepcode"].ToString();
+                StepName = dt.Rows[0]["sc_stepname"].ToString();
+                ScanType = dt.Rows[0]["sc_scantype"].ToString();
+                LineCode = dt.Rows[0]["sc_linecode"].ToString();
+            }
+        }
+
+        /// <summary>
+        /// 获取步骤代码
+        /// </summary>
+        /// <param name="Source"></param>
+        /// <returns></returns>
+        private static string GetStepCodeBySource(string Source)
+        {
+            return dh.getFieldDataByCondition("source", "sc_stepcode", "sc_code='" + Source + "'").ToString();
+        }
+
+        /// <summary>
+        /// 获取箱号
+        /// </summary>
+        /// <param name="pr_id">物料主表的ID</param>
+        /// <param name="kind">管控类型</param>
+        /// <returns></returns>
+        public static string GetOutBoxCode(string Caller, string iMakeCode, string iProdCode, string iUserCode)
+        {
+            string BoxCode = "";
+            string[] param = new string[] { Caller, iMakeCode, iProdCode, iUserCode, BoxCode };
+            dh.CallProcedure("SP_GETPACKORPALLETCODE", ref param);
+            return param[4];
+        }
+
+        public static string GetOutBoxCode1(string Caller, string iMakeCode, string iProdCode, string iUserCode)
+        {
+            string BoxCode = "";
+            string[] param = new string[] { Caller, iMakeCode, iProdCode, iUserCode, BoxCode };
+            dh.CallProcedure("SP_GETPACKORPALLETCODE_TEST", ref param);
+            return param[4];
+        }
+
+        public static bool CheckSNBeforeLoad(string iMakeCode, string iSN, string iFSonCode, string iSonCode, string iRule, string iPrefix, string iLength, string iIfRepeat, string iChecksalecode, out string ErrMessage)
+        {
+            DataTable dt;
+            ErrMessage = "";
+            switch (iRule)
+            {
+                case "TSN":
+                    dt = (DataTable)dh.ExecuteSql("select ms_id,ms_prodcode,ms_nextmacode,ms_salecode,ms_downstatus from makeserial where ms_sncode='" + iSN + "' and ms_makecode<>'" + iMakeCode + "' and ms_status=2 order by ms_id desc", "select");
+                    if (dt.Rows.Count > 0)
+                    {
+                        if (dt.Rows[0]["ms_downstatus"].ToString() != "0")
+                        {
+                            ErrMessage = "序列号:" + iSN + "已下地,请先取消下地";
+                            return false;
+                        }
+                        if (dt.Rows[0]["ms_nextmacode"].ToString() != "")
+                        {
+                            ErrMessage = "序列号:" + iSN + "已被工单" + dt.Rows[0]["ms_nextmacode"].ToString() + "使用";
+                            return false;
+                        }
+                        if ((dt.Rows[0]["ms_salecode"].ToString() != dh.getFieldDataByCondition("make", "ma_salecode", "ma_code='" + iMakeCode + "'").ToString()) && iChecksalecode != "0")
+                        {
+                            ErrMessage = "序列号对应销售订单与工单不符";
+                            return false;
+                        }
+                        //ms_salecode是否等于工单的SaleCode
+                        if (iSonCode != dt.Rows[0]["ms_prodcode"].ToString())
+                        {
+                            ErrMessage = "序列号对应的物料不是:" + iSonCode;
+                            return false;
+                        }
+                        else
+                        {
+                            return true;
+                        }
+                    }
+                    else ErrMessage = "序列号" + iSN + "不存在";
+                    break;
+                case "BARCODE":
+                    if (iIfRepeat != "-1")
+                    {
+                        //判定条码是否已经上料了
+                        dt = (DataTable)dh.ExecuteSql("select cm_barcode from craftmaterial where cm_barcode='" + iSN + "' and cm_status=0", "select");
+                        if (dt.Rows.Count > 0)
+                        {
+                            ErrMessage = "条码" + iSN + "已经上料";
+                            return false;
+                        }
+                    }
+                    dt = (DataTable)dh.ExecuteSql("select bar_prodcode,bar_code from barcode where bar_code='" + iSN + "'", "select");
+                    if (dt.Rows.Count > 0)
+                    {
+                        string bar_prodcode = dt.Rows[0]["bar_prodcode"].ToString();
+                        if (!iFSonCode.Contains(bar_prodcode))
+                        {
+                            if (!iSonCode.Contains(bar_prodcode))
+                            {
+                                ErrMessage = "用户条码号对应的物料不是:" + iSonCode;
+                            }
+                            else
+                            {
+                                ErrMessage = bar_prodcode;
+                                return true;
+                            }
+                        }
+                        else
+                        {
+                            ErrMessage = bar_prodcode;
+                            return true;
+                        }
+                    }
+                    else ErrMessage = "条码" + iSN + "不存在";
+                    break;
+                case "RULE":
+                    if (iIfRepeat != "-1")
+                    {
+                        dt = (DataTable)dh.ExecuteSql("select cm_barcode from craftmaterial where cm_barcode='" + iSN + "' and cm_status=0", "select");
+                        if (dt.Rows.Count > 0)
+                        {
+                            ErrMessage = "条码" + iSN + "已经上料";
+                            return false;
+                        }
+                    }
+                    int sp_length = int.Parse(iLength != "" ? iLength : "0");
+                    //若有多个,以|分割
+                    string[] pres = iPrefix.Split('|');
+                    bool f = false;
+                    for (int i = 0; i < pres.Length; i++)
+                    {
+                        //表示需要按索引位置来区分
+                        if (pres[i].IndexOf('#') > 0)
+                        {
+                            //索引位置
+                            string index = pres[i].Split('#')[1];
+                            string str = pres[i].Split('#')[0];
+                            if (int.TryParse(index, out int index1))
+                            {
+                                if (iSN.Length > index1)
+                                {
+                                    //先截取长度
+                                    if (pres[i] == "" ? true : iSN.Substring(index1-1).StartsWith(str))
+                                    {
+                                        //满足其中一条即可
+                                        f = true;
+                                        break;
+                                    }
+                                }
+                                else
+                                {
+                                    ErrMessage = "索引位置超出字符串长度";
+                                    return false;
+                                }
+                            }
+                            else
+                            {
+                                ErrMessage = "索引位置填写不正确,必须是整数";
+                                return false;
+                            }
+                        }
+                        if (pres[i] == "" ? true : iSN.StartsWith(pres[i]))
+                        {
+                            //满足其中一条即可
+                            f = true;
+                            break;
+                        }
+                    }
+                    if (f)
+                    {
+                        //进行长度匹配
+                        if (iSN.Length == sp_length || sp_length == 0)
+                        {
+                            return true;
+                        }
+                        else ErrMessage = iSN + "长度不匹配";
+                    }
+                    else ErrMessage = iSN + "前缀不匹配";
+                    break;
+                default:
+                    break;
+            }
+            return false;
+        }
+
+        public static bool Packing(string iSN, string iOutBoxCode, bool iAutoNew, string iType, string iSource, string iUser, string iStandarqty, bool iInOrOut, out string oOutBoxCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            oOutBoxCode = "";
+            string[] param = new string[] { iSN, iOutBoxCode, iAutoNew ? "Y" : "N", iType, iSource, iUser, iStandarqty, iInOrOut ? "OUT" : "IN", oOutBoxCode, oErrorMessage };
+            dh.CallProcedure("CS_PACKCARTON", ref param);
+            oOutBoxCode = param[8];
+            oErrorMessage = param[9];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+
+        public static void RecordProdWeight(string iSN, string iType, float iWeight, string iUnit, string iLineCode, string iPrCode, string iSource, string iUser)
+        {
+            //记录重量
+            sql.Clear();
+            sql.Append("insert into weightlog(wl_id,wl_type,wl_scancode,wl_weight,wl_unit,wl_linecode,");
+            sql.Append("wl_prodcode,wl_sccode,wl_indate,wl_inman) values (weightlog_seq.nextval,:wl_type,:wl_scancode,");
+            sql.Append(":wl_weight,:wl_unit,:wl_linecode,:wl_prodcode,:wl_sccode,sysdate,:wl_inman)");
+            dh.ExecuteSql(sql.ToString(), "insert", iType, iSN, iWeight, iUnit, iLineCode, iPrCode, iSource, iUser);
+        }
+
+
+        public static bool CheckUpdate()
+        {
+            string version = BaseUtil.GetCacheData("Version").ToString();
+            DataHelper dh = new DataHelper();
+            string LastVersion = dh.getFieldDataByCondition("configs", "code", "caller='CSUPDATE'").ToString();
+            if (version == LastVersion || version == "" || LastVersion == "")
+            {
+                return false;
+            }
+            else
+            {
+                BaseUtil.SetCacheData("Version", LastVersion);
+                return true;
+            }
+        }
+
+        /// <summary>
+        /// 小箱装大箱的包装规则判断
+        /// </summary>
+        /// <param name="packrule"></param>
+        /// <param name="pa_outboxcode"></param>
+        /// <param name="outboxcode"></param>
+        /// <param name="pa_makecode"></param>
+        /// <param name="pa_salecode"></param>
+        /// <param name="pa_prodcode"></param>
+        /// <param name="error"></param>
+        /// <returns></returns>
+        public static Boolean CheckPackRule(string packrule, string pa_outboxcode, string outboxcode, string pa_makecode, string pa_salecode, string pa_prodcode, string type, out string error)
+        {
+            //按工单核对装箱
+            switch (packrule.ToUpper())
+            {
+                case "MAKE":
+                    string makecode = dh.getFieldDataByCondition("package", "pa_makecode", "pa_outboxcode='" + outboxcode + "'").ToString();
+                    if (makecode != pa_makecode && pa_makecode != "")
+                    {
+                        error = ">>当前箱" + outboxcode + "对应工单号" + makecode + "和所装" + type + "号" + pa_outboxcode + "对应工单" + pa_makecode + "不相等";
+                        return false;
+                    }
+                    break;
+                case "SALE":
+                    if (dh.CheckExist("package", "pa_outboxcode='" + pa_outboxcode + "'"))
+                    {
+                        string salecode = dh.getFieldDataByCondition("package", "pa_salecode", "pa_outboxcode = '" + outboxcode + "'").ToString();
+                        if (salecode != pa_salecode)
+                        {
+                            error = ">>当前箱" + outboxcode + "对应订单号" + salecode + "和所装" + type + "号" + pa_outboxcode + "对应订单" + pa_salecode + "不相等";
+                            return false;
+                        }
+                    }
+                    break;
+                case "PROD":
+                    string prodcode = dh.getFieldDataByCondition("package", "pa_prodcode", "pa_outboxcode='" + outboxcode + "'").ToString();
+                    if (prodcode != pa_prodcode)
+                    {
+                        error = ">>当前箱" + outboxcode + "对应物料" + prodcode + "和所装" + type + "号" + pa_outboxcode + "对应物料" + pa_prodcode + "不相等";
+                        return false;
+                    }
+                    break;
+                case "MIX":
+                    break;
+                default:
+                    prodcode = dh.getFieldDataByCondition("package", "pa_prodcode", "pa_outboxcode='" + outboxcode + "'").ToString();
+                    error = ">>当前箱" + outboxcode + "对应物料" + prodcode + "没有维护装箱规则";
+                    return false;
+                    break;
+            }
+            error = "";
+            return true;
+        }
+        /// <summary>
+        /// 验证是否符合合同防呆
+        /// </summary>
+        /// <param name="msid"></param>
+        /// <param name="macOrBt"></param>
+        /// <param name="type"></param>
+        /// <returns></returns>
+        public static Boolean checkMacOrBtRange(string msid, string macOrBt, string type)
+        {
+            //--判断是否有合同,是否在合同定义的范围内
+            string saleCode = dh.getFieldDataByCondition("makeserial", "ms_salecode", "ms_id='" + msid + "'").ToString();
+            if (saleCode == "")
+            {
+                return true;
+            }
+            //判断是否有合同范围
+            if (dh.CheckExist("SaleMacBTRange", "Sr_Sacode = '" + saleCode + "' and sr_type = '" + type + "'"))
+            {
+                //有合同范围再判断是否在范围内
+                if (!dh.CheckExist("SaleMacBTRange", "Sr_Sacode = '" + saleCode + "' and sr_type = '" + type + "' and '" + macOrBt + "' between SR_STARTCODE and SR_ENDCODE"))
+                {
+                    return false;
+                }
+            }
+            return true;
+        }
+        /// <summary>
+        /// 序列烧录转换
+        /// </summary>
+        /// <param name="iTSN"></param>
+        /// <param name="iSN"></param>
+        /// <param name="iSourcecode"></param>
+        /// <param name="iUsercode"></param>
+        /// <param name="iMacode"></param>
+        /// <param name="iifrechange"></param>
+        /// <param name="iMEI1"></param>
+        /// <param name="iMEI2"></param>
+        /// <param name="iMEI3"></param>
+        /// <param name="iMEID"></param>
+        /// <param name="iNETCODE"></param>
+        /// <param name="iPSN"></param>
+        /// <param name="iID1"></param>
+        /// <param name="iID2"></param>
+        /// <param name="iID3"></param>
+        /// <param name="iMAC"></param>
+        /// <param name="iBT"></param>
+        /// <param name="iCODE1"></param>
+        /// <param name="iCODE2"></param>
+        /// <param name="iCODE3"></param>
+        /// <param name="oErrorMessage"></param>
+        /// <returns></returns>
+        public static bool snChangeAndBurn(string iTSN, string iSN, string iSourcecode, string iUsercode, string iMacode, int iifrechange, string iMEI1, string iMEI2, string iMEI3, string iMEID, string iNETCODE, string iPSN, string iID1, string iID2, string iID3, string iMAC, string iBT, string iCODE1, string iCODE2, string iCODE3, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iTSN, iSN, iSourcecode, iUsercode, iMacode, iifrechange + "", iMEI1, iMEI2, iMEI3, iMEID, iNETCODE, iPSN, iID1, iID2, iID3, iMAC, iBT, iCODE1, iCODE2, iCODE3, oErrorMessage };
+            dh.CallProcedure("CS_SNCHANGEANDBURN", ref param);
+            oErrorMessage = param[20];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
+                return true;
+            else
+                return false;
+        }
+
+        public static bool snBurn(string iTSN, string iSN, string iSourcecode, string iUsercode, string iMacode, int iifrechange, string iMEI1, string iMEI2, string iMEI3, string iMEID, string iNETCODE, string iPSN, string iID1, string iID2, string iID3, string iMAC, string iBT, string iCODE1, string iCODE2, string iCODE3, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iTSN, iSN, iSourcecode, iUsercode, iMacode, iifrechange + "", iMEI1, iMEI2, iMEI3, iMEID, iNETCODE, iPSN, iID1, iID2, iID3, iMAC, iBT, iCODE1, iCODE2, iCODE3, oErrorMessage };
+            dh.CallProcedure("CS_SNBURN", ref param);
+            oErrorMessage = param[20];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null" || oErrorMessage.Contains("AFTERSUCCESS"))
+                return true;
+            else
+                return false;
+        }
+        /// <summary>
+        /// 记录打印
+        /// </summary>
+        /// <param name="printValue"></param>
+        /// <param name="printType"></param>
+        /// <param name="MakeCode"></param>
+        /// <param name="prodCode"></param>
+        /// <param name="sourceCode"></param>
+        /// <param name="stepcode"></param>
+        /// <param name="ifRePrint"></param>
+        /// <param name="userCode"></param>
+        public static void doLabelPrintLog(string printValue, string printType, string MakeCode, string prodCode, string sourceCode, string stepcode, string ifRePrint, string userCode)
+        {
+            sql.Clear();
+            sql.Append("insert into labelprintlog(LPL_ID,LPL_VALUE,LPL_TYPE,LPL_MAKECODE,LPL_PRODCODE,LPL_SOURCECODE,LPL_STEPCODE,LPL_IFREPRINT,LPL_INDATE,LPL_INMAN) ");
+            sql.Append("values( labelprintlog_seq.nextval,:lpl_value,:lpl_type,:makecode,:prodcode,");
+            sql.Append(":SourceCode,:stepcode,:ifreprint,sysdate,:inman)");
+            dh.ExecuteSql(sql.ToString(), "insert", printValue, printType, MakeCode, prodCode, sourceCode, stepcode, ifRePrint, userCode);
+        }
+
+    }
+}

+ 28 - 39
UAS_BARCODEIO/Program.cs

@@ -1,7 +1,9 @@
 using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Principal;
 using System.Text;
 using System.Windows.Forms;
-using System.Security.Principal;
 
 namespace UAS_BARCODEIO
 {
@@ -13,46 +15,33 @@ namespace UAS_BARCODEIO
         [STAThread]
         static void Main()
         {
-            try
+            WindowsIdentity identity = WindowsIdentity.GetCurrent();
+            WindowsPrincipal principal = new WindowsPrincipal(identity);
+
+            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+            //处理UI线程异常
+            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
+            //处理非UI线程异常
+            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            //如果是管理员的身份
+            if (principal.IsInRole(WindowsBuiltInRole.Administrator))
             {
-                WindowsIdentity identity = WindowsIdentity.GetCurrent();
-                WindowsPrincipal principal = new WindowsPrincipal(identity);
-                //设置应用程序处理异常方式:ThreadException处理
-                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
-                //处理UI线程异常
-                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
-                //处理非UI线程异常
-                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
-                #region 应用程序的主入口点
-                Application.EnableVisualStyles();
-                Application.SetCompatibleTextRenderingDefault(false);
-                //启用异常记录日志的操作
-                GlobalEventsHandler g = new GlobalEventsHandler();
-                //添加全局事件的监听
-                Application.AddMessageFilter(g);
-                //如果是管理员的身份
-                if (principal.IsInRole(WindowsBuiltInRole.Administrator))
-                {
-                    Application.Run(new 入库条码规则解析());
-                }
-                else
-                {
-                    //创建启动对象 
-                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
-                    // 设置运行文件
-                    startInfo.FileName = Application.ExecutablePath;
-                    //设置启动动作,确保以管理员身份运行
-                    startInfo.Verb = "runas";
-                    //如果不是管理员,则启动UAC 
-                    System.Diagnostics.Process.Start(startInfo);
-                    //退出 System.Windows.Forms.Application.Exit(); 
-                }
-                #endregion
+                Application.Run(new 入库条码规则解析());
             }
-            catch (Exception ex)
+            else
             {
-                string str = GetExceptionMsg(ex, string.Empty);
-                MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
+                //创建启动对象 
+                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
+                // 设置运行文件
+                startInfo.FileName = Application.ExecutablePath;
+                //设置启动动作,确保以管理员身份运行
+                startInfo.Verb = "runas";
+                //如果不是管理员,则启动UAC 
+                System.Diagnostics.Process.Start(startInfo);
+                //退出 System.Windows.Forms.Application.Exit(); 
             }
         }
 
@@ -86,4 +75,4 @@ namespace UAS_BARCODEIO
             return sb.ToString();
         }
     }
-}
+}

+ 15 - 0
UAS_BARCODEIO/UAS_BARCODEIO.csproj

@@ -77,6 +77,10 @@
     <Reference Include="Oracle.ManagedDataAccess">
       <HintPath>tool\Oracle.ManagedDataAccess.dll</HintPath>
     </Reference>
+    <Reference Include="Seagull.BarTender.Print, Version=10.1.4.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7, processorArchitecture=x86">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>tool\Seagull.BarTender.Print.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -89,6 +93,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="AutoSizeFormClass.cs" />
     <Compile Include="BaseForm.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -102,6 +107,12 @@
     <Compile Include="ClickPicBox.Designer.cs">
       <DependentUpon>ClickPicBox.cs</DependentUpon>
     </Compile>
+    <Compile Include="DataGridViewWithSerialNum.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="DataGridViewWithSerialNum.Designer.cs">
+      <DependentUpon>DataGridViewWithSerialNum.cs</DependentUpon>
+    </Compile>
     <Compile Include="DataHelper.cs" />
     <Compile Include="DbFind.cs">
       <SubType>Form</SubType>
@@ -123,6 +134,7 @@
     <Compile Include="LockCheckBox.Designer.cs">
       <DependentUpon>LockCheckBox.cs</DependentUpon>
     </Compile>
+    <Compile Include="LogicHandler.cs" />
     <Compile Include="MaCodeSearchTextBox.cs">
       <SubType>UserControl</SubType>
     </Compile>
@@ -169,6 +181,9 @@
     <EmbeddedResource Include="ClickPicBox.resx">
       <DependentUpon>ClickPicBox.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="DataGridViewWithSerialNum.resx">
+      <DependentUpon>DataGridViewWithSerialNum.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="DbFind.resx">
       <DependentUpon>DbFind.cs</DependentUpon>
     </EmbeddedResource>

BIN
UAS_BARCODEIO/tool/Seagull.BarTender.Print.dll


+ 117 - 72
UAS_BARCODEIO/入库条码规则解析.Designer.cs

@@ -45,18 +45,21 @@
             this.label5 = new System.Windows.Forms.Label();
             this.LOTNO = new System.Windows.Forms.TextBox();
             this.label6 = new System.Windows.Forms.Label();
-            this.dataGridView1 = new System.Windows.Forms.DataGridView();
-            this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.ZXBZ = new System.Windows.Forms.TextBox();
             this.label7 = new System.Windows.Forms.Label();
             this.Barcode = new System.Windows.Forms.TextBox();
             this.label8 = new System.Windows.Forms.Label();
+            this.GenBarCode = new System.Windows.Forms.Button();
             this.es_custcode = new UAS_BARCODEIO.SearchTextBox();
+            this.BarcodeIO = new System.Windows.Forms.DataGridView();
+            this.PrintBarCode = new System.Windows.Forms.Button();
+            this.CheckBox = new System.Windows.Forms.DataGridViewCheckBoxColumn();
+            this.bi_barcode = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.bi_inqty1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.bi_vendbarcode = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.bi_madedate = new System.Windows.Forms.DataGridViewTextBoxColumn();
             ((System.ComponentModel.ISupportInitialize)(this.Prodiodetail)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.BarcodeIO)).BeginInit();
             this.SuspendLayout();
             // 
             // label2
@@ -100,13 +103,14 @@
             this.pr_spec,
             this.pd_inqty,
             this.bi_inqty});
-            this.Prodiodetail.Enabled = false;
             this.Prodiodetail.Location = new System.Drawing.Point(27, 182);
             this.Prodiodetail.Name = "Prodiodetail";
             this.Prodiodetail.RowHeadersWidth = 82;
             this.Prodiodetail.RowTemplate.Height = 37;
-            this.Prodiodetail.Size = new System.Drawing.Size(1089, 543);
+            this.Prodiodetail.Size = new System.Drawing.Size(1232, 543);
             this.Prodiodetail.TabIndex = 19;
+            this.Prodiodetail.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.Prodiodetail_CellPainting);
+            this.Prodiodetail.SelectionChanged += new System.EventHandler(this.Prodiodetail_SelectionChanged);
             // 
             // pd_prodcode
             // 
@@ -114,6 +118,7 @@
             this.pd_prodcode.HeaderText = "物料编号";
             this.pd_prodcode.MinimumWidth = 10;
             this.pd_prodcode.Name = "pd_prodcode";
+            this.pd_prodcode.ReadOnly = true;
             this.pd_prodcode.Width = 200;
             // 
             // pr_detail
@@ -122,6 +127,7 @@
             this.pr_detail.HeaderText = "物料名称";
             this.pr_detail.MinimumWidth = 10;
             this.pr_detail.Name = "pr_detail";
+            this.pr_detail.ReadOnly = true;
             this.pr_detail.Width = 200;
             // 
             // pr_spec
@@ -130,6 +136,7 @@
             this.pr_spec.HeaderText = "物料规格";
             this.pr_spec.MinimumWidth = 10;
             this.pr_spec.Name = "pr_spec";
+            this.pr_spec.ReadOnly = true;
             this.pr_spec.Width = 200;
             // 
             // pd_inqty
@@ -138,6 +145,7 @@
             this.pd_inqty.HeaderText = "入库数量";
             this.pd_inqty.MinimumWidth = 10;
             this.pd_inqty.Name = "pd_inqty";
+            this.pd_inqty.ReadOnly = true;
             this.pd_inqty.Width = 200;
             // 
             // bi_inqty
@@ -146,6 +154,7 @@
             this.bi_inqty.HeaderText = "已生成条码数量";
             this.bi_inqty.MinimumWidth = 10;
             this.bi_inqty.Name = "bi_inqty";
+            this.bi_inqty.ReadOnly = true;
             this.bi_inqty.Width = 200;
             // 
             // PR_CODE
@@ -224,55 +233,6 @@
             this.label6.TabIndex = 26;
             this.label6.Text = "LotNo";
             // 
-            // dataGridView1
-            // 
-            this.dataGridView1.AllowUserToAddRows = false;
-            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
-            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
-            this.dataGridViewTextBoxColumn1,
-            this.dataGridViewTextBoxColumn2,
-            this.dataGridViewTextBoxColumn3,
-            this.dataGridViewTextBoxColumn4});
-            this.dataGridView1.Enabled = false;
-            this.dataGridView1.Location = new System.Drawing.Point(1145, 182);
-            this.dataGridView1.Name = "dataGridView1";
-            this.dataGridView1.RowHeadersWidth = 82;
-            this.dataGridView1.RowTemplate.Height = 37;
-            this.dataGridView1.Size = new System.Drawing.Size(844, 543);
-            this.dataGridView1.TabIndex = 28;
-            // 
-            // dataGridViewTextBoxColumn1
-            // 
-            this.dataGridViewTextBoxColumn1.DataPropertyName = "bi_barcode";
-            this.dataGridViewTextBoxColumn1.HeaderText = "条码号";
-            this.dataGridViewTextBoxColumn1.MinimumWidth = 10;
-            this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
-            this.dataGridViewTextBoxColumn1.Width = 200;
-            // 
-            // dataGridViewTextBoxColumn2
-            // 
-            this.dataGridViewTextBoxColumn2.DataPropertyName = "bi_inqty";
-            this.dataGridViewTextBoxColumn2.HeaderText = "入库数量";
-            this.dataGridViewTextBoxColumn2.MinimumWidth = 10;
-            this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
-            this.dataGridViewTextBoxColumn2.Width = 200;
-            // 
-            // dataGridViewTextBoxColumn3
-            // 
-            this.dataGridViewTextBoxColumn3.DataPropertyName = "bi_madedate";
-            this.dataGridViewTextBoxColumn3.HeaderText = "DC";
-            this.dataGridViewTextBoxColumn3.MinimumWidth = 10;
-            this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
-            this.dataGridViewTextBoxColumn3.Width = 200;
-            // 
-            // dataGridViewTextBoxColumn4
-            // 
-            this.dataGridViewTextBoxColumn4.DataPropertyName = "bi_vendbarcode";
-            this.dataGridViewTextBoxColumn4.HeaderText = "LotNo";
-            this.dataGridViewTextBoxColumn4.MinimumWidth = 10;
-            this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
-            this.dataGridViewTextBoxColumn4.Width = 200;
-            // 
             // ZXBZ
             // 
             this.ZXBZ.Location = new System.Drawing.Point(168, 1097);
@@ -294,7 +254,7 @@
             // 
             // Barcode
             // 
-            this.Barcode.Location = new System.Drawing.Point(844, 108);
+            this.Barcode.Location = new System.Drawing.Point(823, 114);
             this.Barcode.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.Barcode.Name = "Barcode";
             this.Barcode.Size = new System.Drawing.Size(436, 35);
@@ -305,13 +265,23 @@
             // 
             this.label8.AutoSize = true;
             this.label8.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label8.Location = new System.Drawing.Point(712, 111);
+            this.label8.Location = new System.Drawing.Point(691, 111);
             this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label8.Name = "label8";
             this.label8.Size = new System.Drawing.Size(104, 38);
             this.label8.TabIndex = 33;
             this.label8.Text = "扫码框";
             // 
+            // GenBarCode
+            // 
+            this.GenBarCode.Location = new System.Drawing.Point(673, 768);
+            this.GenBarCode.Name = "GenBarCode";
+            this.GenBarCode.Size = new System.Drawing.Size(169, 45);
+            this.GenBarCode.TabIndex = 34;
+            this.GenBarCode.Text = "生成条码";
+            this.GenBarCode.UseVisualStyleBackColor = true;
+            this.GenBarCode.Click += new System.EventHandler(this.GenBarCode_Click);
+            // 
             // es_custcode
             // 
             this.es_custcode.AllPower = null;
@@ -330,17 +300,87 @@
             this.es_custcode.TableName = null;
             this.es_custcode.TextBoxEnable = false;
             // 
+            // BarcodeIO
+            // 
+            this.BarcodeIO.AllowUserToAddRows = false;
+            this.BarcodeIO.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.BarcodeIO.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.BarcodeIO.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+            this.CheckBox,
+            this.bi_barcode,
+            this.bi_inqty1,
+            this.bi_vendbarcode,
+            this.bi_madedate});
+            this.BarcodeIO.Location = new System.Drawing.Point(1295, 182);
+            this.BarcodeIO.Name = "BarcodeIO";
+            this.BarcodeIO.RowHeadersWidth = 82;
+            this.BarcodeIO.RowTemplate.Height = 23;
+            this.BarcodeIO.Size = new System.Drawing.Size(750, 543);
+            this.BarcodeIO.TabIndex = 35;
+            // 
+            // PrintBarCode
+            // 
+            this.PrintBarCode.Location = new System.Drawing.Point(889, 768);
+            this.PrintBarCode.Name = "PrintBarCode";
+            this.PrintBarCode.Size = new System.Drawing.Size(169, 45);
+            this.PrintBarCode.TabIndex = 36;
+            this.PrintBarCode.Text = "打印条码";
+            this.PrintBarCode.UseVisualStyleBackColor = true;
+            this.PrintBarCode.Click += new System.EventHandler(this.PrintBarCode_Click);
+            // 
+            // CheckBox
+            // 
+            this.CheckBox.DataPropertyName = "CheckBox";
+            this.CheckBox.HeaderText = "勾选";
+            this.CheckBox.MinimumWidth = 10;
+            this.CheckBox.Name = "CheckBox";
+            // 
+            // bi_barcode
+            // 
+            this.bi_barcode.DataPropertyName = "bi_barcode";
+            this.bi_barcode.HeaderText = "条码号";
+            this.bi_barcode.MinimumWidth = 10;
+            this.bi_barcode.Name = "bi_barcode";
+            this.bi_barcode.Width = 200;
+            // 
+            // bi_inqty1
+            // 
+            this.bi_inqty1.DataPropertyName = "bi_inqty";
+            this.bi_inqty1.HeaderText = "入库数量";
+            this.bi_inqty1.MinimumWidth = 10;
+            this.bi_inqty1.Name = "bi_inqty1";
+            this.bi_inqty1.Width = 200;
+            // 
+            // bi_vendbarcode
+            // 
+            this.bi_vendbarcode.DataPropertyName = "bi_vendbarcode";
+            this.bi_vendbarcode.HeaderText = "LOTNO";
+            this.bi_vendbarcode.MinimumWidth = 10;
+            this.bi_vendbarcode.Name = "bi_vendbarcode";
+            this.bi_vendbarcode.Width = 200;
+            // 
+            // bi_madedate
+            // 
+            this.bi_madedate.DataPropertyName = "bi_madedate";
+            this.bi_madedate.HeaderText = "DC";
+            this.bi_madedate.MinimumWidth = 10;
+            this.bi_madedate.Name = "bi_madedate";
+            this.bi_madedate.Width = 200;
+            // 
             // 入库条码规则解析
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(2025, 1225);
+            this.ClientSize = new System.Drawing.Size(2136, 1225);
+            this.Controls.Add(this.PrintBarCode);
+            this.Controls.Add(this.BarcodeIO);
+            this.Controls.Add(this.GenBarCode);
             this.Controls.Add(this.label8);
             this.Controls.Add(this.Barcode);
             this.Controls.Add(this.es_custcode);
             this.Controls.Add(this.ZXBZ);
             this.Controls.Add(this.label7);
-            this.Controls.Add(this.dataGridView1);
             this.Controls.Add(this.LOTNO);
             this.Controls.Add(this.label6);
             this.Controls.Add(this.DC);
@@ -357,9 +397,11 @@
             this.Name = "入库条码规则解析";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "入库条码打印";
+            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
+            this.AutoSizeChanged += new System.EventHandler(this.入库条码规则解析_AutoSizeChanged);
             this.Load += new System.EventHandler(this.Form1_Load);
             ((System.ComponentModel.ISupportInitialize)(this.Prodiodetail)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.BarcodeIO)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -370,11 +412,6 @@
         private System.Windows.Forms.TextBox pi_inoutno;
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.DataGridView Prodiodetail;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_prodcode;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pr_detail;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pr_spec;
-        private System.Windows.Forms.DataGridViewTextBoxColumn pd_inqty;
-        private System.Windows.Forms.DataGridViewTextBoxColumn bi_inqty;
         private System.Windows.Forms.TextBox PR_CODE;
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.TextBox INQTY;
@@ -383,16 +420,24 @@
         private System.Windows.Forms.Label label5;
         private System.Windows.Forms.TextBox LOTNO;
         private System.Windows.Forms.Label label6;
-        private System.Windows.Forms.DataGridView dataGridView1;
-        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
-        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
-        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
-        private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
         private System.Windows.Forms.TextBox ZXBZ;
         private System.Windows.Forms.Label label7;
         private SearchTextBox es_custcode;
         private System.Windows.Forms.TextBox Barcode;
         private System.Windows.Forms.Label label8;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_prodcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pr_detail;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pr_spec;
+        private System.Windows.Forms.DataGridViewTextBoxColumn pd_inqty;
+        private System.Windows.Forms.DataGridViewTextBoxColumn bi_inqty;
+        private System.Windows.Forms.Button GenBarCode;
+        private System.Windows.Forms.DataGridView BarcodeIO;
+        private System.Windows.Forms.Button PrintBarCode;
+        private System.Windows.Forms.DataGridViewCheckBoxColumn CheckBox;
+        private System.Windows.Forms.DataGridViewTextBoxColumn bi_barcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn bi_inqty1;
+        private System.Windows.Forms.DataGridViewTextBoxColumn bi_vendbarcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn bi_madedate;
     }
 }
 

+ 181 - 6
UAS_BARCODEIO/入库条码规则解析.cs

@@ -1,5 +1,8 @@
-using System;
+using Seagull.BarTender.Print;
+using System;
+using System.Collections.Generic;
 using System.Data;
+using System.Drawing;
 using System.Windows.Forms;
 
 namespace UAS_BARCODEIO
@@ -11,11 +14,36 @@ namespace UAS_BARCODEIO
 
         DataTable Dbfind;
 
+        //自适应屏幕
+        AutoSizeFormClass asc = new AutoSizeFormClass();
+
+        Engine engine = new Engine();
+
         public 入库条码规则解析()
         {
             InitializeComponent();
         }
 
+        delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
+
+        void bindingsource(DataGridView dgv, DataTable dt)
+        {
+            //dgv.AutoGenerateColumns = false;
+            //dgv.DataSource = null;
+            //dgv.DataSource = dt;
+            if (dgv.InvokeRequired)
+            {
+                dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
+            }
+            else
+            {
+                dgv.AutoGenerateColumns = false;
+                dgv.DataSource = dt;
+            }
+        }
+
+        static LabelFormatDocument format;
+
         private void Form1_Load(object sender, EventArgs e)
         {
             es_custcode.TableName = "CS_EXPORTSETTING   ";
@@ -26,6 +54,9 @@ namespace UAS_BARCODEIO
             es_custcode.Condition = "";
             es_custcode.DbChange += nr_rule_DBChange;
             SystemInf.dh = dh;
+            format = engine.Documents.Open(Application.StartupPath + @"\BARCODE.btw");
+            asc.controllInitializeSize(this);
+            asc.controlAutoSize(this);
         }
 
         private void nr_rule_DBChange(object sender, EventArgs e)
@@ -38,14 +69,20 @@ namespace UAS_BARCODEIO
         {
             if (e.KeyCode == Keys.Enter)
             {
-                string sql = "select sum(pd_inqty)pd_inqty,pd_prodcode,max(pr_detail)pr_detail,max(pr_spec)pr_spec,sum(nvl(bi_inqty,0))bi_inqty " +
-                    "from prodiodetail left join product on pr_code=pd_prodcode left join barcodeio on bi_prodcode=pd_prodcode " +
-                    "and pd_inoutno=bi_inoutno where pd_inoutno='" + pi_inoutno.Text + "' group by pd_prodcode";
-                DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
-                BaseUtil.FillDgvWithDataTable(Prodiodetail, dt);
+                LoadGridData();
             }
         }
 
+        private void LoadGridData()
+        {
+            string sql = "select pd_inqty,pd_prodcode,pr_detail,pr_spec,bi_inqty from " +
+                "(select pd_prodcode,sum(pd_inqty)pd_inqty from prodiodetail where pd_inoutno='" + pi_inoutno.Text + "' group by pd_prodcode)" +
+                " left join (select bi_prodcode,nvl(sum(bi_inqty),0)bi_inqty from barcodeio " +
+                "where bi_inoutno='" + pi_inoutno.Text + "' group by bi_prodcode) on pd_prodcode=bi_prodcode left join product on pr_code=pd_prodcode";
+            DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
+            BaseUtil.FillDgvWithDataTable(Prodiodetail, dt);
+        }
+
         private void Barcode_KeyDown(object sender, KeyEventArgs e)
         {
             if (e.KeyCode == Keys.Enter)
@@ -89,5 +126,143 @@ namespace UAS_BARCODEIO
                 }
             }
         }
+        bool AutoSized = false;
+        private void 入库条码规则解析_AutoSizeChanged(object sender, EventArgs e)
+        {
+            if (!AutoSized)
+            {
+                asc.controlAutoSize(this);
+                AutoSized = true;
+            }
+        }
+
+        private void Prodiodetail_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
+        {
+            bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
+            if (e.ColumnIndex > 0 && e.RowIndex >= 0)
+            {
+                if (Prodiodetail.Columns[e.ColumnIndex].Name == "pd_prodcode")
+                {
+                    SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
+                    if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString())
+                        e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
+                    else
+                        e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
+                    Rectangle border = e.CellBounds;
+                    border.Width -= 1;
+                    e.Graphics.DrawRectangle(Pens.White, border);
+                    e.PaintContent(e.CellBounds);
+                    e.Handled = true;
+                }
+            }
+        }
+
+        private void Prodiodetail_SelectionChanged(object sender, EventArgs e)
+        {
+            if (Prodiodetail.SelectedRows.Count > 0)
+            {
+                DataGridViewSelectedRowCollection dsc = Prodiodetail.SelectedRows;
+                Prodiodetail.Rows[dsc[0].Index].Selected = true;
+                if (dsc[0].Index - 2 >= 0)
+                    Prodiodetail.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
+                else
+                    Prodiodetail.FirstDisplayedScrollingRowIndex = dsc[0].Index;
+            }
+        }
+
+        private void GenBarCode_Click(object sender, EventArgs e)
+        {
+            string sql = "select pr_zxbzs,pd_piid,pd_piclass,pd_inqty,pd_prodcode,pr_detail,pr_spec,nvl(bi_inqty,0)bi_inqty from " +
+               "(select max(pd_piid)pd_piid,max(pd_piclass)pd_piclass,pd_prodcode,sum(pd_inqty)pd_inqty from prodiodetail where pd_inoutno='" + pi_inoutno.Text + "' group by pd_prodcode)" +
+               " left join (select bi_prodcode,nvl(sum(bi_inqty),0)bi_inqty from barcodeio " +
+               "where bi_inoutno='" + pi_inoutno.Text + "' group by bi_prodcode) on pd_prodcode=bi_prodcode left join product on pr_code=pd_prodcode " +
+               "where pd_prodcode='" + PR_CODE.Text + "'";
+            DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
+            if (dt.Rows.Count == 0)
+            {
+                MessageBox.Show("物料不在对应入库单中" + pi_inoutno.Text);
+                return;
+            }
+            ZXBZ.Text = dt.Rows[0]["pr_zxbzs"].ToString();
+            int pdinqty = int.Parse(dt.Rows[0]["pd_inqty"].ToString());
+            int barqty = int.Parse(dt.Rows[0]["bi_inqty"].ToString());
+            int Minpackage = 0;
+            string pi_id = dt.Rows[0]["pd_piid"].ToString();
+            string pd_piclass = dt.Rows[0]["pd_piclass"].ToString();
+            //本次入库数
+            int NowInqty = int.Parse(INQTY.Text);
+            if (!int.TryParse(ZXBZ.Text, out Minpackage))
+            {
+                MessageBox.Show("最小包装数错误,料号" + PR_CODE.Text);
+                return;
+            }
+            if (int.Parse(INQTY.Text) > pdinqty - barqty)
+            {
+                MessageBox.Show("物料采集后超出入库单数量" + PR_CODE.Text);
+                return;
+            }
+            //生成条码数量
+            int barcount = NowInqty % Minpackage == 0 ? NowInqty / Minpackage : (NowInqty / Minpackage) + 1;
+            List<string> bi_inqty = new List<string>();
+            List<string> bi_barcode = new List<string>();
+            List<string> bi_vendbarcode = new List<string>();
+            List<string> bi_madedate = new List<string>();
+            string datecode = dh.getFieldDataByCondition("dual", "WEEK_TO_DATE('" + DC.Text + "')", "1=1").ToString();
+            for (int i = 0; i < barcount; i++)
+            {
+                string barcode = "";
+                int OneUnit = 0;
+                string[] param = new string[] { PR_CODE.Text, "", barcode };
+                dh.CallProcedure("SP_GETBARCODE", ref param);
+                barcode = param[2].Replace("BARCODE:", "");
+                //如果最后有尾数的话 
+
+                if (i == barcount - 1)
+                {
+                    if (NowInqty % Minpackage == 0)
+                    {
+                        OneUnit = Minpackage;
+                    }
+                    else
+                    {
+                        OneUnit = NowInqty % Minpackage;
+                    }
+                }
+                else
+                {
+                    OneUnit = Minpackage;
+                }
+                bi_inqty.Add(OneUnit.ToString());
+                bi_barcode.Add(barcode);
+                bi_vendbarcode.Add(LOTNO.Text);
+                bi_madedate.Add(datecode);
+                sql = "insert into barcodeio(BI_ID, BI_BARCODE, BI_PIID, BI_PICLASS, BI_INOUTNO, BI_PDNO, BI_PDID, BI_PRODCODE, BI_INQTY,bi_vendbarcode, " +
+                   "BI_MADEDATE, BI_PRODID, BI_STATUS, BI_ORDERCODE, BI_INMAN, BI_INDATE)select barcodeio_seq.nextval,:bi_barcode,'" + pi_id + "'," +
+                   "'" + pd_piclass + "','" + pi_inoutno.Text + "',0,0,'" + PR_CODE.Text + "',:bi_inqty,:bi_vendbarcode,to_date(:bi_madedate,'yyyy-mm-dd'),pr_id,0,'','管理员',sysdate " +
+                   " from product where pr_code='" + PR_CODE.Text + "'";
+                dh.BatchInsert(sql, new string[] { "bi_inqty", "bi_barcode", "bi_vendbarcode", "bi_madedate" }, bi_barcode.ToArray(), bi_inqty.ToArray(), bi_vendbarcode.ToArray(), bi_madedate.ToArray());
+                LoadGridData();
+                LoadBarcodeioData();
+            }
+        }
+
+        private void LoadBarcodeioData()
+        {
+
+            string sql = "select 0 CheckBox,bi_barcode,bi_inqty,bi_datecode,bi_vendbarcode,bi_madedate from barcodeio where bi_inoutno='" + pi_inoutno.Text + "' and bi_prodcode='" + PR_CODE.Text + "'";
+            DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
+            BaseUtil.FillDgvWithDataTable(BarcodeIO, dt);
+        }
+
+        private void PrintBarCode_Click(object sender, EventArgs e)
+        {
+            for (int i = 0; i < BarcodeIO.Rows.Count; i++)
+            {
+                if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True")
+                {
+
+                }
+            }
+        }
     }
 }

+ 7 - 4
UAS_BARCODEIO/入库条码规则解析.resx

@@ -132,16 +132,19 @@
   <metadata name="bi_inqty.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="dataGridViewTextBoxColumn1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="CheckBox.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="dataGridViewTextBoxColumn2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="bi_barcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="dataGridViewTextBoxColumn3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="bi_inqty1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="dataGridViewTextBoxColumn4.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="bi_vendbarcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="bi_madedate.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
 </root>