public static void AddOption(OptionItem opt, int customOptionsId) { SQLDataAccess.ExecuteNonQuery("[Catalog].[sp_AddOption]", CommandType.StoredProcedure, new SqlParameter("@CustomOptionsId", customOptionsId), new SqlParameter("@Title", opt.Title), new SqlParameter("@PriceBC", opt.PriceBc), new SqlParameter("@PriceType", opt.PriceType), new SqlParameter("@SortOrder", opt.SortOrder)); }
protected void btnAddCustomOption_Click(object sender, EventArgs e) { LoadCustomOptions(); var copt = new CustomOption(true) { CustomOptionsId = -1, ProductId = ProductId }; var opt = new OptionItem { OptionId = -1, PriceBc = 0, SortOrder = 10 }; copt.Options = new List<OptionItem> { opt }; _customOptions.Add(copt); UpdateCustomOptions(); }
protected void ddlInputType_SelectedIndexChanged(object sender, EventArgs e) { LoadCustomOptions(); var itp = (CustomOptionInputType)(((DropDownList)sender).SelectedValue.TryParseInt()); if (itp == CustomOptionInputType.CheckBox || itp == CustomOptionInputType.TextBoxMultiLine || itp == CustomOptionInputType.TextBoxSingleLine) { int idx = ((RepeaterItem)(((DropDownList)sender).Parent)).ItemIndex; _customOptions[idx].Options.Clear(); var opt = new OptionItem { OptionId = -1, PriceBc = 0, SortOrder = 10, Title = " " }; _customOptions[idx].Options.Add(opt); } UpdateCustomOptions(); }
protected void Page_Load(object sender, EventArgs e) { if (CustomOptions != null) { SelectedOptions = new List<OptionItem>(); } else { SelectedOptions = null; return; } int idx = 0; foreach (Control ctrl in _controls) { if (ctrl is DropDownList) { int id = SQLDataHelper.GetInt(((DropDownList)ctrl).SelectedValue); SelectedOptions.Add(id > 0 ? CustomOptions[idx].Options.WithId(id) : null); idx++; } else if (ctrl is RadioButtonList) { int id = SQLDataHelper.GetInt(((RadioButtonList)ctrl).SelectedValue); SelectedOptions.Add(id > 0 ? CustomOptions[idx].Options.WithId(id) : null); idx++; } else if (ctrl is CheckBox) { if (((CheckBox)ctrl).Checked) { CustomOptions[idx].Options[0].Title = Resource.Client_UserControls_CustomOptions_Yes; SelectedOptions.Add(CustomOptions[idx].Options[0]); } else { if (CustomOptions[idx].IsRequired) { CustomOptions[idx].Options[0].Title = Resource.Client_UserControls_CustomOptions_No; CustomOptions[idx].Options[0].PriceBc = 0; SelectedOptions.Add(CustomOptions[idx].Options[0]); } else { SelectedOptions.Add(null); } } idx++; } else if (ctrl is TextBox) { if (((TextBox)ctrl).TextMode == TextBoxMode.MultiLine) { if (string.IsNullOrEmpty(((TextBox)ctrl).Text)) { SelectedOptions.Add(null); if (CustomOptions[idx].IsRequired) { IsValid = false; } } else { CustomOptions[idx].Options = new List<OptionItem>(); var opt = new OptionItem { Title = ((TextBox)ctrl).Text }; CustomOptions[idx].Options.Add(opt); SelectedOptions.Add(CustomOptions[idx].Options[0]); } idx++; } else { if (string.IsNullOrEmpty(((TextBox)ctrl).Text)) { SelectedOptions.Add(null); if (CustomOptions[idx].IsRequired) { IsValid = false; } if (ShowValidation) { ((TextBox)ctrl).CssClass = "valid-required group-cOptions"; } } else { CustomOptions[idx].Options = new List<OptionItem>(); var opt = new OptionItem { Title = ((TextBox)ctrl).Text }; CustomOptions[idx].Options.Add(opt); SelectedOptions.Add(CustomOptions[idx].Options[0]); } idx++; } } } }
private void ProcessExcel() { try { // How much ? ------------------ int intRootCategories = 7; int intSubCategoriesLevel1 = 7; int intSubCategoriesLevel2 = 7; int intProductCountForCategory = 500; // Internal Variables ------------------ int intCurrentProductIndex = SQLDataHelper.GetInt(SQLDataAccess.ExecuteScalar("Select MAX(ProductId) + 1 FROM Catalog.Product", CommandType.Text, null)); // 50000 int intProductAltId1 = 0; int intProductAltId2 = 0; int intProductAltId3 = 0; int intProductAltId4 = 0; int intProductAltId5 = 0; int intProductAltId6 = 0; string strCategoryName1 = ""; string strCategoryName2 = ""; string strCategoryName3 = ""; string strPropName1 = ""; string strPropName2 = ""; string strPropName3 = ""; string strPropName4 = ""; string strPropName5 = ""; string strPropName6 = ""; string strPropName7 = ""; int intTempProductId = 0; //int i, j, k; var rnd = new Random(); // --------------- CommonStatistic.TotalRow = (intRootCategories * intSubCategoriesLevel1 * intSubCategoriesLevel2 * intProductCountForCategory); // Step by rows for (int i = 0; i <= intRootCategories - 1; i++) // 15 { strCategoryName1 = Strings.GetRandomString(rnd, 25, 6); if (!chbSimpleMode.Checked) // Simple Mode { strPropName1 = Strings.GetRandomString(rnd, 4); strPropName2 = Strings.GetRandomString(rnd, 7); strPropName3 = Strings.GetRandomString(rnd, 7); strPropName4 = Strings.GetRandomString(rnd, 8); strPropName5 = Strings.GetRandomString(rnd, 8); strPropName6 = Strings.GetRandomString(rnd, 9); strPropName7 = Strings.GetRandomString(rnd, 9); } for (int j = 0; j <= intSubCategoriesLevel1 - 1; j++) // 15 x 10 { strCategoryName2 = Strings.GetRandomString(rnd, 25, 5); for (int k = 0; k <= intSubCategoriesLevel2 - 1; k++) // 15 x 10 x 10 { strCategoryName3 = Strings.GetRandomString(rnd, 25, 4); for (int p = 0; p <= intProductCountForCategory - 1; p++) // 15 x 10 x 10 x 10 { intCurrentProductIndex++; intTempProductId = ProcessProduct(rnd, intCurrentProductIndex); // Category ---------------------------------------------------------------------------------------------- string parentCategory = string.Format("[{0} >> {1} >> {2}]", strCategoryName1.Trim(), strCategoryName2.Trim(), strCategoryName3.Trim()); CategoryService.SubParseAndCreateCategory(parentCategory, intTempProductId); if (!chbSimpleMode.Checked) // Simple Mode { // Property ----------------------------------------------------------------------------------------------- BuildProperties(rnd, intTempProductId, strPropName1, strPropName2, strPropName3, strPropName4, strPropName5, strPropName6, strPropName7); // Images ------------------------------------------------------------------------------------------------- var tempId = PhotoService.AddPhoto(new Photo(0, intTempProductId, PhotoType.Product) { Description = Strings.GetRandomString(rnd, 25, 4), ColorID = Colors[DevTool.GetRandomInt(rnd, 0, Colors.Count - 1)].ColorId, }); if (!string.IsNullOrWhiteSpace(tempId)) { CopyProductPic(rnd, tempId); } tempId = PhotoService.AddPhoto(new Photo(0, intTempProductId, PhotoType.Product) { Description = Strings.GetRandomString(rnd, 25, 4), ColorID = Colors[DevTool.GetRandomInt(rnd, 0, Colors.Count - 1)].ColorId, }); if (!string.IsNullOrWhiteSpace(tempId)) { CopyProductPic(rnd, tempId); } tempId = PhotoService.AddPhoto(new Photo(0, intTempProductId, PhotoType.Product) { Description = Strings.GetRandomString(rnd, 25, 4) }); if (!string.IsNullOrWhiteSpace(tempId)) { CopyProductPic(rnd, tempId); } // Alt Products -------------------------------------------------------------------------------------------- if (intProductAltId1 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId1, RelatedType.Alternative); } if (intProductAltId2 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId2, RelatedType.Alternative); } if (intProductAltId3 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId3, RelatedType.Alternative); } if (intProductAltId4 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId4, RelatedType.Alternative); } if (intProductAltId5 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId5, RelatedType.Alternative); } if (intProductAltId6 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId6, RelatedType.Alternative); } // And RelatedProduct --------------------------------------------- if (intProductAltId1 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId1, RelatedType.Related); } if (intProductAltId2 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId2, RelatedType.Related); } if (intProductAltId3 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId3, RelatedType.Related); } // And RelatedProduct if (intProductAltId4 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId4, RelatedType.Related); } if (intProductAltId5 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId5, RelatedType.Related); } if (intProductAltId6 != 0) { ProductService.AddRelatedProduct(intTempProductId, intProductAltId6, RelatedType.Related); } //intProductAltId1 = intProductAltId2; //intProductAltId2 = intProductAltId3; //intProductAltId3 = intTempProductId; intProductAltId1 = intProductAltId2; intProductAltId2 = intProductAltId3; intProductAltId3 = intProductAltId4; intProductAltId4 = intProductAltId5; intProductAltId5 = intProductAltId6; intProductAltId6 = intTempProductId; // Custom Options -------------------------------------------------------------------------------------------- var copt = new CustomOption(true) { CustomOptionsId = -1, ProductId = intTempProductId }; // copt.InputType = CustomOptionInputType.RadioButton; copt.Title = Demo.GetRandomCity(); var opt = new OptionItem { OptionId = -1, PriceBc = 0, SortOrder = 10 }; opt.Title = Demo.GetRandomName(); var opt2 = new OptionItem { OptionId = -1, PriceBc = DevTool.GetRandomInt(rnd, 0, 100), SortOrder = 20 }; opt2.Title = Demo.GetRandomLastName(); var opt3 = new OptionItem { OptionId = -1, PriceBc = DevTool.GetRandomInt(rnd, 0, 10), SortOrder = 30 }; opt3.Title = Demo.GetRandomName(); copt.Options = new List<OptionItem> { opt, opt2, opt3 }; CustomOptionsService.AddCustomOption(copt); } } } } } CategoryService.RecalculateProductsCountManual(); //TODO find where is this function! //ProductService.SumImportLog(Resource.Admin_ImportXLS_UpdoadingSuccessfullyCompleted,Resource.Admin_ImportXLS_UpdoadingCompletedWithErrors); } catch (Exception ex) { MsgErr(ex.Message + " at xls"); Debug.LogError(ex); } CommonStatistic.IsRun = false; CommonStatistic.ThreadImport.Abort(); }
private void LoadCustomOptions() { var customOptions = new List<CustomOption>(); foreach (RepeaterItem item in rCustomOptions.Items) { var customOption = new CustomOption { CustomOptionsId = ((HiddenField)(item.FindControl("hfId"))).Value.TryParseInt(), ProductId = ((HiddenField)(item.FindControl("hfProductId"))).Value.TryParseInt() }; if (string.IsNullOrEmpty(((TextBox)(item.FindControl("txtTitle"))).Text)) { _valid = false; } int i; if (!int.TryParse(((TextBox)(item.FindControl("txtSortOrder"))).Text, out i)) { _valid = false; } customOption.Title = ((TextBox)(item.FindControl("txtTitle"))).Text; customOption.InputType = (CustomOptionInputType)((((DropDownList)(item.FindControl("ddlInputType"))).SelectedValue.TryParseInt())); customOption.IsRequired = ((CheckBox)(item.FindControl("cbIsRequired"))).Checked; try { customOption.SortOrder = SQLDataHelper.GetInt(((TextBox)(item.FindControl("txtSortOrder"))).Text); } catch (Exception) { customOption.SetFieldToNull(CustomOptionField.SortOrder); } customOption.Options = new List<OptionItem>(); if (customOption.InputType == CustomOptionInputType.CheckBox) { var opt = new OptionItem { Title = " " }; try { opt.PriceBc = SQLDataHelper.GetFloat(((TextBox)(item.FindControl("txtPrice"))).Text); } catch (Exception) { opt.SetFieldToNull(OptionField.PriceBc); _valid = false; } opt.PriceType = OptionPriceType.Fixed; if (Enum.IsDefined(typeof(OptionPriceType), ((DropDownList)(item.FindControl("ddlPriceType"))).SelectedValue)) opt.PriceType = (OptionPriceType)Enum.Parse(typeof(OptionPriceType), ((DropDownList)(item.FindControl("ddlPriceType"))).SelectedValue, true); customOption.Options.Add(opt); } else { foreach (GridViewRow row in ((GridView)(item.FindControl("grid"))).Rows) { var opt = new OptionItem { OptionId = ((Label)(row.Cells[0].FindControl("lId"))).Text.TryParseInt() }; if (string.IsNullOrEmpty(((TextBox)(row.Cells[1].FindControl("txtTitle"))).Text) && !(customOption.InputType == CustomOptionInputType.CheckBox || customOption.InputType == CustomOptionInputType.TextBoxMultiLine || customOption.InputType == CustomOptionInputType.TextBoxSingleLine)) { _valid = false; } opt.Title = ((TextBox)(row.Cells[1].FindControl("txtTitle"))).Text; try { opt.PriceBc = SQLDataHelper.GetFloat(((TextBox)(row.Cells[2].FindControl("txtPriceBC"))).Text); } catch (Exception) { opt.SetFieldToNull(OptionField.PriceBc); _valid = false; } opt.PriceType = OptionPriceType.Fixed; if (Enum.IsDefined(typeof(OptionPriceType), ((DropDownList)(row.Cells[3].FindControl("ddlPriceType"))).SelectedValue)) opt.PriceType = (OptionPriceType)Enum.Parse(typeof(OptionPriceType), ((DropDownList)(row.Cells[3].FindControl("ddlPriceType"))).SelectedValue, true); try { opt.SortOrder = int.Parse(((TextBox)(row.Cells[4].FindControl("txtSortOrder"))).Text); } catch (Exception) { opt.SetFieldToNull(OptionField.SortOrder); _valid = false; } customOption.Options.Add(opt); } } customOptions.Add(customOption); } _customOptions = customOptions; }
protected void rCustomOptions_ItemCommand(object source, RepeaterCommandEventArgs e) { LoadCustomOptions(); if (e.CommandName.Equals("AddNewOption")) { CustomOption copt = _customOptions[e.Item.ItemIndex]; var opt = new OptionItem { OptionId = -1, PriceBc = 0 }; if (copt.Options.Count > 0) { opt.SortOrder = copt.Options[copt.Options.Count - 1].SortOrder + 10; } else { opt.SortOrder = 10; } copt.Options.Add(opt); } else if (e.CommandName.Equals("DeleteCustomOptions")) { _customOptions.RemoveAt(e.Item.ItemIndex); } UpdateCustomOptions(); }