/// <summary> /// Initializes a new instance of the <see cref="DataObject" /> class. /// </summary> /// <param name="id">The id.</param> /// <param name="getSProc">The get S proc.</param> public DataObject(int id, string getSProc) { DatabaseConnection db = new DatabaseConnection(); List<DataObject> me = db.SProcToObjectList(this.GetType(),getSProc, new KeyValuePair<string,object>("@Id",id)); db.Dispose(); DataObjectSerialisers.Copy(me[0], this); }
/// <summary> /// Saves this instance. /// </summary> public void Save() { DatabaseConnection db = new DatabaseConnection(); db.RunScalarCommand(new System.Data.SqlClient.SqlCommand(this.GetSaveSQL(this.Id, "Pricelists"))); db.Dispose(); }
/// <summary> /// Creates this instance. /// </summary> public Pricelist Create() { DatabaseConnection db = new DatabaseConnection(); System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand(this.GetInsertSQL("Pricelists")); db.RunScalarCommand(com); Pricelist p = new Pricelist(db.GetIdentity()); db.Dispose(); return p; }
/// <summary> /// Deletes all product line links for this pricelist /// </summary> public void ClearProductLines() { DatabaseConnection db = new DatabaseConnection(); db.SProc("ClearPricelistsProductLinesLinks", new KeyValuePair<string, object>("@PricelistId", this.Id)); db.Dispose(); }
/// <summary> /// Deletes the specified pricelist id. /// </summary> /// <param name="PricelistId">The pricelist id.</param> public static void Delete(int PricelistId) { DatabaseConnection db = new DatabaseConnection(); db.SProc("DeletePricelist", new KeyValuePair<string, object>("@Id", PricelistId)); db.Dispose(); }
/// <summary> /// Attaches the product line to the pricelist /// </summary> /// <param name="PricelistId">The pricelist id.</param> /// <param name="ProductLineId">The product line id.</param> public static void AttachProductLine(int PricelistId, int ProductLineId) { DatabaseConnection db = new DatabaseConnection(); db.SProc("AttachProductLineToPricelist", new KeyValuePair<string, object>("@PricelistId", PricelistId), new KeyValuePair<string, object>("@ProductLineId", ProductLineId)); db.Dispose(); }
public static string GetDataView(string model,HttpRequest Request) { DatabaseConnection db = new DatabaseConnection(); List<DataObject> results = new List<DataObject>(); Type type; switch (model) { case "Pricelists": type = typeof(Pricelist); results = db.SProcToObjectList(type,"GetPricelistsForUser",new KeyValuePair<string,object>("@UserId",1)); break; case "Quotes": type = typeof(Quote); results = db.SProcToObjectList(type, "GetAllQuotesForUser", new KeyValuePair<string, object>("@UserId", 1)); break; case "Users": type = typeof(User); results = db.SProcToObjectList(type, "GetAllUsers"); break; case "QuoteItems": type = typeof(QuoteItem); int quoteid = Convert.ToInt32(Request.Params["QuoteId"]); results = db.SProcToObjectList(type, "GetQuoteItems", new KeyValuePair<string, object>("@QuoteId", quoteid)); break; case "ProductsToQuote": type = typeof(PricedProduct); results = db.SProcToObjectList(type, "GetProductsAvailableToQuote", new KeyValuePair<string, object>("@QuoteId",Convert.ToInt32(Request.Params["QuoteId"]))); break; case "GetPricedProductsToQuote": type = typeof(PricedProduct); results = db.SProcToObjectList(type, "GetPricedProductsToQuote", new KeyValuePair<string, object>("@PricelistId", Convert.ToInt32(Request.Params["PricelistId"])), new KeyValuePair<string, object>("@ProductLineId", Convert.ToInt32(Request.Params["ProductLineId"]))); break; case "GetPricedPackagesToQuote": type = typeof(PricedPackage); results = db.SProcToObjectList(type, "GetPricedPackagesToQuote", new KeyValuePair<string, object>("@PricelistId", Convert.ToInt32(Request.Params["PricelistId"])), new KeyValuePair<string, object>("@ProductLineId", Convert.ToInt32(Request.Params["ProductLineId"]))); break; case "Products": type = typeof(Product); results = db.SProcToObjectList(type, "GetAllProducts"); break; case "ProductLines": type = typeof(ProductLine); results = db.SProcToObjectList(type, "GetAllProductLines"); break; case "Packages": type = typeof(Package); results = db.SProcToObjectList(type, "GetPackages"); break; case "PackagesInProductLine": type = typeof(Package); results = db.SProcToObjectList(type, "GetPackagesInProductLine", new KeyValuePair<string, object>("@ProductLineId", Convert.ToInt32(Request.Params["ProductLineId"]))); break; case "PackageComponents": type = typeof(PackageComponent); if (String.IsNullOrEmpty(Request.Params["PackageId"])) results = new List<DataObject>(); else results = db.SProcToObjectList(type, "GetPackageComponentsInPackage", new KeyValuePair<string, object>("@PackageId", Convert.ToInt32(Request.Params["PackageId"]))); break; } db.Dispose(); return DataObjectSerialisers.GetJson(results); }
public PricedProduct Price(int PricelistId) { DatabaseConnection db = new DatabaseConnection(); List<DataObject> res = db.SProcToObjectList(typeof(PricedProduct),"GetPricedProduct", new KeyValuePair<string, object>("@ProductId", this.Id), new KeyValuePair<string, object>("@PricelistId", PricelistId)); if (res.Count >0 && res[0].GetType() == typeof( PricedProduct) ) { return (PricedProduct)res[0]; } else { throw new PricingException("Product not priced in this pricelist"); } }
/// <summary> /// Creates this instance. /// </summary> public void Create() { DatabaseConnection db = new DatabaseConnection(); System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand(this.GetInsertSQL("ProductLines")); db.RunScalarCommand(com); db.Dispose(); }
/// <summary> /// Saves this instance. /// </summary> public void Save() { DatabaseConnection db= new DatabaseConnection(); db.RunScalarCommand(new System.Data.SqlClient.SqlCommand(this.GetSaveSQL(this.Id,"Quotes"))); db.Dispose(); this.UpdateTotals(); }
/// <summary> /// Updates the totals values of the quote by adding the values of the pricing items. /// </summary> /// <param name="quoteId">The quote id.</param> public static void UpdateTotals(int quoteId) { DatabaseConnection db = new DatabaseConnection(); object result = db.SProcToObject("UpdateTotals", new KeyValuePair<string, object>("@QuoteId", quoteId)); db.Dispose(); }
/// <summary> /// Creates the quote. /// </summary> /// <param name="ownerId">The owner id.</param> /// <param name="customerId">The customer id.</param> /// <param name="customerName">Name of the customer.</param> /// <param name="pricelistId">The pricelist id.</param> /// <param name="title">The title.</param> /// <returns></returns> public static Quote CreateQuote(int ownerId, int customerId, string customerName, int pricelistId, string title) { DatabaseConnection db = new DatabaseConnection(); object result = db.SProcToObject("CreateQuote", new KeyValuePair<string, object>("@OwnerId", ownerId), new KeyValuePair<string, object>("@CustomerId", customerId), new KeyValuePair<string, object>("@CustomerName", customerName), new KeyValuePair<string, object>("@PricelistId", pricelistId), new KeyValuePair<string, object>("@QuoteTitle", title)); db.Dispose(); Quote q = new Quote(Convert.ToInt32(result)); return q; }