コード例 #1
0
 public void AddSale(string managerName, string clientName, string productName, int productCost, DateTime saleDate)
 {
     var manager = new Manager(0, managerName);
     var client = new Client(0, clientName);
     var product = new Product(0, productName, productCost);
     var sale = new Sale(0, manager, client, product, saleDate);
     _salesDataClient.AddSale(sale);
 }
コード例 #2
0
        public IEnumerable<Sale> Read(string filePath)
        {
            var fileName = Path.GetFileName(filePath);
            if (string.IsNullOrEmpty(fileName))
                throw new ArgumentException(string.Format("File path '{0}' is incorrect.", filePath));
            var managerNameEndIndex = fileName.IndexOf('_');
            if(managerNameEndIndex == -1)
                throw new ArgumentException(string.Format("File path '{0}' is incorrect.", filePath));

            var managerName = fileName.Substring(0, managerNameEndIndex);
            var manager = new Manager(0, managerName);

            using (var csvReader = new CSVFileReader(filePath))
            {
                while (!csvReader.EndOfStream)
                {
                    var values = csvReader.ReadLine();
                    if (values.Length < 4) continue;

                    DateTime saleDate;
                    var success = DateTime.TryParse(values[0].ToString(), out saleDate);
                    if (!success) continue;

                    int cost;
                    success = Int32.TryParse(values[3].ToString(), out cost);
                    if (!success) continue;

                    var clientName = values[1].ToString();
                    var productName = values[2].ToString();

                    var client = new Client(0, clientName);
                    var product = new Product(0, productName, cost);
                    var sale = new Sale(0, manager, client, product, saleDate);

                    yield return sale;
                }
            }
        }
コード例 #3
0
 public void AddSale(Sale sale)
 {
     _salesDataClient.AddSale(sale);
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: GeorgeManiya/EpamTraining
        private static void OnAddNewSale()
        {
            Console.Clear();
            Console.WriteLine("Введите имя клиента");
            var clientName = Console.ReadLine();

            Console.WriteLine("Введите название товара");
            var productName = Console.ReadLine();

            Console.WriteLine("Введите стоимость покупки");
            int cost;
            var correctInput = int.TryParse(Console.ReadLine(), out cost);
            while (!correctInput)
            {
                Console.WriteLine("Некоректная стоимость");
                Console.WriteLine("Введите стоимость покупки заново. Введите 'b' для выхода");
                var read = Console.ReadLine();
                if (read == "b") return;
                correctInput = int.TryParse(read, out cost);
            }

            var manager = new Manager(0, _managerName);
            var client = new Client(0, clientName);
            var product = new Product(0, productName, cost);
            var currentDate = DateTime.Now;
            var sale = new Sale(0, manager, client, product, currentDate);
            _sales.Add(sale);
        }