public static PropertyOption Create(string name, string code, bool conditional = false, ConditionMode mode = ConditionMode.IS, string conditionalTarget = "", string conditionalValue = "") { PropertyOption prop = new PropertyOption(); prop.set(name, code, conditional); if (conditional) { prop.ConditionPropertyTarget = conditionalTarget; prop.ConditionValue = conditionalValue; prop.mode = mode; } return(prop); }
private void btn_value_add_Click(object sender, EventArgs e) { bool isConditional = product.Properties.ElementAt(lb_prop.SelectedIndex).Conditional; PropertyOption option; if (isConditional) { option = PropertyOption.Create("New Value", "", true, PropertyOption.ConditionMode.ISNT, "", ""); } else { option = PropertyOption.Create("New Value", ""); } lb_values.Items.Add(option.Name); product.Properties.ElementAt(lb_prop.SelectedIndex).Values.Add(option); }
private void lb_values_SelectedIndexChanged(object sender, EventArgs e) { bool enabled = lb_values.SelectedIndex >= 0; btn_value_remove.Enabled = enabled; tb_value_prettyname.Enabled = enabled; tb_value_code.Enabled = enabled; if (enabled && product.Properties.ElementAt(lb_prop.SelectedIndex).Conditional) { tb_cond_value.Enabled = true; cb_cond_op.Enabled = true; cb_cond_prop.Enabled = true; cb_cond_prop.Items.Clear(); // set dropdown items foreach (ProductProperty prop in product.Properties) { if (!prop.Conditional) { cb_cond_prop.Items.Add(prop.Title); } } } else { tb_cond_value.Enabled = false; cb_cond_op.Enabled = false; cb_cond_prop.Enabled = false; } if (enabled) { PropertyOption selected = product.Properties.ElementAt(lb_prop.SelectedIndex).Values.ElementAt(lb_values.SelectedIndex); tb_value_prettyname.Text = selected.Name; tb_value_code.Text = selected.Code; tb_cond_value.Text = selected.ConditionValue; cb_cond_op.SelectedIndex = selected.mode == PropertyOption.ConditionMode.IS ? 0 : 1; cb_cond_prop.SelectedItem = selected.ConditionPropertyTarget; } }
private void frm_exports_Load(object sender, EventArgs e) { List <List <PropertyOption> > rows = NextMutable(p, 0); List <ProductProperty> mutableProperties = new List <ProductProperty>(); List <ProductProperty> conditionalProperties = new List <ProductProperty>(); foreach (ProductProperty prop in p.Properties) { if (prop.Conditional) { conditionalProperties.Add(prop); } else { mutableProperties.Add(prop); } } for (int i = 0; i < rows.Count; i++) { List <PropertyOption> row = rows[i]; foreach (ProductProperty prop in conditionalProperties) { PropertyOption selected = null; foreach (PropertyOption possible in prop.Values) { if (selected != null) { continue; // fast forward through rest of loop if selection has been made } List <string> mutablePropStr = new List <string>(); foreach (ProductProperty @this in mutableProperties) { mutablePropStr.Add(@this.Title); } if (possible.mode == PropertyOption.ConditionMode.IS) { if (row[mutablePropStr.IndexOf(possible.ConditionPropertyTarget)].Name == possible.ConditionValue) { selected = possible; } } else { if (row[mutablePropStr.IndexOf(possible.ConditionPropertyTarget)].Name != possible.ConditionValue) { selected = possible; } } } row.Add(selected); } } // Create SKUs for (int i = 0; i < rows.Count; i++) { List <PropertyOption> row = rows[i]; string sku = ""; foreach (SkuComponent skuComponent in p.SkuSchema) { switch (skuComponent.Type) { case SkuComponent.SkuComponentType.STATIC: sku += skuComponent.StaticText; break; case SkuComponent.SkuComponentType.NULL: continue; default: int index = -1; for (int j = 0; j < mutableProperties.Count; j++) { ProductProperty @this = mutableProperties[j]; if (skuComponent.Property.Title == @this.Title) { index = j; } } if (index < 0) { sku += ""; } else { sku += row[index].Code; } break; } } rows[i].Insert(0, new PropertyOption { Name = sku } as PropertyOption); } string[][] strs = new string[rows.Count + 1][]; List <string> headers = new List <string>() { "SKU" }; foreach (ProductProperty @this in mutableProperties) { headers.Add(@this.Title); } foreach (ProductProperty @this in conditionalProperties) { headers.Add(@this.Title); } strs[0] = headers.ToArray(); for (int i = 0; i < rows.Count; i++) { string[] arr = new string[rows[i].Count]; for (int j = 0; j < arr.Length; j++) { arr[j] = rows[i][j].Name; } strs[i + 1] = arr; } Form table = new frm_table(strs); table.Show(); this.Close(); }
public void AddValidValue(string value, string code) { Values.Add(PropertyOption.Create(value, code)); }