Esempio n. 1
0
        /// <summary>
        /// 讀取Ini中BCR Config區塊相關設定
        /// </summary>
        /// <param name="IniFile"></param>
        private static void funSetBCR(clsIniFile IniFile)
        {
            string strSection = "BCR Config";
            string strKey     = string.Empty;
            string strValues  = string.Empty;

            strKey = "BCRQty";
            clsSystem.gintBCRQty = IniFile.funReadValue(strSection, strKey, 8);
            strKey = "BCRID";
            clsSystem.gstrarrBCRID = IniFile.funReadValue(strSection, strKey, "").Split(',');
            strKey = "BCRPort";
            clsSystem.gstrarrPortName = IniFile.funReadValue(strSection, strKey, "").Split(',');

            for (int intCount = 0; intCount < clsSystem.gintBCRQty; intCount++)
            {
                clsCustomSerialPort CustomSerialPort = new clsCustomSerialPort(clsSystem.gstrarrBCRID[intCount], clsSystem.gstrarrPortName[intCount]);
                clsSystem.glstBCRMap.Add(CustomSerialPort);
            }
        }
        private void funGetBCRInfo()
        {
            string    strSQL       = string.Empty;
            string    strEM        = string.Empty;
            DataTable objDataTable = new DataTable();

            try
            {
                strSQL = "SELECT * FROM IN_BUF WHERE BCR_NO IN ('" + string.Join("', '", clsSystem.gstrarrBCRID) + "')";
                if (clsSystem.gobjDB.funGetDT(strSQL, ref objDataTable, ref strEM) == ErrDef.ProcSuccess)
                {
                    clsSystem.intBCRCount = objDataTable.Rows.Count;

                    for (int intCount = 0; intCount < objDataTable.Rows.Count; intCount++)
                    {
                        string strBCRNo  = objDataTable.Rows[intCount]["BCR_NO"].ToString();
                        string strBCRSts = objDataTable.Rows[intCount]["BCR_STS"].ToString();
                        string strBCRID  = objDataTable.Rows[intCount]["BCR_DATA"].ToString();

                        if (clsSystem.glstBCRMap.Exists(BCR => BCR.BCRNo == strBCRNo))
                        {
                            clsCustomSerialPort CustomSerialPort = clsSystem.glstBCRMap.Find(BCR => BCR.BCRNo == strBCRNo);

                            if (tlpBCR.Controls.ContainsKey("lblBCRSts1_" + strBCRNo))
                            {
                                Label objLabel = (Label)tlpBCR.Controls["lblBCRSts1_" + strBCRNo];
                                funShowConnect(CustomSerialPort.IsOpen, objLabel);
                            }
                            if (tlpBCR.Controls.ContainsKey("lblBCRReadID_" + strBCRNo))
                            {
                                Label objLabel = (Label)tlpBCR.Controls["lblBCRReadID_" + strBCRNo];
                                objLabel.Text = strBCRID;

                                if (tlpBCR.Controls.ContainsKey("lblReadingTime_" + strBCRNo) && strBCRID != "n/a")
                                {
                                    Label objLabel2 = (Label)tlpBCR.Controls["lblReadingTime_" + strBCRNo];
                                    objLabel2.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                                }
                            }
                            if (tlpBCR.Controls.ContainsKey("lblBCRSts2_" + strBCRNo))
                            {
                                Label objLabel = (Label)tlpBCR.Controls["lblBCRSts2_" + strBCRNo];
                                funShowBCRSts(strBCRSts, objLabel);

                                if (strBCRSts == cstrBCRReading)
                                {
                                    CustomSerialPort.DiscardOutBuffer();
                                    CustomSerialPort.DiscardInBuffer();
                                    CustomSerialPort.Write("LON" + "\r");
                                    Thread.Sleep(500);
                                    CustomSerialPort.Write("LOFF" + "\r");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var varObject = MethodBase.GetCurrentMethod();
                clsSystem.funWriteExceptionLog(varObject.DeclaringType.FullName, varObject.Name, ex.Message);
            }
            finally
            {
                if (objDataTable != null)
                {
                    objDataTable.Clear();
                    objDataTable.Dispose();
                    objDataTable = null;
                }
            }
        }