protected void Page_Load(object sender, EventArgs e) { //调用WebService举例 ProcedureCtrl ctrl = new ProcedureCtrl(); ProductTrace trace = new ProductTrace(); string oMsg = ""; bool ret = ctrl.SaveProcessEnd("029666666A0111080029", "包装", 0,"","",System.DateTime.Now, out oMsg); Response.Write(oMsg); }
public string GetData(string BarCode, string Process) { // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return(string.Empty); } string sql; SqlDataAdapter adapter = new SqlDataAdapter(); sql = "SELECT Data FROM TB_ProcedureHistory " + "WHERE (ProductID = @ProductID) AND (Process = @Process)"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Process", System.Data.SqlDbType.VarChar, 50, "Process")); sqlCommandMain.Parameters["@Process"].Value = Process; adapter.SelectCommand = sqlCommandMain; DataSet dataSet = new DataSet(); try { sqlConnectionMain.Open(); adapter.Fill(dataSet, "TB_ProcedureHistory"); } finally { sqlConnectionMain.Close(); } if (dataSet.Tables["TB_ProcedureHistory"].Rows.Count > 0) { DataRow row = dataSet.Tables["TB_ProcedureHistory"].Rows[0]; string tmp = row["Data"].ToString(); return(tmp); } else { return(string.Empty); } }
public bool ProcedureChanged(string BarCode) { // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return(false); } try { sqlConnectionMain.Open(); string sql; sql = "SELECT TOP 1 Result FROM TB_ProcedureHistory WHERE (ProductID = @ProductID) " + "ORDER BY BeginTime DESC"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; //sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PlanID", System.Data.SqlDbType.VarChar, 50, "PlanID")); //sqlCommandMain.Parameters["@PlanID"].Value = PlanID; DataReaderMain = sqlCommandMain.ExecuteReader(); if (DataReaderMain.Read()) { if (!DataReaderMain.IsDBNull(DataReaderMain.GetOrdinal("Result"))) { int Result = DataReaderMain.GetInt32(DataReaderMain.GetOrdinal("Result")); if (Result == 2) { DataReaderMain.Close(); return(true); } } } DataReaderMain.Close(); return(false); } finally { sqlConnectionMain.Close(); } }
public bool CheckModelByBarCode(string BarCode, string UID, int Flag) { // 获取品号 string oMsg; ProductTrace pt = new ProductTrace(); string ModelID = pt.GetModelID(BarCode, out oMsg); if (ModelID == string.Empty) { return(false); } return(CheckModel(ModelID, UID, Flag)); }
public bool CanDoNext(string BarCode, string Process) { // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return(false); } // 获取所有下道工序 DataSet ProcessConfig = GetProcedure(ProductID); if (ProcessConfig == null) { return(false); } DataView view = new DataView(ProcessConfig.Tables["Connection"]); view.RowFilter = string.Format("From = '{0}'", Process); ArrayList OutProcess = new ArrayList(); for (int i = 0; i < view.Count; i++) { OutProcess.Add(view[i]["To"]); } // 逐个比较这些工序的上道工序是否已完成,只要有一个完成就认为可进入下道工序 foreach (string tmp in OutProcess) { if (CheckProcedure(BarCode, tmp, 0, out oMsg)) { return(true); } } return(false); }
public bool CanDoNext(string BarCode, string Process) { // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return false; } // 获取所有下道工序 DataSet ProcessConfig = GetProcedure(ProductID); if (ProcessConfig == null) { return false; } DataView view = new DataView(ProcessConfig.Tables["Connection"]); view.RowFilter = string.Format("From = '{0}'", Process); ArrayList OutProcess = new ArrayList(); for (int i = 0; i < view.Count; i++) { OutProcess.Add(view[i]["To"]); } // 逐个比较这些工序的上道工序是否已完成,只要有一个完成就认为可进入下道工序 foreach (string tmp in OutProcess) { if (CheckProcedure(BarCode, tmp, 0, out oMsg)) return true; } return false; }
public bool CheckProcedure(string BarCode, string Process, int BeginOrEnd, out string oMsg) { // 根据条码获得产品序列号 ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return(false); } string sql; bool ret; //首先判断产品是否处于返修状态 if (RepairProduct(ProductID)) { oMsg = "产品需返修"; return(false); } //查工序配置表 DataSet dataSet = GetProcedure(ProductID); if (dataSet == null) { oMsg = "工艺流程不存在或定义错误"; return(false); } //查输入的工序参数是否存在 DataView vProcess = new DataView(dataSet.Tables["Process"]); vProcess.RowFilter = string.Format("Name = '{0}'", Process);// 注意:此处的比较为大小写不敏感的,故有下一句的再次比较 if (vProcess.Count == 0 || vProcess[0]["Name"].ToString() != Process) { oMsg = "输入参数错误(工序不存在)"; return(false); } //加入,判断产品流程是否发生变更 if (ProcedureChanged(ProductID)) { oMsg = "因流程变更,本工序不受控"; return(true); } try { sqlConnectionMain.Open(); switch (BeginOrEnd) { case 0: //begin // 判断上一道工序是否未结束 sql = "SELECT * FROM (" + " SELECT TOP 1 Result FROM TB_ProcedureHistory WHERE (ProductID = @ProductID) ORDER BY BeginTime DESC" + ") A WHERE Result is NULL"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; DataReaderMain = sqlCommandMain.ExecuteReader(); if (DataReaderMain.Read()) { oMsg = "上一道工序未结束"; ret = false; break; } DataReaderMain.Close(); sqlConnectionMain.Close(); //下面代码对于有重名工序的流程无法通过 //得到所有已完成的工序,并比较被检查的工序是否已包含在已完成工序中 string[] FinishedProcess = GetFinishedProcess(ProductID); if (FinishedProcess.Contains(Process)) { oMsg = "本工序已完成"; ret = false; } else { //获得当前工序的所有入口工序 DataView view = new DataView(dataSet.Tables["Connection"]); view.RowFilter = string.Format("To = '{0}'", Process); ArrayList InProcess = new ArrayList(); for (int i = 0; i < view.Count; i++) { InProcess.Add(view[i]["From"]); } //比较后可知当前工序的所有入口工序是否都已完成 string[] tmpIn = (string[])InProcess.ToArray(typeof(string)); string[] tmp = FinishedProcess.Intersect(tmpIn).ToArray(); tmp = tmpIn.Except(tmp).ToArray(); //tmp = tmp.Count() == 0 ? tmpIn : tmp.Except(tmpIn).ToArray(); if (tmp.Count() == 0) { oMsg = string.Empty; ret = true; } else { oMsg = "尚未执行到本工序"; ret = false; } } break; case 1: //end sql = "SELECT TOP 1 Process, Result FROM TB_ProcedureHistory WHERE (ProductID = @ProductID)" + "ORDER BY BeginTime DESC"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; DataReaderMain = sqlCommandMain.ExecuteReader(); if (DataReaderMain.Read()) { string QueryProcess = DataReaderMain.GetString(DataReaderMain.GetOrdinal("Process")); if (QueryProcess == Process) { if (DataReaderMain.IsDBNull(DataReaderMain.GetOrdinal("Result"))) { oMsg = string.Empty; ret = true; break; } else { oMsg = "本工序已完成"; ret = false; break; } } } oMsg = "本工序不是当前工序"; ret = false; break; default: oMsg = "输入参数错误(无效的工序状态)"; ret = false; break; } DataReaderMain.Close(); return(ret); } finally { sqlConnectionMain.Close(); } }
public bool SaveProcessBegin(string BarCode, string Process, string EmployeeID, DateTime BeginTime, out string oMsg) { //工艺流程检查 if (!CheckProcedure(BarCode, Process, 0, out oMsg)) { return(false); } // 获取产品序列号 ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return(false); } //获取班组排工信息 string WorkDispatch = GetDispatch(EmployeeID); //写数据库 try { sqlConnectionMain.Open(); SqlTransaction transaction = sqlConnectionMain.BeginTransaction(); sqlCommandMain.Transaction = transaction; try { Guid DataID = Guid.NewGuid(); //记录生产流程历史 InsertProcedureHistory(ProductID, Process, EmployeeID, int.MaxValue, null, null, DataID, BeginTime, DateTime.MaxValue, WorkDispatch); ////记录生产流程状态 //InsertProcedureState(ProductID, Process, null); ////更新产品档案表中的字段[ManufactureState] //UpdateManufactureState(ProductID, null); // Attempt to commit the transaction. transaction.Commit(); oMsg = string.Empty; return(true); } catch (Exception ex) { Trace.Write(ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception e) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Trace.Write(e.Message); } oMsg = "写数据库出错"; return(false); } } finally { sqlConnectionMain.Close(); } }
public bool CheckModelByBarCode(string BarCode, string UID, int Flag) { // 获取品号 string oMsg; ProductTrace pt = new ProductTrace(); string ModelID = pt.GetModelID(BarCode, out oMsg); if (ModelID == string.Empty) { return false; } return CheckModel(ModelID, UID, Flag); }
public bool SaveProcessBegin(string BarCode, string Process, string EmployeeID, DateTime BeginTime, out string oMsg) { //工艺流程检查 if (!CheckProcedure(BarCode, Process, 0, out oMsg)) { return false; } // 获取产品序列号 ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return false; } //获取班组排工信息 string WorkDispatch = GetDispatch(EmployeeID); //写数据库 try { sqlConnectionMain.Open(); SqlTransaction transaction = sqlConnectionMain.BeginTransaction(); sqlCommandMain.Transaction = transaction; try { Guid DataID = Guid.NewGuid(); //记录生产流程历史 InsertProcedureHistory(ProductID, Process, EmployeeID, int.MaxValue, null, null, DataID, BeginTime, DateTime.MaxValue, WorkDispatch); ////记录生产流程状态 //InsertProcedureState(ProductID, Process, null); ////更新产品档案表中的字段[ManufactureState] //UpdateManufactureState(ProductID, null); // Attempt to commit the transaction. transaction.Commit(); oMsg = string.Empty; return true; } catch (Exception ex) { Trace.Write(ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception e) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Trace.Write(e.Message); } oMsg = "写数据库出错"; return false; } } finally { sqlConnectionMain.Close(); } }
public bool RepairProduct(string BarCode) { // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return false; } try { sqlConnectionMain.Open(); string sql; sql = "SELECT TOP 1 Result FROM TB_ProcedureHistory WHERE (ProductID = @ProductID) " + "ORDER BY BeginTime DESC"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; DataReaderMain = sqlCommandMain.ExecuteReader(); if (DataReaderMain.Read()) { if (!DataReaderMain.IsDBNull(DataReaderMain.GetOrdinal("Result"))) { int Result = DataReaderMain.GetInt32(DataReaderMain.GetOrdinal("Result")); if (Result == 1) { DataReaderMain.Close(); return true; } } } DataReaderMain.Close(); return false; } finally { sqlConnectionMain.Close(); } }
public string[] GetFinishedProcess(string BarCode) { //string[] id1 = { "装配", "总装", "老化", "测试" }; //string[] id2 = { "装配1", "总装1" }; //ArrayList al1 = new ArrayList(id1); //ArrayList al2 = new ArrayList(id2); //string[] id3 = id1.Intersect(id2).ToArray(); //string[] id4 = id2.Except(id3).ToArray(); //string[] id5 = id3.Except(id2).ToArray(); //string[] id6 = id3.Intersect(id2).ToArray(); //string[] id7 = id2.Intersect(id3).ToArray(); //if (id3.Count() == 0) //{ // return id2; //} //{ // return id1; //} //foreach (string id in both) // Console.WriteLine(id); // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { string[] ret1 = new string[0]; return ret1; } string sql; SqlDataAdapter adapter = new SqlDataAdapter(); sql = "SELECT Process FROM TB_ProcedureState WHERE (ProductID = @ProductID)"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; adapter.SelectCommand = sqlCommandMain; DataSet dataSet = new DataSet(); try { sqlConnectionMain.Open(); adapter.Fill(dataSet, "TB_ProcedureState"); } finally { sqlConnectionMain.Close(); } int n = dataSet.Tables["TB_ProcedureState"].Rows.Count; string[] ret = new string[n]; n = 0; foreach (DataRow row in dataSet.Tables["TB_ProcedureState"].Rows) { ret[n] = row["Process"].ToString(); n++; } return ret; }
public string GetData(string BarCode, string Process) { // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return string.Empty; } string sql; SqlDataAdapter adapter = new SqlDataAdapter(); sql = "SELECT Data FROM TB_ProcedureHistory " + "WHERE (ProductID = @ProductID) AND (Process = @Process)"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Process", System.Data.SqlDbType.VarChar, 50, "Process")); sqlCommandMain.Parameters["@Process"].Value = Process; adapter.SelectCommand = sqlCommandMain; DataSet dataSet = new DataSet(); try { sqlConnectionMain.Open(); adapter.Fill(dataSet, "TB_ProcedureHistory"); } finally { sqlConnectionMain.Close(); } if (dataSet.Tables["TB_ProcedureHistory"].Rows.Count > 0) { DataRow row = dataSet.Tables["TB_ProcedureHistory"].Rows[0]; string tmp = row["Data"].ToString(); return tmp; } else { return string.Empty; } }
public bool CheckProcedure(string BarCode, string Process, int BeginOrEnd, out string oMsg) { // 根据条码获得产品序列号 ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return false; } string sql; bool ret; //首先判断产品是否处于返修状态 if (RepairProduct(ProductID)) { oMsg = "产品需返修"; return false; } //查工序配置表 DataSet dataSet = GetProcedure(ProductID); if (dataSet == null) { oMsg = "工艺流程不存在或定义错误"; return false; } //查输入的工序参数是否存在 DataView vProcess = new DataView(dataSet.Tables["Process"]); vProcess.RowFilter = string.Format("Name = '{0}'", Process);// 注意:此处的比较为大小写不敏感的,故有下一句的再次比较 if (vProcess.Count == 0 || vProcess[0]["Name"].ToString() != Process) { oMsg = "输入参数错误(工序不存在)"; return false; } //加入,判断产品流程是否发生变更 if (ProcedureChanged(ProductID)) { oMsg = "因流程变更,本工序不受控"; return true; } try { sqlConnectionMain.Open(); switch (BeginOrEnd) { case 0: //begin // 判断上一道工序是否未结束 sql = "SELECT * FROM (" +" SELECT TOP 1 Result FROM TB_ProcedureHistory WHERE (ProductID = @ProductID) ORDER BY BeginTime DESC" + ") A WHERE Result is NULL"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; DataReaderMain = sqlCommandMain.ExecuteReader(); if (DataReaderMain.Read()) { oMsg = "上一道工序未结束"; ret = false; break; } DataReaderMain.Close(); sqlConnectionMain.Close(); //下面代码对于有重名工序的流程无法通过 //得到所有已完成的工序,并比较被检查的工序是否已包含在已完成工序中 string[] FinishedProcess = GetFinishedProcess(ProductID); if (FinishedProcess.Contains(Process)) { oMsg = "本工序已完成"; ret = false; } else { //获得当前工序的所有入口工序 DataView view = new DataView(dataSet.Tables["Connection"]); view.RowFilter = string.Format("To = '{0}'", Process); ArrayList InProcess = new ArrayList(); for (int i = 0; i < view.Count; i++) { InProcess.Add(view[i]["From"]); } //比较后可知当前工序的所有入口工序是否都已完成 string[] tmpIn = (string[])InProcess.ToArray(typeof(string)); string[] tmp = FinishedProcess.Intersect(tmpIn).ToArray(); tmp = tmpIn.Except(tmp).ToArray(); //tmp = tmp.Count() == 0 ? tmpIn : tmp.Except(tmpIn).ToArray(); if (tmp.Count() == 0) { oMsg = string.Empty; ret = true; } else { oMsg = "尚未执行到本工序"; ret = false; } } break; case 1: //end sql = "SELECT TOP 1 Process, Result FROM TB_ProcedureHistory WHERE (ProductID = @ProductID)" + "ORDER BY BeginTime DESC"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; DataReaderMain = sqlCommandMain.ExecuteReader(); if (DataReaderMain.Read()) { string QueryProcess = DataReaderMain.GetString(DataReaderMain.GetOrdinal("Process")); if (QueryProcess == Process) { if (DataReaderMain.IsDBNull(DataReaderMain.GetOrdinal("Result"))) { oMsg = string.Empty; ret = true; break; } else { oMsg = "本工序已完成"; ret = false; break; } } } oMsg = "本工序不是当前工序"; ret = false; break; default: oMsg = "输入参数错误(无效的工序状态)"; ret = false; break; } DataReaderMain.Close(); return ret; } finally { sqlConnectionMain.Close(); } }
public string[] GetFinishedProcess(string BarCode) { //string[] id1 = { "装配", "总装", "老化", "测试" }; //string[] id2 = { "装配1", "总装1" }; //ArrayList al1 = new ArrayList(id1); //ArrayList al2 = new ArrayList(id2); //string[] id3 = id1.Intersect(id2).ToArray(); //string[] id4 = id2.Except(id3).ToArray(); //string[] id5 = id3.Except(id2).ToArray(); //string[] id6 = id3.Intersect(id2).ToArray(); //string[] id7 = id2.Intersect(id3).ToArray(); //if (id3.Count() == 0) //{ // return id2; //} //{ // return id1; //} //foreach (string id in both) // Console.WriteLine(id); // 获取产品序列号 string oMsg; ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { string[] ret1 = new string[0]; return(ret1); } string sql; SqlDataAdapter adapter = new SqlDataAdapter(); sql = "SELECT Process FROM TB_ProcedureState WHERE (ProductID = @ProductID)"; sqlCommandMain.CommandText = sql; sqlCommandMain.Parameters.Clear(); sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductID", System.Data.SqlDbType.VarChar, 50, "ProductID")); sqlCommandMain.Parameters["@ProductID"].Value = ProductID; adapter.SelectCommand = sqlCommandMain; DataSet dataSet = new DataSet(); try { sqlConnectionMain.Open(); adapter.Fill(dataSet, "TB_ProcedureState"); } finally { sqlConnectionMain.Close(); } int n = dataSet.Tables["TB_ProcedureState"].Rows.Count; string[] ret = new string[n]; n = 0; foreach (DataRow row in dataSet.Tables["TB_ProcedureState"].Rows) { ret[n] = row["Process"].ToString(); n++; } return(ret); }
public bool SaveProcess(string BarCode, string Process, string EmployeeID, int Result, string Exception, string Data, DateTime BeginTime, DateTime EndTime, out string oMsg) { //作业结果检查 if (Result != 0 && Result != 1) { oMsg = "作业结果中输入未定义值"; return(false); } //数据格式检查 try { DataFormatChecker.CheckFormat(Data); } catch (Exception e) { oMsg = e.Message; return(false); } //工艺流程检查 if (!CheckProcedure(BarCode, Process, 0, out oMsg)) { return(false); } // 获取产品序列号 ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return(false); } //获取班组排工信息 string WorkDispatch = GetDispatch(EmployeeID); //获取工序的工段范围 string Range; if (Result == 0) { Range = GetRange(ProductID, Process); } else { Range = "返修"; } //写数据库 try { sqlConnectionMain.Open(); SqlTransaction transaction = sqlConnectionMain.BeginTransaction(); sqlCommandMain.Transaction = transaction; try { Guid DataID = Guid.NewGuid(); //记录生产流程历史 InsertProcedureHistory(ProductID, Process, EmployeeID, Result, Exception, Data, DataID, BeginTime, EndTime, WorkDispatch); //记录生产流程状态 InsertProcedureState(ProductID, Process, DataID); //更新产品档案表中的字段[ManufactureState] UpdateManufactureState(ProductID, Range); // Attempt to commit the transaction. transaction.Commit(); oMsg = string.Empty; return(true); } catch (Exception ex) { Trace.Write(ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception e) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Trace.Write(e.Message); } oMsg = "写数据库出错"; return(false); } } finally { sqlConnectionMain.Close(); } }
public bool SaveProcessEnd(string BarCode, string Process, int Result, string Exception, string Data, DateTime EndTime, out string oMsg) { //作业结果检查 if (Result != 0 && Result != 1) { oMsg = "作业结果中输入未定义值"; return false; } //数据格式检查 try { DataFormatChecker.CheckFormat(Data); } catch (Exception e) { oMsg = e.Message; return false; } //工艺流程检查 if (!CheckProcedure(BarCode, Process, 1, out oMsg)) { return false; } // 获取产品序列号 ProductTrace pt = new ProductTrace(); string ProductID = pt.GetProductID(BarCode, out oMsg); if (ProductID == string.Empty) { return false; } //获取工序的工段范围 string Range; if (Result == 0) Range = GetRange(ProductID, Process); else Range = "返修"; //写数据库 try { sqlConnectionMain.Open(); SqlTransaction transaction = sqlConnectionMain.BeginTransaction(); sqlCommandMain.Transaction = transaction; try { Guid DataID; //记录生产流程历史 UpdateProcedureHistory(ProductID, Process, Result, Exception, Data, EndTime, out DataID); //记录生产流程状态 InsertProcedureState(ProductID, Process, DataID); //更新产品档案表中的字段[ManufactureState] UpdateManufactureState(ProductID, Range); // Attempt to commit the transaction. transaction.Commit(); oMsg = string.Empty; return true; } catch (Exception ex) { Trace.Write(ex.Message); // Attempt to roll back the transaction. try { transaction.Rollback(); } catch (Exception e) { // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Trace.Write(e.Message); } oMsg = "写数据库出错:" + ex.Message; return false; } } finally { sqlConnectionMain.Close(); } }