private void fillgridPerg() { id = -1; buttonDel.Visible = false; buttonEdit.Visible = false; buttonIns.Visible = false; buttonCancel.Visible = false; DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select id_quest, id_qs, questao, name_qs From questionarios, questionset where id_qs_fk = id_qs", DBConnect.db); try { MySqlDataAdapter dados = new MySqlDataAdapter(); dados.SelectCommand = querysql; DataTable tabela = new DataTable(); dados.Fill(tabela); BindingSource fonte = new BindingSource(); fonte.DataSource = tabela; dataGridView1.DataSource = fonte; this.dataGridView1.Columns[0].Visible = false; this.dataGridView1.Columns[1].Visible = false; dataGridView1.Columns[2].HeaderText = "Questão"; dataGridView1.Columns[3].HeaderText = "QuestionSet"; dados.Update(tabela); dataGridView1.AutoResizeColumns(); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; } catch (Exception ex) { MessageBox.Show(ex.Message); } DBConnect.db.Close(); textBoxPerg.Clear(); comboBox1.SelectedIndex = 0; }
private void fillgridDef() { id = -1; buttonDel.Visible = false; buttonEdit.Visible = false; buttonIns.Visible = false; buttonCancel.Visible = false; DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select * From deficiencias", DBConnect.db); try { MySqlDataAdapter dados = new MySqlDataAdapter(); dados.SelectCommand = querysql; DataTable tabela = new DataTable(); dados.Fill(tabela); BindingSource fonte = new BindingSource(); fonte.DataSource = tabela; dataGridView1.DataSource = fonte; this.dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].HeaderText = "Deficiencia"; dados.Update(tabela); dataGridView1.AutoResizeColumns(); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; } catch (Exception ex) { MessageBox.Show(ex.Message); } DBConnect.db.Close(); textBoxDef.Clear(); }
public void fillcombo() { DBConnect NewConnection = new DBConnect(); NewConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("select * from questionset", DBConnect.db); MySqlDataReader dataread = querysql.ExecuteReader(); comboBox1.Items.Add("Selecione um QuestionSet"); int count = 0; while (dataread.Read()) { count = count + 1; comboBox1.Items.Add(dataread["id_qs"].ToString() + " " + "-" + " " + dataread["name_qs"].ToString()); } if (count == 0) { comboBox1.Visible = false; } else { comboBox1.Visible = true; } DBConnect.db.Close(); comboBox1.SelectedIndex = 0; }
private void textfic() { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM Inicio", DBConnect.db); MySqlDataReader read = verifica.ExecuteReader(); while (read.Read()) { string aux = Http + read["mainimage"].ToString(); textBoxFich.Text = aux; } DBConnect.db.Close(); }
private void ButtonName() { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM Inicio", DBConnect.db); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; id_ini = read["id_Inicio"].ToString(); textBoxTitulo.Text = read["maintitle"].ToString(); textBoxPagIni.Text = read["mainbody"].ToString(); string aux = Http + read["mainimage"].ToString(); textBoxFich.Text = aux; try { WebClient client = new WebClient(); byte[] imageData = client.DownloadData(aux); //this.pictureBox1.ImageLocation = aux; this.pictureBox1.Image = Image.FromStream(new MemoryStream(imageData)); } catch { MessageBox.Show("Erro a carregar a imagem ou imagem inixistente !!!"); } } DBConnect.db.Close(); if (count == 0) { buttonInserir.Text = "Inserir"; } else { buttonInserir.Text = "Update"; } }
private void buttonIns_Click(object sender, EventArgs e) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM deficiencias WHERE nome_deficiencia LIKE @def", DBConnect.db); verifica.Parameters.AddWithValue("@def", this.textBoxDef.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { DialogResult dlg = MessageBox.Show("Confirma a inserção da deficiencia " + this.textBoxDef.Text + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("INSERT INTO deficiencias (nome_deficiencia) Values ('" + this.textBoxDef.Text + "')", DBConnect.db); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { MessageBox.Show("Operação Cancelada!!"); } } else { MessageBox.Show("Deficiencia já existe!!"); } DBConnect.db.Close(); fillgridDef(); }
private void fillgridNoti() { //id = -1; //buttonDel.Visible = false; //buttonEdit.Visible = false; //buttonIns.Visible = false; //buttonCancel.Visible = false; DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select * From noticias", DBConnect.db); try { MySqlDataAdapter dados = new MySqlDataAdapter(); dados.SelectCommand = querysql; DataTable tabela = new DataTable(); dados.Fill(tabela); BindingSource fonte = new BindingSource(); fonte.DataSource = tabela; dataGridView1.DataSource = fonte; //this.dataGridView1.Columns[0].Visible = false; //this.dataGridView1.Columns[1].Visible = false; //dataGridView1.Columns[2].HeaderText = "Distrito"; //dataGridView1.Columns[3].HeaderText = "Concelho"; dados.Update(tabela); dataGridView1.AutoResizeColumns(); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; } catch (Exception ex) { MessageBox.Show(ex.Message); } DBConnect.db.Close(); //textBoxConc.Clear(); //comboBox1.SelectedIndex = 0; }
// menu para inserir concelho private void button2_Click(object sender, RoutedEventArgs e) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM distrito", DBConnect.db); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count != 0) { Concelho formCon = new Concelho(); formCon.ShowDialog(); } else { if (MessageBox.Show("Não tem Distritos inseridos, quer inserir agora?","Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { Distrito formDis = new Distrito(); formDis.ShowDialog(); Concelho formCon = new Concelho(); formCon.ShowDialog(); } else { MessageBox.Show("Operação anulada!!!"); } } }
private void buttonEdit_Click(object sender, EventArgs e) { try { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM deficiencias WHERE nome_deficiencia = @def", DBConnect.db); verifica.Parameters.AddWithValue("@def", this.textBoxDef.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { DialogResult dlg = MessageBox.Show("Confirma a alteração na deficiencia " + this.textBoxDef.Text + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" UPDATE deficiencias set nome_deficiencia = @def where id_deficiencia =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.Parameters.AddWithValue("@def", this.textBoxDef.Text); querysql.ExecuteNonQuery(); DBConnect.db.Close(); MessageBox.Show("Alteração Gravada!!"); } else { MessageBox.Show("Alteração cancelada!!"); } } else { MessageBox.Show("Deficiencia já existe!!"); } } catch { MessageBox.Show("Ocorreu um erro!!"); } fillgridDef(); }
private void buttonDel_Click(object sender, EventArgs e) { try { DialogResult dlg = MessageBox.Show("Quer apagar a deficienccia " + this.textBoxDef.Text + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { DialogResult dlg2 = MessageBox.Show("Tem a certeza que quer apagar a deficiencia " + this.textBoxDef.Text + " ?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg2 == DialogResult.Yes) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" Delete from deficiencias where id_deficiencia =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.ExecuteNonQuery(); MessageBox.Show("Apagado com sucesso!!"); DBConnect.db.Close(); } else { MessageBox.Show("Operação anulada!!!"); } } else { MessageBox.Show("Operação anulada!!!"); } } catch { MessageBox.Show("Ocorreu um erro!!"); } fillgridDef(); }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { try { buttonDel.Visible = true; buttonEdit.Visible = true; id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id_deficiencia"].Value.ToString()); DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select * From deficiencias where id_deficiencia =" + id + "", DBConnect.db); querysql.ExecuteNonQuery(); DataTable dt = new DataTable(); MySqlDataAdapter dados = new MySqlDataAdapter(querysql); dados.Fill(dt); foreach (DataRow dr in dt.Rows) { textBoxDef.Text = dr["nome_deficiencia"].ToString(); } } catch { buttonDel.Visible = false; buttonEdit.Visible = false; buttonIns.Visible = false; textBoxDef.Clear(); id = -1; MessageBox.Show("Selecione uma celula valida"); } } }
/// <summary> /// Handles the CellClick event of the dataGridView1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DataGridViewCellEventArgs"/> instance containing the event data.</param> private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { try { buttonDel.Visible = true; buttonEdit.Visible = true; id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value.ToString()); DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select * From contactos where Id =" + id + "", DBConnect.db); querysql.ExecuteNonQuery(); DataTable dt = new DataTable(); MySqlDataAdapter dados = new MySqlDataAdapter(querysql); dados.Fill(dt); foreach (DataRow dr in dt.Rows) { textBoxNome.Text = dr["contatonome"].ToString(); if (dr["contatomorada"].ToString().Length != 0) { string morada = dr["contatomorada"].ToString(); textBoxMorada.Text = morada.Substring(8,morada.Length-8); } if (dr["contatocontato1"].ToString().Length != 0) { string tel1 = dr["contatocontato1"].ToString(); string[] gettel1 = tel1.Split(' '); textBoxTel1.Text = gettel1[2]; } if (dr["contatocontato2"].ToString().Length != 0) { string tel2 = dr["contatocontato2"].ToString(); string[] gettel2 = tel2.Split(' '); textBoxTel2.Text = gettel2[2]; } if (dr["contatoemail"].ToString().Length != 0) { string email = dr["contatoemail"].ToString(); string[] getemail = email.Split(' '); textBoxEmail.Text = getemail[1]; } } } catch { buttonDel.Visible = false; buttonEdit.Visible = false; buttonIns.Visible = false; textBoxNome.Clear(); textBoxMorada.Clear(); textBoxTel1.Clear(); textBoxTel2.Clear(); textBoxEmail.Clear(); id = -1; MessageBox.Show("Selecione uma celula valida"); } } }
private void buttonEdit_Click(object sender, EventArgs e) { try { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM contactos WHERE contatonome LIKE @nome and contatomorada like @morada and contatocontato1 like @tel1 and contatocontato2 like @tel2 and contatoemail like @email ", DBConnect.db); verifica.Parameters.AddWithValue("@nome", this.textBoxNome.Text); verifica.Parameters.AddWithValue("@morada", this.textBoxMorada.Text); verifica.Parameters.AddWithValue("@tel1", this.textBoxTel1.Text); verifica.Parameters.AddWithValue("@tel2", this.textBoxTel2.Text); verifica.Parameters.AddWithValue("@email", this.textBoxEmail.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { DialogResult dlg = MessageBox.Show("Confirma a alteração no Contacto " + this.textBoxNome.Text + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { string aux_morada_final = null; string aux_tel1_final = null; string aux_tel2_final = null; string aux_email_final = null; string aux_morada = "Morada: "; string aux_tel = "Tel.: (+351) "; string aux_email = "Email: "; if (textBoxMorada.TextLength != 0) { aux_morada_final = aux_morada + textBoxMorada.Text; } if (textBoxTel1.TextLength != 0) { aux_tel1_final = aux_tel + textBoxTel1.Text; } if (textBoxTel2.TextLength != 0) { aux_tel2_final = aux_tel + textBoxTel2.Text; } if (textBoxEmail.TextLength != 0) { aux_email_final = aux_email + textBoxEmail.Text; } NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" UPDATE Contactos set contatonome=@nome, contatomorada=@morada, contatocontato1=@tel1, contatocontato2=@tel2, contatoemail=@email where Id =@Id_c", DBConnect.db); querysql.Parameters.AddWithValue("@Id_c", id.ToString()); querysql.Parameters.AddWithValue("@nome", this.textBoxNome.Text); querysql.Parameters.AddWithValue("@morada", aux_morada_final); querysql.Parameters.AddWithValue("@tel1", aux_tel1_final); querysql.Parameters.AddWithValue("@tel2", aux_tel2_final); querysql.Parameters.AddWithValue("@email", aux_email_final); querysql.ExecuteNonQuery(); DBConnect.db.Close(); MessageBox.Show("Alteração Gravada!!"); } else { MessageBox.Show("Alteração cancelada!!"); } } else { MessageBox.Show("Contacto já existe!!"); } } catch { MessageBox.Show("Ocorreu um erro!!"); } fillgridContact(); }
private void buttonInserir_Click(object sender, EventArgs e) { FTPClass ftp = new FTPClass(); DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM Inicio", DBConnect.db); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; string old_file=""; while (read.Read()) { old_file = read["mainimage"].ToString(); count = count + 1; } DBConnect.db.Close(); string nome_arquivo = System.IO.Path.GetFileName(textBoxFich.Text); string aux_arquivo = directoria + nome_arquivo; if (textBoxFich.TextLength != 0 && textBoxPagIni.TextLength != 0 && textBoxTitulo.TextLength !=0) { if (count == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand inserir = new MySqlCommand("INSERT INTO Inicio (maintitle, mainbody, mainimage) Values ('" + this.textBoxTitulo.Text + "','" + this.textBoxPagIni.Text + "','" + aux_arquivo + "')", DBConnect.db); inserir.ExecuteNonQuery(); ftp.upload(textBoxFich.Text, ftp_url, user, pwd, nome_arquivo, directoria); fillgridIni(); MessageBox.Show("Sucesso!!"); } else { try { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); if (textBoxFich.Text == Http + old_file || textBoxFich.TextLength == 0) { MessageBox.Show("true"); MySqlCommand querysql = new MySqlCommand(" UPDATE Inicio set maintitle = @Titulo, mainbody = @Texto where id_Inicio = @Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id_ini); querysql.Parameters.AddWithValue("@Titulo", this.textBoxTitulo.Text); querysql.Parameters.AddWithValue("@Texto", this.textBoxPagIni.Text); querysql.ExecuteNonQuery(); } else { MessageBox.Show("false"); MySqlCommand querysql = new MySqlCommand(" UPDATE Inicio set maintitle = @Titulo, mainbody = @Texto, mainimage = @Image where id_Inicio = @Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id_ini); querysql.Parameters.AddWithValue("@Titulo", this.textBoxTitulo.Text); querysql.Parameters.AddWithValue("@Texto", this.textBoxPagIni.Text); querysql.Parameters.AddWithValue("@Image", aux_arquivo); querysql.ExecuteNonQuery(); if (old_file != null && old_file != "") { ftp.apagar_ficheiro(old_file, ftp_url, user, pwd, ""); } ftp.upload(textBoxFich.Text, ftp_url, user, pwd, nome_arquivo, directoria); } DBConnect.db.Close(); fillgridIni(); MessageBox.Show("Alteração Gravada!!"); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); } } } else { MessageBox.Show("Falta preencher campos"); } }
private void fillgridIni() { //id = -1; //buttonDel.Visible = false; //buttonEdit.Visible = false; //buttonIns.Visible = false; //buttonCancel.Visible = false; DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select * From Inicio", DBConnect.db); try { MySqlDataAdapter dados = new MySqlDataAdapter(); dados.SelectCommand = querysql; DataTable tabela = new DataTable(); dados.Fill(tabela); BindingSource fonte = new BindingSource(); fonte.DataSource = tabela; dataGridView1.DataSource = fonte; this.dataGridView1.Columns[0].Visible = false; //this.dataGridView1.Columns[1].Visible = false; //dataGridView1.Columns[2].HeaderText = "Distrito"; //dataGridView1.Columns[3].HeaderText = "Concelho"; dados.Update(tabela); dataGridView1.AutoResizeColumns(); dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; if(dataGridView1.RowCount == 0) { buttonInserir.Text = "Inserir"; } else { buttonInserir.Text = "Update"; textfic(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } DBConnect.db.Close(); }
/// <summary> /// Handles the Click event of the buttonEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void buttonEdit_Click(object sender, EventArgs e) { string selectedItem = comboBox1.Items[comboBox1.SelectedIndex].ToString(); string[] getid_dist = selectedItem.Split(' '); if (comboBox1.SelectedIndex != 0) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM concelho WHERE nome_conc LIKE @Concelho", DBConnect.db); verifica.Parameters.AddWithValue("@Concelho", this.textBoxConc.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); //MySqlCommand querysql = new MySqlCommand("INSERT INTO concelho (iddistrito_fk, nome_conc) Values ('" + getid_dist[0] + "','" + this.textBoxConc.Text + "')", DBConnect.db); MySqlCommand querysql = new MySqlCommand(" UPDATE concelho set iddistrito_fk = @Distrito, nome_conc = @Concelho where id_concelho =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.Parameters.AddWithValue("@Distrito", getid_dist[0]); querysql.Parameters.AddWithValue("@Concelho", this.textBoxConc.Text); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica1 = new MySqlCommand("SELECT * FROM concelho WHERE iddistrito_fk = @id_distrito", DBConnect.db); verifica1.Parameters.AddWithValue("@id_distrito", getid_dist[0]); MySqlDataReader read1 = verifica1.ExecuteReader(); int count1 = 0; while (read1.Read()) { count1 = count1 + 1; } DBConnect.db.Close(); if (count1 == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" UPDATE concelho set iddistrito_fk = @Distrito, nome_conc = @Concelho where id_concelho =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.Parameters.AddWithValue("@Distrito", getid_dist[0]); querysql.Parameters.AddWithValue("@Concelho", this.textBoxConc.Text); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { MessageBox.Show("Concelho já existe!!"); } } DBConnect.db.Close(); fillgridConc(); } }
/// <summary> /// Handles the Click event of the buttonIns control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void buttonIns_Click(object sender, EventArgs e) { //string selectedItem = comboBox1.Items[comboBox1.SelectedIndex].ToString(); //string[] getid_dist = selectedItem.Split(' '); if (textBoxNome.TextLength != 0) { if (textBoxMorada.TextLength != 0 || textBoxTel1.TextLength != 0 || textBoxTel2.TextLength != 0 || textBoxEmail.TextLength != 0) { string aux_morada_final = null; string aux_tel1_final = null; string aux_tel2_final = null; string aux_email_final = null; string aux_morada = "Morada: "; string aux_tel = "Tel.: (+351) "; string aux_email = "Email: "; if (textBoxMorada.TextLength != 0) { aux_morada_final = aux_morada + textBoxMorada.Text; } if (textBoxTel1.TextLength != 0) { aux_tel1_final = aux_tel + textBoxTel1.Text; } if (textBoxTel2.TextLength != 0) { aux_tel2_final = aux_tel + textBoxTel2.Text; } if (textBoxEmail.TextLength != 0) { aux_email_final = aux_email + textBoxEmail.Text; } DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM contactos WHERE contatonome LIKE @nome", DBConnect.db); verifica.Parameters.AddWithValue("@nome", this.textBoxNome.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { DialogResult dlg = MessageBox.Show("Confirma a inserção do contato " + this.textBoxNome.Text + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("INSERT INTO contactos (contatonome, contatomorada, contatocontato1, contatocontato2, contatoemail) Values ('" + this.textBoxNome.Text + "','" + aux_morada_final + "','" + aux_tel1_final + "','" + aux_tel2_final + "','" + aux_email_final +"')", DBConnect.db); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { MessageBox.Show("Operação Cancelada!!"); } } else { MessageBox.Show("Contato já existe!!"); } DBConnect.db.Close(); fillgridContact(); } else { MessageBox.Show("Tem de inserir pelo menos um Contato!"); } } else { MessageBox.Show("Não preencheu o Nome!"); } }
private void buttonIns_Click(object sender, EventArgs e) { string selectedItem = comboBox1.Items[comboBox1.SelectedIndex].ToString(); string[] getid_qs = selectedItem.Split(' '); if (comboBox1.SelectedIndex != 0) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM questionarios WHERE questao LIKE @Questao", DBConnect.db); verifica.Parameters.AddWithValue("@Questao", this.textBoxPerg.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); DialogResult dlg = MessageBox.Show("Confirma a inserção da Pergunta " + this.textBoxPerg.Text + " do QuestionSet " + getid_qs[2] + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { if (count == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("INSERT INTO questionarios (id_qs_fk, questao) Values ('" + getid_qs[0] + "','" + this.textBoxPerg.Text + "')", DBConnect.db); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica1 = new MySqlCommand("SELECT * FROM questionarios WHERE id_qs_fk = @id_qs", DBConnect.db); verifica1.Parameters.AddWithValue("@id_qs", getid_qs[0]); MySqlDataReader read1 = verifica1.ExecuteReader(); int count1 = 0; while (read1.Read()) { count1 = count1 + 1; } DBConnect.db.Close(); if (count1 == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("INSERT INTO questionarios (id_qs_fk, questao) Values ('" + getid_qs[0] + "','" + this.textBoxPerg.Text + "')", DBConnect.db); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { MessageBox.Show("Pergunta já existe!!"); } } } DBConnect.db.Close(); fillgridPerg(); } else { MessageBox.Show("Selecione um QuestionSet"); } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { try { buttonDel.Visible = true; buttonEdit.Visible = true; id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["id_quest"].Value.ToString()); DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand("Select id_quest, questao, id_qs_fk, id_qs, name_qs From questionarios, questionset where id_qs = id_qs_fk and id_quest =" + id + "", DBConnect.db); querysql.ExecuteNonQuery(); DataTable dt = new DataTable(); MySqlDataAdapter dados = new MySqlDataAdapter(querysql); dados.Fill(dt); foreach (DataRow dr in dt.Rows) { textBoxPerg.Text = dr["questao"].ToString(); comboBox1.SelectedIndex = comboBox1.FindStringExact(dr["id_qs_fk"].ToString() + " " + "-" + " " + dr["name_qs"].ToString()); } } catch { buttonDel.Visible = false; buttonEdit.Visible = false; buttonIns.Visible = false; textBoxPerg.Clear(); id = -1; MessageBox.Show("Selecione uma celula valida"); } } }
private void buttonEdit_Click(object sender, EventArgs e) { string selectedItem = comboBox1.Items[comboBox1.SelectedIndex].ToString(); string[] getid_dist = selectedItem.Split(' '); if (comboBox1.SelectedIndex != 0) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM questionarios WHERE questao LIKE @Questao", DBConnect.db); verifica.Parameters.AddWithValue("@Questao", this.textBoxPerg.Text); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" UPDATE questionarios set id_qs_fk = @QuestionSet, questao = @Questao where id_quest =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.Parameters.AddWithValue("@QuestionSet", getid_dist[0]); querysql.Parameters.AddWithValue("@Questao", this.textBoxPerg.Text); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica1 = new MySqlCommand("SELECT * FROM questionarios WHERE id_qs_fk = @id_qs", DBConnect.db); verifica1.Parameters.AddWithValue("@id_qs", getid_dist[0]); MySqlDataReader read1 = verifica1.ExecuteReader(); int count1 = 0; while (read1.Read()) { count1 = count1 + 1; } DBConnect.db.Close(); if (count1 == 0) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" UPDATE questionarios set id_qs_fk = @QuestionSet, questao = @Questao where id_quest =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.Parameters.AddWithValue("@QuestionSet", getid_dist[0]); querysql.Parameters.AddWithValue("@Questao", this.textBoxPerg.Text); querysql.ExecuteNonQuery(); MessageBox.Show("Sucesso!!"); } else { MessageBox.Show("Questão já existe!!"); } } DBConnect.db.Close(); fillgridPerg(); } }
//perguntas de diagnostico private void buttonPerDia_Click(object sender, RoutedEventArgs e) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM questionset", DBConnect.db); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count != 0) { Questionario pergunt = new Questionario(); pergunt.ShowDialog(); } else { if (MessageBox.Show("Não tem QuestionSet inserido, quer inserir agora?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { QuestionSet quest = new QuestionSet(); quest.ShowDialog(); Questionario pergunt = new Questionario(); pergunt.ShowDialog(); } else { MessageBox.Show("Operação anulada!!!"); } } }
/// <summary> /// Handles the Click event of the buttonDel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void buttonDel_Click(object sender, EventArgs e) { DBConnect NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand verifica = new MySqlCommand("SELECT * FROM concelho WHERE iddistrito_fk = @Id", DBConnect.db); verifica.Parameters.AddWithValue("@Id", id.ToString()); MySqlDataReader read = verifica.ExecuteReader(); int count = 0; while (read.Read()) { count = count + 1; } DBConnect.db.Close(); if (count == 0) { try { DialogResult dlg = MessageBox.Show("Quer apagar o Distrito " + this.textBoxDis.Text + "?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { DialogResult dlg2 = MessageBox.Show("Tem a certeza que quer apagar o Distrito " + this.textBoxDis.Text + " ?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg2 == DialogResult.Yes) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" Delete from distrito where id_distrito =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.ExecuteNonQuery(); MessageBox.Show("Apagado com sucesso!!"); DBConnect.db.Close(); } else { MessageBox.Show("Operação anulada!!!"); } } else { MessageBox.Show("Operação anulada!!!"); } } catch { MessageBox.Show("Ocorreu um erro!!"); } } else { DialogResult dlg = MessageBox.Show("Quer apagar o Distrito " + this.textBoxDis.Text + " e os concelhos associados?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { DialogResult dlg2 = MessageBox.Show("Tem a certeza que quer apagar o Distrito " + this.textBoxDis.Text + " e os concelhos associados?", "MessageBox Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg2 == DialogResult.Yes) { NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql = new MySqlCommand(" Delete from concelho where iddistrito_fk =@Id", DBConnect.db); querysql.Parameters.AddWithValue("@Id", id.ToString()); querysql.ExecuteNonQuery(); DBConnect.db.Close(); NewcConnection = new DBConnect(); NewcConnection.dbConnection(); MySqlCommand querysql1 = new MySqlCommand(" Delete from distrito where id_distrito =@Id", DBConnect.db); querysql1.Parameters.AddWithValue("@Id", id.ToString()); querysql1.ExecuteNonQuery(); DBConnect.db.Close(); MessageBox.Show("Apagados com sucesso!!!"); } else { MessageBox.Show("Operação anulada!!!"); } } else { MessageBox.Show("Operação anulada!!!"); } } fillgridDis(); }