private User FindeUser(int usverId) { using (StudentuConteiner db = new StudentuConteiner()) { try { User usver = db.Users.Where(o => o.UserId == usverId).FirstOrDefault(); return(usver); } 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); } return(null); } }
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); } } }
//===================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); } } }
//===================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); } } }
//===================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); } } }
//===================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); } } }
//===================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); } } }
//check if the record has links with other tables before deleting private bool CheckRecordBeforDelete(Subject subj) { using (StudentuConteiner db = new StudentuConteiner()) { try { //check in Orderlines table var res = db.Orderlines; foreach (OrderLine item in res) { if (item.Subject.SubjectId == subj.SubjectId || item.Subject.SubName == subj.SubName) { return(true); } } //if previos check in Orderlines table wasn't true - check in Author table var authorRes = db.Authors; foreach (Author item in authorRes) { foreach (Subject i in item.Subject) { if (i.SubjectId == subj.SubjectId || i.SubName == subj.SubName) { return(true); } } } return(false); } 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); } } //есть подозрение, что такой подход не очень то правомерен, но пока лень с этим заморачиваться return(false); }
//===================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); } } }
private void OrderLineCall() { using (StudentuConteiner db = new StudentuConteiner()) { try { var list = db.Orderlines.Include("AfterDoneDescriptions") .Include("Directions") .Include("Statuses") .Include("Dates") .ToList(); var res = (from a in list select new { OrderNumber = a.OrderNumber, Direction = a.Direction.DirectionName, Status = a.Status.StatusName, Deadline = a.Dates.DeadLine }); if (res != null) { if (dialogService.YesNoDialog("Номер клиента в черном списке!\nПросмотреть причины?") == true) { //тут над допиливать } else { dialogService.ShowMessage("Этот номер телефона \n\n Н Е\n\n в черном списке"); } } } 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); } } }
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); } } }
//private static string HashPassword(string input) //{ // Create a function to easily hash passwords // return SHA.ComputeSHA256Hash(input); // One function to hash using SHA256 with EasyEncryption library, returns a string. //} //private static bool PasswordsMatch(string userInput, string savedTextFilePassword) //{ // Function to check if the user input the correct password // string hashedInput = HashPassword(userInput); // Hash user input to check it against the one stored in a file // return string.Equals(userInput, savedTextFilePassword); //} //make user indentification private User Identification(User usver) { using (StudentuConteiner db = new StudentuConteiner()) { try { var tmp = db.Users.ToList(); foreach (var item in tmp) { if (item.UserNickName == usver.UserNickName) { if (string.Equals(usver.Pass, item.Pass)) //if (PasswordsMatch(usver.Pass, item.Pass)) { //here we check user status. If he is not work now - authorezation will be failed Dates dt = db.Dates.Where(e => e.Persone.PersoneId == item.Persone.PersoneId).FirstOrDefault(); if (dt.StartDateWork > dt.EndDateWork) { return(item); } else { return(null); } } } } return(null); } 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); } } return(null); }
//===================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); } } }
private void LoadDataForUsersList() { Records.Clear(); using (StudentuConteiner db = new StudentuConteiner()) { try { var COrders = db.Users.ToList().OrderBy(o => o.Persone.Surname); if (COrders == null) { dialogService.ShowMessage("Проблемы со связью с БД при попытке отобразить список пользователей"); return; } foreach (var item in COrders) { Dates date = item.Persone.Dates.Where(e => e.Persone.PersoneId == item.Persone.PersoneId).FirstOrDefault(); UserRecord record = new UserRecord { UserId = item.UserId, NickName = item.UserNickName, FIO = item.Persone.Surname + " " + item.Persone.Name + " " + item.Persone.Patronimic, Accessname = item.AccessName, StartDateWork = date.StartDateWork, FireDATE = date.EndDateWork, Firedate = date.EndDateWork < date.StartDateWork? "работает" : date.EndDateWork.ToString(("d")) }; Records.Add(record); } } 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); } } }
//load data array from "Directions" table public Author CheckAuthorContacts() { using (StudentuConteiner db = new StudentuConteiner()) { try { var list = db.Authors.Include("Persone").ToList(); foreach (var item in list) { if (TmpContacts.Phone1 != "+380" && item.Persone.Contacts.Phone1 == TmpContacts.Phone1 || TmpContacts.Phone2 != "---" && item.Persone.Contacts.Phone1 == TmpContacts.Phone2 || TmpContacts.Phone3 != "---" && item.Persone.Contacts.Phone1 == TmpContacts.Phone3 || TmpContacts.Phone2 != "---" && item.Persone.Contacts.Phone2 == TmpContacts.Phone2 || TmpContacts.Phone3 != "---" && item.Persone.Contacts.Phone2 == TmpContacts.Phone3 || TmpContacts.Phone1 != "---" && item.Persone.Contacts.Phone3 == TmpContacts.Phone1 || TmpContacts.Email1 != "---" && item.Persone.Contacts.Email1 == TmpContacts.Email1 || TmpContacts.Email2 != "---" && item.Persone.Contacts.Email1 == TmpContacts.Email2 || TmpContacts.Email2 != "---" && item.Persone.Contacts.Email2 == TmpContacts.Email2 || TmpContacts.VK != "---" && item.Persone.Contacts.VK == TmpContacts.VK || TmpContacts.Skype != "---" && item.Persone.Contacts.Skype == TmpContacts.Skype) { return(item); } } return(null); } 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); } } return(null); }
private void DefaultDataLoadForEditUser(int usrId) { AccessNameList = new ObservableCollection <string>() { "Админ", "Мастер-админ" }; _Contacts = new _Contacts(); DefaultPhoto = "default_avatar.png"; Usver = new PersoneContactsData(); using (StudentuConteiner db = new StudentuConteiner()) { try { Usver.User = db.Users.Where(e => e.UserId == usrId).FirstOrDefault(); Usver.Persone = Usver.User.Persone; _Contacts.Contacts = Usver.User.Persone.Contacts; Usver.Date = Usver.Persone.Dates.Where(e => e.Persone.PersoneId == Usver.Persone.PersoneId).FirstOrDefault(); Usver.PersoneDescription = Usver.Persone.PersoneDescription; //SelectedRecord = Usver; //Usver.Persone = db.Persones.Where(e => e.PersoneId == Usver.User.Persone.PersoneId).FirstOrDefault(); //_Contacts.Contacts = db.Contacts.Where(e => e.ContactsId == Usver.User.Persone.Contacts.ContactsId).FirstOrDefault(); //Dates date = Usver.Persone.Dates.Where(e => e.Persone.PersoneId == Usver.Persone.PersoneId).FirstOrDefault(); //db.Dates.Attach(date); //Usver.Date = date; } 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); } } }
//===================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); } } }
private void AllAuthorsCall() { using (StudentuConteiner db = new StudentuConteiner()) { try { var result = db.Authors. Include("Subject") .Include("Direction") .Include("Persone") .Include("AuthorStatus").ToList(); AuthorsRecord record; int count = result.Count(); for (int i = 1; i < count; i++) { record = new AuthorsRecord { Author = result[i], Persone = result[i].Persone, Contacts = result[i].Persone.Contacts }; AuthorsRecords.Add(record); } } 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); } } }
//===================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); } } }
//check if the record has links with other tables before deleting private bool CheckRecordBeforDelete(University university) { using (StudentuConteiner db = new StudentuConteiner()) { try { var res1 = db.Clients; foreach (var item in res1) { foreach (var i in item.Universities) { if (i.UniversityId == university.UniversityId || i.UniversityName == university.UniversityName) { return(true); } } } return(false); } 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); } } //есть подозрение, что такой подход не очень то правомерен, но пока лень с этим заморачиваться return(false); }
//===================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); } } }
//check if the record has links with other tables before deleting private bool CheckRecordBeforDelete(Source source) { using (StudentuConteiner db = new StudentuConteiner()) { try { //check in Orderlines table var res = db.Orderlines; foreach (OrderLine item in res) { if (item.Source.SourceId == source.SourceId || item.Source.SourceName == source.SourceName) { return(true); } } return(false); } 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); } } //есть подозрение, что такой подход не очень то правомерен, но пока лень с этим заморачиваться return(false); }
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); } } }
//check if the record has links with other tables before deleting private bool CheckRecordBeforDelete(AuthorStatus authorStatus) { using (StudentuConteiner db = new StudentuConteiner()) { try { var res = db.Authors.ToList(); foreach (Author item in res) { if (item.AuthorStatus.AuthorStatusId == authorStatus.AuthorStatusId || item.AuthorStatus.AuthorStatusName == authorStatus.AuthorStatusName) { return(true); } } return(false); } 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); } } //есть подозрение, что такой подход не очень то правомерен, но пока лень с этим заморачиваться return(false); }
//load data array from "Subjects" table private void LoadSubjectsData() { using (StudentuConteiner db = new StudentuConteiner()) { try { var list = db.Subjects.ToList <Subject>(); foreach (var item in list) { SubjRecords.Add( new Subject { SubjectId = item.SubjectId, SubName = item.SubName }); } Subj = SubjRecords[0]; SelectedSubj2 = Subj; } 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); } } }
//load data array from "Statuses" data private void LoadUniversityData() { using (StudentuConteiner db = new StudentuConteiner()) { try { var list = db.Universities.ToList(); foreach (var item in list) { UniversityRecords.Add( new University { UniversityId = item.UniversityId, UniversityName = item.UniversityName, City = item.City }); } University = UniversityRecords[0]; } 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); } } }
//load data array from "Directions" table public void LoadDirectionsData() { using (StudentuConteiner db = new StudentuConteiner()) { try { var list = db.Directions.ToList <Direction>(); foreach (var item in list) { DirRecords.Add( new Direction { DirectionId = item.DirectionId, DirectionName = item.DirectionName }); } Dir = DirRecords[0]; SelectedDir2 = Dir; } 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); } } }
private string CheckExistLogin(string newUserLogin) { string result = "По технической причине в текущий момент \n регистрация нового пользователя не возможна"; using (StudentuConteiner db = new StudentuConteiner()) { try { var tmp = db.Users.Where(e => e.UserNickName == newUserLogin).FirstOrDefault(); if (tmp != null) { result = "Текущий логин занят. Нужно задать другой"; } else { return(null); } } 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); } } return(result); }
//load data array from "Statuses" data private void LoadData() { using (StudentuConteiner db = new StudentuConteiner()) { try { var list = db.AuthorStatuses.ToList(); foreach (var item in list) { AuthorStatusRecords.Add( new AuthorStatus { AuthorStatusId = item.AuthorStatusId, AuthorStatusName = item.AuthorStatusName }); } AuthorStatus = AuthorStatusRecords[0]; } 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); } } }
//if returned null then db.Users has no entries private string CheckExistUser() { string result = "По технической причине в текущий момент \n регистрация нового пользователя не возможна"; using (StudentuConteiner db = new StudentuConteiner()) { try { if (UserId == 0 && db.Users.Count() > 0) { result = "Регистрировать новых пользователей может только администратор"; } else { return(null); } } 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); } } return(result); }