Browse Source

修改接口代码

章政 8 years ago
parent
commit
7bee4a8330
2 changed files with 291 additions and 362 deletions
  1. 165 53
      MES接口/DataHelper.cs
  2. 126 309
      MES接口/LogicHandler.cs

+ 165 - 53
MES接口/DataHelper.cs

@@ -3,6 +3,7 @@ using System;
 using System.Data;
 using System.Text;
 using System.Configuration;
+using System.Collections.Generic;
 
 namespace MES_Interface
 {
@@ -15,8 +16,10 @@ namespace MES_Interface
         private string ConnectionStrings = ConfigurationManager.ConnectionStrings["MES"].ConnectionString;
         //用户选择的数据库的连接字符串
         public static OracleConnection connection = null;
+        //用户选择的数据库的连接字符串
+        public static string DBConnectionString;
         OracleCommand command = null;
-
+        int ReconnectTime = 0;
         /// <summary>
         /// 执行构造函数的时候打开数据库的链接
         /// </summary>
@@ -37,10 +40,8 @@ namespace MES_Interface
             }
             catch (Exception e)
             {
-                Console.WriteLine(e.Message);
             }
         }
-
         /// <summary>
         /// 根据表名获取该表字段数据类型
         /// </summary>
@@ -48,6 +49,7 @@ namespace MES_Interface
         {
             DataTable dt = new DataTable();
             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();
@@ -62,8 +64,8 @@ namespace MES_Interface
         {
             DataTable dt = new DataTable();
             string sql = "select " + Field + " from " + TableName + " where " + Condition;
-            Console.WriteLine(sql);
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter();
             ad.SelectCommand = command;
             ad.Fill(dt);
@@ -123,14 +125,13 @@ namespace MES_Interface
         {
             DataTable dt = new DataTable();
             string sql = "select count(1) from " + TableName + " where " + Condition;
-            Console.WriteLine(sql);
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
             command.Dispose();
-            int count = int.Parse(dt.Rows[0][0].ToString());
-            return count;
+            return int.Parse(dt.Rows[0][0].ToString());
         }
 
         /// <summary>
@@ -143,13 +144,12 @@ namespace MES_Interface
             DataTable dt = new DataTable();
             string sql = "select count(1) from " + TableName;
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
-            Console.WriteLine(sql);
             ad.Fill(dt);
             ad.Dispose();
             command.Dispose();
-            int count = int.Parse(dt.Rows[0][0].ToString());
-            return count;
+            return int.Parse(dt.Rows[0][0].ToString());
         }
 
         /// <summary>
@@ -161,8 +161,8 @@ namespace MES_Interface
             string sql = "select ";
             sql += AddField(Fields);
             sql += " from " + TableName + " where " + Condition + " and rownum=1";
-            Console.WriteLine(sql);
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
@@ -209,17 +209,13 @@ namespace MES_Interface
             sql.Append(AddField(caption));
             if (condition.Length > 0)
             {
-                if (condition[0].Trim() != "")
-                {
+                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);
-                }
             }
-            Console.WriteLine(sql.ToString());
             command = new OracleCommand(sql.ToString(), connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
@@ -242,8 +238,8 @@ namespace MES_Interface
             string sql = "select ";
             sql += AddField(Fields);
             sql += " from " + TableName + " where " + Condition;
-            Console.WriteLine(sql);
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
@@ -261,6 +257,7 @@ namespace MES_Interface
             sql += Fields;
             sql += " from " + TableName;
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.SelectCommand = command;
             ad.Fill(dt);
@@ -317,7 +314,6 @@ namespace MES_Interface
                 {
                     //获取参数的个数
                     int paramsNum = sql[0].Split(':').Length - 1;
-
                     //解析参数的数据
                     string[] param = GetParamFromSQL(sql[0]);
                     //新建一个二维数组去
@@ -361,7 +357,6 @@ namespace MES_Interface
                     sb.Append(dc.Caption + "=:" + dc.Caption + ",");
                 }
             }
-
             sb.Remove(sb.Length - 1, 1);
             sb.Append(" where " + PrimaryKey + "=:" + PrimaryKey);
             command = new OracleCommand(sb.ToString(), connection);
@@ -436,8 +431,6 @@ namespace MES_Interface
             }
         }
 
-
-
         /// <summary>
         ///  获取配置列表中的数据,支持DaatList,Form,DetailGrid
         /// </summary>
@@ -570,20 +563,14 @@ namespace MES_Interface
         {
             string sql = "select count(1) from " + TableName + " where " + Condition;
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             DataTable dt = new DataTable();
-            Console.WriteLine(sql);
+            
             ad.Fill(dt);
             ad.Dispose();
             command.Dispose();
-            if (int.Parse(dt.Rows[0][0].ToString()) > 0)
-            {
-                return true;
-            }
-            else
-            {
-                return false;
-            }
+            return int.Parse(dt.Rows[0][0].ToString()) > 0;
         }
 
         /// <summary>
@@ -596,6 +583,7 @@ namespace MES_Interface
         {
             object result = null;
             command = new OracleCommand(SQL, connection);
+            Reconnect(command);
             //用来拼接参数的
             if (names.Length > 0)
             {
@@ -620,18 +608,31 @@ namespace MES_Interface
                     }
                 }
                 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":
                     result = new DataTable();
-                    OracleDataAdapter ad = new OracleDataAdapter(command);
-                    ad.Fill((DataTable)result);
-                    ad.Dispose();
+                    try
+                    {
+                        OracleDataAdapter ad = new OracleDataAdapter(command);
+                        ad.Fill((DataTable)result);
+                        ad.Dispose();
+                        //成功执行后将重复连接数置为0
+                        ReconnectTime = 0;
+                    }
+                    catch (Exception)
+                    {
+                        if (ReconnectTime == 0)
+                        {
+                            //重置的数据库链接后只执行一次
+                            ReconnectTime = ReconnectTime + 1;
+                            connection = new OracleConnection(DBConnectionString);
+                            result = ExecuteSql(SQL, Type, names);
+                        }
+                    }
                     break;
                 case "DELETE":
                     result = command.ExecuteNonQuery();
@@ -663,8 +664,9 @@ namespace MES_Interface
         {
             DataTable dt = new DataTable();
             string sql = "select distinct count('" + Field + "') from " + TableName;
-            Console.WriteLine(sql);
+            
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
@@ -693,8 +695,9 @@ namespace MES_Interface
         public void DeleteDataByID(string TableName, string ID, string[] DeleteID)
         {
             string sql = "delete from " + TableName + " where " + ID + " =:DeleteID";
-            Console.WriteLine(sql);
+            
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             command.ArrayBindCount = DeleteID.Length;
             command.Parameters.Add(new OracleParameter("DeleteID", OracleDbType.Long, DeleteID, ParameterDirection.Input));
             command.ExecuteNonQuery();
@@ -713,6 +716,104 @@ namespace MES_Interface
             return dt.Rows[0][0].ToString();
         }
 
+        public void SaveDataTable(DataTable dt, string TableName, string ID, params string[] sql)
+        {
+            if (dt == 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 = dt.Columns.Count - 1; i >= 0; i--)
+            {
+                if (!sb.ToString().Contains(dt.Columns[i].ColumnName.ToUpper()))
+                {
+                    dt.Columns.RemoveAt(i);
+                }
+            }
+            sb.Clear();
+            //计算有多少个是新加的行,根据主键为空来进行判断
+            int NewRowCount = 0;
+            for (int i = 0; i < dt.Rows.Count; i++)
+            {
+                if (dt.Rows[i][ID] == null || dt.Rows[i][ID].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 = dt.Rows.Count - 1; i >= 0; i--)
+                    {
+                        if (dt.Rows[i][ID] == null || dt.Rows[i][ID].ToString() == "")
+                        {
+                            //当为新添加行的时候才去设置参数,设置过后索引+1
+                            for (int j = 0; j < paramsNum; j++)
+                            {
+                                param_array[j][num] = dt.Rows[i][param[j]].ToString();
+                            }
+                            dt.Rows.RemoveAt(i);
+                            num++;
+                        }
+                    }
+                    BatchInsertDataTable(sql[0], param, param_array);
+                }
+            }
+            sb.Clear();
+            sb.Append("update " + TableName + " set ");
+            int ColumnCount = dt.Columns.Count;
+            int RowCount = dt.Rows.Count;
+            //存数据的参数
+            List<string[]> Parameter = new List<string[]>();
+            //存参数名的参数
+            string[] ParName = new string[ColumnCount];
+            for (int i = 0; i < ColumnCount; i++)
+            {
+                ParName[i] = dt.Columns[i].ColumnName;
+                if (i == dt.Columns.Count - 1)
+                    sb.Append(dt.Columns[i].ColumnName + "=:" + dt.Columns[i].ColumnName);
+                else
+                    sb.Append(dt.Columns[i].ColumnName + "=:" + dt.Columns[i].ColumnName + ",");
+            }
+            sb.Append(" where " + ID + " =:" + ID);
+            //先添加参数
+            Parameter.Add(ParName);
+            //添加参数的具体内容
+            for (int i = 0; i < ColumnCount; i++)
+            {
+                string[] par = new string[RowCount];
+                for (int j = 0; j < RowCount; j++)
+                {
+                    par[j] = dt.Rows[j][i].ToString();
+                }
+                Parameter.Add(par);
+            }
+            BatchInsert(sb.ToString(), Parameter.ToArray());
+        }
+
         /// <summary>
         /// 批量通过SQL来执行插入操作 ,参数的第一个数一个string[]数组,用来传递需要添加的参数的名称
         /// 之后的是名称参数数组对应的 ,所有的插入参数数据长度必须是一致的
@@ -722,8 +823,9 @@ namespace MES_Interface
         public void BatchInsert(string sql, params object[][] names)
         {
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             command.ArrayBindCount = names[1].Length;
-            Console.WriteLine(sql);
+            
             //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
             //将第一个数组的下标固定为0作为循环添加的参数的名称
             for (int i = 1; i <= names[0].Length; i++)
@@ -737,6 +839,7 @@ namespace MES_Interface
         public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
         {
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             command.ArrayBindCount = param1[0].Length;
             //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
             //将第一个数组的下标固定为0作为循环添加的参数的名称
@@ -760,6 +863,7 @@ namespace MES_Interface
             DataTable dt = new DataTable();
             string SQL = " select listagg(dld_field,',') within group (order by dld_id)  from datalistdetail where dld_caller='" + Caller + "'";
             command = new OracleCommand(SQL, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter(command);
             ad.Fill(dt);
             ad.Dispose();
@@ -832,8 +936,9 @@ namespace MES_Interface
         public string UpdateByCondition(string TableName, string update, string condition)
         {
             string sql = "update " + TableName + " set " + update + " where " + condition;
-            Console.WriteLine(sql);
+            
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             command.ExecuteNonQuery();
             command.Dispose();
             return sql;
@@ -842,20 +947,20 @@ namespace MES_Interface
         /// <summary>
         /// 调用存储过程
         /// </summary>
-        /// <param name="ProcedureName"></param>
+        /// <param name="ProcedureName"></param>    
         /// <param name="param"></param>
-        public void CallProcedure(string ProcedureName, params string[] param)
+        public void CallProcedure(string ProcedureName, ref string[] param)
         {
-            command.CommandText = "Execute " + ProcedureName;
-            if (param[0].Length > 0)
-            {
-                command.ArrayBindCount = param[1].Length;
-                for (int i = 1; i <= param[0].Length; i++)
-                {
-                    command.Parameters.Add(new OracleParameter(param[0][i - 1].ToString(), OracleDbType.Varchar2, param[i], ParameterDirection.Input));
-                }
-            }
+            command = new OracleCommand(ProcedureName);
+            command.Connection = connection;
+            Reconnect(command);
+            command.CommandText = ProcedureName;
+            command.CommandType = CommandType.StoredProcedure;
+            for (int i = 0; i < param.Length; i++)
+                command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
             command.ExecuteNonQuery();
+            for (int i = 0; i < command.Parameters.Count; i++)
+                param[i] = command.Parameters[i].Value.ToString();
             command.Dispose();
         }
 
@@ -875,6 +980,7 @@ namespace MES_Interface
                 {
                     if (!String.IsNullOrEmpty(sql))
                     {
+                        
                         command.CommandText = sql;
                         command.ExecuteNonQuery();
                     }
@@ -903,7 +1009,6 @@ namespace MES_Interface
             }
             return sql.Substring(0, sql.Length - 1);
         }
-
         /// <summary>
         /// 通过查询的内容获取到字段的描述
         /// </summary>
@@ -938,6 +1043,7 @@ namespace MES_Interface
         {
             DataTable dt = new DataTable();
             command = new OracleCommand(sql, connection);
+            Reconnect(command);
             OracleDataAdapter ad = new OracleDataAdapter();
             ad.SelectCommand = command;
             ad.Fill(dt);
@@ -983,5 +1089,11 @@ namespace MES_Interface
             }
             return param;
         }
+
+        private void Reconnect(OracleCommand cmd)
+        {
+            if (cmd.Connection.State == ConnectionState.Closed)
+                cmd.Connection.Open();
+        }
     }
 }

+ 126 - 309
MES接口/LogicHandler.cs

@@ -22,139 +22,50 @@ namespace MES_Interface
         /// </summary>
         /// <param name="iSnCode"></param>
         /// <param name="iMakeCode"></param>
-        /// <param name="iSource"></param>
+        /// <param name="iSourceCode"></param>
         /// <param name="oErrMessage"></param>
         /// <returns></returns>
-        private bool CheckCurrentStep(string iSnCode, string iMakeCode, string iSource, out string oErrMessage)
+        public bool CheckCurrentStep(string iSnCode, string iMakeCode, string iSourceCode, out string oErrMessage)
         {
-            oErrMessage = "";
-            if (iMakeCode == "")
+            if (GetMakeInfo(iSnCode, out iMakeCode, out oErrMessage))
             {
-                if (!GetMakeInfo(iSnCode, out iMakeCode, out oErrMessage))
+                string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'").ToString();
+                string sourcestepcode = GetStepCodeBySource(iSourceCode);
+                if (nextstepcode == "")
+                {
+                    oErrMessage = "当前序列号已无可执行工序";
                     return false;
-            }
-            string nextstepcode = dh.getFieldDataByCondition("makeserial", "ms_nextstepcode", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'").ToString();
-            string sourcestepcode = GetStepCodeBySource(iSource);
-            if (nextstepcode == "")
-            {
-                oErrMessage = "当前序列号已无可执行工序";
-                return false;
-            }
-            if (nextstepcode == sourcestepcode)
-                return true;
-            else {
-                oErrMessage = "资源" + iSource + "对应的工序是" + sourcestepcode + ",序列号" + iSnCode + "当前工序是" + nextstepcode;
-                return false;
-            }
-
-        }
-
-        private bool CheckMakeStatus(string iMaCode)
-        {
-            if (dh.getFieldDataByCondition(" make ", "ma_statuscode", "ma_code='" + iMaCode + "' ").ToString() == "STARTED")
-                return true;
-            else
-                return false;
-        }
-
-        /// <summary>
-        /// 判断当前工序是否是第一道工序
-        /// </summary>
-        /// <param name="iSnCode"></param>
-        /// <param name="iMakecode"></param>
-        /// <param name="iSourceCode"></param>
-        /// <returns></returns>
-        public bool CheckIfFirstMakeSerial(string iSnCode, string iMakecode, string iSourceCode)
-        {
-            //选取当前的最小的执行顺序
-            string CurrentStep = GetStepCodeBySource(iSourceCode);
-            DataTable dt = (DataTable)dh.ExecuteSql("select  min(mcd_detno) detno from makecraftdetail where mcd_macode='" + iMakecode + "'", "select");
-            string detno = dt.Rows[0]["detno"].ToString();
-            //判断当前最小的执行顺序是否有记录
-            if (dh.getRowCount("makecraftdetail", "mcd_stepcode='" + CurrentStep + "' and mcd_macode='" + iMakecode + "' and mcd_detno ='" + detno + "'") > 0)
-            {
-                if (!dh.CheckExist("MakeSerial", "ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakecode + "'"))
+                }
+                if (nextstepcode == sourcestepcode)
+                    return true;
+                else
                 {
-                    sql.Clear();
-                    sql.Append("Insert into MakeSerial (ms_id, ms_code, ms_sncode ,ms_prodcode, ms_indate,");
-                    sql.Append("ms_wccode,ms_craftcode,ms_craftname,ms_nextstepcode,ms_status,ms_makecode) select MAKESERIAL_SEQ.NEXTVAL,");
-                    sql.Append("'" + iSnCode + "','" + iSnCode + "',ma_prodcode,sysdate,ma_wccode,ma_craftcode,ma_craftname,'" + CurrentStep + "',0,ma_code ");
-                    sql.Append("from make left join makecraftdetail on ma_code =mcd_macode where ma_code='" + iMakecode + "' and mcd_stepcode='" + CurrentStep + "'");
-                    dh.ExecuteSql(sql.ToString(), "insert");
+                    oErrMessage = "资源" + iSourceCode + "对应的工序是" + sourcestepcode + ",序列号" + iSnCode + "当前工序是" + nextstepcode;
+                    return false;
                 }
-                return true;
             }
-            else
-                return false;
+            else return false;
         }
 
         /// <summary>
-        /// 判断下一工序是否是送检工序
+        /// 判断工单是否已经下放
         /// </summary>
+        /// <param name="iMaCode"></param>
         /// <returns></returns>
-        public bool CheckNextStepIfQC(string iSnCode, string iMakeCode, string iStepCode, string iCraftCode, string iUserName, out string oErrorMessage)
+        public bool CheckMakeStatus(string iMaCode, out string ErrorMessage)
         {
-            oErrorMessage = "";
-            string IfQC = dh.getFieldDataByCondition("craft left join  craftdetail on cd_crid=cr_id", "cd_ifoqc", "cr_code='" + iCraftCode + "' and cd_stepcode='" + iStepCode + "'").ToString();
-            if (IfQC != "0" && IfQC != "")
+            string ma_statuscode = dh.getFieldDataByCondition(" make ", "ma_statuscode", "ma_code='" + iMaCode + "' ").ToString();
+            ErrorMessage = "";
+            if (ma_statuscode == "")
             {
-                DataTable dt = dh.getFieldsDataByCondition("make left join product on ma_prodcode=pr_code", new string[] { "ma_nowcheckqty", "pr_qcbatchqty", "ma_checkno", "ma_prodcode", "pr_qualmethod" }, "ma_code='" + iMakeCode + "'");
-                if (dt.Rows.Count > 0)
-                {
-                    string ma_nowcheckqty = dt.Rows[0]["ma_nowcheckqty"].ToString();
-                    string pr_qcbatchqty = dt.Rows[0]["pr_qcbatchqty"].ToString();
-                    string ma_checkno = dt.Rows[0]["ma_checkno"].ToString();
-                    string ma_prodcode = dt.Rows[0]["ma_prodcode"].ToString();
-                    string pr_qualmethod = dt.Rows[0]["pr_qualmethod"].ToString();
-                    if (pr_qcbatchqty != "" && pr_qcbatchqty != "0")
-                    {
-                        //当前批次的送检批数量大于物料资料中的抽检批数或者当前批次编号为空
-                        string checkno = "";
-                        if (int.Parse(ma_nowcheckqty == "" ? "0" : ma_nowcheckqty) >= int.Parse(pr_qcbatchqty) || ma_checkno == "")
-                        {
-                            //原有的抽检批次插入OQCBatch
-                            string ob_id = dh.GetSEQ("OQCBatch_SEQ");
-                            checkno = dh.GetSerialNumberByCaller("Make!CheckQC");
-                            sql.Clear();
-                            sql.Append("insert into OQCBatch  (ob_id, ob_checkno,ob_makecode,ob_source,ob_indate,ob_checkman,ob_batchqty,ob_status,ob_prodcode,ob_projectcode)");
-                            sql.Append(" values('" + ob_id + "','" + checkno + "','" + iMakeCode + "', '工序',sysdate, '" + iUserName + "','" + ma_nowcheckqty + "','UNCHECK','" + ma_prodcode + "','" + pr_qualmethod + "')");
-                            sqls.Add(sql.ToString());
-                            sqls.Add("update makeserial set ms_checkno='" + checkno + "' where ms_makecode='" + iMakeCode + "' and ms_sncode='" + iSnCode + "'");
-                            sqls.Add("update make set ma_checkno='" + checkno + "',ma_nowcheckqty=1 where ma_code='" + iMakeCode + "'");
-                        }
-                        else
-                        {
-                            sqls.Add("update makeserial set ms_checkno='" + ma_checkno + "' where ms_makecode='" + iMakeCode + "' and ms_sncode='" + iSnCode + "'");
-                            sqls.Add("update make set ma_nowcheckqty= ma_nowcheckqty+1  where ma_code='" + iMakeCode + "'");
-                        }
-                        dh.ExecuteSQLTran(sqls.ToArray());
-                        sqls.Clear();
-                        //如果制造单的ma_checkno没有值则新加入一个值
-                        string checkno1 = checkno == "" ? ma_checkno : checkno;
-                        string obd_obid = dh.getFieldDataByCondition("oqcbatch", "ob_id", "ob_checkno='" + checkno1 + "'").ToString();
-                        //插入抽检批次明细表
-                        sql.Clear();
-                        sql.Append("insert into OQCBatchDetail (obd_id,obd_obid,obd_sncode,obd_outboxcode,obd_makecode,obd_checkno,obd_builddate) ");
-                        sql.Append("select OQCBatchDetail_SEQ.nextval,'" + obd_obid + "',ms_sncode,ms_outboxcode,ms_makecode,ms_checkno,");
-                        sql.Append("sysdate from makeserial where  ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
-                        dh.ExecuteSql(sql.ToString(), "insert");
-                        return true;
-                    }
-                    else
-                    {
-                        oErrorMessage = "请维护物料资料的抽检批数";
-                        return false;
-                    }
-                }
-                else
-                {
-                    oErrorMessage = "制造单号不存在";
-                    return false;
-                }
+                ErrorMessage = "工单号" + iMaCode + "不存在";
+                return false;
             }
+            if (ma_statuscode == "STARTED")
+                return true;
             else
             {
-                oErrorMessage = "当前工序的下一工序不是OQC检测";
+                ErrorMessage = "工单必须是已下放状态";
                 return false;
             }
         }
@@ -196,9 +107,10 @@ namespace MES_Interface
             if (dt.Rows.Count > 0)
             {
                 string em_name = dt.Rows[0]["em_name"].ToString();
-                if (dt.Rows[0]["em_type"].ToString() == "admin" && iSourceCode == "")
+                if (iSourceCode == "")
                 {
-                    return true;
+                    oErrorMessage = "岗位资源不允许为空";
+                    return false;
                 }
                 dt = dh.getFieldsDatasByCondition("cs$empgroup left join cs$userresource on ur_groupcode=eg_groupcode left join source on ur_resourcecode=sc_code", new string[] { "ur_resourcecode" }, "eg_emcode = '" + iUserCode + "' and sc_statuscode='AUDITED'");
                 //如果存在该编号
@@ -220,6 +132,33 @@ namespace MES_Interface
             return false;
         }
 
+        public bool CheckStepAttribute(string iCaller, string iSourceCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iCaller, iSourceCode, oErrorMessage };
+            dh.CallProcedure("CS_CHECKSTEPATTRIBUTE", ref param);
+            if (oErrorMessage == "" || oErrorMessage == null)
+                return true;
+            else
+                return false;
+        }
+
+        public bool CheckStepSNAndMacode(string iMakeCode, string iSourceCode, string iSN, string iUserCode, out string oMakeCode, out string oMsID, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            oMakeCode = "";
+            oMsID = "";
+            string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, oMakeCode, oMsID, oErrorMessage };
+            dh.CallProcedure("CS_CHECKSTEPSNANDMACODE", ref param);
+            oMakeCode = param[4];
+            oMsID = param[5];
+            oErrorMessage = param[6];
+            if (oErrorMessage == "" || oErrorMessage == null || oErrorMessage == "null")
+                return true;
+            else
+                return false;
+        }
+
         /// <summary>
         /// 分配Mac地址和BT地址
         /// </summary>
@@ -436,7 +375,7 @@ namespace MES_Interface
                 return true;
             else
             {
-                oErrorMessage = "当前序列号" + iSnCode + "不存在生产记录";
+                oErrorMessage = "序列号:" + iSnCode + " 未归属工单";
                 return false;
             }
         }
@@ -510,38 +449,28 @@ namespace MES_Interface
         /// <summary>
         /// 记录操作日志
         /// </summary>
-        /// <param name="iMakeCode"></param>
         /// <param name="iSnCode"></param>
-        public void InsertMakeProcess(string iSnCode, string iMakeCode, string result, string iUserName)
+        /// <param name="iMakeCode"></param>
+        /// <param name="iMPKind"></param>
+        /// <param name="iResult"></param>
+        /// <param name="iUserName"></param>
+        public void InsertMakeProcess(string iSnCode, string iMakeCode, string iSourceCode, string iMPKind, string iResult, string iUserName)
         {
+            string CurrentStep = "";
+            string LineCode = "";
+            string CurrentStepName = "";
+            GetStepCodeAndNameAndLineBySource(iSourceCode, ref CurrentStep, ref CurrentStepName, ref LineCode);
             sql.Clear();
             sql.Append("insert into MakeProcess(mp_id,mp_makecode,mp_maid, mp_mscode,mp_sncode,mp_stepcode,mp_stepname,");
-            sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode) ");
+            sql.Append("mp_craftcode,mp_craftname,mp_kind,mp_result,mp_indate,mp_inman,mp_wccode,mp_linecode,mp_sourcecode,mp_snstatus,mp_sncheckno,mp_snoutboxcode)");
             sql.Append("select MakeProcess_seq.nextval, ma_code,ma_id,ms_code,ms_sncode,mcd_stepcode,mcd_stepname,");
-            sql.Append("ma_craftcode,ma_craftname,ma_kind,'" + result + "',sysdate,'" + iUserName + "',ma_wccode,ma_linecode,''");
-            sql.Append("from make left join makecraftdetail on mcd_macode=ma_code left join makeserial on ms_makecode=ma_code ");
-            sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "'");
-            //插入makeprocess 
+            sql.Append("ma_craftcode,ma_craftname,'" + iMPKind + "','" + iResult + "',sysdate,'" + iUserName + "',ma_wccode,'" + LineCode + "','" + iSourceCode + "',");
+            sql.Append("ms_status,ms_checkno,ms_outboxcode from make left join makecraftdetail on mcd_macode=ma_code left join makeserial on ms_makecode=ma_code ");
+            sql.Append("where ms_sncode='" + iSnCode + "' and ma_code='" + iMakeCode + "' and mcd_stepcode='" + CurrentStep + "'");
             dh.ExecuteSql(sql.ToString(), "insert");
             sql.Clear();
         }
 
-        /// <summary>
-        /// 记录一般操作日志
-        /// </summary>
-        /// <param name="inMan"></param>
-        /// <param name="Content"></param>
-        /// <param name="Result"></param>
-        /// <param name="Search"></param>
-        /// <param name="Code"></param>
-        public void InsertMessageLog(string inMan, string Content, string Result, string Search, string Code)
-        {
-            sql.Clear();
-            sql.Append("insert into messagelog (ml_id,ml_date,ml_man,ml_content,ml_result,ml_search,code) ");
-            sql.Append("values (messagelog_seq.nextval,sysdate,'" + inMan + "','" + Content + "','" + Result + "','" + Search + "','" + Code + "')");
-            dh.ExecuteSql(sql.ToString(), "insert");
-        }
-
         /// <summary>
         /// 保存Mac地址和BT地址
         /// </summary>
@@ -560,12 +489,14 @@ namespace MES_Interface
             {
                 string sql = "update MakeSerial set ms_mac=:iWifi,ms_bt=:iBT,ms_othcode1=:iCode1,ms_othcode2=:iCode2,ms_othcode3=:iCode3 where ms_sncode='" + iSN + "' and ms_makecode='" + MakeCode + "'";
                 dh.ExecuteSql(sql, "update", iWIFI, iBT, iCode1, iCode2, iCode3);
-                if (dh.CheckExist("SnInfo", "si_sn='" + iSN + "'"))
+                DataTable dt = (DataTable)dh.ExecuteSql("select si_sn from SnInfo where si_sn='" + iSN + "' or  si_sn in (select sn from makesnrelation where firstsn='" + iSN + "' or sn='" + iSN + "')", "select");
+                if (dt.Rows.Count > 0)
                 {
-                    sql = "update SnInfo set si_mac=:iMac,si_bt=:iBT,si_othcode1=:iCode1,si_othcode2=:iCode2,si_othcode3=:iCode3 where si_sncode='" + iSN + "'";
+                    sql = "update SnInfo set si_mac=:iMac,si_bt=:iBT,si_othcode1=:iCode1,si_othcode2=:iCode2,si_othcode3=:iCode3 where si_sn='" + dt.Rows[0]["si_sn"].ToString() + "'";
                     dh.ExecuteSql(sql, "update", iWIFI, iBT, iCode1, iCode2, iCode3);
                 }
-                else {
+                else
+                {
                     sql = "insert into SnInfo(si_id,si_sn,si_mac,si_bt,si_othcode1,si_othcode2,si_othcode3) values(SnInfo_seq.nextval,:iSn,:iWifi,:iBt,:iCode1,:iCode2,:iCode3)";
                     dh.ExecuteSql(sql, "insert", iSN, iWIFI, iBT, iCode1, iCode2, iCode3);
                 }
@@ -575,6 +506,31 @@ namespace MES_Interface
                 return false;
         }
 
+        public bool SetStepFinish(string iMakeCode, string iSourceCode, string iSN, string iMPKind, string iResult, string iUserCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string StepCode = dh.getFieldDataByCondition("Makeserial", "ms_stepcode", "ms_sncode='" + iSN + "'").ToString();
+            string CurrentStep = GetStepCodeBySource(iSourceCode);
+            if (StepCode == CurrentStep)
+            {
+                InsertMakeProcess(iSN, iMakeCode, iSourceCode, iMPKind, iResult, iUserCode);
+                return true;
+            }
+            else {
+                return CS_SetFinish(iMakeCode, iSourceCode, iSN, iUserCode, out oErrorMessage);
+            }
+        }
+
+        private bool CS_SetFinish(string iMakeCode, string iSourceCode, string iSN, string iUserCode, out string oErrorMessage)
+        {
+            oErrorMessage = "";
+            string[] param = new string[] { iMakeCode, iSourceCode, iSN, iUserCode, oErrorMessage };
+            dh.CallProcedure("CS_SETSTEPFINISH", ref param);
+            if (oErrorMessage == "" || oErrorMessage == null)
+                return true;
+            else
+                return false;
+        }
 
         /// <summary>
         /// 方法说明:测试详细信息录入系统,针对一个SN多个测试项目结果可循环调用
@@ -637,43 +593,34 @@ namespace MES_Interface
         /// </summary>
         /// <param name="iSnCode"></param>
         /// <param name="iMakeCode"></param>
-        /// <param name="iUserName"></param>
+        /// <param name="iUserCode"></param>
         /// <param name="iSourceCode"></param>
         /// <param name="iBadCode"></param>
         /// <param name="iBadRemark"></param>
         /// <param name="oErrorMessage"></param>
         /// <returns></returns>
-        public bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserName, string iSourceCode, string iResult, string[] iBadCode, string[] iBadRemark, out string oErrorMessage)
+        public bool SetTestNGDetail(string iSnCode, string iMakeCode, string iUserCode, string iSourceCode, string iResult, string[] iBadGroupCode, string[] iBadCode, string[] iBadRemark, out string oErrorMessage)
         {
             oErrorMessage = "";
             string StepCode = "";
             string StepName = "";
             if (iResult == "" || iResult == null)
-            {
                 iResult = "检查未通过";
-            }
             GetStepCodeAndNameBySource(iSourceCode, ref StepCode, ref StepName);
+            string ms_status = dh.getFieldDataByCondition("makeserial", "ms_status", "ms_sncode='" + iSnCode + "'").ToString();
             sql.Clear();
-            sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,");
-            sql.Append("mb_indate,mb_stepcode,mb_sourcecode,mb_badcode,mb_badtable,mb_soncode,mb_status,mb_badremark)");
-            sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + iUserName + "',sysdate,'" + StepCode + "',ms_sourcecode,:bc_code,'',");
+            sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
+            sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_soncode,mb_status,mb_badremark)");
+            sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + iUserCode + "',sysdate,'" + StepCode + "',ms_sourcecode,:bc_code,:bg_code,'',");
             sql.Append("sp_soncode,'0',:bc_remark from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
             sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + iSnCode + "'");
-            dh.BatchInsert(sql.ToString(), new string[] { "bc_code", "bc_remark" }, iBadCode, iBadRemark);
-            //更新序列号状态,待维修,返修工序
-            string st_rstepcode = dh.getFieldDataByCondition("step", "st_rstepcode", "st_code='" + StepCode + "'").ToString();
-            sql.Clear();
-            sql.Append("update makeserial set ms_status = 3,ms_nextstepcode ='" + st_rstepcode + "', ");
-            sql.Append("ms_stepcode ='" + StepCode + "' where ms_sncode ='" + iSnCode + "' and ms_makecode ='" + iMakeCode + "'");
-            dh.ExecuteSql(sql.ToString(), "update");
-            //更新makecraftdetail 工单采集记录表,根据工单号和工序编号 记录当前测试工序采集数量
-            dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty+1,mcd_outqty = mcd_outqty + 1", "mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "'");
+            dh.BatchInsert(sql.ToString(), new string[] { "bc_code", "bg_code", "bc_remark" }, iBadCode, iBadGroupCode, iBadRemark);
             //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
-            dh.UpdateByCondition("makeserial", "ms_paststep = ms_paststep ||'," + StepCode + "'", "ms_sncode='" + iSnCode + "'");
-            //记录操作日志
-            InsertMakeProcess(iSnCode, iMakeCode, iResult, iUserName);
+            dh.UpdateByCondition("makeserial", "ms_paststep = ms_paststep ||'," + StepCode + "',ms_status=3", "ms_sncode='" + iSnCode + "'");
             //判断当前采集点是否为扣料工序cd_ifreduce =-1 则为扣料工序
-            SetCollectionFinish(iSnCode, iMakeCode, iUserName, iSourceCode, out oErrorMessage);
+            //之前保存的不良就不再调用
+            if (ms_status != "3")
+                SetStepFinish(iMakeCode, iSourceCode, iSnCode, "不良采集", iResult, iUserCode, out oErrorMessage);
             return true;
         }
 
@@ -697,8 +644,8 @@ namespace MES_Interface
                 return false;
             }
             sql.Clear();
-            sql.Append("select nvl(cd_ifreduce,0) cd_ifreduce  from craft left join ");
-            sql.Append("craftdetail on cd_crid=cr_id where cr_code=(select ma_craftcode  from makeserial left join make on ma_code = ms_makecode ");
+            sql.Append("select nvl(cd_ifreduce,0) cd_ifreduce from craft left join craftdetail on cd_crid=cr_id ");
+            sql.Append("where cr_code=(select ma_craftcode  from makeserial left join make on ma_code = ms_makecode ");
             sql.Append("where ms_sncode = '" + iSnCode + "') and cd_stepcode='" + StepCode + "'");
             DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
             sql.Clear();
@@ -708,21 +655,21 @@ namespace MES_Interface
                 if (cd_ifreduce == "-1")
                 {
                     sql.Clear();
-                    sql.Append("select dsl_location,dsl_table, max(dsl_baseqty) baseqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and ");
+                    sql.Append("select dsl_location,dsl_table,max(dsl_baseqty) baseqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and ");
                     sql.Append("dsl_linecode='" + LineCode + "' and dsl_status=0 and dsl_remainqty>0 and dsl_invalidtime is null group by dsl_location,dsl_table");
                     dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
                     for (int i = 0; i < dt.Rows.Count; i++)
                     {
                         sql.Clear();
-                        sql.Append("selet dsl_id,dsl_remainqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and dsl_linecode='" + LineCode + "' ");
+                        sql.Append("select dsl_id,dsl_remainqty from devsmtlocation where dsl_makecode='" + iMakeCode + "' and dsl_linecode='" + LineCode + "' ");
                         sql.Append("and dsl_status=0 and dsl_remainqty>0 and dsl_invalidtime is null and rownum<3 order by dsl_id asc ");
                         DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
-                        for (int j = 0; j < dt.Rows.Count; j++)
+                        for (int j = 0; j < dt1.Rows.Count; j++)
                         {
                             //外层循环的值dt
                             double baseqty = (double)dt.Rows[i]["baseqty"];
-                            double dsl_remainqty = (double)dt.Rows[i]["dsl_remainqty"];
                             //内层循环的值dt1
+                            double dsl_remainqty = (double)dt1.Rows[j]["dsl_remainqty"];
                             string dsl_id = dt1.Rows[j]["dsl_id"].ToString();
                             if (baseqty > 0)
                             {
@@ -730,21 +677,21 @@ namespace MES_Interface
                                 {
                                     sql.Clear();
                                     sql.Append("update devsmtlocation set dsl_remainqty=0,dsl_invalidtime =sysdate, dsl_validtime =(case when dsl_validtime ");
-                                    sql.Append("is null then sysdate else  dsl_validtime),dsl_status=-1 where dsl_id=" + dsl_id);
+                                    sql.Append("is null then sysdate else  dsl_validtime end),dsl_status=-1 where dsl_id=" + dsl_id);
                                     dh.ExecuteSql(sql.ToString(), "update");
                                     baseqty -= dsl_remainqty;
                                 }
                                 else
                                 {
                                     sql.Clear();
-                                    sql.Append("update devsmtlocation set dsl_remainqty=dsl_remainqty-NVL(dsl_baseqty,0),dsl_efftime=(case when");
-                                    sql.Append("dsl_validtime is null then sysdate else dsl_validtime) where dsl_id=" + dsl_id);
+                                    sql.Append("update devsmtlocation set dsl_remainqty=dsl_remainqty-NVL(dsl_baseqty,0),DSL_INVALIDTIME=(case when");
+                                    sql.Append("dsl_validtime is null then sysdate else dsl_validtime end) where dsl_id=" + dsl_id);
                                     dh.ExecuteSql(sql.ToString(), "update");
                                     baseqty = 0;
                                 }
                             }
                             else
-                                dh.ExecuteSql("update devsmtlocation set dsl_efftime=sysdate where dsl_id=" + dsl_id, "update");
+                                dh.ExecuteSql("update devsmtlocation set DSL_INVALIDTIME=sysdate where dsl_id=" + dsl_id, "update");
                         }
                     }
                     sql.Clear();
@@ -811,7 +758,7 @@ namespace MES_Interface
         /// <param name="iUserName"></param>
         /// <param name="oErrorMessage"></param>
         /// <returns></returns>
-        public bool SetMaterialDown(string iSnCode, string iBarCode, string iCurrentStep, string iUserName, out string oErrorMessage)
+        public bool SetMaterialDown(string iSnCode, string iBarCode, string iSourceCode, string iCurrentStep, string iUserName, out string oErrorMessage)
         {
             //序列号不为空的时候
             oErrorMessage = "";
@@ -849,10 +796,10 @@ namespace MES_Interface
                     string cm_stepcode = dt.Rows[0]["cm_stepcode"].ToString();
                     string cm_mccode = dt.Rows[0]["cm_mccode"].ToString();
                     dh.ExecuteSql("delete from Craftmaterial where cm_id=" + cm_id, "delete");
-                    InsertMakeProcess(ms_macode, iSnCode, "下料成功", iUserName);
+                    InsertMakeProcess(ms_macode, iSnCode, iSourceCode, "下料操作", "下料成功", iUserName);
                     int count = dh.getRowCount("craftMaterial", "cm_mccode='" + cm_mccode + "' and cm_stepcode='" + cm_stepcode + "' and cm_sncode='" + iSnCode + "'");
                     if (count == 0)
-                        dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty = mcd_okqty - 1", "mcd_mccode='" + cm_mccode + "' and mcd_stepcode='" + cm_stepcode + "'");
+                        dh.UpdateByCondition("makecraftdetail ", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1,mcd_okqty = mcd_okqty - 1", "mcd_mccode='" + cm_mccode + "' and mcd_stepcode='" + cm_stepcode + "'");
                 }
                 return true;
             }
@@ -870,139 +817,9 @@ namespace MES_Interface
         /// <param name="iResult"></param>
         /// <param name="oErrorMessage"></param>
         /// <returns></returns>
-        public bool UpdateMakeMessage(string iSnCode, string iMakeCode, string iSourceCode, string iUserName, string iResult, out string oErrorMessage)
+        public bool UpdateMakeMessage(string iSnCode, string iMakeCode, string iMPKind, string iSourceCode, string iUserCode, string iResult, out string oErrorMessage)
         {
-            oErrorMessage = "";
-            string StepCode = "";
-            string StepName = "";
-            string LineCode = "";
-            if (iResult == "" || iResult == null)
-            {
-                iResult = "测试合格";
-            }
-            GetStepCodeAndNameAndLineBySource(iSourceCode, ref StepCode, ref StepName, ref LineCode);
-            //判断是否上料工序,如果是的话执行该步骤
-            DataTable dt = dh.getFieldsDataByCondition("make left join craft on cr_code=ma_craftcode left join craftdetail on cd_crid=cr_id", new string[] { "cd_ifinput", "cr_code" }, "ma_code='" + iMakeCode + "' and cd_stepcode='" + StepCode + "'");
-            string Yes_No = dh.GetConfig("BatchNumber", "MESSetting").ToString();
-            string cr_code = "";
-            if (dt.Rows.Count > 0)
-            {
-                cr_code = dt.Rows[0]["cr_code"].ToString();
-                if (dt.Rows[0]["cd_ifinput"].ToString() != "0")
-                {
-                    sql.Clear();
-                    sql.Append("select wm_concat(mss_prodcode) code,count(1) cn from (select sum(nvl(mss_remain,0))remain,mss_prodcode,max(mss_baseqty) mss_baseqty ");
-                    sql.Append("from makesourcestock where mss_makecode='" + iMakeCode + "' and mss_stepcode='" + StepCode + "' ");
-                    sql.Append("and mss_linecode='" + LineCode + "' group by mss_prodcode)T where T.remain<mss_baseqty and rownum<20");
-                    dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
-                    //如果配置的是Yes
-                    if (Yes_No != "0")
-                    {
-                        //如果批次料不足
-                        if (dt.Rows.Count > 0 && int.Parse(dt.Rows[0]["cn"].ToString()) > 0)
-                        {
-                            oErrorMessage += "批次物料:" + iSnCode + "," + dt.Rows[0]["code"] + "岗位备料不足";
-                            return false;
-                        }
-                    }
-                    //如果配置的是No 或者批次料足够
-                    else if (Yes_No == "0" || dt.Rows.Count == 0)
-                    {
-                        //扣减批次数量,插入数据至用料表
-                        sql.Clear();
-                        sql.Append("select mss_prodcode , max(mss_baseqty) baseqty from makesourcestock ");
-                        sql.Append("mss_makecode='" + iMakeCode + "' and mss_stepcode='" + StepCode + "'  and mss_linecode='" + LineCode + "' group by mss_prodcode");
-                        DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
-                        for (int i = 0; i < dt1.Rows.Count; i++)
-                        {
-                            string prodcode = dt1.Rows[i]["mss_prodcode"].ToString();
-                            //本次上料需要扣除的数量
-                            int baseqty = int.Parse(dt1.Rows[i]["baseqty"].ToString());
-                            sql.Clear();
-                            sql.Append("select mss_remain,mss_useqty,mss_id ,mss_barcode from makesourcestock where mss_makecode='" + iMakeCode + "' and ");
-                            sql.Append("mss_stepcode='" + StepCode + "' and mss_prodcode='" + prodcode + "'  and mss_linecode='" + LineCode + "'  and mss_remain >0 order by mss_id  asc");
-                            DataTable dt2 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
-                            for (int j = 0; i < dt2.Rows.Count; j++)
-                            {
-                                int remain = int.Parse(dt2.Rows[j]["mss_remain"].ToString());
-                                int useqty = int.Parse(dt2.Rows[j]["mss_useqty"].ToString());
-                                string mss_id = dt2.Rows[j]["mss_id"].ToString();
-                                string barcode = dt2.Rows[j]["mss_barcode"].ToString();
-                                //如果可扣数量大于0
-                                if (baseqty > 0)
-                                {
-                                    //并且可扣数量大于剩余数量
-                                    if (baseqty > remain)
-                                    {
-                                        sql.Clear();
-                                        sql.Append("update makesourcestock set mss_useqty=nvl(mss_useqty,0)+mss_remain,mss_remain = 0 where mss_id='" + mss_id + "' ");
-                                        dh.ExecuteSql(sql.ToString(), "update");
-                                        //扣减剩余数量
-                                        baseqty -= remain;
-                                    }
-                                    else if (remain >= baseqty)
-                                    {
-                                        dh.ExecuteSql("update makesourcestock set mss_remain = mss_remain-baseqty where mss_id =" + mss_id, "select");
-                                        baseqty = 0;
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            //查询批次和批数量
-            int batchqty = 0;
-            string checkno = "";
-            dt = (DataTable)dh.ExecuteSql("select count(ms_checkno) count,ms_checkno from makeserial where ms_checkno=(select ms_checkno from makeserial where ms_sncode='" + iSnCode + "') group by ms_checkno", "select");
-            if (dt.Rows.Count > 0)
-            {
-                batchqty = int.Parse(dt.Rows[0]["count"].ToString());
-                checkno = dt.Rows[0]["ms_checkno"].ToString();
-            }
-            object nextstepcode = dh.getFieldDataByCondition("makecraftdetail", "mcd_nextstepcode", "mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "'");
-            if (iResult.Contains("批次通过") && dt.Rows.Count > 0)
-            {
-                //更新执行的数量
-                sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty+" + batchqty + ",mcd_outqty = mcd_outqty + " + batchqty + ",mcd_okqty = mcd_okqty + " + batchqty + " where mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "' ");
-                //更新makeSerial 的下一工序
-                sqls.Add("update makeserial set ms_paststep = ms_paststep || '," + StepCode + "',ms_nextstepcode='" + nextstepcode.ToString() + "' where ms_checkno='" + checkno + "'");
-            }
-            else
-            {
-                //更新执行的数量
-                sqls.Add("update makecraftdetail set mcd_inqty=mcd_inqty+1,mcd_outqty = mcd_outqty + 1,mcd_okqty = mcd_okqty + 1 where mcd_macode='" + iMakeCode + "' and mcd_stepcode='" + StepCode + "' ");
-                //更新makeSerial 的下一工序
-                sqls.Add("update makeserial set ms_paststep = ms_paststep || '," + StepCode + "',ms_nextstepcode='" + nextstepcode.ToString() + "' where ms_sncode='" + iSnCode + "' and ms_makecode='" + iMakeCode + "'");
-            }
-            //更新序列号已经采集的工序 ms_paststep 已采集数据,更新下一工序
-            dh.ExecuteSQLTran(sqls.ToArray());
-            sqls.Clear();
-            //记录操作日志
-            InsertMakeProcess(iSnCode, iMakeCode, iResult, iUserName);
-            //检测下道工序是否存在,不存在 更新状态为已完成
-            if (nextstepcode == null || nextstepcode.ToString() == "")
-            {
-                if (iResult.Contains("批次通过"))
-                {
-                    sqls.Add("update make set ma_madeqty=ma_madeqty+" + batchqty + " where ma_code='" + iMakeCode + "'");
-                    sqls.Add("update makeserial set ms_status=2 where ms_checkno='" + checkno + "'");
-                }
-                else
-                {
-                    sqls.Add("update make set ma_madeqty=ma_madeqty+1  where ma_code='" + iMakeCode + "'");
-                    sqls.Add("update makeserial set ms_status=2 where ms_sncode='" + iSnCode + "'");
-                }
-                dh.ExecuteSQLTran(sqls.ToArray());
-                sqls.Clear();
-            }
-            else
-            {
-                CheckNextStepIfQC(iSnCode, iMakeCode, nextstepcode.ToString(), cr_code, iUserName, out oErrorMessage);
-            }
-            // 将数据插入craftmaterial表
-            SetCollectionFinish(iSnCode, iMakeCode, iUserName, iSourceCode, out oErrorMessage);
-            return true;
+            return SetStepFinish(iMakeCode, iSourceCode, iSnCode, iMPKind, iResult, iUserCode, out oErrorMessage);
         }
 
         /// <summary>