예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            using (SSISEntities context = new SSISEntities())
            {
                List <Collection_Point> collectionPts  = context.Collection_Point.Where(w => w.deleted != "Y").ToList();
                List <Department>       departmentList = context.Departments.Where(w => w.deleted != "Y").ToList();

                Session[SESSION_DEPARTMENT_LIST] = departmentList;

                if (collectionPts.Count == 0)
                {
                    return;
                }

                // If the user is tagged to a collection point, add it into the location name
                string currentUser = User.Identity.Name;

                int currentCollectionPtId = collectionPts.First().collection_pt_id;
                // Get the department codes that are related to this value
                List <Department> departments = departmentList.Where(w => w.collection_point == currentCollectionPtId).ToList();

                // Get all that can be disbursed given the current user
                DisbursementModelCollection disbursingList = FacadeFactory.getDisbursementService(context).getAllThatCanBeSignedOff(currentUser);

                //Session[SESSION_DISBURSING_LIST] = disbursingList;

                string currentDepartmentCode = departments.First().dept_code;

                var itemGroups = disbursingList.SelectMany(sm =>
                                                           sm.Items
                                                           .Select(s => new { s.Key.ItemCode, s.Key.Description, Quantity = s.Value, sm.Department.dept_code, sm.RequestId, sm.Department.name, sm.CollectionPtId })
                                                           ).GroupBy(k => new { k.ItemCode, k.Description, DeptCode = k.dept_code }, v => v).ToList();

                /* Filter active collection points */
                List <int> activeCollectionPoints = itemGroups.SelectMany(sm => sm.Select(s => s.CollectionPtId)).Distinct().ToList();

                foreach (var collectionPt in collectionPts)
                {
                    if (collectionPt.username == currentUser)
                    {
                        collectionPt.location += " [Assigned to you]";
                    }
                    if (!activeCollectionPoints.Contains(collectionPt.collection_pt_id))
                    {
                        collectionPt.location += " (Empty)";
                    }
                }

                ddlCollectionPoints.DataSource     = collectionPts;
                ddlCollectionPoints.DataValueField = "collection_pt_id";
                ddlCollectionPoints.DataTextField  = "location";
                ddlCollectionPoints.DataBind();

                List <ConfirmDisbursementViewModel> list = new List <ConfirmDisbursementViewModel>();

                foreach (var itemGroup in itemGroups)
                {
                    int        itemQty = itemGroup.Select(s => s.Quantity).Aggregate((a, b) => a + b);
                    List <int> reqIds  = itemGroup.Select(s => s.RequestId).ToList();

                    ConfirmDisbursementViewModel model = new ConfirmDisbursementViewModel();
                    model.ItemCode        = itemGroup.Key.ItemCode;
                    model.ItemDescription = itemGroup.Key.Description;
                    model.DeptCode        = itemGroup.Key.DeptCode;
                    //model.DeptName = deptGroup.First().name;
                    model.QuantityExpected = itemQty;
                    model.QuantityActual   = itemQty;
                    model.RequestIds       = reqIds;
                    //model.Include = true;

                    list.Add(model);
                }

                Session[SESSION_DISBURSING_LIST] = list;

                list = list.Where(w => w.DeptCode == currentDepartmentCode).ToList();

                //_refreshGrid(list);

                lblNoDepartments.Visible = false;

                _refrehDepartmentsDropDown(departments);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            panelNoItems.Visible = false;
            panelNormal.Visible  = false;

            string forwardedDeptCode = Request.QueryString["dept"];

            using (SSISEntities context = new SSISEntities())
            {
                //List<Collection_Point> collectionPts = context.Collection_Point.Where(w => w.deleted != "Y").ToList();
                List <Department>       departmentList   = context.Departments.Where(w => w.deleted != "Y").ToList();
                List <Collection_Point> collectionPtList = context.Collection_Point.Where(w => w.deleted != "Y").ToList();
                List <Dept_Registry>    usersList        = context.Dept_Registry.Where(w => w.deleted != "Y").ToList();

                Session[SESSION_DEPARTMENT_LIST]    = departmentList;
                Session[SESSION_COLLECTION_PT_LIST] = collectionPtList;
                Session[SESSION_USER_LIST]          = usersList;

                string currentUser = User.Identity.Name;

                // Get all that can be disbursed given the current user
                DisbursementModelCollection disbursingList = FacadeFactory.getDisbursementService(context).getAllThatCanBeSignedOff(currentUser);

                //Session[SESSION_DISBURSING_LIST] = disbursingList;

                var itemGroups = disbursingList.SelectMany(sm =>
                                                           sm.Items
                                                           .Select(s => new { s.Key.ItemCode, s.Key.Description, Quantity = s.Value, sm.Department.dept_code, sm.RequestId, sm.Department.name })
                                                           ).GroupBy(k => new { k.ItemCode, k.Description, DeptCode = k.dept_code }, v => v).ToList();

                List <ConfirmDisbursementViewModel> filteredDisbursingList = new List <ConfirmDisbursementViewModel>();

                foreach (var itemGroup in itemGroups)
                {
                    int        itemQty = itemGroup.Select(s => s.Quantity).Where(w => w > 0).Aggregate((a, b) => a + b);
                    List <int> reqIds  = itemGroup.Select(s => s.RequestId).ToList();

                    ConfirmDisbursementViewModel model = new ConfirmDisbursementViewModel();
                    model.ItemCode        = itemGroup.Key.ItemCode;
                    model.ItemDescription = itemGroup.Key.Description;
                    model.DeptCode        = itemGroup.Key.DeptCode;
                    //model.DeptName = deptGroup.First().name;
                    model.QuantityExpected = itemQty;
                    model.QuantityActual   = itemQty;
                    model.RequestIds       = reqIds;
                    //model.Include = true;

                    filteredDisbursingList.Add(model);
                }

                string currentDepartmentCode = departmentList.First().dept_code;

                if (forwardedDeptCode != null)
                {
                    // Forwarded from View Generated forms
                    currentDepartmentCode = forwardedDeptCode;
                }

                // Mark empty departments
                List <string> deptCodes = filteredDisbursingList.Select(s => s.DeptCode).ToList();

                foreach (var dept in departmentList)
                {
                    // If the dept does not have disbursements:
                    if (!deptCodes.Contains(dept.dept_code))
                    {
                        dept.name += " (empty)";
                    }
                }


                Session[SESSION_DISBURSING_LIST]   = filteredDisbursingList;
                Session[SESSION_CURRENT_DEPT_CODE] = currentDepartmentCode;

                //filteredDisbursingList = filteredDisbursingList.Where(w => w.DeptCode == currentDepartmentCode).ToList();

                _refreshDepartmentsDropDown(departmentList);

                _refreshGrid(filteredDisbursingList);

                ddlDepartments.SelectedValue = currentDepartmentCode;

                if (departmentList.Count == 0 || disbursingList.Count == 0)
                {
                    panelNoItems.Visible = true;
                }
                else
                {
                    panelNormal.Visible = true;
                }
            }
        }