Exemple #1
0
    public List <clsMBuku> TampilData()
    {
        using (SqlConnection conn = new SqlConnection(StrConn))
        {
            string          Query   = "SELECT * FROM Buku;";
            List <clsMBuku> tmpBaca = new List <clsMBuku>();
            SqlCommand      cmd     = new SqlCommand(Query, conn);

            SqlDataReader reader;
            conn.Open();
            reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    clsMBuku objTemp = new clsMBuku();
                    objTemp.FKdJenis   = reader["KdJenis"].ToString();
                    objTemp.FKdBuku    = reader["KdBuku"].ToString();
                    objTemp.FJudul     = reader["Judul"].ToString();
                    objTemp.FPengarang = reader["Pengarang"].ToString();
                    objTemp.FHarga     = System.Convert.ToDouble(reader["Harga"]);
                    objTemp.FGambar    = reader["Gambar"].ToString();
                    objTemp.FStock     = System.Convert.ToInt32(reader["Stock"]);
                    tmpBaca.Add(objTemp);
                }
            }
            return(tmpBaca);
        }
    }
Exemple #2
0
 protected void btnUbah_Click(object sender, EventArgs e)
 {
     try
     {
         _MBuku = new clsMBuku();
         int _hasil;
         _MBuku.PKdBuku    = KdBuku.Text;
         _MBuku.PJudul     = Judul.Text;
         _MBuku.PHarga     = System.Convert.ToDouble(Harga.Text);
         _MBuku.PPengarang = Pengarang.Text;
         string GbrBuku = "";
         if (FUGbr.HasFile == true)
         {
             GbrBuku = System.IO.Path.GetFileName(FUGbr.PostedFile.FileName);
             FUGbr.SaveAs(Server.MapPath("~/Gambar/Upload/") + GbrBuku);
         }
         _MBuku.PGambar  = GbrBuku;
         _MBuku.PStock   = System.Convert.ToInt32(Stok.Text);
         _MBuku.PKdJenis = ddJenis.SelectedItem.Value.ToString();
         _hasil          = _MBuku.Ubah();
         if (_hasil == 1)
         {
             string pesan = "alert(\"Data Behasil Diubah\");";
             ScriptManager.RegisterStartupScript
                 (this, GetType(), "UBAH DATA", pesan, true);
             bersih();
             KdBuku.Text = _MBuku.autonumber();
         }
         else
         {
             string pesan = "alert(\"Data Tidak Berhasil Diubah\");";
             ScriptManager.RegisterStartupScript
                 (this, typeof(string), "UBAH DATA", pesan, true);
         }
     }
     catch (Exception ex)
     {
         string errorex = ex.Message;
         string pesan   = "alert(\"ERROR LAINNYA;'" + errorex + "\");";
         ScriptManager.RegisterStartupScript
             (this, GetType(), "UBAH DATA", pesan, true);
     }
 }