Example #1
0
        public static CQueryDef SaveIntoProviderOffersProducts(InputInvoice Invoice, InputProduct Product)
        {
            var sql = string.Format(@"INSERT INTO [ProviderOffers_Products](Product_Key, Count, Price, Purchase_Key) VALUES('{0}', '{1}', '{2}', '{3}')",
                                    Product.Product_Key, Product.Count, Product.Price, Invoice._purchaseKey);

            return(new CQueryDef(sql, CSqlReader.SqlStorage.ExecuteNonQuery));
        }
Example #2
0
        public static CQueryDef SaveProductsBoughtCount(InputProduct Product)
        {
            var sql = string.Format(@"UPDATE [Products] SET Products_Bought = Products_Bought + {0} WHERE Product_Key = {1}",
                                    Product.Count, Product.Product_Key);

            return(new CQueryDef(sql, CSqlReader.SqlStorage.ExecuteNonQuery));
        }
Example #3
0
        private void BUT_Add_Product_Click(object sender, EventArgs e)
        {
            if (CValidate.Validate(CB_Provider.Text != String.Empty &&
                                   CB_Product_Name.Text != String.Empty &&
                                   CB_Product_Code.Text != String.Empty &&
                                   TB_Product_Price.Text != String.Empty &&
                                   NUD_Product_Count.Value >= 1))
            {
                var providerId = _queries.ProviderIdByName(CB_Provider.Text);
                var productKey = _queries.ProductKeyByName(CB_Product_Name.Text);

                InputProduct inputProduct = new InputProduct(
                    DTM_ArrivalProduct.Value,
                    CB_Provider.Text,
                    providerId,
                    CB_Product_Code.Text,
                    CB_Product_Name.Text,
                    float.Parse(TB_Product_Price.Text),
                    NUD_Product_Count.Value,
                    productKey);

                _inputProducts.Add(inputProduct);
                LB_Product_List.Items.Add(inputProduct.Name);
                LB_ProductCount.Items.Add(inputProduct.Count);

                CB_Product_Name.Text    = String.Empty;
                CB_Product_Code.Text    = String.Empty;
                TB_Product_Price.Text   = String.Empty;
                NUD_Product_Count.Value = 1;
            }
        }
Example #4
0
        private void BUT_Del_Product_Click(object sender, EventArgs e)
        {
            InputProduct p = _inputProducts.Find(x => x.Name == LB_Product_List.SelectedItem.ToString());

            _inputProducts.Remove(p);
            LB_Product_List.Items.Remove(LB_Product_List.SelectedItem.ToString());
            LB_ProductCount.SelectedIndex = LB_Product_List.SelectedIndex;
            LB_ProductCount.Items.RemoveAt(LB_Product_List.SelectedIndex + 1);
        }
Example #5
0
        private static void CreateRecipe()
        {
            Console.WriteLine("---Създай рецепта---");
            Console.WriteLine("За да се върнете назад използвайте команда:");
            Console.WriteLine("-->Назад");
            Console.WriteLine("Или...");

            Console.WriteLine();

            Console.Write("Въведете име на рецептата:");

            while (true)
            {
                var InputRecipeName = Console.ReadLine(); Console.WriteLine();

                if (InputRecipeName.ToLower() == "назад")
                {
                    Console.Clear();
                    MainMenu();
                    break;
                }

                if (RecipeExist(InputRecipeName))
                {
                    Console.WriteLine("Рецепта с такова име съществува, моля въведете друго:");
                }
                else
                {
                    var InputTime = 0;
                    Console.Write("Колко минути са нужни за приготвянето:");
                    while (true)
                    {
                        try { InputTime = int.Parse(Console.ReadLine()); break; }
                        catch { Console.WriteLine("Въведената стойност трябва да е цяло число!"); }
                    }
                    Console.WriteLine();

                    Console.Write("За колко порции е дадената рецепта:");
                    var InputPortion = 0;
                    while (true)
                    {
                        try { InputPortion = int.Parse(Console.ReadLine()); break; }
                        catch { Console.WriteLine("Въведената стойност трябва да е цяло число!"); }
                    }
                    Console.WriteLine();

                    Console.WriteLine("Въведете продуктите:");
                    Console.WriteLine("За да прекратите въвеждането на продуктите, използвайте команда:");
                    Console.WriteLine("-->Изход");

                    int timer = 0;

                    List <string> InputProductsNameList       = new List <string>();
                    List <double> InputProductsAmountList     = new List <double>();
                    List <string> InputProductsAmountTypeList = new List <string>();

                    string InputProduct;
                    double InputAmount;
                    string InputAmountType;

                    while (true)
                    {
                        Console.Write("Продукт {0}:", timer + 1);

                        InputProduct = Console.ReadLine();
                        if (InputProduct.ToLower() == "изход")
                        {
                            break;
                        }
                        else
                        {
                            timer++;
                            InputProductsNameList.Add(InputProduct);

                            Console.Write("Количество:");
                            while (true)
                            {
                                try { InputAmount = double.Parse(Console.ReadLine()); break; }
                                catch { Console.WriteLine("Въведената стойност трябва да е число!"); }
                            }
                            InputProductsAmountList.Add(InputAmount);

                            Console.Write("Мерна единица:");
                            InputAmountType = Console.ReadLine();
                            InputProductsAmountTypeList.Add(InputAmountType);

                            Console.WriteLine();
                        }
                    }

                    Console.Write("Опишете на кратко начинът на приготвяне:");
                    var InputInstruction = Console.ReadLine();

                    Console.WriteLine();

                    Console.WriteLine("За да запазите промените използвайте команда:");
                    Console.WriteLine("-->Запази");
                    Console.WriteLine("За да се върнете, без да запазите промените използвайте команда:");
                    Console.WriteLine("-->Назад");

                    while (true)
                    {
                        var InputSave = Console.ReadLine().ToLower();
                        if (InputSave == "запази")
                        {
                            SaveRecipe(InputRecipeName, InputInstruction, InputTime, InputPortion, timer, InputProductsNameList,
                                       InputProductsAmountList, InputProductsAmountTypeList);

                            Console.WriteLine("Искате ли да се съдадете нова рецепта или да се върнете към менюто?");
                            Console.WriteLine("-->Нова рецепта");
                            Console.WriteLine("-->Меню");

                            while (true)
                            {
                                var NewInput = Console.ReadLine();
                                if (NewInput.ToLower() == "нова рецепта")
                                {
                                    Console.Clear();
                                    CreateRecipe();
                                    break;
                                }
                                if (NewInput.ToLower() == "меню")
                                {
                                    Console.Clear();
                                    MainMenu();
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("Невалидна команда!");
                                }
                            }
                            break;
                        }
                        else if (InputSave == "назад")
                        {
                            Console.Clear();
                            MainMenu();
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Невалидна команда!");
                        }
                    }
                }
                break;
            }
        }
Example #6
0
 public List <Product> ProductList(InputProduct inputProduct)
 {
     return(_productContext.ProductsList(inputProduct));
 }
Example #7
0
        private ProductionInfo getProductionInfo(string infobox)
        {
            ProductionInfo result = null;

            //short circuit infoboxes without production info
            if (!infobox.Contains("|Produces Amount"))
            {
                return(result);
            }

            using (var reader = new StringReader(infobox))
            {
                string curLine;
                while ((curLine = reader.ReadLine()) != null)
                {
                    curLine = curLine.Replace(_commons.InfoboxTemplateEnd, string.Empty);

                    if (curLine.StartsWith("|Produces Amount Electricity", StringComparison.OrdinalIgnoreCase))
                    {
                        var productionAmountElectricity = curLine.Replace("|Produces Amount Electricity", string.Empty)
                                                          .Replace("=", string.Empty)
                                                          .Trim();

                        if (double.TryParse(productionAmountElectricity, NumberStyles.Number, cultureForParsing, out var parsedProductionAmountElectricity))
                        {
                            if (result == null)
                            {
                                result = new ProductionInfo();
                            }

                            if (result.EndProduct == null)
                            {
                                result.EndProduct = new EndProduct();
                            }

                            result.EndProduct.AmountElectricity = parsedProductionAmountElectricity;
                        }
                    }
                    else if (curLine.StartsWith("|Produces Amount", StringComparison.OrdinalIgnoreCase))
                    {
                        var productionAmount = curLine.Replace("|Produces Amount", string.Empty)
                                               .Replace("=", string.Empty)
                                               .Trim();

                        if (double.TryParse(productionAmount, NumberStyles.Number, cultureForParsing, out var parsedProductionAmount))
                        {
                            if (result == null)
                            {
                                result = new ProductionInfo();
                            }

                            if (result.EndProduct == null)
                            {
                                result.EndProduct = new EndProduct();
                            }

                            result.EndProduct.Amount = parsedProductionAmount;
                        }
                    }
                    else if (curLine.StartsWith("|Produces Icon", StringComparison.OrdinalIgnoreCase))
                    {
                        var icon = curLine.Replace("|Produces Icon", string.Empty)
                                   .Replace("=", string.Empty)
                                   .Trim();

                        if (string.IsNullOrWhiteSpace(icon))
                        {
                            continue;
                        }

                        if (result == null)
                        {
                            result = new ProductionInfo();
                        }

                        if (result.EndProduct == null)
                        {
                            result.EndProduct = new EndProduct();
                        }

                        result.EndProduct.Icon = icon;
                    }
                    else if (curLine.StartsWith("|Input ", StringComparison.OrdinalIgnoreCase))
                    {
                        var matchAmount = regexInputAmount.Match(curLine);
                        if (matchAmount.Success)
                        {
                            var matchedCounter = matchAmount.Groups["counter"].Value;
                            if (!int.TryParse(matchedCounter, out var counter))
                            {
                                throw new Exception("could not find counter");
                            }

                            //handle entry with no value e.g. "|Input 2 Amount     = "
                            var matchedValue = matchAmount.Groups["value"].Value;
                            if (string.IsNullOrWhiteSpace(matchedValue))
                            {
                                continue;
                            }

                            if (!double.TryParse(matchedValue, NumberStyles.Number, cultureForParsing, out var inputValue))
                            {
                                throw new Exception("could not find value for input");
                            }

                            if (result == null)
                            {
                                result = new ProductionInfo();
                            }

                            var foundInputProduct = result.InputProducts.FirstOrDefault(x => x.Order == counter);
                            if (foundInputProduct == null)
                            {
                                foundInputProduct = new InputProduct
                                {
                                    Order = counter
                                };

                                result.InputProducts.Add(foundInputProduct);
                            }

                            foundInputProduct.Amount = inputValue;

                            continue;
                        }

                        var matchAmountElectricity = regexInputAmountElectricity.Match(curLine);
                        if (matchAmountElectricity.Success)
                        {
                            var matchedCounter = matchAmountElectricity.Groups["counter"].Value;
                            if (!int.TryParse(matchedCounter, out var counter))
                            {
                                throw new Exception("could not find counter");
                            }

                            //handle entry with no value e.g. "|Input 1 Amount Electricity    = "
                            var matchedValue = matchAmountElectricity.Groups["value"].Value;
                            if (string.IsNullOrWhiteSpace(matchedValue))
                            {
                                continue;
                            }

                            if (!double.TryParse(matchedValue, NumberStyles.Number, cultureForParsing, out var inputValue))
                            {
                                throw new Exception("could not find value for input");
                            }

                            if (result == null)
                            {
                                result = new ProductionInfo();
                            }

                            var foundInputProduct = result.InputProducts.FirstOrDefault(x => x.Order == counter);
                            if (foundInputProduct == null)
                            {
                                foundInputProduct = new InputProduct
                                {
                                    Order = counter
                                };

                                result.InputProducts.Add(foundInputProduct);
                            }

                            foundInputProduct.AmountElectricity = inputValue;

                            continue;
                        }

                        var matchIcon = regexInputIcon.Match(curLine);
                        if (matchIcon.Success)
                        {
                            var matchedCounter = matchIcon.Groups["counter"].Value;
                            if (!int.TryParse(matchedCounter, out var counter))
                            {
                                throw new Exception("could not find counter");
                            }

                            //handle entry with no value e.g. "|Input 1 Icon = "
                            var matchedFileName = matchIcon.Groups["fileName"].Value;
                            if (string.IsNullOrWhiteSpace(matchedFileName))
                            {
                                continue;
                            }

                            if (result == null)
                            {
                                result = new ProductionInfo();
                            }

                            var foundInputProduct = result.InputProducts.FirstOrDefault(x => x.Order == counter);
                            if (foundInputProduct == null)
                            {
                                foundInputProduct = new InputProduct
                                {
                                    Order = counter
                                };

                                result.InputProducts.Add(foundInputProduct);
                            }

                            foundInputProduct.Icon = matchedFileName;

                            continue;
                        }
                    }
                }
            }

            if (result != null)
            {
                //order by number from infobox
                result.InputProducts = result.InputProducts.OrderBy(x => x.Order).ToList();
            }

            return(result);
        }