public static void Delete(int id) { HardwareProduct deleteProd = Hcon.HardwareProducts.Where(p => p.ProductId == id).Single(); Hcon.HardwareProducts.Remove(deleteProd); Hcon.SaveChanges(); }
public static void Insert(HardwareProduct HP) { if (IsValid(HP)) { Hcon.HardwareProducts.Add(HP); Hcon.SaveChanges(); } }
public static bool IsValid(HardwareProduct HP) { if (HP.Title == "" || HP.Manufacturer == "" || HP.Description == "") { return(false); } else if ((double)HP.Price <= 0) { DialogResult drPrice = MessageBox.Show("Are you sure this product is 0 dollars? (y/n)", "REALLY?", MessageBoxButtons.YesNo, MessageBoxIcon.Information); return(drPrice == DialogResult.Yes); } else { return(true); } }
public static HardwareProduct getProduct(long id) { OracleConnection oracleConnection = new OracleConnection(ConfigurationManager.ConnectionStrings["Bazi"].ConnectionString); OracleCommand cmd = new OracleCommand(); cmd.Connection = oracleConnection; cmd.CommandText = "SELECT HARDID, PERFORMANSI, IMEMODEL,TO_CHAR(GODNAPROIZVOD,'DD-MM-YYYY'), SLIKAPATEKA, OPIS, BRPOSETENOST, NVL(vkupnaOcena,0) FROM HARDVERPROIZVOD WHERE HARDVERPROIZVOD.hardid=:prod"; cmd.Parameters.Add(new OracleParameter("prod", id)); HardwareProduct hp = new HardwareProduct(); try { oracleConnection.Open(); OracleDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { hp.hardid = rdr.GetInt64(0); hp.performansi = rdr.GetString(1); hp.imeModel = rdr.GetString(2); hp.slikaPateka = rdr.GetString(4); hp.opis = rdr.GetString(5); hp.brPosetenost = rdr.GetInt64(6); hp.vkupnaOcena = rdr.GetDouble(7); hp.godNaProizvod = rdr.GetString(3); } rdr.Close(); } catch (Exception e) { } finally { oracleConnection.Close(); } return hp; }
public static List<HardwareProduct> getPreviewProductsForSearch(string searchText) { OracleConnection oracleConnection = new OracleConnection(ConfigurationManager.ConnectionStrings["Bazi"].ConnectionString); OracleCommand cmd = new OracleCommand(); cmd.Connection = oracleConnection; cmd.CommandText = "SELECT HARDID, PERFORMANSI, IMEMODEL, SLIKAPATEKA, OPIS, BRPOSETENOST, NVL(VKUPNAOCENA,0),TO_CHAR(GODNAPROIZVOD,'DD-MM-YYYY') as GODNAPROIZVOD FROM HARDVERPROIZVOD WHERE upper(IMEMODEL) like upper(:SearchText)||'%'"; cmd.Parameters.Add(new OracleParameter("SearchText", searchText)); List<HardwareProduct> prodList = new List<HardwareProduct>(); try { oracleConnection.Open(); OracleDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { HardwareProduct p = new HardwareProduct(); p.hardid = rdr.GetInt64(0); p.performansi = rdr.GetString(1); p.imeModel = rdr.GetString(2); p.slikaPateka = rdr.GetString(3); p.opis = rdr.GetString(4); p.brPosetenost = rdr.GetInt64(5); p.vkupnaOcena = rdr.GetDouble(6); if (p.godNaProizvod != null) { p.godNaProizvod = rdr.GetString(7); } prodList.Add(p); } rdr.Close(); } catch (Exception e) { } finally { oracleConnection.Close(); } return prodList; }
public static List<HardwareProduct> getPreviewProducts(string filter) { OracleConnection oracleConnection = new OracleConnection(ConfigurationManager.ConnectionStrings["Bazi"].ConnectionString); OracleCommand cmd = new OracleCommand(); cmd.Connection = oracleConnection; if (filter == "all") cmd.CommandText = "SELECT HARDID, PERFORMANSI, IMEMODEL, SLIKAPATEKA, OPIS, BRPOSETENOST, NVL(VKUPNAOCENA,0),TO_CHAR(GODNAPROIZVOD,'DD-MM-YYYY') as GODNAPROIZVOD FROM HARDVERPROIZVOD "; else cmd.CommandText = "SELECT hp.HARDID, hp.PERFORMANSI, hp.IMEMODEL, hp.SLIKAPATEKA, hp.OPIS, hp.BRPOSETENOST, NVL(hp.VKUPNAOCENA,0),TO_CHAR(hp.GODNAPROIZVOD,'DD-MM-YYYY') as GODNAPROIZVOD FROM HARDVERPROIZVOD hp, TIPHARDVER th, KATEGORIJA k where hp.hardid = th.hardid and th.katid = k.katid and k.katime = :filter "; cmd.Parameters.Add(new OracleParameter("filter", filter)); List<HardwareProduct> prodList = new List<HardwareProduct>(); try { oracleConnection.Open(); OracleDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { HardwareProduct p = new HardwareProduct(); p.hardid = rdr.GetInt64(0); p.performansi = rdr.GetString(1); p.imeModel = rdr.GetString(2); p.slikaPateka = rdr.GetString(3); p.opis = rdr.GetString(4); p.brPosetenost = rdr.GetInt64(5); p.vkupnaOcena = rdr.GetDouble(6); p.godNaProizvod = rdr.GetString(7); prodList.Add(p); } rdr.Close(); } catch (Exception e) { } finally { oracleConnection.Close(); } return prodList; }
public static void Update(HardwareProduct HP) { Hcon.HardwareProducts.AddOrUpdate(HP); Hcon.SaveChanges(); }