Пример #1
0
        public JsonResult GetAttendanceRepotrt(int year, int month)
        {
            int              employeeid = Convert.ToInt32(Session["Emp_ID"].ToString());
            string           from       = year + "-" + month + "-" + 01;
            string           to         = year + "-" + month + "-" + 31;
            EmployeeProperty emp        = new EmployeeProperty();

            emp.Id = employeeid;
            Employee_BLL empbll          = new Employee_BLL(emp);
            int          empattendanceid = empbll.GetEmployeeAttendanceId();

            objattendancebll = new Attendance_BLL();
            DataTable dt          = objattendancebll.SelectEmployeeAttendance(from, to, empattendanceid);
            var       dtserialize = JsonConvert.SerializeObject(dt);

            return(Json(new { data = dtserialize }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public FileResult DownloadAttendance(int year, int month)
        {
            int              employeeid = Convert.ToInt32(Session["Emp_ID"].ToString());
            string           from       = year + "-" + month + "-" + 01;
            string           to         = year + "-" + month + "-" + 31;
            EmployeeProperty emp        = new EmployeeProperty();

            emp.Id = employeeid;
            Employee_BLL empbll          = new Employee_BLL(emp);
            int          empattendanceid = empbll.GetEmployeeAttendanceId();

            objattendancebll = new Attendance_BLL();
            DataTable dt       = objattendancebll.SelectEmployeeAttendance(from, to, empattendanceid);
            string    fullName = Server.MapPath("~" + "/AttendanceFiles/Attendance Report" + from + to + employeeid);
            bool      flag     = WriteDataTableToExcel(dt, "Attendance Report" + employeeid, fullName);

            if (flag)
            {
                try
                {
                    byte[] fileBytes = System.IO.File.ReadAllBytes(fullName + ".xlsx");
                    string fileName  = Path.GetFileName(fullName + ".xlsx");
                    return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
                }
                catch (Exception ex)
                {
                    //StringBuilder sb = new StringBuilder();
                    //sb.Append("log something");

                    //File.AppendAllText(filePath + "log.txt", sb.ToString());
                    //sb.Clear();
                    byte[] fileBytes = new byte[1];
                    return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, ""));
                }
            }
            else
            {
                byte[] fileBytes = System.IO.File.ReadAllBytes(fullName);
                string fileName  = Path.GetFileName("");

                return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, "abc Else Case"));
            }
        }