public Choices.ItemChoicesDataTable GetChoicesByItem(int ItemId) { ChoicesTableAdapters.ItemChoicesTableAdapter choices = new lw.Products.ChoicesTableAdapters.ItemChoicesTableAdapter(); return(choices.GetChoicesByItem(ItemId)); }
/* * the complicated part * The point is to create all possible combinations between different * options relating a different choices * so for example we might have * Colors: red, blue * Sizes: L, XL * Style: Long, Short * Results will be red,L,Long - red,L,Short - red, Xl, long, red, xl,short... * then the same for blue * Inside the database and to minimize the content we will use their ids instead * of their names * */ public void CreateInvntoryRecords(int ItemId) { ChoicesTableAdapters.ItemChoicesTableAdapter choicesAdp = new lw.Products.ChoicesTableAdapters.ItemChoicesTableAdapter(); Choices.ItemChoicesDataTable choices = choicesAdp.GetChoicesByItem(ItemId); ChoicesTableAdapters.ItemOptionsViewTableAdapter itemOptionsViewAdp = new lw.Products.ChoicesTableAdapters.ItemOptionsViewTableAdapter(); Choices.ItemOptionsViewDataTable options = itemOptionsViewAdp.GetByItem(ItemId); /* Loop through choices, * Each Step is considered as a level * We get the options for the choice * then we loop through options of previous level * Ex: * Step 1: (Colors) * red 1 ==> ID = RedID * blue 1 ==> ID = BlueID * Setp 2: (Sizes) * red, S 2 ==> ID = RedID,SID * red, L 2 * blue, S 2 * blue, L 2 * Step 3: (Style) * red, S, Long 3 ==> ID = RedId,SID,LongID * red, S, Short 3 * red, L, Long 3 * ... * ... * With each step the complexity multiplies * * Sorting by ids is the best choice * We will be using the itterator i as the level * */ Choices.ItemOptionsInventoryTempDataTable inventory = new Choices.ItemOptionsInventoryTempDataTable(); DataView choicesView = new DataView(choices, "", "ChoiceId", DataViewRowState.CurrentRows); for (int i = 0; i < choicesView.Count; i++) { DataView optionsView = new DataView(options, string.Format("ChoiceId={0}", choicesView[i]["ChoiceId"]), "OptionId", DataViewRowState.CurrentRows); for (int j = 0; j < optionsView.Count; j++) { //First level.. if (i == 0) { DataRow row = inventory.NewRow(); row["Key"] = optionsView[j]["OptionId"]; row["Level"] = i; inventory.Rows.Add(row); } else { DataView inventoryView = new DataView(inventory, String.Format("Level={0}", i - 1), "", DataViewRowState.CurrentRows); for (int k = 0; k < inventoryView.Count; k++) { DataRow row = inventory.NewRow(); row["Key"] = string.Format("{0},{1}", inventoryView[k]["Key"], optionsView[j]["OptionId"]); row["Level"] = i; inventory.Rows.Add(row); } } } } DataView iView = new DataView(inventory, string.Format("Level={0}", choices.Count - 1), "", DataViewRowState.CurrentRows); StringBuilder sb = new StringBuilder(); foreach (DataRowView drv in iView) { sb.Append(string.Format( @"exec('UpdateItemOptionsInventory ""{0}"", ""{1}"", ""0"", ""0"", ""0""');", ItemId, drv["Key"])); } if (sb.Length > 0) { DBUtils.ExecuteQuery(sb.ToString(), cte.lib); } }
public Choices.ItemChoicesDataTable GetChoices() { ChoicesTableAdapters.ItemChoicesTableAdapter choices = new lw.Products.ChoicesTableAdapters.ItemChoicesTableAdapter(); return(choices.GetData()); }
public void DeleteChoice(int ChoiceId) { ChoicesTableAdapters.ItemChoicesTableAdapter choices = new lw.Products.ChoicesTableAdapters.ItemChoicesTableAdapter(); DeleteOptionByChoice(ChoiceId); choices.DeleteChoice(ChoiceId); }
public void UpdateChoice(int ChoiceId, string Choice) { ChoicesTableAdapters.ItemChoicesTableAdapter choices = new lw.Products.ChoicesTableAdapters.ItemChoicesTableAdapter(); choices.UpdateChoice(ChoiceId, Choice); }
public void AddChoiceGroup(string GroupName) { ChoicesTableAdapters.ItemChoicesTableAdapter choices = new lw.Products.ChoicesTableAdapters.ItemChoicesTableAdapter(); choices.AddChoice(GroupName); }