private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (e.RowIndex >= 0) { if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn) { var nw = ConfigurationManager.ConnectionStrings["nw"]; using (SqlConnection con = new SqlConnection(nw.ConnectionString)) { if (senderGrid.Columns[e.ColumnIndex].Name == "DeleteBox") { con.Open(); var cmd = new SqlCommand("RemoveFromTrashById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[7].Value); var stuff = cmd.ExecuteNonQuery(); cmd = new SqlCommand("RemoveById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[7].Value); stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateTrashForm(); } else { con.Open(); var cmd = new SqlCommand("RemoveFromTrashById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[7].Value); var stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateTrashForm(); } } } else { var viewEmailForm = new ViewEmailForm(senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString()); viewEmailForm.ShowDialog(); } } }
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (e.RowIndex >= 0) { if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn) { var nw = ConfigurationManager.ConnectionStrings["nw"]; using (SqlConnection con = new SqlConnection(nw.ConnectionString)) { if (senderGrid.Columns[e.ColumnIndex].Name == "DeleteBox") { con.Open(); SqlCommand cmd = new SqlCommand("RemoveFromImportantById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); var stuff = cmd.ExecuteNonQuery(); cmd = new SqlCommand("MoveToTrashById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateImportantForm(); } else if (senderGrid.Columns[e.ColumnIndex].Name == "SpamBox") { con.Open(); SqlCommand cmd = new SqlCommand("RemoveFromImportantById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); var stuff2 = cmd.ExecuteNonQuery(); // cmd = new SqlCommand("GetIdByEmail", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Email", emailUser); var idUser = cmd.ExecuteScalar(); cmd = new SqlCommand("AddSpammerById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID_User", idUser); cmd.Parameters.AddWithValue("@ID_Spammer", senderGrid.Rows[e.RowIndex].Cells[10].Value); try { var stuff = cmd.ExecuteNonQuery(); } catch (SqlException ex) { //nu face nimic //atunci cand arunca o exceptie unique // cand se insereaza aceasi combinatie // user-spammer } // cmd = new SqlCommand("MoveToSpamById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); var stuff1 = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateImportantForm(); } else if (senderGrid.Columns[e.ColumnIndex].Name == "ImportantBox") { con.Open(); SqlCommand cmd = new SqlCommand("RemoveFromImportantById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); var stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateImportantForm(); } else { // aici va fi CreateMessage form-ul } } } else { var viewEmailForm = new ViewEmailForm(senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString()); viewEmailForm.ShowDialog(); } } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (e.RowIndex >= 0) { if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn) { var nw = ConfigurationManager.ConnectionStrings["nw"]; using (SqlConnection con = new SqlConnection(nw.ConnectionString)) { if (senderGrid.Columns[e.ColumnIndex].Name == "DeleteBox") { con.Open(); var cmd = new SqlCommand("RemoveFromSpamById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); var stuff = cmd.ExecuteNonQuery(); cmd = new SqlCommand("MoveToTrashById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateSpamForm(); } else if (senderGrid.Columns[e.ColumnIndex].Name == "SpamBox") { con.Open(); var cmd = new SqlCommand("GetIdByEmail", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Email", emailUser); var idUser = cmd.ExecuteScalar(); cmd = new SqlCommand("RemoveSpammerById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID_User", idUser); cmd.Parameters.AddWithValue("@ID_Spammer", senderGrid.Rows[e.RowIndex].Cells[10].Value); var stuff = cmd.ExecuteNonQuery(); cmd = new SqlCommand("RemoveFromSpamById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateSpamForm(); } else if (senderGrid.Columns[e.ColumnIndex].Name == "ImportantBox") { con.Open(); SqlCommand cmd = new SqlCommand("RemoveFromSpamById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); var stuff = cmd.ExecuteNonQuery(); cmd = new SqlCommand("MoveToImportantById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ID", senderGrid.Rows[e.RowIndex].Cells[8].Value); stuff = cmd.ExecuteNonQuery(); dataGridView1.Rows.Clear(); PopulateSpamForm(); } else { //CreateMessage form-ul } } } else { var viewEmailForm = new ViewEmailForm(senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[1].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[2].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[3].Value.ToString(), senderGrid.Rows[e.RowIndex].Cells[4].Value.ToString()); viewEmailForm.ShowDialog(); } } }