protected void AttachButton_Click(object sender, EventArgs e) { string attach = Request.Form["attach"]; if (!string.IsNullOrEmpty(attach)) { string[] ids = attach.Replace(" ", "").Split(",".ToCharArray()); foreach (string strId in ids) { int dgid = AlwaysConvert.ToInt(strId); DigitalGood dg = DigitalGoodDataSource.Load(dgid); if (dg != null) { int index = _Product.DigitalGoods.IndexOf(dg.Id); if (index < 0) { ProductDigitalGood pdg = new ProductDigitalGood(); pdg.Product = _Product; pdg.OptionList = _OptionList; pdg.DigitalGood = dg; _Product.DigitalGoods.Add(pdg); } } } _Product.DigitalGoods.Save(); } Response.Redirect(CancelButton.NavigateUrl); }
public static ProductDigitalGood Load(Int32 productDigitalGoodId, bool useCache) { if (productDigitalGoodId == 0) { return(null); } ProductDigitalGood productDigitalGood = null; string key = "ProductDigitalGood_" + productDigitalGoodId.ToString(); if (useCache) { productDigitalGood = ContextCache.GetObject(key) as ProductDigitalGood; if (productDigitalGood != null) { return(productDigitalGood); } } productDigitalGood = new ProductDigitalGood(); if (productDigitalGood.Load(productDigitalGoodId)) { if (useCache) { ContextCache.SetObject(key, productDigitalGood); } return(productDigitalGood); } return(null); }
public static ProductDigitalGoodCollection LoadForVariant(int productId, string optionList, int maximumRows, int startRowIndex, string sortExpression) { bool variantSpecified = !string.IsNullOrEmpty(optionList); //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + ProductDigitalGood.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_ProductDigitalGoods"); selectQuery.Append(" WHERE ProductId = @productId"); if (variantSpecified) { selectQuery.Append(" AND OptionList = @optionList"); } else { selectQuery.Append(" AND OptionList IS NULL"); } if (!string.IsNullOrEmpty(sortExpression)) { selectQuery.Append(" ORDER BY " + sortExpression); } Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@productId", System.Data.DbType.Int32, productId); if (variantSpecified) { database.AddInParameter(selectCommand, "@optionList", System.Data.DbType.String, optionList); } //EXECUTE THE COMMAND ProductDigitalGoodCollection results = new ProductDigitalGoodCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { ProductDigitalGood digitalGood = new ProductDigitalGood(); ProductDigitalGood.LoadDataReader(digitalGood, dr); results.Add(digitalGood); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
public static bool Delete(Int32 productDigitalGoodId) { ProductDigitalGood productDigitalGood = new ProductDigitalGood(); if (productDigitalGood.Load(productDigitalGoodId)) { return(productDigitalGood.Delete()); } return(false); }
private void AssociateProduct(int relatedProductId) { Product product = ProductDataSource.Load(relatedProductId); if (product != null) { if (!IsProductAssciated(product)) { ProductDigitalGood pgd = new ProductDigitalGood(); pgd.ProductId = product.Id; pgd.DigitalGoodId = _DigitalGoodId; pgd.Save(); _DigitalGood.ProductDigitalGoods.Add(pgd); product.DigitalGoods.Add(pgd); } } }
public static ProductDigitalGoodCollection LoadForCriteria(string sqlCriteria, int maximumRows, int startRowIndex, string sortExpression) { //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT"); if (maximumRows > 0) { selectQuery.Append(" TOP " + (startRowIndex + maximumRows).ToString()); } selectQuery.Append(" " + ProductDigitalGood.GetColumnNames(string.Empty)); selectQuery.Append(" FROM ac_ProductDigitalGoods"); string whereClause = string.IsNullOrEmpty(sqlCriteria) ? string.Empty : " WHERE " + sqlCriteria; selectQuery.Append(whereClause); if (!string.IsNullOrEmpty(sortExpression)) { selectQuery.Append(" ORDER BY " + sortExpression); } Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); //EXECUTE THE COMMAND ProductDigitalGoodCollection results = new ProductDigitalGoodCollection(); int thisIndex = 0; int rowCount = 0; using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read() && ((maximumRows < 1) || (rowCount < maximumRows))) { if (thisIndex >= startRowIndex) { ProductDigitalGood productDigitalGood = new ProductDigitalGood(); ProductDigitalGood.LoadDataReader(productDigitalGood, dr); results.Add(productDigitalGood); rowCount++; } thisIndex++; } dr.Close(); } return(results); }
private void ReleaseProduct(int relatedProductId) { Product product = ProductDataSource.Load(relatedProductId); if (product != null) { int index = -1; for (int i = 0; i < _DigitalGood.ProductDigitalGoods.Count; i++) { ProductDigitalGood pgd = _DigitalGood.ProductDigitalGoods[i]; if (pgd.DigitalGoodId == _DigitalGoodId && pgd.ProductId == relatedProductId) { index = i; break; } } if (index > -1) { _DigitalGood.ProductDigitalGoods.DeleteAt(index); _DigitalGood.ProductDigitalGoods.Save(); } } }
public static SaveResult Insert(ProductDigitalGood productDigitalGood) { return(productDigitalGood.Save()); }
public static SaveResult Update(ProductDigitalGood productDigitalGood) { return(productDigitalGood.Save()); }
public static bool Delete(ProductDigitalGood productDigitalGood) { return(productDigitalGood.Delete()); }