Example #1
0
        private void bwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            storingList   = StoringController.SelectIsNotLoad();
            outputingList = OutputingController.SelectIsNotLoad();

            if (outputingList.Count > 0)
            {
                foreach (var outputInDB in outputingList)
                {
                    OutputingCurrent current = new OutputingCurrent();
                    current.Outputing = outputInDB;
                    outputingCurrentList.Add(current);
                }
            }
            else
            {
                OutputingModel outputingDefault = new OutputingModel()
                {
                    ProductNo         = "Default",
                    Barcode           = "Default",
                    SizeNo            = "Default",
                    CartonNo          = 0,
                    GrossWeight       = 0,
                    ActualWeight      = 0,
                    DifferencePercent = 0,
                    IsPass            = false,
                    WorkerId          = "Default",
                    IssuesId          = 0
                };

                OutputingCurrent currentDefault = new OutputingCurrent();
                currentDefault.Outputing = outputingDefault;
                outputingCurrentList.Add(currentDefault);
            }
        }
Example #2
0
        public static bool Insert(OutputingModel model)
        {
            var @ProductNo         = new SqlParameter("@ProductNo", model.ProductNo);
            var @Barcode           = new SqlParameter("@Barcode", model.Barcode);
            var @SizeNo            = new SqlParameter("@SizeNo", model.SizeNo);
            var @CartonNo          = new SqlParameter("@CartonNo", model.CartonNo);
            var @GrossWeight       = new SqlParameter("@GrossWeight", model.GrossWeight);
            var @ActualWeight      = new SqlParameter("@ActualWeight", model.ActualWeight);
            var @DifferencePercent = new SqlParameter("@DifferencePercent", model.DifferencePercent);
            var @IsPass            = new SqlParameter("@IsPass", model.IsPass);
            var @WorkerId          = new SqlParameter("@WorkerId", model.WorkerId);
            var @IssuesId          = new SqlParameter("@IssuesId", model.IssuesId);

            StoringSystemEntities db = new StoringSystemEntities();

            if (db.ExecuteStoreCommand("EXEC spm_InsertOutputing @ProductNo, @Barcode, @SizeNo, @CartonNo, @GrossWeight, @ActualWeight, @DifferencePercent, @IsPass, @WorkerId, @IssuesId",
                                       @ProductNo, @Barcode, @SizeNo, @CartonNo, @GrossWeight, @ActualWeight, @DifferencePercent, @IsPass, @WorkerId, @IssuesId) >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            // Input
            double actualWeight = 0;
            int    cartonNo     = 0;

            Double.TryParse(txtActualWeight.Text.ToString(), out actualWeight);
            Int32.TryParse(txtCartonNo.Text.ToString(), out cartonNo);
            string sizeNo = txtSizeNo.Text.ToString();

            // Output

            if (mode == 1)
            {
                var overrideOutputCarton = receiveOutputModel;
                overrideOutputCarton.ActualWeight      = actualWeight;
                overrideOutputCarton.CartonNo          = cartonNo;
                overrideOutputCarton.SizeNo            = sizeNo;
                overrideOutputCarton.IsPass            = true;
                overrideOutputCarton.GrossWeight       = 0;
                overrideOutputCarton.DifferencePercent = 0;
                overrideOutputCarton.IssuesId          = 0;
                if (OutputingController.Insert(overrideOutputCarton) == false)
                {
                    MessageBox.Show("Error occurred!", "Infor", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                outputingCurrent = overrideOutputCarton;
            }

            if (mode == 2)
            {
                var overrideStoringCarton = receiveStoringModel;

                overrideStoringCarton.ActualWeight      = actualWeight;
                overrideStoringCarton.CartonNo          = cartonNo;
                overrideStoringCarton.SizeNo            = sizeNo;
                overrideStoringCarton.IsPass            = true;
                overrideStoringCarton.GrossWeight       = 0;
                overrideStoringCarton.DifferencePercent = 0;
                overrideStoringCarton.IssuesId          = 0;
                if (StoringController.Insert(overrideStoringCarton) == false)
                {
                    MessageBox.Show("Error occurred!", "Infor", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                storingCurrent = overrideStoringCarton;
            }
            MessageBox.Show("Thùng Đã Được Pass!\nPASSED!", "Infor", MessageBoxButton.OK, MessageBoxImage.Information);
            btnSave.IsEnabled           = false;
            groupUpdateCarton.IsEnabled = false;

            Thread.Sleep(2000);
            this.Close();
        }
Example #4
0
        private void btnBarcodeComplete_Click(object sender, RoutedEventArgs e)
        {
            ClearValue();
            barcode           = txtBarCodeComplete.Text.Trim();
            storingPerBarcode = storingList.Where(w => w.Barcode == barcode).FirstOrDefault();
            if (storingPerBarcode == null)
            {
                MessageBox.Show("Thùng chưa được cân ở INPUT !", "Infor", MessageBoxButton.OK, MessageBoxImage.Information);
                HighLightTextblock(txtBarCodeComplete, btnBarcodeComplete);
                return;
            }

            outputingPerBarcode = outputingCurrentList.Where(w => w.Outputing.Barcode == barcode && w.Outputing.IsPass == true).Select(s => s.Outputing).FirstOrDefault();
            if (outputingPerBarcode != null)
            {
                MessageBox.Show("Thùng đã được cân !", "Infor", MessageBoxButton.OK, MessageBoxImage.Information);
                HighLightTextblock(txtBarCodeComplete, btnBarcodeComplete);
                return;
            }
            NoneHighLightTextblock(txtBarCodeComplete);

            tblProductNo.Text = storingPerBarcode.ProductNo;
            tblSizeItemQuantityCartonNo.Text = string.Format("Size: {0}\nCartonNo: {1}", storingPerBarcode.SizeNo, storingPerBarcode.CartonNo);

            serialPortReceive.Close();
            ComPortHelper.WriteToPort(portWrite, "DIO[0]:VALUE=0\r\n");
            ComPortHelper.WriteToPort(portWrite, "DIO[3]:VALUE=0\r\n");
            if (double.TryParse(txtMinActualWeight.Text, out minActualWeight) == false)
            {
                txtMinActualWeight.BorderBrush = Brushes.Red;
            }
            else
            {
                txtMinActualWeight.ClearValue(TextBox.BorderBrushProperty);
            }

            if (double.TryParse(txtMaxActualWeight.Text, out maxActualWeight) == false)
            {
                txtMaxActualWeight.BorderBrush = Brushes.Red;
            }

            else
            {
                txtMaxActualWeight.ClearValue(TextBox.BorderBrushProperty);
            }

            serialPortReceive.Open();
        }
        public CheckIssuesWindow(OutputingModel _receiveOutputModel, StoringModel _receiveStoringModel, IssuesType.Issues _issuesType, string factory)
        {
            this.receiveStoringModel = _receiveStoringModel;
            this.receiveOutputModel  = _receiveOutputModel;
            this.issuesType          = _issuesType;
            this.factory             = factory;
            issuesList              = new List <IssuesModel>();
            electricScaleProfile    = new ElectricScaleProfile();
            findControlAccountModel = new ControlIssuesAccountModel();

            storingCurrent   = new StoringModel();
            outputingCurrent = new OutputingModel();

            mailAddressReceiveMessageList = new List <MailAddressReceiveMessageModel>();
            MailAddress mailAddressSend = new MailAddress("*****@*****.**", factory);

            smtpClient = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new NetworkCredential(mailAddressSend.Address, "Happy2018"),
                Timeout               = 10 * 1000,
            };
            smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
            mailMessage = new MailMessage
            {
                From       = mailAddressSend,
                IsBodyHtml = true,
                Subject    = "Storing-System",
            };
            flagSending = false;

            bwInsertAndSendEmail                     = new BackgroundWorker();
            bwInsertAndSendEmail.DoWork             += new DoWorkEventHandler(bwInsertAndSendEmail_DoWork);
            bwInsertAndSendEmail.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwInsertAndSendEmail_RunWorkerCompleted);

            InitializeComponent();
        }
Example #6
0
        private void CompareWeight()
        {
            Dispatcher.Invoke(new Action(() =>
            {
                tblGrossWeight.Text = string.Format("{0}", storingPerBarcode.ActualWeight);
                tblGrossWeight.Tag  = string.Format("{0}", storingPerBarcode.ActualWeight);
            }));

            double grossWeight  = 0;
            double actualWeight = 0;

            Dispatcher.Invoke(new Action(() =>
            {
                Double.TryParse(tblGrossWeight.Tag.ToString(), out grossWeight);
                Double.TryParse(tblActualWeight.Tag.ToString(), out actualWeight);
            }));

            double percentDiffence = actualWeight / grossWeight;

            tblDifferencePercent.Dispatcher.Invoke(new Action(() => tblDifferencePercent.Text = string.Format("{0}", Math.Round(100 * (percentDiffence - 1), 2))));

            outputingInsert.ProductNo    = storingPerBarcode.ProductNo;
            outputingInsert.Barcode      = storingPerBarcode.Barcode;
            outputingInsert.CartonNo     = storingPerBarcode.CartonNo;
            outputingInsert.SizeNo       = storingPerBarcode.SizeNo;
            outputingInsert.GrossWeight  = grossWeight;
            outputingInsert.ActualWeight = actualWeight;
            outputingInsert.WorkerId     = account.UserName;


            outputingInsert.DifferencePercent = Math.Round(100 * (percentDiffence - 1), 2);
            // PASS
            if (percentDiffence >= LIMITED_MIN && percentDiffence <= LIMITED_MAX)
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    tblResult.Foreground = Brushes.White;
                    tblResult.Text       = string.Format("{0} - Pass", outputingInsert.CartonNo);
                    brResult.Background  = Brushes.Green;
                }));
                outputingInsert.IsPass   = true;
                outputingInsert.IssuesId = 0;

                if (OutputingController.Insert(outputingInsert) == false)
                {
                    MessageBox.Show("Insert Error!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                OutputingCurrent outputCurrentInsert = new OutputingCurrent();
                outputCurrentInsert.Outputing = outputingInsert;
                outputingCurrentList.Add(outputCurrentInsert);
            }
            else
            {
                outputingInsert.IsPass = false;
                //LOW
                if (percentDiffence < LIMITED_MIN)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        tblResult.Foreground = Brushes.Black;
                        tblResult.Text       = string.Format("{0} - Low", outputingInsert.CartonNo);
                        brResult.Background  = Brushes.Yellow;
                    }));
                }
                else
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        tblResult.Foreground = Brushes.White;
                        tblResult.Text       = string.Format("{0} - Hi", outputingInsert.CartonNo);
                        brResult.Background  = Brushes.Red;
                    }));
                }
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    CheckIssuesWindow window = new CheckIssuesWindow(outputingInsert, null, IssuesType.Issues.IssuesCompareWeight, factory);
                    window.ShowDialog();

                    OutputingModel outputRecieve          = window.outputingCurrent;
                    OutputingCurrent outputCurrentRecieve = new OutputingCurrent();
                    outputCurrentRecieve.Outputing        = outputRecieve;
                    outputingCurrentList.Add(outputCurrentRecieve);
                }));
            }
            Dispatcher.Invoke(new Action(() =>
            {
                txtBarCodeComplete.Focus();
                txtBarCodeComplete.SelectAll();
                btnBarcodeComplete.IsEnabled = true;
                btnBarcodeComplete.IsDefault = true;
            }));
        }
        private void bwInsertAndSendEmail_DoWork(object sender, DoWorkEventArgs e)
        {
            // Send Email
            mailAddressReceiveMessageList = MailAddressReceiveMessageController.Get();
            foreach (MailAddressReceiveMessageModel mailAddressReceiveMessage in mailAddressReceiveMessageList)
            {
                MailAddress mailAddressReceive = new MailAddress(mailAddressReceiveMessage.MailAddress, mailAddressReceiveMessage.Name);
                mailMessage.To.Add(mailAddressReceive);
            }

            string reason = "";

            reason = issuesList.Where(w => w.IssuesId == issuesId).Select(s => s.IssuesName).FirstOrDefault().ToString();
            string mailBody = "";

            // OUTPUT PROMBLEM
            if (receiveOutputModel != null)
            {
                mode = 1;
                receiveOutputModel.IssuesId = issuesId;
                // InsertDB
                if (OutputingController.Insert(receiveOutputModel) == false)
                {
                    MessageBox.Show("Insert Error!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                //CreatedLog
                string logBodyOldCarton = "Production No.: {0}, Size No.: {1}, Carton No.: {2}, Gross Weight: {3}kg, Actual Weight: {4}kg, Difference Percent: {5}%, Created By: {6}, Reason :{7}, Location {8}";
                LogHelper.CreateOutputLog(string.Format(logBodyOldCarton, receiveOutputModel.ProductNo, receiveOutputModel.SizeNo, receiveOutputModel.CartonNo, receiveOutputModel.GrossWeight, receiveOutputModel.ActualWeight, receiveOutputModel.DifferencePercent, findControlAccountModel.FullName, reason, electricScaleProfile.Location));

                // Created Email
                mailBody = @"<html><table border='1' style='width:100%'>
                                    <tr><td>ProductNo</td><td>SizeNo</td><td>CartonNo</td><td>Gross Weight</td><td>Actual Weight</td><td>Difference Percent</td><td>Check By</td><td>Location</td><td>Reason</td></tr>
                                    <tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3} kg</td><td>{4} kg</td><td>{5} %</td><td>{6}</td><td>{7}</td><td>{8}</td></tr>
                                    </table></html>";
                //string logBody = "Production No.:{0} Size No.:{1} Carton No.:{2} Gross Weight:{3}kg Actual Weight: {4}kg Difference Percent:{5}% Check by:{6} Reason:{7}";
                mailMessage.Subject = string.Format("STORING SYSTEM - OUTPUT PROMBLEM");
                mailMessage.Body    = string.Format(mailBody, receiveOutputModel.ProductNo, receiveOutputModel.SizeNo, receiveOutputModel.CartonNo, receiveOutputModel.GrossWeight, receiveOutputModel.ActualWeight, receiveOutputModel.DifferencePercent, findControlAccountModel.FullName, electricScaleProfile.Location, reason);

                outputingCurrent = receiveOutputModel;
            }

            // INPUT PROBLEM
            if (receiveStoringModel != null)
            {
                mode = 2;

                receiveStoringModel.IssuesId = issuesId;
                if (StoringController.Insert(receiveStoringModel) == false)
                {
                    MessageBox.Show("Insert Error!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (issuesType == IssuesType.Issues.IssuesFirstCartonOfSizeOfPO)
                {
                    mailBody         = @"<html><table border='1' style='width:100%'>
                                    <tr><td>ProductNo</td><td>SizeNo</td><td>CartonNo</td><td>Check By</td><td>Location</td><td>Reason</td></tr>
                                    <tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>
                                    </table></html>";
                    mailMessage.Body = string.Format(mailBody, receiveStoringModel.ProductNo, receiveStoringModel.SizeNo, receiveStoringModel.CartonNo, findControlAccountModel.FullName, electricScaleProfile.Location, reason);
                    //string logBody = "Production No.:{0} Size No.:{1} Carton No.:{2} Gross Weight:{3}kg Actual Weight: {4}kg Difference Percent:{5}% Check by:{6} Reason:{7}";
                    mailMessage.Subject = string.Format("STORING SYSTEM - INPUT PROBLEM - FIRST CARTON");
                }

                if (issuesType == IssuesType.Issues.IssuesCompareWeight)
                {
                    mailBody = @"<html><table border='1' style='width:100%'>
                                    <tr><td>ProductNo</td><td>SizeNo</td><td>CartonNo</td><td>Gross Weight</td><td>Actual Weight</td><td>Difference Percent</td><td>Check By</td><td>Location</td><td>Reason</td></tr>
                                    <tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3} kg</td><td>{4} kg</td><td>{5} %</td><td>{6}</td><td>{7}</td><td>{8}</td></tr>
                                    </table></html>";
                    //string logBody = "Production No.:{0} Size No.:{1} Carton No.:{2} Gross Weight:{3}kg Actual Weight: {4}kg Difference Percent:{5}% Check by:{6} Reason:{7}";
                    mailMessage.Subject = string.Format("STORING SYSTEM - INPUT PROMBLEM - WEIGHT");
                    mailMessage.Body    = string.Format(mailBody, receiveStoringModel.ProductNo, receiveStoringModel.SizeNo, receiveStoringModel.CartonNo, receiveStoringModel.GrossWeight, receiveStoringModel.ActualWeight, receiveStoringModel.DifferencePercent, findControlAccountModel.FullName, electricScaleProfile.Location, reason);

                    string logBodyOldCarton = "Production No.: {0}, Size No.: {1}, Carton No.: {2}, Gross Weight: {3}kg, Actual Weight: {4}kg, Difference Percent: {5}%, Created By: {6}, Reason :{7}, Location {8}";
                    LogHelper.CreateIssuesLog(string.Format(logBodyOldCarton, receiveStoringModel.ProductNo, receiveStoringModel.SizeNo, receiveStoringModel.CartonNo, receiveStoringModel.GrossWeight, receiveStoringModel.ActualWeight, receiveStoringModel.DifferencePercent, findControlAccountModel.FullName, reason, electricScaleProfile.Location));
                }
                storingCurrent = receiveStoringModel;
            }

            if (flagSending == false && mailMessage.To.Count > 0)
            {
                if (CheckInternetConnection.CheckConnection() == false)
                {
                    MessageBox.Show("Không có kết nối Internet!\nNo Internet Connection!", "Info", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                smtpClient.SendAsync(mailMessage, mailMessage);
                flagSending = true;
                MessageBox.Show("Đã gửi Email!\nSent Email!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }