protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("~/login.aspx?return=Views/DepartmentHead/DEMO_ViewAllPending.aspx");
            }

            UserModel           user = new UserModel(User.Identity.Name);
            List <RequestModel> pendings;

            using (SSISEntities context = new SSISEntities())
            {
                pendings = FacadeFactory.getRequestService(context).getAllPendingRequestsOfDepartment(user.Department.dept_code).ToList();
            }
            if (pendings.Count > 0)
            {
                gvPendings.DataSource = pendings;
                gvPendings.DataBind();

                lblInfo.Text = pendings.Count + " requests.";
            }
            else
            {
                lblInfo.Text = "No pending requests.";
            }

            Session[SESSION_PENDINGS] = pendings;
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Hide buttons first
                panelApproval.Visible = false;

                string requestedStr = Request.QueryString["id"];
                int    requestId;
                if (requestedStr == null)
                {
                    return;
                }

                int.TryParse(requestedStr, out requestId);

                if (requestId == 0)
                {
                    return;
                }

                RequestModel request;

                using (SSISEntities context = new SSISEntities())
                {
                    request = FacadeFactory.getRequestService(context).findRequestById(requestId);

                    if (request == null)
                    {
                        lblInfo.Text = "Could not find that request";
                        return;
                    }
                }

                Session[SESSION_REQUEST_ID] = requestId;

                lblRequestId.Text    += requestedStr;
                lblEmployeeName.Text += request.Username;
                lblReason.Text       += request.Reason;
                lblInfo.Text          = "Status: " + request.Status;

                Dictionary <string, int> items = request.Items
                                                 .Where(w => w.Value > 0)
                                                 .ToDictionary(k => k.Key.Description, v => v.Value);

                if (request.Status == RequestStatus.PENDING || request.Status == RequestStatus.UPDATED)
                {
                    panelApproval.Visible = true;
                }

                gvItems.DataSource = items;
                gvItems.DataBind();
            }
        }
示例#3
0
        protected void btnReject_Click(object sender, EventArgs e)
        {
            using (SSISEntities context = new SSISEntities())
            {
                RequestModel request = FacadeFactory.getRequestService(context).findRequestById((int)Session[SESSION_REQUEST_ID]);
                FacadeFactory.getRequestService(context).rejectRequest(request, "Low Kway Boo");

                context.SaveChanges();
            }

            Response.Redirect("DEMO_ApproveRequest.aspx?id=" + (int)Session[SESSION_REQUEST_ID]);
        }
        protected void btnCancelRequest_Click(object sender, EventArgs e)
        {
            int    requestId = (int)Session[SESSION_REQ_EDIT_ID];
            string username  = User.Identity.Name;

            using (SSISEntities context = new SSISEntities())
            {
                FacadeFactory.getRequestService(context).setRequestToCancelled(requestId, username);
                context.SaveChanges();
            }

            Response.Redirect("EmpRequestHistory.aspx", false);
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = "Hello, World";
            RequestModel r = new RequestModel();

            using (SSISEntities context = new SSISEntities())
            {
                r = FacadeFactory.getRequestService(context).findRequestById(1);
            }

            Label1.Text = r.Items.Keys.First().ItemCode;

            ItemModel a = new ItemModel();
            ItemModel b = new ItemModel();

            Dictionary <ItemModel, int> cc = new Dictionary <ItemModel, int>();

            a.ItemCode = "happy";
            b.ItemCode = "happy";

            cc.Add(a, 0);

            Label2.Text = cc.ContainsKey(b).ToString();
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            _checkQtyRows();

            UserModel currentUserModel;

            List <MakeNewRequestModel> models = _getModelsFromSession();

            using (SSISEntities context = new SSISEntities())
            {
                currentUserModel = new UserModel(User.Identity.Name);

                Dictionary <string, int> items = new Dictionary <string, int>();
                foreach (var model in models)
                {
                    // If the user didn't add a quantity, just SKIP
                    if (model.Quantity == 0)
                    {
                        continue;
                    }

                    if (items.ContainsKey(model.CurrentItem))
                    {
                        int qty = items[model.CurrentItem];
                        items.Remove(model.CurrentItem);

                        items.Add(model.CurrentItem, model.Quantity + qty);
                    }
                    else
                    {
                        items.Add(model.CurrentItem, model.Quantity);
                    }
                }

                Dictionary <ItemModel, int> itemModels = new Dictionary <ItemModel, int>();
                foreach (var item in items)
                {
                    Stock_Inventory stock = context.Stock_Inventory.Find(item.Key);
                    ItemModel       im    = new ItemModel(stock);
                    itemModels.Add(im, item.Value);
                }

                UserModel    user   = (UserModel)Session[SESSION_USER_MODEL];
                RequestModel newReq = new RequestModel();
                newReq.Items      = itemModels;
                newReq.Reason     = tbReason.Text;
                newReq.Department = user.Department;
                newReq.Status     = RequestStatus.PENDING;
                newReq.UserModel  = user;

                bool isEditing = (Session[SESSION_IS_EDITING] as bool?).Value;

                if (isEditing)
                {
                    newReq.RequestId = (int)Session[SESSION_REQ_EDIT_ID];
                    FacadeFactory.getRequestService(context).updateRequestChanges(newReq);
                }
                else
                {
                    FacadeFactory.getRequestService(context).saveNewRequest(newReq);
                }

                context.SaveChanges();
            }

            /* Email logic */
            string    fromEmail = currentUserModel.Email;
            string    fromName  = currentUserModel.Fullname;
            UserModel deptHead  = currentUserModel.FindDelegateOrDeptHead();
            string    toEmail   = deptHead.Email;
            string    toName    = deptHead.Fullname;

            string        subject = string.Format("New pending request from {0}", fromName);
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine("Dear " + toName + ",");
            sb.AppendLine("<br />");
            sb.AppendLine("<br />");
            sb.AppendLine(string.Format("{0} has requested for some items, pending your approval.", fromName));
            sb.AppendLine("<br />");
            sb.AppendLine(string.Format("The request's reason is: {0}", tbReason.Text));
            sb.AppendLine("<br />");
            sb.AppendLine(string.Format("Please <a href=\"{0}\">follow this link to view the request</a>.", "https://rebrand.ly/ssis-mgr-viewpending"));
            sb.AppendLine("<br />");
            sb.AppendLine("<br />");
            sb.AppendLine("Thank you.");
            sb.AppendLine("<br />");
            sb.AppendLine("<br />");
            sb.AppendLine("<i>This message was auto-generated by the Stationery Store Inventory System.</i>");

            string body = sb.ToString();

            new Emailer(fromEmail, fromName).SendEmail(toEmail, toName, subject, body);
            /* End of email logic */

            //Response.Redirect(Request.Url.ToString(), false);
            Response.Redirect("EmpRequestHistory.aspx", false);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { // New entry into page
                // Check that user is not a d head or dlg head or whatever
                UserModel userModel = new UserModel(User.Identity.Name);
                if (userModel.isDelegateHead() || userModel.isDeptHead() || userModel.isStoreManager())
                {
                    Response.Redirect("~/Views/notauthorized.aspx");
                }

                int requestId = 0;
                // Get any request string
                string requestToEdit = Request.QueryString["edit"];
                int.TryParse(requestToEdit, out requestId); // 0 if fails

                //if (requestId > 0)
                //{
                //    lblPageTitle.Text = "Update Request (Id " + requestId + ")";
                //    isEditing = true;
                //}

                Session[SESSION_IS_EDITING] = false;

                List <MakeNewRequestModel> models = new List <MakeNewRequestModel>();
                using (SSISEntities context = new SSISEntities())
                {
                    List <Category> cats = context.Categories.Where(w => w.deleted != "Y").ToList();
                    Session[SESSION_CATEGORIES] = cats;
                    List <Stock_Inventory> stocks = context.Stock_Inventory.Where(w => w.deleted != "Y").ToList();
                    Session[SESSION_STOCKS] = stocks;
                    RequestModelCollection requests;

                    /*
                     * if (!User.Identity.IsAuthenticated)
                     * {
                     *  Response.Redirect("~/login.aspx?return=Views/StoreClerk/MakeNewRequest.aspx");
                     * }*/

                    UserModel currentUser = new UserModel(User.Identity.Name);
                    //UserModel currentUser = new UserModel("Sally");
                    try
                    {
                        string deptCode = currentUser.Department.dept_code;
                        requests = FacadeFactory.getRequestService(context).getAllApprovedRequests()
                                   .fromDepartment(deptCode);
                    }
                    catch (ItemNotFoundException)
                    {
                        requests = null;
                    }

                    Session[SESSION_USER_MODEL]    = currentUser;
                    Session[SESSION_APPROVED_REQS] = requests;

                    if (requestId == 0)
                    { // Making a new request
                        MakeNewRequestModel model = _makeNewModel(0);
                        models.Add(model);

                        panelCannotChange.Visible = false;
                        panelNormalBtns.Visible   = true;
                        btnCancelRequest.Visible  = false;
                    }
                    else
                    {
                        Request found = context.Requests.Find(requestId);
                        // Set to cannot update first
                        panelCannotChange.Visible = true;
                        panelNormalBtns.Visible   = false;
                        string reason = "";
                        if (found == null)
                        {
                            reason = "That request could not be found.";
                        }
                        else if (found.username != currentUser.Username)
                        {
                            reason = "You did not make this request.";
                        }
                        else if (found.current_status != RequestStatus.PENDING && found.current_status != RequestStatus.UPDATED)
                        {
                            // status is neither pending nor updated
                            switch (found.current_status)
                            {
                            case RequestStatus.CANCELLED:
                                reason = "The request was cancelled.";
                                break;

                            case RequestStatus.REJECTED:
                                reason = "The request was already rejected.";
                                break;

                            default:     // Approved or others
                                reason = "The request was already approved.";
                                break;
                            }
                        }
                        else
                        {
                            // Request can be updated
                            panelCannotChange.Visible = false;
                            panelNormalBtns.Visible   = true;
                            btnCancelRequest.Visible  = true;

                            RequestModel rModel = FacadeFactory.getRequestService(context).findRequestById(requestId);

                            tbReason.Text = rModel.Reason;

                            int numIter = 0;
                            foreach (var item in rModel.Items)
                            {
                                if (item.Value == 0)
                                {
                                    continue;
                                }
                                MakeNewRequestModel model = _makeNewModel(numIter, item.Key.Category.cat_id, item.Key.ItemCode, item.Value);
                                models.Add(model);
                                numIter++;
                            }

                            lblPageTitle.Text = "Update Request (Id " + requestId + ")";

                            //isEditing = true;
                            Session[SESSION_IS_EDITING]  = true;
                            Session[SESSION_REQ_EDIT_ID] = requestId;
                            btnSubmit.Text = "Save Changes";
                        }

                        lblCannotChangeInfo.Text = reason;
                    }
                }

                Session[SESSION_MODELS] = models;
                _refreshGrid(models);
            } // end of isPostBack
        }