public List <InventoryR> GetAllProduct() { string query = "SELECT * from inventory"; List <InventoryR> iList = new List <InventoryR>(); DatabaseConnection dc = new DatabaseConnection(); dc.ConnectWithDB(); SqlDataReader sdr = dc.GetData(query); while (sdr.Read()) { InventoryR i = new InventoryR(); i.ProductId = sdr["ProductId"].ToString(); i.ProductName = sdr["ProductName"].ToString(); i.Volume = Convert.ToInt32(sdr["Volume"]); i.Price = Convert.ToDouble(sdr["Price"]); i.Store = sdr["Store"].ToString(); i.Category = sdr["Catagory"].ToString(); i.Tax = Convert.ToInt32(sdr["Tax"]); iList.Add(i); } dc.CloseConnection(); return(iList); }
public List <InventoryR> searchInventory(string text) { string query = "SELECT * from inventory WHERE ProductId like '%" + text + "%' or ProductName like '%" + text + "%' or Volume like '%" + text + "%' or Price like '%" + text + "%' or Store like '%" + text + "%' or Catagory like '%" + text + "%' or Tax like '%" + text + "%'"; List <InventoryR> iList = new List <InventoryR>(); DatabaseConnection dc = new DatabaseConnection(); dc.ConnectWithDB(); SqlDataReader sdr = dc.GetData(query); while (sdr.Read()) { InventoryR i = new InventoryR(); i.ProductId = sdr["ProductId"].ToString(); i.ProductName = sdr["ProductName"].ToString(); i.Price = Convert.ToDouble(sdr["Price"]); i.Volume = Convert.ToInt32(sdr["Volume"]); i.Store = sdr["Store"].ToString(); i.Category = sdr["Catagory"].ToString(); i.Tax = Convert.ToInt32(sdr["Tax"]); iList.Add(i); } dc.CloseConnection(); return(iList); }
public bool Update(InventoryR i) { try { // INSERT INTO inventory(ProductName,ProductId,Volume,Price,Store,Category,Tax) VALUES ("yamaha 180","y180",10,120000,"basundhora","bike",5); string query = "UPDATE inventory SET ProductId = '" + i.ProductId + "',ProductName = '" + i.ProductName + "', Volume =" + i.Volume + ", Price = " + i.Price + ", Store= '" + i.Store + "',Catagory= '" + i.Category + "',Tax= " + i.Tax + "WHERE ProductId = '" + i.ProductId + "' "; DatabaseConnection dc = new DatabaseConnection(); dc.ConnectWithDB(); int x = dc.ExecuteSQL(query); dc.CloseConnection(); return(true); } catch (Exception) { return(false); } }
public bool Insert(InventoryR i) { try { // INSERT INTO inventory(ProductName,ProductId,Volume,Price,Store,Category,Tax) VALUES ("yamaha 180","y180",10,120000,"basundhora","bike",5); string query = " INSERT into inventory VALUES ('" + i.ProductId + "','" + i.ProductName + "', " + i.Volume + ", " + i.Price + ", '" + i.Store + "', '" + i.Category + "' , " + i.Tax + ") "; DatabaseConnection dc = new DatabaseConnection(); dc.ConnectWithDB(); int x = dc.ExecuteSQL(query); dc.CloseConnection(); return(true); } catch (Exception) { return(false); } }
public bool UpdatePrice(InventoryR er) { try { // UPDATE employee SET DepartmentName="sales" WHERE id="M102"; string query = "UPDATE inventory SET ProductId = '" + er.ProductId + "',Price =" + er.Price + " WHERE ProductId = '" + er.ProductId + "' "; DatabaseConnection dc = new DatabaseConnection(); dc.ConnectWithDB(); int x = dc.ExecuteSQL(query); dc.CloseConnection(); return(true); } catch (Exception) { return(false); } }
public InventoryR GetProduct(string productId) { string query = "SELECT * from inventory WHERE ProductId = '" + productId + "'"; InventoryR i = null; DatabaseConnection dc = new DatabaseConnection(); dc.ConnectWithDB(); SqlDataReader sdr = dc.GetData(query); if (sdr.Read()) { //(ProductName,ProductId,Volume,Price,Store,Category,Tax) i = new InventoryR(); i.ProductId = sdr["ProductId"].ToString(); i.ProductName = sdr["ProductName"].ToString(); i.Price = Convert.ToDouble(sdr["Volume"]); i.Volume = Convert.ToInt32(sdr["Price"]); i.Store = sdr["Quantity"].ToString(); i.Category = sdr["Catagory"].ToString(); i.Tax = Convert.ToInt32(sdr["Tax"]); } dc.CloseConnection(); return(i); }