Exemplo n.º 1
0
        /// <summary>
        /// 將檢測資料插入資料庫中
        /// </summary>
        /// <param name="NowProductInfo">當前機台資料物件</param>
        /// <param name="Station">當站站名</param>
        /// <param name="TestItem">測試項目</param>
        /// <param name="TestResult">測試結果 PASS,NG</param>
        /// <param name="MeasureValue">測試數值</param>
        /// <param name="NowDate">測試日期YYYYMMDD</param>
        /// <param name="NowTime">測試時間HHMMSS</param>
        /// <param name="ErrorMessage">錯誤訊息</param>
        /// <returns></returns>
        public bool InsertTestResultRecord(ProductInfo NowProductInfo, string Station, string TestItem, string TestResult, string MeasureValue, string NowDate, string NowTime, out string ErrorMessage)
        {
            //string dbHost = ResultReaderSystemPara.DataBaseHost;///資料庫位址
            //string dbUser = ResultReaderSystemPara.DataBaseAccontName;///資料庫使用者名稱
            //string dbPass = ResultReaderSystemPara.DataBaseAccontPassword;///"資料庫使用者密碼"
            //string dbName = "WIP";///資料庫名稱;
            ErrorMessage = "";
            using (SqlConnection cn = new SqlConnection())
            {
                cn.ConnectionString = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
                cn.Open();

                if (cn.State == ConnectionState.Open)
                {
                    string InsertToUsbTestRecord = "INSERT INTO PICS.dbo.HCS_UsbTestRecode(";
                    string VALUES = ") VALUES(";

                    SQL_HcsUsbTestRecordTable sql_TestRecord = new SQL_HcsUsbTestRecordTable();

                    SqlTransaction tran = cn.BeginTransaction();
                    try
                    {
                        string sqlstr = InsertToUsbTestRecord
                                        + sql_TestRecord.TRID + "," + sql_TestRecord.ID + ","
                                        + sql_TestRecord.PN + ","
                                        + sql_TestRecord.Model + ","
                                        + sql_TestRecord.Datein + "," + sql_TestRecord.Timein + ","
                                        + sql_TestRecord.TestItem + ","
                                        + sql_TestRecord.TestResult + ","
                                        + sql_TestRecord.SO + ","
                                        + sql_TestRecord.Station + ","
                                        + sql_TestRecord.MeasureValue

                                        + VALUES
                                        + "'" + NowProductInfo.TRID + "'" + "," + "'" + NowProductInfo.ID + "'" + ","
                                        + "'" + NowProductInfo.PartNo + "'" + ","
                                        + "'" + NowProductInfo.ModelName + "'" + ","
                                        + "'" + NowDate + "'" + "," + "'" + NowTime + "'" + ","
                                        + "'" + TestItem + "'" + ","
                                        + "'" + TestResult + "'" + ","
                                        + "'" + NowProductInfo.SoNo + "'" + ","
                                        + "'" + Station + "'" + ","
                                        + "'" + MeasureValue + "'"
                                        + ")";

                        SqlCommand cmd = new SqlCommand(sqlstr, cn, tran);

                        cmd.ExecuteNonQuery();
                        tran.Commit();

                        return(true);
                    }
                    catch (SqlException ex)
                    {
                        tran.Rollback();
                        ErrorMessage = ex.ToString();
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 將檢測資料插入資料庫中
        /// </summary>
        /// <param name="NowProductInfo">當前機台資料物件</param>
        /// <param name="Station">當站站名</param>
        /// <param name="TestItem">測試項目</param>
        /// <param name="TestResult">測試結果 PASS,NG</param>
        /// <param name="MeasureValue">測試數值</param>
        /// <param name="NowDate">測試日期YYYYMMDD</param>
        /// <param name="NowTime">測試時間HHMMSS</param>
        /// <param name="ErrorMessage">錯誤訊息</param>
        /// <returns></returns>
        public bool InsertTestResultRecord(ProductInfo NowProductInfo, string Station, string TestItem, string TestResult, string MeasureValue,
                                           string HwVersion, string SwVersion, string ToolVersion,
                                           string NowDate, string NowTime, out string ErrorMessage)
        {
            ErrorMessage = "";


            ///抓取機台產品訊息(將剛刷入的TRID進資料庫抓取相對應的機台資訊(包含ModelName,料號,工廠流線ID號碼))
            CheckTRID(NowProductInfo.TRID, ref NowProductInfo, out ErrorMessage);

            using (SqlConnection cn = new SqlConnection())
            {
                cn.ConnectionString = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;

                try
                {
                    cn.Open();
                }
                catch (SqlException ex)
                {
                    ErrorMessage = ex.Message;
                    return(false);
                }

                if (cn.State == ConnectionState.Open)
                {
                    string InsertToUsbTestRecord = "INSERT INTO PICS.dbo.HCS_UsbTestRecode(";
                    string VALUES = ") VALUES(";

                    SQL_HcsUsbTestRecordTable sql_TestRecord = new SQL_HcsUsbTestRecordTable();

                    SqlTransaction tran = cn.BeginTransaction();
                    try
                    {
                        string sqlstr = InsertToUsbTestRecord
                                        + sql_TestRecord.TRID + "," + sql_TestRecord.ID + ","
                                        + sql_TestRecord.PN + ","
                                        + sql_TestRecord.Model + ","
                                        + sql_TestRecord.Datein + "," + sql_TestRecord.Timein + ","
                                        + sql_TestRecord.TestItem + ","
                                        + sql_TestRecord.TestResult + ","
                                        + sql_TestRecord.SO + ","
                                        + sql_TestRecord.Station + ","
                                        + sql_TestRecord.MeasureValue + ","
                                        + sql_TestRecord.HwVersion + ","
                                        + sql_TestRecord.SwVersion + ","
                                        + sql_TestRecord.ToolVersion

                                        + VALUES
                                        + "'" + NowProductInfo.TRID + "'" + "," + "'" + NowProductInfo.ID + "'" + ","
                                        + "'" + NowProductInfo.PartNo + "'" + ","
                                        + "'" + NowProductInfo.ModelName + "'" + ","
                                        + "'" + NowDate + "'" + "," + "'" + NowTime + "'" + ","
                                        + "'" + TestItem + "'" + ","
                                        + "'" + TestResult + "'" + ","
                                        + "'" + NowProductInfo.SoNo + "'" + ","
                                        + "'" + Station + "'" + ","
                                        + "'" + MeasureValue + "'" + ","
                                        + "'" + HwVersion + "'" + ","
                                        + "'" + SwVersion + "'" + ","
                                        + "'" + ToolVersion + "'"
                                        + ")";

                        SqlCommand cmd = new SqlCommand(sqlstr, cn, tran);

                        cmd.ExecuteNonQuery();
                        tran.Commit();

                        return(true);
                    }
                    catch (SqlException ex)
                    {
                        tran.Rollback();
                        ErrorMessage = ex.Message;
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }