private void btn_prop_add_Click(object sender, EventArgs e) { Label l = new Label(); if (lb_products.SelectedItem == null || lb_properties.SelectedItem == null) { return; } l.Text = "<" + lb_products.SelectedItem + "." + lb_properties.SelectedItem + ">"; l.Font = new Font(FontFamily.GenericMonospace, 8.0f); l.AutoSize = true; l.Click += skuComponentClicked; flp_sku.Controls.Add(l); ProductProperty prop = Products.ElementAt(lb_products.SelectedIndex).Properties.ElementAt(lb_properties.SelectedIndex); SkuComponent component = new SkuComponent(); component.Property = prop; SkuComponents.Add(component); }
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(); }