Пример #1
0
    private void BindGrid()
    {
        int orderID;

        if (Request.QueryString["OrderID"] == null)
        {
            Response.Redirect(LoginController.PurchaseOrderListURI);
        }
        else
        {
            orderID = Convert.ToInt32(Request.QueryString["OrderID"]);
            pOrder  = pCtrlr.GetPurchaseOrderByID(orderID);
            orderid = pOrder.PurchaseOrderID;
            lblsupervisorName.Text = pOrder.Employee.EmpName;
            lblSupplierName.Text   = pOrder.Supplier.SupplierName;
            lblOrderID.Text        = Convert.ToString(pOrder.PurchaseOrderID);
            lblorderStatus.Text    = pOrder.Status;
            if (pOrder.Status == "Pending")
            {
                lblorderStatus.ForeColor = System.Drawing.Color.Blue;
            }
            else if (pOrder.Status == "Approved")
            {
                lblorderStatus.ForeColor = System.Drawing.Color.Green;
            }
            else if (pOrder.Status == "Rejected")
            {
                lblorderStatus.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                lblorderStatus.ForeColor = System.Drawing.Color.Black;
            }
            List <PurchaseOrderItemDetails> itemList = pCtrlr.GetPurchaseOrderItemsDetails(orderID);
            GvPurchaseDetail.DataSource = itemList;
            GvPurchaseDetail.DataBind();

            decimal?totAmnt = 0;
            foreach (PurchaseOrderItemDetails item in itemList)
            {
                totAmnt += item.Price * item.OrderQty;
            }
            lblTotalAmount.Text = String.Format("{0:C}", totAmnt);
            foreach (GridViewRow row in GvPurchaseDetail.Rows)
            {
                if (Session["emp"] != null)
                {
                    if (Session["empRole"].ToString() == "Store Clerk")
                    {
                        Employee emp = (Employee)Session["emp"];
                        if (emp.EmpID == pOrder.RequestedBy)
                        {
                            if (pOrder.Status == "Closed" || pOrder.Status == "Rejected")
                            {
                                lbldelivery.Visible                 = false;
                                txtDeliveryOrderID.Visible          = false;
                                BtnCloseOrder.Visible               = false;
                                BtnReject.Visible                   = false;
                                GvPurchaseDetail.Columns[5].Visible = false;
                            }
                            else if (pOrder.Status == "Approved")
                            {
                                lbldelivery.Visible                 = true;
                                txtDeliveryOrderID.Visible          = true;
                                BtnCloseOrder.Visible               = true;
                                GvPurchaseDetail.Columns[5].Visible = true;
                            }
                            else if (pOrder.Status == "Pending")
                            {
                                lbldelivery.Visible                 = false;
                                txtDeliveryOrderID.Visible          = false;
                                BtnCloseOrder.Visible               = false;
                                GvPurchaseDetail.Columns[5].Visible = true;
                            }
                        }
                        else
                        {
                            if (pOrder.Status == "Closed" || pOrder.Status == "Rejected" || pOrder.Status == "Approved" || pOrder.Status == "Pending")
                            {
                                lbldelivery.Visible                 = false;
                                txtDeliveryOrderID.Visible          = false;
                                BtnCloseOrder.Visible               = false;
                                BtnReject.Visible                   = false;
                                GvPurchaseDetail.Columns[5].Visible = false;
                            }
                        }
                        lblRemark.Visible  = false;
                        txtRemark.Visible  = false;
                        BtnApprove.Visible = false;
                        BtnReject.Visible  = false;
                    }
                    else if (Session["empRole"].ToString() == "Store Supervisor" || Session["empRole"].ToString() == "Store Manager")
                    {
                        if (pOrder.Status == "Closed" || pOrder.Status == "Rejected" || pOrder.Status == "Approved")
                        {
                            lblRemark.Visible  = false;
                            txtRemark.Visible  = false;
                            BtnApprove.Visible = false;
                            BtnReject.Visible  = false;
                        }
                        else
                        {
                            lblRemark.Visible  = true;
                            txtRemark.Visible  = true;
                            BtnApprove.Visible = true;
                            BtnReject.Visible  = true;
                        }
                        GvPurchaseDetail.Columns[5].Visible = false;
                        lbldelivery.Visible        = false;
                        txtDeliveryOrderID.Visible = false;
                        BtnCloseOrder.Visible      = false;
                    }
                }
            }
        }
    }