public bool onSaveClick(FormValue <string, string> formValue, string value) { if (!DAO.getInstance().addNote(formValue.getKey(), new FormValue <string, string> (formValue.getValue(), value))) { MessageBox.Show("Данный показатель уже существует!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else { return(true); } }
public void deleteButtonClick(FormValue <string, string> formValue, string id) { DAO.getInstance().deleteNote(formValue.getKey(), new FormValue <string, string> (formValue.getValue(), id)); }
public void updateNote(string nameTable, FormValue<string, string> primaryKey, params FormValue<string, string>[] values) { string sqlCommand; string settingString = string.Empty; if (values.Length > 0) settingString += values[0].getKey() + "='" + values[0].getValue() + "'"; for (int i = 1; i < values.Length; i++) { settingString += ", " + values[i].getKey() + "='" + values[i].getValue() + "'"; } sqlCommand = string.Format("Update {0} Set {1} where {2}='{3}'", nameTable, settingString, primaryKey.getKey(), primaryKey.getValue()); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(sqlCommand, connection); cmd.ExecuteNonQuery(); connection.Close(); } }
public void deleteNote(string nameTable, FormValue<string, string> primaryKey) { string sqlCommand; sqlCommand = string.Format("Delete {0} where {1}='{2}'", nameTable, primaryKey.getKey(), primaryKey.getValue()); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand(sqlCommand, connection); cmd.ExecuteNonQuery(); connection.Close(); } }
public DataTable findRow(string nameTable, FormValue<string, string> value) { string sqlCommand = string.Empty; using (SqlConnection connection = new SqlConnection(connectionString)) { sqlCommand = string.Format("Select * From {0} where UPPER(REPLACE({1},' ','')) LIKE(UPPER(REPLACE('{2}',' ','')))", nameTable, value.getKey(), " %" + value.getValue().Trim() + "%"); connection.Open(); SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand, connection); SqlCommandBuilder builder = new SqlCommandBuilder(dataAdapter); DataTable table = new DataTable(); dataAdapter.Fill(table); connection.Close(); return table; } }