コード例 #1
0
ファイル: Message.cs プロジェクト: salted-fish-3kg/BiuBiuBiu
        /// <summary>
        /// 添加监听对象
        /// </summary>
        /// <param name="name"></param>
        public static Subject AttachSubject(string name)
        {
            if (subjects.ContainsKey(name))
            {
                return(null);
            }
            _Subject _subject = new _Subject();

            _subject.name = name;
            subjects.Add(name, _subject);
            return(_subject);
        }
コード例 #2
0
 private void AuthorDafaultDataLoad(Author author)
 {
     using (StudentuConteiner db = new StudentuConteiner())
     {
         try
         {
             db.Authors.Attach(author);
             _AuthorStatus = new _AuthorStatus();
             _AuthorStatus.AuthorStatus = author.AuthorStatus;
             _Contacts             = new _Contacts();
             _Contacts.Contacts    = author.Persone.Contacts;
             _Contacts.TmpContacts = _Contacts.Contacts;
             _Dir = new _Direction();
             foreach (var item in author.Direction)
             {
                 _Dir.AuthorDirections.Add(item);
             }
             //Date = new Dates();
             //Date = author.Persone.Dates[0];
             PersoneContactsData.Date    = author.Persone.Dates[0];
             PersoneContactsData.Persone = author.Persone;
             //Persone = author.Persone;
             //PersoneDescription = author.Persone.PersoneDescription;
             PersoneContactsData.PersoneDescription = author.Persone.PersoneDescription;
             _Subj = new _Subject();
             foreach (var item in author.Subject)
             {
                 _Subj.AuthorSubjects.Add(item);
             }
         }
         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);
         }
     }
 }
コード例 #3
0
        private void DefaultDataLoad()
        {
            DefaultPhoto = "default_avatar.png";
            //Author = new Author();
            _AuthorStatus = new _AuthorStatus();
            _Contacts     = new _Contacts();
            //Date = new Dates();
            _Dir = new _Direction();
            //Persone = new Persone();
            PersoneContactsData = new PersoneContactsData();

            //PersoneDescription = new PersoneDescription();
            _Subj         = new _Subject();
            dialogService = new DefaultDialogService();
            showWindow    = new DefaultShowWindowService();
        }
コード例 #4
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);
                }
            }
        }