private void new_btn_save_Click(object sender, EventArgs e) { if (new_nameTextBox.Text == "") { MessageBox.Show("Choose a name"); return; } if (NameExists(new_nameTextBox.Text)) { MessageBox.Show("Choose different name"); return; } if (new_nameTextBox.Text.Length > 14) { MessageBox.Show("Use a smaller name"); return; } //INSERT INTO table_name(column1, column2, column3, ...) //VALUES(value1, value2, value3, ...); using (SqlConnection myConnection = new SqlConnection(CONNECTION_STRING)) { string sql = "INSERT INTO BackgroundColors (Name,HueMin,HueMax,SatMin,SatMax,ValMin,ValMax) VALUES ('" + new_nameTextBox.Text + "'," + new_hueMinNumericUpDown.Value + "," + new_hueMaxNumericUpDown.Value + "," + new_satMinNumericUpDown.Value + "," + new_satMaxNumericUpDown.Value + "," + new_valMinNumericUpDown.Value + "," + new_valMaxNumericUpDown.Value + ");"; //MessageBox.Show(sql); //return; using (SqlCommand cmd = new SqlCommand(sql, myConnection)) { try { myConnection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); myConnection.Close(); //reloads the ComboBoxes and resets values count = 0; new_nameTextBox.Text = ""; new_hueMinNumericUpDown.Value = 0; new_hueMaxNumericUpDown.Value = 179; new_satMinNumericUpDown.Value = 0; new_satMaxNumericUpDown.Value = 255; new_valMinNumericUpDown.Value = 0; new_valMaxNumericUpDown.Value = 255; //MessageBox.Show(sql); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", deleteBox); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", UpdateBox); MessageBox.Show("Sucess!"); } catch { MessageBox.Show("Error"); } } } }
private void button2_Click(object sender, EventArgs e) { //delete button int id = TranslationTools.GetId(deleteBox); if (id == 13) { MessageBox.Show(deleteBox.Text + " can't be deleted"); return; } try { using (SqlConnection myConnection = new SqlConnection(CONNECTION_STRING)) { //string sql = "select * from BackgroundColors where IDColor=" + TranslationTools.GetId(UpdateBox); string sql = "DELETE FROM BackgroundColors WHERE IDColor=" + id; //MessageBox.Show(sql); //return; using (SqlCommand cmd = new SqlCommand(sql, myConnection)) { myConnection.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); //DataTable dt = new DataTable(); //dt.Load(dr); myConnection.Close(); //reloads the ComboBoxes count = 0; TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", deleteBox); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", UpdateBox); } } }catch { return; } MessageBox.Show("Element sucessefully eliminated!"); }
public RemoveBackground() { InitializeComponent(); TranslationTools.FillDropDownList("SELECT IDColor, Name FROM BackgroundColors Order by IDColor", comboColors); }
private void ColorsManagementDialog_Load(object sender, EventArgs e) { //throw new NotImplementedException(); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", deleteBox); TranslationTools.FillDropDownList("Select * From BackgroundColors Order by IDColor", UpdateBox); }
public Form_PreviewBG() { InitializeComponent(); TranslationTools.FillDropDownList("SELECT IDColor, Name FROM BackgroundColors Order by IDColor", comboBox1); }