Exemple #1
0
        // Generate a the name of the applicable stock glass list
        private List <string> GetStockGlassListName(ProductLine product, Dictionary <string, object> parameters)
        {
            // Filter the stock glass list based on glass category
            List <string> stockGlassLists = stockGlassLines.Where(pair => pair.Key.Contains(product.GlassCategory)).Select(pair => pair.Key).ToList();

            // Filter the stock glass list based on two holes parameter, if present
            if (parameters.ContainsKey("TwoHoles") && (bool)parameters["TwoHoles"])
            {
                stockGlassLists = stockGlassLists.Where(list => list.Contains("TwoHoles")).ToList();
            }
            // Remove elements from the list with holes if not specified
            else
            {
                stockGlassLists = stockGlassLists.Where(list => !list.Contains("TwoHoles")).ToList();
            }

            return(stockGlassLists);
        }
Exemple #2
0
        // Update the displayed fields whenever a new product line is selected
        private void ProductLineSelector_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Retrieving productline object based on selectedItem
            if (ProductLineSelector.SelectedItems.Count == 0)
            {
                return;
            }
            string      selectedItem = ProductLineSelector.SelectedItems[0].Text;
            ProductLine productLine  = productLines.Where(n => n.Name.Equals(selectedItem)).First();

            //TODO: loop through inputs and examine their type, add corresponding element to input layout
            //TODO: Do the same for outputs

            foreach (var property in productLine.GetType().GetProperties()) //Getting the properties of the ProductLine type to Loop through
            {
                var value = property.GetValue(productLine);                 //Getting the value of the given property from the actual ProductLine object

                // Generate input fields (these values are List<string>)
                if (value is List <string> && ((List <string>)Convert.ChangeType(value, typeof(List <string>))).Count > 0)              //If the value of the property is a List<string> and has a count > 0:
                {
                    List <string> elementsToAdd = ((List <string>)Convert.ChangeType(value, typeof(List <string>)));

                    // Add float inputs for the selected product
                    if (property.Name.Equals("FloatInputs", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (string elementTitle in elementsToAdd)
                        {
                            AddFloatInput(elementTitle);
                        }
                    }

                    // Add boolean inputs for the selected product
                    else if (property.Name.Equals("BoolInputs", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (string elementTitle in elementsToAdd)
                        {
                            AddBoolInput(elementTitle);
                        }
                    }
                }

                // Generate output fields (these values are Dictionary<string,string>)
                else if (value is Dictionary <string, string> )
                {
                    Dictionary <string, string> outputToAdd = (Dictionary <string, string>)value;
                    foreach (KeyValuePair <string, string> kvp in outputToAdd)
                    {
                        // Add float outputs for the selected product
                        if (property.Name.Equals("FloatOutputs", StringComparison.OrdinalIgnoreCase))
                        {
                            AddFloatOutput(kvp.Key);
                        }
                        // Add enum outputs for the selected product
                        else if (property.Name.Equals("EnumOutputs", StringComparison.OrdinalIgnoreCase))
                        {
                            AddEnumOutput(kvp.Key);
                        }
                    }
                }
                else if (value is Dictionary <string, List <string> > )
                {
                    Dictionary <string, List <string> > elementsToAdd = (Dictionary <string, List <string> >)value;

                    foreach (KeyValuePair <string, List <string> > kvp in elementsToAdd)
                    {
                        AddEnumInput(kvp);
                    }
                }
            }

            // By default, add a boolean field to indicate whether the resulting measurements are in stock
            AddBoolOutput("Can Use Stock Glass?");

            // Update the selected product line
            selectedProduct = productLine;
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Code Ran before window is brought to screen, this is where available JSON configs should be loaded

            // Retrieve all json files in the current directory
            string fextension = ".json";
            var    myFiles    = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.*", SearchOption.AllDirectories)
                                .Where(s => fextension.Contains(Path.GetExtension(s)));

            // Initialize the list of products
            List <ProductLine> productList = new List <ProductLine>();

            // Initialize the list of stock glass
            Dictionary <string, StockGlassLine> stockGlassList = new Dictionary <string, StockGlassLine>();

            // Analyze each file
            foreach (var file in myFiles)
            {
                // Parse the product line logic
                if (file.Contains("product_line_config.json"))
                {
                    using (var stream = new StreamReader(file))                    //put a test file in your bin/Debug/ folder to see this in action
                    {
                        string  json_data       = stream.ReadToEnd();
                        dynamic productListJson = JsonConvert.DeserializeObject <Object>(json_data);      //A dynamic object has dynamic runtime properties that can be referenced even though the compiler doesn't know what they are

                        foreach (var productLine in productListJson.ProductLines)                         // Look at each product line in the config
                        {
                            // Create a new product line
                            ProductLine product = new ProductLine(productLine);

                            // Add the product to the product list
                            productList.Add(product);
                        }
                    }
                }
                // Parse the stock glass line inventory
                else if (file.Contains("stock_glass_line_config.json"))
                {
                    using (var stream = new StreamReader(file))                    //put a test file in your bin/Debug/ folder to see this in action
                    {
                        string  json_data          = stream.ReadToEnd();
                        dynamic stockGlassListJson = JsonConvert.DeserializeObject <Object>(json_data); //A dynamic object has dynamic runtime properties that can be referenced even though the compiler doesn't know what they are

                        foreach (var stockGlassLine in stockGlassListJson)                              // Look at each stock glass line in the config
                        {
                            // Create a new stock glass line
                            StockGlassLine stockLine = new StockGlassLine();

                            foreach (var size in stockGlassLine.First)                             // Add each possible size to the stock glass line
                            {
                                stockLine.AvailableStockGlass.Add(new StockGlass((float)size.Width, (float)size.Height));
                            }

                            // Once all of the sizes have been added, add the stock glass line to the product list
                            stockGlassList.Add((string)stockGlassLine.Name, stockLine);
                        }
                    }
                }
            }

            // Start the application
            Application.Run(new Main(productList, stockGlassList));
        }