Esempio n. 1
0
        public bool Delete(Pegawai p)
        {
            bool isSuccess = false;

            // conn.Open();
            try
            {
                string       sql = "DELETE FROM pegawai  WHERE IDPEGAWAI=@IDPEGAWAI";
                MySqlCommand cmd = new MySqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@IDPEGAWAI", p.IDPEG);


                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Esempio n. 2
0
        public bool validateUsername(Pegawai p)
        {
            string str = "select * from pegawai";

            conn.Open();
            MySqlCommand    command = new MySqlCommand(str, conn);
            MySqlDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                str = reader.GetString("USERNAME");
                if (str == p.Username)
                {
                    conn.Close();
                    return(true);
                }
            }
            conn.Close();
            return(false);
        }
Esempio n. 3
0
        public bool Insert(Pegawai p)
        {
            bool isSuccess = false;

            //SqlConnection conn = new SqlConnection(myconnstrng);
            conn.Open();
            try
            {
                string       sql = "INSERT INTO pegawai(NAMA_PEGAWAI,USERNAME,PASSWORD,ALAMAT_PEGAWAI,NO_TELP_PEGAWAI,GAJI,ROLE,CABANG) VALUES(@NAMA_PEGAWAI,@USERNAME,@PASSWORD,@ALAMAT_PEGAWAI,@NO_TELP_PEGAWAI,@GAJI,@ROLE,@CABANG)";
                MySqlCommand cmd = new MySqlCommand(sql, conn);

                //cmd.Parameters.AddWithValue("@IDPEGAWAI", p.IDPEG);
                cmd.Parameters.AddWithValue("@NAMA_PEGAWAI", p.Name);
                cmd.Parameters.AddWithValue("@USERNAME", p.Username);
                cmd.Parameters.AddWithValue("@PASSWORD", p.Password);
                cmd.Parameters.AddWithValue("@ALAMAT_PEGAWAI", p.Alamat);
                cmd.Parameters.AddWithValue("@NO_TELP_PEGAWAI", p.Telepon);
                cmd.Parameters.AddWithValue("@GAJI", p.Gaji);
                cmd.Parameters.AddWithValue("@ROLE", p.Role);
                cmd.Parameters.AddWithValue("@CABANG", p.cabang);
                //   conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Esempio n. 4
0
        public bool Update(Pegawai p)
        {
            bool isSuccess = false;

            conn.Open();
            try
            {
                string       sql = "UPDATE pegawai SET NAMA_PEGAWAI=@NAMA_PEGAWAI,USERNAME=@USERNAME,PASSWORD=@PASSWORD,ALAMAT_PEGAWAI=@ALAMAT_PEGAWAI,NO_TELP_PEGAWAI=@NO_TELP_PEGAWAI,GAJI=@GAJI,ROLE=@ROLE, CABANG=@CABANG WHERE IDPEGAWAI=@IDPEGAWAI  ";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@IDPEGAWAI", p.IDPEG);
                cmd.Parameters.AddWithValue("@NAMA_PEGAWAI", p.Name);
                cmd.Parameters.AddWithValue("@USERNAME", p.Username);
                cmd.Parameters.AddWithValue("@PASSWORD", p.Password);
                cmd.Parameters.AddWithValue("@ALAMAT_PEGAWAI", p.Alamat);
                cmd.Parameters.AddWithValue("@NO_TELP_PEGAWAI", p.Telepon);
                cmd.Parameters.AddWithValue("@GAJI", p.Gaji);
                cmd.Parameters.AddWithValue("@ROLE", p.Role);
                cmd.Parameters.AddWithValue("@CABANG", p.cabang);
                // conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }
Esempio n. 5
0
        public bool Delete(Pegawai p)
        {
            bool          isSuccess = false;
            SqlConnection conn      = new SqlConnection(myconnstrng);

            try
            {
                string     sql = "DELETE FROM pegawai  WHERE NAMA_PEGAWAI=@NAMA_PEGAWAI ";
                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@NAMA_PEGAWAI", p.Name);
                cmd.Parameters.AddWithValue("@USERNAME", p.Username);
                cmd.Parameters.AddWithValue("@PASSWORD", p.Password);
                cmd.Parameters.AddWithValue("@ALAMAT_PEGAWAI", p.Alamat);
                cmd.Parameters.AddWithValue("@NO_TELP_PEGAWAI", p.Telepon);
                cmd.Parameters.AddWithValue("@GAJI", p.Gaji);
                cmd.Parameters.AddWithValue("@ROLE", p.Role);

                conn.Open();
                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                conn.Close();
            }
            return(isSuccess);
        }