private void dataGrid_Selection(object sender, EventArgs e) { if (executedFirstTime) { executedFirstTime = false; return; } try { int selectedIndex = dataGridViewNotAvailable.SelectedRows[0].Index; if (selectedIndex != -1) { if (dataGridViewNotAvailable.SelectedRows[0].Cells[0].Value != null) { int id = int.Parse(dataGridViewNotAvailable.SelectedRows[0].Cells[0].Value.ToString()); selectedNotavailable = new Notavailable(); selectedNotavailable = notavailableservice.GetNotavailable(id); Console.WriteLine(id); #region Set data to Fields #endregion btnDelete.Enabled = true; } } } catch (ArgumentOutOfRangeException es) { Console.WriteLine(es.Message); } }
public Notavailable GetNotavailable(int id) { string connectionString = @"Server=us-cdbr-east-03.cleardb.com;Database=heroku_e9719c4a59b4c8f;Uid=b9ff0a805dbcc5;Pwd=25d16e4a;"; MySqlConnection conn = new MySqlConnection(connectionString); Notavailable notavailable = new Notavailable(); try { string query = "SELECT * FROM notavailables WHERE id = @id"; conn.Open(); MySqlCommand cmd = new MySqlCommand(query, conn); cmd.Parameters.AddWithValue("@id", id); MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { notavailable.Id = rdr.GetInt32(0); notavailable.Duration = rdr.GetString(1); notavailable.Lec_name = rdr.GetString(2); notavailable.Group_code = rdr.GetString(3); notavailable.Subgroup_code = rdr.GetString(4); notavailable.Session_Id = rdr.GetInt32(5); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return(notavailable); }
public Notavailable GetNotavailable(int id) { SQLiteConnection conn = new SQLiteConnection("Data Source=database.db;Version=3;"); Notavailable notavailable = new Notavailable(); try { string query = "SELECT * FROM notavailables WHERE id = @id"; conn.Open(); SQLiteCommand cmd = new SQLiteCommand(query, conn); cmd.Parameters.AddWithValue("@id", id); SQLiteDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { notavailable.Id = rdr.GetInt32(0); notavailable.Duration = rdr.GetString(1); notavailable.Lec_name = rdr.GetString(2); notavailable.Group_code = rdr.GetString(3); notavailable.Subgroup_code = rdr.GetString(4); notavailable.Session_Id = rdr.GetInt32(5); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return(notavailable); }
private void button4_Click(object sender, EventArgs e) { if (comboBoxLec.SelectedIndex == -1) { comboBoxLec.Focus(); } else if (comboBoxGroup.SelectedIndex == -1) { comboBoxGroup.Focus(); } else if (comboBoxSub.SelectedIndex == -1) { comboBoxSub.Focus(); } else if (comboBoxSid.SelectedIndex == -1) { comboBoxSid.Focus(); } else if (textBox1.Text == String.Empty) { textBox1.Focus(); errorNot.SetError(textBox1, "Please Enter Time"); } else { Notavailable notavailable = new Notavailable(); INotavailableService notavailableService = new NotavailableService(); // Set Data notavailable.Duration = textBox1.Text.Trim(); notavailable.Lec_name = comboBoxLec.Text; notavailable.Group_code = comboBoxGroup.Text; notavailable.Subgroup_code = comboBoxSub.Text; notavailable.Session_Id = int.Parse(comboBoxSid.Text); //Insert Data if (notavailableService.addNotavailable(notavailable)) { SuccessMessage sc = new SuccessMessage("Not Available Time Added Successfully !"); sc.Show(); textBox1.Text = ""; comboBoxLec.SelectedIndex = -1; comboBoxGroup.SelectedIndex = -1; comboBoxSub.SelectedIndex = -1; comboBoxSid.SelectedIndex = -1; } else { ErrorMessage ec = new ErrorMessage("Oops, Somthing went wrong!"); ec.Show(); textBox1.Text = ""; comboBoxLec.SelectedIndex = -1; comboBoxGroup.SelectedIndex = -1; comboBoxSub.SelectedIndex = -1; comboBoxSid.SelectedIndex = -1; } } }
public bool addNotavailable(Notavailable notavailable) { Boolean result = false; string connectionString = @"Server=us-cdbr-east-03.cleardb.com;Database=heroku_e9719c4a59b4c8f;Uid=b9ff0a805dbcc5;Pwd=25d16e4a;"; MySqlConnection conn = new MySqlConnection(connectionString); try { string query = "INSERT INTO notavailables (duration, lec_name, group_code, subgroup_code, session_id) VALUES (@duration, @lec_name, @group_code, @subgroup_code, @session_id)"; conn.Open(); MySqlCommand cmd = new MySqlCommand(query, conn); cmd.Parameters.AddWithValue("@duration", notavailable.Duration); cmd.Parameters.AddWithValue("@lec_name", notavailable.Lec_name); cmd.Parameters.AddWithValue("@group_code", notavailable.Group_code); cmd.Parameters.AddWithValue("@subgroup_code", notavailable.Subgroup_code); cmd.Parameters.AddWithValue("@session_id", notavailable.Session_Id); cmd.Prepare(); if (cmd.ExecuteNonQuery() == 1) { result = true; } else { result = false; } } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return(result); }
public bool addNotavailable(Notavailable notavailable) { Boolean result = false; SQLiteConnection conn = new SQLiteConnection("Data Source=database.db;Version=3;"); try { string query = "INSERT INTO notavailables (duration, lec_name, group_code, subgroup_code, session_id) VALUES (@duration, @lec_name, @group_code, @subgroup_code, @session_id)"; conn.Open(); SQLiteCommand cmd = new SQLiteCommand(query, conn); cmd.Parameters.AddWithValue("@duration", notavailable.Duration); cmd.Parameters.AddWithValue("@lec_name", notavailable.Lec_name); cmd.Parameters.AddWithValue("@group_code", notavailable.Group_code); cmd.Parameters.AddWithValue("@subgroup_code", notavailable.Subgroup_code); cmd.Parameters.AddWithValue("@session_id", notavailable.Session_Id); cmd.Prepare(); //Console.WriteLine(cmd); if (cmd.ExecuteNonQuery() == 1) { result = true; } else { result = false; } } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return(result); }
public List <Notavailable> getAllNotavailables() { string connectionString = @"Server=us-cdbr-east-03.cleardb.com;Database=heroku_e9719c4a59b4c8f;Uid=b9ff0a805dbcc5;Pwd=25d16e4a;"; MySqlConnection conn = new MySqlConnection(connectionString); List <Notavailable> arrayNotavailables = null; try { string query = "SELECT * FROM notavailables"; conn.Open(); MySqlCommand cmd = new MySqlCommand(query, conn); MySqlDataReader rdr = cmd.ExecuteReader(); arrayNotavailables = new List <Notavailable>(); while (rdr.Read()) { Notavailable notavailable = new Notavailable(); notavailable.Id = rdr.GetInt32(0); notavailable.Duration = rdr.GetString(1); notavailable.Lec_name = rdr.GetString(2); notavailable.Group_code = rdr.GetString(3); notavailable.Subgroup_code = rdr.GetString(4); notavailable.Session_Id = rdr.GetInt32(5); arrayNotavailables.Add(notavailable); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return(arrayNotavailables); }
public List <Notavailable> getAllNotavailables() { SQLiteConnection conn = new SQLiteConnection("Data Source=database.db;Version=3;"); List <Notavailable> arrayNotavailables = null; try { string query = "SELECT * FROM notavailables"; conn.Open(); SQLiteCommand cmd = new SQLiteCommand(query, conn); SQLiteDataReader rdr = cmd.ExecuteReader(); arrayNotavailables = new List <Notavailable>(); while (rdr.Read()) { Notavailable notavailable = new Notavailable(); notavailable.Id = rdr.GetInt32(0); notavailable.Duration = rdr.GetString(1); notavailable.Lec_name = rdr.GetString(2); notavailable.Group_code = rdr.GetString(3); notavailable.Subgroup_code = rdr.GetString(4); notavailable.Session_Id = rdr.GetInt32(5); arrayNotavailables.Add(notavailable); } } catch (Exception e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return(arrayNotavailables); }
private void btnRefresh_Click(object sender, EventArgs e) { populateData(); selectedNotavailable = new Notavailable(); btnDelete.Enabled = false; }