Beispiel #1
0
 void DataTransferFinished(object sender, DataTransferFinishedArgs e)
 {
     if (nCount > 300)
     {
         richTextBox1.Text = "";
         nCount            = 0;
     }
     richTextBox1.Text = e.TransferMsg + "\n" + richTextBox1.Text;
     txtTestTime.Text  = string.Format("{0:yyyy-MM-dd HH:mm:ss}", e.MaxTestDateTime.ToString());
     txtFilePath.Text  = e.TransferDbFile;
     timer1.Enabled    = true;
 }
        /// <summary>
        /// 将数据从Access数据库转移到MES数据库。
        /// </summary>
        /// <param name="element">设备配置。</param>
        /// <returns>true:转置成功。false:转置失败。</returns>
        public void Execute(IVTestDeviceElement element, System.DateTime MaxTestDateTimeFromServer)
        {
            bool   blTransferDataResult = true;
            string strTransferDataMsg   = "";

            dNewMaxTestTime    = MaxTestDateTimeFromServer;
            dMaxUploadTestTime = MaxTestDateTimeFromServer;
            List <string> lstSqlForInsert = new List <string>();
            List <string> lstSqlForUpdateIVDataDefault = new List <string>();

            try
            {
                String _day = SqlHelper.ExecuteDataTable("select max(InspectTime) from ZWIP_COROL_TEST", connHost).Rows[0][0].ToString();

                string    _str = "select top 1 [LotSN] ,[InspectTime] ,[InspectResult] ,[InspectValue],[BlueValue],[Operator],[Shift],[RcpName],[LocalIp],[DeviceID] from t_ColorInspectResult  where InspectTime > '" + _day + "'order by [InspectTime] ";
                DataTable d1t  = SqlHelper.ExecuteDataTable(_str, connClient);
                if (d1t.Rows.Count > 0)
                {
                }
                else
                {
                    strTransferDataMsg   = string.Format("没有找到对应的COLOR数据文件{0} ", strAccessFullPath);
                    blTransferDataResult = false;
                }
                DataTable dt = null;

                if (blTransferDataResult)
                {
                    String _keysql = "select count(*) from ZWIP_COROL_TEST where LOT_NUMBER ='" + d1t.Rows[0]["LotSN"].ToString() + "'and InspectTime='" + d1t.Rows[0]["InspectTime"].ToString() + "'";
                    int    _key    = Convert.ToInt32(SqlHelper.ExecuteDataTable(_keysql, connHost).Rows[0][0]);
                    if (_key == 0)
                    {
                        #region Builder Insert Sql
                        StringBuilder sbsql = new StringBuilder();
                        sbsql.Append("INSERT INTO [ZWIP_COROL_TEST] ([LOT_NUMBER] ,[InspectTime] ,[InspctResult],[InspectValue] ,[BlueValue]  ,[Opetator] ,[Shift] ,[RcpName]  ,[LocalIp],[DeviceID] ,[DataTime])");
                        sbsql.Append("VALUES ( ");
                        sbsql.Append("'" + d1t.Rows[0]["LotSN"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["InspectTime"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["InspectResult"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["InspectValue"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["BlueValue"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["Operator"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["Shift"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["RcpName"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["LocalIp"].ToString() + "',");
                        sbsql.Append("'" + d1t.Rows[0]["DeviceID"].ToString() + "',");
                        sbsql.Append("'" + DateTime.Now + "'");
                        sbsql.Append(" )");

                        string _str1 = sbsql.ToString();

                        SqlHelper.ExecuteNonQuery(_str1, connHost);
                        sbsql.Clear();
                        //isDefault = false;
                        #endregion
                    }
                    else
                    {
                        strTransferDataMsg = string.Format("{1:yyyy-MM-dd HH:mm:ss}数据已存在>{0} ", strTransferDataMsg, System.DateTime.Now.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                blTransferDataResult = false;
                strTransferDataMsg   = ex.Message;
            }
            finally
            {
                lstSqlForInsert.Clear();
                lstSqlForUpdateIVDataDefault.Clear();
            }


            DataTransferFinishedArgs arg = new DataTransferFinishedArgs();
            arg.TransferDataResult = blTransferDataResult;
            arg.TransferDbFile     = strAccessFullPath;
            if (blTransferDataResult)
            {
                strTransferDataMsg  = string.Format("{1:yyyy-MM-dd HH:mm:ss}上传Coler数据成功>{0} ", strTransferDataMsg, System.DateTime.Now.ToString());
                arg.MaxTestDateTime = dNewMaxTestTime;
            }
            else
            {
                strTransferDataMsg  = string.Format("{1:yyyy-MM-dd HH:mm:ss}上传Coler数据失败>{0} ", strTransferDataMsg, System.DateTime.Now.ToString());
                arg.MaxTestDateTime = dMaxUploadTestTime;
            }
            arg.TransferMsg = strTransferDataMsg;

            if (OnDataTransferFinished != null)
            {
                OnDataTransferFinished(this, arg);
            }
        }