瀏覽代碼

修改称量数取数字段

章政 8 年之前
父節點
當前提交
fb5d3ae3da

+ 239 - 95
UAS-MES/DataOperate/DataHelper.cs

@@ -5,7 +5,6 @@ using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
 using System.Text;
-using System.Windows;
 using UAS_MES.PublicMethod;
 
 namespace UAS_MES.DataOperate
@@ -17,7 +16,8 @@ namespace UAS_MES.DataOperate
         //用户选择的数据库的连接字符串
         public static string DBConnectionString;
         public static OracleConnection connection = null;
-        OracleCommand command = new OracleCommand();
+        OracleCommand command = null;
+        int ReconnectTime = 0;
         /// <summary>
         /// 执行构造函数的时候打开数据库的链接
         /// </summary>
@@ -30,28 +30,9 @@ namespace UAS_MES.DataOperate
                     connection = new OracleConnection(ConnectionStrings);
                 else
                     connection = new OracleConnection(DBConnectionString);
-                command.Connection = connection;
-                command.Connection.Open();
-                command.CommandTimeout = 0;
-            }
-            catch (Exception e)
-            {
-                if (DBConnectionString == null || DBConnectionString == ConnectionStrings)
-                    connection = new OracleConnection(ConnectionStrings);
-                else
-                    connection = new OracleConnection(DBConnectionString);
-                try
-                {
-                    command.Connection = connection;
-                    command.Connection.Open();
-                }
-                catch (Exception)
-                {
-                    return;
-                }
-                command.CommandTimeout = 0;
-                LogManager.DoLog(e.Message);
+                connection.Open();
             }
+            catch (Exception e) { LogManager.DoLog(e.Message); }
         }
 
         /// <summary>
@@ -60,12 +41,12 @@ namespace UAS_MES.DataOperate
         public DataTable GetColumnDataType(string TableName)
         {
             DataTable dt = new DataTable();
-            command.CommandText = "select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')";
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
+            command.Dispose();
             return dt;
         }
 
@@ -76,9 +57,7 @@ namespace UAS_MES.DataOperate
         {
             DataTable dt = new DataTable();
             string sql = "select " + Field + " from " + TableName + " where " + Condition;
-            Console.WriteLine(sql);
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter();
             ad.SelectCommand = command;
@@ -90,13 +69,13 @@ namespace UAS_MES.DataOperate
             {
                 connection = new OracleConnection(DBConnectionString);
                 connection.Open();
-                command.Connection = connection;
+                command = new OracleCommand(sql, connection);
                 ad = new OracleDataAdapter();
                 ad.SelectCommand = command;
                 ad.Fill(dt);
             }
             ad.Dispose();
-
+            command.Dispose();
             if (dt.Rows.Count > 0)
             {
                 return dt.Rows[0][0];
@@ -115,7 +94,6 @@ namespace UAS_MES.DataOperate
         /// <returns></returns>
         public object ExecutePrintSQL(string SQL, params string[] Parameters)
         {
-            command.Parameters.Clear();
             //按照?拆分数据,然后以:Param替换问号,同时添加参数
             string[] Param = SQL.Split('?');
             int ParamNum = Param.Length - 1;
@@ -127,8 +105,8 @@ namespace UAS_MES.DataOperate
                 {
                     sb.Append(Param[i] + ":Param" + i);
                 }
-                command.CommandText = sb.ToString();
-                command.CommandType = CommandType.Text;
+                command = new OracleCommand(sb.ToString(), connection);
+
                 for (int i = 0; i < ParamNum; i++)
                 {
                     command.Parameters.Add("Param" + i, OracleDbType.Varchar2, Parameters[i], ParameterDirection.Input);
@@ -137,6 +115,7 @@ namespace UAS_MES.DataOperate
                 DataTable dt = new DataTable();
                 ad.Fill(dt);
                 ad.Dispose();
+                command.Dispose();
                 return dt;
             }
             return "参数错误,请检查SQL语句";
@@ -150,12 +129,12 @@ namespace UAS_MES.DataOperate
         {
             DataTable dt = new DataTable();
             string sql = "select count(1) from " + TableName + " where " + Condition;
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
+            command.Dispose();
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -168,12 +147,13 @@ namespace UAS_MES.DataOperate
         {
             DataTable dt = new DataTable();
             string sql = "select count(1) from " + TableName;
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
+
             ad.Fill(dt);
             ad.Dispose();
+            command.Dispose();
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -186,9 +166,7 @@ namespace UAS_MES.DataOperate
             string sql = "select ";
             sql += AddField(Fields);
             sql += " from " + TableName + " where " + Condition + " and rownum=1";
-            Console.WriteLine(sql);
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             try
@@ -199,16 +177,32 @@ namespace UAS_MES.DataOperate
             {
                 connection = new OracleConnection(DBConnectionString);
                 connection.Open();
-                command.Connection = connection;
+                command = new OracleCommand(sql, connection);
                 ad = new OracleDataAdapter();
                 ad.SelectCommand = command;
                 ad.Fill(dt);
             }
             ad.Dispose();
-
+            command.Dispose();
             return dt;
         }
 
+        /// <summary>
+        /// 将DataTable导入到指定的表中
+        /// </summary>
+        /// <param name="DataTable"></param>
+        /// <param name="TableName"></param>
+        public void InsertDataTable(DataTable DataTable, string TableName)
+        {
+            for (int i = 0; i < DataTable.Rows.Count; i++)
+            {
+                for (int j = 0; j < DataTable.Columns.Count; j++)
+                {
+
+                }
+            }
+        }
+
         /// <summary>
         /// 按分页获取数据
         /// </summary>
@@ -237,13 +231,12 @@ namespace UAS_MES.DataOperate
                 else
                     sql.Append(" from " + TableName + ") A where ROWNUM <= " + CurrentPage * PageSize + ") where RN> " + (CurrentPage - 1) * PageSize);
             }
-            command.CommandText = sql.ToString();
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql.ToString(), connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
-
+            command.Dispose();
             dt.Columns.RemoveAt(0);
             foreach (DataColumn dc in dt.Columns)
             {
@@ -262,9 +255,8 @@ namespace UAS_MES.DataOperate
             string sql = "select ";
             sql += AddField(Fields);
             sql += " from " + TableName + " where " + Condition;
-            Console.WriteLine(sql);
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             try
@@ -275,13 +267,13 @@ namespace UAS_MES.DataOperate
             {
                 connection = new OracleConnection(DBConnectionString);
                 connection.Open();
-                command.Connection = connection;
+                command = new OracleCommand(sql, connection);
                 ad = new OracleDataAdapter();
                 ad.SelectCommand = command;
                 ad.Fill(dt);
             }
             ad.Dispose();
-
+            command.Dispose();
             return dt;
         }
 
@@ -294,9 +286,7 @@ namespace UAS_MES.DataOperate
             string sql = "select ";
             sql += Fields;
             sql += " from " + TableName;
-            Console.WriteLine(sql);
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.SelectCommand = command;
@@ -308,15 +298,177 @@ namespace UAS_MES.DataOperate
             {
                 connection = new OracleConnection(DBConnectionString);
                 connection.Open();
-                command.Connection = connection;
+                command = new OracleCommand(sql, connection);
                 ad = new OracleDataAdapter();
                 ad.SelectCommand = command;
                 ad.Fill(dt);
             }
             ad.Dispose();
+            command.Dispose();
             return dt;
         }
 
+        /// <summary>
+        /// 根据DataTable和指定的表名更新数据,如果需要保存新增的数据则需要传递一条Insert的SQL
+        /// </summary>
+        /// <param name="DataTable"></param>
+        /// <param name="TableName"></param>
+        /// <param name="Condition"></param>
+        public void UpDateTableByCondition(DataTable DataTable, string TableName, string PrimaryKey, params string[] sql)
+        {
+            if (DataTable == null)
+            {
+                return;
+            }
+            StringBuilder sb = new StringBuilder();
+            //预防插入的DataTable中存在不属于该表的列,在进行下一步操作之前全部剔除
+            DataTable data = (DataTable)ExecuteSql("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", "select");
+            //将所有的字段拼接起来
+            for (int i = 0; i < data.Rows.Count; i++)
+            {
+                sb.Append("#" + data.Rows[i]["Column_Name"].ToString());
+            }
+            //移除掉所有不属于该表的列
+            for (int i = DataTable.Columns.Count - 1; i >= 0; i--)
+            {
+                if (!sb.ToString().Contains(DataTable.Columns[i].ColumnName.ToUpper()))
+                {
+                    DataTable.Columns.RemoveAt(i);
+                }
+            }
+            sb.Clear();
+            //计算有多少个是新加的行,根据主键为空来进行判断
+            int NewRowCount = 0;
+            for (int i = 0; i < DataTable.Rows.Count; i++)
+            {
+                if (DataTable.Rows[i][PrimaryKey] == null || DataTable.Rows[i][PrimaryKey].ToString() == "")
+                {
+                    NewRowCount = NewRowCount + 1;
+                }
+            }
+            if (sql.Length > 0)
+            {
+                if (NewRowCount > 0)
+                {
+                    //获取参数的个数
+                    int paramsNum = sql[0].Split(':').Length - 1;
+                    //解析参数的数据
+                    string[] param = GetParamFromSQL(sql[0]);
+                    //新建一个二维数组去
+                    string[][] param_array = new string[paramsNum][];
+                    //实例化每个一维数组
+                    for (int i = 0; i < paramsNum; i++)
+                    {
+                        param_array[i] = new string[NewRowCount];
+                    }
+                    //设置每列参数的索引
+                    int num = 0;
+                    //变量所有的行,如果有主键为空的则移除,不为空的进行参数的拼接
+                    for (int i = DataTable.Rows.Count - 1; i >= 0; i--)
+                    {
+                        if (DataTable.Rows[i][PrimaryKey] == null || DataTable.Rows[i][PrimaryKey].ToString() == "")
+                        {
+                            //当为新添加行的时候才去设置参数,设置过后索引+1
+                            for (int j = 0; j < paramsNum; j++)
+                            {
+                                param_array[j][num] = DataTable.Rows[i][param[j]].ToString();
+                            }
+                            DataTable.Rows.RemoveAt(i);
+                            num++;
+                        }
+                    }
+                    BatchInsertDataTable(sql[0], param, param_array);
+                }
+            }
+            //不是新增行的启用更新的方法
+            sb.Append("update " + TableName + " set ");
+            //拼接语句,特殊处理日期
+
+            foreach (DataColumn dc in DataTable.Columns)
+            {
+                if (!dc.DataType.ToString().Equals("System.DateTime"))
+                {
+                    sb.Append(dc.Caption + "=:" + dc.Caption + ",");
+                }
+                else
+                {
+                    sb.Append(dc.Caption + "=:" + dc.Caption + ",");
+                }
+            }
+            sb.Remove(sb.Length - 1, 1);
+            sb.Append(" where " + PrimaryKey + "=:" + PrimaryKey);
+            command = new OracleCommand(sb.ToString(), connection);
+            OracleDataAdapter ad = new OracleDataAdapter(command);
+            // 参数的长度是DataTable的行数决定的
+            command.ArrayBindCount = DataTable.Rows.Count;
+            //默认全部是Varchar2类型的
+            OracleDbType ob = OracleDbType.Varchar2;
+            for (int i = 0; i < DataTable.Columns.Count; i++)
+            {
+                object[] param = new object[DataTable.Rows.Count];
+                for (int j = 0; j < DataTable.Rows.Count; j++)
+                {
+                    DateTime dt = DateTime.Now;
+                    if (DateTime.TryParse(DataTable.Rows[j][i].ToString(), out dt))
+                    {
+                        param[j] = dt;
+                        ob = OracleDbType.Date;
+                    }
+                    else
+                    {
+                        ob = OracleDbType.Varchar2;
+                        param[j] = DataTable.Rows[j][i];
+                    }
+                }
+                //添加批量更新的参数
+                command.Parameters.Add(new OracleParameter(DataTable.Columns[i].Caption, ob, param, ParameterDirection.Input));
+            }
+            ad.UpdateCommand = command;
+            ad.Update(DataTable);
+            ad.Dispose();
+            command.Dispose();
+        }
+
+        /// <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>
@@ -326,13 +478,13 @@ namespace UAS_MES.DataOperate
         public bool CheckExist(string TableName, string Condition)
         {
             string sql = "select count(1) from " + TableName + " where " + Condition;
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             DataTable dt = new DataTable();
             ad.Fill(dt);
             ad.Dispose();
+            command.Dispose();
             return int.Parse(dt.Rows[0][0].ToString()) > 0;
         }
 
@@ -344,10 +496,8 @@ namespace UAS_MES.DataOperate
         /// <returns></returns>
         public object ExecuteSql(string SQL, string Type, params object[] names)
         {
-            command.Parameters.Clear();
             object result = null;
-            command.CommandText = SQL;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(SQL, connection);
             Reconnect(command);
             //用来拼接参数的
             if (names.Length > 0)
@@ -375,7 +525,6 @@ namespace UAS_MES.DataOperate
                 for (int i = 0; i < addpar.Length; i++)
                     command.Parameters.Add(new OracleParameter(addpar[i].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
             }
-            Console.WriteLine(SQL);
             switch (Type.ToUpper())
             {
                 case "SELECT":
@@ -389,7 +538,7 @@ namespace UAS_MES.DataOperate
                     {
                         connection = new OracleConnection(DBConnectionString);
                         connection.Open();
-                        command.Connection = connection;
+                        command = new OracleCommand(SQL, connection);
                         ad = new OracleDataAdapter();
                         ad.SelectCommand = command;
                         ad.Fill((DataTable)result);
@@ -432,6 +581,7 @@ namespace UAS_MES.DataOperate
                     }
                     break;
             }
+            command.Dispose();
             return result;
         }
 
@@ -442,17 +592,16 @@ namespace UAS_MES.DataOperate
         public void CheckSQL(string SQL)
         {
             SQL = SQL.Replace("?", ":Param");
-            command.CommandText = SQL;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(SQL, connection);
             command.ExecuteNonQuery();
+            command.Dispose();
         }
 
         public int GetDistinctRowCount(string TableName, string Field)
         {
             DataTable dt = new DataTable();
             string sql = "select distinct count('" + Field + "') from " + TableName;
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             try
@@ -463,12 +612,13 @@ namespace UAS_MES.DataOperate
             {
                 connection = new OracleConnection(DBConnectionString);
                 connection.Open();
-                command.Connection = connection;
+                command = new OracleCommand(sql, connection);
                 ad = new OracleDataAdapter();
                 ad.SelectCommand = command;
                 ad.Fill(dt);
             }
             ad.Dispose();
+            command.Dispose();
             return int.Parse(dt.Rows[0][0].ToString());
         }
 
@@ -492,25 +642,23 @@ namespace UAS_MES.DataOperate
         /// <param name="DeleteID">需要删除主键ID的数组</param>
         public void DeleteDataByID(string TableName, string ID, string[] DeleteID)
         {
-            command.Parameters.Clear();
             string sql = "delete from " + TableName + " where " + ID + " =:DeleteID";
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             command.ArrayBindCount = DeleteID.Length;
             command.Parameters.Add(new OracleParameter("DeleteID", OracleDbType.Long, DeleteID, ParameterDirection.Input));
             try
             {
                 command.ExecuteNonQuery();
-                command.ArrayBindCount = 0;
             }
             catch (Exception)
             {
                 command.Connection = new OracleConnection(DBConnectionString);
                 command.Connection.Open();
                 command.ExecuteNonQuery();
-                command.ArrayBindCount = 0;
             }
+            command.Dispose();
         }
 
         /// <summary>
@@ -648,10 +796,10 @@ namespace UAS_MES.DataOperate
         /// <param name="names"></param>
         public void BatchInsert(string sql, params object[][] names)
         {
-            command.Parameters.Clear();
-            command.CommandText = sql;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             command.ArrayBindCount = names[1].Length;
+
             //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
             //将第一个数组的下标固定为0作为循环添加的参数的名称
             for (int i = 1; i <= names[0].Length; i++)
@@ -661,21 +809,19 @@ namespace UAS_MES.DataOperate
             try
             {
                 command.ExecuteNonQuery();
-                command.ArrayBindCount = 0;
             }
             catch (Exception)
             {
                 command.Connection = new OracleConnection(DBConnectionString);
                 command.Connection.Open();
                 command.ExecuteNonQuery();
-                command.ArrayBindCount = 0;
             }
+            command.Dispose();
         }
 
         public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
         {
-            command.Parameters.Clear();
-            command.CommandText = sql;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             command.ArrayBindCount = param1[0].Length;
             //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
@@ -687,15 +833,14 @@ namespace UAS_MES.DataOperate
             try
             {
                 command.ExecuteNonQuery();
-                command.ArrayBindCount = 0;
             }
             catch (Exception)
             {
                 command.Connection = new OracleConnection(DBConnectionString);
                 command.Connection.Open();
                 command.ExecuteNonQuery();
-                command.ArrayBindCount = 0;
             }
+            command.Dispose();
         }
 
         /// <summary>
@@ -753,6 +898,7 @@ namespace UAS_MES.DataOperate
             return dt1;
         }
 
+
         /// <summary>
         /// 通过条件更新
         /// </summary>
@@ -762,8 +908,7 @@ namespace UAS_MES.DataOperate
         public string UpdateByCondition(string TableName, string update, string condition)
         {
             string sql = "update " + TableName + " set " + update + " where " + condition;
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             try
             {
@@ -775,6 +920,7 @@ namespace UAS_MES.DataOperate
                 command.Connection.Open();
                 command.ExecuteNonQuery();
             }
+            command.Dispose();
             return sql;
         }
 
@@ -785,11 +931,11 @@ namespace UAS_MES.DataOperate
         /// <param name="param"></param>
         public void CallProcedure(string ProcedureName, ref string[] param)
         {
-            command.Parameters.Clear();
+            command = new OracleCommand(ProcedureName);
+            command.Connection = connection;
+            Reconnect(command);
             command.CommandText = ProcedureName;
             command.CommandType = CommandType.StoredProcedure;
-            command.ArrayBindCount = 0;
-            Reconnect(command);
             for (int i = 0; i < param.Length; i++)
                 command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
             try
@@ -798,14 +944,13 @@ namespace UAS_MES.DataOperate
             }
             catch (Exception)
             {
-                Console.WriteLine(command.Parameters.Count);
                 command.Connection = new OracleConnection(DBConnectionString);
                 command.Connection.Open();
                 command.ExecuteNonQuery();
             }
             for (int i = 0; i < command.Parameters.Count; i++)
                 param[i] = command.Parameters[i].Value.ToString();
-
+            command.Dispose();
         }
 
         /// <summary>
@@ -815,6 +960,8 @@ namespace UAS_MES.DataOperate
         public void ExecuteSQLTran(params string[] SQL)
         {
             OracleTransaction tx = connection.BeginTransaction();
+            command = new OracleCommand();
+            command.Connection = connection;
             command.Transaction = tx;
             try
             {
@@ -823,7 +970,6 @@ namespace UAS_MES.DataOperate
                     if (!String.IsNullOrEmpty(sql))
                     {
                         command.CommandText = sql;
-                        command.CommandType = CommandType.Text;
                         try
                         {
                             command.ExecuteNonQuery();
@@ -843,6 +989,7 @@ namespace UAS_MES.DataOperate
                 tx.Rollback();
                 throw new Exception(E.Message);
             }
+            command.Dispose();
         }
 
         /// <summary>
@@ -892,8 +1039,7 @@ namespace UAS_MES.DataOperate
         public object GetLabelParam(string sql)
         {
             DataTable dt = new DataTable();
-            command.CommandText = sql;
-            command.CommandType = CommandType.Text;
+            command = new OracleCommand(sql, connection);
             Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter();
             ad.SelectCommand = command;
@@ -905,7 +1051,7 @@ namespace UAS_MES.DataOperate
             {
                 connection = new OracleConnection(DBConnectionString);
                 connection.Open();
-                command.Connection = connection;
+                command = new OracleCommand(sql, connection);
                 ad = new OracleDataAdapter();
                 ad.SelectCommand = command;
                 ad.Fill(dt);
@@ -913,11 +1059,12 @@ namespace UAS_MES.DataOperate
             if (dt.Rows.Count > 0)
             {
                 ad.Dispose();
-
+                command.Dispose();
                 return dt.Rows[0][0];
             }
             else
             {
+                command.Dispose();
                 return "";
             }
         }
@@ -955,10 +1102,7 @@ namespace UAS_MES.DataOperate
 
         public void Dispose()
         {
-            if (command != null)
-                command.Dispose();
-            if (connection != null)
-                connection.Dispose();
+
         }
 
         private void Reconnect(OracleCommand cmd)

+ 60 - 33
UAS-MES/FunctionCode/Make/Make_CartonBoxWeigh.Designer.cs

@@ -30,7 +30,7 @@
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Make_CartonBoxWeigh));
             this.ma_code_label = new System.Windows.Forms.Label();
-            this.mcd_okqty = new System.Windows.Forms.Label();
+            this.mcd_inqty = new System.Windows.Forms.Label();
             this.mcd_okqty_label = new System.Windows.Forms.Label();
             this.panel6 = new System.Windows.Forms.Panel();
             this.pr_cartongw_label = new System.Windows.Forms.Label();
@@ -49,6 +49,8 @@
             this.AutoPrint = new System.Windows.Forms.CheckBox();
             this.PrintNum = new System.Windows.Forms.NumericUpDown();
             this.label2 = new System.Windows.Forms.Label();
+            this.ComList = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
+            this.BaudRate = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.PrinterList = new UAS_MES.CustomControl.ComBoxWithFocus.PrinterCombox();
             this.StartWeight = new UAS_MES.CustomControl.ButtonUtil.NormalButton();
             this.Confirm = new UAS_MES.CustomControl.ButtonUtil.NormalButton();
@@ -64,8 +66,8 @@
             this.pr_cartongw = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.pr_code = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.OperateResult = new UAS_MES.CustomControl.RichText.RichTextAutoBottom();
-            this.BaudRate = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
-            this.ComList = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
+            this.mcd_waitqty = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
+            this.mcd_waitqty_label = new System.Windows.Forms.Label();
             this.panel6.SuspendLayout();
             this.panel4.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.PrintNum)).BeginInit();
@@ -81,14 +83,14 @@
             this.ma_code_label.TabIndex = 97;
             this.ma_code_label.Text = "制造单号";
             // 
-            // mcd_okqty
+            // mcd_inqty
             // 
-            this.mcd_okqty.AutoSize = true;
-            this.mcd_okqty.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.mcd_okqty.Location = new System.Drawing.Point(105, 487);
-            this.mcd_okqty.Name = "mcd_okqty";
-            this.mcd_okqty.Size = new System.Drawing.Size(0, 27);
-            this.mcd_okqty.TabIndex = 94;
+            this.mcd_inqty.AutoSize = true;
+            this.mcd_inqty.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.mcd_inqty.Location = new System.Drawing.Point(105, 487);
+            this.mcd_inqty.Name = "mcd_inqty";
+            this.mcd_inqty.Size = new System.Drawing.Size(0, 27);
+            this.mcd_inqty.TabIndex = 94;
             // 
             // mcd_okqty_label
             // 
@@ -284,6 +286,30 @@
             this.label2.TabIndex = 171;
             this.label2.Text = "打印张数";
             // 
+            // ComList
+            // 
+            this.ComList.AutoSize = true;
+            this.ComList.CutLength = null;
+            this.ComList.Location = new System.Drawing.Point(937, 55);
+            this.ComList.MaximumSize = new System.Drawing.Size(150, 0);
+            this.ComList.Name = "ComList";
+            this.ComList.Size = new System.Drawing.Size(47, 12);
+            this.ComList.TabIndex = 173;
+            this.ComList.Text = "ComList";
+            this.ComList.Visible = false;
+            // 
+            // BaudRate
+            // 
+            this.BaudRate.AutoSize = true;
+            this.BaudRate.CutLength = null;
+            this.BaudRate.Location = new System.Drawing.Point(937, 39);
+            this.BaudRate.MaximumSize = new System.Drawing.Size(150, 0);
+            this.BaudRate.Name = "BaudRate";
+            this.BaudRate.Size = new System.Drawing.Size(53, 12);
+            this.BaudRate.TabIndex = 172;
+            this.BaudRate.Text = "BaudRate";
+            this.BaudRate.Visible = false;
+            // 
             // PrinterList
             // 
             this.PrinterList.Location = new System.Drawing.Point(936, 111);
@@ -332,7 +358,7 @@
             // 
             this.pd_barcode.AutoSize = true;
             this.pd_barcode.CutLength = null;
-            this.pd_barcode.Location = new System.Drawing.Point(934, 14);
+            this.pd_barcode.Location = new System.Drawing.Point(937, 21);
             this.pd_barcode.MaximumSize = new System.Drawing.Size(150, 0);
             this.pd_barcode.Name = "pd_barcode";
             this.pd_barcode.Size = new System.Drawing.Size(65, 12);
@@ -487,35 +513,34 @@
             this.OperateResult.TabIndex = 87;
             this.OperateResult.Text = "";
             // 
-            // BaudRate
+            // mcd_waitqty
             // 
-            this.BaudRate.AutoSize = true;
-            this.BaudRate.CutLength = null;
-            this.BaudRate.Location = new System.Drawing.Point(937, 39);
-            this.BaudRate.MaximumSize = new System.Drawing.Size(150, 0);
-            this.BaudRate.Name = "BaudRate";
-            this.BaudRate.Size = new System.Drawing.Size(53, 12);
-            this.BaudRate.TabIndex = 172;
-            this.BaudRate.Text = "BaudRate";
-            this.BaudRate.Visible = false;
+            this.mcd_waitqty.AutoSize = true;
+            this.mcd_waitqty.CutLength = null;
+            this.mcd_waitqty.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.mcd_waitqty.Location = new System.Drawing.Point(106, 539);
+            this.mcd_waitqty.MaximumSize = new System.Drawing.Size(150, 0);
+            this.mcd_waitqty.Name = "mcd_waitqty";
+            this.mcd_waitqty.Size = new System.Drawing.Size(0, 27);
+            this.mcd_waitqty.TabIndex = 175;
             // 
-            // ComList
+            // mcd_waitqty_label
             // 
-            this.ComList.AutoSize = true;
-            this.ComList.CutLength = null;
-            this.ComList.Location = new System.Drawing.Point(937, 55);
-            this.ComList.MaximumSize = new System.Drawing.Size(150, 0);
-            this.ComList.Name = "ComList";
-            this.ComList.Size = new System.Drawing.Size(47, 12);
-            this.ComList.TabIndex = 173;
-            this.ComList.Text = "ComList";
-            this.ComList.Visible = false;
+            this.mcd_waitqty_label.AutoSize = true;
+            this.mcd_waitqty_label.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.mcd_waitqty_label.Location = new System.Drawing.Point(31, 539);
+            this.mcd_waitqty_label.Name = "mcd_waitqty_label";
+            this.mcd_waitqty_label.Size = new System.Drawing.Size(52, 27);
+            this.mcd_waitqty_label.TabIndex = 174;
+            this.mcd_waitqty_label.Text = "待称";
             // 
             // Make_CartonBoxWeigh
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1072, 608);
+            this.Controls.Add(this.mcd_waitqty);
+            this.Controls.Add(this.mcd_waitqty_label);
             this.Controls.Add(this.ComList);
             this.Controls.Add(this.BaudRate);
             this.Controls.Add(this.label2);
@@ -534,7 +559,7 @@
             this.Controls.Add(this.pr_detail);
             this.Controls.Add(this.ma_salecode);
             this.Controls.Add(this.ma_code_label);
-            this.Controls.Add(this.mcd_okqty);
+            this.Controls.Add(this.mcd_inqty);
             this.Controls.Add(this.mcd_okqty_label);
             this.Controls.Add(this.Clean);
             this.Controls.Add(this.normalButton1);
@@ -571,7 +596,7 @@
         private CustomControl.ValueLabel.ValueLabel pr_detail;
         private CustomControl.ValueLabel.ValueLabel ma_salecode;
         private System.Windows.Forms.Label ma_code_label;
-        private System.Windows.Forms.Label mcd_okqty;
+        private System.Windows.Forms.Label mcd_inqty;
         private System.Windows.Forms.Label mcd_okqty_label;
         private CustomControl.ButtonUtil.NormalButton Clean;
         private CustomControl.ButtonUtil.NormalButton normalButton1;
@@ -602,5 +627,7 @@
         private System.Windows.Forms.Label label2;
         private CustomControl.ValueLabel.ValueLabel BaudRate;
         private CustomControl.ValueLabel.ValueLabel ComList;
+        private CustomControl.ValueLabel.ValueLabel mcd_waitqty;
+        private System.Windows.Forms.Label mcd_waitqty_label;
     }
 }

+ 3 - 1
UAS-MES/FunctionCode/Make/Make_CartonBoxWeigh.cs

@@ -85,7 +85,7 @@ namespace UAS_MES.Make
                 //根据箱号查询表单数据
                 pd_barcode.Text = dh.getFieldDataByCondition("makeserial left join package on ms_prodcode=pa_prodcode", "ms_sncode", "pa_outboxcode='" + outboxcode.Text + "'").ToString();
                 sql.Clear();
-                sql.Append("select pa_totalqty,pd_barcode,ma_code,mcd_okqty,ma_qty,ma_qty-mcd_okqty as mcd_waitqty,ma_salecode,pr_detail,pr_cartonunit,pr_code,pr_cartongw,");
+                sql.Append("select pa_totalqty,pd_barcode,ma_code,mcd_inqty,ma_qty,ma_qty-mcd_inqty as mcd_waitqty,ma_salecode,pr_detail,pr_cartonunit,pr_code,pr_cartongw,");
                 sql.Append("pr_cartonmaxw,pr_cartonminw from package left join product on pr_code=pa_prodcode left join make on ma_prodcode=pr_code left join makecraftdetail ");
                 sql.Append("on mcd_macode=ma_code left join  packagedetail on pd_outboxcode=pa_outboxcode where pa_outboxcode='" + outboxcode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
                 dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
@@ -214,5 +214,7 @@ namespace UAS_MES.Make
                 indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
             }
         }
+
+   
     }
 }

+ 29 - 29
UAS-MES/FunctionCode/Make/Make_ColorBoxWeigh.Designer.cs

@@ -35,6 +35,8 @@
             this.pr_code_label = new System.Windows.Forms.Label();
             this.pr_colorboxunit = new System.Windows.Forms.Label();
             this.panel6 = new System.Windows.Forms.Panel();
+            this.pr_colorboxgw = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
+            this.pr_code = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.label22 = new System.Windows.Forms.Label();
             this.weight = new System.Windows.Forms.Label();
             this.panel4 = new System.Windows.Forms.Panel();
@@ -68,8 +70,6 @@
             this.Clean = new UAS_MES.CustomControl.ButtonUtil.NormalButton();
             this.normalButton1 = new UAS_MES.CustomControl.ButtonUtil.NormalButton();
             this.sncode = new UAS_MES.CustomControl.TextBoxWithIcon.EnterTextBox();
-            this.pr_colorboxgw = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
-            this.pr_code = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.OperateResult = new UAS_MES.CustomControl.RichText.RichTextAutoBottom();
             this.BaudRate = new System.Windows.Forms.Label();
             this.ComList = new System.Windows.Forms.Label();
@@ -85,7 +85,7 @@
             // 
             this.mcd_waitqty_label.AutoSize = true;
             this.mcd_waitqty_label.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.mcd_waitqty_label.Location = new System.Drawing.Point(14, 512);
+            this.mcd_waitqty_label.Location = new System.Drawing.Point(14, 510);
             this.mcd_waitqty_label.Name = "mcd_waitqty_label";
             this.mcd_waitqty_label.Size = new System.Drawing.Size(52, 27);
             this.mcd_waitqty_label.TabIndex = 65;
@@ -146,6 +146,31 @@
             this.panel6.Size = new System.Drawing.Size(381, 124);
             this.panel6.TabIndex = 62;
             // 
+            // pr_colorboxgw
+            // 
+            this.pr_colorboxgw.AutoSize = true;
+            this.pr_colorboxgw.CutLength = null;
+            this.pr_colorboxgw.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.pr_colorboxgw.Location = new System.Drawing.Point(141, 77);
+            this.pr_colorboxgw.MaximumSize = new System.Drawing.Size(150, 0);
+            this.pr_colorboxgw.Name = "pr_colorboxgw";
+            this.pr_colorboxgw.Size = new System.Drawing.Size(0, 27);
+            this.pr_colorboxgw.TabIndex = 80;
+            this.pr_colorboxgw.Tag = "1";
+            // 
+            // pr_code
+            // 
+            this.pr_code.AutoSize = true;
+            this.pr_code.CutLength = null;
+            this.pr_code.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.pr_code.Location = new System.Drawing.Point(141, 26);
+            this.pr_code.MaximumSize = new System.Drawing.Size(150, 0);
+            this.pr_code.Name = "pr_code";
+            this.pr_code.Size = new System.Drawing.Size(0, 27);
+            this.pr_code.TabIndex = 79;
+            this.pr_code.Tag = "1";
+            this.pr_code.TextChanged += new System.EventHandler(this.pr_code_TextChanged);
+            // 
             // label22
             // 
             this.label22.AutoSize = true;
@@ -407,7 +432,7 @@
             this.mcd_waitqty.AutoSize = true;
             this.mcd_waitqty.CutLength = null;
             this.mcd_waitqty.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.mcd_waitqty.Location = new System.Drawing.Point(89, 512);
+            this.mcd_waitqty.Location = new System.Drawing.Point(89, 510);
             this.mcd_waitqty.MaximumSize = new System.Drawing.Size(150, 0);
             this.mcd_waitqty.Name = "mcd_waitqty";
             this.mcd_waitqty.Size = new System.Drawing.Size(0, 27);
@@ -543,31 +568,6 @@
             this.sncode.TabIndex = 57;
             this.sncode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.sncode_KeyDown);
             // 
-            // pr_colorboxgw
-            // 
-            this.pr_colorboxgw.AutoSize = true;
-            this.pr_colorboxgw.CutLength = null;
-            this.pr_colorboxgw.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.pr_colorboxgw.Location = new System.Drawing.Point(141, 77);
-            this.pr_colorboxgw.MaximumSize = new System.Drawing.Size(150, 0);
-            this.pr_colorboxgw.Name = "pr_colorboxgw";
-            this.pr_colorboxgw.Size = new System.Drawing.Size(0, 27);
-            this.pr_colorboxgw.TabIndex = 80;
-            this.pr_colorboxgw.Tag = "1";
-            // 
-            // pr_code
-            // 
-            this.pr_code.AutoSize = true;
-            this.pr_code.CutLength = null;
-            this.pr_code.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.pr_code.Location = new System.Drawing.Point(141, 26);
-            this.pr_code.MaximumSize = new System.Drawing.Size(150, 0);
-            this.pr_code.Name = "pr_code";
-            this.pr_code.Size = new System.Drawing.Size(0, 27);
-            this.pr_code.TabIndex = 79;
-            this.pr_code.Tag = "1";
-            this.pr_code.TextChanged += new System.EventHandler(this.pr_code_TextChanged);
-            // 
             // OperateResult
             // 
             this.OperateResult.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

+ 7 - 1
UAS-MES/FunctionCode/Make/Make_ColorBoxWeigh.cs

@@ -68,7 +68,7 @@ namespace UAS_MES.Make
             if (e.KeyCode == Keys.Enter)
             {
                 sql.Clear();
-                sql.Append("select ms_makecode,mcd_okqty,ma_qty,ma_qty-mcd_okqty as mcd_waitqty,ma_salecode,pr_detail,pr_colorboxunit,pr_code,pr_colorboxgw,");
+                sql.Append("select ms_makecode,mcd_inqty,ma_qty,ma_qty-mcd_inqty as mcd_waitqty,ma_salecode,pr_detail,pr_colorboxunit,pr_code,pr_colorboxgw,");
                 sql.Append("pr_colorboxunit,pr_colorboxmaxw,pr_colorboxminw from makeserial left join make on ms_makecode=ma_code left join product on ");
                 sql.Append("ms_prodcode=pr_code left join makecraftdetail on ms_makecode=mcd_macode where ms_sncode='" + sncode.Text + "'");
                 dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
@@ -231,5 +231,11 @@ namespace UAS_MES.Make
                 indate[i] = Convert.ToDateTime(dt.Rows[i]["pl_indate"].ToString());
             }
         }
+
+        private void LoadCollectNum()
+        {
+            DataTable dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_waitqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ms_makecode.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
+            BaseUtil.SetFormValue(Controls, dt);
+        }
     }
 }