private void UpdateStudent(int studentId)
 {
     using (var context = new HostelModelContainer()) {
         // обновление информации про студента
         Student student = context.StudentSet.Single(s => s.Id == studentId);
         Person  person  = student.Person;
         person.FirstName           = txtFN.Text;
         person.LastName            = txtLN.Text;
         person.MiddleName          = txtMN.Text;
         person.Passport            = txtPasp.Text;
         person.RegistrationAddress = txtAddr.Text;
         Person father = person.Father;
         if (father == null)
         {
             father = new Person();
             context.PersonSet.Add(father);
             person.Father = father;
         }
         father.FirstName  = txtFFN.Text;
         father.LastName   = txtFLN.Text;
         father.MiddleName = txtFMN.Text;
         Person mother = person.Mother;
         if (mother == null)
         {
             mother = new Person();
             context.PersonSet.Add(mother);
             person.Mother = mother;
         }
         mother.FirstName  = txtMFN.Text;
         mother.LastName   = txtMLN.Text;
         mother.MiddleName = txtMMN.Text;
         context.SaveChanges();
     }
 }
 private void DeactivateStudent(int studentId)
 {
     //  деактивация студента
     using (var context = new HostelModelContainer()) {
         Student student = context.StudentSet.Single(s => s.Id == studentId);
         student.Active = false;
         context.SaveChanges();
     }
 }
Beispiel #3
0
 // Поселить студента в комнату. Если студент уже где-то живет то он буоет выселен, если roomId == -1 то он будет просто выселен
 public static (Occupation, Occupation) SetOccupation(int studentId, int roomId)
 {
     using (var context = new HostelModelContainer()) {
         Occupation previousOcupation = context.OccupationSet.SingleOrDefault(o => o.Student.Id == studentId && o.Active);
         if (previousOcupation != null)
         {
             Room room = previousOcupation.Room; // дозагрузка информации про комнату
         }
         if (roomId != -1)
         {
             if (previousOcupation == null || (previousOcupation.Room.Id != roomId))
             {
                 if (previousOcupation != null)
                 {
                     previousOcupation.Active = false;
                 }
                 Occupation occupation = new Occupation()
                 {
                     Active   = true,
                     Student  = context.StudentSet.Single(s => s.Id == studentId),
                     Room     = context.RoomSet.Single(r => r.Id == roomId),
                     FromDate = DateTime.Today
                 };
                 context.OccupationSet.Add(occupation);
                 context.SaveChanges();
                 return(previousOcupation, occupation);
             }
             else
             {
                 return(previousOcupation, previousOcupation);
             }
         }
         else
         {
             if (previousOcupation != null)
             {
                 previousOcupation.Active = false;
                 context.SaveChanges();
             }
             return(previousOcupation, null);
         }
     }
 }
        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            // проверки корректности
            String errorText = null;

            if (dpkPaymentDate.SelectedDate == null)
            {
                errorText = "Дата оплаты не указана";
            }
            double amount = 0;

            if (tbxAmount.Text.Length > 0 && !Double.TryParse(tbxAmount.Text, out amount))
            {
                errorText = "Ввеедено некорректное значение для стоимости оплаты";
            }
            if (amount < 0)
            {
                errorText = "Стоимость оплаты не может быть отрицательной";
            }
            if (amount > 0 && tbxPaymentNumber.Text.Length == 0)
            {
                errorText = "Не задан номер счета";
            }

            // изменения
            if (errorText == null)
            {
                using (var context = new HostelModelContainer()) {
                    context.Set(typeof(Occupation)).Attach(occupation);
                    Order   order   = occupation.Order;
                    Payment payment = new Payment()
                    {
                        Order       = order,
                        Amount      = amount,
                        PaymentDate = dpkPaymentDate.SelectedDate.Value,
                        Number      = tbxPaymentNumber.Text
                    };
                    context.PaymentSet.Add(payment);
                    context.SaveChanges();
                }
                Close();
            }
            else
            {
                lblError.Content = errorText;
            }
        }
 private int CreateNewStudent()
 {
     using (var context = new HostelModelContainer()) {
         // создание нового студента
         Person person = new Person();
         context.PersonSet.Add(person);
         person.FirstName           = txtFN.Text;
         person.LastName            = txtLN.Text;
         person.MiddleName          = txtMN.Text;
         person.Passport            = txtPasp.Text;
         person.RegistrationAddress = txtAddr.Text;
         Person father = new Person();
         context.PersonSet.Add(father);
         person.Father     = father;
         father.FirstName  = txtFFN.Text;
         father.LastName   = txtFLN.Text;
         father.MiddleName = txtFMN.Text;
         Person mother = new Person();
         context.PersonSet.Add(mother);
         person.Mother     = mother;
         mother.FirstName  = txtMFN.Text;
         mother.LastName   = txtMLN.Text;
         mother.MiddleName = txtMMN.Text;
         Student student = new Student();
         context.StudentSet.Add(student);
         student.Person = person;
         int   facultyId = faculties[cmbFaculty.SelectedIndex].Id;
         int   year      = Int32.Parse(txtYear.Text);
         int   number    = Int32.Parse(txtGrpNumber.Text);
         Group group     = (from g in context.GroupSet
                            where g.Faculty.Id == facultyId && g.StudyYear == year && g.Number == number
                            select g).FirstOrDefault();
         student.Group  = group;
         student.Active = true;
         context.SaveChanges();
         return(student.Id);
     }
 }
Beispiel #6
0
        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            // проверки корректности
            String errorText = null;

            if (dpkFrom.SelectedDate == null)
            {
                errorText = "Дата заселения не указана";
            }
            if (dpkTo.SelectedDate != null && dpkFrom.SelectedDate != null && dpkFrom.SelectedDate > dpkTo.SelectedDate)
            {
                errorText = "Дата заселения должна быть больше даты выселения";
            }
            double price = 0;

            if (tbxPrice.Text.Length > 0 && !Double.TryParse(tbxPrice.Text, out price))
            {
                errorText = "Ввеедено некорректное значение для цены";
            }
            if (price < 0)
            {
                errorText = "Цена не может быть отрицательной";
            }
            if (price > 0 && tbxOrderNumber.Text.Length == 0)
            {
                errorText = "Не задан номер счета";
            }
            if (price > 0 && dpkOrder.SelectedDate == null)
            {
                errorText = "Не задана дата платежа";
            }
            if (price == 0 && payments > 0)
            {
                errorText = "Нельзя удалить счет по которому есть платежи";
            }

            // изменения
            if (errorText == null)
            {
                using (var context = new HostelModelContainer()) {
                    context.Set(typeof(Occupation)).Attach(occupation);
                    occupation.FromDate = dpkFrom.SelectedDate.Value;
                    occupation.ToDate   = dpkTo.SelectedDate;

                    Order order = occupation.Order;
                    if (price > 0)
                    {
                        if (order == null)
                        {
                            order = new Order()
                            {
                                Ocupation = occupation
                            };
                            context.OrderSet.Add(order);
                        }
                        order.Price     = price;
                        order.OrderDate = dpkOrder.SelectedDate.Value;
                        order.Number    = tbxOrderNumber.Text;
                    }

                    if (order != null && price == 0)
                    {
                        context.OrderSet.Remove(order);
                    }
                    context.SaveChanges();
                }
                Close();
            }
            else
            {
                lblError.Content = errorText;
            }
        }