Example #1
0
 private void LoadData(int Id)
 {
     this.CurrentObjectId = Id;
     using (var db = new SportEntities(SportProgramSettings.ConnectionString))
     {
         Students CurrentObject = db.Students.Find(Id);
         textBox1.Text = CurrentObject.StudentId.ToString();
         textBox2.Text = CurrentObject.LastName;
         textBox3.Text = CurrentObject.FirstName;
         textBox4.Text = CurrentObject.MiddleName;
         if (CurrentObject.Birdth.HasValue)
         {
             string[] data = CurrentObject.Birdth.Value.ToShortDateString().Split('.');
             textBox9.Text           = data[0];
             comboBox2.SelectedIndex = int.Parse(data[1]);
             textBox5.Text           = data[2];
         }
         if (CurrentObject.Phone != "")
         {
             PhoneNumber pn = new PhoneNumber(CurrentObject.Phone);
             textBox6.Text = pn.Operator;
             textBox7.Text = pn.Part1;
             textBox8.Text = pn.Part2;
         }
     }
 }
 private void LoadData(int Id)
 {
     if (Id == -1)
     {
         return;
     }
     using (var db = new SportEntities(SportProgramSettings.ConnectionString))
     {
         Subscriptions sub = db.Subscriptions.Find(Id);
         SetCurrentGroup(sub.GroupId);
         if (sub.IsUnlimited)
         {
             radioButton_TypeUnlim.Checked = true;
         }
         else
         {
             radioButton_TypeLim.Checked = true;
         }
         numeric_HoursCur.Value           = sub.SubHoursLeft;
         numeric_HoursMax.Value           = (int)sub.SubHoursMax;
         box_StartDateDay.Text            = sub.DateStart.Day.ToString();
         box_StartDateMonth.SelectedIndex = sub.DateStart.Month;
         box_StartDateYear.SelectedIndex  = Array.FindIndex(Years, x => x == sub.DateStart.Year);
     }
 }
Example #3
0
        private void AddData(object sender, EventArgs e)
        {
            if (!CheckAllFields())
            {
                return;
            }

            // Добавление занятий

            Schedule newSchedule = new Schedule
            {
                GroupId    = CurrentGroupId,
                Days       = GetCheckersString(),
                TimeStart  = int.Parse(textBox3.Text) * 60 + int.Parse(textBox4.Text),
                Hall       = int.Parse(textBox5.Text),
                IsPeriodic = radioButton1.Enabled
            };

            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    db.Schedule.Add(newSchedule);
                    db.SaveChanges();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! Занятие не было добавлено.\nВозникло исключение: " + ex.Message, "Ошибка!");
            }
        }
Example #4
0
 private void UpdateData(object sender, EventArgs e)
 {
     if (!CheckAllFields())
     {
         return;
     }
     try
     {
         using (var db = new SportEntities(SportProgramSettings.ConnectionString))
         {
             Students CurrentObject = db.Students.Find(CurrentObjectId);
             CurrentObject.LastName   = textBox2.Text;
             CurrentObject.FirstName  = textBox3.Text;
             CurrentObject.MiddleName = textBox4.Text;
             CurrentObject.Birdth     = textBox9.Text.Length == 0 ? null : (DateTime?)(DateTime.Parse($"{textBox9.Text}.{comboBox2.SelectedIndex}.{textBox5.Text}"));
             CurrentObject.Phone      = textBox6.Text.Length == 0 ? "" : (new PhoneNumber(textBox6.Text, textBox7.Text, textBox8.Text)).ToString();
             db.SaveChanges();
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! Изменения ученика не были сохранены.\nВозникло исключение: " + ex.Message, "Ошибка!");
     }
 }
Example #5
0
        private void AddData(object sender, EventArgs e)
        {
            if (!CheckAllFields())
            {
                return;
            }
            Groups newGroup = new Groups
            {
                Name        = textBox2.Text,
                Description = textBox3.Text,
                TrainerId   = CurrentTrainerId
            };

            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    db.Groups.Add(newGroup);
                    db.SaveChanges();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! Группа не была добавлена.\nВозникло исключение: " + ex.Message, "Ошибка!");
            }
        }
Example #6
0
 private void RefreshSubscriptionList(int pageIndex)
 {
     ShowSubscription(-1);
     // Проверка на то, что студент выбран
     if (CurrentStudentId == -1)
     {
         return;
     }
     // Получение списка и вывод его
     try
     {
         using (var db = new SportEntities(SportProgramSettings.ConnectionString))
         {
             // Получаем ученика
             Students student = db.Students.Find(CurrentStudentId);
             // Обновляем инфу о постраничной навигации
             int itemsCount = student.Subscriptions.Count();
             PageNavigationUpdate(pageIndex, itemsCount);
             // Работаем с подписками (вывод и все дела)
             PageSubscriptions = student.Subscriptions.OrderByDescending(x => x.DateStart)
                                 .Skip(SubsPagePartition * pageIndex).Take(SubsPagePartition).ToList();
             listBox_Subscriptions.Items.Clear();
             foreach (var s in PageSubscriptions)
             {
                 listBox_Subscriptions.Items.Add(
                     $"С {s.DateStart.ToShortDateString()} по {s.DateEnd.ToShortDateString()}. {s.Groups.Name}({s.Groups.Trainers.LastName})");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Произошла ошибка при выводе подписок ученика. Exception: " + ex);
     }
 }
Example #7
0
        private void AddData(object sender, EventArgs e)
        {
            if (!CheckAllFields())
            {
                return;
            }
            Students newStudent = new Students
            {
                LastName   = textBox2.Text,
                FirstName  = textBox3.Text,
                MiddleName = textBox4.Text,
                Birdth     = textBox9.Text.Length == 0 ? null : (DateTime?)(DateTime.Parse($"{textBox9.Text}.{comboBox2.SelectedIndex}.{textBox5.Text}")),
                Phone      = textBox6.Text.Length == 0 ? "" : (new PhoneNumber(textBox6.Text, textBox7.Text, textBox8.Text)).ToString()
            };

            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    db.Students.Add(newStudent);
                    db.SaveChanges();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! Ученик не был добавлен.\nВозникло исключение: " + ex.Message, "Ошибка!");
            }
        }
Example #8
0
 private void LoadData(int Id)
 {
     this.CurrentObjectId = Id;
     using (var db = new SportEntities(SportProgramSettings.ConnectionString))
     {
         Schedule CurrentObject = db.Schedule.Find(Id);
         textBox1.Text  = CurrentObject.Id.ToString();
         textBox2.Text  = $"[ИД {CurrentObject.GroupId}] {CurrentObject.Groups.Name} (Тренер {CurrentObject.Groups.Trainers.LastName})";
         CurrentGroupId = CurrentObject.GroupId;
         CheckNeededCheckers(CurrentObject.Days);
         textBox3.Text = ((int)((double)CurrentObject.TimeStart / 60)).ToString();
         if (textBox3.Text.Length == 1)
         {
             textBox3.Text = "0" + textBox3.Text;
         }
         textBox4.Text = (CurrentObject.TimeStart % 60).ToString();
         if (textBox4.Text.Length == 1)
         {
             textBox4.Text = "0" + textBox4.Text;
         }
         textBox5.Text = CurrentObject.Hall.ToString();
         if (CurrentObject.IsPeriodic)
         {
             radioButton1.Checked = true;
         }
         else
         {
             radioButton2.Checked = true;
         }
     }
 }
Example #9
0
        public string GetStudentReport(int studentId, DateTime from, DateTime to)
        {
            StringBuilder sb = new StringBuilder();

            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                // Находим тренера
                Students student = db.Students.Find(studentId);
                // Заполняем шапку отчёта
                sb.AppendLine($"Отчёт сформирован {DateTime.Now}");
                sb.AppendLine($"Ученик: {student.LastName} {student.FirstName} {student.MiddleName} (StudentId {student.StudentId})");
                sb.AppendLine($"Границы отчёта: С `{from.ToShortDateString()}` ПО `{to.ToShortDateString()}`");
                sb.AppendLine();
                // Получаем список сессий, в которых был этот ученик
                var sessions = db.StudentsInSessions
                               .Where(x => x.StudentId == studentId && from <= x.Sessions.Date && x.Sessions.Date <= to)
                               .Select(x => x.Sessions)
                               .OrderBy(x => x.Date).ThenBy(x => x.Time).ToList();
                foreach (Sessions s in sessions)
                {
                    int studentsCount = s.StudentsInSessions.Count();
                    sb.AppendLine($"{s.Date.ToShortDateString()} {s.Time} :: {s.Groups.Name} (GroupId {s.GroupId})");
                }
            }

            return(sb.ToString());
        }
Example #10
0
        private void button_SaveAdd_Click(object sender, EventArgs e)
        {
            if (!CheckFields())
            {
                return;
            }
            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    DateTime startDate = new DateTime(Years[box_StartDateYear.SelectedIndex], box_StartDateMonth.SelectedIndex, int.Parse(box_StartDateDay.Text));
                    DateTime formDate  = new DateTime(Years[box_StartDateYear.SelectedIndex], box_StartDateMonth.SelectedIndex, int.Parse(box_StartDateDay.Text));

                    Subscriptions sub = db.Subscriptions.First(x => x.SubscriptionId == CurrentSubscribeId);

                    sub.StudentId    = CurrentStudentId;
                    sub.GroupId      = CurrentGroupId;
                    sub.BuyTime      = DateTime.Now;
                    sub.IsUnlimited  = radioButton_TypeUnlim.Checked;
                    sub.SubHoursMax  = (int?)numeric_HoursMax.Value;
                    sub.SubHoursLeft = (int)numeric_HoursCur.Value;
                    sub.DateStart    = startDate.AddDays(0);
                    sub.DateEnd      = formDate.AddMonths(1).AddDays(-1);

                    db.SaveChanges();

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка при сохранении данных. Exception: " + ex);
            }
        }
Example #11
0
        private void CardInserted(object sender, CardInsertedEventArgs e)
        {
            if (!e.Value.HasValue)
            {
                MessageBox.Show("Ошибка контакта с картой. Попробуйте снова.");
                return;
            }

            synchronizationContext.Post(new SendOrPostCallback(o =>
            {
                int id = (int)o;
                if (id == 0)
                {
                    labelRead.Text = "<Пустая карта>";
                    return;
                }

                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    Students student = db.Students.Find(id);
                    labelRead.Text   = student == null
                        ? $"Ученика с ID == {id} не существует"
                        : $"(Ид {student.StudentId}) {student.FirstName} {student.MiddleName} {student.LastName}";
                }
            }), e.Value.Value);
        }
Example #12
0
 private void UpdateData(object sender, EventArgs e)
 {
     if (!CheckAllFields())
     {
         return;
     }
     try
     {
         using (var db = new SportEntities(SportProgramSettings.ConnectionString))
         {
             Schedule CurrentObject = db.Schedule.Find(CurrentObjectId);
             CurrentObject.GroupId    = CurrentGroupId;
             CurrentObject.Days       = GetCheckersString();
             CurrentObject.TimeStart  = int.Parse(textBox3.Text) * 60 + int.Parse(textBox4.Text);
             CurrentObject.Hall       = int.Parse(textBox5.Text);
             CurrentObject.IsPeriodic = radioButton1.Enabled;
             db.SaveChanges();
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! Изменения занятия не были сохранены.\nВозникло исключение: " + ex.Message, "Ошибка!");
     }
 }
Example #13
0
 private void SubscribtionToForm(int PresetSubscribeId)
 {
     if (PresetSubscribeId == -1)
     {
         return;
     }
     using (var db = new SportEntities(SportProgramSettings.ConnectionString))
     {
         Subscriptions sub = db.Subscriptions.Find(PresetSubscribeId);
         SetCurrentGroup(sub.GroupId);
         if (sub.IsUnlimited)
         {
             radioButton_TypeUnlim.Checked = true;
         }
         else
         {
             radioButton_TypeLim.Checked = true;
         }
         numeric_Hours.Value        = (int)sub.SubHoursMax;
         box_Duration.SelectedIndex = 0;
         //box_StartDateDay.Text = sub.DateStart.Day.ToString();
         //box_StartDateMonth.SelectedIndex = sub.DateStart.Month;
         //box_StartDateYear.SelectedIndex = Array.FindIndex(Years, x => x == sub.DateStart.Year);
         var curDate = DateTime.Now;
         box_StartDateDay.Text            = curDate.Day.ToString();
         box_StartDateMonth.SelectedIndex = curDate.Month;
         box_StartDateYear.SelectedIndex  = Array.FindIndex(Years, x => x == curDate.Year);
     }
 }
Example #14
0
        private void AddData(object sender, EventArgs e)
        {
            if (!CheckAllFields())
            {
                return;
            }
            Trainers newTrainer = new Trainers
            {
                LastName   = textBox2.Text,
                FirstName  = textBox3.Text,
                MiddleName = textBox4.Text
            };

            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    db.Trainers.Add(newTrainer);
                    db.SaveChanges();
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! Тренер не был добавлен.\nВозникло исключение: " + ex.Message, "Ошибка!");
            }
        }
Example #15
0
 private void LoadData(int Id)
 {
     this.CurrentObjectId = Id;
     using (var db = new SportEntities(SportProgramSettings.ConnectionString))
     {
         Trainers CurrentObject = db.Trainers.Find(Id);
         textBox1.Text = CurrentObject.TrainerId.ToString();
         textBox2.Text = CurrentObject.LastName;
         textBox3.Text = CurrentObject.FirstName;
         textBox4.Text = CurrentObject.MiddleName;
     }
 }
Example #16
0
        private void button_Action_Click(object sender, EventArgs e)
        {
            if (CurrentStudentId == -1 || CurrentSessionId == -1)
            {
                return;
            }
            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    // Получаем объект абонемента
                    Subscriptions sub = db.Subscriptions.Find(CurrentSubscription.SubscriptionId);
                    CurrentSubscription = sub;
                    // Регистрация и удаление с сессии
                    StudentsInSessions presence = db.StudentsInSessions
                                                  .Where(x => x.StudentId == CurrentStudentId && x.SessionId == CurrentSessionId)
                                                  .FirstOrDefault();
                    if (presence == null)
                    {
                        if (sub.SubHoursLeft == 0)
                        {
                            MessageBox.Show("У ученика закончились часы посещения");
                            return;
                        }

                        db.StudentsInSessions.Add(new StudentsInSessions
                        {
                            SessionId = CurrentSessionId,
                            StudentId = CurrentStudentId
                        }
                                                  );
                        sub.SubHoursLeft--;
                        button_Action.Text = LABEL_UNREG;
                    }
                    else
                    {
                        db.StudentsInSessions.Remove(presence);
                        sub.SubHoursLeft++;
                        button_Action.Text = LABEL_REG;
                    }

                    db.SaveChanges();

                    UpdateVisitsInfo(sub.SubHoursLeft, sub.SubHoursMax);
                }

                RefreshSISList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка при регистрации ученика на занятие.\n\nError: " + ex);
            }
        }
Example #17
0
        public string GetTrainerReport(int trainerId, DateTime from, DateTime to, bool isDetailed)
        {
            StringBuilder sb = new StringBuilder();

            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                // Находим тренера
                Trainers trainer = db.Trainers.Find(trainerId);
                // Заполняем шапку отчёта
                sb.AppendLine($"Отчёт сформирован {DateTime.Now}");
                sb.AppendLine($"Тренер: {trainer.LastName} {trainer.FirstName} {trainer.MiddleName} (TrainerId {trainer.TrainerId})");
                sb.AppendLine($"Границы отчёта: С `{from.ToShortDateString()}` ПО `{to.ToShortDateString()}`");
                sb.AppendLine();
                // Получаем список групп, подконтрольных тренеру
                int[] trainerGroupIds = db.Groups.Where(x => x.TrainerId == trainerId).Select(x => x.GroupId).ToArray();
                if (trainerGroupIds.Length == 0)
                {
                    sb.AppendLine("Этот тренер не тренирует никаких групп.");
                    return(sb.ToString());
                }
                // Получаем список сессий, проведенных тренером за указанный период
                var sessions = db.Sessions.Where(x => trainerGroupIds.Contains(x.GroupId) && from <= x.Date && x.Date <= to).OrderBy(x => x.Date).ThenBy(x => x.Time);
                if (sessions.Count() == 0)
                {
                    sb.AppendLine("У тренера не было занятий в этом периоде.");
                    return(sb.ToString());
                }
                foreach (Sessions s in sessions)
                {
                    int studentsCount = s.StudentsInSessions.Count();
                    sb.AppendLine($"{s.Date.ToShortDateString()} {s.Time} [ {studentsCount} ] {s.Groups.Name} (GroupId {s.GroupId})");
                    if (isDetailed)
                    {
                        StringBuilder sbStudents = new StringBuilder();
                        var           students   = s.StudentsInSessions.ToList();
                        sbStudents.AppendLine("Ученики:");
                        if (studentsCount == 0)
                        {
                            sbStudents.AppendLine("\t <<никого не было>>");
                        }
                        for (int i = 0; i < students.Count; i++)
                        {
                            sbStudents.AppendLine($"\t{i + 1}. {students[i].Students.LastName} {students[i].Students.FirstName} {students[i].Students.MiddleName} (StudentId {students[i].Students.StudentId})");
                        }
                        sbStudents.AppendLine();
                        sb.Append(sbStudents.ToString());
                    }
                }
            }

            return(sb.ToString());
        }
Example #18
0
 private void LoadData(int Id)
 {
     using (var db = new SportEntities(SportProgramSettings.ConnectionString))
     {
         this.CurrentObjectId = Id;
         Groups CurrentObject = db.Groups.Find(Id);
         textBox1.Text    = CurrentObject.GroupId.ToString();
         textBox2.Text    = CurrentObject.Name;
         textBox3.Text    = CurrentObject.Description;
         textBox4.Text    = $"(ИД {CurrentObject.Trainers.TrainerId}) {CurrentObject.Trainers.LastName}";
         CurrentTrainerId = CurrentObject.Trainers.TrainerId;
     }
 }
Example #19
0
        private void SetCurrentStudent(int studentId)
        {
            if (studentId == -1)
            {
                MessageBox.Show("Ошибка чтения карты, попробуйте еще раз.");
                return;
            }

            if (studentId == 0)
            {
                CurrentStudentId           = studentId;
                CurrentSubscribeId         = -1;
                label_StudentFullName.Text = string.Empty;
                label_StudentId.Text       = string.Empty;

                SubsPageLast    = 0;
                SubsPageCurrent = 0;
                PageNavigationUpdate(0, 0);

                PageSubscriptions.Clear();
                listBox_Subscriptions.Items.Clear();
                ShowSubscription(-1);


                MessageBox.Show("Эта карта не привязана ни к одному ученику.");
                return;
            }

            try
            {
                CurrentStudentId = studentId;
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    Students student = db.Students.Find(CurrentStudentId);
                    if (student == null)
                    {
                        MessageBox.Show($"Нет ученика с ИД {CurrentStudentId}");
                        return;
                    }

                    label_StudentId.Text       = student.StudentId.ToString();
                    label_StudentFullName.Text = $"{student.FirstName} {student.MiddleName} {student.LastName}";
                }

                RefreshSubscriptionList(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка при выборе ученика. Exception: " + ex);
            }
        }
Example #20
0
        private void FillAll()
        {
            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                CurrentSession        = db.Sessions.Find(CurrentSessionId);
                groupBox_Session.Text = $"Занятие (Ид {CurrentSessionId})";
                label_FromName.Text   = $"Форма регистрации на занятие «{CurrentSession.Groups.Name}»";
                Trainers train = CurrentSession.Groups.Trainers;
                label_SessionTrainer.Text = $"{train.FirstName} {train.MiddleName} {train.LastName}";
                label_SessionGroup.Text   = CurrentSession.Groups.Name;
                label_SessionTime.Text    = $"{CurrentSession.Date.ToShortDateString()} {CurrentSession.Time}";
            }

            RefreshSISList();
        }
Example #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            ObjectListForm selectGroupForm = new ObjectListForm(SearchForm.GROUPS);

            selectGroupForm.ShowDialog();
            if (selectGroupForm.CheckedId == -1)
            {
                return;
            }
            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                Groups group = db.Groups.Find(selectGroupForm.CheckedId);
                textBox2.Text  = $"(ИД {group.GroupId}) {group.Name}";
                CurrentGroupId = group.GroupId;
            }
        }
Example #22
0
 private void SetCurrentGroup(int groupId)
 {
     try
     {
         CurrentGroupId = groupId;
         using (var db = new SportEntities(SportProgramSettings.ConnectionString))
         {
             Groups group = db.Groups.Find(CurrentGroupId);
             box_Group.Text = $"[Ид {group.GroupId}] {group.Name} ({group.Trainers.LastName})";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Произошла ошибка при выборе группы. Exception: " + ex);
     }
 }
Example #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            ObjectListForm selectTrainerForm = new ObjectListForm(SearchForm.TRAINERS);

            selectTrainerForm.ShowDialog();
            if (selectTrainerForm.CheckedId == -1)
            {
                return;
            }
            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                Trainers trainer = db.Trainers.Find(selectTrainerForm.CheckedId);
                textBox4.Text    = $"(ИД {trainer.TrainerId}) {trainer.LastName}";
                CurrentTrainerId = trainer.TrainerId;
            }
        }
Example #24
0
 private void button_Delete_Click(object sender, EventArgs e)
 {
     try
     {
         using (var db = new SportEntities(SportProgramSettings.ConnectionString))
         {
             Schedule CurrentObject = db.Schedule.Find(CurrentObjectId);
             db.Schedule.Remove(CurrentObject);
             db.SaveChanges();
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! Не удалось удалить занятие.\nВозникло исключение: " + ex.Message, "Ошибка!");
     }
 }
Example #25
0
        private void button1_Click(object sender, EventArgs e)
        {
            ObjectListForm selectStudentForm = new ObjectListForm(SearchForm.STUDENTS);

            selectStudentForm.ShowDialog();
            if (selectStudentForm.CheckedId == -1)
            {
                return;
            }
            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                Students student = db.Students.Find(selectStudentForm.CheckedId);
                labelStudent.Text =
                    $"(Ид {student.StudentId}) {student.FirstName} {student.MiddleName} {student.LastName}";
                CurrentStudentId = selectStudentForm.CheckedId;
            }
        }
Example #26
0
        private void button_Delete_Click(object sender, EventArgs e)
        {
            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    Subscriptions sub = db.Subscriptions.First(x => x.SubscriptionId == CurrentSubscribeId);

                    db.Subscriptions.Remove(sub);
                    db.SaveChanges();

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка при удалении записи. Exception: " + ex);
            }
        }
Example #27
0
        private void button_SaveAdd_Click(object sender, EventArgs e)
        {
            if (!CheckFields())
            {
                return;
            }
            try
            {
                using (var db = new SportEntities(SportProgramSettings.ConnectionString))
                {
                    DateTime             startDate = new DateTime(Years[box_StartDateYear.SelectedIndex], box_StartDateMonth.SelectedIndex, int.Parse(box_StartDateDay.Text));
                    DateTime             formDate  = new DateTime(Years[box_StartDateYear.SelectedIndex], box_StartDateMonth.SelectedIndex, int.Parse(box_StartDateDay.Text));
                    List <Subscriptions> subs      = new List <Subscriptions>();
                    for (int i = 0; i < SportProgramSettings.Subscribe_DurationList[box_Duration.SelectedIndex]; i++)
                    {
                        Subscriptions sub = new Subscriptions
                        {
                            StudentId    = CurrentStudentId,
                            GroupId      = CurrentGroupId,
                            BuyTime      = DateTime.Now,
                            IsUnlimited  = radioButton_TypeUnlim.Checked,
                            SubHoursMax  = (int?)numeric_Hours.Value,
                            SubHoursLeft = (int)numeric_Hours.Value,
                            DateStart    = startDate.AddDays(0),
                            DateEnd      = formDate.AddMonths(i + 1).AddDays(-1)
                        };
                        subs.Add(sub);
                        startDate = sub.DateEnd.AddDays(1);
                    }
                    db.Subscriptions.AddRange(subs);
                    db.SaveChanges();

                    IsNewAdded = true;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Произошла ошибка при сохранении данных. Exception: " + ex);
            }
        }
Example #28
0
        private void buttonChooseTarget_Click(object sender, EventArgs e)
        {
            ObjectListForm olf;

            if (IsTrainer)
            {
                olf = new ObjectListForm(SearchForm.TRAINERS);
                olf.ShowDialog();
                if (olf.CheckedId == -1)
                {
                    return;
                }
            }
            else
            {
                olf = new ObjectListForm(SearchForm.STUDENTS);
                olf.ShowDialog();
                if (olf.CheckedId == -1)
                {
                    return;
                }
            }

            CurrentTargetId = olf.CheckedId;
            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                if (IsTrainer)
                {
                    Trainers t = db.Trainers.Find(olf.CheckedId);
                    textBoxCurrentTarget.Text = $"(ИД {t.TrainerId}) {t.LastName} {t.FirstName} {t.MiddleName}";
                }
                else
                {
                    Students t = db.Students.Find(olf.CheckedId);
                    textBoxCurrentTarget.Text = $"(ИД {t.StudentId}) {t.LastName} {t.FirstName} {t.MiddleName}";
                }
            }
        }
Example #29
0
 private void UpdateData(object sender, EventArgs e)
 {
     if (!CheckAllFields())
     {
         return;
     }
     try
     {
         using (var db = new SportEntities(SportProgramSettings.ConnectionString))
         {
             Trainers CurrentObject = db.Trainers.Find(CurrentObjectId);
             CurrentObject.LastName   = textBox2.Text;
             CurrentObject.FirstName  = textBox3.Text;
             CurrentObject.MiddleName = textBox4.Text;
             db.SaveChanges();
         }
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Ошибка! Изменения тренера не были сохранены.\nВозникло исключение: " + ex.Message, "Ошибка!");
     }
 }
Example #30
0
        private void RefreshSISList()
        {
            listBox_Students.Items.Clear();
            using (var db = new SportEntities(SportProgramSettings.ConnectionString))
            {
                var students = db.StudentsInSessions.Where(x => x.SessionId == CurrentSessionId).Join(
                    db.Students,      // второй набор
                    p => p.StudentId, // свойство-селектор объекта из первого набора
                    c => c.StudentId, // свойство-селектор объекта из второго набора
                    (p, c) => new     // результат
                {
                    c.StudentId,
                    c.LastName,
                    c.FirstName,
                    c.MiddleName,
                }).ToList();
                //List<Students> students = db.Students.SqlQuery($"SELECT * FROM Students WHERE StudentId IN (SELECT * FROM StudentsInSessions WHERE SessionId = {CurrentSessionId})").ToList();

                foreach (var s in students)
                {
                    listBox_Students.Items.Add($"[Ид {s.StudentId}] {s.LastName} {s.FirstName} {s.MiddleName}");
                }
            }
        }