Пример #1
0
 //For customer after enter information
 public int LoginOrderProduct(FormCollection f)
 {
     try
     {
         AccountBusiness ab = new AccountBusiness();
         CustomerOrderBusiness cob = new CustomerOrderBusiness();
         if (Session["Cart"] == null)
         {
             return -4;
         }
         List<CustomerCartViewModel> cart = GetCart();
         string orderTime = DateTime.Now.ToString("yyyyMMdd");
         int amount = Convert.ToInt32(Session["Amount"]);
         int taxAmount = Convert.ToInt32(Session["TaxAmount"]);
         int discount = Convert.ToInt32(Session["DiscountAmount"]);
         string sAccount = f.Get("txtAccount").ToString();
         string sPassword = f.Get("txtPassword").ToString();
         User endUser = ab.checkLogin(sAccount, sPassword);
         if (endUser != null)
         {
             int checkRole = endUser.RoleId;
             if (checkRole != 3)
             {
                 TempData["Notify"] = "Tài khoản không hợp lệ";
                 return -2;
             }
             Session["User"] = endUser;
             Session["UserId"] = endUser.UserId;
             Session["CusUserId"] = endUser.Customers.ElementAt(0).CustomerId;
             TempData["userName"] = endUser.Username.ToString();
             Session["Phonenumber"] = endUser.Customers.ElementAt(0).CustomerPhoneNumber.ToString();
         }
         else
         {
             TempData["Notify"] = "Sai tài khoản hoặc mật khẩu";
             return -3;
         }
         int cusUserId = Convert.ToInt32(Session["UserId"]);
         DateTime planDeliveryDate = DateTime.ParseExact(Session["DeliveryDate"].ToString(), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture);
         string Note = Session["Note"].ToString();
         cob.OrderProduct(orderTime, planDeliveryDate, amount, taxAmount, discount, cusUserId, cart, Note);
         TempData["orderCode"] = cob.GetOrderCode();
         Session["Cart"] = null;
         Session["Amount"] = null;
         Session["TaxAmount"] = null;
         Session["DiscountAmount"] = null;
         Session["Note"] = null;
         return 1;
     }
     catch
     {
         return -5;
     }
 }
Пример #2
0
        public int Login(FormCollection f, string strURL)
        {
            AccountBusiness ab = new AccountBusiness();
            try
            {
                string sAccount = f.Get("txtAccount");
                string sPassword = f.Get("txtPassword");
                User endUser = ab.checkLogin(sAccount, sPassword);
                if (endUser == null)
                {
                    return -1;
                }
                if (!endUser.IsConfirmed)
                {
                    ab.ConfirmAccount(endUser.UserId);
                }
                if (endUser.RoleId == 3)
                {
                    if (!endUser.Customers.ElementAt(0).IsActive)
                    {
                        return -2;
                    }
                    Session["User"] = endUser;
                    Session["UserId"] = endUser.UserId;
                    Session["CusUserId"] = endUser.Customers.ElementAt(0).CustomerId;
                    Session["Phonenumber"] = endUser.Customers.ElementAt(0).CustomerPhoneNumber;

                    //Check customer off notifier
                    List<Order> lstNewOrderNoty = ab.CustomerOffNewOrderNoty((int)Session["UserId"]);
                    List<Order> lstEditedOrderNoty = ab.CustomerOffEditedOrderNoty((int)Session["UserId"]);
                    List<Order> lstConfirmOrderNoty = ab.CustomerOffConfirmOrderNoty((int)Session["UserId"]);
                    if (lstNewOrderNoty != null)
                    {
                        Session["CusNewOrderCountPartial"] = Session["CusNotificateCount"] = lstNewOrderNoty.Count;
                        if (lstEditedOrderNoty != null)
                        {
                            Session["CusEditOrderCountPartial"] = lstEditedOrderNoty.Count;
                            Session["CusNotificateCount"] = lstNewOrderNoty.Count + lstEditedOrderNoty.Count;
                            if (lstConfirmOrderNoty != null)
                            {
                                Session["CusConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count;
                                Session["CusNotificateCount"] = lstNewOrderNoty.Count + lstEditedOrderNoty.Count + lstConfirmOrderNoty.Count;
                            }
                        }
                        else
                        {
                            if (lstConfirmOrderNoty != null)
                            {
                                Session["CusConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count;
                                Session["CusNotificateCount"] = lstNewOrderNoty.Count + lstConfirmOrderNoty.Count;
                            }
                        }
                    }
                    else
                    {
                        if (lstEditedOrderNoty != null)
                        {
                            Session["CusEditOrderCountPartial"] = Session["CusNotificateCount"] = lstEditedOrderNoty.Count;
                            if (lstConfirmOrderNoty != null)
                            {
                                Session["CusConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count;
                                Session["CusNotificateCount"] = lstEditedOrderNoty.Count + lstConfirmOrderNoty.Count;
                            }
                        }
                        else
                        {
                            if (lstConfirmOrderNoty != null)
                            {
                                Session["CusConfirmOrderCountPartial"] = Session["CusNotificateCount"] = lstConfirmOrderNoty.Count;
                            }
                        }
                    }

                    //Open connection with this Customer
                    string dependencyCheckSql = string.Format("{0}{1}", "SELECT OrderStatus FROM dbo.[Orders] WHERE CustomerUserId=", endUser.UserId);
                    Session["CheckToNotify"] = endUser.UserId;
                    MvcApplication.changeStatusNotifer.Start("BMAChangeDB", dependencyCheckSql);
                    MvcApplication.changeStatusNotifer.Change += this.OnChange3;
                    return 1;
                }
                else
                {
                    if (endUser.RoleId == 2)
                    {
                        if (!endUser.Staffs.ElementAt(0).IsActive)
                        {
                            return -2;
                        }

                        MvcApplication.notifier.Dispose();
                        MvcApplication.notifier.Start("BMAChangeDB", "SELECT OrderId FROM dbo.[Orders]");
                        MvcApplication.notifier.Change += this.OnChange;

                        MvcApplication.lowQuantityNotifer.Dispose();
                        MvcApplication.lowQuantityNotifer.Start("BMAChangeDB", "SELECT ProductMaterialId,CurrentQuantity,StandardQuantity FROM dbo.[ProductMaterial] WHERE (CurrentQuantity < StandardQuantity AND IsActive = 'True')");
                        MvcApplication.lowQuantityNotifer.Change += this.OnChange2;

                        //Check staff off notifier
                        List<Order> lstNewOrderNoty = ab.StaffOffNewOrderNoty();
                        List<Order> lstConfirmOrderNoty = ab.StaffOffConfirmOrderNoty();
                        List<Order> lstCancelOrderNoty = ab.StaffOffCancelOrderNoty();
                        List<ProductMaterial> lstLowQuantityNoty = ab.StaffOffLowQuantityNoty();

                        if (lstNewOrderNoty != null)
                        {
                            Session["NewOrderCountPartial"] = Session["NotificateCount"] = lstNewOrderNoty.Count;
                            if (lstConfirmOrderNoty != null)
                            {
                                Session["ConfirmOrderCountPartial"] = lstConfirmOrderNoty.Count;
                                Session["NotificateCount"] = lstConfirmOrderNoty.Count + lstNewOrderNoty.Count;
                                if (lstCancelOrderNoty != null)
                                {
                                    Session["CancelOrderCountPartial"] = lstCancelOrderNoty.Count;
                                    Session["NotificateCount"] = lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count + lstNewOrderNoty.Count;
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count + lstNewOrderNoty.Count;
                                    }
                                }
                                else
                                {
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstConfirmOrderNoty.Count + lstNewOrderNoty.Count;
                                    }
                                }
                            }
                            else
                            {
                                if (lstCancelOrderNoty != null)
                                {
                                    Session["CancelOrderCountPartial"] = lstCancelOrderNoty.Count;
                                    Session["NotificateCount"] = lstCancelOrderNoty.Count + lstNewOrderNoty.Count;
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count + lstNewOrderNoty.Count;
                                    }
                                }
                                else
                                {
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstNewOrderNoty.Count;
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (lstConfirmOrderNoty != null)
                            {
                                Session["ConfirmOrderCountPartial"] = Session["NotificateCount"] = lstConfirmOrderNoty.Count;
                                if (lstCancelOrderNoty != null)
                                {
                                    Session["CancelOrderCountPartial"] = lstCancelOrderNoty.Count;
                                    Session["NotificateCount"] = lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count;
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count + lstConfirmOrderNoty.Count;
                                    }
                                }
                                else
                                {
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstConfirmOrderNoty.Count;
                                    }
                                }
                            }
                            else
                            {
                                if (lstCancelOrderNoty != null)
                                {
                                    Session["CancelOrderCountPartial"] = Session["NotificateCount"] = lstCancelOrderNoty.Count;
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = lstLowQuantityNoty.Count;
                                        Session["NotificateCount"] = lstLowQuantityNoty.Count + lstCancelOrderNoty.Count;
                                    }
                                }
                                else
                                {
                                    if (lstLowQuantityNoty != null)
                                    {
                                        Session["LowMaterialCountPartial"] = Session["NotificateCount"] = lstLowQuantityNoty.Count;
                                    }
                                }
                            }
                        }

                    }
                    Session["User"] = endUser;
                    Session["UserId"] = endUser.UserId;
                    Session["UserRole"] = endUser.Role.RoleId;
                    return 2;
                }
            }
            catch
            {
                return -1;
            }
        }