private void listBoxDisciplina_SelectedIndexChanged(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; string query = "Select * from Disciplina where Disciplina = '" + listBoxDisciplina.SelectedItem.ToString() + "'; "; MySqlConnection connection = new MySqlConnection(Conexao); try { connection.Open(); MySqlCommand MyCommand3 = new MySqlCommand(query, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_Disc.Text = MyReader3["ID_Disciplina"].ToString(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { connection.Close(); } }
private void pictureBox6_Click(object sender, EventArgs e) { if (listBoxSelecAlunos.SelectedItem == null) { MessageBox.Show("Seleciona o aluno que queres remover"); } else { listBoxIDAluno.Items.Clear(); listBoxTdAlunos.Items.Add(listBoxSelecAlunos.SelectedItem); listBoxSelecAlunos.Items.Remove(listBoxSelecAlunos.SelectedItem); string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); foreach (var listBoxItem in listBoxSelecAlunos.Items) { connection.Open(); string i = listBoxItem.ToString(); string query3 = "select * from Aluno where Nome = '" + i + "' ;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { listBoxIDAluno.Items.Add(MyReader3["ID_Aluno"].ToString()); } connection.Close(); } } }
private void pictureBox10_Click(object sender, EventArgs e) { if (listBoxAdicionar.SelectedItem != null) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string query = "select * from Aluno where Nome = '" + listBoxAdicionar.SelectedItem.ToString() + "'"; MySqlCommand MyCommand3 = new MySqlCommand(query, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_AlunoEspecifico.Text = MyReader3["ID_Aluno"].ToString(); } connection.Close(); textBoxValidacao.Text = "0"; //Inativo listBoxAluno.Items.Add(listBoxAdicionar.SelectedItem.ToString()); listBoxAdicionar.Items.Remove(listBoxAdicionar.SelectedItem.ToString()); listBoxID_AlunoEspecifico.Items.Remove(textBoxID_AlunoEspecifico.Text); } //if (textBoxValidacao.Text == "1") //{ //} }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); string Turma = comboBox1.SelectedItem.ToString(); string query = "SELECT * from Turma where Turma = '" + Turma + "';"; if (comboBox1.SelectedItem != null) { try { dataGridView1.DataSource = LoadDGV(); connection.Open(); MySqlCommand MyCommand3 = new MySqlCommand(query, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_Turma.Text = MyReader3["ID_Turma"].ToString(); //String com o valor ID_Turma dataGridView1.DataSource = LoadDGV(); } connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { connection.Close(); } } }
void ID_Prof_Dentro() { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; string query = "Select * from Professor where nome = '" + dataGridViewProfDentro.SelectedCells[0].Value.ToString() + "'; "; MySqlConnection connection = new MySqlConnection(Conexao); MySqlCommand cmdconnection = new MySqlCommand(query, connection); try { connection.Open(); MySqlCommand MyCommand3 = new MySqlCommand(query, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_Prof.Text = MyReader3["ID_Professor"].ToString(); //String com o valor ID_Turma } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { connection.Close(); } }
private void btCari_Click(object sender, EventArgs e) { { try { string MyConnection3 = "datasource=localhost; port=3306; username=root; password=new_password; database=artrockdb;SslMode=none"; string Query = "select* from gitar where Serial='" + this.tbCari.Text + "';"; MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); MySqlCommand MyCommand3 = new MySqlCommand(Query, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand3.ExecuteReader(); StringBuilder sb = new StringBuilder(); if (MyReader3.Read()) { FormUpdate fupdate = new FormUpdate(); fupdate.ShowDialog(); } else { MessageBox.Show("Gitar tidak ditemukan!"); } MyConn3.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void dataGridView2_SelectionChanged(object sender, EventArgs e) { if (dataGridView2.SelectedCells.Count <= 0) { return; } string select = dataGridView2.SelectedCells[3].Value.ToString(); string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string query = "select * from Evento where ID_Evento = '" + select + "' "; MySqlCommand MyCommand = new MySqlCommand(query, connection); MySqlDataReader MyReader; MyReader = MyCommand.ExecuteReader(); while (MyReader.Read()) { textBoxDt_Inicio.Text = MyReader["Dt_Inicio"].ToString(); textBoxDt_Final.Text = MyReader["Dt_Final"].ToString(); textBoxID_Disc2.Text = MyReader["ID_Disciplina"].ToString(); textBoxID_Turma2.Text = MyReader["ID_Turma"].ToString(); textBoxDesc_Agenda.Text = MyReader["Descricao"].ToString(); } connection.Close(); connection.Open(); string ID_Disc = textBoxID_Disc2.Text; string query2 = "select Disciplina from Disciplina where ID_Disciplina = '" + ID_Disc + "' ;"; MySqlCommand MyCommand2 = new MySqlCommand(query2, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { textBoxDisciplina.Text = MyReader2["Disciplina"].ToString(); } connection.Close(); connection.Open(); string ID_Turma = textBoxID_Turma2.Text; string query3 = "select Turma from Turma where ID_Turma = '" + ID_Turma + "' ;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxTurmaAgenda.Text = MyReader3["Turma"].ToString(); } connection.Close(); }
private void delete_btn_Click(object sender, EventArgs e) { del_confirm del = new del_confirm(); del.ShowDialog(); selectedItems2 = new ListBox.SelectedObjectCollection(project_list); selectedItems2 = project_list.SelectedItems; int selectedIndex = project_list.SelectedIndex; if (selectedIndex != -1) { if (del.Showconfirmation() == true) { for (int i = selectedItems2.Count - 1; i >= 0; i--) { projIDii = selectedItems2[i].ToString(); } projIDiii = projIDii.Split(','); proID = Convert.ToInt32(projIDiii[0]); //proj.Remove(proj[selectedIndex]); MySqlConnection connection = new MySqlConnection(connec); connection.Open(); string query = "DELETE FROM `internal_communication_4`.`projects` WHERE(`project_id` = " + this.proID + "); "; MySqlCommand idused = new MySqlCommand(query, connection); MySqlDataReader MyReader3; MyReader3 = idused.ExecuteReader(); while (MyReader3.Read()) { } connection.Close(); //delete subject associated connection.Open(); string query7 = "DELETE FROM `internal_communication_4`.`subjects` WHERE(`Project_project_id` = " + this.proID + "); "; MySqlCommand comma = new MySqlCommand(query7, connection); MySqlDataReader MyReader6; MyReader6 = comma.ExecuteReader(); while (MyReader6.Read()) { } connection.Close(); for (int i = selectedItems2.Count - 1; i >= 0; i--) { project_list.Items.Remove(selectedItems2[i]); } projectDA.Save(proj); } else { } } else { MessageBox.Show("You must select a project"); } }
private void comboBoxDisc3_SelectedIndexChanged(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string disciplina3 = comboBoxDisc3.SelectedItem.ToString(); string query3 = "select * from Disciplina where Disciplina = '" + disciplina3 + "' "; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxIDDisc3.Text = MyReader3["ID_Disciplina"].ToString(); } connection.Close(); }
private void pictureBox1_Click(object sender, EventArgs e) // Adicionar professor à turma { if (comboBox2.SelectedItem == null) { MessageBox.Show("Escolha em que turma deseja inserir o professor."); } else { comboBox2.Enabled = false; string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; string i = dataGridViewProfFora.SelectedCells[0].Value.ToString(); string query = "Select * from Professor where nome = '" + i + "'; "; MySqlConnection connection = new MySqlConnection(Conexao); try { connection.Open(); MySqlCommand MyCommand3 = new MySqlCommand(query, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_Prof.Text = MyReader3["ID_Professor"].ToString(); //String com o valor ID_Turma } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { connection.Close(); } listBoxID_Disciplina.Items.Clear(); listBoxDisciplina.Items.Clear(); panelDisciplina.Visible = true; LoadListBox(); pictureBox1.Visible = false; pictureBox2.Visible = false; } }
private void EducandoCombo() { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string ID_EE = textBoxID_EE.Text; string query3 = "select * from aluno where ID_EE = '" + ID_EE + "';"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { comboBoxEducando.Items.Add(MyReader3["Nome"].ToString()); } connection.Close(); }
private void button3_Click(object sender, EventArgs e) { Random rnd = new Random(); int p_id = rnd.Next(1, 100000); try { string MyConnection2 = "datasource=localhost;port=3306;username=root;password=9490"; //string Query = "insert into world.delivery values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + p_id + "','" + u_name +"');"; string Query = "insert into world.delivery values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + p_id + "','" + u_name + "');"; string Query2 = "insert into world.transport values ('" + p_id + "','" + u_name + "','" + this.textBox1.Text + "');"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("Pay at the reception and collect paid_id"); while (MyReader2.Read()) { } MyConn2.Close(); MySqlConnection MyConn3 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand3 = new MySqlCommand(Query2, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand3.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader3.Read()) { } MyConn3.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message + "---> RANDOM NUMBER REPREAT "); } //now depending on the values of pickup and drop we pur check constrain in the transport table. }
private void comboBoxTurma3_SelectedIndexChanged(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); if (comboBoxTurma3.SelectedItem == null) { } else { connection.Open(); string Turma = comboBoxTurma3.SelectedItem.ToString(); string query3 = "select * from Turma where Turma = '" + Turma + "' ;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_Turma3.Text = MyReader3["ID_Turma"].ToString(); } connection.Close(); dataGridViewEventosTurma.DataSource = LoadEventosTurma(); this.dataGridViewEventosTurma.Columns["ID_Evento"].Visible = false; listBoxAluno.Items.Clear(); connection.Close(); connection.Open(); string query = "select Nome from Aluno where ID_Turma = '" + textBoxID_Turma3.Text + "'"; MySqlCommand MyCommand = new MySqlCommand(query, connection); MySqlDataReader MyReader; MyReader = MyCommand.ExecuteReader(); while (MyReader.Read()) { listBoxAluno.Items.Add(MyReader.GetString("Nome")); } connection.Close(); listBoxAdicionar.Items.Clear(); listBoxID_AlunoEspecifico.Items.Clear(); } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string Turma = comboBox1.SelectedItem.ToString(); string query3 = "select * from Turma where Turma = '" + Turma + "';"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxID_Turma.Text = MyReader3["ID_Turma"].ToString(); } connection.Close(); dataGridViewTurma.DataSource = LoadTurma(); }
private void radiobtnVIP_Checked(object sender, RoutedEventArgs e) { comboboxChooseBed.Items.Clear(); comboboxChooseWard.Items.Clear(); try { string Query = "select distinct ward_name from ward_bed where bed_type='" + "VIP" + "';"; MySqlCommand MyCommand3 = new MySqlCommand(Query, conn); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { name = MyReader3.GetString(0); comboboxChooseWard.Items.Add(name); } MyReader3.Close(); } catch { } this.comboboxChooseWard.IsEnabled = true; }
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { string connetionString = null; MySqlConnection cnn; connetionString = "Server=localhost;Database=Scholendar;Uid=root"; cnn = new MySqlConnection(connetionString); string turma = comboBox2.SelectedItem.ToString(); string Query = "select * from Turma where Turma ='" + turma + "'"; // QUERY VERIFICAÇÃO TURMA COMBOBOX if (comboBox2.SelectedItem != null) { try { dataGridViewProfDentro.DataSource = LoadDGV(); dataGridViewProfFora.DataSource = LoadDGV2(); cnn.Open(); MySqlCommand MyCommand3 = new MySqlCommand(Query, cnn); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBox1.Text = MyReader3["ID_Turma"].ToString(); //String com o valor ID_Turma } dataGridViewProfDentro.DataSource = LoadDGV(); cnn.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cnn.Close(); } } }
private void LoadListBox() { listBoxID_Disciplina.Items.Clear(); string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); MySqlDataAdapter adapter = new MySqlDataAdapter(); connection.Open(); string ID_Prof = textBoxID_Prof.Text; string queryIDTurma = "select distinct * from Prof_Disc where ID_professor = '" + ID_Prof + "';"; MySqlCommand MyCommand2 = new MySqlCommand(queryIDTurma, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { listBoxID_Disciplina.Items.Add(MyReader2["ID_Disciplina"].ToString()); } connection.Close(); foreach (var listBoxItem in listBoxID_Disciplina.Items) { connection.Open(); string i = listBoxItem.ToString(); string query3 = "select * from Disciplina where ID_Disciplina = '" + i + "' ;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { listBoxDisciplina.Items.Add(MyReader3["Disciplina"].ToString()); } connection.Close(); } }
private void LoadListBox() { listBoxID_Turma.Items.Clear(); string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); connection.Open(); string ID_EE = textBoxID_EE.Text; string queryIDTurma = "select * from Aluno where ID_EE = '" + ID_EE + "';"; MySqlCommand MyCommand2 = new MySqlCommand(queryIDTurma, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { listBoxID_Turma.Items.Add(MyReader2["ID_Turma"].ToString()); } connection.Close(); foreach (var listBoxItem in listBoxID_Turma.Items) { connection.Open(); string i = listBoxItem.ToString(); string query3 = "select * from Turma where ID_Turma = '" + i + "' order by AnoEscolar;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { comboBox1.Items.Add(MyReader3["Turma"].ToString()); } connection.Close(); } }
private void refresh_Click(object sender, EventArgs e) { try { string MyConnection = "datasource=localhost;port=3306;username=root;password=root"; string Query = "delete from test.skillee ;"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); //MessageBox.Show("Data Deleted"); while (MyReader2.Read()) { } MyConn2.Close(); string MyConnection3 = "datasource=localhost;port=3306;username=root;password=root"; string Query3 = "delete from test.qualificationee ;"; MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); MySqlCommand MyCommand3 = new MySqlCommand(Query3, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand3.ExecuteReader(); MessageBox.Show("Data Deleted"); while (MyReader3.Read()) { } MyConn3.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Button4_Click_1(object sender, EventArgs e) { this.Enabled = false; progressBar2.Enabled = true; progressBar3.Enabled = true; progressBar4.Enabled = true; progressBar5.Enabled = true; if (bank_ra.Checked) { MessageBox.Show("در این نسخه امکان پرداخت بانکی وجود ندارد"); } else { refresh(); string sql = " SELECT * FROM bot WHERE chatid='" + client_id2 + "' "; MySqlConnection conn = new MySqlConnection(strconn); MySqlCommand cmd = new MySqlCommand(sql, conn); conn.Open(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { vip = reader.GetString("vip"); night = reader.GetString("night"); rate = Convert.ToDouble(reader.GetString("rate")); ratesimp = Convert.ToDouble(reader.GetString("ratesimp")); } conn.Close(); var dateNow2 = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("Iran Standard Time")); var date = new DateTime(dateNow2.Year, dateNow2.Month, dateNow2.Day, dateNow2.Hour, dateNow2.Minute, dateNow2.Second); if (clas == true) { MySqlCommand command; if (amount < (cost * rate)) { MessageBox.Show("موجودی کافی نیست"); } else { String insertQuery = "insert into orderc(type,class,blocktext,clientid,des,date,halghe,voice,photo,dhalghe,progress,file,Mac,User,errordes,status,pay,despay,Vip,Night) values(4,1,'',@clientid,@dess,@date,@halghe,'','','','','','','','','','yes','موجودی',@vip,@night)"; conn.Open(); command = new MySqlCommand(insertQuery, conn); command.Parameters.Add("@clientid", MySqlDbType.Int16, 11); command.Parameters.Add("@dess", MySqlDbType.VarChar, 128); command.Parameters.Add("@date", MySqlDbType.DateTime); command.Parameters.Add("@halghe", MySqlDbType.Int16, 11); command.Parameters.Add("@dhalghe", MySqlDbType.VarChar, 128); command.Parameters.Add("@vip", MySqlDbType.Int16, 11); command.Parameters.Add("@night", MySqlDbType.Int16, 11); command.Parameters["@clientid"].Value = client_id2; command.Parameters["@dess"].Value = richTextBox1.Text; command.Parameters["@date"].Value = date; command.Parameters["@halghe"].Value = halghe; command.Parameters["@dhalghe"].Value = textBox8.Text; command.Parameters["@vip"].Value = vip; command.Parameters["@night"].Value = night; if (command.ExecuteNonQuery() == 1) { getlastid(); if (pictureBox1.Image != null) { WebClient client = new WebClient(); client.Credentials = new NetworkCredential("saiona", "saiona123"); var uri = new System.Uri(@"ftp://golden-art.ir/public_html/Images/" + id + namepic1 + ".jpg", UriKind.Absolute); client.UploadProgressChanged += new UploadProgressChangedEventHandler(Progresss1); client.UploadFileAsync(uri, imgadd); } if (pictureBox2.Image != null) { WebClient client2 = new WebClient(); client2.Credentials = new NetworkCredential("saiona", "saiona123"); var uri2 = new System.Uri(@"ftp://golden-art.ir/public_html/Images/" + id + namepic2 + ".jpg", UriKind.Absolute); client2.UploadProgressChanged += new UploadProgressChangedEventHandler(Progresss2); client2.UploadFileAsync(uri2, imgadd2); } if (pictureBox3.Image != null) { WebClient client3 = new WebClient(); client3.Credentials = new NetworkCredential("saiona", "saiona123"); var uri3 = new System.Uri(@"ftp://golden-art.ir/public_html/Images/" + id + namepic3 + ".jpg", UriKind.Absolute); client3.UploadProgressChanged += new UploadProgressChangedEventHandler(Progresss3); client3.UploadFileAsync(uri3, imgadd3); } if (pictureBox4.Image != null) { WebClient client4 = new WebClient(); client4.Credentials = new NetworkCredential("saiona", "saiona123"); var uri4 = new System.Uri(@"ftp://golden-art.ir/public_html/Images/" + id + namepic4 + ".jpg", UriKind.Absolute); client4.UploadProgressChanged += new UploadProgressChangedEventHandler(Progresss4); client4.UploadFileAsync(uri4, imgadd4); } label23.Visible = true; } conn.Close(); if (pictureBox1.Image == null) { names1 = null; } else { names1 = (id + namepic1 + ".jpg"); } if (pictureBox2.Image == null) { names2 = null; } else { names2 = (id + namepic2 + ".jpg"); } if (pictureBox3.Image == null) { names3 = null; } else { names3 = (id + namepic3 + ".jpg"); } if (pictureBox4.Image == null) { names4 = null; } else { names4 = (id + namepic4 + ".jpg"); } string query2 = "UPDATE orderc SET lphoto='" + names1 + "',lphoto2='" + names2 + "',lphoto3='" + names3 + "',lphoto4='" + names4 + "' WHERE id='" + id + "'"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn3 = new MySqlConnection(strconn); //This is command class which will handle the query and connection object. MySqlCommand MyCommand3 = new MySqlCommand(query2, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand3.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader3.Read()) { } MyConn3.Close(); string query = "UPDATE bot SET amont='" + (amount - ((cost * rate) + smscost)) + "' WHERE chatid='" + client_id2 + "'"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(strconn); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader2.Read()) { } MyConn2.Close(); if (smsla == "1") { smssend(mobla, id.ToString(), "order"); } radioButton1.Checked = true; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; radioButton6.Checked = false; radioButton7.Checked = false; textBox8.Text = ""; richTextBox1.Text = ""; } } else { MySqlCommand command; if (amount < (sympcost * ratesimp)) { MessageBox.Show("موجودی کافی نیست"); } else { String insertQuery = "insert into orderc(type,class,blocktext,clientid,des,date,voice,photo,dhalghe,progress,file,Mac,User,errordes,status,pay,despay,Vip,Night) values(4,2,'',@clientid,@dess,@date,'','','','','','','','','','yes','موجودی',@vip,@night)"; conn.Open(); command = new MySqlCommand(insertQuery, conn); command.Parameters.Add("@clientid", MySqlDbType.Int16, 11); command.Parameters.Add("@dess", MySqlDbType.VarChar, 128); command.Parameters.Add("@date", MySqlDbType.DateTime); command.Parameters.Add("@vip", MySqlDbType.Int16, 11); command.Parameters.Add("@night", MySqlDbType.Int16, 11); command.Parameters["@clientid"].Value = client_id2; command.Parameters["@dess"].Value = richTextBox1.Text; command.Parameters["@date"].Value = date; command.Parameters["@vip"].Value = vip; command.Parameters["@night"].Value = night; if (command.ExecuteNonQuery() == 1) { label23.Visible = true; } conn.Close(); string query = "UPDATE bot SET amont='" + (amount - ((sympcost * ratesimp) + smscost)) + "' WHERE chatid='" + client_id2 + "'"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(strconn); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader2.Read()) { } MyConn2.Close(); if (smsla == "1") { smssend(mobla, id.ToString(), "order"); } radioButton1.Checked = true; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; radioButton6.Checked = false; radioButton7.Checked = false; textBox8.Text = ""; richTextBox1.Text = ""; pictureBox1.Image = null; pictureBox2.Image = null; pictureBox3.Image = null; pictureBox4.Image = null; img = null; img2 = null; img3 = null; img4 = null; } } getid(); refresh(); } if (pictureBox1.Image == null && pictureBox2.Image == null && pictureBox3.Image == null && pictureBox4.Image == null) { this.Enabled = true; } }
private void save_Click(object sender, EventArgs e) { Double t = Convert.ToDouble(this.tel.Text); Double t2 = Convert.ToDouble(254000000000 + t); String newtel = "+" + t2.ToString(); if (checkBox1.Checked == true) { //ADD NEW CUSTOMER string MyConnection2 = "datasource=localhost;port=3306;username=root"; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into drawgift.customer(name,passport,address,idno,tel) values('" + this.name.Text + "','" + this.pass.Text + "','" + this.area.Text + "','" + this.idno.Text + "','" + newtel + "');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader2.Read()) { } MyReader2.Close(); MyConn2.Close(); } if (pass.Text != "N/A") { //UPDATE CUSTOMER DETAILS string MyConnection7 = "datasource=localhost;port=3306;username=root"; //This is my insert query in which i am taking input from the user through windows forms string Query = "UPDATE drawgift.customer set passport='" + pass.Text + "'WHERE idno='" + idno.Text + "'|| tel='" + tel.Text + "' "; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn7 = new MySqlConnection(MyConnection7); //This is command class which will handle the query and connection object. MySqlCommand MyCommand7 = new MySqlCommand(Query, MyConn7); MySqlDataReader MyReader7; MyConn7.Open(); MyReader7 = MyCommand7.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader7.Read()) { } MyReader7.Close(); MyConn7.Close(); } //GENERATE TOKEN string MyConnection4 = "datasource=localhost;port=3306;username=root"; //This is my insert query in which i am taking input from the user through windows forms //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn4 = new MySqlConnection(MyConnection4); //This is command class which will handle the query and connection object. MyConn4.Open(); //get account no string q2 = "select COUNT(id) as idc from drawgift.entries ;"; MySqlCommand com4 = new MySqlCommand(q2, MyConn4); MySqlDataReader r2; r2 = com4.ExecuteReader(); r2.Read(); int ab = Convert.ToInt32(r2["idc"]) + 1; String raf = ("GALLERIA-" + ab).ToString(); r2.Close(); //ITERATE TRHOUGH ARRAY for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { object a = dataGridView1.Rows[i].Cells["Total"].Value; int aNumber = 0; int setlimit = 1000; if (a != null) { aNumber = Convert.ToInt32(a.ToString()); } int vouch = (aNumber / setlimit); dataGridView1.Rows[i].Cells["vouchers"].Value = vouch; //ASSIGN VALUABLES object va = dataGridView1.Rows[i].Cells["vouchers"].Value; String v = va.ToString(); object sh = dataGridView1.Rows[i].Cells["Shop"].Value; // String s = sh.ToString(); //String tot = a.ToString(); //SEARCH FOR SHOPNAME string shopconnection = "datasource=localhost;port=3306;username=root"; //This is my insert query in which i am taking input from the user through windows forms string shopquery = "SELECT cname FROM drawgift.shop WHERE name='" + sh + "'"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection shopconn = new MySqlConnection(shopconnection); //This is command class which will handle the query and connection object. MySqlCommand shopcommand = new MySqlCommand(shopquery, shopconn); MySqlDataReader shopreader; shopconn.Open(); shopreader = shopcommand.ExecuteReader(); // Here our query will be executed and data saved into the database. shopreader.Read(); String shopname = shopreader["cname"].ToString(); shopreader.Close(); shopconn.Close(); //RUN INSERT SCRIPT try { //ADD NEW RAFFLE ENTRY string MyConnection3 = "datasource=localhost;port=3306;username=root"; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into drawgift.entries(customername,passport,tel,address,raffleno,idno,shop,amount,points,dateadded)values('" + this.name.Text + "','" + this.pass.Text + "','" + newtel + "','" + this.area.Text + "','" + raf + "','" + this.idno.Text + "','" + shopname + "','" + a + "','" + vouch + "','" + this.datea.Text + "');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader3.Read()) { // Find your Account Sid and Auth Token at twilio.com/user/account /* string AccountSid = "AC76b83713f0c7385af9352e3dfb902288"; * string AuthToken = "6e48fb10b5b82dd13f2eb663d6a3c210"; * var twilio = new TwilioRestClient(AccountSid, AuthToken); * * twilio.SendMessage("+17083283330","+254728944815","This is the ship that made the Kessel Run in fourteen parsecs?" * );*/ // Specify your login credentials string username = "******"; string apiKey = "93f87c6f181904289e830c9fabda74e70cfcaef5d804e9811d9f097dee44989e"; // Specify the numbers that you want to send to in a comma-separated list // Please ensure you include the country code (+254 for Kenya in this case) string recipients = this.tel.Text; // And of course we want our recipients to know what we really do string message = "I'm a lumberjack and its ok, I sleep all night and I work all day"; // Create a new instance of our awesome gateway class AfricasTalkingGateway gateway = new AfricasTalkingGateway(username, apiKey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Thats it, hit send and we'll take care of the rest gateway.sendMessage(recipients, message); dynamic results = gateway.sendMessage(recipients, message); foreach (dynamic result in results) { Console.Write((string)result["number"] + ","); Console.Write((string)result["status"] + ","); // status is either "Success" or "error message" Console.Write((string)result["messageId"] + ","); Console.WriteLine((string)result["cost"]); } } catch (AfricasTalkingGatewayException e1) { Console.WriteLine("Encountered an error: " + e1.Message); } } MyReader3.Close(); MyConn3.Close(); //RESET EVERYTHING } catch (Exception ex) { MessageBox.Show(ex.Message); } } MessageBox.Show("ENTRIES SAVED"); tel.Enabled = true; tel.Text = "0"; idno.Enabled = true; idno.Text = ""; name.Enabled = false; name.Text = ""; pass.Enabled = false; pass.Text = ""; area.Enabled = false; area.Text = ""; checkBox1.Checked = false; dataGridView1.Rows.Clear(); }
private void button5_Click(object sender, EventArgs e) { string Conexao = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;"; MySqlConnection connection = new MySqlConnection(Conexao); MySqlDataAdapter adapter = new MySqlDataAdapter(); if (comboBoxTipo3.SelectedItem == null || comboBoxTurma3.SelectedItem == null || comboBoxDisc3.SelectedItem == null || textBoxDesc3.Text == "" || textBoxInicio.Text == "") { MessageBox.Show("Preencha todos os parâmetros"); } else { if (textBoxFim.Text == "") { DialogResult dialogResult = MessageBox.Show("Não quer adicionar prazo final ao Evento?", "", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { } else if (dialogResult == DialogResult.No) { connection.Open(); CriarEvento(); string ID_Turma = textBoxID_Turma3.Text; string ID_Disciplina = textBoxID_Disc3.Text; string Tipo = comboBoxTipo3.SelectedItem.ToString(); string Inicio = textBoxInicio.Text; string Fim = textBoxFim.Text; string Descricao = textBoxDesc3.Text; string query = "select * from Evento where ID_Turma = '" + ID_Turma + "' and ID_Disciplina = '" + ID_Disciplina + "' and Tipo = '" + Tipo + "' and dt_inicio = '" + Inicio + "' and dt_final = '" + Fim + "' and Descricao = '" + Descricao + "'"; MySqlCommand MyCommand2 = new MySqlCommand(query, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { textBoxID_Evento3.Text = MyReader2["ID_Evento"].ToString(); } connection.Close(); connection.Open(); string ID_Evento = textBoxID_Evento3.Text; string ID_Professor = textBoxID_Prof.Text; string query2 = "insert into professor_Evento values ('" + ID_Evento + "', '" + ID_Professor + "','0')"; adapter.InsertCommand = new MySqlCommand(query2, connection); adapter.InsertCommand.ExecuteNonQuery(); connection.Close(); if (listBoxID_AlunoEspecifico.Items.Count == 0) { connection.Open(); string query3 = "select * from Aluno where ID_Turma = '" + ID_Turma + "' ;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { listBoxIDAluno.Items.Add((MyReader3["ID_Aluno"].ToString())); } connection.Close(); foreach (var listBoxItem in listBoxIDAluno.Items) { connection.Open(); string i = listBoxItem.ToString(); string query4 = "insert into Aluno_Evento (ID_Aluno, ID_Evento, notificacao) values ('" + i + "','" + ID_Evento + "', '1');"; adapter.InsertCommand = new MySqlCommand(query4, connection); adapter.InsertCommand.ExecuteNonQuery(); connection.Close(); } } else { foreach (var listBoxItem in listBoxID_AlunoEspecifico.Items) { connection.Open(); string i = listBoxItem.ToString(); string query5 = "insert into Aluno_Evento (ID_Aluno, ID_Evento, notificacao) values ('" + i + "','" + ID_Evento + "', '1');"; adapter.InsertCommand = new MySqlCommand(query5, connection); adapter.InsertCommand.ExecuteNonQuery(); connection.Close(); } } Clear(); dataGridView2.DataSource = LoadAgenda(); dataGridViewEventosTurma.DataSource = LoadEventosTurma(); listBoxAdicionar.Items.Clear(); listBoxID_AlunoEspecifico.Items.Clear(); } } else { connection.Open(); CriarEvento(); string ID_Turma = textBoxID_Turma3.Text; string ID_Disciplina = textBoxID_Disc3.Text; string Tipo = comboBoxTipo3.SelectedItem.ToString(); string Inicio = textBoxInicio.Text; string Fim = textBoxFim.Text; string Descricao = textBoxDesc3.Text; string query = "select * from Evento where ID_Turma = '" + ID_Turma + "' and ID_Disciplina = '" + ID_Disciplina + "' and Tipo = '" + Tipo + "' and dt_inicio = '" + Inicio + "' and dt_final = '" + Fim + "' and Descricao = '" + Descricao + "'"; MySqlCommand MyCommand2 = new MySqlCommand(query, connection); MySqlDataReader MyReader2; MyReader2 = MyCommand2.ExecuteReader(); while (MyReader2.Read()) { textBoxID_Evento3.Text = MyReader2["ID_Evento"].ToString(); } connection.Close(); connection.Open(); string ID_Evento = textBoxID_Evento3.Text; string ID_Professor = textBoxID_Prof.Text; string query2 = "insert into professor_Evento values ('" + ID_Evento + "', '" + ID_Professor + "',1)"; adapter.InsertCommand = new MySqlCommand(query2, connection); adapter.InsertCommand.ExecuteNonQuery(); connection.Close(); if (listBoxID_AlunoEspecifico.Items.Count == 0) { connection.Open(); string query3 = "select * from Aluno where ID_Turma = '" + ID_Turma + "' ;"; MySqlCommand MyCommand3 = new MySqlCommand(query3, connection); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { listBoxIDAluno.Items.Add((MyReader3["ID_Aluno"].ToString())); } connection.Close(); foreach (var listBoxItem in listBoxIDAluno.Items) { connection.Open(); string i = listBoxItem.ToString(); string query4 = "insert into Aluno_Evento (ID_Aluno, ID_Evento, notificacao) values ('" + i + "','" + ID_Evento + "', '1');"; adapter.InsertCommand = new MySqlCommand(query4, connection); adapter.InsertCommand.ExecuteNonQuery(); connection.Close(); } } else { foreach (var listBoxItem in listBoxID_AlunoEspecifico.Items) { connection.Open(); string i = listBoxItem.ToString(); string query4 = "insert into Aluno_Evento (ID_Aluno, ID_Evento, notificacao) values ('" + i + "','" + ID_Evento + "', '1');"; adapter.InsertCommand = new MySqlCommand(query4, connection); adapter.InsertCommand.ExecuteNonQuery(); connection.Close(); } } //Clear(); dataGridView2.DataSource = LoadAgenda(); dataGridViewEventosTurma.DataSource = LoadEventosTurma(); listBoxAdicionar.Items.Clear(); listBoxID_AlunoEspecifico.Items.Clear(); } } }
private void btnIngresar_Click(object sender, EventArgs e) { MySqlConnection connection = new MySqlConnection("datasource = mysql5044.site4now.net; username=a6f6c3_ibernal; password=sIyNbvYEf8H0; database=db_a6f6c3_ibernal;" ); MySqlCommand command; //Establecemos variables de tipo comando MySqlDataReader mdr; //Establecemos variables de tipo DataReader connection.Open(); //Abrimos la coneccion con la BD string selectQuery = "SELECT * FROM usuarios WHERE Nombre = '" + txtUsuario.Text + "' AND Contrasena = '" + txtContra.Text + "';"; //Establecemos una secuencia SQL command = new MySqlCommand(selectQuery, connection); //La mandamos en conjunto de la conexion a la BD mdr = command.ExecuteReader(); //Vemos si la secuencia arrpjp datos de regreso if (mdr.Read()) //si lo encontro datos { string MyConnection2 = "datasource = mysql5044.site4now.net; username=a6f6c3_ibernal; password=sIyNbvYEf8H0; database=db_a6f6c3_ibernal;" ; string Query = "update usuarios set LastLogin='******' where Nombre='" + this.txtUsuario.Text + "';"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); //Establecemos una nueva coneccion pero esta vez vamos a grabar la ultima fecha de coneccion del usuario MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); MyConn2.Close(); MessageBox.Show("Bienvenido!", "Acceso comprobado", MessageBoxButtons.OK, MessageBoxIcon.Information); //Una vez comprobado el acceso procedemos a ver que tipo de usuario es string idtenti = @"SELECT Tipo FROM usuarios WHERE Nombre='" + this.txtUsuario.Text + "';";//realizamos la consulta MySqlCommand Identificador = new MySqlCommand(idtenti, MyConn2); MySqlDataReader MyReader3; MyConn2.Open(); MyReader3 = Identificador.ExecuteReader(); string tipo; if (MyReader3.Read()) //si MyrRader3 lee datos entonces { tipo = MyReader3["Tipo"].ToString(); //asignamos en la variable string el tipo de usuario //MessageBox.Show(tipo); tipoCompartido = tipo; Form jefe = new ImpresosBernal.DashBoard_Jefe(); txtContra.Text = " "; txtUsuario.Text = ""; if (tipo == "Jefe") { jefe.Show(); } this.Visible = false; } MyConn2.Close(); } else { if (!(string.IsNullOrEmpty(txtUsuario.Text) || string.IsNullOrEmpty(txtContra.Text)))//Nos aseguramos que no esten vacias los textbox { MessageBox.Show("Credenciales incorrectas, por favor intente nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } connection.Close(); }
private void button1_Click(object sender, EventArgs e) { try { string MyConnection2 = "datasource=localhost;port=3306;username=root;password=9490"; //get curr location before updating and check it from the set.... string Query1 = "select current_location from world.transport where paid_id= " + this.textBox1.Text + ";"; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query1, MyConn2); MySqlDataAdapter adapt = new MySqlDataAdapter(MyCommand2); DataTable ds = new DataTable(); adapt.Fill(ds); string prev_loc = ds.Rows[0][0].ToString(); string next_loc = this.textBox2.Text; string[] South = { "Chennai", "Manipal", "Mangalore", "Udupi", "Goa", "Hyderabad" }; string[] North = { "Mumbai", "Delhi", "Ahemdabad", "Agra", "Goa" }; MessageBox.Show("Previous Location: " + prev_loc + " Current Location: " + next_loc); //Final location check string Query3 = "select drop_location from world.delivery where paid_id= " + this.textBox1.Text + ";"; MySqlConnection MyConn3 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand3 = new MySqlCommand(Query3, MyConn3); MySqlDataAdapter adapt1 = new MySqlDataAdapter(MyCommand3); DataTable dt = new DataTable(); adapt1.Fill(dt); string final_loc = ds.Rows[0][0].ToString(); if (final_loc == next_loc) { this.Hide(); Form1 f1 = new Form1(); MessageBox.Show("The Location has been reached."); } if (South.Contains(prev_loc) && South.Contains(next_loc)) { try { string Query = "Update world.transport set current_location = '" + this.textBox2.Text + "' where paid_id = " + this.textBox1.Text; MySqlConnection MyConn7 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand7 = new MySqlCommand(Query, MyConn7); MySqlDataReader MyReader3; MyConn7.Open(); MyReader3 = MyCommand7.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("Note: Updated the current location"); while (MyReader3.Read()) { } MyConn3.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //Previous UPDATE ROUTE /* try * { * MessageBox.Show("FIRST ELSE"); * string Query = "select * from world.path_finder where paid_id ="+this.textBox1.Text; * MySqlConnection MyConn6 = new MySqlConnection(MyConnection2); * MySqlCommand MyCommand6 = new MySqlCommand(Query, MyConn6); * MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); * MyAdapter.SelectCommand = MyCommand6; * DataTable dTable = new DataTable(); * MyAdapter.Fill(dTable); * dataGridView1.DataSource = dTable; * //MyConn2.Close(); * * } * catch (Exception ex) * { * MessageBox.Show(ex.Message); * } * //BACKTRACKING SHOW ROUTE IN GRID.*/ if (North.Contains(prev_loc) && North.Contains(next_loc)) { try { string Query = "Update world.transport set current_location= '" + this.textBox2.Text + "' where paid_id=" + this.textBox1.Text; MySqlConnection MyConn4 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand4 = new MySqlCommand(Query, MyConn4); MySqlDataReader MyReader4; MyConn4.Open(); MyReader4 = MyCommand4.ExecuteReader(); // Here our query will be executed and data saved into the database. MessageBox.Show("Note: Updated the current location"); while (MyReader4.Read()) { } MyConn4.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } try { string Query2 = "select * from world.path_finder where paid_id =" + this.textBox1.Text; MySqlConnection MyConn5 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand5 = new MySqlCommand(Query2, MyConn5); MySqlDataAdapter MyAdapter1 = new MySqlDataAdapter(); MyAdapter1.SelectCommand = MyCommand5; DataTable dTable1 = new DataTable(); MyAdapter1.Fill(dTable1); dataGridView2.DataSource = dTable1; } catch (Exception ex) { MessageBox.Show(ex.Message); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void BCl(object sender, RoutedEventArgs e) { int count = Mylist.Count / 3; int counter = 0; string MyConnection2 = "datasource=localhost;port=3306;username=root;password=;database=gpcenter;"; double x = 0, y = 0, z = 0; MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); int User_id = 1; int movement_id = 1; string code = "GP1.3gam3a_pre"; codenum++; string co = code + Convert.ToString(codenum); string q = "INSERT INTO `video` (`Id`, `Code`, `GroupId`, `MovementId`) VALUES (NULL, '" + co + "','" + User_id + "','" + movement_id + "');"; MySqlCommand MyCommand1 = new MySqlCommand(q, MyConn2); MySqlDataReader MyReader1; MyConn2.Open(); //int id = (int)MyCommand1.ExecuteScalar(); MyReader1 = MyCommand1.ExecuteReader(); while (MyReader1.Read()) { //string rid = MyReader1["Id"].ToString(); } MyConn2.Close(); MyConn2.Open(); string q2 = "SELECT Id FROM `video` WHERE Id=LAST_INSERT_ID()"; MySqlCommand MyCommand12 = new MySqlCommand(q2, MyConn2); MySqlDataReader MyReader12; MyReader12 = MyCommand12.ExecuteReader(); while (MyReader12.Read()) { } //int id = rid; int rid = (int)MyReader12["Id"]; int id = rid; MyConn2.Close(); int jointid = 1; for (int j = 0; j < count; j++) { if (counter <= Mylist.Count) { for (int i = 0; i < 3; i++) { if (i == 0) { x = Mylist[counter]; counter++; } if (i == 1) { y = Mylist[counter]; counter++; } if (i == 2) { z = Mylist[counter]; counter++; } } } string Query = "INSERT INTO `videopoint`( `VideoId`, `JointId`, `x`, `y`, `z`) VALUES ('" + id + "','" + jointid + "','" + x + "','" + y + "','" + z + "');"; MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); //MessageBox.Show("Save Data"); while (MyReader2.Read()) { } MyConn2.Close(); jointid++; if (jointid == 7) { jointid = 1; } } Mylist.Clear(); string qtest = "INSERT INTO `checkvideo` (`Id`, `VideoId`, `Value`, `CoachCheck`) VALUES (NULL, '" + id + "', NULL , '0');"; MySqlCommand MyCommand3test = new MySqlCommand(qtest, MyConn2); MySqlDataReader MyReader3; MyConn2.Open(); //int id = (int)MyCommand1.ExecuteScalar(); MyReader3 = MyCommand3test.ExecuteReader(); while (MyReader3.Read()) { //string rid = MyReader1["Id"].ToString(); } MyConn2.Close(); //sw.Close(); //filenum++; }
private void new_btn_Click(object sender, EventArgs e) { //create a random number TO CHANGE TO ENUMERATE Random rnd = new Random(); int projectid = rnd.Next(1, 100000); if (int.TryParse(nwyr_txtbx.Text, out year)) { year = int.Parse(nwyr_txtbx.Text); } else { MessageBox.Show("Please input a correct project year"); } //In case the project ID already exist MySqlConnection connection = new MySqlConnection(connec); connection.Open(); string query0 = "SELECT project_id FROM internal_communication_4.projects WHERE ( project_id = " + projectid + ")"; MySqlCommand idused = new MySqlCommand(query0, connection); MySqlDataReader MyReader3; MyReader3 = idused.ExecuteReader(); while (MyReader3.Read()) { if (MyReader3.GetString(0) != null) { Random rrnd = new Random(); projectid = rrnd.Next(1, 100000); } } connection.Close(); //text file saved Projects_class pro = new Projects_class(); pro.ID = projectid; pro.Project_name = nwnm_txtbx.Text; pro.Year = year; pro.Category = nwcat_txtbx.Text; proj.Add(pro); projectDA.Save(proj); //databased saved connection.Open(); string query = "INSERT INTO internal_communication_4.projects(project_id,project_name,project_year,project_category) VALUES('" + projectid + "','" + this.nwnm_txtbx.Text + "','" + this.year + "','" + this.nwcat_txtbx.Text + "')"; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader MyReader2; MyReader2 = command.ExecuteReader(); while (MyReader2.Read()) { } connection.Close(); MessageBox.Show("project " + pro.Project_name + " successfully created!"); nwnm_txtbx.Text = ""; nwyr_txtbx.Text = ""; nwcat_txtbx.Text = ""; this.Close(); project_selection_form pr = new project_selection_form(); pr.ShowDialog(); }
private void save_Click(object sender, EventArgs e) { Double t = Convert.ToDouble(this.tel.Text); Double t2 = Convert.ToDouble(254000000000 + t); String newtel = "+" + t2.ToString(); if (checkBox1.Checked == true) { //ADD NEW CUSTOMER string MyConnection2 = "datasource=techcube.co.ke;port=3306;username=techcube_galleria;password=Pandora.2017"; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into techcube_galleria.customer(name,passport,address,idno,tel,gender) values('" + this.name.Text + "','" + this.pass.Text + "','" + this.area.Text + "','" + this.idno.Text + "','" + newtel + "','" + this.gender.Text + "');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader2.Read()) { } MyReader2.Close(); MyConn2.Close(); } if (pass.Text != "N/A") { //UPDATE CUSTOMER DETAILS string MyConnection7 = "datasource=techcube.co.ke;port=3306;username=techcube_galleria;password=Pandora.2017"; //This is my insert query in which i am taking input from the user through windows forms string Query = "UPDATE techcube_galleria.customer set passport='" + pass.Text + "'WHERE idno='" + idno.Text + "'|| tel='" + tel.Text + "' "; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn7 = new MySqlConnection(MyConnection7); //This is command class which will handle the query and connection object. MySqlCommand MyCommand7 = new MySqlCommand(Query, MyConn7); MySqlDataReader MyReader7; MyConn7.Open(); MyReader7 = MyCommand7.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader7.Read()) { } MyReader7.Close(); MyConn7.Close(); } //GENERATE TOKEN string MyConnection4 = "datasource=techcube.co.ke;port=3306;username=techcube_galleria;password=root"; //This is my insert query in which i am taking input from the user through windows forms //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn4 = new MySqlConnection(MyConnection4); //This is command class which will handle the query and connection object. MyConn4.Open(); //get account no string q2 = "select COUNT(id) as idc from techcube_galleria.entries where promo='VALENTINES2017' ;"; MySqlCommand com4 = new MySqlCommand(q2, MyConn4); MySqlDataReader r2; r2 = com4.ExecuteReader(); r2.Read(); int ab = Convert.ToInt32(r2["idc"]) + 1; String raf = ("GALLERIA-VALS-" + ab).ToString(); r2.Close(); //ITERATE TRHOUGH ARRAY for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { object a = dataGridView1.Rows[i].Cells["Total"].Value; int aNumber = 0; int setlimit = 1000; if (a != null) { aNumber = Convert.ToInt32(a.ToString()); } int vouch = (aNumber / setlimit); dataGridView1.Rows[i].Cells["vouchers"].Value = vouch; //ASSIGN VALUABLES object va = dataGridView1.Rows[i].Cells["vouchers"].Value; String v = va.ToString(); object sh = dataGridView1.Rows[i].Cells["Shop"].Value; // String s = sh.ToString(); //String tot = a.ToString(); //SEARCH FOR SHOPNAME string shopconnection = "datasource=techcube.co.ke;port=3306;username=techcube_galleria;password=Pandora.2017"; //This is my insert query in which i am taking input from the user through windows forms string shopquery = "SELECT cname FROM techcube_galleria.shop WHERE name='" + sh + "'"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection shopconn = new MySqlConnection(shopconnection); //This is command class which will handle the query and connection object. MySqlCommand shopcommand = new MySqlCommand(shopquery, shopconn); MySqlDataReader shopreader; shopconn.Open(); shopreader = shopcommand.ExecuteReader(); // Here our query will be executed and data saved into the database. shopreader.Read(); String shopname = shopreader["cname"].ToString(); shopreader.Close(); shopconn.Close(); //VALIDATE TEL NO if (checkBox1.Checked == false) { string phone = this.tel.Text; //RUN INSERT SCRIPT try { //ADD NEW RAFFLE ENTRY string MyConnection3 = "datasource=techcube.co.ke;port=3306;username=techcube_galleria;password=Pandora.2017"; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into techcube_galleria.entries(customername,passport,tel,address,raffleno,idno,shop,amount,points,dateadded,promo)values('" + this.name.Text + "','" + this.pass.Text + "','" + phone + "','" + this.area.Text + "','" + raf + "','" + this.idno.Text + "','" + shopname + "','" + a + "','" + vouch + "','" + this.datea.Text + "','" + "VALENTINES2017');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader3.Read()) { } MyReader3.Close(); MyConn3.Close(); //RESET EVERYTHING } catch (Exception ex) { MessageBox.Show(ex.Message); } //END INSERT } else if (checkBox1.Checked == true) { //RUN INSERT SCRIPT try { //ADD NEW RAFFLE ENTRY string MyConnection3 = "datasource=techcube.co.ke;port=3306;username=techcube_galleria;password=Pandora.2017"; //This is my insert query in which i am taking input from the user through windows forms string Query = "insert into techcube_galleria.entries(customername,passport,tel,address,raffleno,idno,shop,amount,points,dateadded)values('" + this.name.Text + "','" + this.pass.Text + "','" + newtel + "','" + this.area.Text + "','" + raf + "','" + this.idno.Text + "','" + shopname + "','" + a + "','" + vouch + "','" + this.datea.Text + "');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader3.Read()) { } MyReader3.Close(); MyConn3.Close(); //RESET EVERYTHING } catch (Exception ex) { MessageBox.Show(ex.Message); } //END INSERT } } MessageBox.Show("ENTRIES SAVED"); tel.Enabled = true; tel.Text = "0"; idno.Enabled = true; idno.Text = ""; name.Enabled = false; name.Text = ""; pass.Enabled = false; pass.Text = ""; area.Enabled = false; area.Text = ""; checkBox1.Checked = false; dataGridView1.Rows.Clear(); }
private void button2_Click(object sender, EventArgs e) { string sql = null; string nome = textBoxnome.Text; string email = textBoxEmail.Text; string telemovel = textBoxTel.Text; string dn = textBoxDN.Text; string utilizador = textBoxUtilizador.Text; string hex = textBoxHex.Text; string dec = textBoxDec.Text; string connetionString = null; connetionString = "Server=localhost;Database=Scholendar;Uid=root"; MySqlConnection cnn; MySqlDataAdapter adapter = new MySqlDataAdapter(); cnn = new MySqlConnection(connetionString); if (comboBox1.SelectedItem.ToString() == "EE") { //ClearTxt(); if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text)) { MessageBox.Show("Preencha todos os campos!"); } else { sql = "insert into EE (Nome, Email, Telemovel, Utilizador, Pass) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "' , 'EE123A' )"; try { cnn.Open(); adapter.InsertCommand = new MySqlCommand(sql, cnn); adapter.InsertCommand.ExecuteNonQuery(); MessageBox.Show("Encarregado de Educação Inserido!"); ClearTxt(); comboBoxEE.Items.Clear(); FillcomboboxEE(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cnn.Close(); } } } else if (comboBox1.SelectedItem.ToString() == "Aluno") { //ClearTxt(); if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text) || string.IsNullOrEmpty(textBoxDN.Text) || string.IsNullOrEmpty(textBoxDec.Text) || string.IsNullOrEmpty(textBoxHex.Text) || comboBoxTurma.SelectedItem == null || comboBoxEE.SelectedItem == null) { MessageBox.Show("Preencha todos os campos!"); } else { try { cnn.Open(); string turma = comboBoxTurma.SelectedItem.ToString(); string Query3 = "select * from Turma where Turma ='" + turma + "'"; MySqlCommand MyCommand3 = new MySqlCommand(Query3, cnn); MySqlDataReader MyReader3; MyReader3 = MyCommand3.ExecuteReader(); while (MyReader3.Read()) { textBoxIDTurma.Text = MyReader3["ID_Turma"].ToString(); } cnn.Close(); cnn.Open(); string aluno = comboBoxEE.SelectedItem.ToString(); string QueryA = "select * from EE where Nome ='" + aluno + "'"; MySqlCommand MyCommand4 = new MySqlCommand(QueryA, cnn); MySqlDataReader MyReader4; MyReader4 = MyCommand4.ExecuteReader(); while (MyReader4.Read()) { textBoxAluno.Text = MyReader4["ID_EE"].ToString(); } cnn.Close(); cnn.Open(); string IDTurma = textBoxIDTurma.Text; string ID_EE = textBoxAluno.Text; sql = "insert into Aluno (Nome, Email, Telemovel, Utilizador,DataDeNascimento,Hex,De,Pass,ID_Turma, ID_EE) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "', '" + dn + "', '" + hex + "', '" + dec + "' , 'Aluno123A', '" + IDTurma + "' , '" + ID_EE + "' )"; adapter.InsertCommand = new MySqlCommand(sql, cnn); adapter.InsertCommand.ExecuteNonQuery(); MessageBox.Show("Aluno Inserido!"); ClearTxt(); comboBoxEE.SelectedItem = null; comboBoxTurma.SelectedItem = null; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cnn.Clone(); } } } else if (comboBox1.SelectedItem.ToString() == "Professor") { if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text) || string.IsNullOrEmpty(textBoxDec.Text) || string.IsNullOrEmpty(textBoxHex.Text) || comboBoxDisc.SelectedItem == null) { MessageBox.Show("Preencha todos os campos!"); } else { try { cnn.Open(); sql = "insert into Professor (Nome, Email, Telemovel, Utilizador, Pass, Hex, De) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "', 'Prof123A' , '" + hex + "', '" + dec + "')"; adapter.InsertCommand = new MySqlCommand(sql, cnn); adapter.InsertCommand.ExecuteNonQuery(); MessageBox.Show("Professor Inserido!"); cnn.Close(); cnn.Open(); string professor = textBoxnome.Text; string query = "select * from Professor where nome = '" + professor + "' "; MySqlCommand MyCommand = new MySqlCommand(query, cnn); MySqlDataReader MyReader; MyReader = MyCommand.ExecuteReader(); while (MyReader.Read()) { textBoxIDProf.Text = MyReader["ID_Professor"].ToString(); } cnn.Close(); string Disc1 = textBoxIDDisc.Text; string Disc2 = textBoxIDDisc2.Text; string Disc3 = textBoxIDDisc3.Text; string Disc4 = textBoxIDDisc4.Text; string Professor = textBoxIDProf.Text; cnn.Open(); string query2 = "insert into Prof_Disc values ('" + Disc1 + "', '" + Professor + "')"; adapter.InsertCommand = new MySqlCommand(query2, cnn); adapter.InsertCommand.ExecuteNonQuery(); cnn.Close(); if (comboBoxDisc2.SelectedItem != null) { cnn.Open(); string query3 = "insert into Prof_Disc values('" + Disc2 + "', '" + Professor + "')"; adapter.InsertCommand = new MySqlCommand(query3, cnn); adapter.InsertCommand.ExecuteNonQuery(); cnn.Close(); if (comboBoxDisc3.SelectedItem != null) { cnn.Open(); string query4 = "insert into Prof_Disc values('" + Disc3 + "', '" + Professor + "')"; adapter.InsertCommand = new MySqlCommand(query4, cnn); adapter.InsertCommand.ExecuteNonQuery(); cnn.Close(); if (comboBoxDisc4.SelectedItem != null) { cnn.Open(); string query5 = "insert into Prof_Disc values('" + Disc4 + "', '" + Professor + "')"; adapter.InsertCommand = new MySqlCommand(query5, cnn); adapter.InsertCommand.ExecuteNonQuery(); cnn.Close(); } } } ClearTxt(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cnn.Close(); } } } else if (comboBox1.SelectedItem.ToString() == "Admin") { if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text) || string.IsNullOrEmpty(textBoxDec.Text) || string.IsNullOrEmpty(textBoxHex.Text)) { MessageBox.Show("Preencha todos os campos!"); } else { try { cnn.Close(); cnn.Open(); sql = "insert into Admin (Nome, Email, Telemovel, Utilizador, Pass, Hex, De) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "', 'adm123' , '" + hex + "', '" + dec + "')"; adapter.InsertCommand = new MySqlCommand(sql, cnn); adapter.InsertCommand.ExecuteNonQuery(); MessageBox.Show("Admin Inserido!"); ClearTxt(); cnn.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { cnn.Close(); } } } }
private void btnAddmore_Click(object sender, EventArgs e) { int p_code = int.Parse(txtCode.Text); int p_qty = int.Parse(txtQty.Text); float p_unitPrice; int p_stock_id, p_stock_qty; //find stock record by barcode try { //This is my connection string i have assigned the database file address path string MyConnection2 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket"; //This is my insert query in which i am taking input from the user through windows forms string Query = "Select * from stock where barcode= '" + p_code + "'"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); //This is command class which will handle the query and connection object. MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader2.Read()) { p_unitPrice = float.Parse(MyReader2.GetString(3)); p_stock_id = int.Parse(MyReader2.GetString(0)); p_stock_qty = int.Parse(MyReader2.GetString(5)); int new_stock_qty = p_stock_qty - p_qty; float amount = p_qty * p_unitPrice; //remove qty from stock try { //This is my connection string i have assigned the database file address path string MyConnection4 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket"; //This is my update query in which i am taking input from the user through windows forms and update the record. string Query4 = "update stock set total_qty='" + new_stock_qty + "' where barcode='" + p_code + "';"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn4 = new MySqlConnection(MyConnection4); MySqlCommand MyCommand4 = new MySqlCommand(Query4, MyConn4); MySqlDataReader MyReader4; MyConn4.Open(); MyReader4 = MyCommand4.ExecuteReader(); while (MyReader4.Read()) { } MyConn4.Close();//Connection closed here } catch (Exception ex) { MessageBox.Show(ex.Message); } //insert sale record try { //This is my connection string i have assigned the database file address path string MyConnection3 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket"; //This is my insert query in which i am taking input from the user through windows forms string Query3 = "insert into `sale` (stock_id,qty,amount) values('" + p_stock_id + "','" + p_qty + "','" + amount + "');"; //This is MySqlConnection here i have created the object and pass my connection string. MySqlConnection MyConn3 = new MySqlConnection(MyConnection3); //This is command class which will handle the query and connection object. MySqlCommand MyCommand3 = new MySqlCommand(Query3, MyConn3); MySqlDataReader MyReader3; MyConn3.Open(); MyReader3 = MyCommand3.ExecuteReader(); // Here our query will be executed and data saved into the database. while (MyReader3.Read()) { } MyConn3.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } MyConn2.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } updateData(); }