Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["hdnNumberPerPage"] != "" && Request.QueryString["hdnNumberPerPage"] != null)
            {
                hdnNumberPerPage.Value = Request.QueryString["hdnNumberPerPage"].ToString();
            }
            if (Request.QueryString["hdnCurrentPageNo"] != "" && Request.QueryString["hdnCurrentPageNo"] != null)
            {
                hdnCurrentPageNo.Value = Request.QueryString["hdnCurrentPageNo"].ToString();
            }
            if (Request.QueryString["hdnTotalRecordsCount"] != "" && Request.QueryString["hdnTotalRecordsCount"] != null)
            {
                hdnTotalRecordsCount.Value = Request.QueryString["hdnTotalRecordsCount"].ToString();
            }

            StringBuilder filter = new StringBuilder();

            filter.Append(" 1=1 ");

            if (Request.QueryString["IsNewSearch"] != "" && Request.QueryString["IsNewSearch"] != null)
            {
                IsNewSearch.Value = Request.QueryString["IsNewSearch"].ToString();
            }
            if (IsNewSearch.Value == "1")
            {
                hdnCurrentPageNo.Value = "";
            }
            if (Request.QueryString["Search"] != "" && Request.QueryString["Search"] != null)
            {
                Search.Value = Request.QueryString["Search"].ToString();
                string columnNameName = Converter.GetColumnNameByPropertyName <Branch>(nameof(Silverlake.Utility.Branch.Name));
                filter.Append(" and " + columnNameName + " like '%" + Search.Value + "%'");
                string columnNameCode = Converter.GetColumnNameByPropertyName <Branch>(nameof(Silverlake.Utility.Branch.Code));
                filter.Append(" or " + columnNameCode + " like '%" + Search.Value + "%'");
            }


            int skip = 0, take = 10;

            if (hdnCurrentPageNo.Value == "")
            {
                skip = 0;
                take = 10;
                hdnNumberPerPage.Value     = "10";
                hdnCurrentPageNo.Value     = "1";
                hdnTotalRecordsCount.Value = IBranchService.GetCountByFilter(filter.ToString()).ToString();
            }
            else
            {
                skip = (Convert.ToInt32(hdnCurrentPageNo.Value) - 1) * 10;
                take = 10;
            }

            List <Branch> objs = IBranchService.GetDataByFilter(filter.ToString(), skip, take, false);

            List <Department> departments = IDepartmentService.GetData(0, 0, false);

            StringBuilder asb   = new StringBuilder();
            int           index = 1;

            foreach (Branch obj in objs)
            {
                StringBuilder           departmentsHTML   = new StringBuilder();
                List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByPropertyName(nameof(BranchDepartment.BranchId), obj.Id.ToString(), true, 0, 0, false);
                bool isSelectAllChecked = obj.IsAll == 1 ? true : false;
                departmentsHTML.Append(@"
                    <label class='icheck'>
                        <div class='flat-blue single-row'>
                            <div class='checkbox'>
                                <input type='checkbox' name='checkRow' class='checkRow selectAll' value='' " + (isSelectAllChecked ? "checked" : "") + @"/> <label>Select All</label><br/>
                            </div>
                        </div>
                    </label>
                ");
                foreach (Department d in departments)
                {
                    bool isChecked = false;
                    if (isSelectAllChecked)
                    {
                        isChecked = true;
                    }
                    else if (branchDepartments.Count > 0)
                    {
                        BranchDepartment bd = branchDepartments.Where(x => x.DepartmentId == d.Id && x.Status == 1).FirstOrDefault();
                        if (bd == null)
                        {
                            isChecked = true;
                        }
                    }
                    departmentsHTML.Append(@"
                        <label class='icheck'>
                            <div class='flat-green single-row'>
                                <div class='checkbox'>
                                    <input type='checkbox' name='checkRow' class='checkRow' value='" + d.Id + @"' " + (isChecked ? "checked" : "") + @"/> <label>" + d.Code + @"</label><br/>
                                </div>
                            </div>
                        </label>
                    ");
                }
                Company company = ICompanyService.GetSingle(obj.CompanyId);
                asb.Append(@"<tr>
                                <td class='icheck'>
                                    <div class='square single-row'>
                                        <div class='checkbox'>
                                            <input type='checkbox' name='checkRow' class='checkRow' value='" + obj.Id + @"' /> <label>" + index + @"</label><br/>
                                        </div>
                                    </div>
                                    <span class='row-status'>" + (obj.Status == 1 ? "<span class='label label-success'>Active</span>" : "<span class='label label-danger'>Inactive</span>") + @"</span>
                                </td>
                                <td><strong>" + obj.Code + "</strong><br/>" + obj.Name + @"</td>
                                <td style='width: 300px;'>
                                    " + departmentsHTML.ToString() + @"
                                </td>
                                <td>" + obj.CreatedDate.ToString("dd/MM/yyyy") + @"</td>
                                <td>" + (obj.UpdatedDate == null ? "-" : obj.UpdatedDate.Value.ToString("dd/MM/yyyy")) + @"</td>
                            </tr>");
                index++;
            }
            branchesTBody.InnerHtml = asb.ToString();
        }
Beispiel #2
0
        public static object UpdateDepartments(List <IdDepartments> allObjs)
        {
            Int32 LoginUserId = 0;

            if (HttpContext.Current.Session["UserId"] != null)
            {
                LoginUserId = Convert.ToInt32(HttpContext.Current.Session["UserId"].ToString());
            }
            foreach (IdDepartments bds in allObjs)
            {
                int    branchId = bds.Id;
                Branch branch   = IBranchService.GetSingle(branchId);
                if (bds.isSelectAll)
                {
                    branch.IsAll       = 1;
                    branch.UpdatedDate = DateTime.Now;
                    branch.UpdatedBy   = LoginUserId;
                    IBranchService.UpdateData(branch);

                    List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByPropertyName(nameof(BranchDepartment.BranchId), branchId.ToString(), true, 0, 0, false);
                    branchDepartments.ForEach(x =>
                    {
                        x.UpdatedBy   = LoginUserId;
                        x.UpdatedDate = DateTime.Now;
                        x.Status      = 0;
                    });
                    IBranchDepartmentService.UpdateBulkData(branchDepartments);
                }
                else
                {
                    //List<Department> departments = IDepartmentService.GetData(0, 0, false);
                    List <BranchDepartment> branchDepartments = IBranchDepartmentService.GetDataByPropertyName(nameof(BranchDepartment.BranchId), branchId.ToString(), true, 0, 0, false);

                    foreach (BranchDepartment bd in branchDepartments)
                    {
                        int?deptId = bds.DepartmentIds.Where(x => x == bd.DepartmentId).FirstOrDefault();
                        if (deptId == 0)
                        {
                            BranchDepartment bdNew = bd;
                            bd.Status      = 0;
                            bd.UpdatedBy   = LoginUserId;
                            bd.UpdatedDate = DateTime.Now;
                            IBranchDepartmentService.UpdateData(bd);
                        }
                        else
                        {
                            BranchDepartment bdNew = bd;
                            bd.Status      = 1;
                            bd.UpdatedBy   = LoginUserId;
                            bd.UpdatedDate = DateTime.Now;
                            IBranchDepartmentService.UpdateData(bd);
                        }
                    }

                    foreach (int departmentId in bds.DepartmentIds)
                    {
                        BranchDepartment bd = branchDepartments.Where(x => x.DepartmentId == departmentId).FirstOrDefault();
                        if (bd == null)
                        {
                            bd = new BranchDepartment
                            {
                                BranchId     = branchId,
                                DepartmentId = departmentId,
                                CreatedBy    = LoginUserId,
                                CreatedDate  = DateTime.Now,
                                UpdatedBy    = LoginUserId,
                                UpdatedDate  = DateTime.Now,
                                Status       = 1
                            };
                            IBranchDepartmentService.PostData(bd);
                        }
                        else
                        {
                            if (bd.Status == 0)
                            {
                                bd.Status      = 1;
                                bd.UpdatedBy   = LoginUserId;
                                bd.UpdatedDate = DateTime.Now;
                                IBranchDepartmentService.UpdateData(bd);
                            }
                        }
                    }

                    branch.IsAll       = 0;
                    branch.UpdatedDate = DateTime.Now;
                    branch.UpdatedBy   = LoginUserId;
                    IBranchService.UpdateData(branch);
                }
            }
            return(true);
        }