public EditRecordWindow(DBStructureViewModel tmpSelectedRecord) { SelectedRecord = tmpSelectedRecord; InitializeComponent(); editNameText.Focus(); selectedToEditConverter(tmpSelectedRecord); Logger.Instance.LogInfo("editRecord window initialization completed"); }
public void addToDataBaseXML(DBStructureViewModel record) { try { this.dataBaseFileX.Element("persons").Add( new XElement("person", new XElement("ID", record.Id), new XElement("pesel", record.Pesel), new XElement("name", record.Name), new XElement("familyName", record.FamilyName), new XElement("birthDate", record.BirthDate), new XElement("phone", record.Phone) ) ); } catch (Exception) { throw; } }
public DBStructureViewModel userRecord() { try { if (!convertStringToInt(addPeselText.Text)) { AddErrorText.Text = "Pesel! - use numbers"; AddErrorBlock.Text = "Error(s):"; AddErrorText.Foreground = Brushes.Red; AddErrorBlock.Foreground = Brushes.Red; Logger.Instance.LogError("Error in pesel!"); if (!convertStringToInt(addPhoneText.Text)) { AddErrorText.Text = "Pesel! Phone! - use numbers"; Logger.Instance.LogError("Error in phone!"); } } else if (!convertStringToInt(addPhoneText.Text)) { AddErrorText.Text = "Phone! - use numbers"; AddErrorBlock.Text = "Error(s):"; AddErrorText.Foreground = Brushes.Red; AddErrorBlock.Foreground = Brushes.Red; Logger.Instance.LogError("Error in phone!"); } else { this.AddedRecord = new DBStructureViewModel() { Name = addNameText.Text, FamilyName = addFamilyText.Text, Phone = addPhoneText.Text, BirthDate = addBirthText.DisplayDate.Date, Pesel = addPeselText.Text, Id = ++InnerID }; Logger.Instance.LogInfo(string.Format("User added record with:\n\tFamilyName: {0}\n\tName: {1}\n\tPhone: {2}\n\tBirthDate: {3}\n\tPesel: {4}", AddedRecord.FamilyName, AddedRecord.Name, AddedRecord.Phone, AddedRecord.BirthDate, AddedRecord.Pesel)); } return this.AddedRecord; } catch (Exception ex) { Logger.Instance.LogError(string.Format("Error during creation of new record!\n{0}", ex.ToString())); return new DBStructureViewModel(); } }
private DBStructureViewModel fillMyDBRecord(string tmpSearch) { string name, familyName, phone, pesel; DateTime birth; string[] tmp = tmpSearch.Split('='); DBStructureViewModel tmpRecord = new DBStructureViewModel(); string caseString = tmp[0]; switch (caseString.ToLower().TrimEnd().TrimStart()) { case ("name"): { name = tmp[1]; tmpRecord.Name = name.ToLower(); break; } case ("family name"): { familyName = tmp[1]; tmpRecord.FamilyName = familyName.ToLower(); break; } case ("phone number"): { phone = tmp[1]; tmpRecord.Phone = phone.ToLower(); break; } case ("pesel"): { pesel = tmp[1]; tmpRecord.Pesel = pesel.ToLower(); break; } case ("birth date"): { birth = Convert.ToDateTime(tmp[1]); tmpRecord.BirthDate = birth; break; } default: { Exception ex = new Exception("No records found or wrong syntax"); throw ex; } } return tmpRecord; }
private void checkIfExiste(DBStructureViewModel searchedRecord) { foreach (var item in this.DBList) { if (FiltredDBList.Contains(item)) { continue; } else { if (!string.IsNullOrEmpty(searchedRecord.Name)) { if ((item.Name).ToLower().Contains(searchedRecord.Name)) { FiltredDBList.Add(item); continue; } } else if (!string.IsNullOrEmpty(searchedRecord.FamilyName)) { if ((item.FamilyName).ToLower().Contains(searchedRecord.FamilyName)) { FiltredDBList.Add(item); continue; } } else if (!string.IsNullOrEmpty(searchedRecord.Pesel)) { if ((item.Pesel).ToLower().Contains(searchedRecord.Pesel)) { FiltredDBList.Add(item); continue; } } else if (!string.IsNullOrEmpty(searchedRecord.Phone)) { if ((item.Phone).ToLower().Contains(searchedRecord.Phone)) { FiltredDBList.Add(item); continue; } } else if (searchedRecord.BirthDate > DateTime.MinValue) { if (DateTime.Compare(item.BirthDate, searchedRecord.BirthDate) == 0) { FiltredDBList.Add(item); continue; } } } } }
internal void Search() { try { Logger.Instance.LogInfo(string.Format("User tried to search: {0}", this.FilterString)); string[] tmpSearch = default(string[]); tmpSearch = FilterString.Split(';'); DBStructureViewModel searchedRecord = new DBStructureViewModel(); foreach (var item in tmpSearch) { searchedRecord = fillMyDBRecord(item); checkIfExiste(searchedRecord); } } catch (Exception) { throw; } }
public void AddNewRecord(DBStructureViewModel record) { try { _DBList.Add(record); fileSaved = false; } catch (Exception ex) { Logger.Instance.LogError(ex.Message); } }
private DBStructureViewModel editSaveRecord() { Logger.Instance.LogInfo("Trying to save record"); if (!convertStringToInt(editPeselText.Text)) { editErrors.Text = "Pesel! - use numbers"; editerrorBlock.Text = "Error(s):"; editErrors.Foreground = Brushes.Red; editerrorBlock.Foreground = Brushes.Red; Logger.Instance.LogError("Error in pesel!"); if (!convertStringToInt(editPhoneText.Text)) { editErrors.Text = "Pesel! Phone! - use numbers"; Logger.Instance.LogError("Error in phone!"); } } else if (!convertStringToInt(editPhoneText.Text)) { editErrors.Text = "Phone! - use numbers"; editerrorBlock.Text = "Error(s):"; editErrors.Foreground = Brushes.Red; editerrorBlock.Foreground = Brushes.Red; Logger.Instance.LogError("Error in phone!"); } else { this.EditedRecord = new DBStructureViewModel() { Name = editNameText.Text, FamilyName = editFamilyText.Text, BirthDate = editBirthText.DisplayDate.Date, Pesel = editPeselText.Text, Phone = editPhoneText.Text, Id = this.SelectedRecord.Id }; Logger.Instance.LogInfo(string.Format("User edited record with:\n\tFamilyName: {0}\n\tName: {1}\n\tPhone: {2}\n\tBirthDate: {3}\n\tPesel: {4}", EditedRecord.FamilyName, EditedRecord.Name, EditedRecord.Phone, EditedRecord.BirthDate, EditedRecord.Pesel)); } return this.EditedRecord; }
private void selectedToEditConverter(DBStructureViewModel selectedToEdited) { try { editNameText.Text = selectedToEdited.Name; editFamilyText.Text = selectedToEdited.FamilyName; editBirthText.Text = selectedToEdited.BirthDate.ToString(); editPeselText.Text = selectedToEdited.Pesel; editPhoneText.Text = selectedToEdited.Phone; Logger.Instance.LogInfo("Conversion completed"); } catch (Exception) { throw; } }