private void btHome_Click(object sender, EventArgs e) { Form_Home fr3 = new Form_Home(); this.Dispose(); fr3.ShowDialog(); }
private void close_Click(object sender, EventArgs e) { this.Visible = false; Form_Home frm3 = new Form_Home(); frm3.ShowDialog(); }
private void btnLogin_Click(object sender, EventArgs e) { string query = "select * from siswa where NIS = '" + tbNIS.Text + "';"; MySqlDataReader reader; Form_Home f3 = new Form_Home(); UserID = tbNIS.Text; try { connect.Open(); MySqlCommand SQLCommand = new MySqlCommand(query, connect); reader = SQLCommand.ExecuteReader(); int count = 0; while (reader.Read()) { count = count + 1; } if (count == 1 && tbPass.Text == reader["password"].ToString()) { this.Visible = false; f3.Show(); } else if (count == 1 && tbPass.Text != reader["password"].ToString()) { MessageBox.Show("Password Salah"); } else if (count == 0) { MessageBox.Show("Akun belum terdaftar"); } connect.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { Form_Home fr3 = new Form_Home(); MySqlCommand cmd; FileStream fs; BinaryReader br; int RowsAffected = 0; //Kalo ubah foto try { if (tbFoto.Text.Length > 0) { string FileName = tbFoto.Text; byte[] ImageData; fs = new FileStream(FileName, FileMode.Open, FileAccess.Read); br = new BinaryReader(fs); ImageData = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); string CmdString = "UPDATE siswa set gambar=@Image " + "where NIS='" + lblShowNis.Text + "'"; cmd = new MySqlCommand(CmdString, con); cmd.Parameters.Add("@Image", MySqlDbType.Blob); cmd.Parameters["@Image"].Value = ImageData; con.Open(); RowsAffected = cmd.ExecuteNonQuery(); RowsAffected = 1; con.Close(); } else if (lblShowNis.Text.Length > 0) { string CmdString = "UPDATE siswa set nama=@Nama, email=@Email, alamat=@Alamat, no_hp=@Nope, motto=@Motto, ttl=@Ttl " + "where NIS='" + lblShowNis.Text + "'"; cmd = new MySqlCommand(CmdString, con); cmd.Parameters.Add("@Nama", MySqlDbType.VarChar, 50); cmd.Parameters.Add("@Email", MySqlDbType.VarChar, 100); cmd.Parameters.Add("@Alamat", MySqlDbType.VarChar, 100); cmd.Parameters.Add("@Nope", MySqlDbType.VarChar, 100); cmd.Parameters.Add("@Motto", MySqlDbType.VarChar, 100); cmd.Parameters.Add("@Ttl", MySqlDbType.Date); cmd.Parameters["@Nama"].Value = tbNama.Text; cmd.Parameters["@Email"].Value = tbEmail.Text; cmd.Parameters["@Alamat"].Value = tbAlamat.Text; cmd.Parameters["@Nope"].Value = tbTelp.Text; cmd.Parameters["@Motto"].Value = tbMotto.Text; cmd.Parameters["@Ttl"].Value = dateTimePicker1.Value; con.Open(); RowsAffected = cmd.ExecuteNonQuery(); RowsAffected = 1; con.Close(); } if (RowsAffected > 0) { MessageBox.Show("Data berhasil di update"); } else { MessageBox.Show("Data harus lengkap!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }