private void addSetup(object sender, RoutedEventArgs e) { try { StringBuilder sb = new StringBuilder(); sb.Append("SET foreign_key_checks = 0;"); sb.Append("INSERT INTO setups (technique_id, description) VALUES ("); sb.AppendFormat("(SELECT technique_id from techniques where name='{0}'), ", techniqueName_textbox.Text); sb.AppendFormat("'{0}')", setup_textBox.Text); MySqlCommand cmd; cmd = this.conn.CreateCommand(); cmd.CommandText = sb.ToString(); if (cmd.ExecuteNonQuery() == 1) { setup_textBox.Clear(); AddTechniqueDialog atd = new AddTechniqueDialog(true, mouse_x, mouse_y, "Setup"); atd.Show(); } string createText = sb.ToString() + Environment.NewLine; File.AppendAllText("C:/Users/T420/Documents/Visual Studio 2015/Projects/Jiu Jitsu Assistant/db_creation/data2.txt", createText); } catch (Exception ex) { AddTechniqueDialog atd = new AddTechniqueDialog(false, mouse_x, mouse_y, "setup"); atd.Show(); } }
private void AddNewTechnique(object sender, RoutedEventArgs e) { try{ StringBuilder sb = new StringBuilder(); sb.Append("SET foreign_key_checks = 0;"); sb.AppendFormat("INSERT INTO techniques (group_id,name,date_learned,belt_level,position_from,position_to,nogi_flag) VALUES ({0},'{1}','{2}','{3}', {4} , {5}, {6} )", techniqueGroup_comboBox.SelectedValue.ToString(), techniqueName_textbox.Text, dateLearned_datepicker.SelectedDate.Value.Date.ToString("yyyy-MM-dd"), ((ComboBoxItem)belt_comboBox.SelectedItem).Name, from_Position_comboBox.SelectedValue.ToString(), to_Position_comboBox.SelectedValue.ToString(), nogi_checkBox.IsChecked); MySqlCommand cmd; cmd = this.conn.CreateCommand(); cmd.CommandText = sb.ToString(); int effectedRows = cmd.ExecuteNonQuery(); if (effectedRows != 0) { LoadTechniques(); disableAddTechniqueControls(); } //javascript like alert dialog to let user know if adding technique was successful AddTechniqueDialog atd = new AddTechniqueDialog(true, mouse_x, mouse_y, "Technique"); atd.Show(); string createText = sb.ToString() + Environment.NewLine; File.AppendAllText("C:/Users/T420/Documents/Visual Studio 2015/Projects/Jiu Jitsu Assistant/db_creation/data2.txt", createText); } catch (Exception ex) { resetAddTechniqueValues(); AddTechniqueDialog atd = new AddTechniqueDialog(false, mouse_x, mouse_y, "technique"); atd.Show(); } }