Exemplo n.º 1
0
        /// <summary>
        /// Change item menu
        /// </summary>
        public void ChangeValue()
        {
            string id = "";
            int    resultId;
            string field = "";
            string j     = "";

            isItemType += changeItemController.IsItemType;

            parseId += changeItemController.ParseId;

            isCorrectId    += changeItemController.IsCorrectId;
            getItemByValue += changeItemController.GetItemValue;
            getItemById    += changeItemController.GetItemById;
            Console.WriteLine();
            Console.WriteLine("Choose id of user's field that you want to change(0 to cancel):");
            id = Console.ReadLine();
            if (id.Equals("0"))
            {
                enterPagePL.ChangeView();
            }

            Console.WriteLine();
            Console.WriteLine("Choose field that you want to change(0 to cancel):");
            field = Console.ReadLine();

            if (field.Equals("0"))
            {
                enterPagePL.ChangeView();
            }

            Console.WriteLine();
            Console.WriteLine("Enter new value:");
            j = Console.ReadLine();


            if (isItemType(field) && isCorrectId(id))
            {
                resultId = parseId(id);
                dictReports[getItemByValue(field)](resultId, j);

                var result = getItemById(resultId);
                Console.WriteLine();
                Console.WriteLine("Changed value");

                Console.WriteLine();
                Console.WriteLine("Id  Name  Price  Category  Description");
                Console.WriteLine();
                foreach (var i in result)
                {
                    Console.WriteLine(i.Id + " " + i.Name + " " + i.Price + " " + i.Category + " " + i.Description);
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("Wrong data");
            }


            ChangeValue();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Chnage info
        /// </summary>
        public void ChangeValue()
        {
            string id    = "";
            string field = "";
            string j     = "";

            ShowPersons();
            try
            {
                if (getType() == typeof(User))
                {
                    id = getId().ToString();
                }
                else
                {
                    Console.WriteLine("Choose id of user's field that you want to change:");
                    id = Console.ReadLine();
                    if (Int32.TryParse(id, out int resultId))
                    {
                        if (id.Equals("0"))
                        {
                            enterPagePL.ChangeView();
                        }
                    }
                    else
                    {
                        Console.WriteLine("Wrong choise");

                        enterPagePL.ChangeView();
                    }
                }
            }
            catch (ArgumentException i)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Choose field that you want to change:");
            OutputFields();

            try
            {
                field = Console.ReadLine();
                if (Int32.TryParse(field, out int intField) && intField >= 1 && intField <= 5)
                {
                    if (field.Equals("0"))
                    {
                        enterPagePL.ChangeView();
                    }
                }
                else
                {
                    Console.WriteLine("Wrong parameters");
                    enterPagePL.ChangeView();
                }
            }
            catch (ArgumentException i)
            {
                Console.WriteLine(i.Message);
            }

            Console.WriteLine("Enter value");

            try
            {
                j = Console.ReadLine();
                if (j is null || j == "")
                {
                    Console.WriteLine("Wrong parameter");
                }
            }
            catch (ArgumentException i)
            {
                Console.WriteLine(i.ToString());
            }

            if (Enum.TryParse(field, out FieldType fieldType))
            {
                if (Int32.TryParse(id, out int resultId) && getLastId() >= resultId)
                {
                    if (resultId == 0 || fieldType == 0)
                    {
                        enterPagePL.ChangeView();
                    }
                    dictReports[--fieldType](resultId, j);
                }
                else
                {
                    enterPagePL.ChangeView();
                }
            }

            Output();
        }