private void btnSubmit_Click(object sender, EventArgs e)
        {
            string query =
                "insert into siswa(NIS, nama, email, jurusan, kelas, password, no_hp, ttl, motto, alamat)" +
                " values ('" + tbNIS.Text + "', '" + tbNama.Text + "', '" + tbEmail.Text + "', '" +
                cbJurusan.Text + "', '" + cbKelas.Text + "','" + tbPass.Text + "', '" + tbNo.Text + "', " +
                "'" + dateTimePicker1.Value.Date.ToString("yyyyMMdd") + "', '" + tbMotto.Text + "', '" + tbAlamat.Text + "') ;";
            MySqlDataReader reader;

            Form_Login f1 = new Form_Login();

            try
            {
                connect.Open();
                MySqlCommand SQLCommand = new MySqlCommand(query, connect);

                if (tbNIS.TextLength > 5)
                {
                    MessageBox.Show("Panjang NIS tidak boleh lebih dari 5");
                }
                else if (tbNIS.Text.Equals("") || tbNama.Text.Equals("") || tbEmail.Equals("") || cbJurusan.Text.Equals("") ||
                         cbKelas.Text.Equals("") || tbPass.Text.Equals("") || tbNo.Text.Equals("") || tbMotto.Text.Equals("") ||
                         tbAlamat.Text.Equals(""))
                {
                    MessageBox.Show("Data harus terisi semua");
                }
                else
                {
                    reader = SQLCommand.ExecuteReader();
                    this.Dispose();
                    f1.ShowDialog();
                }
                //MessageBox.Show("Connected");*/
                connect.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("NIS sudah memiliki akun");
            }
        }
Exemple #2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            Form_Login   frm1 = new Form_Login();
            MySqlCommand cmd, cmd2;
            FileStream   fs;
            BinaryReader br;

            string CmdGetNama = "Select nama from siswa where nis='" + frm1.getuid() + "'";

            //string CmdGetNama = "Select nama from siswa where nis='55555'";
            cmd2 = new MySqlCommand(CmdGetNama, con);

            if (tbKet.Text.Length > 0)
            {
                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 = "INSERT into kenangan(nis, nama, gambar, video, keterangan) values (@nis, @nama, @Image, @video, @ket)";
                        cmd = new MySqlCommand(CmdString, con);

                        cmd.Parameters.Add("@Image", MySqlDbType.Blob);
                        //cmd.Parameters.Add("@id", MySqlDbType.Int16, 5);
                        cmd.Parameters.Add("@nis", MySqlDbType.Int16, 5);
                        cmd.Parameters.Add("@nama", MySqlDbType.VarChar, 100);
                        cmd.Parameters.Add("@video", MySqlDbType.VarChar, 10000);
                        cmd.Parameters.Add("@ket", MySqlDbType.VarChar, 100000);

                        cmd.Parameters["@Image"].Value = ImageData;
                        // cmd.Parameters["@id"].Value = 0;
                        cmd.Parameters["@nis"].Value   = frm1.getuid();
                        cmd.Parameters["@video"].Value = tbVideo.Text;
                        cmd.Parameters["@ket"].Value   = tbKet.Text;
                        con.Open();
                        MySqlDataReader nama_read = cmd2.ExecuteReader();
                        if (nama_read.Read())
                        {
                            cmd.Parameters["@nama"].Value = nama_read.GetValue(0).ToString();
                        }
                        con.Close();

                        con.Open();
                        int RowsAffected = cmd.ExecuteNonQuery();

                        if (RowsAffected > 0)
                        {
                            MessageBox.Show("Data berhasil di upload");
                            Form_AlbumKenangan frm9 = new Form_AlbumKenangan();
                            this.Dispose();
                            frm9.ShowDialog();
                        }
                        con.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }
            }
        }