Ejemplo n.º 1
0
        public void DeleteSubj()
        {
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res = db.Orderlines;
                    if (Subj.SubjectId != 1 && !CheckRecordBeforDelete(Subj))
                    {
                        if (dialogService.YesNoDialog("Точно нужно удалить эту запись?") == true)
                        {
                            //changing DB
                            //we find all the records in which we have the desired Id and make a replacement
                            foreach (OrderLine order in res)
                            {
                                if (order.Subject.SubjectId == Subj.SubjectId)
                                {
                                    order.Subject = db.Subjects.Find(new Subject()
                                    {
                                        SubjectId = 1
                                    }.SubjectId);
                                }
                            }
                            db.Subjects.Remove(db.Subjects.Find(Subj.SubjectId));
                            db.SaveChanges();
                            //changing collection
                            AuthorSubjects.Remove(Subj);
                            SubjRecords.Remove(Subj);

                            Subj          = SubjRecords[0];
                            SelectedSubj2 = Subj;
                        }
                    }
                    else
                    {
                        dialogService.ShowMessage("Нельзя удалить эту запись");
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
 //===================THIS METHOD IS FOR DELETE RECORDS FROM WORKTYPES TABLES==============
 public void DeleteWorkType()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res = db.Orderlines;
             if (WorkType.WorkTypeId != 1 && !CheckRecordBeforDelete(WorkType))
             {
                 if (dialogService.YesNoDialog("Точно нужно удалить эту запись?") == true)
                 {
                     //changing DB
                     //we find all the records in which we have the desired Id and make a replacement
                     foreach (OrderLine order in res)
                     {
                         if (order.WorkType.WorkTypeId == WorkType.WorkTypeId)
                         {
                             //here we replace deleting record on "---"
                             order.WorkType = db.WorkTypes.Find(new WorkType()
                             {
                                 WorkTypeId = 1
                             }.WorkTypeId);
                         }
                     }
                     //here we remove a record from DB
                     db.WorkTypes.Remove(db.WorkTypes.Find(WorkType.WorkTypeId));
                     db.SaveChanges();
                     //changing collection
                     WorkTypesRecords.Remove(WorkType);
                 }
             }
             else
             {
                 dialogService.ShowMessage("Нельзя удалить эту запись");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 3
0
 //===================THIS METHOD IS FOR ADD RECORDS SUBJECTS TABLE==============
 public void AddSubj(string newSubName)
 {
     Subj.SubName = newSubName;
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res2 = db.Subjects.Any(o => o.SubName == Subj.SubName);
             if (!res2)
             {
                 if (!string.IsNullOrEmpty(Subj.SubName) || Subj.SubName != "---")
                 {
                     Subj.SubName.Trim();
                     if (Subj.SubName[0] == ' ')
                     {
                         dialogService.ShowMessage("Нельзя добавить пустую строку");
                         return;
                     }
                     db.Subjects.Add(Subj);
                     db.SaveChanges();
                     SubjRecords.Clear();
                     LoadSubjectsData();
                     Subj          = new Subject();
                     SelectedSubj2 = Subj;
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 dialogService.ShowMessage("Уже есть такое название в базе данных");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 4
0
 //===================THIS METHOD IS FOR ADD RECORDS IN WORKTYPE TABLES==============
 public void AddWorkType(string newName)
 {
     WorkType.TypeOfWork = newName;
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res = db.WorkTypes.Any(o => o.TypeOfWork == WorkType.TypeOfWork);
             if (!res)
             {
                 if (!string.IsNullOrEmpty(WorkType.TypeOfWork) || WorkType.TypeOfWork != "---")
                 {
                     WorkType.TypeOfWork = WorkType.TypeOfWork.ToLower();
                     WorkType.TypeOfWork.Trim();
                     if (WorkType.TypeOfWork[0] == ' ')
                     {
                         dialogService.ShowMessage("Нельзя добавить пустую строку");
                         return;
                     }
                     db.WorkTypes.Add(WorkType);
                     db.SaveChanges();
                     WorkTypesRecords.Clear();
                     LoadWorkTypesData();
                     WorkType = new WorkType();
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 dialogService.ShowMessage("Уже есть такое название в базе данных");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 5
0
 //===================THIS METHOD IS FOR ADD RECORDS IN STATUS TABLES==============
 public void AddStatus(string newName)
 {
     Status.StatusName = newName;
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res4 = db.Statuses.Any(o => o.StatusName == Status.StatusName);
             if (!res4)
             {
                 if (!string.IsNullOrEmpty(Status.StatusName))
                 {
                     Status.StatusName = Status.StatusName.ToLower();
                     Status.StatusName.Trim();
                     if (Status.StatusName[0] == ' ')
                     {
                         dialogService.ShowMessage("Нельзя добавить пустую строку");
                         return;
                     }
                     db.Statuses.Add(Status);
                     db.SaveChanges();
                     StatusRecords.Clear();
                     LoadStatusData();
                     Status = new Status();
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 dialogService.ShowMessage("Уже есть такое название в базе данных");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 6
0
 //===================THIS METHOD IS FOR DELETE RECORDS FROM STATUS TABLES==============
 public void DeleteAuthorStatus()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res = db.Authors;
             if (AuthorStatus.AuthorStatusId != 1 && !CheckRecordBeforDelete(AuthorStatus))
             {
                 if (dialogService.YesNoDialog("Точно нужно удалить эту запись?") == true)
                 {
                     //changing DB
                     //we find all the records in which we have the desired Id and make a replacement
                     foreach (Author item in res)
                     {
                         if (item.AuthorStatus.AuthorStatusId == AuthorStatus.AuthorStatusId)
                         {
                             item.AuthorStatus = db.AuthorStatuses.Find(new AuthorStatus()
                             {
                                 AuthorStatusId = 1
                             }.AuthorStatusId);
                         }
                     }
                     db.AuthorStatuses.Remove(db.AuthorStatuses.Find(AuthorStatus.AuthorStatusId));
                     db.SaveChanges();
                     //changing collection
                     AuthorStatusRecords.Remove(AuthorStatus);
                 }
             }
             else
             {
                 dialogService.ShowMessage("Нельзя удалить эту запись");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 7
0
 //===================THIS METHOD IS FOR DELETE RECORDS FROM STATUS TABLES==============
 public void DeleteUniversity()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res = db.Universities.ToList();
             int len = res.Count();
             if (University.UniversityId != 1 && !CheckRecordBeforDelete(University))
             {
                 if (dialogService.YesNoDialog("Точно нужно удалить эту запись?") == true)
                 {
                     //changing DB
                     //we find all the records in which we have the desired Id and make a replacement
                     for (int i = 0; i < len; i++)
                     {
                         if (res[i].UniversityId == University.UniversityId)
                         {
                             res[i] = db.Universities.Find(1);
                         }
                     }
                     db.Universities.Remove(db.Universities.Find(University.UniversityId));
                     db.SaveChanges();
                     //changing collection
                     UniversityRecords.Remove(University);
                 }
             }
             else
             {
                 dialogService.ShowMessage("Нельзя удалить эту запись");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 8
0
 //===================THIS METHOD IS FOR EDIT RECORDS IN STATUS TABLES==============
 public void EditUniversity(string newName)
 {
     if (University.UniversityName == "---")
     {
         dialogService.ShowMessage("Нельзя редактировать эту запись");
         return;
     }
     University.UniversityName = newName;
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res4 = db.Universities.Find(University.UniversityId);
             if (res4 != null)
             {
                 //changing DB
                 University.UniversityName.Trim();
                 University.City.Trim();
                 if (University.UniversityName[0] == ' ' || University.City[0] == ' ')
                 {
                     dialogService.ShowMessage("Нельзя добавить пустую строку");
                     return;
                 }
                 res4.UniversityName = University.UniversityName;
                 res4.City           = University.City;
                 db.SaveChanges();
                 UniversityRecords.Clear();
                 LoadUniversityData();
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 9
0
        //===================THIS METHOD IS FOR EDIT RECORDS IN DIRECTIONS TABLE==============
        public void EditDir(string newDirName)
        {
            if (Dir.DirectionName == "---")
            {
                dialogService.ShowMessage("Нельзя редактировать эту запись");
                return;
            }
            Dir.DirectionName = newDirName;
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res1 = db.Directions.Find(Dir.DirectionId);
                    if (res1 != null)
                    {
                        //changing DB
                        res1.DirectionName = Dir.DirectionName.ToLower();
                        Dir.DirectionName.Trim();

                        db.SaveChanges();
                        DirRecords.Clear();
                        LoadDirectionsData();
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 10
0
        //===================THIS METHOD IS FOR EDIT RECORDS IN SUBJECTS TABLE==============
        public void EditSubj(string newSubName)
        {
            if (Subj.SubName == "---")
            {
                dialogService.ShowMessage("Нельзя редактировать эту запись");
                return;
            }
            Subj.SubName = newSubName;

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res2 = db.Subjects.Find(Subj.SubjectId);
                    if (res2 != null)
                    {
                        //changing DB
                        res2.SubName = Subj.SubName;
                        db.SaveChanges();
                        SubjRecords.Clear();
                        LoadSubjectsData();
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 11
0
 //===================THIS METHOD IS FOR EDIT RECORDS IN  WORKTYPES TABLES==============
 public void EditWorkType(string newName)
 {
     if (WorkType.TypeOfWork == "---")
     {
         dialogService.ShowMessage("Нельзя редактировать эту запись");
         return;
     }
     WorkType.TypeOfWork = newName;
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res = db.WorkTypes.Find(WorkType.WorkTypeId);
             if (res != null)
             {
                 //changing DB
                 res.TypeOfWork = WorkType.TypeOfWork.ToLower();
                 db.SaveChanges();
                 WorkTypesRecords.Clear();
                 LoadWorkTypesData();
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 12
0
 private void DeleteRecord(Records i, string msg)
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             //хз , как эта движуха работае в реале. Не удаляется ли чего нужного... надо тестить
             if (!dialogService.YesNoDialog(msg))
             {
                 return;
             }
             OrderLine tmpOrder = db.Orderlines.Where(c => c.OrderLineId == i.RecordId).FirstOrDefault();
             if (tmpOrder != null)
             {
                 db.Orderlines.Remove(tmpOrder);
                 db.SaveChanges();
             }
             Records.Clear();
             LoadData();
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 13
0
 //===================THIS METHOD IS FOR EDIT RECORDS IN STATUS TABLES==============
 public void EditAuthorStatus()
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             var res4 = db.AuthorStatuses.Find(AuthorStatus.AuthorStatusId);
             if (res4 != null)
             {
                 //changing DB
                 res4.AuthorStatusName = AuthorStatus.AuthorStatusName.ToLower();
                 db.SaveChanges();
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 14
0
        private void SaveUserData()
        {
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    //initial data validation
                    string error;
                    error = UsverDataValidation();
                    if (error != null)
                    {
                        dialogService.ShowMessage(error);
                        return;
                    }

                    // тут мы проверяем контакты по БД.Если есть такие, то подтянуть
                    //нужную person вместо того, чтоб создавать новую с одинковыми контактами


                    Persone tmpPerson = CheckExistPerson(_Contacts.Contacts, 0);
                    if (tmpPerson == null)
                    {
                        dialogService.ShowMessage("Проблемы со связью с базой данных\n на стадии проверки существования контактов " +
                                                  "\n при добавлении нового пользователя");
                        return;
                    }

                    if (tmpPerson.PersoneId != 0)
                    {
                        Persone  persone     = new Persone();
                        Contacts OldContacts = new Contacts();
                        //тут мы находим Person , которая уже имеется в БД с такими же контактами для дальнейшей работы с ней
                        //в текущем контексте
                        Usver.Persone = db.Persones.Where(e => e.PersoneId == tmpPerson.PersoneId).FirstOrDefault();                        OldContacts = db.Contacts.Where(c => c.ContactsId == Usver.Persone.Contacts.ContactsId).FirstOrDefault();
                        OldContacts   = db.Contacts.Where(c => c.ContactsId == Usver.Persone.Contacts.ContactsId).FirstOrDefault();
                        //тут мы подготавливаем данные для вызова окна сравнения текущих данных личности пользователя
                        //и предыдущих его данных
                        _Contacts.OldPersoneCompare     = (Persone)persone.CloneExceptVirtual();
                        _Contacts.CurPersoneCompare     = (Persone)this.Usver.Persone.CloneExceptVirtual();
                        _Contacts.TmpContacts           = (Contacts)OldContacts.CloneExceptVirtual();
                        _Contacts.OldTmpContactsCompare = (Contacts)OldContacts.CloneExceptVirtual();
                        _Contacts.TmpContactsCompare    = (Contacts)this._Contacts.Contacts.CloneExceptVirtual();
                        //вызывем окно сравнения
                        CompareContatctsWindow compareContatctsWindow = new CompareContatctsWindow(this);
                        showWindow.ShowDialog(compareContatctsWindow);

                        //если в результате сравнения не был принят ни один из вариантов
                        if (!_Contacts.saveCompareResults)
                        {
                            //тут лучше придумать диалоговое окно с радиокнопками , для выбора вариантов действия
                            // - отменить прием заказа и отправить пользователя закрыть окно приема заказа
                            //т.к. не понятно как реализовать закрытие окна из вьюмодел не вмешиваяся в сраный мввм
                            //но в идеале закрыть окно приема заказа. Думаю, что это потянет за собой перепил по всему проекту
                            //процедуры закрытия окна.
                            // -
                            if (dialogService.YesNoDialog("Не сохранен ни один из вариантов...\n" +
                                                          "Отменить процедуру оформления нового пользователя?"))
                            {
                                dialogService.ShowMessage("Ок. Тогда просто закройте окно оформления нового пользователя");
                                _Contacts.Contacts = OldContacts;
                                cancelSaveUserData = true;
                                return;
                            }
                            else
                            {
                                dialogService.ShowMessage("В базе данных не могут дублироваться контакты\n" +
                                                          "Задайте другие контактные данные пользователя в окне приема заказа.");
                                _Contacts.Contacts = OldContacts;
                                cancelSaveUserData = true;
                                return;
                            };
                        }

                        bool personeCompare  = persone.ComparePersons(persone, _Contacts.Persone);
                        bool contactsCompare = _Contacts.CompareContacts(persone.Contacts, _Contacts.Contacts);

                        if (!personeCompare)
                        {
                            db.Entry(Usver.Persone).State = EntityState.Modified;
                            Usver.Persone.CopyExeptVirtualIdPhoto(Usver.Persone, _Contacts.Persone);
                        }
                        if (!contactsCompare)
                        {
                            db.Entry(OldContacts).State = EntityState.Modified;
                            _Contacts.Contacts.CopyExceptVirtualAndId(OldContacts, _Contacts.Contacts);
                            Usver.Persone.Contacts = _Contacts.Contacts;
                        }
                        //db.SaveChanges();
                    }
                    else
                    {
                        Usver.Persone.Contacts = _Contacts.Contacts;
                    }
                    //  Usver.User.Pass = SHA.ComputeSHA256Hash(Usver.User.Pass);
                    Usver.Persone.Dates.Add(Usver.Date);
                    Usver.User.Persone = Usver.Persone;
                    Usver.User.Persone.PersoneDescription = Usver.PersoneDescription;
                    db.Users.Add(Usver.User);
                    db.SaveChanges();
                    newUserSave = true;
                    if (!anyUsersInDB)
                    {
                        dialogService.ShowMessage("Данные сохранены. Теперь нужно авторизироваться...");
                    }
                    else
                    {
                        dialogService.ShowMessage("Данные сохранены.");
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 15
0
 private void SaveNewOrder(string name, string phone1, int dir, int workType,
                           int subj, decimal price, decimal prepayment, int source)
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             OrderLine Order = new OrderLine();
             Persone = new Persone()
             {
                 Name = name
             };
             Contacts Contacts = new Contacts()
             {
                 Phone1 = phone1
             };
             Order.Direction = db.Directions.Find(new Direction()
             {
                 DirectionId = dir
             }.DirectionId);
             Order.Client = new Client()
             {
                 Persone = Persone
             };
             Order.WorkType = db.WorkTypes.Find(new WorkType()
             {
                 WorkTypeId = workType
             }.WorkTypeId);
             Order.Dates = new Dates()
             {
                 DateOfReception = DateTime.Now,
                 DeadLine        = DateTime.Now.AddDays(5),
                 AuthorDeadLine  = DateTime.Now.AddDays(4)
             };
             Order.Subject = db.Subjects.Find(new Subject()
             {
                 SubjectId = subj
             }.SubjectId);
             Order.Money = new Money()
             {
                 Price = price, Prepayment = prepayment
             };
             Order.Status = db.Statuses.Find(new Status()
             {
                 StatusId = 2
             }.StatusId);
             Order.Source = db.Sources.Find(new Source()
             {
                 SourceId = source
             }.SourceId);
             Order.User = db.Users.Where(e => e.UserId == Usver.UserId).FirstOrDefault();
             db.Orderlines.Add(Order);
             db.SaveChanges();
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 16
0
 private void AddAuthor(string name, string surname, string nickName,
                        string phone1, int authorstatus, int subj1, int subj2,
                        int dir1, int dir2, double authorrating)
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             Persone = new Persone()
             {
                 Name     = name,
                 Surname  = surname,
                 NickName = nickName
             };
             Contacts Contacts = new Contacts()
             {
                 Phone1 = phone1
             };
             Persone.Contacts    = Contacts;
             Author              = new Author();
             Author.AuthorStatus = db.AuthorStatuses.Find(new AuthorStatus()
             {
                 AuthorStatusId = authorstatus
             }.AuthorStatusId);
             Author.Subject.Add(db.Subjects.Find(new Subject()
             {
                 SubjectId = subj1
             }.SubjectId));
             Author.Subject.Add(db.Subjects.Find(new Subject()
             {
                 SubjectId = subj2
             }.SubjectId));
             Author.Direction.Add(db.Directions.Find(new Direction()
             {
                 DirectionId = dir1
             }.DirectionId));
             Author.Direction.Add(db.Directions.Find(new Direction()
             {
                 DirectionId = dir2
             }.DirectionId));
             Author.Rating = authorrating;
             Persone.Author.Add(Author);
             db.Persones.Add(Persone);
             db.SaveChanges();
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 17
0
        private void LoadPreviosData()//setting default values in DB ​​on first start
        {
            using (StudentuConteiner db = new StudentuConteiner())
            {
                {
                    if (db.Universities.Count() == 0)
                    {
                        db.Universities.Add(new University()
                        {
                            UniversityName = "---", City = "---"
                        });
                        db.Universities.Add(new University()
                        {
                            UniversityName = "(КНУ) Криворожский национальный университет", City = "Кривой Рог"
                        });
                        db.Universities.Add(new University()
                        {
                            UniversityName = "(КГПУ) Криворожский государственный педагогический университет", City = "Кривой Рог"
                        });
                        db.Universities.Add(new University()
                        {
                            UniversityName = "(КЭИ) Киевский экономический", City = "Кривой Рог"
                        });
                        db.Universities.Add(new University()
                        {
                            UniversityName = "Одесская юридическая академия", City = "Кривой Рог"
                        });
                        db.Universities.Add(new University()
                        {
                            UniversityName = "(НМетАУ) Национальная Металлургическая академия Украины", City = "Кривой Рог"
                        });
                        db.Universities.Add(new University()
                        {
                            UniversityName = "(ДонНТУ) Донецкий национальный технический университет", City = "Кривой Рог"
                        });
                        db.SaveChanges();
                    }

                    if (db.Statuses.Count() == 0)
                    {
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "---"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "принят"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "готов"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "выполняется"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "отдан заказчику"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "на оценке"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "принят на доработку"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "дорабатывается"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "отказ от выполнения"
                        });
                        db.Statuses.Add(new Status()
                        {
                            StatusName = "ждем новостей от заказчика"
                        });
                        db.SaveChanges();
                    }
                    //add default authorstatuses
                    if (db.AuthorStatuses.Count() == 0)
                    {
                        db.AuthorStatuses.Add(new AuthorStatus()
                        {
                            AuthorStatusName = "---"
                        });
                        db.AuthorStatuses.Add(new AuthorStatus()
                        {
                            AuthorStatusName = "работает"
                        });
                        db.AuthorStatuses.Add(new AuthorStatus()
                        {
                            AuthorStatusName = "уволен"
                        });
                        db.AuthorStatuses.Add(new AuthorStatus()
                        {
                            AuthorStatusName = "не проверен"
                        });
                        db.AuthorStatuses.Add(new AuthorStatus()
                        {
                            AuthorStatusName = "проверяется"
                        });
                        db.AuthorStatuses.Add(new AuthorStatus()
                        {
                            AuthorStatusName = "на паузе"
                        });
                    }
                    if (db.Directions.Count() == 0)
                    {
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "---"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "физика"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "математика"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "химия"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "экономика"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "бухгалтерский учет"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "история"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "педагогика"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "психология"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "программирование"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "информатика"
                        });
                        db.Directions.Add(new Direction()
                        {
                            DirectionName = "лингвистика"
                        });
                        db.SaveChanges();
                    }
                    //add default worktype
                    if (db.WorkTypes.Count() == 0)
                    {
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "---"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "контрольная"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "курсовая"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "дипломная"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "реферат"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "отчет по практике"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "распечатка"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "ксерокопия"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "сканкопия"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "набор текста"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "чертежи"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "тезисы"
                        });
                        db.WorkTypes.Add(new WorkType()
                        {
                            TypeOfWork = "статья"
                        });
                        db.SaveChanges();
                    }
                    //add default subjects
                    if (db.Subjects.Count() == 0)
                    {
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "---"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "высшая математика"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "теория вероятностей"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "математическая статистика"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "ТОЭ(теоретические основы электротехники)"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "дошкольная педагогика"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "украинский язык"
                        });
                        db.Subjects.Add(new Subject()
                        {
                            SubName = "английский язык"
                        });
                        db.SaveChanges();
                    }
                    //add default author
                    if (db.Authors.Count() == 0)
                    {
                        Persone Persone = new Persone()
                        {
                            NickName = "---"
                        };
                        Contacts Contacts = new Contacts()
                        {
                            Phone1 = "---"
                        };
                        Persone.Contacts = Contacts;
                        Author Author = new Author();
                        Author.AuthorStatus = db.AuthorStatuses.Find(new AuthorStatus()
                        {
                            AuthorStatusId = 1
                        }.AuthorStatusId);
                        Author.Subject.Add(db.Subjects.Find(new Subject()
                        {
                            SubjectId = 1
                        }.SubjectId));
                        Persone.Author.Add(Author);
                        db.Persones.Add(Persone);
                        db.SaveChanges();
                    }
                    //add default sources
                    if (db.Sources.Count() == 0)
                    {
                        db.Sources.Add(new Source()
                        {
                            SourceName = "---"
                        });
                        db.Sources.Add(new Source()
                        {
                            SourceName = "Вайбер"
                        });
                        db.Sources.Add(new Source()
                        {
                            SourceName = "Соцсети"
                        });
                        db.Sources.Add(new Source()
                        {
                            SourceName = "Сайт"
                        });
                        db.Sources.Add(new Source()
                        {
                            SourceName = "Оформлен лично в офисе"
                        });
                        db.SaveChanges();
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private void SaveEditUserData(int usrId)
        {
            //db.Dates.Attach(date);

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    //initial data validation
                    string error;
                    error = UsverDataValidation();
                    if (error != null)
                    {
                        dialogService.ShowMessage(error);
                        return;
                    }

                    // here we check contacts in the database. If there are such, then pull up
                    // the desired person instead of creating a new one with single contacts

                    Persone tmpPerson = CheckExistPerson(_Contacts.Contacts, usrId);
                    if (tmpPerson == null)
                    {
                        dialogService.ShowMessage("Проблемы со связью с базой данных\n на стадии проверки существования контактов " +
                                                  "\n при редактирования данных пользователя");
                        return;
                    }

                    if (tmpPerson.PersoneId != 0)
                    {
                        Persone prs = CompareContacts(tmpPerson.PersoneId);
                        if (prs == null)
                        {
                            dialogService.ShowMessage("Редактирование данных пользователя прервано");
                            return;
                        }
                        prs.PersoneId = Usver.Persone.PersoneId;
                        Usver.Persone = prs;
                    }
                    else
                    {
                        Usver.Persone.Contacts = _Contacts.Contacts;
                    }

                    Dates dt = Usver.Persone.Dates.Where(e => e.Persone.PersoneId == Usver.Persone.PersoneId).FirstOrDefault();
                    dt = Usver.Date;
                    //Usver.User.Pass = SHA.ComputeSHA256Hash(Usver.User.Pass);
                    Usver.User.Persone = Usver.Persone;
                    Usver.User.Persone.PersoneDescription                 = Usver.PersoneDescription;
                    db.Entry(Usver.User).State                            = EntityState.Modified;
                    db.Entry(Usver.User.Persone).State                    = EntityState.Modified;
                    db.Entry(Usver.User.Persone.Contacts).State           = EntityState.Modified;
                    db.Entry(Usver.User.Persone.PersoneDescription).State = EntityState.Modified;
                    db.Entry(dt).State = EntityState.Modified;
                    db.SaveChanges();

                    dialogService.ShowMessage("Данные сохранены.");
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 19
0
        private void SaveAuthorData()
        {
            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    string errValidation = ValidAuthorDataCheck();
                    if (errValidation != null)
                    {
                        errValidation += "\n\n Данные автора НЕ были сохранены";
                        dialogService.ShowMessage(errValidation);
                        return;
                    }
                    else
                    {
                        //if we  need to modified entrie
                        if (PersoneContactsData.Author.AuthorId != 0)
                        {
                            db.Entry(PersoneContactsData.Persone).State = EntityState.Modified;
                            db.Entry(PersoneContactsData.Date).State    = EntityState.Modified;
                            db.Entry(PersoneContactsData.Author).State  = EntityState.Modified;
                            db.Entry(_Dir.Dir).State   = EntityState.Modified;
                            db.Entry(_Subj.Subj).State = EntityState.Modified;
                            db.Entry(PersoneContactsData.PersoneDescription).State = EntityState.Modified;
                        }
                        PersoneContactsData.Persone.Contacts = _Contacts.Contacts;
                        if (PersoneContactsData.Author.AuthorId != 0)
                        {
                            PersoneContactsData.Persone.Dates[0] = PersoneContactsData.Date;
                        }
                        else
                        {
                            PersoneContactsData.Persone.Dates.Add(PersoneContactsData.Date);
                        }

                        PersoneContactsData.Persone.PersoneDescription = PersoneContactsData.PersoneDescription;
                        PersoneContactsData.Author.Persone             = PersoneContactsData.Persone;
                        PersoneContactsData.Author.AuthorStatus        = db.AuthorStatuses.Find(_AuthorStatus.AuthorStatus.AuthorStatusId);
                        if (PersoneContactsData.Author.AuthorId == 0)
                        {
                            db.Authors.Add(PersoneContactsData.Author);
                        }
                        db.SaveChanges();

                        //удаляем из списка направлений упоминания об авторе, если в списке направлений автора нет более того или  иного направления после правки
                        // remove the author’s mention from the list of directions if the author’s list does not have more than one direction or another after editing
                        var res = db.Directions.ToList();
                        foreach (var i in res)
                        {
                            if (i.Author.Contains(PersoneContactsData.Author) && !_Dir.AuthorDirections.Contains(i))
                            {
                                i.Author.Remove(PersoneContactsData.Author);
                            }
                            continue;
                        }


                        foreach (Direction item in _Dir.AuthorDirections)
                        {
                            var res1 = db.Directions.Find(item.DirectionId);
                            if (res1 != null && !res1.Author.Contains(PersoneContactsData.Author))
                            {
                                //changing DB
                                if (PersoneContactsData.Author.AuthorId != 0)
                                {
                                    res1.Author.Add(PersoneContactsData.Author);
                                    continue;
                                }
                                else
                                {
                                    res1.Author.Add(PersoneContactsData.Author);
                                }
                                continue;
                            }
                        }
                        db.SaveChanges();

                        //удаляем из списка предметов упоминания об авторе, если в списке предметов автора нет более того или  иного направления после правки
                        // remove the author’s mention from the list of subjects if the author’s list does not have more than one subject or another after editing
                        var res2 = db.Subjects.ToList();
                        foreach (var i in res2)
                        {
                            if (i.Authors.Contains(PersoneContactsData.Author) && !_Subj.AuthorSubjects.Contains(i))
                            {
                                i.Authors.Remove(PersoneContactsData.Author);
                            }
                            continue;
                        }
                        //here we add author in subjects
                        foreach (Subject item in _Subj.AuthorSubjects)
                        {
                            var res1 = db.Subjects.Find(item.SubjectId);
                            if (res1 != null)
                            {
                                //changing DB
                                res1.Authors.Add(PersoneContactsData.Author);
                                continue;
                            }
                            else
                            {
                                res1.Authors.Add(PersoneContactsData.Author);
                            }
                            continue;
                        }
                        db.SaveChanges();

                        dialogService.ShowMessage("Данные автора сохранены");
                        //обнуляем поля окна
                        //clear window fields
                        if (PersoneContactsData.Author.AuthorId == 0)
                        {
                            _Contacts = new _Contacts();
                            PersoneContactsData.Persone = new Persone();
                            _AuthorStatus = new _AuthorStatus();
                            PersoneContactsData.Author = new Author();
                            PersoneContactsData.Date   = new Dates();
                            _Subj = new _Subject();
                            _Dir  = new _Direction();
                            PersoneContactsData.PersoneDescription = new PersoneDescription();
                        }
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 20
0
        private void AddFakeAuthors()
        {
            //GetFakeOrder
            _Test test = new _Test();

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    DateTime  date  = new DateTime(2021, 2, 01);
                    OrderLine Order = new OrderLine();
                    for (int i = 0; i < 50; i++)
                    {
                        Author  author  = new Author();
                        Persone persone = new Persone();
                        author.Direction.Add(db.Directions.Find(test.rnd.Next(1, 12)));
                        author.Subject.Add(db.Subjects.Find(test.rnd.Next(1, 9)));
                        persone.Male       = test.RandomBool();
                        persone.Female     = !persone.Male;
                        persone.Name       = test.RandName(persone.Male);
                        persone.Surname    = test.RandSurName(persone.Male);
                        persone.Patronimic = test.RandPatronimic(persone.Male);
                        persone.Contacts   = new Contacts()
                        {
                            Phone1 = test.RandPhone(), Phone2 = test.RandPhone()
                        };
                        persone.PersoneDescription = new PersoneDescription()
                        {
                            Description = test.RandDescription()
                        };
                        persone.Dates.Add(new Dates()
                        {
                            DayBirth = new DateTime(test.rnd.Next(1955, 2001),
                                                    test.rnd.Next(1, 12), test.rnd.Next(1, 28)),
                            StartDateWork = new DateTime(test.rnd.Next(2008, 2021),
                                                         test.rnd.Next(1, 12), test.rnd.Next(1, 28))
                        }
                                          );

                        //persone.PersoneDescription = new PersoneDescription() { BlackList=};
                        author.Rating       = test.rnd.Next(0, 10);
                        persone.NickName    = persone.Name + "_" + author.Direction[0].DirectionName;
                        author.Persone      = persone;
                        author.AuthorStatus = db.AuthorStatuses.Find(test.rnd.Next(1, 6));



                        db.Authors.Add(author);

                        db.SaveChanges();
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 21
0
 //===================THIS METHOD IS FOR ADD RECORDS IN STATUS TABLES==============
 public void AddUniversity(string newName)
 {
     University.UniversityName = newName;
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             bool flag = false;
             var  res4 = db.Universities.ToList();
             foreach (var item in res4)
             {
                 if (item.City == University.City && item.UniversityName == University.UniversityName)
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 if (!string.IsNullOrEmpty(University.UniversityName))
                 {
                     University.UniversityName.Trim();
                     University.City.Trim();
                     if (University.UniversityName[0] == ' ' || University.City[0] == ' ')
                     {
                         dialogService.ShowMessage("Нельзя добавить пустую строку");
                         return;
                     }
                     db.Universities.Add(University);
                     db.SaveChanges();
                     UniversityRecords.Clear();
                     LoadUniversityData();
                     University = new University();
                 }
                 else
                 {
                     return;
                 }
             }
             else
             {
                 dialogService.ShowMessage("Уже есть такое название в базе данных");
             }
         }
         catch (ArgumentNullException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (OverflowException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.SqlClient.SqlException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
         catch (System.Data.Entity.Core.EntityException ex)
         {
             dialogService.ShowMessage(ex.Message);
         }
     }
 }
Ejemplo n.º 22
0
        private void AddFakeOrders()
        {
            //GetFakeOrder
            _Test test = new _Test();

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    //над присоеденить к контексту
                    int       orderNumer = 26500;
                    DateTime  date       = new DateTime(2014, 2, 01);
                    OrderLine Order      = new OrderLine();
                    for (int i = orderNumer; i < orderNumer + 30000; i++)
                    {
                        Order.OrderNumber = i;

                        Order.Direction    = db.Directions.Find(test.rnd.Next(1, 12));
                        Order.WorkType     = db.WorkTypes.Find(test.rnd.Next(1, 13));
                        Order.Subject      = db.Subjects.Find(test.rnd.Next(1, 9));
                        Order.Source       = db.Sources.Find(test.rnd.Next(1, 6));
                        Order.Status       = db.Statuses.Find(test.rnd.Next(1, 10));
                        Order.WorkInCredit = test.RandomBool();
                        Order.Dates        = new Dates()
                        {
                            DateOfReception = date, DeadLine = date.AddDays(test.rnd.Next(1, 30))
                        };
                        Order.Money = new Money()
                        {
                            Price = test.rnd.Next(500, 1001), Prepayment = 500
                        };
                        Order.SaveToBase      = test.RandomBool();
                        Order.Saved           = true;
                        Order.WorkDescription = test.RandWorkDescription();
                        //Order.Author =
                        Persone Persone = new Persone();
                        Persone.PriceRating = test.rnd.Next(0, 10);
                        Persone.Male        = test.RandomBool();
                        Persone.Female      = !Persone.Male;
                        Persone.Name        = test.RandName(Persone.Male);
                        Persone.Surname     = test.RandSurName(Persone.Male);
                        Persone.Patronimic  = test.RandPatronimic(Persone.Male);
                        Persone.Contacts    = new Contacts()
                        {
                            Phone1 = test.RandPhone(), Phone2 = test.RandPhone()
                        };
                        Persone.PersoneDescription = new PersoneDescription()
                        {
                            Description = test.RandDescription()
                        };

                        Order.Client = new Client()
                        {
                            Persone = Persone, Course = test.rnd.Next(1, 4)
                        };
                        Order.Client.Universities.Add(db.Universities.Find(test.rnd.Next(1, 7)));
                        Order.User = db.Users.Find(test.rnd.Next(0, 2));

                        //нижние две строки кода - признак того, что что-то пошло не тиак, но вроде работает....
                        db.Configuration.AutoDetectChangesEnabled = false;
                        db.Configuration.ValidateOnSaveEnabled    = false;
                        db.Orderlines.Add(Order);

                        db.SaveChanges();

                        db.Entry(Order).State = EntityState.Modified;
                        Order.ParentId        = Order.OrderLineId;

                        db.SaveChanges();

                        db.Entry(Order).State = EntityState.Detached;
                        if (i % test.rnd.Next(1, 11) == 0)
                        {
                            date = date.AddDays(1);
                            if (date.Year == DateTime.Now.Year && date.Month == DateTime.Now.Month && date.Day > DateTime.Now.Day)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 23
0
        //===================THIS METHOD IS FOR ADD RECORDS IN DIRECTIONS TABLE==============
        public void  AddDir(string newDirName)
        {
            if (Dir != null)
            {
                Dir.DirectionName = newDirName;
            }
            else
            {
                Dir = new Direction()
                {
                    DirectionName = newDirName
                }
            };

            using (StudentuConteiner db = new StudentuConteiner())
            {
                try
                {
                    var res1 = db.Directions.Any(o => o.DirectionName == Dir.DirectionName);
                    if (!res1)
                    {
                        if (!string.IsNullOrEmpty(Dir.DirectionName) || Dir.DirectionName != "---")
                        {
                            Dir.DirectionName = Dir.DirectionName.ToLower();
                            Dir.DirectionName.Trim();
                            if (Dir.DirectionName[0] == ' ')
                            {
                                dialogService.ShowMessage("Нельзя добавить пустую строку");
                                return;
                            }
                            db.Directions.Add(Dir);
                            db.SaveChanges();
                            DirRecords.Clear();
                            LoadDirectionsData();
                            Dir          = new Direction();
                            SelectedDir2 = Dir;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        dialogService.ShowMessage("Уже есть такое название в базе данных");
                    }
                }
                catch (ArgumentNullException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (OverflowException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityCommandExecutionException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
                catch (System.Data.Entity.Core.EntityException ex)
                {
                    dialogService.ShowMessage(ex.Message);
                }
            }
        }