public string PostComponent(clsAllComponents prComponent) { // add try { int lcRecCount = clsDbConnection.Execute("INSERT INTO tblProduct" + " (Type, Name, tblCategoryName, Price, Quantity, Brand, Condition, Warranty, Modified)" + "VALUES (@Type, @Name, @CategoryName, @Price, @Quantity, @Brand, @Condition, @Warranty, @Modified)", prepareComponentParameters(prComponent)); if (lcRecCount == 1) { return("Component succesfully added"); } else { return("Component Could not be added "); } } catch (SqlException ex) { if (ex.Number == 2627) { return("There is already item with this name, select Another name for the item and try again"); } else { return(ex.GetBaseException().Message); } } }
private Dictionary <string, object> prepareComponentParameters(clsAllComponents prComponent) { Dictionary <string, object> par = new Dictionary <string, object>(10); par.Add("Name", prComponent.Name); par.Add("CategoryName", prComponent.tblCategoryName); par.Add("Price", prComponent.Price); par.Add("Quantity", prComponent.Quantity); par.Add("Brand", prComponent.Brand); par.Add("Type", prComponent.Type); par.Add("Condition", prComponent.Condition); par.Add("Warranty", prComponent.Warranty); par.Add("Modified", prComponent.Modified); return(par); }
public clsAllComponents GetComponentDetails(string ID) { Dictionary <string, object> par = new Dictionary <string, object>(1); par.Add("Id", ID); DataTable lcResult = clsDbConnection.GetDataTable("SELECT * FROM tblProduct WHERE Name = @Id", par); clsAllComponents lcComponents = new clsAllComponents(); return(new clsAllComponents() { Name = (string)lcResult.Rows[0]["Name"], tblCategoryName = (string)lcResult.Rows[0]["tblCategoryName"], Brand = (string)lcResult.Rows[0]["Brand"], Type = (string)lcResult.Rows[0]["Type"], Condition = (string)lcResult.Rows[0]["Condition"], Warranty = lcResult.Rows[0]["Warranty"] is DBNull ? (float?)null : Convert.ToSingle(lcResult.Rows[0]["Warranty"]) }); }
public string PutComponent(clsAllComponents prComponent) { // insert try { int lcRecCount = clsDbConnection.Execute("UPDATE tblProduct SET" + " Type = @Type, Name = @Name, tblCategoryName = @CategoryName, Price = @Price, Quantity = @Quantity, Brand = @Brand, Condition = @Condition, Warranty = @Warranty, Modified = @Modified" + " WHERE Name = @Name", prepareComponentParameters(prComponent)); if (lcRecCount == 1) { return("Component succesfully Updated"); } else { return("Item No longer exists "); } } catch (SqlException) { return("Item no longer exists"); } }