private void personsListBox_SelectedIndexChanged(object sender, EventArgs e) { string personItem = this.personsListBox.SelectedItem.ToString(); int index = personItem.IndexOf(' '); string _Name = personItem.Substring(0, index); personItem = personItem.Substring(index + 1, personItem.Length - index - 1); index = personItem.IndexOf(' '); string _MiddleName = personItem.Substring(0, index); string _SurName = personItem.Substring(index + 1, personItem.Length - index - 1); string _GroupName = this.groupsComboBox.SelectedItem.ToString(); CurrentPerson = new Person(_GroupName, _Name, _MiddleName, _SurName, true); this.nameTextBox.Text = CurrentPerson.Name; this.surNameTextBox.Text = CurrentPerson.Surname; this.MidNameTextBox.Text = CurrentPerson.MiddleName; this.mobilePhoneTextBox.Text = CurrentPerson.MobilePhone; this.homePhoneTextBox.Text = CurrentPerson.HomePhone; this.workPhoneTextBox.Text = CurrentPerson.WorkPhone; this.emailTextBox.Text = CurrentPerson.Email; this.addrTextBox.Text = CurrentPerson.Addres; this.currentPhotoPath = CurrentPerson.PhotoPath; if (this.currentPhotoPath == null) { this.currentPhotoPath = CurrentDirrectoryReturner.getDirrectory() + "\\data\\noPhotoAvailable.jpg"; } var picStream = File.OpenRead(this.currentPhotoPath); this.photoPictureBox.Image = Image.FromStream(picStream); picStream.Close(); }
private void addButton_Click(object sender, EventArgs e) { if (this.groupsComboBox.Text.Length != 0) { String _GroupName = this.groupsComboBox.Text; String _Name = this.nameTextBox.Text; String _MiddleName = this.MidNameTextBox.Text; String _SurName = this.surNameTextBox.Text; String _MobilePhone = this.mobilePhoneTextBox.Text; String _HomePhone = this.homePhoneTextBox.Text; String _WorkPhone = this.workPhoneTextBox.Text; String _Email = this.emailTextBox.Text; String _Addres = this.addrTextBox.Text; String _PhotoPath = CurrentDirrectoryReturner.getDirrectory() + "\\data\\Photos\\" + _GroupName + "_" + _SurName + "_" + _Name + "_" + _MiddleName + ".jpg"; Person newPerson = new Person(_GroupName, _Name, _MiddleName, _SurName, _MobilePhone, _HomePhone, _WorkPhone, _Email, _Addres, _PhotoPath); int res = newPerson.save(); if (res == 0) { this.updateGroupsList(); this.updatePersonsList(); File.Copy(this.currentPhotoPath, _PhotoPath, true); MessageBox.Show("Успешное сохранение!", "Успешно!"); } else { MessageBox.Show("Ошибка! Информаци не была сохранена! Попробуйте повторить попытку!", "Ошибка!"); } } else { MessageBox.Show("Ошибка! Вы не указали группу для нового контакта!", "Ошибка!"); } }
public int delete() { string filePath = CurrentDirrectoryReturner.getDirrectory() + "//data//data.mdb"; DataBase dataBase = DataBase.getInstanceDB(filePath); string sqlQuery = "DELETE FROM [Persons] WHERE name='" + this.name + "' AND surname='" + this.surname + "' AND middlename='" + this.middleName + "' AND groupName='" + this.groupname + "'"; int res = dataBase.sendNonQuery(sqlQuery); return(res); }
public Groups() { string filePath = CurrentDirrectoryReturner.getDirrectory() + "//data//data.mdb"; DataBase dataBase = DataBase.getInstanceDB(filePath); this.countOfGroups = dataBase.selectCountDistinct("Persons", "groupName", ""); groups = new string[this.countOfGroups]; string sqlQuery = "SELECT DISTINCT [groupName] FROM [Persons]"; string[,] res = new string[this.countOfGroups, 1]; dataBase.sendQuery <string>(sqlQuery, 1, res); for (int i = 0; i < this.countOfGroups; i++) { String r = res[i, 0]; this.groups[i] = r; } }
public PersonsList(string _GroupName) { groupName = _GroupName; string filePath = CurrentDirrectoryReturner.getDirrectory() + "//data//data.mdb"; DataBase dataBase = DataBase.getInstanceDB(filePath); this.countOfPersons = dataBase.selectCount("Persons", "groupName", ""); personItem = new string[this.countOfPersons]; string sqlQuery = "SELECT name, middlename, surname FROM [Persons] WHERE groupName='" + groupName + "'"; string[,] res = new string[this.countOfPersons, 3]; dataBase.sendQuery <string>(sqlQuery, 3, res); for (int i = 0; i < this.countOfPersons; i++) { this.personItem[i] = res[i, 0] + " "; this.personItem[i] += (res[i, 1] + " "); this.personItem[i] += res[i, 2]; } }
public int update(Dictionary <String, String> UpdatedValues) { string filePath = CurrentDirrectoryReturner.getDirrectory() + "//data//data.mdb"; DataBase dataBase = DataBase.getInstanceDB(filePath); string sqlQuery = "UPDATE [Persons] SET "; int CountOfUpdating = UpdatedValues.Count(); for (int i = 0; i < CountOfUpdating; i++) { string upStr = UpdatedValues.Keys.ElementAt(i) + "='" + UpdatedValues.Values.ElementAt(i) + "'"; sqlQuery += upStr; if (i != CountOfUpdating - 1) { sqlQuery += ", "; } } String where = " WHERE name='" + this.name + "' AND surname='" + this.surname + "' AND middlename='" + this.middleName + "' AND groupName='" + this.groupname + "'"; sqlQuery += where; return(dataBase.sendNonQuery(sqlQuery)); }
public int save() { string filePath = CurrentDirrectoryReturner.getDirrectory() + "//data//data.mdb"; DataBase dataBase = DataBase.getInstanceDB(filePath); string where = "groupName='" + this.groupname + "' AND name='" + this.name + "' AND surname='" + this.surname + "' AND middlename='" + this.middleName + "'"; int countOfSuchPersons = dataBase.selectCount("Persons", "*", where); if (countOfSuchPersons == 0) { string sqlQuery = "INSERT INTO [Persons] (name, surname, middlename, mobile_phone, home_phone, work_phone, email, address, photoPath, groupName) values ('" + this.name + "','" + this.surname + "','" + this.middleName + "','" + this.mobilePhone + "','" + this.homePhone + "','" + this.workPhone + "','" + this.email + "','" + this.addres + "','" + this.photoPath + "','" + this.groupname + "')"; int res = dataBase.sendNonQuery(sqlQuery); return(res); } else { return(countOfSuchPersons); } }
public Person(string _GroupName, string _Name, string _MiddleName, string _SurName, bool _GetFromDB) { this.groupname = _GroupName; this.name = _Name; this.surname = _SurName; this.middleName = _MiddleName; if (_GetFromDB) { string[,] resOfQuery = new string[1, 6]; string filePath = CurrentDirrectoryReturner.getDirrectory() + "//data//data.mdb"; DataBase dataBase = DataBase.getInstanceDB(filePath); string filter = "WHERE name='" + this.name + "' AND surname='" + this.surname + "' AND middlename='" + this.middleName + "' AND groupName='" + this.groupname + "'"; string sqlQuery = "SELECT mobile_phone, home_phone, work_phone, email, address, photoPath FROM [Persons] " + filter; dataBase.sendQuery <string>(sqlQuery, 6, resOfQuery); this.mobilePhone = resOfQuery[0, 0]; this.homePhone = resOfQuery[0, 1]; this.workPhone = resOfQuery[0, 2]; this.email = resOfQuery[0, 3]; this.addres = resOfQuery[0, 4]; this.photoPath = resOfQuery[0, 5]; } }
private void saveButton_Click(object sender, EventArgs e) { Dictionary <String, String> UpdatedValues = new Dictionary <String, String>(); if (!this.groupsComboBox.Text.Equals(this.CurrentPerson.Groupname)) { UpdatedValues.Add("groupName", this.groupsComboBox.Text); } if (!this.nameTextBox.Text.Equals(this.CurrentPerson.Name)) { UpdatedValues.Add("name", this.nameTextBox.Text); } if (!this.surNameTextBox.Text.Equals(this.CurrentPerson.Surname)) { UpdatedValues.Add("surname", this.surNameTextBox.Text); } if (!this.MidNameTextBox.Text.Equals(this.CurrentPerson.MiddleName)) { UpdatedValues.Add("middlename", this.MidNameTextBox.Text); } if (!this.mobilePhoneTextBox.Text.Equals(this.CurrentPerson.MobilePhone)) { UpdatedValues.Add("mobile_phone", this.mobilePhoneTextBox.Text); } if (!this.workPhoneTextBox.Text.Equals(this.CurrentPerson.WorkPhone)) { UpdatedValues.Add("work_phone", this.workPhoneTextBox.Text); } if (!this.homePhoneTextBox.Text.Equals(this.CurrentPerson.HomePhone)) { UpdatedValues.Add("home_phone", this.homePhoneTextBox.Text); } if (!this.emailTextBox.Text.Equals(this.CurrentPerson.Email)) { UpdatedValues.Add("email", this.emailTextBox.Text); } if (!this.addrTextBox.Text.Equals(this.CurrentPerson.Addres)) { UpdatedValues.Add("address", this.addrTextBox.Text); } if (!this.currentPhotoPath.Equals(this.CurrentPerson.PhotoPath) && !this.currentPhotoPath.Equals(CurrentDirrectoryReturner.getDirrectory() + "\\data\\noPhotoAvailable.jpg")) { try { String _GroupName = this.groupsComboBox.Text; String _Name = this.nameTextBox.Text; String _MiddleName = this.MidNameTextBox.Text; String _SurName = this.surNameTextBox.Text; String _PhotoPath = CurrentDirrectoryReturner.getDirrectory() + "\\data\\Photos\\" + _GroupName + "_" + _SurName + "_" + _Name + "_" + _MiddleName + ".jpg"; File.Copy(this.currentPhotoPath, _PhotoPath, true); UpdatedValues.Add("photoPath", _PhotoPath); }finally {} } if (UpdatedValues.Count > 0) { int res = this.CurrentPerson.update(UpdatedValues); if (res == 0) { this.updateGroupsList(); this.updatePersonsList(); MessageBox.Show("Изменения сохранены", "Успешно!"); } else { MessageBox.Show("Ошибка сохранения", "Ошибка"); } } else { MessageBox.Show("Отображаемые данные актуальны. Нет изменений для внесения в базу данных", "Внимание"); } /* * if (!this.currentPhotoPath.Equals(this.CurrentPerson.PhotoPath) && !this.currentPhotoPath.Equals(CurrentDirrectoryReturner.getDirrectory() + "\\data\\noPhotoAvailable.jpg")) * { * try * { * String _GroupName = this.groupsComboBox.Text; * String _Name = this.nameTextBox.Text; * String _MiddleName = this.MidNameTextBox.Text; * String _SurName = this.surNameTextBox.Text; * String _PhotoPath = CurrentDirrectoryReturner.getDirrectory() + "\\data\\Photos\\" + * _GroupName + "_" + _SurName + "_" + _Name + "_" + _MiddleName + ".jpg"; * File.Copy(this.currentPhotoPath, _PhotoPath, true); * MessageBox.Show("Фото обновленно успешно", "Успешно"); * } * catch (Exception exp) * { * MessageBox.Show("Ошибка замены фотографии", "Ошибка"); * } * }*/ }