public static Pembelian FindOneByKode(string kode) { Database.OpenConnection(); string select = String.Concat("SELECT * FROM ", nama_tabel, " WHERE kode = @kode"); Sql.MySqlDataAdapter da = new Sql.MySqlDataAdapter(); da.SelectCommand = new Sql.MySqlCommand(select, Database.conn); da.SelectCommand.Parameters.AddWithValue("@kode", kode); Sql.MySqlCommandBuilder cb = new Sql.MySqlCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); Database.CloseConnection(); Pembelian pembelian = new Pembelian(); if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Rows[0]; pembelian.setId(Convert.ToInt32(dr["id"])); pembelian.setKode(dr["kode"].ToString()); pembelian.setSupplier(Supplier.FindOneById(Convert.ToInt16(dr["id_supplier"]))); pembelian.setCreatedAt(Convert.ToDateTime(dr["created_at"])); pembelian.setUpdatedAt(Convert.ToDateTime(dr["updated_at"])); return(pembelian); } return(null); }
public static PembelianDetail FindOneById(int id) { Database.OpenConnection(); string select = String.Concat("SELECT * FROM ", nama_tabel, " WHERE id = @id"); Sql.MySqlDataAdapter da = new Sql.MySqlDataAdapter(); da.SelectCommand = new Sql.MySqlCommand(select, Database.conn); da.SelectCommand.Parameters.AddWithValue("@id", id); Sql.MySqlCommandBuilder cb = new Sql.MySqlCommandBuilder(da); DataSet ds = new DataSet(); da.Fill(ds); Database.CloseConnection(); PembelianDetail pembelianDetail = new PembelianDetail(); if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Rows[0]; pembelianDetail.setId(Convert.ToInt32(dr["id"])); pembelianDetail.setBarang(Barang.FindOneById(Convert.ToInt32(dr["id_barang"]))); pembelianDetail.setPembelian(Pembelian.FindOneById(Convert.ToInt32(dr["id_pembelian"]))); pembelianDetail.setKuantitas(Convert.ToInt32(dr["kuantitas"])); pembelianDetail.setHargaBarang(Convert.ToDecimal(dr["harga_barang"])); pembelianDetail.setCreatedAt(Convert.ToDateTime(dr["created_at"])); pembelianDetail.setUpdatedAt(Convert.ToDateTime(dr["updated_at"])); return(pembelianDetail); } return(null); }
public PembelianDetail setPembelian(Pembelian pembelian) { this.pembelian = pembelian; return(this); }