示例#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);
                    }
                }
            }
        }