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; } }