Пример #1
0
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs s)
        {
            try
            {
                SyncLock.WaitOne();
                BarcodeTransaction bt        = new BarcodeTransaction();
                SerialPort         sp        = (SerialPort)sender;
                string             ReadData  = sp.ReadExisting();
                string             ModSerNum = ReadData.Substring(0, 14);
                int ReaderID = 1;

                //if (!Int32.TryParse(ReadData.Substring(15, 2), out ReaderID))
                //    throw new FormatException("Can not parse Barcode Reader ID" + ReadData.Substring(15, 2).ToString());

                bt.ModuleSerialNumber = ModSerNum;
                bt.LaminatorBarcodeReaderMappingID = brdao.GetBarcodeReaderLaminatorMappingIDByBarcodeReaderID(ReaderID);
                bt.CreationTime = System.DateTime.Now;
                btdao.InsertNewBarcodeReaderTransaction(bt);
                SyncLock.ReleaseMutex();
            }
            catch (FormatException fe)
            {
                logger.Error(fe.Message.ToString());
            }
            catch (SqlException se)
            {
                logger.Error(se.Message.ToString());
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message.ToString());
            }
        }
        private void btn_submit_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txt_bcserial.Text))
                {
                    MessageBox.Show("Please provide barcode serial number", "Validation:");
                }
                else
                {
                    string BarcodeSerialNumber = txt_bcserial.Text;
                    int    BarcodeReaderSerial = 0;

                    if (!Int32.TryParse(dd_bcrserial.SelectedValue.ToString(), out BarcodeReaderSerial))
                    {
                        throw new FormatException("Can not parse barcode reader serial number");
                    }

                    int      bcrlamnummap        = brdao.GetBarcodeReaderLaminatorMappingIDByBarcodeReaderID(BarcodeReaderSerial);
                    DateTime BarcodeCreationDate = System.DateTime.Now;

                    BarcodeTransaction bt = new BarcodeTransaction();
                    bt.ID = BarcodeTransactionID;
                    bt.ModuleSerialNumber = BarcodeSerialNumber;
                    bt.LaminatorBarcodeReaderMappingID = bcrlamnummap;
                    bt.CreationTime = BarcodeCreationDate;


                    if (BarcodeTransactionID > 0)
                    {
                        bt.IsErrorResolved = true;
                        bt.ErrorID         = BarcodeTransErrorID;
                    }

                    long NumRowsAffected = btdao.InsertNewBarcodeReaderTransaction(bt);

                    bt.BarcodeReaderSerialNumber = brdao.GetReaderDetailsByReaderID(BarcodeReaderSerial).Rows[0]["SerialNumber"].ToString();
                    bt.LaminatorNumber           = ldao.GetLaminatorDetailsByBarcodeReaderLaminatorMappingID(bcrlamnummap).Rows[0]["LaminatorNumber"].ToString();

                    if (BarcodeTransactionID > 0)
                    {
                        eru.EditExcelEntries(bt.ID.ToString(), bt.ModuleSerialNumber, bt.BarcodeReaderSerialNumber, bt.LaminatorNumber);
                    }
                    else
                    {
                        bt.ID = NumRowsAffected;
                        eru.UpdateExcelFromExternalApplications(bt.ID, bt.ModuleSerialNumber, bt.BarcodeReaderSerialNumber, bt.LaminatorNumber, bt.CreationTime.ToString());
                    }

                    MessageBox.Show("Barcode transaction saved successfully", "Success:");
                }
            }
            catch (SqlException se)
            {
                if (se.Number == 2627)
                {
                    MessageBox.Show("Entry with same module serial number already exists in database, duplicate entries are not allowed.", "Duplicates:");
                }
                else
                {
                    MessageBox.Show("SQL Exception thrown at PopulateBarcodeReaderDD(): " + se.Message, "Database Exception:");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception thrown at PopulateBarcodeReaderDD(): " + ex.Message, "Exception:");
            }
        }