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(); } }
public string AutoIDRakBuku() { String id = null; Koneksi conn = new Koneksi(); SqlConnection koneksi = conn.con(); try { using (koneksi) { koneksi.Open(); string sql = "select top 1 id_rak from tb_Rak order by id_rak desc"; SqlCommand sqlcom = new SqlCommand(sql, koneksi); using (sqlcom) { SqlDataReader dr = sqlcom.ExecuteReader(); if (dr.Read()) { string id_rak = dr.GetString(0); int subid = Convert.ToInt32(id_rak.Substring(1)); if (subid < 9) { id = "R0" + (subid + 1).ToString(); } else if (subid < 100) { id = "R" + (subid + 1).ToString(); } } else { id = "R01"; } } koneksi.Close(); } } catch (Exception e) { MessageBox.Show(e.Message); } return(id); }
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 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(); } }