示例#1
0
        public Boolean SendInventoryNotification(List<string> emailList, string bodyHtml, SystemUsers sentUser)
        {
            try
            {
                MailMessage completeMessage = new MailMessage();
                completeMessage.From = new MailAddress("*****@*****.**");
                completeMessage.Subject = "Inventory Approval Notification";
                completeMessage.Body = bodyHtml;
                completeMessage.IsBodyHtml = true;

                //SmtpClient client = new SmtpClient("TingleNT30.wctingle.com");
                //client.UseDefaultCredentials = true;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.Credentials = new NetworkCredential("*****@*****.**", "ZXCasdQWE123!");
                client.EnableSsl = true;

                using (FormContext ctx = new FormContext())
                {
                    foreach (string email in emailList)
                    {
                        InventoryApprovalNotifications newRN = new InventoryApprovalNotifications
                        {
                            BodyHtml = bodyHtml,
                            SentBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == sentUser.SystemUserID),
                            Status = 0,
                            Timestamp = DateTime.Now,
                            ToEmailAddress = email
                        };

                        ctx.InventoryApprovalNotifications.Add(newRN);
                        ctx.SaveChanges();

                        try
                        {
                            completeMessage.To.Clear();
                            completeMessage.To.Add(email);
                            client.Send(completeMessage);

                            newRN.Status = 1;

                            ctx.SaveChanges();
                        }
                        catch (Exception exc)
                        { }

                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public bool AddExpeditedOrderForm(string oowOrderNumber, string customer, string accountNumber, ExpediteCode expediteCode, string purchaseOrderNumber, string materialSku, string quantityOrdered,
            Nullable<DateTime> installDate, string sM, string contactName, string phoneNumber, string shipToName, string shipToAddress, string shipToCity, string shipToState, string shipToZip,
            string additionalInfo, Status status, string submittedByUser, string ccFormToEmail, string company, out Int32 formId)
        {
            try
            {
                using (FormContext _db = new FormContext())
                {
                    var expCode = _db.ExpediteCodes.SingleOrDefault(ec => ec.ExpediteCodeID == expediteCode.ExpediteCodeID);
                    var submissionStatus = _db.Statuses.SingleOrDefault(s => s.StatusId == status.StatusId);

                    var newForm = new ExpeditedOrderForm();
                    newForm.Timestamp = DateTime.Now;
                    newForm.OowOrderNumber = oowOrderNumber;
                    newForm.Customer = customer;
                    newForm.AccountNumber = accountNumber;
                    newForm.ExpediteCode = expCode;
                    newForm.PurchaseOrderNumber = purchaseOrderNumber;
                    newForm.InstallDate = installDate;
                    newForm.SM = sM;
                    newForm.ContactName = contactName;
                    newForm.PhoneNumber = phoneNumber;
                    newForm.ShipToName = shipToName;
                    newForm.ShipToAddress = shipToAddress;
                    newForm.ShipToCity = shipToCity;
                    newForm.ShipToState = shipToState;
                    newForm.ShipToZip = shipToZip;
                    newForm.AdditionalInfo = additionalInfo;
                    newForm.Status = submissionStatus;
                    newForm.SubmittedByUser = submittedByUser;
                    newForm.CCFormToEmail = ccFormToEmail;
                    newForm.Company = company;

                    _db.ExpeditedOrderForms.Add(newForm);
                    _db.SaveChanges();

                    formId = newForm.RecordId;
                }
                return true;
            }
            catch (Exception ex)
            {
                formId = 0;
                return false;
                //throw ex;

            }
        }
        public void fvEmailInsert_InsertItem()
        {
            try
            {
                TextBox txtNameInsert = (TextBox)fvEmailInsert.FindControl("txtNameInsert");
                TextBox txtAddressInsert = (TextBox)fvEmailInsert.FindControl("txtAddressInsert");
                RadioButtonList rblCompanyInsert = (RadioButtonList)fvEmailInsert.FindControl("rblCompanyInsert");
                RadioButtonList rblStatusInsert = (RadioButtonList)fvEmailInsert.FindControl("rblStatusInsert");
                Int16 status = Convert.ToInt16(rblStatusInsert.SelectedValue);
                int id = Convert.ToInt32(ddlFormName.SelectedValue);

                using (FormContext ctx = new FormContext())
                {
                    var tForm = ctx.TForms.Where(f => f.FormID == id).FirstOrDefault();

                    EmailAddress newEmail = new EmailAddress();

                    newEmail.Name = txtNameInsert.Text;
                    newEmail.Address = txtAddressInsert.Text;
                    newEmail.Company = rblCompanyInsert.SelectedValue;
                    newEmail.Status = status;
                    newEmail.TForm = tForm;
                    newEmail.Timestamp = DateTime.Now;

                    ctx.EmailAddresses.Add(newEmail);

                    if (ModelState.IsValid)
                    {
                        ctx.SaveChanges();
                        gvEmailList.DataBind();
                    }

                    lblEmailMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblEmailMessage.Text = "Unable to insert new Email Address.  Please contact your system administrator.";
            }
        }
        protected void gvEmailList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblEmailAddressID = (Label)gvr.FindControl("lblEmailAddressIDEdit");
                int id = Convert.ToInt32(lblEmailAddressID.Text);

                using (FormContext ctx = new FormContext())
                {
                    var emailAddress = ctx.EmailAddresses.Where(ea => ea.EmailAddressID == id).FirstOrDefault();

                    emailAddress.Name = ((TextBox)gvr.FindControl("txtNameEdit")).Text;
                    emailAddress.Address = ((TextBox)gvr.FindControl("txtAddressEdit")).Text;
                    emailAddress.Status = Convert.ToInt16(((RadioButtonList)gvr.FindControl("rblStatusEdit")).SelectedValue);
                    emailAddress.Company = ((DropDownList)gvr.FindControl("ddlCompanyEdit")).SelectedValue;

                    ctx.EmailAddresses.Attach(emailAddress);
                    ctx.Entry(emailAddress).State = EntityState.Modified;

                    ctx.SaveChanges();
                    gvEmailList.DataBind();

                    lblEmailMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblEmailMessage.Text = "Unable to update Email Address.  Please contact your system administrator.";
            }
        }
        protected void btnAddComment_Click(object sender, EventArgs e)
        {
            try
            {
                Label lblRecordId = (Label)fvReport.FindControl("lblRecordId");
                int recordId;
                Int32.TryParse(lblRecordId.Text, out recordId);
                RadTextBox txtNewComment = (RadTextBox)fvReport.FindControl("txtNewComment");
                Repeater rptrComments = (Repeater)fvReport.FindControl("rptrComments");

                UserLogic newLogic = new UserLogic();

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

                using (var ctx = new FormContext())
                {
                    var thisForm = ctx.MustIncludeForms.FirstOrDefault(eof => eof.RecordId == recordId);

                    Comments newComment = new Comments
                    {
                        Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Must Include"),
                        Note = txtNewComment.Text,
                        RelatedFormId = thisForm.RecordId,
                        SystemComment = false,
                        Timestamp = DateTime.Now,
                        User = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID)
                    };

                    ctx.Comments.Add(newComment);
                    ctx.SaveChanges();

                    txtNewComment.Text = "";
                    txtNewComment.Invalid = false;

                    rptrComments.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        protected void gvSkus_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblRecordIdEdit = (Label)gvr.FindControl("lblRecordIdEdit");
                int id = Convert.ToInt32(lblRecordIdEdit.Text);

                using (FormContext ctx = new FormContext())
                {
                    var sku = ctx.SkuQuantityItems.FirstOrDefault(x => x.RecordId == id);

                    sku.Completed = ((CheckBox)gvr.FindControl("cbCompletedEdit")).Checked;
                    sku.MaterialSku = ((TextBox)gvr.FindControl("txtMaterialSkuEdit")).Text;
                    sku.Quantity = ((TextBox)gvr.FindControl("txtQuantityEdit")).Text;

                    ctx.SaveChanges();
                    gvSkus.DataBind();
                    lblAddSkuMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblAddSkuMessage.Text = "Unable to update Material SKU# and/or Quantity.  Please contact your system administrator.";
            }
        }
        public void gvSkus_DeleteItem(int RecordId)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    SkuQuantity SkuToDelete = ctx.SkuQuantityItems.FirstOrDefault(x => x.RecordId == RecordId);

                    if (SkuToDelete != null)
                    {
                        ctx.SkuQuantityItems.Remove(SkuToDelete);
                        ctx.SaveChanges();
                    }

                    lblAddSkuMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblAddSkuMessage.Text = "Unable to delete Material SKU# and Quantity.  Please contact your system administrator.";
            }
        }
        protected void btnAddComment_Click(object sender, EventArgs e)
        {
            try
            {
                int recordId;
                Int32.TryParse(lblRecordId.Text, out recordId);

                UserLogic newLogic = new UserLogic();

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

                using (var ctx = new FormContext())
                {
                    var thisForm = ctx.CannotWaitForContainerForms.FirstOrDefault(eof => eof.RecordId == recordId);

                    Comments newComment = new Comments
                    {
                        Form = ctx.TForms.FirstOrDefault(x => x.FormName == "Cannot Wait For Container"),
                        Note = txtNewComment.Text,
                        RelatedFormId = thisForm.RecordId,
                        SystemComment = false,
                        Timestamp = DateTime.Now,
                        User = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID)
                    };

                    ctx.Comments.Add(newComment);
                    ctx.SaveChanges();

                    txtNewComment.Text = "";
                    txtNewComment.Invalid = false;

                    rptrComments.DataBind();
                    Session["NewComment"] = "true";

                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#9
0
        protected void btnSaveAccountSettings_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    UserLogic uLogic = new UserLogic();
                    System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                    SystemUsers currentUser = uLogic.GetCurrentUser(user);

                    using (FormContext ctx = new FormContext())
                    {
                        var updateUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID);

                        updateUser.Greeting = txtGreeting.Text;
                        updateUser.DisplayName = txtDisplayName.Text;
                        updateUser.UserStatus = ctx.UserStatuses.FirstOrDefault(x => x.StatusText == ddlUserStatus.SelectedText);

                        ctx.SaveChanges();

                        divSaveCancel.Visible = false;
                        divLabelEdit.Visible = true;
                        divDisplayNameEdit.Visible = false;
                        ddlUserStatus.Enabled = false;
                        txtGreeting.Enabled = false;

                        lblUser.Text = txtDisplayName.Text;
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
        public void fvVendors_InsertItem()
        {
            try
            {
                TextBox txtVendorNameInsert = (TextBox)fvVendors.FindControl("txtVendorNameInsert");
                TextBox txtVendorPhoneInsert = (TextBox)fvVendors.FindControl("txtVendorPhoneInsert");
                TextBox txtVendorFaxInsert = (TextBox)fvVendors.FindControl("txtVendorFaxInsert");

                using (FormContext ctx = new FormContext())
                {
                    if (!ctx.Vendors.Any(x => x.VendorName == txtVendorNameInsert.Text.Trim()))
                    {
                        Vendor newVendor = new Vendor();

                        newVendor.VendorName = txtVendorNameInsert.Text;
                        newVendor.VendorPhone = txtVendorPhoneInsert.Text;
                        newVendor.VendorPhone = txtVendorFaxInsert.Text;
                        newVendor.CurrentStock = 0;
                        newVendor.Timestamp = DateTime.Now;

                        ctx.Vendors.Add(newVendor);

                        ctx.SaveChanges();
                        gvVendors.DataBind();

                        lblVariableMessage.Text = "";
                    }
                    else
                    {
                        lblVariableMessage.Text = "A Vendor named: " + txtVendorNameInsert.Text + " already exists.  Please try again.";
                    }
                }
            }
            catch (Exception ex)
            {
                lblVariableMessage.Text = "Unable to add this Vendor.  Please contact your system administrator.";
            }
        }
        public void fvUserInsert_InsertItem()
        {
            try
            {
                TextBox txtUserNameInsert = (TextBox)fvUserInsert.FindControl("txtUserNameInsert");
                TextBox txtDisplayNameInsert = (TextBox)fvUserInsert.FindControl("txtDisplayNameInsert");
                TextBox txtEmailAddressInsert = (TextBox)fvUserInsert.FindControl("txtEmailAddressInsert");
                RadioButtonList rblUserStatusInsert = (RadioButtonList)fvUserInsert.FindControl("rblUserStatusInsert");
                CheckBox cbInventoryApproval = (CheckBox)fvUserInsert.FindControl("cbInventoryApproval");
                int roleId = Convert.ToInt32(((DropDownList)fvUserInsert.FindControl("ddlUserRoleInsert")).SelectedValue);
                Int16 status = Convert.ToInt16(rblUserStatusInsert.SelectedValue);

                using (FormContext ctx = new FormContext())
                {
                    if (ctx.SystemUsers.Where(su => su.UserName == txtUserNameInsert.Text).FirstOrDefault() == null)
                    {
                        SystemUsers newUser = new SystemUsers();
                        UserRoles newRole = ctx.UserRoles.Where(ur => ur.UserRoleId == roleId).FirstOrDefault();

                        newUser.UserName = txtUserNameInsert.Text;
                        newUser.DisplayName = txtDisplayNameInsert.Text;
                        newUser.EmailAddress = txtEmailAddressInsert.Text;
                        newUser.Status = status;
                        newUser.UserRole = newRole;
                        newUser.InventoryApprovalUser = cbInventoryApproval.Checked;

                        ctx.SystemUsers.Add(newUser);

                        if (ModelState.IsValid)
                        {
                            ctx.SaveChanges();
                            gvUsers.DataBind();
                        }
                        lblUserMessage.Text = "";
                    }
                    else
                    {
                        lblUserMessage.Text = "A User with the username: "******" already exists.";
                    }
                }
            }
            catch (Exception ex)
            {
                lblUserMessage.Text = "Unable to add new User.  Please contact your system administrator.";
            }
        }
        protected void gvVendors_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblRecordId = (Label)gvr.FindControl("lblRecordIdEdit");
                int id = Convert.ToInt32(lblRecordId.Text);

                using (FormContext ctx = new FormContext())
                {
                    var vendor = ctx.Vendors.FirstOrDefault(x => x.RecordId == id);

                    vendor.VendorName = ((TextBox)gvr.FindControl("lblVendorNameEdit")).Text;
                    vendor.VendorPhone = ((TextBox)gvr.FindControl("lblVendorPhoneEdit")).Text;
                    vendor.VendorFax = ((TextBox)gvr.FindControl("lblVendorFaxEdit")).Text;

                    ctx.SaveChanges();
                    gvVendors.DataBind();

                    lblVariableMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblVariableMessage.Text = "Unable to update Vendor.  Please contact your system administrator.";
            }
        }
        protected void gvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblSystemUserID = (Label)gvr.FindControl("lblSystemUserIDEdit");
                int id = Convert.ToInt32(lblSystemUserID.Text);
                int userRoleID = Convert.ToInt32(((DropDownList)gvr.FindControl("ddlUserRoleEdit")).SelectedValue);
                Boolean invMgmt = Convert.ToBoolean(((CheckBox)gvr.FindControl("cbInventoryManagementEdit")).Checked);

                using (FormContext ctx = new FormContext())
                {
                    var systemUser = ctx.SystemUsers.Where(su => su.SystemUserID == id).FirstOrDefault();

                    systemUser.DisplayName = ((TextBox)gvr.FindControl("txtDisplayNameEdit")).Text;
                    systemUser.EmailAddress = ((TextBox)gvr.FindControl("txtEmailAddressEdit")).Text;
                    systemUser.Status = Convert.ToInt16(((RadioButtonList)gvr.FindControl("rblUserStatusEdit")).SelectedValue);
                    systemUser.UserRole = ctx.UserRoles.Where(ur => ur.UserRoleId == userRoleID).FirstOrDefault();
                    systemUser.InventoryApprovalUser = invMgmt;

                    ctx.SystemUsers.Attach(systemUser);
                    ctx.Entry(systemUser).State = EntityState.Modified;

                    ctx.SaveChanges();
                    gvUsers.DataBind();
                    lblUserMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblUserMessage.Text = "Unable to update user.  Please contact your system administrator.";
            }
        }
        protected void gvNotificationEmails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblRecorIdEdit = (Label)gvr.FindControl("lblRecorIdEdit");
                int id = Convert.ToInt32(lblRecorIdEdit.Text);

                using (FormContext ctx = new FormContext())
                {
                    var notiEmail = ctx.NotificationEmailAddresses.FirstOrDefault(x => x.RecordId == id);

                    notiEmail.Name = ((TextBox)gvr.FindControl("txtNameEdit")).Text;
                    notiEmail.Address = ((TextBox)gvr.FindControl("txtAddressEdit")).Text;
                    notiEmail.Status = Convert.ToInt16(((RadioButtonList)gvr.FindControl("rblNotificationEmailStatusEdit")).SelectedValue);

                    ctx.SaveChanges();
                    gvNotificationEmails.DataBind();

                    lblNotificationEmailMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblNotificationEmailMessage.Text = "Unable to update Notification Email Address.  Please contact your system administrator.";
            }
        }
        protected void gvExpediteCodes_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                GridView gv = (GridView)sender;
                GridViewRow gvr = (GridViewRow)gv.Rows[e.RowIndex];
                Label lblExpediteCodeID = (Label)gvr.FindControl("lblExpediteCodeIDEdit");
                int id = Convert.ToInt32(lblExpediteCodeID.Text);

                using (FormContext ctx = new FormContext())
                {
                    var expCode = ctx.ExpediteCodes.FirstOrDefault(x => x.ExpediteCodeID == id);

                    expCode.Code = ((TextBox)gvr.FindControl("txtCodeEdit")).Text;
                    expCode.Description = ((TextBox)gvr.FindControl("txtDescriptionEdit")).Text;
                    expCode.Status = Convert.ToInt16(((RadioButtonList)gvr.FindControl("rblCodeStatusEdit")).SelectedValue);

                    ctx.SaveChanges();
                    gvExpediteCodes.DataBind();

                    lblVariableMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblVariableMessage.Text = "Unable to update Expedite Code.  Please contact your system administrator.";
            }
        }
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                int formId = Convert.ToInt32(((RadButton)sender).CommandArgument);
                System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                UserLogic uLogic = new UserLogic();
                SystemUsers currentUser = uLogic.GetCurrentUser(user);
                int userId = currentUser.SystemUserID;

                using (FormContext ctx = new FormContext())
                {
                    if (ctx.InventoryApprovalItems.Any(x => x.RecordId == formId))
                    {
                        var editForm = ctx.InventoryApprovalItems.FirstOrDefault(x => x.RecordId == formId);
                        editForm.Status = ctx.InventoryApprovalStatuses.FirstOrDefault(x => x.StatusDescription == "Approved");
                        editForm.ApprovedBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);
                        editForm.ApprovedDate = DateTime.Now;
                        editForm.LastModifiedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);
                        editForm.LastModifiedTimestamp = DateTime.Now;
                    }

                    ctx.SaveChanges();

                    RebindGrids();

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnPostComment_Click(object sender, EventArgs e)
        {
            try
            {
                if (!String.IsNullOrWhiteSpace(txtComments.Text))
                {
                    System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                    UserLogic uLogic = new UserLogic();
                    SystemUsers currentUser = uLogic.GetCurrentUser(user);

                    using (FormContext ctx = new FormContext())
                    {
                        InventoryComments newComment = new InventoryComments
                        {
                            Note = txtComments.Text,
                            SystemComment = false,
                            Timestamp = DateTime.Now,
                            User = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == currentUser.SystemUserID)
                        };

                        ctx.InventoryApprovalComments.Add(newComment);
                        ctx.SaveChanges();

                        txtComments.Text = "";
                        rptrComments.DataBind();
                        lblCommentMessage.Text = "";
                    }
                }
            }
            catch(Exception ex)
            {
                lblCommentMessage.Text = "Unable to Save Comment";
            }
        }
        public void gvUsers_DeleteItem(int SystemUserID)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    SystemUsers UserToDelete = ctx.SystemUsers.Where(su => su.SystemUserID == SystemUserID).FirstOrDefault();

                    if (UserToDelete != null)
                    {
                        ctx.SystemUsers.Remove(UserToDelete);
                        ctx.SaveChanges();
                    }

                    lblUserMessage.Text = "";
                }
            }
            catch (Exception ex)
            {
                lblUserMessage.Text = "Unable to delete User.  Please contact your system administrator.";
            }
        }
        protected void btnAddSkuQuantity_Click(object sender, EventArgs e)
        {
            try
            {
                Label lblRecordId = (Label)fvReport.FindControl("lblRecordId");
                RadTextBox txtMaterialSkuInsert = (RadTextBox)fvReport.FindControl("txtMaterialSkuInsert");
                RadTextBox txtQuantityOrderedInsert = (RadTextBox)fvReport.FindControl("txtQuantityOrderedInsert");

                GridView gvSkus = (GridView)fvReport.FindControl("gvSkus");
                int recordId;
                Int32.TryParse(lblRecordId.Text, out recordId);

                using (FormContext ctx = new FormContext())
                {
                    var thisForm = ctx.DirectOrderForms.FirstOrDefault(eof => eof.RecordId == recordId);

                    SkuQuantity newSQ = new SkuQuantity
                    {
                        MaterialSku = txtMaterialSkuInsert.Text,
                        Quantity = txtQuantityOrderedInsert.Text,
                        DirectOrderForm = thisForm,
                        Completed = false
                    };

                    ctx.SkuQuantityItems.Add(newSQ);
                    ctx.SaveChanges();
                    txtMaterialSkuInsert.Text = "";
                    txtQuantityOrderedInsert.Text = "";
                }

                gvSkus.DataBind();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void fvExpediteCodes_InsertItem()
        {
            try
            {
                TextBox txtCodeInsert = (TextBox)fvExpediteCodes.FindControl("txtCodeInsert");
                TextBox txtDescriptionInsert = (TextBox)fvExpediteCodes.FindControl("txtDescriptionInsert");
                RadioButtonList rblCodeStatusInsert = (RadioButtonList)fvExpediteCodes.FindControl("rblCodeStatusInsert");
                Int16 statusId = Convert.ToInt16(rblCodeStatusInsert.SelectedValue);

                using (FormContext ctx = new FormContext())
                {
                    if (!ctx.ExpediteCodes.Any(x => x.Code == txtCodeInsert.Text))
                    {
                        ExpediteCode newCode = new ExpediteCode();

                        newCode.Timestamp = DateTime.Now;
                        newCode.Code = txtCodeInsert.Text;
                        newCode.Description = txtDescriptionInsert.Text;
                        newCode.Status = statusId;

                        ctx.ExpediteCodes.Add(newCode);

                        ctx.SaveChanges();
                        gvExpediteCodes.DataBind();

                        lblVariableMessage.Text = "";
                    }
                    else
                    {
                        lblVariableMessage.Text = "An Expedite Code named: " + txtCodeInsert.Text + " already exists.  Please try again.";
                    }
                }
            }
            catch (Exception ex)
            {
                lblUserMessage.Text = "Unable to add this Expedite Code.  Please contact your system administrator.";
            }
        }
示例#21
0
        public Boolean SendMail(string from, List<string> emailList, string subject, string bodyHtml, TForm newForm, Int32 formId, SystemUsers sentUser)
        {
            try
            {
                MailMessage completeMessage = new MailMessage();
                completeMessage.From = new MailAddress(from);
                completeMessage.Subject = subject;
                completeMessage.Body = bodyHtml;
                completeMessage.IsBodyHtml = true;

                //SmtpClient client = new SmtpClient("TingleNT30.wctingle.com");
                //client.UseDefaultCredentials = true;
                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.Credentials = new NetworkCredential("*****@*****.**", "ZXCasdQWE123!");
                client.EnableSsl = true;

                using (FormContext ctx = new FormContext())
                {

                    foreach (string email in emailList)
                    {

                        RequestNotifications newRN = new RequestNotifications
                        {
                            Form = ctx.TForms.FirstOrDefault(x => x.FormID == newForm.FormID),
                            BodyHtml = bodyHtml,
                            RequestedFormId = formId,
                            SentBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == sentUser.SystemUserID),
                            Status = 0,
                            Timestamp = DateTime.Now,
                            ToEmailAddress = email
                        };

                        ctx.RequestNotifications.Add(newRN);
                        ctx.SaveChanges();

                        try
                        {
                            completeMessage.To.Clear();
                            completeMessage.To.Add(email);
                            client.Send(completeMessage);

                            newRN.Status = 1;

                            ctx.SaveChanges();
                        }
                        catch(Exception exc)
                        {}

                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
                //throw ex;
            }
        }
        public bool UpdateFormPermissions(string formName, string roleName, bool status)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    if (ctx.FormPermissions.Any(x => x.FormName == formName && x.UserRole.RoleName == roleName))
                    {
                        var formPermission = ctx.FormPermissions.First(x => x.FormName == formName && x.UserRole.RoleName == roleName);
                        formPermission.Enabled = status;
                    }
                    else
                    {
                        FormPermissions formPermission = new FormPermissions();
                        formPermission.FormName = formName;
                        formPermission.UserRole = ctx.UserRoles.First(x => x.RoleName == roleName);
                        formPermission.Enabled = status;

                        ctx.FormPermissions.Add(formPermission);
                    }

                    ctx.SaveChanges();
                }

                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    foreach (Vendor vendor in ctx.Vendors)
                    {
                        RadNumericTextBox txt = (RadNumericTextBox)phCurrentStock.FindControl("txt" + vendor.VendorName.Replace(" ", ""));
                        vendor.CurrentStock = Convert.ToDecimal(txt.Text);
                    }

                    ctx.SaveChanges();

                    divUdpateCurrentStock.Visible = false;
                }
            }
            catch(Exception ex)
            {
                throw;
            }
        }
        protected void ddlOrderedStatus_SelectedIndexChanged(object sender, DropDownListEventArgs e)
        {
            try
            {
                GridEditableItem editedItem = (sender as RadDropDownList).NamingContainer as GridEditableItem;
                RadDropDownList ddlApprovedStatus = sender as RadDropDownList;
                string statusDesc = ddlApprovedStatus.SelectedText;
                int formId = Convert.ToInt32(editedItem.GetDataKeyValue("RecordId"));
                System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                UserLogic uLogic = new UserLogic();
                SystemUsers currentUser = uLogic.GetCurrentUser(user);
                int userId = currentUser.SystemUserID;

                using (FormContext ctx = new FormContext())
                {
                    if (ctx.InventoryApprovalItems.Any(x => x.RecordId == formId))
                    {
                        var editForm = ctx.InventoryApprovalItems.FirstOrDefault(x => x.RecordId == formId);

                        editForm.Status = ctx.InventoryApprovalStatuses.FirstOrDefault(x => x.StatusDescription == statusDesc);
                        editForm.LastModifiedTimestamp = DateTime.Now;
                        editForm.LastModifiedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);

                        if (statusDesc == "Pending Approval")
                        {
                            editForm.ApprovedBy = null;
                            editForm.ApprovedDate = null;
                            editForm.OrderDate = null;
                            editForm.OrderedBy = null;
                            editForm.ActualShipDate = null;
                        }
                        else if (statusDesc == "Approved")
                        {
                            editForm.OrderedBy = null;
                            editForm.OrderDate = null;
                            editForm.ActualShipDate = null;
                        }
                        else if (statusDesc == "Arrived")
                        {
                            editForm.ReceivedBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);
                            editForm.ArrivalDate = DateTime.Now;
                            editForm.TimeToArrival = Math.Round((DateTime.Now - editForm.EstimatedShipDate.Value).TotalDays / 7, 1).ToString() + " weeks";
                        }
                        else if (statusDesc == "Invoiced")
                        {
                            editForm.InvoicedBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);
                            editForm.InvoiceDate = DateTime.Now;
                            editForm.TimeToArrival = Math.Round((DateTime.Now - editForm.EstimatedShipDate.Value).TotalDays / 7, 1).ToString() + " weeks";
                        }
                        else if (statusDesc == "Cancelled")
                        {
                            editForm.CancelledBy = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);
                            editForm.CancelledDate = DateTime.Now;
                        }

                    }

                    ctx.SaveChanges();

                    RebindGrids();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void btnAddSkuQuantity_Click(object sender, EventArgs e)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    SkuQuantity newSQ = new SkuQuantity
                    {
                        MaterialSku = txtMaterialSku.Text,
                        Quantity = txtQuantityOrdered.Text,
                        TempId = lblRandomIdentifier.Text,
                        Completed = false
                    };

                    ctx.SkuQuantityItems.Add(newSQ);
                    ctx.SaveChanges();
                    txtMaterialSku.Text = "";
                    txtQuantityOrdered.Text = "";
                }

                gvSkus.DataBind();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        protected void gridPendingApproval_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                using (FormContext ctx = new FormContext())
                {
                    System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                    UserLogic uLogic = new UserLogic();
                    SystemUsers currentUser = uLogic.GetCurrentUser(user);
                    int userId = currentUser.SystemUserID;

                    GridBatchEditingEventArgument argument = e.CommandArgument as GridBatchEditingEventArgument;
                    Hashtable oldValues = argument.OldValues;
                    Hashtable newValues = argument.NewValues;
                    int recordId = Convert.ToInt32(oldValues["RecordId"].ToString());
                    int vendorId = Convert.ToInt32(newValues["Vendor.VendorName"].ToString());
                    string po = newValues["PurchaseOrderNumber"].ToString();
                    string materialGroup = newValues["MaterialGroup"].ToString();
                    decimal cost = Convert.ToDecimal(newValues["Cost"].ToString());
                    string containerNumber = newValues["ContainerNumber"].ToString();
                    int priorityId = Convert.ToInt32(newValues["Priority.PriorityText"].ToString());
                    DateTime estimatedShipDate = Convert.ToDateTime(newValues["EstimatedShipDate"].ToString());
                    DateTime estimatedTimeOfArrival = Convert.ToDateTime(newValues["EstimatedTimeOfArrival"].ToString());

                    var updateForm = ctx.InventoryApprovalItems.FirstOrDefault(x => x.RecordId == recordId);
                    updateForm.Vendor = ctx.Vendors.FirstOrDefault(x => x.RecordId == vendorId);
                    updateForm.PurchaseOrderNumber = po;
                    updateForm.MaterialGroup = materialGroup;
                    updateForm.Cost = cost;
                    updateForm.ContainerNumber = containerNumber;
                    updateForm.Priority = ctx.Priorities.FirstOrDefault(x => x.RecordId == priorityId);
                    updateForm.LastModifiedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId);
                    updateForm.LastModifiedTimestamp = DateTime.Now;
                    updateForm.EstimatedShipDate = estimatedShipDate;
                    updateForm.EstimatedTimeOfArrival = estimatedTimeOfArrival;

                    ctx.SaveChanges();

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        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.";
            }
        }
        protected void btnAddNewItem_Click(object sender, EventArgs e)
        {
            try
            {
                int vendorId = Convert.ToInt32(ddlVendor.SelectedValue);
                int priorityId = Convert.ToInt32(ddlPriority.SelectedValue);
                System.Security.Principal.IPrincipal user = System.Web.HttpContext.Current.User;
                UserLogic uLogic = new UserLogic();
                SystemUsers currentUser = uLogic.GetCurrentUser(user);
                int userId = currentUser.SystemUserID;
                DateTime tryESD;
                Nullable<DateTime> esd = null;
                DateTime tryETA;
                Nullable<DateTime> eta = null;

                DateTime.TryParse(txtEstShipDate.Value, out tryESD);

                if (tryESD.Year > 0001)
                {
                    esd = tryESD;
                }

                DateTime.TryParse(txtETA.Value, out tryETA);

                if (tryETA.Year > 0001)
                {
                    eta = tryETA;
                }

                using (FormContext ctx = new FormContext())
                {
                    InventoryApprovalForm newForm = new InventoryApprovalForm
                    {
                        Timestamp = DateTime.Now,
                        Company = ddlCompany.SelectedText,
                        Vendor = ctx.Vendors.FirstOrDefault(x => x.RecordId == vendorId),
                        PurchaseOrderNumber = txtPO.Text,
                        MaterialGroup = txtMaterialGroup.Text,
                        Cost = Convert.ToDecimal(txtCost.Value),
                        ContainerNumber = txtContainer.Text,
                        Priority = ctx.Priorities.FirstOrDefault(x => x.RecordId == priorityId),
                        EstimatedShipDate = esd,
                        EstimatedTimeOfArrival = eta,
                        LastModifiedTimestamp = DateTime.Now,
                        LastModifiedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId),
                        Status = ctx.InventoryApprovalStatuses.FirstOrDefault(x => x.StatusDescription == "Pending Approval"),
                        SubmittedUser = ctx.SystemUsers.FirstOrDefault(x => x.SystemUserID == userId)
                    };

                    ctx.InventoryApprovalItems.Add(newForm);

                    ctx.SaveChanges();

                    gridPendingApproval.Rebind();

                    ddlCompany.SelectedIndex = 0;
                    ddlVendor.SelectedIndex = 0;
                    txtPO.Text = "";
                    txtMaterialGroup.Text = "";
                    txtCost.Text = "";
                    txtContainer.Text = "";
                    ddlPriority.SelectedValue = "Normal";
                    txtEstShipDate.Value = "";
                    txtETA.Value = "";

                }
            }
            catch(Exception ex)
            {
                throw;
            }
        }
        protected void btnInsertEmail_Click(object sender, EventArgs e)
        {
            RadTextBox txtNameInsert = (RadTextBox)fvReport.FindControl("txtNameInsert");
            RadTextBox txtAddressInsert = (RadTextBox)fvReport.FindControl("txtAddressInsert");
            RadComboBox ddlNotifyOther = (RadComboBox)fvReport.FindControl("ddlNotifyOther");
            RadioButtonList rblNotificationEmailStatusInsert = (RadioButtonList)fvReport.FindControl("rblNotificationEmailStatusInsert");
            Label lblInsertEmailMessage = (Label)fvReport.FindControl("lblInsertEmailMessage");

            try
            {
                using (FormContext ctx = new FormContext())
                {
                    if (!ctx.NotificationEmailAddresses.Any(x => x.Name == txtNameInsert.Text || x.Address == txtAddressInsert.Text))
                    {
                        if (!ctx.SystemUsers.Any(x => x.EmailAddress == txtAddressInsert.Text))
                        {
                            NotificationEmailAddress newEmail = new NotificationEmailAddress();

                            newEmail.Timestamp = DateTime.Now;
                            newEmail.Name = txtNameInsert.Text;
                            newEmail.Address = txtAddressInsert.Text;
                            newEmail.Status = Convert.ToInt16(rblNotificationEmailStatusInsert.SelectedValue);

                            ctx.NotificationEmailAddresses.Add(newEmail);

                            ctx.SaveChanges();

                            lblInsertEmailMessage.Text = "";
                            txtAddressInsert.Text = "";
                            txtNameInsert.Text = "";
                            rblNotificationEmailStatusInsert.SelectedIndex = 0;
                            ddlNotifyOther.DataBind();
                        }
                        else
                        {
                            lblInsertEmailMessage.Text = "A System User already exists with this Email Address.  Please enter a unique Email Address.";
                        }
                    }
                    else
                    {
                        if (ctx.NotificationEmailAddresses.Any(x => x.Name == txtNameInsert.Text && x.Address == txtAddressInsert.Text))
                        {
                            lblInsertEmailMessage.Text = "A Notification Email already exists with this Name and Email Address.  Please enter a unique Name and Email Address.";
                        }
                        else if (ctx.NotificationEmailAddresses.Any(x => x.Name == txtNameInsert.Text))
                        {
                            lblInsertEmailMessage.Text = "A Notification Email already exists with this Name.  Please enter a unique Name.";
                        }
                        else if (ctx.NotificationEmailAddresses.Any(x => x.Address == txtAddressInsert.Text))
                        {
                            lblInsertEmailMessage.Text = "A Notification Email already exists with this Email Address.  Please enter a unique Email Address.";
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                lblInsertEmailMessage.Text = "Unable to add this Email Address.  Please contact your system administrator.";
            }
        }
        protected void gridInventoryNotificationList_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                var editableItem = ((GridEditableItem)e.Item);

                using (FormContext ctx = new FormContext())
                {
                    int recordId = Convert.ToInt32(editableItem.GetDataKeyValue("RecordId"));
                    InventoryNotificationEmails email = ctx.InventoryNotificationEmailAddresses.FirstOrDefault(x => x.RecordId == recordId);

                    if (email != null)
                    {
                        email.Name = ((RadTextBox)editableItem.FindControl("txtNameEdit")).Text;
                        email.Address = ((RadTextBox)editableItem.FindControl("txtAddressEdit")).Text;
                        email.Status = Convert.ToInt16(((RadioButtonList)editableItem.FindControl("rblStatusEdit")).SelectedValue);

                        ctx.SaveChanges();
                    }

                    gridInventoryNotificationList.Rebind();

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }