Exemplo n.º 1
0
        private void add_Click(object sender, EventArgs e)
        {
            if (checkZachNumberDistinction.Checked)
            {
                if (_repo.FindStudent(ZachNumber.Text) != null)
                {
                    MessageBox.Show("Такой студент уже есть.");
                    return;
                }
            }

            var newStudent = new Student {
                F = FBox.Text,
                I = IBox.Text,
                O = OBox.Text,
                Address = Address.Text,
                BirthDate = BirthDate.Value,
                Expelled = Expelled.Checked,
                NFactor = NFactor.Checked,
                Orders = OrderList.Text,
                PaidEdu = PayForThis.Checked,
                Phone = Phone.Text,
                Starosta = Starosta.Checked,
                ZachNumber = ZachNumber.Text
            };

            _repo.AddStudent(newStudent);

            RefreshView();
        }
Exemplo n.º 2
0
        private void SaveClick(object sender, EventArgs e)
        {
            if (_mode == StudentDetailsMode.New)
            {
                var s = new Student
                {
                    Address = AddressBox.Text,
                    BirthDate = BirthDateBox.Value,
                    Expelled = ExpelledBox.Checked,
                    F = FamilyBox.Text,
                    I = NameBox.Text,
                    NFactor = FromSchoolBox.Checked,
                    O = PatronymicBox.Text,
                    Orders = OrdersBox.Text,
                    PaidEdu = PaidLearningBox.Checked,
                    Phone = PhoneBox.Text,
                    Starosta = StarostaBox.Checked,
                    ZachNumber = IdNumBox.Text
                };

                _repo.Students.AddStudent(s);

                var group = _repo.StudentGroups.FindStudentGroup(StudentGroupBox.Text);
                if (group != null)
                {
                    var sig = new StudentsInGroups(s, group);
                    _repo.StudentsInGroups.AddStudentsInGroups(sig);
                }

                _studentList.UpdateSearchBoxItems();
                DialogResult = DialogResult.OK;
                Close();
            }

            if (_mode == StudentDetailsMode.Edit)
            {
                var s = _repo.Students.GetStudent(_student.StudentId);

                s.Address = AddressBox.Text;
                s.BirthDate = BirthDateBox.Value;
                s.Expelled = ExpelledBox.Checked;
                s.F = FamilyBox.Text;
                s.I = NameBox.Text;
                s.NFactor = FromSchoolBox.Checked;
                s.O = PatronymicBox.Text;
                s.Orders = OrdersBox.Text;
                s.PaidEdu = PaidLearningBox.Checked;
                s.Phone = PhoneBox.Text;
                s.Starosta = StarostaBox.Checked;
                s.ZachNumber = IdNumBox.Text;

                _repo.Students.UpdateStudent(s);

                _studentList.UpdateSearchBoxItems();
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Exemplo n.º 3
0
        public StudentProperties(StudentList parent, ScheduleRepository repo, int studentId, StudentDetailsMode mode)
        {
            InitializeComponent();

            _studentList = parent;
            _repo = repo;
            _student = _repo.Students.GetStudent(studentId);
            _mode = mode;

            if ((_student == null) && mode == StudentDetailsMode.Edit)
            {
                Close();
            }
        }
Exemplo n.º 4
0
 public StudentView(Student st)
 {
     StudentId = st.StudentId;
     FIO = st.F + " " + st.I + " " + st.O;
     ZachNumber  = st.ZachNumber;
     BirthDate = st.BirthDate.ToShortDateString();
     Address = st.Address;
     Phone = st.Phone;
     Orders = st.Orders;
     Expelled = st.Expelled;
     NFactor = st.NFactor;
     PaidEdu = st.PaidEdu;
     Starosta = st.Starosta;
 }
Exemplo n.º 5
0
 public MySQLStudent(Student student)
 {
     StudentId = student.StudentId;
     F = student.F;
     I = student.I;
     O = student.O;
     ZachNumber = student.ZachNumber;
     BirthDate = student.BirthDate.ToString("yyyy-MM-dd");
     Address = student.Address;
     Phone = student.Phone;
     Orders = student.Orders;
     Starosta = student.Starosta ? 1 : 0;
     NFactor = student.NFactor ? 1 : 0;
     PaidEdu = student.PaidEdu ? 1 : 0;
     Expelled = student.Expelled ? 1 : 0;
 }
Exemplo n.º 6
0
        public StudentView(Student st)
        {
            StudentId = st.StudentId;
            Fio = st.F + " " + st.I + " " + st.O;
            ZachNumber  = st.ZachNumber;
            BirthDate = st.BirthDate.ToShortDateString();
            Address = st.Address;
            Phone = st.Phone;
            Orders = st.Orders;
            Expelled = st.Expelled;
            NFactor = st.NFactor;
            PaidEdu = st.PaidEdu;
            Starosta = st.Starosta;

            Summary = Fio + " " + " (" + (Expelled ? "+" : "-") + ZachNumber + ")";
        }
Exemplo n.º 7
0
        private void ImportStudentData(string filename)
        {
            var studentList = new List<Student>();
            var studentGroups = new List<StudentGroup>();
            var studentsInGroups = new List<StudentsInGroups>();

            var sr = new StreamReader(filename);

            string line;

            var maxStudentId = _repo
                .GetAllStudents()
                .Select(s => s.StudentId)
                .Max();
            maxStudentId++;

            var StudentIdRemap = new Dictionary<int, int>();

            sr.ReadLine();
            while ((line = sr.ReadLine()) != "StudentGroups")
            {
                var studentParts = line.Split('@');
                var student = new Student() {
                    StudentId = maxStudentId,
                    F = studentParts[1],
                    I = studentParts[2],
                    O = studentParts[3],
                    Address = "",
                    BirthDate = new DateTime(2000,1,1),
                    Expelled = false,
                    NFactor = false,
                    Orders = "",
                    PaidEdu = false,
                    Phone = "",
                    Starosta = false,
                    ZachNumber = ""
                };

                StudentIdRemap.Add(int.Parse(studentParts[0]), maxStudentId);

                studentList.Add(student);

                _repo.AddStudent(student);

                maxStudentId++;
            }

            StudentGroup group = null;
            var maxGroupId = _repo
                .GetAllStudentGroups()
                .Select(s => s.StudentGroupId)
                .Max();
            maxGroupId++;

            var groupIdRemap = new Dictionary<int, int>();
            while ((line = sr.ReadLine()) != "StudentsInGroups")
            {
                var groupParts = line.Split('@');

                if (!_repo.GetFiltredStudentGroups(sg => sg.Name == groupParts[1]).Any())
                {
                    group = new StudentGroup()
                    {
                        StudentGroupId = maxGroupId,
                        Name = groupParts[1]
                    };

                    groupIdRemap.Add(int.Parse(groupParts[0]), maxGroupId);

                    studentGroups.Add(group);

                    _repo.AddStudentGroup(group);

                    maxGroupId++;
                }
                else
                {
                    var gr = _repo.GetFirstFiltredStudentGroups(sg => sg.Name == groupParts[1]);
                    studentGroups.Add(gr);

                    groupIdRemap.Add(int.Parse(groupParts[0]), gr.StudentGroupId);
                }
            }

            while ((line = sr.ReadLine()) != null)
            {
                var sigParts = line.Split('@');

                var studentId = int.Parse(sigParts[0]);
                studentId = StudentIdRemap[studentId];

                var studentGroupId = int.Parse(sigParts[1]);
                if (groupIdRemap.ContainsKey(studentGroupId))
                {
                    studentGroupId = groupIdRemap[studentGroupId];
                }
                else
                {
                    studentGroupId = _repo.GetFirstFiltredStudentGroups( sg => sg.Name ==
                        studentGroups.FirstOrDefault(stg => stg.StudentGroupId == studentGroupId).Name).StudentGroupId;
                }

                var sig = new StudentsInGroups()
                {
                    Student = _repo.GetStudent(studentId),
                    StudentGroup = _repo.GetStudentGroup(studentGroupId)
                };

                studentsInGroups.Add(sig);

                _repo.AddStudentsInGroups(sig);
            }

            sr.Close();
        }
        public Student AddStudent(Student student)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                student.StudentId = 0;

                context.Students.Add(student);
                context.SaveChanges();

                return student;
            }
        }
        public void UpdateStudent(Student student)
        {
            using (var context = new ScheduleContext(ConnectionString))
            {
                var curStudent = context.Students.FirstOrDefault(s => s.StudentId == student.StudentId);

                curStudent.F = student.F;
                curStudent.I = student.I;
                curStudent.O = student.O;

                curStudent.ZachNumber = student.ZachNumber;
                curStudent.BirthDate = student.BirthDate;
                curStudent.Address = student.Address;
                curStudent.Phone = student.Phone;
                curStudent.Starosta = student.Starosta;
                curStudent.NFactor = student.NFactor;
                curStudent.PaidEdu = student.PaidEdu;
                curStudent.Expelled = student.Expelled;
                curStudent.Orders = student.Orders;

                context.SaveChanges();
            }
        }
 public StudentsInGroups FindStudentsInGroups(Student s, StudentGroup sg)
 {
     using (var context = new ScheduleContext(ConnectionString))
     {
         return context.StudentsInGroups.Include(sig => sig.Student).Include(sig => sig.StudentGroup).FirstOrDefault(sig => sig.Student.StudentId == s.StudentId && sig.StudentGroup.StudentGroupId == sg.StudentGroupId);
     }
 }
Exemplo n.º 11
0
        public static Dictionary<string, List<Student>> ImportStudentsWithBaseGroups(string basePath)
        {
            var result = new Dictionary<string, List<Student>>();

            int state = 0; // 0 - new group; 1 - people
            string currentGroup = "";
            var sr = new StreamReader(basePath + "StudentGroups.txt");
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                if (line == "")
                {
                    state = 0;
                    continue;
                }

                switch (state)
                {
                    case 0:
                        currentGroup = line;
                        result.Add(line, new List<Student>());

                        state = 1;
                        break;
                    case 1:
                        var data = line.Split('@');
                        var newStudent = new Student
                        {
                            F = data[0],
                            I = data[1],
                            O = data[2],
                            ZachNumber = data[3],
                            BirthDate = (data[4] == "") ? new DateTime(1980, 1, 1) : new DateTime(int.Parse(data[4].Substring(6, 4)), int.Parse(data[4].Substring(3, 2)), int.Parse(data[4].Substring(0, 2))),
                            Address = data[5],
                            Phone = data[6],
                            Orders = data[7],
                            Starosta = (data[8] == "1") ? true : false,
                            NFactor = (data[9] == "1") ? true : false,
                            PaidEdu = (data[10] == "1") ? true : false,
                            Expelled = (data[11] == "1") ? true : false
                        };

                        result[currentGroup].Add(newStudent);
                        break;
                    default:
                        break;
                }

            }
            sr.Close();

            return result;
        }
Exemplo n.º 12
0
        private void SetControlsFromStudent(Student studentToSet)
        {
            if (studentToSet == null)
            {
                FamilyBox.Text = "";
                NameBox.Text = "";
                PatronymicBox.Text = "";
                IdNumBox.Text = "";
                BirthDateBox.Value = DateTime.Now;
                AddressBox.Text = "";
                PhoneBox.Text = "";
                OrdersBox.Text = "";
                StarostaBox.Checked = false;
                FromSchoolBox.Checked = false;
                PaidLearningBox.Checked = false;
                ExpelledBox.Checked = false;
                StudentGroupBox.Text = "";
                StudentGroupBox.ReadOnly = false;
                return;
            }

            FamilyBox.Text = studentToSet.F;
            NameBox.Text = studentToSet.I;
            PatronymicBox.Text = studentToSet.O;
            IdNumBox.Text = studentToSet.ZachNumber;
            BirthDateBox.Value = studentToSet.BirthDate;
            AddressBox.Text = studentToSet.Address;
            PhoneBox.Text = studentToSet.Phone;
            OrdersBox.Text = studentToSet.Orders;
            StarostaBox.Checked = studentToSet.Starosta;
            FromSchoolBox.Checked = studentToSet.NFactor;
            PaidLearningBox.Checked = studentToSet.PaidEdu;
            ExpelledBox.Checked = studentToSet.Expelled;

            var studentGroupIds = _repo
                .StudentsInGroups
                .GetFiltredStudentsInGroups(sig => sig.Student.StudentId == studentToSet.StudentId)
                .Select(sig => sig.StudentGroup.StudentGroupId)
                .ToList();

            var studentGroup = _repo
                .StudentGroups
                .GetFiltredStudentGroups(sg =>
                    studentGroupIds.Contains(sg.StudentGroupId) &&
                    !sg.Name.Contains('I') && !sg.Name.Contains('-') &&
                    !sg.Name.Contains('+') && !sg.Name.Contains(".)"))
                .OrderBy(g => g.Name)
                .ToList();

            if (studentGroup.Count > 0)
            {
                StudentGroupBox.Text = studentGroup[0].Name;
            }

            var groupsList = _repo
                .StudentsInGroups
                .GetFiltredStudentsInGroups(sig => sig.Student.StudentId == studentToSet.StudentId)
                .Select(sig => sig.StudentGroup.Name)
                .Where(groupname => groupname != studentGroup[0].Name)
                .OrderBy(n => n)
                .ToList();

            if (groupsList.Count > 0)
            {
                StudentGroupBox.Text += Resources.OpenParenthesis + groupsList.Aggregate((a,b) => a + ", " + b) + Resources.CloseParenthesis;
            }
            StudentGroupBox.ReadOnly = true;
        }