/// <summary>
        /// Unpacking a specific carton
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridViewCartonList_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Space || e.KeyCode == Keys.Delete) && this.dataGridViewCartonList.CurrentRow != null)
            {
                try
                {                //Handle exception for carton
                    DataGridViewRow dataGridViewRow = this.dataGridViewCartonList.CurrentRow;
                    if (dataGridViewRow != null)
                    {
                        DataRowView dataRowView = dataGridViewRow.DataBoundItem as DataRowView;
                        DataDetail.DataDetailCartonRow selectedCarton = dataRowView.Row as DataDetail.DataDetailCartonRow;

                        if (selectedCarton != null && selectedCarton.CartonStatus == (byte)GlobalVariables.BarcodeStatus.BlankBarcode)
                        {
                            string selectedCartonDescription = this.GetSerialNumber(selectedCarton.Pack00Barcode) + ": " + selectedCarton.Pack00Barcode + (char)13 + "   " + this.GetSerialNumber(selectedCarton.Pack01Barcode) + ": " + selectedCarton.Pack01Barcode + (char)13 + "   " + this.GetSerialNumber(selectedCarton.Pack02Barcode) + ": " + selectedCarton.Pack02Barcode + (char)13 + "   " + this.GetSerialNumber(selectedCarton.Pack03Barcode) + ": " + selectedCarton.Pack03Barcode + (char)13 + "   " + "[...]";

                            if (e.KeyCode == Keys.Space) //Update barcode
                            {
                                string cartonBarcode = "";
                                if (CustomInputBox.Show("BP Filling System", "Please input barcode for this carton:" + (char)13 + (char)13 + selectedCarton.CartonBarcode + (char)13 + "   " + selectedCartonDescription, ref cartonBarcode) == System.Windows.Forms.DialogResult.OK)
                                {
                                    if (this.barcodeScannerMCU.UpdateCartonBarcode(selectedCarton.CartonID, cartonBarcode))
                                    {
                                        MessageBox.Show("Carton: " + (char)13 + cartonBarcode + (char)13 + "   " + selectedCartonDescription + "\r\nHas been updated successfully.", "Handle exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                }
                            }

                            if (e.KeyCode == Keys.Delete)
                            {
                                if (MessageBox.Show("Are you sure you want to remove this carton:" + (char)13 + (char)13 + selectedCarton.CartonBarcode + (char)13 + "   " + selectedCartonDescription, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                                {
                                    if (this.barcodeScannerMCU.UndoCartonToPack(selectedCarton.CartonID))
                                    {
                                        MessageBox.Show("Carton: " + (char)13 + selectedCarton.CartonBarcode + (char)13 + "   " + selectedCartonDescription + "\r\nHas been removed successfully.", "Handle exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    GlobalExceptionHandler.ShowExceptionMessageBox(this, exception);
                }
            }
        }
Beispiel #2
0
        public Boolean UpdateCartonBarcode(int cartonID, string cartonBarcode)
        {
            if (cartonID <= 0 || cartonBarcode.Length < 12)
            {
                throw new Exception("Invalid barcode: It is required 12 letters barcode [" + cartonBarcode + "]");
            }

            lock (this.cartonDataTable)
            {
                DataDetail.DataDetailCartonRow dataDetailCartonRow = this.cartonDataTable.FindByCartonID(cartonID);
                if (dataDetailCartonRow != null && dataDetailCartonRow.CartonStatus == (byte)GlobalVariables.BarcodeStatus.BlankBarcode)
                {
                    lock (this.CartonTableAdapter)
                    {
                        int rowsAffected = this.CartonTableAdapter.UpdateCartonBarcode((byte)GlobalVariables.BarcodeStatus.Normal, cartonBarcode, dataDetailCartonRow.CartonID);
                        if (rowsAffected == 1)
                        {
                            dataDetailCartonRow.CartonStatus  = (byte)GlobalVariables.BarcodeStatus.Normal;
                            dataDetailCartonRow.CartonBarcode = cartonBarcode;
                        }
                        else
                        {
                            throw new System.ArgumentException("Fail to handle this carton", "Insufficient update carton");
                        }
                    }

                    this.NotifyPropertyChanged("CartonList");

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #3
0
        private void MatchingAndAddCarton(string cartonBarcode)
        {
            if (GlobalVariables.IgnoreEmptyCarton && this.packInOneCarton.Count <= 0)
            {
                return;
            }

            lock (this.cartonDataTable)
            {
                lock (this.packInOneCarton)
                {
                    lock (this.CartonTableAdapter)
                    {
                        try
                        {
                            using (System.Transactions.TransactionScope transactionScope = new System.Transactions.TransactionScope())
                            {
                                DataDetail.DataDetailCartonRow dataDetailCartonRow = this.cartonDataTable.NewDataDetailCartonRow();

                                dataDetailCartonRow.CartonDate    = DateTime.Now;
                                dataDetailCartonRow.CartonBarcode = cartonBarcode;
                                dataDetailCartonRow.CartonStatus  = (byte)(cartonBarcode == GlobalVariables.BlankBarcode ? GlobalVariables.BarcodeStatus.BlankBarcode : (this.packInOneCarton.Count == this.packInOneCarton.NoItemPerCarton || this.FillingLineData.FillingLineID == GlobalVariables.FillingLine.Pail ? GlobalVariables.BarcodeStatus.Normal : GlobalVariables.BarcodeStatus.EmptyCarton));
                                dataDetailCartonRow.FillingLineID = (int)this.FillingLineData.FillingLineID;

                                for (int i = 0; i < 24; i++)
                                {       //This use NON TYPED DATASET  -- Not so good, bescause the compiler can not detect error at compile time, but it is ok (I know exactly what in every row)
                                    dataDetailCartonRow["Pack" + i.ToString("00") + "Barcode"] = this.packInOneCarton.Count > i?this.packInOneCarton.ElementAt(i).PrintedBarcode : "";
                                }

                                this.cartonDataTable.Rows.InsertAt(dataDetailCartonRow, 0);             //this.cartonDataTable.AddDataDetailCartonRow(dataDetailCartonRow);

                                int rowsAffected = this.CartonTableAdapter.Update(dataDetailCartonRow); //Save

                                if (rowsAffected == 1)                                                  //Add Whole Carton Successfully
                                {
                                    if (this.packInOneCarton.Count > 0)                                 //Try to remove detail pack
                                    {
                                        if (UpdateDataDetailPack(GlobalVariables.BarcodeStatus.Deleted))
                                        {
                                            this.packInOneCarton = new MessageQueue();
                                        }
                                        else
                                        {
                                            throw new Exception("Insufficient remove detailing pack: " + dataDetailCartonRow.CartonBarcode);                                                                                                              //Only on if save ok
                                        }
                                    }
                                }
                                else
                                {
                                    throw new Exception("Insufficient save carton: " + dataDetailCartonRow.CartonBarcode); //Only on if save ok
                                }
                                transactionScope.Complete();                                                               //this.cartonDataTable.AcceptChanges();



                                #region Just maintain 300 rows only
                                if (this.cartonDataTable.Rows.Count > (this.FillingLineData.FillingLineID == Global.Class.Library.GlobalVariables.FillingLine.Pail ? 300 : 300))
                                {
                                    for (int j = this.cartonDataTable.Rows.Count - 1; j >= 0; j--)
                                    {
                                        DataDetail.DataDetailCartonRow cartonRow = this.cartonDataTable.Rows[j] as DataDetail.DataDetailCartonRow;
                                        if (cartonRow != null && cartonRow.CartonStatus != (byte)GlobalVariables.BarcodeStatus.BlankBarcode)
                                        {
                                            this.cartonDataTable.Rows.RemoveAt(j); break;
                                        }
                                    }
                                }
                                #endregion Just maintain 300 rows only
                            }
                        }
                        catch (System.Exception exception)
                        {
                            this.MainStatus = exception.Message;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public Boolean UndoCartonToPack(int cartonID)
        {
            if (cartonID <= 0)
            {
                return(false);
            }

            lock (this.packInOneCarton)
            {
                if (this.packInOneCarton.Count <= 0)
                {
                    lock (this.cartonDataTable)
                    {
                        DataDetail.DataDetailCartonRow dataDetailCartonRow = this.cartonDataTable.FindByCartonID(cartonID);
                        if (dataDetailCartonRow != null && dataDetailCartonRow.CartonStatus == (byte)GlobalVariables.BarcodeStatus.BlankBarcode)
                        {
                            //COPY Data FROM cartonDataTable TO packInOneCarton
                            for (int i = 0; i < this.packInOneCarton.NoItemPerCarton; i++)
                            {                               //This use NON TYPED DATASET  -- Not so good, bescause the compiler can not detect error at compile time, but it is ok (I know exactly what in every row)
                                MessageData messageData = this.AddDataDetailPack(dataDetailCartonRow["Pack" + i.ToString("00") + "Barcode"].ToString(), packInOneCarton.NextPackSubQueueID);
                                if (messageData != null)
                                {
                                    this.packInOneCarton.Enqueue(messageData);
                                }
                            }

                            if (this.packInOneCarton.Count > 0)
                            {
                                UpdateDataDetailPack(GlobalVariables.BarcodeStatus.ReadyToCarton);
                            }

                            this.NotifyPropertyChanged("PackInOneCarton");

                            lock (this.CartonTableAdapter)
                            {
                                //REMOVE data IN cartonDataTable
                                int rowsAffected = this.CartonTableAdapter.Delete(dataDetailCartonRow.CartonID);//Delete
                                if (rowsAffected == 1)
                                {
                                    this.cartonDataTable.Rows.Remove(dataDetailCartonRow);
                                }
                                else
                                {
                                    throw new System.ArgumentException("Fail to handle this carton", "Insufficient remove carton");
                                }
                            }

                            this.NotifyPropertyChanged("CartonList");

                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    throw new System.ArgumentException("Fail to handle this carton", "Another carton is on the line");
                }
            }
        }