public static bool Edit(DataBaseItem item) { bool result = false; try { string sql = "UPDATE main SET" + " firstName = '" + item.firstName + "'," + " secondName = '" + item.secondName + "'," + " lastName = '" + item.lastName + "'," + " phone = '" + item.phone + "'," + " email = '" + item.email + "'," + " county = '" + item.county + "'," + " city = '" + item.city + "'," + " street = '" + item.street + "'," + " house = '" + item.house + "'," + " flat = '" + item.flat + "'" + " WHERE id='" + item.id + "';"; SQLiteCommand command = new SQLiteCommand(connection); command.CommandText = sql; command.ExecuteNonQuery(); return(true); } catch (Exception e) { } return(result); }
private void OKbutton_Click(object sender, RoutedEventArgs e) { if (dataBaseItem == null) { DataBaseItem item = new DataBaseItem(); item.firstName = firstname.textEdit.Text; item.phone = phone.textEdit.Text; item.email = email.textEdit.Text; if (DataBase.Add(item)) { Close(); } else { MessageBox.Show("Wrong data format"); } } else { dataBaseItem.firstName = firstname.textEdit.Text; dataBaseItem.phone = phone.textEdit.Text; dataBaseItem.email = email.textEdit.Text; if (DataBase.Edit(dataBaseItem)) { Close(); } else { MessageBox.Show("Wrong data format"); } } }
//Fname, Lname, Phone, Addr, Email public EditWindow(Window Owner, DataBaseItem dataBaseItem) { this.Owner = Owner; InitializeComponent(); firstname = AddControl("Имя:"); phone = AddControl("Телефон:"); email = AddControl("Email:"); if (dataBaseItem != null) { this.dataBaseItem = dataBaseItem; firstname.textEdit.Text = dataBaseItem.firstName; phone.textEdit.Text = dataBaseItem.phone; email.textEdit.Text = dataBaseItem.email; } }
//------------------------------------------------------------------------------------------------- public static bool Add(DataBaseItem dataBaseItem) { if (dataBaseItem == null) { return(false); } if (string.IsNullOrEmpty(dataBaseItem.firstName)) { return(false); } if (string.IsNullOrEmpty(dataBaseItem.phone)) { return(false); } if (string.IsNullOrEmpty(dataBaseItem.email)) { return(false); } try { string sql = "INSERT INTO main (`id`, `firstName`, `secondName`,`lastName`,`phone`,`email`,`county`,`city`,`street`,`house`,`flat`) VALUES " + "(NULL," + "'" + dataBaseItem.firstName + "'," + "'" + dataBaseItem.secondName + "'," + "'" + dataBaseItem.lastName + "'," + "'" + dataBaseItem.phone + "'," + "'" + dataBaseItem.email + "'," + "'" + dataBaseItem.county + "'," + "'" + dataBaseItem.city + "'," + "'" + dataBaseItem.street + "'," + "'" + dataBaseItem.house + "'," + "'" + dataBaseItem.flat + "');"; SQLiteCommand command = new SQLiteCommand(connection); command.CommandText = sql; command.ExecuteNonQuery(); return(true); } catch (Exception e) { return(false); } }
public static List <DataBaseItem> Get(string firstName) { List <DataBaseItem> list = null; try { string sql = "SELECT * FROM main WHERE firstName LIKE '%" + firstName + "%' or phone LIKE '%" + firstName + "%' ORDER BY `firstName` ASC;"; SQLiteCommand command = new SQLiteCommand(connection); command.CommandText = sql; SQLiteDataReader reader = command.ExecuteReader(); list = new List <DataBaseItem>(); while (reader.Read()) { DataBaseItem dataBaseItem = new DataBaseItem(); dataBaseItem.id = Convert.ToInt32(reader["id"]); dataBaseItem.firstName = (string)reader["firstName"]; dataBaseItem.secondName = (string)reader["secondName"]; dataBaseItem.lastName = (string)reader["lastName"]; dataBaseItem.phone = (string)reader["phone"]; dataBaseItem.email = (string)reader["email"]; dataBaseItem.county = (string)reader["county"]; dataBaseItem.city = (string)reader["city"]; dataBaseItem.street = (string)reader["street"]; dataBaseItem.house = (string)reader["house"]; dataBaseItem.flat = Convert.ToInt32(reader["flat"]); list.Add(dataBaseItem); } } catch (Exception e) { } return(list); }
private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e) { DataBaseItem dbItem = this.Tag as DataBaseItem; System.Diagnostics.Process.Start("https://www.google.com/maps?q=" + dbItem.county + " " + dbItem.city + " " + dbItem.street + " " + dbItem.house); }