Beispiel #1
0
        /// <summary>
        /// Добавляет всю группу студентов в систему
        /// </summary>
        /// <param name="name">Имя группы</param>
        /// <param name="department">Кафедра группы</param>
        /// <param name="fileStudent">Файл со списком студентов</param>
        /// <returns>Страница</returns>
        public ActionResult AddGroupAndStudent(string name, int department, HttpPostedFileBase fileStudent)
        {
            Messages messages = new Messages();

            if (fileStudent != null)
            {
                Group  group    = Group.AddGroup(name, department);
                string fileName = Request.PhysicalApplicationPath + "\\Files\\" + fileStudent.FileName;
                Microsoft.Office.Interop.Excel.Application excelApplication = null;
                Microsoft.Office.Interop.Excel.Workbooks   excelWorkbooks;
                Microsoft.Office.Interop.Excel.Workbook    excelFile = null;
                Microsoft.Office.Interop.Excel.Worksheet   excelWorksheet;
                try
                {
                    fileStudent.SaveAs(fileName);
                    excelApplication = new Microsoft.Office.Interop.Excel.Application();
                    excelWorkbooks   = excelApplication.Workbooks;
                    excelFile        = excelWorkbooks.Open(fileName);
                    excelWorksheet   = (Microsoft.Office.Interop.Excel.Worksheet)excelFile.Worksheets.get_Item(1);
                    for (int i = 2;; i++)
                    {
                        Microsoft.Office.Interop.Excel.Range fioStudnt   = excelWorksheet.Range["A" + i];
                        Microsoft.Office.Interop.Excel.Range emailStudnt = excelWorksheet.Range["B" + i];
                        string telephoneStudnt      = excelWorksheet.Range["C" + i].Value2 ?? "";
                        int    currentSemestrStudnt = Convert.ToInt32(excelWorksheet.Range["D" + i].Value2 ?? "1");
                        string addressStudnt        = excelWorksheet.Range["E" + i].Value2;
                        string recordBookStudnt     = group.Name + (excelWorksheet.Range["F" + i].Value2 != null ? Convert.ToInt32(excelWorksheet.Range["F" + i].Value2).ToString("D2") : i.ToString("D2"));
                        Student.TypeOfEducation typeOfEducetionStudnt = Student.ConverStringToEnum(excelWorksheet.Range["G" + i].Value2 ?? "");
                        string contactsParentsStudnt           = excelWorksheet.Range["H" + i].Value2 ?? "";
                        string employmentInTheDepartmentStudnt = excelWorksheet.Range["I" + i].Value2 ?? "";
                        if (fioStudnt.Value2 != null || emailStudnt.Value2 != null)
                        {
                            string[] fio = ((string)fioStudnt.Value2.ToString()).Split(' ');
                            Student.AddStudent(fio[0], fio[1], fio[2], emailStudnt.Value2.ToString(), telephoneStudnt, group.ID, currentSemestrStudnt, addressStudnt, recordBookStudnt, typeOfEducetionStudnt, contactsParentsStudnt, employmentInTheDepartmentStudnt, false);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    excelFile.Close();
                    excelApplication.Quit();
                    System.IO.File.Delete(fileName);
                }
                messages.Add(Messages.Message.TypeMessage.good, string.Format("Группа {0} добавленна", name));
            }
            TempData["messages"] = messages;
            return(Redirect("/Admin"));
        }
Beispiel #2
0
        /// <summary>
        /// Преобразовывает элемент перчисления в строку
        /// </summary>
        /// <param name="value">Элемент перечисления</param>
        /// <returns>Строковая интерпритация элемнта перечисления</returns>
        public static string GetEnumDescription(Student.TypeOfEducation value)
        {
            switch (value)
            {
            case TypeOfEducation.dayBudget:
                return("денна - бюджет");

            case TypeOfEducation.dayContract:
                return("денна - контракт");

            case TypeOfEducation.extramural:
                return("заочна");
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Добавление студента
        /// </summary>
        /// <param name="name">Имя студента</param>
        /// <param name="surname">Фамилия студента</param>
        /// <param name="secondName">Отчество студента</param>
        /// <param name="email">Email студента</param>
        /// <param name="telephone">Телефон студента</param>
        /// <param name="group">Группа студента</param>
        /// <param name="currentSemestr">Семестр на котором учится студент</param>
        /// <param name="address">Адрес студента</param>
        /// <param name="recordBook">Код зачетной книги студента</param>
        /// <param name="typeOfEducation">Тип обралования студента ('дена','заочна')</param>
        /// <param name="contactsParents">Контакты родителей студента</param>
        /// <param name="employmentInTheDepartment">Чем занимается студент на кафедре</param>
        /// <param name="admin">Является ли студент администраторм системы</param>
        /// <returns>Новый студент</returns>
        public static Student AddStudent(string surname, string name, string secondName, string email, string telephone,
                                         int group, int currentSemestr, string address, string recordBook, Student.TypeOfEducation typeOfEducation, string contactsParents,
                                         string employmentInTheDepartment, bool admin)
        {
            DB db = new DB();

            db.QueryToRespontTable(string.Format("insert into student(Group_id, Surname, Name, Second_name, Semester, Address, Telephone, Record_book, Type_of_education, Сontacts_parents, Employment_in_the_department) values ({0}, '{1}', '{2}', '{3}', {4}, '{5}', '{6}', '{7}', '{8}', '{9}', '{10}');", group, surname, name, secondName, currentSemestr, address, telephone, recordBook, Student.GetEnumDescription(typeOfEducation), contactsParents, employmentInTheDepartment));
            DB.ResponseTable userIdTable = db.QueryToRespontTable("select LAST_INSERT_ID() as id;");
            userIdTable.Read();
            Student user = new Student(Users.AddStudentUsers(email, admin ? 2 : 0, Convert.ToInt32(userIdTable["id"])));

            user.GetInformationAboutUserFromDB();
            return(user);
        }