Ejemplo n.º 1
0
        public FileResult Excel_NotRegisterStudents()
        {
            string path = Path.Combine(Server.MapPath("~/Content/Reports/Excel/"), "StudentTemplate.xlsx");

            Microsoft_Excel _Excel = new Microsoft_Excel(path);

            _Excel.Open(1);

            int i = 1;

            foreach (var item in db.Tbl_Student.Where(a => a.Student_Info == false || a.Student_Form1 == false || a.Student_Form2 == false || a.Student_TakeTurn == false).OrderBy(a => a.Student_Code).ToList())
            {
                _Excel.WriteToCell(i, 0, item.Student_Code);
                _Excel.WriteToCell(i, 1, item.Student_NationalCode);
                _Excel.WriteToCell(i, 2, item.Student_SIID.HasValue ? item.Tbl_StudentInfo.SI_Name : "نا معلوم");
                _Excel.WriteToCell(i, 3, item.Student_SIID.HasValue ? item.Tbl_StudentInfo.SI_Family : "نا معلوم");
                _Excel.WriteToCell(i, 4, item.Student_Info ? "تکمیل شده" : "تکمیل نشده");
                _Excel.WriteToCell(i, 5, item.Student_Form1 ? "تکمیل شده" : "تکمیل نشده");
                _Excel.WriteToCell(i, 6, item.Student_Form2 ? "تکمیل شده" : "تکمیل نشده");
                _Excel.WriteToCell(i, 7, item.Student_TakeTurn ? "تکمیل شده" : "تکمیل نشده");

                i++;
            }

            string SaveAsPath = Path.Combine(Server.MapPath("~/App_Data/Excel/"), string.Format("{0}.xlsx", Guid.NewGuid()));

            _Excel.SaveAs(SaveAsPath);

            _Excel.Close();

            return(File(SaveAsPath, "*", string.Format("{0}.xlsx", "دانشجویان ثبت نام نشده")));
        }
Ejemplo n.º 2
0
        public ActionResult ImportStudentFromExcel(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    string path = Path.Combine(Server.MapPath("~/Images"), Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                }
                catch
                {
                    TempData["TosterState"]   = "error";
                    TempData["TosterType"]    = TosterType.Maseage;
                    TempData["TosterMassage"] = "خطا";
                    return(View());
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";
            }

            Microsoft_Excel excel = new Microsoft_Excel(@"C:\2.xlsx");

            excel.Open(1);
            int row_count = excel.Get_RowCount();

            string[,] ex = excel.Get_Range(1, 1, row_count, 2);
            excel.Close();

            for (int i = 0; i < row_count; i++)
            {
                Tbl_Student _Student = new Tbl_Student()
                {
                    Student_Code         = ex[i, 0],
                    Student_NationalCode = ex[i, 1],
                    Student_Guid         = Guid.NewGuid()
                };

                db.Tbl_Student.Add(_Student);
            }


            if (Convert.ToBoolean(db.SaveChanges() > 0))
            {
                TempData["TosterState"]   = "success";
                TempData["TosterType"]    = TosterType.Maseage;
                TempData["TosterMassage"] = "ثبت نام با موفقیت انجام شده";
                return(View());
            }
            else
            {
                TempData["TosterState"]   = "error";
                TempData["TosterType"]    = TosterType.Maseage;
                TempData["TosterMassage"] = "خطا";
                return(View());
            }
        }
        public FileResult Excel(int id)
        {
            var _TakeTurn = db.Tbl_TurnTimeSheet.Where(a => a.TTS_ID == id).SingleOrDefault().Tbl_TakeTurn;

            var _Student = _TakeTurn.Select(a => a.Tbl_Student).OrderBy(a => a.Student_Code).Select(a => new Model_StudentTakeTimeList
            {
                ID               = a.Student_ID,
                Student_Code     = a.Student_Code,
                Student_National = a.Student_NationalCode,
                Student_Name     = a.Student_SIID.HasValue ? a.Tbl_StudentInfo.SI_Name : "نا معلوم",
                Student_Family   = a.Student_SIID.HasValue ? a.Tbl_StudentInfo.SI_Family : "نا معلوم",
                per              = false,
            }).ToList();


            string path = Path.Combine(Server.MapPath("~/Content/Reports/Excel/"), "TurnReportTemplate.xlsx");

            Microsoft_Excel _Excel = new Microsoft_Excel(path);

            _Excel.Open(1);

            int i = 1;

            foreach (var item in _Student)
            {
                _Excel.WriteToCell(i, 0, item.Student_Code);
                _Excel.WriteToCell(i, 1, item.Student_National);
                _Excel.WriteToCell(i, 2, item.Student_Name);
                _Excel.WriteToCell(i, 3, item.Student_Family);

                i++;
            }

            string SaveAsPath = Path.Combine(Server.MapPath("~/App_Data/Excel/"), string.Format("{0}.xlsx", Guid.NewGuid()));

            _Excel.SaveAs(SaveAsPath);

            _Excel.Close();

            string filename = _TakeTurn.FirstOrDefault().Tbl_TurnTimeSheet.TTS_Name;

            return(File(SaveAsPath, "*", string.Format("{0}.xlsx", filename)));
        }