Esempio n. 1
0
        private void dispatcherTimerSendReport_Tick(object sender, EventArgs e)
        {
            var currentTime = DateTime.Now;

            if (currentTime.Hour == createReportHour && currentTime.Minute == createReportMinute && currentTime.Second == createReportSecond)
            {
                var storingReportPerDateList = new List <StoringModel>();
                storingReportPerDateList = StoringController.SelectByDate(DateTime.Now, account.UserName);
                if (storingReportPerDateList.Count > 0)
                {
                    // Send Email
                    mailAddressReceiveMessageList = MailAddressReceiveMessageController.Get();
                    foreach (MailAddressReceiveMessageModel mailAddressReceiveMessage in mailAddressReceiveMessageList)
                    {
                        MailAddress mailAddressReceive = new MailAddress(mailAddressReceiveMessage.MailAddress, mailAddressReceiveMessage.Name);
                        mailMessage.To.Add(mailAddressReceive);
                    }

                    string mailHeader = @"<html><table border='1' style='width:75%'>
                                    <tr><td style='width:20%'>ProductNo</td><td style='width:15%'>Total</td><td style='width:15%'>Inputted</td><td style='width:15%'>Total Inputted</td><td style='width:15%'>Balance</td><td style='width:20%'>Location</td></tr>";
                    string mailBody   = "";
                    foreach (var productNo in storingReportPerDateList.Select(s => s.ProductNo).Distinct().ToList())
                    {
                        //int total = storingTempList.Where(w => w.ProductNo == productNo).Select(s => s.CartonNo).Max();
                        int total    = CartonNumberingDetailController.Select(productNo).Select(s => s.CartonNo).Max();
                        int inputted = storingReportPerDateList.Where(w => w.ProductNo == productNo && w.IsPass == true && w.IsComplete == true).Count();
                        //int totalInputed = storingCurrentList.Where(w => w.StoringModel.ProductNo == productNo && w.StoringModel.IsPass == true && w.StoringModel.IsComplete == true).Count();
                        int totalInputted = StoringController.SelectPerPO(productNo).Where(w => w.IsPass == true && w.IsComplete == true).Count();
                        int balance       = total - totalInputted;
                        mailBody += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>",
                                                  productNo, total, inputted, totalInputted, balance, electricScaleProfile.Location);
                    }
                    mailMessage.Body = mailHeader + mailBody + "</table></html>";

                    if (flagSending == false && mailMessage.To.Count > 0 && CheckInternetConnection.CheckConnection() == true)
                    {
                        smtpClient.SendAsync(mailMessage, mailMessage);
                        flagSending = true;
                        MessageBox.Show(String.Format("Đã gửi report ngày: {0:dd/MM/yyyy HH:mm:ss}", DateTime.Now), "Infor", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
        }
        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);
            }
        }