Ejemplo n.º 1
0
        public List <NomenclatureDTO> GetGoods(CatalogType type)
        {
            using (var uow = UnitOfWorkFactory.CreateWithoutRoot())
            {
                var types = Enum.GetValues(typeof(MobileCatalog))
                            .Cast <MobileCatalog>()
                            .Where(x => x.ToString().StartsWith(type.ToString()))
                            .ToArray();

                var list = NomenclatureRepository.GetNomenclatureWithPriceForMobileApp(uow, types);
                if (type == CatalogType.Water)
                {
                    list = list.OrderByDescending(n => n.Weight)
                           .ThenBy(n => n.NomenclaturePrice.Any() ? n.NomenclaturePrice.Max(p => p.Price) : 0)
                           .ToList();
                }
                else
                {
                    list = list.OrderBy(n => (int)n.MobileCatalog)
                           .ThenBy(n => n.NomenclaturePrice.Any() ? n.NomenclaturePrice.Max(p => p.Price) : 0)
                           .ToList();
                }

                var listDto = list.Select(n => new NomenclatureDTO(n)).ToList();

                var imageIds = NomenclatureRepository.GetNomenclatureImagesIds(uow, list.Select(x => x.Id).ToArray());
                listDto.Where(dto => imageIds.ContainsKey(dto.Id))
                .ToList()
                .ForEach(dto => dto.imagesIds = imageIds[dto.Id]);
                return(listDto);
            }
        }
Ejemplo n.º 2
0
        public static void DeleteRecord(int menuCatalog)
        {
            Console.WriteLine(" Введите ID удаляемой записи:");
            bool        isInputFieldFinished = false;
            CatalogType catalogies           = (CatalogType)menuCatalog;

            while (!isInputFieldFinished)
            {
                string inputLine = Console.ReadLine();
                if (inputLine.Length == 0)
                {
                    continue;
                }
                string         filePath = Data.CreateFile(catalogies.ToString());
                List <Catalog> catalogs = Data.GetList(filePath);
                if (int.TryParse(inputLine, out int userInput))
                {
                    if (userInput == 0)
                    {
                        Console.Clear();
                        isInputFieldFinished = true;
                        break;
                    }
                    Catalog catalog = catalogs.FirstOrDefault(x => x.Id == userInput);
                    if (catalog == null)
                    {
                        Console.WriteLine(" Запись с данным ID не существует.");
                    }
                    else
                    {
                        Expenses expenses = null;
                        if (catalogies == CatalogType.GoodsCategory)
                        {
                            expenses = Data.GetExpenses().FirstOrDefault(x => x.CategoryId == userInput);
                        }
                        else if (catalogies == CatalogType.Goods)
                        {
                            expenses = Data.GetExpenses().FirstOrDefault(x => x.GoodsId == userInput);
                        }
                        else if (catalogies == CatalogType.Unit)
                        {
                            expenses = Data.GetExpenses().FirstOrDefault(x => x.UnitId == userInput);
                        }

                        if (expenses != null)
                        {
                            Console.WriteLine("Запись с данным ID используется в покупках. Не может быть удалена.");
                        }
                        else
                        {
                            catalogs.Remove(catalog);
                            string lines = Catalog.ListToCsv(catalogs);
                            Data.SaveAllData(filePath, lines);
                            isInputFieldFinished = true;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static int InputCatalog(string input, CatalogType catalogType, string error)
        {
            Console.WriteLine($"\n Введите имя {input} или ID:");
            bool isInputFieldFinished = false;
            int  catalogID            = -1;

            while (!isInputFieldFinished)
            {
                string inputLine = Console.ReadLine();
                if (inputLine.Trim().Length == 0)
                {
                    continue;
                }
                string         filePath = Data.CreateFile(catalogType.ToString());
                List <Catalog> catalogs = Data.GetList(filePath);
                if (int.TryParse(inputLine, out catalogID))
                {
                    Catalog catalog = catalogs.FirstOrDefault(x => x.Id == catalogID);
                    if (catalog == null)
                    {
                        Console.WriteLine($" {error} с данным ID не существует.");
                    }
                    else
                    {
                        return(catalogID);
                    }
                }
                else
                {
                    Catalog catalog = catalogs.FirstOrDefault(x => x.Name.ToLower().StartsWith(inputLine.ToLower()));
                    if (catalog == null)
                    {
                        Console.WriteLine($" {error} с данным именем не существует. Добавить?");
                        Menu menu  = new Menu();
                        int  toAdd = menu.AskAddRecord();
                        while (toAdd != 1 && toAdd != 2)
                        {
                            toAdd = menu.AskAddRecord();
                        }
                        if (toAdd == 1)
                        {
                            catalogID = AddRecord(inputLine, filePath, catalogs);
                            return(catalogID);
                        }
                        else if (toAdd == 2)
                        {
                            InputCatalog(input, catalogType, error);
                            isInputFieldFinished = true;
                        }
                    }
                    else
                    {
                        return(catalog.Id);
                    }
                }
            }
            return(catalogID);
        }
Ejemplo n.º 4
0
        public static void AddRecord(int menuCatalog)
        {
            Console.WriteLine("\n Добавить:");
            CatalogType catalogies = (CatalogType)menuCatalog;
            string      filePath   = Data.CreateFile(catalogies.ToString());
            int         id         = Data.GetMaxId(filePath);
            string      allLines   = UserInput.ProcessUserInput(id, catalogies);

            Data.SaveData(filePath, allLines);
        }
Ejemplo n.º 5
0
        public static void TableExpensesDynamic(int from, int to)
        {
            List <Expenses> expensesList = Data.GetExpenses().Where(x => x.Id > from && x.Id <= to).ToList();
            int             maxEnum      = Enum.GetValues(typeof(CatalogType)).Cast <int>().Max();
            int             minEnum      = Enum.GetValues(typeof(CatalogType)).Cast <int>().Min();

            for (CatalogType catalogType = (CatalogType)minEnum; catalogType <= (CatalogType)maxEnum; catalogType++)
            {
                Data.CreateFile(catalogType.ToString());
            }

            List <Catalog> categories = Data.GetList(CatalogType.GoodsCategory + ".csv");
            List <Catalog> goods      = Data.GetList(CatalogType.Goods + ".csv");
            List <Catalog> units      = Data.GetList(CatalogType.Unit + ".csv");
            string         mainHeader = "ПОКУПКИ";

            string[] header      = new string[] { "ID", "Категория", "Наименование", "Ед.измер.", "Цена", "Кол-во", "Дата" };
            int      WindowWidth = Console.WindowWidth - 4;

            int[] maxWidth = new int[] {
                Constant.IdColumnPers,
                Constant.CategoryColumnPers,
                Constant.NameColumnPers,
                Constant.UnitColumnPers,
                Constant.PriceColumnPers,
                Constant.QuantityColumnPers,
                Constant.DateColumnPers
            };
            for (int i = 1; i < maxWidth.Length; i++)
            {
                maxWidth[i] = (int)(Console.WindowWidth / 100f * maxWidth[i]);
            }
            Console.Clear();
            Console.WriteLine(" ." + new string('_', WindowWidth) + ".");
            Console.WriteLine(" |" + new string(' ', WindowWidth) + "|");
            Console.WriteLine(" |" + WriteCenter(mainHeader, WindowWidth));
            Console.WriteLine(" |" + new string('_', WindowWidth) + "|");
            Console.WriteLine(" |" + WriteStr(maxWidth, ' '));
            Console.WriteLine(" |" + WriteCenterStr(header, maxWidth));
            Console.WriteLine(" |" + WriteStr(maxWidth, '_'));
            for (int i = 0; i < expensesList.Count; i++)
            {
                Console.WriteLine(" |" + WriteStr(maxWidth, ' '));
                string[] row = new string[] { expensesList[i].Id.ToString(),
                                              categories.FirstOrDefault(x => x.Id == expensesList[i].CategoryId).Name,
                                              goods.FirstOrDefault(x => x.Id == expensesList[i].GoodsId).Name,
                                              units.FirstOrDefault(x => x.Id == expensesList[i].UnitId).Name,
                                              expensesList[i].Price.ToString(),
                                              expensesList[i].Quantity.ToString(),
                                              expensesList[i].Date.ToShortDateString() };
                CellLineBreak(row, maxWidth);
                Console.WriteLine(" |" + WriteStr(maxWidth, '_'));
            }
        }
Ejemplo n.º 6
0
        public static void TableExpenses(int from, int to)
        {
            List <Expenses> expensesList = Data.GetExpenses().Where(x => x.Id > from && x.Id <= to).ToList();
            int             maxEnum      = Enum.GetValues(typeof(CatalogType)).Cast <int>().Max();
            int             minEnum      = Enum.GetValues(typeof(CatalogType)).Cast <int>().Min();

            for (CatalogType catalogType = (CatalogType)minEnum; catalogType <= (CatalogType)maxEnum; catalogType++)
            {
                Data.CreateFile(catalogType.ToString());
            }

            List <Catalog> categories = Data.GetList(CatalogType.GoodsCategory + ".csv");
            List <Catalog> goods      = Data.GetList(CatalogType.Goods + ".csv");
            List <Catalog> units      = Data.GetList(CatalogType.Unit + ".csv");


            int[] maxWidth = new int[] { Constant.IdColumnLength,
                                         Constant.CategoryColumnLength,
                                         Constant.NameColumnLength,
                                         Constant.UnitColumnLength,
                                         Constant.PriceColumnLength,
                                         Constant.QuantityColumnLength,
                                         Constant.DateColumnLength };
            Console.Clear();
            Console.WriteLine(" .____________________________________________________________________________________________________________________.");
            Console.WriteLine(" |                                                                                                                    |");
            Console.WriteLine(" |                                                 ПОКУПКИ                                                            |");
            Console.WriteLine(" |____________________________________________________________________________________________________________________|");
            Console.WriteLine(" |     |                     |                               |                    |            |   Кол-  |            |");
            Console.WriteLine(" | ID  |      Категория      |         Наименование          |     Ед. измер.     |    Цена    |   ство  |    Дата    |");
            Console.WriteLine(" |_____|_____________________|_______________________________|____________________|____________|_________|____________|");
            for (int i = 0; i < expensesList.Count; i++)
            {
                Console.WriteLine(" |     |                     |                               |                    |            |         |            |");
                string[] row = new string[] { expensesList[i].Id.ToString(),
                                              categories.FirstOrDefault(x => x.Id == expensesList[i].CategoryId).Name,
                                              goods.FirstOrDefault(x => x.Id == expensesList[i].GoodsId).Name,
                                              units.FirstOrDefault(x => x.Id == expensesList[i].UnitId).Name,
                                              expensesList[i].Price.ToString(),
                                              expensesList[i].Quantity.ToString(),
                                              expensesList[i].Date.ToShortDateString() };
                CellLineBreak(row, maxWidth);
                Console.WriteLine(" |_____|_____________________|_______________________________|____________________|____________|_________|____________|");
            }
        }
Ejemplo n.º 7
0
        public static void EditRecord(int menuCatalog)
        {
            Console.WriteLine("\n Введите ID редактируемой записи:");
            bool        isInputFieldFinished = false;
            CatalogType catalogies           = (CatalogType)menuCatalog;

            while (!isInputFieldFinished)
            {
                string inputLine = Console.ReadLine();
                if (inputLine.Trim().Length == 0)
                {
                    continue;
                }
                string         filePath = Data.CreateFile(catalogies.ToString());
                List <Catalog> catalogs = Data.GetList(filePath);
                if (int.TryParse(inputLine, out int userInput))
                {
                    if (userInput == 0)
                    {
                        Console.Clear();
                        isInputFieldFinished = true;
                        break;
                    }
                    Catalog catalog = catalogs.FirstOrDefault(x => x.Id == userInput);
                    if (catalog == null)
                    {
                        //Console.Clear();
                        Console.WriteLine(" Запись с данным ID не существует.");
                    }
                    else
                    {
                        Console.WriteLine(" Запишите новое имя.");
                        string editedName = Console.ReadLine();
                        catalog.Name = ValidateName(catalogs, editedName);
                        string lines = Catalog.ListToCsv(catalogs);
                        Data.SaveAllData(filePath, lines);
                        isInputFieldFinished = true;
                        Console.Clear();
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void TableCatalogs(CatalogType catalogType, int from, int to)
        {
            string         filePath = Data.CreateFile(catalogType.ToString());
            List <Catalog> catalog  = Data.GetList(filePath).Where(x => x.Id > from && x.Id <= to).ToList();

            int[] maxWidth = new int[] { Constant.IdCatColumnLength, Constant.NameCatColumnLength };

            Console.Clear();
            Console.WriteLine(" .____________________________________________________________________________________________________________________.");
            Console.WriteLine(" |                                                                                                                    |");
            Console.WriteLine(" |                  {0}  |", catalogType + new string(' ', 96 - catalogType.ToString().Length));
            Console.WriteLine(" |____________________________________________________________________________________________________________________|");
            Console.WriteLine(" |       |                                                                                                            |");
            Console.WriteLine(" | ID    |     Наименование                                                                                           |");
            Console.WriteLine(" |_______|____________________________________________________________________________________________________________|");
            for (int i = 0; i < catalog.Count; i++)
            {
                Console.WriteLine(" |       |                                                                                                            |");
                string[] row = new string[] { catalog[i].Id.ToString(), catalog[i].Name };
                CellLineBreak(row, maxWidth);

                Console.WriteLine(" |_______|____________________________________________________________________________________________________________|");
            }
        }