public static void Remove(ProductOptionBase option, ApplicationProduct Product, string table) { string query = string.Format("DELETE FROM {0} WHERE ProductId = @ProductId AND OptionId = @OptionId", tables[table]); using (SqlConnection cnn = new SqlConnection(Properties.Settings.Default.PersianSoftwareConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, cnn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@ProductId", Product.ProductId)); cmd.Parameters.Add(new SqlParameter("@OptionId", option.Id)); foreach (SqlParameter Parameter in cmd.Parameters) { if (Parameter.Value == null) { Parameter.Value = DBNull.Value; } } cnn.Open(); int affected = cmd.ExecuteNonQuery(); /* * if (affected == 0) * { * } */ cnn.Close(); } } }
private void RemoveFromSelectedDataSource(ProductOptionBase option) { int itemIndex = 0; for (itemIndex = 0; itemIndex < this.selectedItems.Count; itemIndex++) { if (this.selectedItems[itemIndex].Id == option.Id) { this.selectedItems.RemoveAt(itemIndex); } } }
internal static IEnumerable GetOptions(string tableName, int languageId) { List <ProductOptionBase> list = null; int idIndex = 0; int nameIndex = 2; string query = string.Format("SELECT * FROM {0}", tableName); if (tableName != "ListLanguages") { query += string.Format(" WHERE LanguageId = {0}", languageId); } using (SqlConnection cnn = new SqlConnection(Properties.Settings.Default.PersianSoftwareConnectionString)) { using (SqlCommand cmd = new SqlCommand(query, cnn)) { cmd.CommandType = CommandType.Text; cnn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader != null && reader.HasRows) { list = new List <ProductOptionBase>(); while (reader.Read()) { if (reader[0] != null) { ProductOptionBase option = new ProductOptionBase(); option.Id = Convert.ToInt32(reader[idIndex]); option.Name = Convert.ToString(reader[nameIndex]); list.Add(option); } } reader.Close(); } } cnn.Close(); } } return(list); }
void OptionCheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e) { if (this.Product.ProductId <= 0) { throw new InvalidOperationException("Product Id must be > 0"); } else { if (this.Items[e.Index] != null) { ProductOptionBase item = (ProductOptionBase)this.Items[e.Index]; if (e.NewValue == CheckState.Checked) { AddToSelectedDataSource(item); AddAction(item, this.Product, this.Name.Replace("chbx", "")); } else if (e.NewValue == CheckState.Unchecked) { RemoveFromSelectedDataSource(item); RemoveAction(item, this.Product, this.Name.Replace("chbx", "")); } } } }
private void AddToSelectedDataSource(ProductOptionBase option) { this.selectedItems.Add(option); }