private string EmailCategory(PurchaseOrderHeader purchaseOrder)
        {
            TimeSpan ts        = purchaseOrder.ShipDate - purchaseOrder.OrderDate;
            int      totalDays = ts.Days;

            TimeSpan tsRemaining = purchaseOrder.ShipDate - DateTime.Today;

            int daysRemaining = tsRemaining.Days;

            int perDaysRemaining = 0;

            if (daysRemaining != null && daysRemaining != 0)
            {
                perDaysRemaining = (daysRemaining / totalDays) * 100;
            }

            if ((purchaseOrder.ProgressPer - perDaysRemaining) >= 0 || (purchaseOrder.ProgressPer - perDaysRemaining) >= -5 || (purchaseOrder.ProgressPer - perDaysRemaining) >= 5)
            {
                return("#31B404");
            }
            else if ((purchaseOrder.ProgressPer - perDaysRemaining) > -5 && (purchaseOrder.ProgressPer - perDaysRemaining) < -30)
            {
                return("#FF8000");
            }
            else
            {
                return("#ff0000");
            }
        }
Exemple #2
0
        public List <PurchaseOrderHeader> GetData()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString.ToString();

            var purchaseOrder = new List <PurchaseOrderHeader>();

            using (SqlConnection connection =
                       new SqlConnection(connectionString))
            {
                // Create the Command and Parameter objects.
                SqlCommand command = new SqlCommand();
                command.CommandText = "GETPURCHASEORDER_ForNotification";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection  = connection;

                try
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var purchaseOrderHeader = new PurchaseOrderHeader
                            {
                                OrderNumber  = reader["OrderNumber"] is DBNull ? null : reader["OrderNumber"].ToString(),
                                OrderDate    = reader.GetFieldValue <DateTime>(1),
                                ShipDate     = reader.GetFieldValue <DateTime>(2),
                                Status       = reader["STATUS"] is DBNull ? null : reader["STATUS"].ToString(),
                                ProgressPer  = Convert.ToInt32(reader["ProgressPer"]),
                                SupplierName = reader["Name"] is DBNull ? null : reader["Name"].ToString(),
                                Email        = reader["Email"] is DBNull ? null : reader["Email"].ToString()
                            };

                            purchaseOrder.Add(purchaseOrderHeader);
                        }
                        reader.Close();
                    }
                    // return purchaseOrder;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return(purchaseOrder);
            }
        }
        private string HtmlContentEscalation(PurchaseOrderHeader purchaseOrder)
        {
            StringBuilder sb = new StringBuilder();

            string emailCategory = EmailCategory(purchaseOrder);

            if (emailCategory == "#FF8000" || emailCategory == "#ff0000")
            {
                string srtContent = @"<html><head><title></title></head><body style='color: #ff0000;'><div style='color: #ff0000;'><span style='font-size:14px;'><span style='font-family:verdana,geneva,sans-serif;'>Dear " + purchaseOrder.SupplierName + " ,</span></span></div><div style='color: #ff0000;'&nbsp;</div><div style='color: #ff0000;'><span style='font-size:14px;'><span style='font-family:verdana,geneva,sans-serif;'>Please take immediate action on following PO. As per our record ship date is very close or passed and progress is " + purchaseOrder.ProgressPer + "%.</span></span></div><div style='color: #ff0000;'>&nbsp;</div><div style='color: #ff0000;'><span style='font-family:verdana,geneva,sans-serif;'><span style='font-size:16px;'>";

                string strHeading = @"<strong>PO Number &nbsp; &nbsp; &nbsp;Order Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ship Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Progress % &nbsp; &nbsp; &nbsp;&nbsp;</strong></span></span></div>";

                string srtData = @"<p><span style='color:" + emailCategory + ";'><span style='font-size:12px;'><span style='font-family:verdana,geneva,sans-serif;'>&nbsp; &nbsp; &nbsp; " + purchaseOrder.OrderNumber + "   &nbsp; &nbsp; &nbsp; " + purchaseOrder.OrderDate + " &nbsp; &nbsp; &nbsp; &nbsp;" + purchaseOrder.ShipDate + "  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; " + purchaseOrder.Status + " &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;" + purchaseOrder.ProgressPer + "&nbsp;</span></span></span></p>";

                sb.Append(srtData);

                string strFooter = @"<p>&nbsp;</p><p><span style='font-size:12px;'><span style='font-family:verdana,geneva,sans-serif;'>Kindly ensure that appropriate action has been taken on above.</span></span></p><p><font face='verdana, geneva, sans-serif'><span style='font-size: 12px;'>Regards,</span></font></p><p><font face='verdana, geneva, sans-serif'><span style='font-size: 12px;'>IT Devision</span></font></p><p><span style='font-size: 12px; font-family: verdana, geneva, sans-serif;'>Surya Industries &nbsp;PVT. LTD.</span></p>   <p><span style='font-size: 12px; font-family: verdana, geneva, sans-serif;'>*** THIS IS AN AUTOGENERATED MAIL. PLEASE DO NOT REPLY TO THIS MESSAGE *** </span></p>   </body></html>";

                return(srtContent + strHeading + sb.ToString() + strFooter);
            }

            return(sb.ToString());
        }
 public string GetEscalationContent(PurchaseOrderHeader purchaseOrder)
 {
     return(HtmlContentEscalation(purchaseOrder));
 }