protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    Int32 formId;
                    int statusId;
                    DateTime tryDueDate;
                    Nullable<DateTime> dueDate = null;
                    string emailListString = lblEmailsSentTo.Text.Replace(" ", "");
                    List<string> emailList = emailListString.Split(',').ToList<string>();

                    System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                    UserLogic uLogic = new UserLogic();
                    SystemUsers currentUser = uLogic.GetCurrentUser(user);

                    statusId = Convert.ToInt32(ddlStatus.SelectedValue);

                    if (txtDueByDate.Value != "")
                    {
                        DateTime.TryParse(txtDueByDate.Value, out tryDueDate);

                        if (tryDueDate.Year > 0001)
                        {
                            dueDate = tryDueDate;
                        }
                    }
                    else
                    {
                        dueDate = null;
                    }

                    using (FormContext ctx = new FormContext())
                    {
                        var status = ctx.Statuses.Where(s => s.StatusId.Equals(statusId)).FirstOrDefault();
                        Int32 requestedUserId = Convert.ToInt32(ddlRequestedBy.SelectedValue);
                        var requestedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == requestedUserId);
                        var modifiedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID);

                        Models.LowInventoryForm newForm = new Models.LowInventoryForm
                        {
                            Timestamp = DateTime.Now,
                            Company = ddlCompany.SelectedValue,
                            OrderNumber = txtOrderNumber.Text,
                            Plant = ctx.Plants.FirstOrDefault(x => x.PlantText == ddlPlants.SelectedText),
                            Line = txtLine.Text,
                            Quantity = txtQuantity.Text,
                            SKU = txtSKU.Text,
                            Status = ctx.Statuses.FirstOrDefault(s => s.StatusText == ddlStatus.SelectedItem.Text),
                            RequestedUser = requestedUser,
                            LastModifiedUser = modifiedUser,
                            SubmittedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID),
                            DueDate = dueDate,
                            Priority = ctx.Priorities.FirstOrDefault(x => x.PriorityText == ddlPriority.SelectedText),
                            LastModifiedTimestamp = DateTime.Now
                        };

                        if (ddlAssignedTo.SelectedIndex != -1)
                        {
                            Int32 assignedUserId = Convert.ToInt32(ddlAssignedTo.SelectedValue);
                            newForm.AssignedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == assignedUserId);
                        }

                        ctx.LowInventoryForms.Add(newForm);
                        ctx.SaveChanges();

                        if (newForm.AssignedUser != null)
                        {
                            Int32 assignedUserId = Convert.ToInt32(ddlAssignedTo.SelectedValue);

                            UserAssignmentAssociation uA = new UserAssignmentAssociation
                            {
                                Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                                RelatedFormId = newForm.RecordId,
                                User = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == assignedUserId)
                            };

                            ctx.UserAssignments.Add(uA);
                        }

                        if (newForm.RequestedUser != null)
                        {
                            UserRequestAssociation uR = new UserRequestAssociation
                            {
                                Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                                RelatedFormId = newForm.RecordId,
                                User = requestedUser
                            };

                            ctx.UserRequests.Add(uR);
                        }

                        ctx.SaveChanges();

                        formId = newForm.RecordId;

                        Comments systemComment = new Comments
                        {
                            Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                            Note = "Request Created By: " + currentUser.DisplayName,
                            RelatedFormId = formId,
                            SystemComment = true,
                            Timestamp = DateTime.Now
                        };

                        ctx.Comments.Add(systemComment);

                        Comments systemComment2 = new Comments
                        {
                            Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                            Note = "Requested By: " + requestedUser.DisplayName,
                            RelatedFormId = formId,
                            SystemComment = true,
                            Timestamp = DateTime.Now
                        };

                        ctx.Comments.Add(systemComment2);

                        if (ddlAssignedTo.SelectedIndex != -1)
                        {
                            Comments systemComment3 = new Comments
                            {
                                Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                                Note = "Request Assigned To: " + requestedUser.DisplayName,
                                RelatedFormId = formId,
                                SystemComment = true,
                                Timestamp = DateTime.Now
                            };

                            ctx.Comments.Add(systemComment3);
                        }

                        if (txtComments.Text != "")
                        {
                            Comments firstComment = new Comments
                            {
                                Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                                Note = txtComments.Text,
                                RelatedFormId = formId,
                                SystemComment = false,
                                Timestamp = DateTime.Now,
                                User = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID),
                            };

                            ctx.Comments.Add(firstComment);
                            ctx.SaveChanges();
                        }

                        if (lblEmailsSentTo.Text != "")
                        {
                            Comments notifyComment = new Comments
                            {
                                Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Low Inventory"),
                                Note = "Request Notifications Sent To: " + lblEmailsSentTo.Text,
                                RelatedFormId = formId,
                                SystemComment = true,
                                Timestamp = DateTime.Now
                            };

                            ctx.Comments.Add(notifyComment);

                            ctx.SaveChanges();

                            TForm submittedForm = ctx.TForms.FirstOrDefault(tf => tf.FormName == "Low Inventory");

                            SendEmail msg = new SendEmail();
                            StringBuilder bodyHtml = new StringBuilder();

                            bodyHtml.AppendLine("<div style=\"width:50%; text-align:center;\"><img src=\"http://www.wctingle.com/img/Logo.jpg\" /><br /><br />")
                                .Append("A new Low Inventory Request has been submitted.<br /><br />")
                                .AppendLine("<table style=\"border: 4px solid #d0604c;background-color:#FFF;width:100%;margin-lefT:auto; margin-right:auto;\">")
                                .AppendLine("    <tr>")
                                .AppendLine("        <td colspan=\"4\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 20px;border: 4px solid #d0604c; color:#FFF; background-color:#bc4445;\">Low Inventory Request</td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Company:</td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(ddlCompany.SelectedText).AppendLine("</td>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%; color:#bc4445\"></td>")
                                .AppendLine("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000\"></td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Order #:</td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(txtOrderNumber.Text).AppendLine("</td>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Plant:</td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(ddlPlants.SelectedText).AppendLine("</td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Line:</td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(txtLine.Text).AppendLine("</td>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Quantity:</td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(txtQuantity.Text).AppendLine("</td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">SKU:</td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(txtSKU.Text).AppendLine("</td>")
                                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\"></td>")
                                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\"></td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .AppendLine("       <td style=\"width:100%;\" colspan=\"4\">")
                                .AppendLine("        <table style=\"border:none; width:100%\">")
                                .AppendLine("            <tr>")
                                .AppendLine("                <td colspan=\"4\">")
                                .AppendLine("                    <span style=\"font-weight:bold; color:#bc4445; text-decoration:underline\">Assignment and Request Details:</span>")
                                .AppendLine("                </td>")
                                .AppendLine("            </tr>")
                                .AppendLine("            <tr>")
                                .AppendLine("                <td style=\"width:20%; text-align:right\"><span class=\"formRedText\">Requested By:</span></td>")
                                .Append("                    <td style=\"width:25%; text-align:left\">").AppendLine(ddlRequestedBy.SelectedItem.Text)
                                .AppendLine("                </td>")
                                .AppendLine("                <td style=\"width:20%; text-align:right\"><span class=\"formRedText\">Assigned To:</span></td>")
                                .Append("                   <td style=\"width:25%; text-align:left\">");

                            if (ddlAssignedTo.SelectedIndex != -1) { bodyHtml.AppendLine(ddlAssignedTo.SelectedItem.Text); } else { bodyHtml.AppendLine("N/A"); }

                            bodyHtml.AppendLine("            </td>")
                                .AppendLine("            </tr>")
                                .AppendLine("            <tr>")
                                .AppendLine("                <td style=\"width:18%; text-align:right\"><span class=\"formRedText\">Date Created:</span></td>")
                                .AppendLine("                <td style=\"width:18%; text-align:left\">")
                                .AppendLine(DateTime.Now.ToShortDateString())
                                .AppendLine("                </td>")
                                .AppendLine("                <td style=\"width:18%; text-align:right\"><span class=\"formRedText\">Due By:</span></td>")
                                .Append("                    <td style=\"width:18%; text-align:left\">").Append(txtDueByDate.Value).AppendLine("</td>")
                                .AppendLine("            </tr>")
                                .AppendLine("            <tr>")
                                .AppendLine("                <td style=\"width:10%; text-align:right\"><span class=\"formRedText\">Status:</span></td>")
                                .Append("                    <td style=\"width:10%; text-align:left\">").AppendLine(ddlStatus.SelectedText)
                                .AppendLine("                </td>")
                                .AppendLine("                <td style=\"width:10%; text-align:right\"><span class=\"formRedText\">Priority:</span></td>")
                                .Append("                    <td style=\"width:10%; text-align:left\">").AppendLine(ddlPriority.SelectedText)
                                .AppendLine("                </td>")
                                .AppendLine("            </tr>")
                                .AppendLine("        </table>")
                                .AppendLine("       </td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .Append("       <td style=\"width:100%; text-align:center\" colspan=\"4\">Created By: ").AppendLine(currentUser.DisplayName)
                                .AppendLine("       </td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .Append("           <td style=\"width:100%; text-align:center\" colspan=\"4\"><span style=\"color:#bc4445; font-weight:bold\">Request Notifications Sent To:</span> <br />")
                                .AppendLine(lblEmailsSentTo.Text)
                                .AppendLine("       </td>")
                                .AppendLine("    </tr>")
                                .AppendLine("    <tr>")
                                .AppendLine("           <td style=\"width:100%; text-align:center\" colspan=\"4\"><br /><br /></td>")
                                .AppendLine("    </tr>")
                                .AppendLine("</table><br /><br />");

                            if (cbSendComments.Checked)
                            {
                                bodyHtml.AppendLine("<div style=\"width:80%; color:#bc4445; margin: 0 auto; text-align:center;\">Comments<br /></div>")
                                    .AppendLine("<div style=\"width:80%; background-color:#bc4445; margin: 0 auto; text-align: left; padding:3px; color: white; \">")
                                    .Append(txtComments.Text).AppendLine("<br /><br />")
                                    .AppendLine("<span style=\"padding-right:15px\">").AppendLine(currentUser.DisplayName).AppendLine("</span>")
                                    .AppendLine(DateTime.Now.ToString("MMMM dd, yyyy"))
                                    .AppendLine("</div>");

                            }

                            bodyHtml.AppendLine("</div><br /><br />");

                            bool result = msg.SendMail("*****@*****.**", emailList, "Low Inventory Request", bodyHtml.ToString(), submittedForm, formId, currentUser);

                            ddlCompany.Enabled = false;
                            txtOrderNumber.Enabled = false;
                            ddlPlants.Enabled = false;
                            txtLine.Enabled = false;
                            txtQuantity.Enabled = false;
                            txtSKU.Enabled = false;
                            ddlRequestedBy.Enabled = false;
                            ddlAssignedTo.Enabled = false;
                            txtDueByDate.Disabled = true;
                            ddlStatus.Enabled = false;
                            ddlPriority.Enabled = false;
                            cbNotifyStandard.Enabled = false;
                            cbNotifyRequester.Enabled = false;
                            cbNotifyOther.Enabled = false;
                            cbNotifyAssignee.Enabled = false;
                            cbSendComments.Enabled = false;
                            txtComments.Enabled = false;

                            string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                            Response.Redirect(pageUrl + "?FormAction=add&sendEmail=" + result.ToString());
                        }
                        else
                        {
                            string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count());
                            Response.Redirect(pageUrl + "?FormAction=add&sendEmail=NotRequired");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                pnlCompleted.Visible = true;
                pnlForm.Visible = false;
                lblMessage.Text = "An error occured during submission of this request.  <br /><br />It is possible that the form was completed before this error occurred, <br />so please contact your System Administrator before re-submitting.";
            }
        }
        public void SendUpdateEmail(Int32 FormId, string EmailList, Boolean SendComments, Boolean IncludeSystemComments)
        {
            Tingle_WebForms.Models.MustIncludeForm myForm = ctx.MustIncludeForms.FirstOrDefault(eof => eof.RecordId == FormId);
            TForm submittedForm = ctx.TForms.FirstOrDefault(tf => tf.FormName == "Must Include");
            Boolean anyComments = false;
            IEnumerable<Comments> finalComments = null;

            string dueDateString = "";

            if (myForm.DueDate != null)
            {
                dueDateString = myForm.DueDate.Value.ToShortDateString();
            }

            if (IncludeSystemComments)
            {
                if (ctx.Comments.Any(x => x.Form.FormName == "Must Include" && x.RelatedFormId == myForm.RecordId))
                {
                    anyComments = true;

                    IEnumerable<Comments> commentsList = ctx.Comments
                        .Where(x => x.Form.FormName == "Must Include" && x.RelatedFormId == myForm.RecordId)
                        .Include(x => x.User)
                        .OrderByDescending(x => x.RecordId)
                        .ToList();

                    finalComments = commentsList;
                }
            }
            else
            {
                if (ctx.Comments.Any(x => x.Form.FormName == "Must Include" && x.RelatedFormId == myForm.RecordId && x.SystemComment == false))
                {
                    anyComments = true;

                    IEnumerable<Comments> commentsList = ctx.Comments
                        .Where(x => x.Form.FormName == "Must Include" && x.RelatedFormId == myForm.RecordId && x.SystemComment == false)
                        .Include(x => x.User)
                        .OrderByDescending(x => x.RecordId)
                        .ToList();

                    finalComments = commentsList;
                }
            }

            string emailListString = EmailList.Replace(" ", "");
            List<string> emailList = emailListString.Split(',').ToList<string>();

            System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
            UserLogic uLogic = new UserLogic();
            SystemUsers currentUser = uLogic.GetCurrentUser(user);

            SendEmail msg = new SendEmail();
            StringBuilder bodyHtml = new StringBuilder();

            bodyHtml.AppendLine("<div style=\"width:50%; text-align:center;\"><img src=\"http://www.wctingle.com/img/Logo.jpg\" /><br /><br />")
                .AppendLine("<table style=\"border: 4px solid #d0604c;background-color:#FFF;width:100%;margin-lefT:auto; margin-right:auto;\">")
                .AppendLine("    <tr>")
                .AppendLine("        <td colspan=\"4\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 20px;border: 4px solid #d0604c; color:#FFF; background-color:#bc4445;\">Must Include Request Update</td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Company:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.Company).AppendLine("</td>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;\"></td>")
                .AppendLine("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;\"></td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">PO:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.PO).AppendLine("</td>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Armstrong Reference:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.ArmstrongReference).AppendLine("</td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Pattern:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.Pattern).AppendLine("</td>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Line:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.Line).AppendLine("</td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Order #:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.OrderNumber).AppendLine("</td>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\"></td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\"></td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Customer:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.Customer).AppendLine("</td>")
                .AppendLine("        <td style=\"text-align:right;font-size:16px;font-weight:bold;width:25%;color:#bc4445;\">Warehouse:</td>")
                .Append("        <td style=\"text-align:left;font-size:16px;font-weight:bold;width:25%;color:#000;\">").Append(myForm.Warehouse.WarehouseText).AppendLine("</td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("       <td style=\"width:100%;\" colspan=\"4\">")
                .AppendLine("        <table style=\"border:none; width:100%\">")
                .AppendLine("            <tr>")
                .AppendLine("                <td colspan=\"4\" style=\"text-align:center\">")
                .AppendLine("                    <span style=\"font-weight:bold; color:#bc4445; text-decoration:underline\">Assignment and Request Details:</span>")
                .AppendLine("                </td>")
                .AppendLine("            </tr>")
                .AppendLine("            <tr>")
                .AppendLine("                <td style=\"width:25%; text-align:right\">Requested By:</td>")
                .Append("                    <td style=\"width:25%; text-align:left\">").AppendLine(myForm.RequestedUser.DisplayName)
                .AppendLine("                </td>")
                .AppendLine("                <td style=\"width:25%; text-align:right\">Assigned To:</td>")
                .Append("                   <td style=\"width:25%; text-align:left\">");

            if (myForm.AssignedUser != null) { bodyHtml.AppendLine(myForm.AssignedUser.DisplayName); } else { bodyHtml.AppendLine("N/A"); }

            bodyHtml.AppendLine("            </td>")
                .AppendLine("            </tr>")
                .AppendLine("            <tr>")
                .AppendLine("                <td style=\"width:25%; text-align:right\">Date Created:</td>")
                .AppendLine("                <td style=\"width:25%; text-align:left\">").Append(myForm.Timestamp.ToShortDateString())
                .AppendLine("                </td>")
                .AppendLine("                <td style=\"width:25%; text-align:right\">Due By:</td>")
                .Append("                    <td style=\"width:25%; text-align:left\">").Append(dueDateString).AppendLine("</td>")
                .AppendLine("            </tr>")
                .AppendLine("            <tr>")
                .AppendLine("                <td style=\"width:25%; text-align:right\">Status:</td>")
                .Append("                    <td style=\"width:25%; text-align:left\">").AppendLine(myForm.Status.StatusText)
                .AppendLine("                </td>")
                .AppendLine("                <td style=\"width:25%; text-align:right\">Priority:</td>")
                .Append("                    <td style=\"width:25%; text-align:left\">").AppendLine(myForm.Priority.PriorityText)
                .AppendLine("                </td>")
                .AppendLine("            </tr>")
                .AppendLine("        </table>")
                .AppendLine("       </td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .Append("           <td style=\"width:25%; text-align:right\">Created By:</td>")
                .Append("           <td style=\"width:25%; text-align:left\">").AppendLine(myForm.SubmittedUser.DisplayName).Append("</td>")
                .Append("           <td style=\"width:25%; text-align:right\">Updated By:</td>")
                .Append("           <td style=\"width:25%; text-align:left\">").AppendLine(myForm.LastModifiedUser.DisplayName).Append("</td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .Append("           <td style=\"width:25%; text-align:right\"></td>")
                .Append("           <td style=\"width:25%; text-align:left\"></td>")
                .Append("           <td style=\"width:25%; text-align:right\">Last Update:</td>")
                .Append("           <td style=\"width:25%; text-align:left\">").AppendLine(myForm.LastModifiedTimestamp.ToShortDateString()).Append("</td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .Append("           <td style=\"width:100%; text-align:center\" colspan=\"4\"><span style=\"color:#bc4445; font-weight:bold\">Request Notifications Sent To:</span> <br />")
                .AppendLine(EmailList)
                .AppendLine("       </td>")
                .AppendLine("    </tr>")
                .AppendLine("    <tr>")
                .AppendLine("           <td style=\"width:100%; text-align:center\" colspan=\"4\"><br /><br /></td>")
                .AppendLine("    </tr>")
                .AppendLine("</table><br /><br />");

            if (SendComments && anyComments)
            {
                bodyHtml.AppendLine("<div style=\"width:100%; padding-top:10px\">");

                foreach (var comment in finalComments)
                {
                    if (comment.SystemComment == false)
                    {
                        bodyHtml.AppendLine("<div style=\"width:80%; background-color:#bc4445; margin: 0 auto; text-align:left; font-size:12px; color:white;word-wrap: break-word;\">")
                            .AppendLine("<div style=\"width:100%; margin:10px\">").AppendLine(comment.Note).AppendLine("<br /><br />")
                            .AppendLine("<span style=\"padding-right:20px\">by ").AppendLine(comment.User.DisplayName).AppendLine("</span>")
                            .AppendLine(comment.Timestamp.ToString())
                            .AppendLine("</div></div>");
                    }
                    else
                    {
                        bodyHtml.AppendLine("<div style=\"width:80%; background-color:#FFF; margin: 0 auto; text-align:right; font-size:12px; color:#bc4445; word-wrap: break-word;\">")
                            .AppendLine("<div style=\"width:95%; padding: 5px;\">").AppendLine(comment.Note).AppendLine("<br /><br />")
                            .AppendLine(comment.Timestamp.ToString())
                            .AppendLine("</div></div>");
                    }
                }
            }

            bodyHtml.AppendLine("</div><br /><br />");

            bool result = msg.SendMail("*****@*****.**", emailList, "Must Include Request Update", bodyHtml.ToString(), submittedForm, myForm.RecordId, currentUser);
        }
        protected void btnSendNotification_Click(object sender, EventArgs e)
        {
            try
            {
                string emailListString = lblEmailsSentTo.Text.Replace(" ", "");
                List<string> emailList = emailListString.Split(',').ToList<string>();

                if (Page.IsValid && emailListString != "")
                {
                    string notifyAbout = ddlNotifyAbout.SelectedText;
                    string overLast = ddlNotifyOverLast.SelectedText;
                    int days = overLast == "All" ? 9999 : Convert.ToInt32(overLast);

                    DateTime maxDate = DateTime.Now.AddDays(-1 * days);

                    string commentCountText = ddlCommentCount.SelectedText;
                    int commentCount = ddlCommentCount.SelectedText != "All" ? Convert.ToInt32(commentCountText) : 0;
                    Boolean sendComments = cbSendComments.Checked;
                    Boolean anyComments = false;
                    IEnumerable<InventoryComments> finalComments = null;

                    if (_ctx.InventoryApprovalComments.Any(x => x.SystemComment == false))
                    {
                        anyComments = true;

                        IEnumerable<InventoryComments> commentsList = _ctx.InventoryApprovalComments
                            .Where(x => x.SystemComment == false)
                            .Include(x => x.User)
                            .OrderByDescending(x => x.RecordId)
                            .ToList();

                        if (commentCount > 0)
                        {
                            commentsList = commentsList.Take(commentCount);
                        }

                        finalComments = commentsList;
                    }

                    System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                    UserLogic uLogic = new UserLogic();
                    SystemUsers currentUser = uLogic.GetCurrentUser(user);

                    SendEmail msg = new SendEmail();
                    StringBuilder bodyHtml = new StringBuilder();

                    bodyHtml.AppendLine("<div style=\"width:50%; text-align:center;\"><img src=\"http://www.wctingle.com/img/Logo.jpg\" /><br /><br />")
                        .Append("An Inventory Approval Notification has been sent by ").Append(currentUser.DisplayName).Append("<br /><br />")
                        .AppendLine("<table style=\"border: 4px solid #d0604c;background-color:#FFF;width:100%;margin-lefT:auto; margin-right:auto;\">")
                        .AppendLine("    <tr>")
                        .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 20px;border: 4px solid #d0604c; color:#FFF; background-color:#bc4445;\">Inventory Approval Notification</td>")
                        .AppendLine("    </tr>")
                        .AppendLine("    <tr>")
                        .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 14px;color:#FFF; background-color:#bc4445;\">")
                        .Append("Notification About ").Append(notifyAbout).Append(" Orders over the last ").Append(overLast).Append(" Days")
                        .AppendLine("</td>")
                        .AppendLine("    </tr>")
                        .AppendLine("    <tr>")
                        .AppendLine("        <td colspan=\"2\" style=\"text-align:right;font-size:12px;width:25%;color:#bc4445;\">Company:</td>")
                        .Append("        <td colspan=\"2\" style=\"text-align:left;font-size:12px;width:25%;color:#000;\">").Append(ddlCompanyGlobal.SelectedText).AppendLine("</td>")
                        .Append("        <td colspan=\"2\"></td>")
                        .AppendLine("        <td colspan=\"2\" style=\"text-align:right;font-size:12px;width:25%; color:#bc4445\">Vendor:</td>")
                        .AppendLine("        <td colspan=\"2\" style=\"text-align:left;font-size:12px;width:25%;color:#000\">").Append(ddlVendorsGlobal.SelectedText).Append("</td>")
                        .AppendLine("    </tr>")
                        .AppendLine("    <tr><td colspan=\"10\" style=\"padding-bottom:5px;\"</td></tr>");

                    if (notifyAbout == "Pending Approval" || notifyAbout == "All")
                    {
                        bodyHtml.AppendLine("    <tr>")
                            .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 16px;border-top: 4px solid #d0604c; border-bottom: 4px solid #d0604c; color:#000; background-color:#FFF;\">Pending Approval</td>")
                            .AppendLine("    </tr>");

                        using (FormContext ctx = new FormContext())
                        {
                            if (ctx.InventoryApprovalItems.Any(x => x.Status.StatusDescription == "Pending Approval" && x.Timestamp >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                            {
                                bodyHtml.AppendLine("    <tr>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Vendor</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">PO #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Material Group</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Cost</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Container #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Priority</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Order Entry Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Est. Ship Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">ETA</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Created By</td>")
                                    .AppendLine("    </tr>");

                                foreach (InventoryApprovalForm item in ctx.InventoryApprovalItems.Where(x => x.Status.StatusDescription == "Pending Approval" && x.Timestamp >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                                {
                                    bodyHtml.AppendLine("    <tr>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.Vendor.VendorName).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.PurchaseOrderNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.MaterialGroup).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Cost.ToString("c0")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ContainerNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Priority.PriorityText).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Timestamp.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.EstimatedShipDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.EstimatedTimeOfArrival.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.SubmittedUser.DisplayName).Append("</td>")
                                        .AppendLine("    </tr>");
                                }
                            }

                            bodyHtml.AppendLine("    <tr><td colspan=\"10\" style=\"padding-bottom:5px;\"</td></tr>");
                        }
                    }

                    if (notifyAbout == "Approved" || notifyAbout == "All")
                    {
                        bodyHtml.AppendLine("    <tr>")
                            .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 16px;border-top: 4px solid #d0604c; border-bottom: 4px solid #d0604c; color:#000; background-color:#FFF;\">Approved</td>")
                            .AppendLine("    </tr>");

                        using (FormContext ctx = new FormContext())
                        {
                            if (ctx.InventoryApprovalItems.Any(x => x.Status.StatusDescription == "Approved" && x.ApprovedDate.Value >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                            {
                                bodyHtml.AppendLine("    <tr>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Vendor</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">PO #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Material Group</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Cost</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Container #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Priority</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Order Entry Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Est. Ship Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">ETA</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Approved</td>")
                                    .AppendLine("    </tr>");

                                foreach (InventoryApprovalForm item in ctx.InventoryApprovalItems.Where(x => x.Status.StatusDescription == "Approved" && x.Timestamp >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                                {
                                    bodyHtml.AppendLine("    <tr>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.Vendor.VendorName).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.PurchaseOrderNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.MaterialGroup).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Cost.ToString("c0")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ContainerNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Priority.PriorityText).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Timestamp.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.EstimatedShipDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.EstimatedTimeOfArrival.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ApprovedDate.Value.ToString("MM/dd/yy")).Append(" <br />by ").Append(item.ApprovedBy.DisplayName)
                                        .Append("</td>")
                                        .AppendLine("    </tr>");
                                }
                            }

                            bodyHtml.AppendLine("    <tr><td colspan=\"10\" style=\"padding-bottom:5px;\"</td></tr>");
                        }
                    }

                    if (notifyAbout == "Ordered" || notifyAbout == "All")
                    {
                        bodyHtml.AppendLine("    <tr>")
                            .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 16px;border-top: 4px solid #d0604c; border-bottom: 4px solid #d0604c; color:#000; background-color:#FFF;\">Ordered</td>")
                            .AppendLine("    </tr>");

                        using (FormContext ctx = new FormContext())
                        {
                            if (ctx.InventoryApprovalItems.Any(x => x.Status.StatusDescription == "Ordered" && x.OrderDate.Value >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                            {
                                bodyHtml.AppendLine("    <tr>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Vendor</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">PO #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Material Group</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Cost</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Container #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Priority</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Order Entry Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Ship Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">ETA</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Ordered</td>")
                                    .AppendLine("    </tr>");

                                foreach (InventoryApprovalForm item in ctx.InventoryApprovalItems.Where(x => x.Status.StatusDescription == "Ordered" && x.OrderDate >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                                {
                                    bodyHtml.AppendLine("    <tr>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.Vendor.VendorName).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.PurchaseOrderNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.MaterialGroup).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Cost.ToString("c0")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ContainerNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Priority.PriorityText).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Timestamp.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ActualShipDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.EstimatedTimeOfArrival.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.OrderDate.Value.ToString("MM/dd/yy")).Append(" <br />by ").Append(item.OrderedBy.DisplayName)
                                        .Append("</td>")
                                        .AppendLine("    </tr>");
                                }
                            }

                            bodyHtml.AppendLine("    <tr><td colspan=\"10\" style=\"padding-bottom:5px;\"</td></tr>");
                        }
                    }

                    if (notifyAbout == "Arrived" || notifyAbout == "All")
                    {
                        bodyHtml.AppendLine("    <tr>")
                            .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 16px;border-top: 4px solid #d0604c; border-bottom: 4px solid #d0604c; color:#000; background-color:#FFF;\">Arrived</td>")
                            .AppendLine("    </tr>");

                        using (FormContext ctx = new FormContext())
                        {
                            if (ctx.InventoryApprovalItems.Any(x => x.Status.StatusDescription == "Arrived" && x.ArrivalDate.Value >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                            {
                                bodyHtml.AppendLine("    <tr>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Vendor</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">PO #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Material Group</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Cost</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Container #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Priority</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Ordered Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Ship Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Arrived</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Time To Arrival</td>")
                                    .AppendLine("    </tr>");

                                foreach (InventoryApprovalForm item in ctx.InventoryApprovalItems.Where(x => x.Status.StatusDescription == "Arrived" && x.ArrivalDate >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                                {
                                    bodyHtml.AppendLine("    <tr>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.Vendor.VendorName).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.PurchaseOrderNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.MaterialGroup).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Cost.ToString("c0")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ContainerNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Priority.PriorityText).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.OrderDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ActualShipDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ArrivalDate.Value.ToString("MM/dd/yy")).Append(" <br />by ").Append(item.ReceivedBy.DisplayName)
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.TimeToArrival).Append("</td>")
                                        .Append("</td>")
                                        .AppendLine("    </tr>");
                                }
                            }

                            bodyHtml.AppendLine("    <tr><td colspan=\"10\" style=\"padding-bottom:5px;\"</td></tr>");
                        }
                    }

                    if (notifyAbout == "Invoiced" || notifyAbout == "All")
                    {
                        bodyHtml.AppendLine("    <tr>")
                            .AppendLine("        <td colspan=\"10\" style=\"text-align: center;vertical-align: middle;font-weight: bold;font-size: 16px;border-top: 4px solid #d0604c; border-bottom: 4px solid #d0604c; color:#000; background-color:#FFF;\">Invoiced</td>")
                            .AppendLine("    </tr>");

                        using (FormContext ctx = new FormContext())
                        {
                            if (ctx.InventoryApprovalItems.Any(x => x.Status.StatusDescription == "Invoiced" && x.InvoiceDate.Value >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                            {
                                bodyHtml.AppendLine("    <tr>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Vendor</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">PO #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#bc4445;\">Material Group</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Cost</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Container #</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Priority</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Ordered Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Arrival Date</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Time To Arrival</td>")
                                    .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#bc4445;\">Invoiced</td>")
                                    .AppendLine("    </tr>");

                                foreach (InventoryApprovalForm item in ctx.InventoryApprovalItems.Where(x => x.Status.StatusDescription == "Invoiced" && x.InvoiceDate >= DbFunctions.AddDays(DateTime.Now, -1 * days)))
                                {
                                    bodyHtml.AppendLine("    <tr>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.Vendor.VendorName).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.PurchaseOrderNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:15%;color:#000;\">").Append(item.MaterialGroup).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Cost.ToString("c0")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ContainerNumber).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.Priority.PriorityText).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.OrderDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.ArrivalDate.Value.ToString("MM/dd/yy")).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.TimeToArrival).Append("</td>")
                                        .AppendLine("        <td style=\"text-align:center;font-size:12px;width:10%;color:#000;\">").Append(item.InvoiceDate.Value.ToString("MM/dd/yy")).Append(" <br />by ").Append(item.InvoicedBy.DisplayName)

                                        .Append("</td>")
                                        .AppendLine("    </tr>");
                                }
                            }

                            bodyHtml.AppendLine("    <tr><td colspan=\"10\" style=\"padding-bottom:5px;\"</td></tr>");
                        }
                    }

                    bodyHtml.AppendLine("</table><br /><br />");

                    if (sendComments && anyComments)
                    {
                        bodyHtml.AppendLine("<div style=\"width:100%; padding-top:10px\">");

                        foreach (var comment in finalComments)
                        {
                            if (comment.SystemComment == false)
                            {
                                bodyHtml.AppendLine("<div style=\"width:80%; background-color:#bc4445; margin: 0 auto; text-align:left; font-size:12px; color:white;word-wrap: break-word;\">")
                                    .AppendLine("<div style=\"width:100%; margin:10px\">").AppendLine(comment.Note).AppendLine("<br /><br />")
                                    .AppendLine("<span style=\"padding-right:20px\">by ").AppendLine(comment.User.DisplayName).AppendLine("</span>")
                                    .AppendLine(comment.Timestamp.ToString())
                                    .AppendLine("</div></div>");
                            }
                            //else
                            //{
                            //    bodyHtml.AppendLine("<div style=\"width:80%; background-color:#FFF; margin: 0 auto; text-align:right; font-size:12px; color:#bc4445; word-wrap: break-word;\">")
                            //        .AppendLine("<div style=\"width:95%; padding: 5px;\">").AppendLine(comment.Note).AppendLine("<br /><br />")
                            //        .AppendLine(comment.Timestamp.ToString())
                            //        .AppendLine("</div></div>");
                            //}
                        }
                    }

                    bool result = msg.SendInventoryNotification(emailList, bodyHtml.ToString(), currentUser);

                    lblNotificationMessage.Text = "Inventory Approval Notification Sent Successfully.";
                }
                else
                {
                    lblNotificationMessage.Text = "No Email Addresses were selected.  Notification not sent.";
                }

            }
            catch (Exception ex)
            {
                lblNotificationMessage.Text = "An error occured during the notification.  <br /><br />Please contact your System Administrator for more information.";
            }
        }