public string AutoIDAdmin() { String id = null; Koneksi conn = new Koneksi(); SqlConnection koneksi = conn.con(); try { using (koneksi) { koneksi.Open(); string sql = "select top 1 id_admin from tb_Admin order by id_admin desc"; SqlCommand sqlcom = new SqlCommand(sql, koneksi); using (sqlcom) { SqlDataReader dr = sqlcom.ExecuteReader(); if (dr.Read()) { string id_admin = dr.GetString(0); int subid = Convert.ToInt32(id_admin.Substring(1)); if (subid < 9) { id = "A000" + (subid + 1).ToString(); } else if (subid < 100) { id = "A00" + (subid + 1).ToString(); } else if (subid < 1000) { id = "A0" + (subid + 1).ToString(); } else if (subid < 10000) { id = "A" + (subid + 1).ToString(); } } else { id = "A0001"; } } koneksi.Close(); } } catch (Exception e) { MessageBox.Show(e.Message); } return(id); }
private void Form1_Load(object sender, EventArgs e) { hapus_edit(); hapus_member(); cmbkjrsan.SelectedIndex = 0; AutoGeneratedID autoid = new AutoGeneratedID(); string id_member = autoid.AutoIDMember(); txtidmember.Text = id_member; txtidmember.ReadOnly = true; try { koneksi = conn.con(); koneksi.Open(); sql = "Select * from tb_Member order by id_member desc"; adapter.SelectCommand = new SqlCommand(sql, koneksi); adapter.Fill(ds, "Member"); dv = new DataView(); dv.Table = ds.Tables[0]; dataGridView1.DataSource = dv; dataGridView2.DataSource = dv; dataGridView3.DataSource = dv; dataGridView4.DataSource = dv; koneksi.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { koneksi.Close(); } }
private void MenuUtama_Load(object sender, EventArgs e) { SqlParameter sqlP; FileStream fs = new FileStream("tempadmin.txt", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); string line = sr.ReadLine(); label5.Text = line; String cek = label5.Text; sr.Close(); fs.Close(); Koneksi conn = new Koneksi(); SqlConnection koneksi = conn.con(); koneksi.Open(); SqlCommand cekadmin = new SqlCommand("select * from tb_Admin where id_admin = @cek ", koneksi); sqlP = cekadmin.Parameters.Add("@cek", SqlDbType.VarChar, 15); sqlP.Value = cek; try { SqlDataReader reader = cekadmin.ExecuteReader(); while (reader.Read()) { label6.Text = reader[3].ToString(); if (label6.Text == "Admin") { pictureBox1.Enabled = true; } else { pictureBox1.Enabled = false; } } } catch (Exception) { MessageBox.Show("Gagal"); } finally { koneksi.Close(); } }
private void pictureBox5_Click(object sender, EventArgs e) { Koneksi conn = new Koneksi(); SqlConnection koneksi = conn.con(); koneksi.Open(); string status = "No"; string status1 = "Yes"; SqlCommand sqlupdate = new SqlCommand("update tb_Admin set status = @status where status = @status1", koneksi); using (sqlupdate) { sqlupdate.Parameters.AddWithValue("@status", status); sqlupdate.Parameters.AddWithValue("@status1", status1); int result = sqlupdate.ExecuteNonQuery(); if (result != 0) { Login lgn = new Login(); lgn.Show(); this.Hide(); File.Delete("tempadmin.txt"); } } }
private void button2_Click(object sender, EventArgs e) { koneksi = conn.con(); koneksi.Open(); String id_admin = txtidadmin_hapus.Text; string nama = txtnama_hapus.Text; var peringatan = MessageBox.Show("Apakah Anda Ingin Benar-Benar Menghapus Data Ini!", "Peringatan", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (peringatan == DialogResult.Yes) { SqlCommand sqldelete = new SqlCommand("delete from tb_Admin WHERE id_admin = @id_admin", koneksi); using (sqldelete) { sqldelete.Parameters.AddWithValue("@nama", nama); sqldelete.Parameters.AddWithValue("@id_admin", id_admin); int result = sqldelete.ExecuteNonQuery(); if (result != 0) { adapter = new SqlDataAdapter("select * from tb_Admin order by id_admin desc", koneksi); DataTable dtMember = new DataTable(); sqldelete.ExecuteNonQuery(); dataGridView1.DataSource = dtMember; dataGridView4.DataSource = dtMember; dataGridView6.DataSource = dtMember; adapter.SelectCommand.ExecuteNonQuery(); adapter.Fill(dtMember); MessageBox.Show("Data Member Berhasil Dihapus!"); koneksi.Close(); hapus_admin(); } else { MessageBox.Show("Data Member Gagal Dihapus!"); } } } }
private void button1_Click(object sender, EventArgs e) { string nama = textBox1.Text; string pswd = textBox2.Text; Koneksi conn = new Koneksi(); SqlConnection koneksi = conn.con(); koneksi.Open(); SqlCommand sqllogin = new SqlCommand("Select * from tb_Admin where nama = @nama", koneksi); SqlParameter sqlP; sqlP = sqllogin.Parameters.Add("@nama", SqlDbType.VarChar, 15); sqlP.Value = nama; try { SqlDataReader reader = sqllogin.ExecuteReader(); if (reader.Read()) { string id = reader[0].ToString(); string user = reader[1].ToString(); string password = reader[5].ToString(); if (nama == user && pswd == password) { string status = "Yes"; koneksi = conn.con(); koneksi.Open(); SqlCommand sqlupdate = new SqlCommand("update tb_Admin set status = @status where nama = @nama", koneksi); using (sqlupdate) { sqlupdate.Parameters.AddWithValue("@status", status); sqlupdate.Parameters.AddWithValue("@nama", nama); int result = sqlupdate.ExecuteNonQuery(); if (result != 0) { FileStream fs = new FileStream("tempadmin.txt", FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(id); sw.Flush(); sw.Close(); fs.Close(); MenuUtama mu = new MenuUtama(); mu.Show(); this.Hide(); } } } else { MessageBox.Show("Login Gagal, Cek Nama Dan Password Anda!"); textBox1.Text = ""; textBox2.Text = ""; } } } catch (Exception) { MessageBox.Show("Gagal"); textBox1.Text = ""; textBox2.Text = ""; } finally { koneksi.Close(); } }
private void Peminjaman_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'cCIT_LibraryDataSet4.tb_Peminjaman' table. You can move, or remove it, as needed. this.tb_PeminjamanTableAdapter.Fill(this.cCIT_LibraryDataSet4.tb_Peminjaman); resetpengembalian(); textBox2.Enabled = false; btncari_tambah.Enabled = false; button2.Enabled = false; reset(); AutoGeneratedID auto = new AutoGeneratedID(); string id = auto.AutoIDPeminjaman(); textBox1.Text = id; try { koneksi = conn.con(); koneksi.Open(); sql = "Select p.id_peminjaman_detail, m.nama, p.status from tb_Peminjaman_Details p join tb_Member m on m.id_member = p.id_member where m.id_member = p.id_member order by id_peminjaman_detail desc"; adapter.SelectCommand = new SqlCommand(sql, koneksi); adapter.Fill(ds, "Peminjaman Detail"); dv = new DataView(); dv.Table = ds.Tables[0]; dataGridView2.DataSource = dv; dataGridView3.DataSource = dv; koneksi.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { koneksi.Close(); } }