Browse Source

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

caosy 6 years ago
parent
commit
ced416f09b

+ 5 - 0
UAS-出货标签管理(吉利通)/App.config

@@ -6,6 +6,11 @@
       <section name="贴标机标签打印.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
     </sectionGroup>
   </configSections>
+  <connectionStrings>
+    <add name="UAS_LabelMachine.Properties.Settings.LabelPrintConnectionString"
+      connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\LabelPrint.accdb"
+      providerName="System.Data.OleDb" />
+  </connectionStrings>
   <startup useLegacyV2RuntimeActivationPolicy="true">
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
     <supportedRuntime version="v2.0.50727" />

+ 2 - 2
UAS-出货标签管理(吉利通)/Entity/SystemInf.cs

@@ -6,8 +6,8 @@
         //备用数据库链接,防止主链接被释放
         public static DataHelper dh1;
 
-        public static AccessDBHelper adh;
+        public static SqliteDBHelper adh;
 
-        public static AccessDBHelper back_adh;
+        public static SqliteDBHelper back_adh;
     }
 }

+ 5 - 5
UAS-出货标签管理(吉利通)/Login.cs

@@ -15,9 +15,9 @@ namespace UAS_LabelMachine
 
         DataHelper dh1;
         //后端操作
-        AccessDBHelper adh1;
+        SqliteDBHelper adh1;
         //数据上传操作
-        AccessDBHelper adh2;
+        SqliteDBHelper adh2;
         DataTable dt;
 
         public Login()
@@ -38,13 +38,13 @@ namespace UAS_LabelMachine
             dh = new DataHelper();
             dh1 = new DataHelper();
             //启动时压缩数据库
-            BaseUtil.CompactAccessDB("LabelPrint.accdb");
-            adh1 = new AccessDBHelper("LabelPrint.accdb");
-            adh2 = new AccessDBHelper("LabelPrint.accdb");
+            adh1 = new SqliteDBHelper("LabelPrint.db3");
+            adh2 = new SqliteDBHelper("LabelPrint.db3");
             SystemInf.dh = dh;
             SystemInf.dh1 = dh1;
             SystemInf.back_adh = adh1;
             SystemInf.adh = adh2;
+            adh1.ExecuteZip();
             //获取账套信息
             dt = (DataTable)dh.ExecuteSql("select ma_function,ms_pwd,ma_user from master ", "select");
             DataTable MasterDB = dt.Clone();

+ 1 - 1
UAS-出货标签管理(吉利通)/ParamSetting.cs

@@ -14,7 +14,7 @@ namespace UAS_LabelMachine
     public partial class ParamSetting : Form
     {
         AutoSizeFormClass asc = new AutoSizeFormClass();
-        AccessDBHelper dbhelper;
+        SqliteDBHelper dbhelper;
         DataTable COMINFO;
         DataTable plcinstruct;
         DataTable DataExtra;

+ 8 - 0
UAS-出货标签管理(吉利通)/Properties/Settings.settings

@@ -23,5 +23,13 @@
     <Setting Name="OutboxCapacity" Type="System.Decimal" Scope="User">
       <Value Profile="(Default)">0</Value>
     </Setting>
+    <Setting Name="LabelPrintConnectionString" Type="(Connection string)" Scope="Application">
+      <DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
+&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
+  &lt;ConnectionString&gt;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\LabelPrint.accdb&lt;/ConnectionString&gt;
+  &lt;ProviderName&gt;System.Data.OleDb&lt;/ProviderName&gt;
+&lt;/SerializableConnectionString&gt;</DesignTimeValue>
+      <Value Profile="(Default)">Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\LabelPrint.accdb</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

+ 10 - 0
UAS-出货标签管理(吉利通)/Properties/Settings1.Designer.cs

@@ -106,5 +106,15 @@ namespace UAS_LabelMachine.Properties {
                 this["OutboxCapacity"] = value;
             }
         }
+        
+        [global::System.Configuration.ApplicationScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)]
+        [global::System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\LabelPrint.accdb")]
+        public string LabelPrintConnectionString {
+            get {
+                return ((string)(this["LabelPrintConnectionString"]));
+            }
+        }
     }
 }

+ 6 - 2
UAS-出货标签管理(吉利通)/PublicMethod/BaseUtil.cs

@@ -64,7 +64,7 @@ namespace UAS_LabelMachine
             if (DateCode.Length == 4)
             {
                 oYear = int.Parse(DateCode.Substring(0, 2));
-                DateTime date=  new DateTime(DateTime.Now.Year, 1, 1).AddDays(7 * int.Parse(DateCode.Substring(2, 2)));
+                DateTime date = new DateTime(DateTime.Now.Year, 1, 1).AddDays(7 * int.Parse(DateCode.Substring(2, 2)));
                 oMonth = date.Month;
                 oDay = date.Day;
             }
@@ -279,7 +279,11 @@ namespace UAS_LabelMachine
                                     }
                                     else if (collection[i] is NumericUpDown)
                                     {
-                                        (collection[i] as NumericUpDown).Value = int.Parse(dt.Rows[0][j].ToString());
+                                        int num = 0;
+                                        if (int.TryParse(dt.Rows[0][j].ToString(), out num))
+                                        {
+                                            (collection[i] as NumericUpDown).Value = num;
+                                        }
                                     }
                                     else
                                     {

+ 2 - 2
UAS-出货标签管理(吉利通)/PublicMethod/LogicHandler.cs

@@ -7,7 +7,7 @@ namespace UAS_LabelMachine.PublicMethod
 {
     class LogicHandler
     {
-        static AccessDBHelper adh = SystemInf.adh;
+        static SqliteDBHelper adh = SystemInf.adh;
 
         static DataHelper dh = SystemInf.dh;
 
@@ -43,7 +43,7 @@ namespace UAS_LabelMachine.PublicMethod
         /// </summary>
         /// <param name="PLC"></param>
         /// <param name="Movement"></param>
-        public static void SendDataToPLC(SerialPortWithTag PLC, string Movement, AccessDBHelper adh)
+        public static void SendDataToPLC(SerialPortWithTag PLC, string Movement, SqliteDBHelper adh)
         {
             DataTable dt = (DataTable)adh.ExecuteSql("select * from plcinstruct", "select");
             if (PLC.IsOpen && dt.Rows.Count > 0)

+ 941 - 0
UAS-出货标签管理(吉利通)/PublicMethod/SqliteDBHelper.cs

@@ -0,0 +1,941 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.SQLite;
+using System.IO;
+using System.Text;
+using System.Windows.Forms;
+
+namespace UAS_LabelMachine
+{
+    class SqliteDBHelper
+    {
+        private string _fileName;
+        private string _connectionString;
+        private SQLiteConnection _odcConnection = null;
+        private SQLiteCommand command = null;
+
+        public SqliteDBHelper(string fileName)
+        {
+            this._fileName = fileName;
+            this._connectionString = @"Data Source=" + fileName + ";";
+            Open();
+        }
+
+        public void Open()
+        {
+            try
+            {
+                // 建立连接
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                // 打开连接
+                this._odcConnection.Open();
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+            }
+        }
+
+        public  void ExecuteZip()
+        {
+            command = new SQLiteCommand("Vacuum", this._odcConnection);
+            command.ExecuteNonQuery();
+        }
+
+        public void Close()
+        {
+            this._odcConnection.Close();
+        }
+
+
+        public DataTable GetDataTable(string sql)
+        {
+            DataTable ds = new DataTable();
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
+            try
+            {
+                adapter.Fill(ds);
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("sql語句: " + sql + " 執行失敗!" + ex.Message);
+            }
+            adapter.Dispose();
+            return ds;
+        }
+
+        public DataSet GetDataSet(string sql)
+        {
+            DataSet ds = new DataSet();
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
+            try
+            {
+                adapter.Fill(ds);
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("sql語句: " + sql + " 執行失敗!" + ex.Message);
+            }
+            adapter.Dispose();
+            return ds;
+        }
+
+        public void Reconnect(SQLiteCommand cmd)
+        {
+            if (cmd.Connection.State == ConnectionState.Closed)
+            {
+                cmd.Connection.Open();
+                //超时重连
+            }
+        }
+
+        /// <summary>
+        /// 根据表名获取该表字段数据类型
+        /// </summary>
+        public DataTable GetColumnDataType(string TableName)
+        {
+            DataTable dt = new DataTable();
+            command = new SQLiteCommand("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            ad.Fill(dt);
+            ad.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 获取第一行第一列的信息
+        /// </summary>
+        public object getFieldDataByCondition(string TableName, string Field, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select " + Field + " from " + TableName + " where " + Condition;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter();
+            ad.SelectCommand = command;
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            ad.Dispose();
+            if (dt.Rows.Count > 0)
+            {
+                return dt.Rows[0][0];
+            }
+            else
+            {
+                return "";
+            }
+        }
+
+        public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
+        {
+            command = new SQLiteCommand(sql, _odcConnection);
+            SQLiteDataAdapter adapter = new SQLiteDataAdapter();
+            adapter.UpdateBatchSize = param1[0].Length;
+            //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
+            //将第一个数组的下标固定为0作为循环添加的参数的名称
+            for (int i = 0; i < param.Length; i++)
+            {
+                command.Parameters.Add(new SQLiteParameter(param[i].ToString(), param1[i]));
+            }
+            try
+            {
+                command.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+
+            }
+        }
+
+        public void DeleleFile(string accessFile)
+        {
+            var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();
+            try
+            {
+                string tempFile = Path.Combine(Path.GetDirectoryName(accessFile), Path.GetRandomFileName() + Path.GetExtension(accessFile));
+                dbe.CompactDatabase(accessFile, tempFile);
+                FileInfo temp = new FileInfo(tempFile);
+                temp.CopyTo(accessFile, true);
+                temp.Delete();
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine("Error: " + e.Message);
+            }
+        }
+
+        /// <summary>
+        /// 插入DataTable到Access数据库
+        /// </summary>
+        /// <param name="dt"></param>
+        /// <param name="TableName"></param>
+        public void SaveDataTable(DataTable dt, string TableName)
+        {
+            StringBuilder sb = new StringBuilder();
+            //预防插入的DataTable中存在不属于该表的列,在进行下一步操作之前全部剔除
+            //DataTable data = (DataTable)ExecuteSql("select top 1 * from " + TableName, "select");
+            ////将所有的字段拼接起来
+            //for (int i = 0; i < data.Columns.Count; i++)
+            //{
+            //    sb.Append("#" + data.Columns[i].ColumnName.ToString().ToUpper());
+            //}
+            ////移除掉所有不属于该表的列
+            //for (int i = dt.Columns.Count - 1; i >= 0; i--)
+            //{
+            //    if (!sb.ToString().Contains(dt.Columns[i].ColumnName.ToUpper()))
+            //    {
+            //        dt.Columns.RemoveAt(i);
+            //    }
+            //}
+            sb.Clear();
+            sb.Append("insert into " + TableName + " (");
+            string field = "";
+            string valuefield = "";
+            for (int i = 0; i < dt.Columns.Count; i++)
+            {
+                if (i != dt.Columns.Count - 1)
+                {
+                    field += dt.Columns[i].ColumnName + ",";
+                    valuefield += "?,";
+                }
+                else
+                {
+                    field += dt.Columns[i].ColumnName + "";
+                    valuefield += "?";
+                }
+            }
+            sb.Append(field + ") values(" + valuefield + ")");
+            SQLiteTransaction tx = this._odcConnection.BeginTransaction();
+            command = new SQLiteCommand();
+            command.Connection = this._odcConnection;
+            command.Transaction = tx;
+            string sql = sb.ToString();
+            try
+            {
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    command.CommandText = sql;
+                    for (int j = 0; j < dt.Columns.Count; j++)
+                    {
+                        command.Parameters.AddWithValue(dt.Columns[j].ColumnName, dt.Rows[i][j]);
+                    }
+                    try
+                    {
+                        command.ExecuteNonQuery();
+                        command.Parameters.Clear();
+                    }
+                    catch (Exception e)
+                    {
+                        MessageBox.Show(e.Message.ToString());
+                    }
+                }
+                tx.Commit();
+            }
+            catch (Exception E)
+            {
+                tx.Rollback();
+                throw new Exception(E.Message);
+            }
+        }
+
+        public void BatchInsert(string tableName, DataTable dt)
+        {
+            List<string> columnList = new List<string>();
+            foreach (DataColumn one in dt.Columns)
+            {
+                columnList.Add(one.ColumnName);
+            }
+            SQLiteDataAdapter adapter = new SQLiteDataAdapter();
+            adapter.SelectCommand = new SQLiteCommand("select pib_id from " + tableName, this._odcConnection);
+            using (SQLiteCommandBuilder builder = new SQLiteCommandBuilder(adapter))
+            {
+                adapter.InsertCommand = builder.GetInsertCommand();
+                foreach (string one in columnList)
+                {
+                    adapter.InsertCommand.Parameters.Add(new SQLiteParameter(one.ToLower(), "Test"));
+                }
+            }
+        }
+
+        /// <summary>
+        /// 获取指定表的记录的条数 ,带条件
+        /// </summary>
+        /// <returns></returns>
+        public int getRowCount(string TableName, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select count(1) from " + TableName + " where " + Condition;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            ad.Fill(dt);
+            ad.Dispose();
+            return int.Parse(dt.Rows[0][0].ToString());
+        }
+
+        /// <summary>
+        /// 获取指定表的记录的条数 ,不带条件
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <returns></returns>
+        public int getRowCount(string TableName)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select count(1) from " + TableName;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            ad.Fill(dt);
+            ad.Dispose();
+            return int.Parse(dt.Rows[0][0].ToString());
+        }
+
+        /// <summary>
+        /// 通过表名和获取单行的记录
+        /// </summary>
+        public DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += AddField(Fields);
+            sql += " from " + TableName + " where " + Condition + " and rownum=1";
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            ad.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 按分页获取数据
+        /// </summary>
+        /// <param name="TableName">表名</param>
+        /// <param name="Fields">查询字段</param>
+        /// <param name="CurrentPage">当前页面</param>
+        /// <param name="PageSize">页面展示条数</param>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        // SELECT * FROM (SELECT   A.*  FROM (SELECT* FROM datalist) A WHERE ROWNUM <= 50) WHERE ROWNUM >= 21
+        public DataTable getFieldsDatasByPageing(string TableName, string Fields, int CurrentPage, int PageSize, string Caller, params string[] condition)
+        {
+            DataTable dt = new DataTable();
+            StringBuilder sql = new StringBuilder();
+            //先查询出配置出去的列
+            //获取查询的列
+            string[] caption = GetCaptionFromField(Fields);
+            //获取对应列的描述
+            string[] field = GetField(Fields);
+            sql.Append(" select * from (select RowNum RN, A.* from (select ");
+            sql.Append(AddField(caption));
+            if (condition.Length > 0)
+            {
+                if (condition[0] != null && condition[0].Trim() != "")
+                    sql.Append(" from " + TableName + " where " + condition[0] + " ) A where ROWNUM <=" + CurrentPage * PageSize + ") where RN>" + (CurrentPage - 1) * PageSize);
+                else
+                    sql.Append(" from " + TableName + ") A where ROWNUM <= " + CurrentPage * PageSize + ") where RN> " + (CurrentPage - 1) * PageSize);
+            }
+            command = new SQLiteCommand(sql.ToString(), this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            ad.Fill(dt);
+            ad.Dispose();
+            dt.Columns.RemoveAt(0);
+            foreach (DataColumn dc in dt.Columns)
+            {
+                dc.ColumnName = field[dt.Columns.IndexOf(dc)];
+                dc.Caption = caption[dt.Columns.IndexOf(dc)];
+            }
+            return dt;
+        }
+
+        /// <summary>
+        /// 通过表名,字段和条件获取DataTable类型的数据
+        /// </summary>
+        public DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += AddField(Fields);
+            sql += " from " + TableName + " where " + Condition;
+
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            ad.Dispose();
+            return dt;
+        }
+
+        /// <summary>
+        /// 通过表名,字段获取DataTable类型的数据
+        /// </summary>
+        public DataTable getFieldsDatas(string TableName, string Fields)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select ";
+            sql += Fields;
+            sql += " from " + TableName;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            ad.SelectCommand = command;
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            ad.Dispose();
+            return dt;
+        }
+
+
+        /// <summary>
+        /// 获取DbFind的数据的DataTable的结构
+        /// </summary>
+        /// <param name="field"></param>
+        /// <param name="caller"></param>
+        /// <returns></returns>
+        public DataTable GetDbFindDataTable(string field, string caller)
+        {
+            string sql = "select * from dbfindsetui where ds_caller='" + caller + "' and ds_whichui='" + field + "'";
+            DataTable dt = (DataTable)ExecuteSql(sql, "select");
+            if (dt.Rows.Count != 0)
+            {
+                //通过#号分割字段
+                string[] dbfield = dt.Rows[0]["ds_findtoui"].ToString().Split('#');
+                string[] cnfield = dt.Rows[0]["ds_dbcaption"].ToString().Split('#');
+                //获取查询要查询的Table
+                string dbtable = dt.Rows[0]["ds_tables"].ToString();
+                //拼接查询的字段
+                for (int i = 0; i < dbfield.Length; i++)
+                {
+                    dbfield[i] = dbfield[i].Split(',')[0];
+                }
+                //新建一个空的DataTable
+                DataTable dt1 = new DataTable();
+                //往空的DataTable添加结构,ColumnName是中文,Caption是实际的字段名称
+                for (int i = 0; i < cnfield.Length; i++)
+                {
+                    dt1.Columns.Add(cnfield[i]);
+                    dt1.Columns[i].Caption = dbfield[i];
+                }
+                //返回一个带有结构的空的DataTable
+                //DbFind.BindTable1 = dbtable;
+                return dt1;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 检测内容是否存在
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <param name="Condition"></param>
+        /// <returns></returns>
+        public bool CheckExist(string TableName, string Condition)
+        {
+            string sql = "select count(1) from " + TableName + " where " + Condition;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            DataTable dt = new DataTable();
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            ad.Dispose();
+            return int.Parse(dt.Rows[0][0].ToString()) > 0;
+        }
+
+        /// <summary>
+        /// 直接执行SQL,同时传入SQL的类型
+        /// </summary>
+        /// <param name="SQL"></param>
+        /// <param name="Type"></param>
+        /// <returns></returns>
+        public object ExecuteSql(string SQL, string Type, params object[] names)
+        {
+            object result = null;
+            command = new SQLiteCommand(SQL, this._odcConnection);
+            Reconnect(command);
+            //用来拼接参数的
+            if (names.Length > 0)
+            {
+                string[] par = SQL.Split(':');
+                //用来存参数的数组
+                StringBuilder[] addpar = new StringBuilder[par.Length - 1];
+                for (int i = 0; i < par.Length - 1; i++)
+                {
+                    //新建一个char类型的数组用来存储每个字节的变量
+                    char[] c = par[i + 1].ToCharArray();
+                    addpar[i] = new StringBuilder();
+                    for (int j = 0; j < c.Length; j++)
+                    {
+                        if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
+                        {
+                            addpar[i].Append(c[j]);
+                        }
+                        else
+                        {
+                            break;
+                        }
+                    }
+                }
+                for (int i = 0; i < addpar.Length; i++)
+                    command.Parameters.Add(new SQLiteParameter(addpar[i].ToString(), names[i]));
+            }
+
+            switch (Type.ToUpper())
+            {
+                case "SELECT":
+                    SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+                    result = new DataTable();
+                    try
+                    {
+                        ad.Fill((DataTable)result);
+                    }
+                    catch (Exception)
+                    {
+                        this._odcConnection = new SQLiteConnection(this._connectionString);
+                        this._odcConnection.Open();
+                        command = new SQLiteCommand(SQL, this._odcConnection);
+                        ad = new SQLiteDataAdapter();
+                        ad.SelectCommand = command;
+                        ad.Fill((DataTable)result);
+                    }
+                    break;
+                case "DELETE":
+                    try
+                    {
+                        result = command.ExecuteNonQuery();
+                    }
+                    catch (Exception)
+                    {
+                        command.Connection = new SQLiteConnection(this._connectionString);
+                        command.Connection.Open();
+                        result = command.ExecuteNonQuery();
+                    }
+                    break;
+                case "UPDATE":
+                    try
+                    {
+                        result = command.ExecuteNonQuery();
+                    }
+                    catch (Exception)
+                    {
+                        command.Connection = new SQLiteConnection(this._connectionString);
+                        command.Connection.Open();
+                        result = command.ExecuteNonQuery();
+                    }
+                    break;
+                case "INSERT":
+                    try
+                    {
+                        result = command.ExecuteNonQuery();
+                    }
+                    catch (Exception)
+                    {
+                        command.Connection = new SQLiteConnection(this._connectionString);
+                        command.Connection.Open();
+                        result = command.ExecuteNonQuery();
+                    }
+                    break;
+            }
+
+            return result;
+        }
+
+        /// <summary>
+        /// 为了同步BS端的条码维护,检测时允许问号的存在,在检测时默认将问号换成:Param参数
+        /// </summary>
+        /// <param name="SQL"></param>
+        public void CheckSQL(string SQL)
+        {
+            SQL = SQL.Replace("?", ":Param");
+            command = new SQLiteCommand(SQL, this._odcConnection);
+            command.ExecuteNonQuery();
+
+        }
+
+        public int GetDistinctRowCount(string TableName, string Field)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select distinct count('" + Field + "') from " + TableName;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter(command);
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            ad.Dispose();
+
+            return int.Parse(dt.Rows[0][0].ToString());
+        }
+
+        /// <summary>
+        /// 根据Caller获取流水号
+        /// </summary>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        public string GetSerialNumberByCaller(string Caller)
+        {
+            string SerialNumber = getFieldDataByCondition("MaxNumbers", "mn_number", "mn_tablename='" + Caller + "'").ToString();
+            UpdateByCondition("MaxNumbers", "mn_number=mn_number+1", "mn_tablename='" + Caller + "'");
+            return SerialNumber;
+        }
+
+        /// <summary>
+        /// 通过序列的名称获取序列
+        /// </summary>
+        /// <param name="SeqName"></param>
+        /// <returns></returns>
+        public string GetSEQ(string SeqName)
+        {
+            DataTable dt = new DataTable();
+            dt = (DataTable)ExecuteSql("SELECT " + SeqName + ".NEXTVAL FROM DUAL", "select");
+            return dt.Rows[0][0].ToString();
+        }
+
+        /// <summary>
+        /// 通过序列的名称获取序列
+        /// </summary>
+        /// <param name="SeqName"></param>
+        /// <returns></returns>
+        public string[] GetSEQ(string SeqName, int Num)
+        {
+            DataTable dt = new DataTable();
+            dt = (DataTable)ExecuteSql("SELECT " + SeqName + ".nextval  FROM DUAL CONNECT BY LEVEL<=" + Num, "select");
+            string[] SerialNum = new string[dt.Rows.Count];
+            for (int i = 0; i < dt.Rows.Count; i++)
+            {
+                SerialNum[i] = dt.Rows[i][0].ToString();
+            }
+            return SerialNum;
+        }
+
+        /// <summary>
+        /// 取Configs表中的配置,进行该客户是否执行某个操作
+        /// </summary>
+        /// <param name="Code"></param>
+        /// <param name="Caller"></param>
+        /// <returns></returns>
+        public object GetConfig(string Code, string Caller)
+        {
+            DataTable dt = new DataTable();
+            string sql = "select Data from configs where code='" + Code + "' and caller='" + Caller + "'";
+            dt = (DataTable)ExecuteSql(sql, "select");
+            if (dt.Rows.Count == 0)
+            {
+                return "";
+            }
+            else
+            {
+                return dt.Rows[0]["Data"];
+            }
+        }
+
+
+        //将数据类型的列类型转换为DataTable
+        public DataTable DataTypeColumnToDataTable(DataTable dt)
+        {
+            DataTable dt1 = new DataTable();
+            dt1.Rows.Add();
+            foreach (DataRow dr in dt.Rows)
+            {
+                dt1.Columns.Add(dr[0].ToString());
+                int index = dt.Rows.IndexOf(dr);
+                if (dr[1].ToString() == "NUMBER")
+                {
+                    dt1.Rows[0][index] = 0;
+                }
+                if (dr[1].ToString() == "VARCHAR2")
+                {
+                    dt1.Rows[0][index] = "这是一段文字";
+                }
+                if (dr[1].ToString() == "DATE")
+                {
+                    dt1.Rows[0][index] = DateTime.Now.ToString("yyyy-MM-dd");
+                }
+                if (dr[1].ToString() == "FLOAT")
+                {
+                    dt1.Rows[0][index] = 1.0;
+                }
+                if (dr[1].ToString() == "CLOB")
+                {
+                    dt1.Rows[0][index] = "一段长文字";
+                }
+            }
+            return dt1;
+        }
+
+
+        /// <summary>
+        /// 通过条件更新
+        /// </summary>
+        /// <param name="TableName"></param>
+        /// <param name="update"></param>
+        /// <param name="condition"></param>
+        public int UpdateByCondition(string TableName, string update, string condition)
+        {
+            string sql = "update " + TableName + " set " + update + " where " + condition;
+            command = new SQLiteCommand(sql, this._odcConnection);
+            int Rowcount = 0;
+            Reconnect(command);
+            try
+            {
+                Rowcount = command.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+                command.Connection = new SQLiteConnection(this._connectionString);
+                command.Connection.Open();
+                Rowcount = command.ExecuteNonQuery();
+            }
+            return Rowcount;
+        }
+
+
+        /// <summary>
+        /// 出现异常进行回滚的执行方法
+        /// </summary>
+        /// <param name="SQL"></param>
+        public void ExecuteSQLTran(params string[] SQL)
+        {
+            SQLiteTransaction tx = this._odcConnection.BeginTransaction();
+            command = new SQLiteCommand();
+            command.Connection = this._odcConnection;
+            command.Transaction = tx;
+            try
+            {
+                foreach (string sql in SQL)
+                {
+                    if (!String.IsNullOrEmpty(sql))
+                    {
+                        command.CommandText = sql;
+                        try
+                        {
+                            command.ExecuteNonQuery();
+                        }
+                        catch (Exception)
+                        {
+                            command.Connection = new SQLiteConnection(this._connectionString);
+                            command.Connection.Open();
+                            command.ExecuteNonQuery();
+                        }
+                    }
+                }
+                tx.Commit();
+            }
+            catch (Exception E)
+            {
+                tx.Rollback();
+                throw new Exception(E.Message);
+            }
+        }
+
+        /// <summary>
+        /// 用于将string 的数组转换成SQL的查询内容
+        /// </summary>
+        /// <param name="Fields"></param>
+        /// <returns></returns>
+        private string AddField(string[] Fields)
+        {
+            string sql = " ";
+            foreach (string field in Fields)
+            {
+                sql += field + ",";
+            }
+            return sql.Substring(0, sql.Length - 1);
+        }
+        /// <summary>
+        /// 通过查询的内容获取到字段的描述
+        /// </summary>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        private static string[] GetCaptionFromField(string field)
+        {
+            string[] caption = field.Split(',');
+            for (int i = 0; i < caption.Length; i++)
+            {
+                caption[i] = caption[i].Substring(0, caption[i].LastIndexOf("as")).Trim();
+            }
+            return caption;
+        }
+
+        /// <summary>
+        /// 通过查询的语句获取查询的字段
+        /// </summary>
+        /// <param name="field"></param>
+        /// <returns></returns>
+        private static string[] GetField(string field)
+        {
+            string[] fields = field.Split(',');
+            for (int i = 0; i < fields.Length; i++)
+            {
+                fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
+            }
+            return fields;
+        }
+
+        public object GetLabelParam(string sql)
+        {
+            DataTable dt = new DataTable();
+            command = new SQLiteCommand(sql, this._odcConnection);
+            Reconnect(command);
+            SQLiteDataAdapter ad = new SQLiteDataAdapter();
+            ad.SelectCommand = command;
+            try
+            {
+                ad.Fill(dt);
+            }
+            catch (Exception)
+            {
+                this._odcConnection = new SQLiteConnection(this._connectionString);
+                this._odcConnection.Open();
+                command = new SQLiteCommand(sql, this._odcConnection);
+                ad = new SQLiteDataAdapter();
+                ad.SelectCommand = command;
+                ad.Fill(dt);
+            }
+            if (dt.Rows.Count > 0)
+            {
+                ad.Dispose();
+
+                return dt.Rows[0][0];
+            }
+            else
+            {
+                return "";
+            }
+        }
+
+        public static string[] GetParamFromSQL(string SQL)
+        {
+            string[] par = SQL.Split(':');
+            //用来存参数的数组
+            StringBuilder[] addpar = new StringBuilder[par.Length - 1];
+            string[] param = new string[par.Length - 1];
+            for (int i = 0; i < par.Length - 1; i++)
+            {
+                //新建一个char类型的数组用来存储每个字节的变量
+                char[] c = par[i + 1].ToCharArray();
+                addpar[i] = new StringBuilder();
+
+                for (int j = 0; j < c.Length; j++)
+                {
+                    if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
+                    {
+                        addpar[i].Append(c[j]);
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
+            for (int i = 0; i < par.Length - 1; i++)
+            {
+                param[i] = addpar[i].ToString();
+            }
+            return param;
+        }
+
+
+        public void AddColumFromDataTable(DataTable dt, string tablename)
+        {
+            DataTable dt2 = (DataTable)ExecuteSql("select * from " + tablename + "  limit 0,1", "select");
+            foreach (DataColumn item in dt.Columns)
+            {
+                if (!dt2.Columns.Contains(item.ToString()))
+                {
+                    switch (item.DataType.ToString())
+                    {
+                        case "System.String":
+                            ExecuteSql("alter table " + tablename + " add [" + item.ToString() + "] varchar(200) NULL", "update");
+                            break;
+                        case "System.Decimal":
+                            ExecuteSql("alter table " + tablename + " add [" + item.ToString() + "] number NULL", "update");
+                            break;
+                        case "System.DateTime":
+                            ExecuteSql("alter table " + tablename + " add [" + item.ToString() + "] date NULL", "update");
+                            break;
+                        default:
+                            break;
+                    }
+                }
+            }
+        }
+    }
+}

+ 5 - 0
UAS-出货标签管理(吉利通)/UAS-出货标签管理(吉利通).csproj

@@ -116,6 +116,9 @@
     <Reference Include="System" />
     <Reference Include="System.configuration" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Data.SQLite">
+      <HintPath>tool\System.Data.SQLite.dll</HintPath>
+    </Reference>
     <Reference Include="System.Runtime.Serialization" />
     <Reference Include="System.ServiceModel" />
     <Reference Include="System.Web" />
@@ -251,6 +254,7 @@
       <DesignTimeSharedInput>True</DesignTimeSharedInput>
       <DependentUpon>Settings.settings</DependentUpon>
     </Compile>
+    <Compile Include="PublicMethod\SqliteDBHelper.cs" />
     <Compile Include="PublicMethod\AccessDBHelper.cs" />
     <Compile Include="PublicMethod\ArrayList.cs" />
     <Compile Include="PublicMethod\AutoSizeFormClass.cs" />
@@ -397,6 +401,7 @@
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings1.Designer.cs</LastGenOutput>
     </None>
+    <None Include="tool\LabelPrint.db3" />
     <None Include="tool\Lppx2.tlb" />
   </ItemGroup>
   <ItemGroup>

+ 30 - 35
UAS-出货标签管理(吉利通)/UAS_出货标签管理.cs

@@ -26,9 +26,9 @@ namespace UAS_LabelMachine
 
         DataHelper dh1;
 
-        AccessDBHelper adh;
+        SqliteDBHelper adh;
 
-        AccessDBHelper back_adh;
+        SqliteDBHelper back_adh;
 
         DataTable dt;
 
@@ -293,6 +293,8 @@ namespace UAS_LabelMachine
                 byte[] readBuffer = new byte[len];
                 port.Read(readBuffer, 0, len); //将数据读入缓存
                 string msg = Encoding.ASCII.GetString(readBuffer, 0, len).Replace("\n", "").Replace("\r", "").Replace("\t", ""); //获取出入库产品编号
+                if (LabelInf.Rows.Count == 0)
+                    return;
                 int pib_pdno = int.Parse(LabelInf.Rows[CurrentRowIndex].Cells["pib_pdno"].Value.ToString());
                 if (DetailRange.Checked)
                 {
@@ -412,7 +414,10 @@ namespace UAS_LabelMachine
                 MessageLog.AppendText("接收返回消息异常!具体原因:" + ex.Message + ex.StackTrace, Color.Red);
             }
         }
-
+        string year = "";
+        string month = "";
+        string day = "";
+        string date = "";
         private bool RegexMatch(string CheckType, string msg, out string ErrorMsg)
         {
             ErrorMsg = "";
@@ -458,11 +463,7 @@ namespace UAS_LabelMachine
                                         {
                                             DateCode = matchs1.Groups[reg.GroupNumberFromName(groupName)].Value;
                                         }
-                                        string year = "";
-                                        string month = "";
-                                        string day = "";
-                                        string date = "";
-                                        LogicHandler.GetTimeFromDatecode(dh,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                                        LogicHandler.GetTimeFromDatecode(dh, DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                                         System.DateTime dtime;
                                         //有效期比对
                                         if (System.DateTime.TryParseExact(date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dtime))
@@ -702,7 +703,7 @@ namespace UAS_LabelMachine
                             dr[0]["pib_datecode"] = DateCode;
                             try
                             {
-                                LogicHandler.GetTimeFromDatecode(dh1,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                                LogicHandler.GetTimeFromDatecode(dh1, DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                                 dr[0]["pib_year"] = year;
                                 dr[0]["pib_month"] = month;
                                 dr[0]["pib_day"] = day;
@@ -778,7 +779,7 @@ namespace UAS_LabelMachine
                     //解析DateCode,将值设置到年月日
                     try
                     {
-                        LogicHandler.GetTimeFromDatecode(dh1,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
+                        LogicHandler.GetTimeFromDatecode(dh1, DateCode, pi_cardcode.Text, out year, out month, out day, out date);
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
@@ -1536,17 +1537,17 @@ namespace UAS_LabelMachine
             if (LabelInf.Rows.Count > 0)
             {
                 //设置初始化的采集进度
-                int Count = Count = adh.getRowCount("prodiobarcode", "pib_ifrecheck=-1 and pib_inoutno='" + pi_inoutno.Text + "'");
+                int Count = Count = back_adh.getRowCount("prodiobarcode", "pib_ifrecheck=-1 and pib_inoutno='" + pi_inoutno.Text + "'");
                 string midboxcode = "";
                 string outboxcode = "";
                 if (CurrentRowIndex - 1 >= 0)
                 {
-                    midboxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
-                    outboxcode = adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
+                    midboxcode = back_adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
+                    outboxcode = back_adh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
                 }
                 //未超出当前范围的时候
-                int midboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (midboxcode == "" ? "1" : midboxcode));
-                int outboxcount = adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (outboxcode == "" ? "1" : outboxcode));
+                int midboxcount = back_adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1=" + (midboxcode == "" ? "1" : midboxcode));
+                int outboxcount = back_adh.getRowCount("prodiobarcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2=" + (outboxcode == "" ? "1" : outboxcode));
                 midboxProcess.Text = midboxcount + "/" + MidBoxCapacity.Value;
                 outboxProcess.Text = outboxcount + "/" + OutBoxCapacity.Value;
                 //设置当前的箱号和盒号
@@ -2045,15 +2046,6 @@ namespace UAS_LabelMachine
                 LogicHandler.SendDataToPLC(PLC1, PLCInstruct.DeviceStart, adh);
                 MessageLog.AppendText("PLC启动成功\n", Color.Blue);
             }
-            adh.ExecuteSql("update prodiobarcode set pib_ifpick=0,pib_ifprint=0,pib_ifmodify=0 where pib_ifrecheck=0 and pib_inoutno='" + pi_inoutno.Text + "'", "update");
-            dr = LabelInfDataTable.Select("pib_ifrecheck=0");
-            for (int i = 0; i < dr.Length; i++)
-            {
-                dr[i]["pib_ifpick"] = 0;
-                dr[i]["pib_ifprint"] = 0;
-                dr[i]["pib_ifmodify"] = 0;
-            }
-            LabelInf.Invalidate();
         }
 
         private void PLCStop_Click(object sender, EventArgs e)
@@ -2322,7 +2314,7 @@ namespace UAS_LabelMachine
             string month = "0";
             string day = "0";
             string date = "";
-            LogicHandler.GetTimeFromDatecode(dh1,datecode, pi_cardcode.Text, out year, out month, out day, out date);
+            LogicHandler.GetTimeFromDatecode(dh1, datecode, pi_cardcode.Text, out year, out month, out day, out date);
             adh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "update");
             LoadGridData();
             setvalue.FindForm().Close();
@@ -2338,7 +2330,7 @@ namespace UAS_LabelMachine
             string month = "0";
             string day = "0";
             string date = "";
-            LogicHandler.GetTimeFromDatecode(dh1,datecode, pi_cardcode.Text, out year, out month, out day, out date);
+            LogicHandler.GetTimeFromDatecode(dh1, datecode, pi_cardcode.Text, out year, out month, out day, out date);
             adh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "update");
             LoadGridData();
             DataTable pibid_dt = (DataTable)adh.ExecuteSql("select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno, "select");
@@ -2361,17 +2353,21 @@ namespace UAS_LabelMachine
 
         private void SetOutboxBarcode()
         {
-            string year = "0";
-            string month = "0";
-            string day = "0";
-            string date = "";
+            string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
             //解析DateCode,将值设置到年月日
             try
             {
-                LogicHandler.GetTimeFromDatecode(dh,DateCode, pi_cardcode.Text, out year, out month, out day, out date);
-                LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
-                LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
-                LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
+                DataRow[] dr = LabelInfDataTable.Select("pib_id=" + pib_id);
+                if (dr.Length > 0)
+                {
+                    try
+                    {
+                        dr[0]["pib_year"] = year;
+                        dr[0]["pib_month"] = month;
+                        dr[0]["pib_day"] = day;
+                    }
+                    catch { }
+                }
             }
             catch (Exception) { }
             int outboxcode1 = int.Parse(Process_midboxcode.Text == "" ? "1" : Process_midboxcode.Text);
@@ -2543,7 +2539,6 @@ namespace UAS_LabelMachine
             //设置中盒外箱号
             LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value = outboxcode1;
             LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = outboxcode2;
-            string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
             if (SingleLabelAutoPrint.Checked)
                 adh.ExecuteSql("update prodiobarcode set pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "',pib_outboxcode2=" + outboxcode2 + ",pib_outboxcode1=" + outboxcode1 + ",pib_custoutboxcode='" + OutBoxBarCode + "',pib_custmidboxcode='" + MidBoxBarCode + "',pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "',pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1 where pib_id=" + pib_id, "update");
             else

BIN
UAS-出货标签管理(吉利通)/tool/LabelPrint.db3


BIN
UAS-出货标签管理(吉利通)/tool/System.Data.SQLite.dll


+ 17 - 29
UAS-出货标签管理/PublicMethod/DataHelper.cs

@@ -33,39 +33,27 @@ namespace UAS_LabelMachine
         ////需要显示的账套
         //public static readonly string Masters = "YHND_SZ,YHND_HK,DATACENTER";
 
-        ////华商龙外网地址
-        //private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YITOA_DATACENTER;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=218.18.115.198)(PORT=1523)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
-        ////华商龙ERP地址
-        //public static readonly string ERPAddesss = "http://218.18.115.198:8888/ERP/";
-        ////华商龙FTP
-        //public static readonly string FTPAdress = "ftp://218.18.115.198:21|Print|Administrator1@#";
-        ////Oracle端口
-        //public static readonly string OraclePort = "1523";
-        ////需要显示的账套
-        //public static readonly string Masters = "XSQ,N_YITOA_YWC,ZXN,N_YITOA_LHCT,N_YITOA_CT,N_CHL,N_YITOA_HK,N_HUASL_SHTL,N_WILICHK,N_WILIC,N_E_SHINE_SH,N_SHBJ,N_BJKG,N_HUASL,N_HUASL_QD,N_HUASL_XM,N_HUASL_SZ";
+        //华商龙外网地址
+        private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YITOA_DATACENTER;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=218.18.115.198)(PORT=1523)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        //华商龙ERP地址
+        public static readonly string ERPAddesss = "http://218.18.115.198:8888/ERP/";
+        //华商龙FTP
+        public static readonly string FTPAdress = "ftp://218.18.115.198:21|Print|Administrator1@#";
+        //Oracle端口
+        public static readonly string OraclePort = "1523";
+        //需要显示的账套
+        public static readonly string Masters = "XSQ,N_YITOA_YWC,ZXN,N_YITOA_LHCT,N_YITOA_CT,N_CHL,N_YITOA_HK,N_HUASL_SHTL,N_WILICHK,N_WILIC,N_E_SHINE_SH,N_SHBJ,N_BJKG,N_HUASL,N_HUASL_QD,N_HUASL_XM,N_HUASL_SZ";
 
-        ////泽天外网地址
-        //private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=ZT_TEST;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.47.41.2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
-        ////泽天ERP地址
-        //public static readonly string ERPAddesss = "http://183.47.41.2:8099/ERP/";
-        ////泽天FTP
-        //public static readonly string FTPAdress = "ftp://183.47.41.3:21|uas|Zt2018";
+        ////UAS测试地址
+        //private readonly string ConnectionStrings = "Data Source=192.168.253.6/orcl;User ID=UAS_TEST;PassWord=select!#%*(";
+        ////UAS测试地址
+        //public static readonly string ERPAddesss = "http://192.168.253.6/uas_test/";
+        ////UAS测试FTP
+        //public static readonly string FTPAdress = "ftp://192.168.253.9/PrintFile|mesconfig|Administrator1@#";
         ////Oracle端口
         //public static readonly string OraclePort = "1521";
         ////需要显示的账套
-        //public static readonly string Masters = "ZT_TEST";
-        //用户选择的数据库的连接字符串
-
-        //UAS测试地址
-        private readonly string ConnectionStrings = "Data Source=192.168.253.6/orcl;User ID=UAS_TEST;PassWord=select!#%*(";
-        //UAS测试地址
-        public static readonly string ERPAddesss = "http://192.168.253.6/uas_test/";
-        //UAS测试FTP
-        public static readonly string FTPAdress = "ftp://192.168.253.9/PrintFile|mesconfig|Administrator1@#";
-        //Oracle端口
-        public static readonly string OraclePort = "1521";
-        //需要显示的账套
-        public static readonly string Masters = "UAS_TEST";
+        //public static readonly string Masters = "UAS_TEST";
         public static string DBConnectionString;
         static OracleConnection connection = null;
         static OracleCommand command = null;

+ 16 - 77
UAS-出货标签管理/UAS_出货标签管理.cs

@@ -129,8 +129,6 @@ namespace UAS_LabelMachine
         /*用于存放采集项目的Grid信息*/
         Dictionary<string, Dictionary<string, string>> SiItem;
         int CloumnCount = 0;
-        /*需要重绘的Cell*/
-        Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
         //使用二维数组进行排序
         ArrayList<ArrayList<string>> ScanData;
         ArrayList<string> GetData;
@@ -537,20 +535,9 @@ namespace UAS_LabelMachine
                             {
                                 dt.Rows[i]["pib_lotno"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
                                 dt.Rows[i]["pib_datecode"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
-                                //将采集数据正确的Cell添加到键值对中
-                                if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"]))
-                                {
-                                    PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]);
-                                }
-                                PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true);
-                                if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"]))
-                                {
-                                    PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]);
-                                }
-                                PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true);
-                                LabelInf.Refresh();
                                 LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
                                 LabelInf.Rows[i].Cells["Choose"].Value = true;
+                                LabelInf.Invalidate();
                                 //当前行的索引随循环增长
                                 CurrentRowIndex = i;
                                 if (SingleLabelAutoPrint.Checked)
@@ -576,20 +563,10 @@ namespace UAS_LabelMachine
                             dt.Rows[i]["pib_lotno"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
                             dt.Rows[i]["pib_datecode"] = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
                             CurrentRowIndex = i;
-                            //将采集数据正确的Cell添加到键值对中
-                            if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"]))
-                            {
-                                PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]);
-                            }
-                            PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true);
-                            if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"]))
-                            {
-                                PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]);
-                            }
-                            PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true);
                             LabelInf.Refresh();
                             LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
                             LabelInf.Rows[i].Cells["Choose"].Value = true;
+                            LabelInf.Invalidate();
                             SetOutBoxCode2(true);
                         }
                     }
@@ -597,6 +574,7 @@ namespace UAS_LabelMachine
                     {
                         LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
                         LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
+                        LabelInf.Invalidate();
                         //勾选了单盘自动打印
                         if (SingleLabelAutoPrint.Checked)
                         {
@@ -772,17 +750,11 @@ namespace UAS_LabelMachine
                             {
                                 CollectVeProdCodePass = false;
                                 //添加需要重绘的Cell
-                                if (PaintCell.ContainsKey(cell))
-                                    PaintCell.Remove(cell);
-                                PaintCell.Add(cell, false);
                                 LabelInf.Refresh();
                                 MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
                             }
                             else
                             {
-                                if (PaintCell.ContainsKey(cell))
-                                    PaintCell.Remove(cell);
-                                PaintCell.Add(cell, true);
                                 LabelInf.Refresh();
                                 CollectVeProdCodePass = true;
                             }
@@ -796,18 +768,11 @@ namespace UAS_LabelMachine
                             if (cell.Value.ToString() != Matchstr)
                             {
                                 CollectQTYPass = false;
-                                //添加需要重绘的Cell
-                                if (PaintCell.ContainsKey(cell))
-                                    PaintCell.Remove(cell);
-                                PaintCell.Add(cell, false);
                                 LabelInf.Refresh();
                                 MessageLog.AppendText(">>数量不匹配\n", Color.Red);
                             }
                             else
                             {
-                                if (PaintCell.ContainsKey(cell))
-                                    PaintCell.Remove(cell);
-                                PaintCell.Add(cell, true);
                                 LabelInf.Refresh();
                                 CollectQTYPass = true;
                             }
@@ -821,18 +786,11 @@ namespace UAS_LabelMachine
                             if (cell.Value.ToString() != Matchstr)
                             {
                                 CollectQTYPass = false;
-                                //添加需要重绘的Cell
-                                if (PaintCell.ContainsKey(cell))
-                                    PaintCell.Remove(cell);
-                                PaintCell.Add(cell, false);
                                 LabelInf.Refresh();
                                 MessageLog.AppendText(">>品牌不匹配\n", Color.Red);
                             }
                             else
                             {
-                                if (PaintCell.ContainsKey(cell))
-                                    PaintCell.Remove(cell);
-                                PaintCell.Add(cell, true);
                                 LabelInf.Refresh();
                                 CollectQTYPass = true;
                             }
@@ -1148,7 +1106,7 @@ namespace UAS_LabelMachine
                     PI_ID = dt.Rows[0]["pi_id"].ToString();
                     if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
                     {
-                        string[] param = new string[] { PI_ID, "", "" };
+                        string[] param = new string[] { PI_ID, "" };
                         dh.CallProcedure("GetCustBarcode", param);
                     }
                     LoadGridData(sender, e);
@@ -1520,6 +1478,7 @@ namespace UAS_LabelMachine
                             MessageBox.Show("单盘打印范围错误");
                             return;
                         }
+                        LabelInf.Invalidate();
                     }
                     catch (Exception)
                     {
@@ -2054,38 +2013,18 @@ namespace UAS_LabelMachine
                 }
                 if (e.RowIndex >= 0)
                 {
-                    //重绘制定的Cell,表示采集的数量不匹配
-                    if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_qty"]))
-                    {
-                        SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
-                        e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_qty"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
-                        Rectangle border = e.CellBounds;
-                        border.Width -= 1;
-                        e.Graphics.DrawRectangle(Pens.Black, border);
-                        e.PaintContent(e.CellBounds);
-                        e.Handled = true;
-                    }
-                    //表示采集的供应商物料编号不匹配
-                    if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]))
+                    if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
                     {
-                        SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
-                        e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
-                        Rectangle border = e.CellBounds;
-                        border.Width -= 1;
-                        e.Graphics.DrawRectangle(Pens.Black, border);
-                        e.PaintContent(e.CellBounds);
-                        e.Handled = true;
-                    }
-                    //表示采集的供应商物料编号不匹配
-                    if (LabelInf.Columns[e.ColumnIndex].Name == "pib_brand" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_brand"]))
-                    {
-                        SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
-                        e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_brand"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
-                        Rectangle border = e.CellBounds;
-                        border.Width -= 1;
-                        e.Graphics.DrawRectangle(Pens.Black, border);
-                        e.PaintContent(e.CellBounds);
-                        e.Handled = true;
+                        if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
+                        {
+                            SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
+                            e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
+                            Rectangle border = e.CellBounds;
+                            border.Width -= 1;
+                            e.Graphics.DrawRectangle(Pens.Black, border);
+                            e.PaintContent(e.CellBounds);
+                            e.Handled = true;
+                        }
                     }
                 }
             }