Hi,
I'm trying to save prices from a process into Dynamicweb. All info is parsed into the Dynamicweb Price object (namespace Dynamicweb.eCommerce.Prices) before I call the Save method on the Price object. The Save method contains the logic as shown in the attachment and below.
public void Save(string IDStr, string prodID, string currCode) { using (IDbConnection connection = Database.CreateConnection("Ecom.mdb")) { using (IDbCommand command = connection.CreateCommand()) { DataSet dataSet = new DataSet(); IDbDataAdapter adapter = Database.CreateAdapter(); string str = "SELECT * FROM EcomPrices WHERE PriceID = '" + IDStr + "'" + " AND PriceProductID = '" + prodID + "'" + " AND PriceCurrency = '" + currCode + "'"; command.CommandText = str; adapter.SelectCommand = command; object obj = (object) Database.CreateCommandBuilder(ref adapter); adapter.Fill(dataSet); DataRow row; if (dataSet.Tables[0].Rows.Count > 0) { row = dataSet.Tables[0].Rows[0]; } else { row = dataSet.Tables[0].NewRow(); dataSet.Tables[0].Rows.Add(row); this.ID = NumberGenerator.GetNumber("PRICE"); } row["PriceID"] = (object) this.ID; row["PriceProductID"] = (object) this.ProductID; row["PriceProductVariantID"] = (object) this.VariantID; row["PriceProductLanguageID"] = (object) this.LanguageID; row["PriceUnitID"] = (object) this.UnitID; row["PriceCurrency"] = (object) this.CurrencyCode; row["PriceQuantity"] = (object) this.Quantity; row["PricePeriodID"] = (object) this.PeriodID; row["PriceAmount"] = (object) this.Amount; row["PriceCustomerGroupID"] = (object) this.CustomerGroupID; row["PricePriority"] = (object) this.Priority; row["PriceUserCustomerNumber"] = (object) this.UserCustomerNumber; adapter.Update(dataSet); dataSet.Dispose(); } } this.UpdateMatrixDoublePrice(); }
The way I'm reading this section is that the save method first tries to get a record from the database using the PriceID, the ProductID and the CurrencyCode. When there's no hit it does create a new record. When there are more then 0 records it takes the first one and saves the new data over the old data... But what happens if I'm having multiple EcomPrice records in the database for different pricelists and debtors?
What is the best way to create new pricematrix objects in the database from code? Is it the Save method on a Price object or are there different ways to achieve this?
Thanks!
Tom