Esempio n. 1
0
        public JsonResult SelectRows_Danhsachnghiphep(AbsentModels model, string curentPage)
        {
            AbsentModels   param   = new AbsentModels();
            AbsentServices service = new AbsentServices();
            int            loginid = 0;

            if (Session["userid"].ToString().Trim() != "1")
            {
                loginid = int.Parse(Session["userid"].ToString());
            }
            param.nguoitao   = loginid;
            param.maphongban = model.maphongban;
            maphongbanexcel  = model.maphongban;
            int tongsodong = service.CountRows(param);
            int trang      = 1;

            try
            {
                trang = int.Parse(curentPage);
                trang = trang + 1;
            }
            catch (Exception) { trang = 1; }

            int sotrang = 1;

            if (tongsodong > 20)
            {
                if (tongsodong % 20 > 0)
                {
                    sotrang = (tongsodong / 20) + 1;
                }
                else
                {
                    sotrang = (tongsodong / 20);
                }
            }

            int trangbd = 1; int trangkt = 20;

            if (trang != 1 && trang <= sotrang)
            {
                trangbd = (trangkt * (trang - 1)) + 1;
                trangkt = trangkt * trang;
            }

            List <AbsentModels> lstResult = new List <AbsentModels>();

            if (trang <= sotrang)
            {
                lstResult = service.SelectRows_Danhsachnghiphep(param, trangbd, trangkt);
            }
            else if (trang != 1 && trang > sotrang)
            {
                trang = trang - 1;
            }
            foreach (var list in lstResult)
            {
                string mang = "";
                if (list.nghiphep.Trim() == "1")
                {
                    mang = mang + "Nghỉ phép" + ", ";
                }
                if (list.nghiom.Trim() == "1")
                {
                    mang = mang + "Nghỉ ốm" + ", ";
                }
                if (list.nghithaisan.Trim() == "1")
                {
                    mang = mang + "Nghỉ thai sản" + ", ";
                }
                if (list.nghikhongluong.Trim() == "1")
                {
                    mang = mang + "Nghỉ không lương" + ", ";
                }
                if (list.nghiviecrieng.Trim() == "1")
                {
                    mang = mang + "Nghỉ việc riêng có lương" + ", ";
                }
                if (list.nghikhac.Trim() == "1")
                {
                    mang = mang + "Nghỉ khác" + ", ";
                }
                if (mang.Length > 0)
                {
                    mang = mang.Trim().Remove(mang.Trim().Length - 1);
                }
                list.loaiphepnam = mang;

                if (list.duyetcap1 == "0")
                {
                    list.duyetcap1ten = "Chờ duyệt";
                }
                else if (list.duyetcap1 == "1")
                {
                    list.duyetcap1ten = "Đã duyệt";
                }
                else if (list.duyetcap1 == "2")
                {
                    list.duyetcap1ten = "Không duyệt";
                }

                if (list.duyetcap2 == "0")
                {
                    list.duyetcap2ten = "Chờ duyệt";
                }
                else if (list.duyetcap2 == "1")
                {
                    list.duyetcap2ten = "Đã duyệt";
                }
                else if (list.duyetcap2 == "2")
                {
                    list.duyetcap2ten = "Không duyệt";
                }

                if (list.xacnhantruockhivaolamlai == "0")
                {
                    list.xacnhantruockhivaolamlaiten = "No";
                }
                else
                {
                    list.xacnhantruockhivaolamlaiten = "Yes";
                }
            }

            StringBuilder sbResult        = new StringBuilder();
            StringBuilder sbRows          = new StringBuilder();

            if (lstResult.Count > 0)
            {
                string strSTT = "";
                int    i      = trangbd;
                foreach (var item in lstResult)
                {
                    strSTT = i.ToString();
                    sbRows.Append(PrepareDataJson_Danhsachnghiphep(item, strSTT));
                    i++;
                }
                if (sbRows.Length > 0)
                {
                    sbRows.Remove(sbRows.Length - 1, 1);
                }
            }
            sbResult.Append("{");
            sbResult.Append("\"isHeader\":\"" + "111" + "\",");

            sbResult.Append("\"curentPage\":\"" + "" + trang + "" + "\",");

            sbResult.Append("\"Pages\":\"" + "" + sotrang + "" + "\",");

            if (trang > 1 && lstResult.Count > 0)
            {
                sbResult.Append("\"SubRow\":\"" + "true" + "\",");
                sbResult.Append("\"RowID\":\"" + model.manghiphep + "\",");
            }
            sbResult.Append("\"data\":[" + sbRows.ToString() + "]");
            sbResult.Append("}");

            return(Json(sbResult.ToString(), JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult ExportLicensing()
        {
            //check login
            if (!IsLogged())
            {
                return(BackToLogin());
            }

            List <AbsentModels> lstResult = new List <AbsentModels>();

            AbsentModels   param   = new AbsentModels();
            AbsentServices service = new AbsentServices();

            param.maphongban = maphongbanexcel;

            int loginid = 0;

            if (Session["loginid"].ToString() != "admin")
            {
                loginid = int.Parse(Session["userid"].ToString());
            }
            param.nguoitao = loginid;

            lstResult = service.SelectRows_Danhsachnghiphep(param, 1, 5000);
            DataTable dt = new DataTable();

            dt.TableName = "Employee";
            dt.Columns.Add("hovaten");
            dt.Columns.Add("ngaynghi");
            dt.Columns.Add("songay");
            dt.Columns.Add("nghiden");
            foreach (var item in lstResult)
            {
                DataRow row = dt.NewRow();
                dt.Rows.Add(row);
                row["hovaten"]  = item.hovaten;
                row["ngaynghi"] = item.ngayxinnghitu;
                row["songay"]   = item.songayxinnghi;
                row["nghiden"]  = item.ngayxinnghiden;
                dt.AcceptChanges();
            }
            using (XLWorkbook wb = new XLWorkbook())
            {
                wb.Worksheets.Add(dt);
                wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
                wb.Style.Font.Bold            = true;

                Response.Clear();
                Response.Buffer      = true;
                Response.Charset     = "";
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;filename= EmployeeReport.xlsx");

                using (MemoryStream MyMemoryStream = new MemoryStream())
                {
                    wb.SaveAs(MyMemoryStream);
                    MyMemoryStream.WriteTo(Response.OutputStream);
                    Response.Flush();
                    Response.End();
                }
            }
            return(RedirectToAction("Vacationlist"));
        }