Esempio n. 1
0
        public bool SaveCalibrateRecord(string Model, string SN, string ProductModel, string EmployeeID, string Data, out string oMsg)
        {
            //数据格式检查
            try
            {
                DataFormatChecker.CheckCalFormat(Data);
            }
            catch (Exception e)
            {
                oMsg = e.Message;
                return(false);
            }

            try
            {
                sqlCommandMain.CommandText = "INSERT INTO TB_InstrumentCalRecord(Model, SN, ProductModel, EmployeeID, CalTime, Data) " +
                                             "VALUES (@Model, @SN, @ProductModel, @EmployeeID, GETDATE(), @Data)";
                sqlCommandMain.Parameters.Clear();
                sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Model", System.Data.SqlDbType.VarChar, 50));
                sqlCommandMain.Parameters["@Model"].Value = Model;
                sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@SN", System.Data.SqlDbType.VarChar, 50));
                sqlCommandMain.Parameters["@SN"].Value = SN;
                sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ProductModel", System.Data.SqlDbType.VarChar, 50));
                sqlCommandMain.Parameters["@ProductModel"].Value = ProductModel;
                sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@EmployeeID", System.Data.SqlDbType.VarChar, 50));
                sqlCommandMain.Parameters["@EmployeeID"].Value = EmployeeID;
                sqlCommandMain.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Data", System.Data.SqlDbType.Text));
                sqlCommandMain.Parameters["@Data"].Value = (System.Data.SqlTypes.SqlString)Data;
                try
                {
                    sqlConnectionMain.Open();

                    sqlCommandMain.ExecuteNonQuery();
                }
                finally
                {
                    sqlConnectionMain.Close();
                }
            }
            catch (Exception ex)
            {
                Trace.Write(ex.Message);

                oMsg = "写数据库出错:" + ex.Message;
                return(false);
            }

            oMsg = string.Empty;
            return(true);
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        public bool SaveProcessPurely(string BarCode, string Process, string EmployeeID, int Result,
                                      string Exception, string Data, DateTime BeginTime, DateTime EndTime,
                                      out string oMsg)
        {
            //作业结果检查
            if (Result != 0 && Result != 1 && Result != 2)
            {
                oMsg = "作业结果中输入未定义值";
                return(false);
            }

            //数据格式检查
            try
            {
                DataFormatChecker.CheckFormat(Data);
            }
            catch (Exception e)
            {
                oMsg = e.Message;
                return(false);
            }

            //写数据库
            try
            {
                sqlConnectionMain.Open();

                SqlTransaction transaction = sqlConnectionMain.BeginTransaction();
                sqlCommandMain.Transaction = transaction;

                try
                {
                    Guid DataID = Guid.NewGuid();

                    //记录生产流程历史
                    InsertProcedureHistory(BarCode, Process, EmployeeID, Result, Exception, Data, DataID, BeginTime, EndTime, "NoWorkDispatch");

                    // 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();
            }
        }