Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string SearchText = string.Empty;
            int departmentId = 0;

            if (!string.IsNullOrEmpty(Request.QueryString["DepartmentId"]) && int.TryParse(Request.QueryString["DepartmentId"], out int n))
            {
                departmentId = Convert.ToInt32(Request.QueryString["DepartmentId"]);
            }
            //if (!string.IsNullOrEmpty(Request.QueryString["DocType"]))
            //    DocType.SelectedValue = Request.QueryString["DocType"];

            if (departmentId != 0 || !string.IsNullOrEmpty(Request.QueryString["DocType"]) || !string.IsNullOrEmpty(Request.QueryString["Search"]))
            {
                List <DocTypeSetModel> list = ISetService.GetSetsForMfilesAccount(departmentId, Request.QueryString["DocType"].ToString(), Request.QueryString["Search"].ToString(), 0, 0);
                if (list != null && list.Count != 0)
                {
                    StringBuilder asb   = new StringBuilder();
                    int           index = 1;
                    ExcelPackage  pck   = new ExcelPackage();

                    var ws = pck.Workbook.Worksheets.Add("Sample1");

                    ws.Cells["A" + index].Value = "S.No";
                    ws.Cells["B" + index].Value = "Branch";
                    ws.Cells["C" + index].Value = "Batch No";
                    ws.Cells["D" + index].Value = "Department";
                    ws.Cells["E" + index].Value = "Document Type";
                    ws.Cells["F" + index].Value = "AA NO/Project Code/Welfare Code";
                    ws.Cells["G" + index].Value = "Acount NO";
                    ws.Cells["H" + index].Value = "Total Pages";
                    ws.Cells["I" + index].Value = "Status";
                    ws.Cells["J" + index].Value = "User";
                    ws.Cells["K" + index].Value = "Created On";
                    ws.Cells["L" + index].Value = "Updated On";
                    index++;
                    int i = 1;
                    List <Department> departmentList = IDepartmentService.GetData(0, 0, false);
                    List <Branch>     branchList     = IBranchService.GetData(0, 0, false);
                    foreach (DocTypeSetModel set in list)
                    {
                        Department department = departmentList.FirstOrDefault(a => a.Id == set.DepartmentId);
                        ws.Cells["A" + index].Value = i;
                        ws.Cells["B" + index].Value = branchList.Count(a => a.Id == set.BatchId) != 0 ? branchList.FirstOrDefault(a => a.Id == set.BatchId).Code : "";
                        ws.Cells["C" + index].Value = set.BatchNo;
                        ws.Cells["D" + index].Value = departmentList.Count(a => a.Id == set.DepartmentId) != 0 ? departmentList.FirstOrDefault(a => a.Id == set.DepartmentId).Code : "";
                        ws.Cells["E" + index].Value = set.DocType;
                        ws.Cells["F" + index].Value = set.AANO;
                        ws.Cells["G" + index].Value = set.AccountNo;
                        ws.Cells["H" + index].Value = set.PageCount;
                        ws.Cells["I" + index].Value = MfileStatus(set.IsReleased);
                        ws.Cells["J" + index].Value = set.BatchUser;
                        ws.Cells["K" + index].Value = set.CreatedDate.ToString("dd/MM/yyyy HH:mm:ss");
                        ws.Cells["L" + index].Value = set.CreatedDate.ToString("dd/MM/yyyy HH:mm:ss");
                        i++;
                        index++;
                    }
                    pck.SaveAs(Response.OutputStream);
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", "attachment;  filename=Sample1.xlsx");
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);

                    Response.End();
                }
            }
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string SearchText = string.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["IsNewSearch"]))
            {
                IsNewSearch.Value = Request.QueryString["IsNewSearch"].ToString();
            }

            divError.Visible  = false;
            divResult.Visible = false;
            int departmentId = 0;
            List <Department> departmentList = IDepartmentService.GetData(0, 0, false);

            DepartmentId.DataSource     = departmentList;
            DepartmentId.DataTextField  = "Name";
            DepartmentId.DataValueField = "Id";
            DepartmentId.DataBind();
            DepartmentId.Items.Insert(0, new ListItem()
            {
                Text = "Select Department", Value = ""
            });
            DocType.Items.Insert(0, new ListItem()
            {
                Text = "Select Doc Type", Value = ""
            });
            if (!string.IsNullOrEmpty(Request.QueryString["DepartmentId"]) && int.TryParse(Request.QueryString["DepartmentId"], out int n))
            {
                DepartmentId.SelectedValue = Request.QueryString["DepartmentId"];
                departmentId = Convert.ToInt32(Request.QueryString["DepartmentId"]);
                List <DocTypeModel> docTypes = IDepartmentService.GetDocTypesByDepartmentId(departmentId);
                DocType.DataSource     = docTypes;
                DocType.DataTextField  = "DocType";
                DocType.DataValueField = "DocType";
                DocType.DataBind();
                if (!string.IsNullOrEmpty(Request.QueryString["DocType"]))
                {
                    DocType.SelectedValue = Request.QueryString["DocType"];
                }
            }
            else
            {
            }
            //if (!string.IsNullOrEmpty(Request.QueryString["DocType"]))
            //    DocType.SelectedValue = Request.QueryString["DocType"];

            if (departmentId != 0 || !string.IsNullOrEmpty(Request.QueryString["DocType"]) || !string.IsNullOrEmpty(Request.QueryString["Search"]))
            {
                if (!string.IsNullOrEmpty(Request.QueryString["Search"]))
                {
                    Search.Value = Request.QueryString["Search"];
                }

                if (!string.IsNullOrEmpty(Request.QueryString["hdnNumberPerPage"]))
                {
                    hdnNumberPerPage.Value = Request.QueryString["hdnNumberPerPage"].ToString();
                }

                if (!string.IsNullOrEmpty(Request.QueryString["hdnCurrentPageNo"]))
                {
                    hdnCurrentPageNo.Value = Request.QueryString["hdnCurrentPageNo"].ToString();
                }

                if (!string.IsNullOrEmpty(Request.QueryString["hdnTotalRecordsCount"]))
                {
                    hdnTotalRecordsCount.Value = Request.QueryString["hdnTotalRecordsCount"].ToString();
                }

                int skip = 0, take = 10;
                if (IsNewSearch.Value != "0")
                {
                    skip = 0;
                    take = 10;
                    hdnNumberPerPage.Value     = "10";
                    hdnCurrentPageNo.Value     = "1";
                    hdnTotalRecordsCount.Value = ISetService.GetSetsForMfilesAccountCount(departmentId, Request.QueryString["DocType"], Request.QueryString["Search"]).ToString();
                }
                else
                {
                    skip = (Convert.ToInt32(hdnCurrentPageNo.Value) - 1) * 10;
                    take = 10;
                }

                List <DocTypeSetModel> list = new List <DocTypeSetModel>();
                if (departmentId != 0 || !string.IsNullOrEmpty(Request.QueryString["DocType"]) || !string.IsNullOrEmpty(Request.QueryString["Search"]))
                {
                    list = ISetService.GetSetsForMfilesAccount(departmentId, Request.QueryString["DocType"], Request.QueryString["Search"], skip, take);
                }

                StringBuilder asb           = new StringBuilder();
                int           index         = 1;
                foreach (DocTypeSetModel set in list)
                {
                    Branch     branch         = IBranchService.GetSingle(set.BranchId);
                    Department department     = departmentList.FirstOrDefault(a => a.Id == set.DepartmentId);
                    string     departmentCode = department.Code;
                    string     deptCode       = departmentCode.Split('-')[0];
                    string     jobCode        = departmentCode.Split('-')[1];
                    string     columnData     = "";
                    if (departmentCode == "E-LIBRARY")
                    {
                        //AA NUMBER
                        //ACCOUNT NUMBER
                        columnData  = "AA No: " + set.AANO;
                        columnData += "<br/>Account No: " + set.AccountNo;
                    }
                    else if (deptCode == "ETP")
                    {
                        if (jobCode == "LN")
                        {
                            columnData  = "AA No: " + set.AANO;
                            columnData += "<br/>Account No: " + set.AccountNo;
                        }
                        else if (jobCode == "LL")
                        {
                            columnData = "AA No: " + set.AANO;
                        }
                        else if (jobCode == "PR")
                        {
                            columnData = "Project Code: " + set.AANO;
                        }
                        else if (jobCode == "WF")
                        {
                            columnData = "Welfare Code: " + set.AANO;
                        }
                    }
                    else if (deptCode == "LOS")
                    {
                        columnData = "AA No: " + set.AANO;
                    }

                    asb.Append(@"<tr>
                                    <td class=''>
                                        " + index + @"
                                    </td>
                                    <td>" + branch.Code + @"</td>
                                    <td>" + department.Code + @"</td>
                                    <td class='text-center mb-5'>
                                        " + set.BatchNo + @"
                                    </td>
                                    <td>
                                        <div><strong>" + columnData + @"</strong><div>
                                    </td>
                                    <td><div style='min-width: 150px;'><a href='#' data-original-title='Click to view' data-trigger='hover' data-placement='bottom' class='popovers text-info'><strong>" + set.DocType + @"</strong></a> ( <small> pages: <strong>" + set.PageCount + @"</strong></small> )</div></td>
                                    <td>" + MfileStatus(set.IsReleased) + @"</td>
                                    <td><a data-original-title='Click to view' data-trigger='hover' data-placement='bottom' class='popovers text-info' href='SetView.aspx?setId=" + set.SetId + @"' target='_blank'><i class='fa fa-eye'></i></a></td>
                                    <td>" + set.CreatedDate.ToString("dd/MM/yyyy HH:mm:ss") + @"</td>
                                </tr>");
                    //  }
                    index++;
                }

                string result = @"<button data-dismiss='alert' class='close close-sm' type='button'>
                                            <i class='fa fa-times'></i></button>
                                        <strong>Done!</strong> Found the " + hdnTotalRecordsCount.Value + " records with .";
                if (departmentId != 0)
                {
                    result += DepartmentId.SelectedItem.Text + " Department &";
                }
                if (!string.IsNullOrEmpty(Request.QueryString["DocType"]))
                {
                    result += Request.QueryString["DocType"] + " Doc Type &";
                }
                if (!string.IsNullOrEmpty(Request.QueryString["Search"]))
                {
                    result += "this " + Request.QueryString["Search"] + " text.";
                }
                divResult.Visible   = true;
                divResult.InnerHtml = result;

                setsTbody.InnerHtml = asb.ToString();
            }
            else
            {
                if (IsNewSearch.Value == "1")
                {
                    divError.Visible = true;
                }
                divError.InnerHtml = @"<button data-dismiss='alert' class='close close-sm' type='button'>
                                            <i class='fa fa-times'></i></button>
                                        <strong>Oh snap!</strong> Please select at lest one select option.";
            }
        }