示例#1
0
        /// <summary>
        /// Adds to inventory.
        /// </summary>
        public void AddToInventory()
        {
            try
            {
                Console.WriteLine("Enter name of the item to add");
                string name = Console.ReadLine();
                Console.WriteLine("Enter the weight of the item");
                double weight = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Enter the price of item");
                double price = Convert.ToDouble(Console.ReadLine());
                InventoryManagement managementModel = new InventoryManagement()
                {
                    Name       = name,
                    Weight     = weight,
                    PricePerKg = price
                };

                string data = InventoryManagement.ReadFile(this.constants.InventoryProducts);
                this.inventory = JsonConvert.DeserializeObject <List <InventoryManagement> >(data);
                this.inventory.Add(managementModel);
                var convertedJson = JsonConvert.SerializeObject(this.inventory);
                File.WriteAllText(this.constants.InventoryProducts, convertedJson);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Manages this instance.
        /// </summary>
        public void Manage()
        {
            try
            {
                char ch;
                do
                {
                    InventoryManagement inventory = new InventoryManagement();
                    Console.WriteLine("Enter 1 to read the data from file");
                    Console.WriteLine("Enter 2 to Add the data to file");
                    Console.WriteLine("Enter 3 to Update the data in file");
                    Console.WriteLine("Enter 4 to Remove the data in file");
                    int choice = Convert.ToInt32(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                        inventory.InventoryManagementData();
                        break;

                    case 2:
                        inventory.AddToInventory();
                        break;

                    case 3:
                        inventory.UpdateInventoryData();
                        break;

                    case 4:
                        inventory.Delete();
                        break;
                    }

                    Console.WriteLine("Do you want to continue (y/n)");
                    ch = Convert.ToChar(Console.ReadLine());
                }while (ch != 'n');
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#3
0
        /// <summary>
        /// Deletes this instance.
        /// </summary>
        public void Delete()
        {
            try
            {
                string data = InventoryManagement.ReadFile(this.constants.InventoryProducts);
                IList <InventoryManagement> inventoryDetails = JsonConvert.DeserializeObject <List <InventoryManagement> >(data);

                foreach (var items in inventoryDetails)
                {
                    Console.WriteLine(items.Id + "\t" + items.Name + "\t" + items.Weight + "\t" + items.PricePerKg);
                }

                Console.WriteLine("Enter the Id to Delete");
                int id = Convert.ToInt32(Console.ReadLine());
                foreach (var item in inventoryDetails)
                {
                    while (id == item.Id)
                    {
                        Console.WriteLine(item.Id + "\t" + item.Name + "\t" + item.Weight + "\t" + item.PricePerKg);
                        break;
                    }
                }

                foreach (var item in inventoryDetails)
                {
                    while (id == item.Id)
                    {
                        inventoryDetails.Remove(item);
                        break;
                    }
                }

                var convertedJson = JsonConvert.SerializeObject(inventoryDetails);
                File.WriteAllText(this.constants.InventoryProducts, convertedJson);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#4
0
        /// <summary>
        /// Updates the inventory data.
        /// </summary>
        public void UpdateInventoryData()
        {
            try
            {
                ////Constants constants = new Constants();
                string data = InventoryManagement.ReadFile(this.constants.InventoryProducts);
                IList <InventoryManagement> inventoryDetails = JsonConvert.DeserializeObject <List <InventoryManagement> >(data);
                foreach (var items in inventoryDetails)
                {
                    Console.WriteLine(items.Id + "\t" + items.Name + "\t" + items.Weight + "\t" + items.PricePerKg);
                }

                Console.WriteLine("Enter the Id to update");
                int id = Convert.ToInt32(Console.ReadLine());
                foreach (var item in inventoryDetails)
                {
                    while (id == item.Id)
                    {
                        Console.WriteLine(item.Id + "\t" + item.Name + "\t" + item.Weight + "\t" + item.PricePerKg);
                        break;
                    }
                }

                Console.WriteLine("Enter 1 to change the price \n Enter 2 to change weight");
                int property  = Convert.ToInt32(Console.ReadLine());
                int newPrice  = 0;
                int newWeight = 0;
                switch (property)
                {
                case 1:
                    Console.WriteLine("Enter new Price");
                    newPrice = Convert.ToInt32(Console.ReadLine());
                    foreach (var item in inventoryDetails)
                    {
                        while (id == item.Id)
                        {
                            item.PricePerKg = newPrice;
                            break;
                        }
                    }

                    break;

                case 2:
                    Console.WriteLine("Enter new Price");
                    newWeight = Convert.ToInt32(Console.ReadLine());
                    foreach (var item in inventoryDetails)
                    {
                        while (id == item.Id)
                        {
                            item.Weight = this.Weight;
                            break;
                        }
                    }

                    break;
                }

                var convertedJson = JsonConvert.SerializeObject(inventoryDetails);
                File.WriteAllText(this.constants.InventoryProducts, convertedJson);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
示例#5
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            string condition     = null;
            int    caseCondition = 0;

            try
            {
                do
                {
                    Console.WriteLine("enter 1 for inventory details");
                    Console.WriteLine("enter 2 for regular expression");
                    Console.WriteLine("enter 3 for stock");
                    Console.WriteLine("enter 4 for inventory management");
                    Console.WriteLine("enter 5 for deck of cards");
                    Console.WriteLine("enter 6 for stock data processing");
                    Console.WriteLine("enter 7 for address book");
                    Console.WriteLine("enter 8 for deck of cards in queue");
                    Console.WriteLine("enter 9 for getting transaction in queue");
                    Console.WriteLine("enter 10 for getting transaction in stack");
                    try
                    {
                        caseCondition = Convert.ToInt32(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("enter proper condition");
                    }

                    switch (caseCondition)
                    {
                    case 1:
                        ////creating object of inventory class
                        Inventory inventory = new Inventory();
                        inventory.PrintData();
                        break;

                    case 2:
                        ////creating object of RegularExpression class
                        RegularExpression regularExpression = new RegularExpression();
                        regularExpression.ReplacingRegularExpressionWithString();
                        break;

                    case 3:
                        ////creating object of Stock class
                        Stock stock = new Stock();
                        stock.CreateStock();
                        break;

                    case 4:
                        ////creating object of InventoryManagement class
                        InventoryManagement inventoryManagement = new InventoryManagement();
                        inventoryManagement.Manage();
                        break;

                    case 5:
                        ////creating object of DeckOfCards class
                        DeckOfCards deckOfCards = new DeckOfCards();
                        deckOfCards.Distribution();
                        break;

                    case 6:
                        ////creating the object of DataProcessingMainClass class
                        DataProcessingMainClass dataProcessingMainClass = new DataProcessingMainClass();
                        dataProcessingMainClass.DataProcesssing();
                        break;

                    case 7:
                        ////creating the object of AddressBook class
                        AddressBook addressBook = new AddressBook();
                        addressBook.AddressBookDetails();
                        break;

                    case 8:
                        ////creating the object of CardQueue class
                        CardQueue cardQueue = new CardQueue();
                        cardQueue.CardInQueue();
                        break;

                    case 9:
                        ////creating the object of TransactionsInQueue class
                        TransactionsInQueue transaction = new TransactionsInQueue();
                        transaction.TransactionInQueue();
                        break;

                    case 10:
                        ////creating the object of TransactionStack class
                        TransactionStack transactionStack = new TransactionStack();
                        transactionStack.StackTransaction();
                        break;
                    }

                    Console.WriteLine("Enter Y to continue OR any key to stop");

                    condition = Console.ReadLine();
                }while (condition.Equals("y") || condition.Equals("Y"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
            }
        }