Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I'm tiring to write a console application with C# , and i want to observance OOP , functionality ,Abstraction, Encapsulation, Inheritance , Polymorphic ,code style , working with file.

Here is the description of my project,

This is a support application for a company that sell laptops, customer after buying laptop can check hardware that use in their laptop.

I have problem with user login ,search and query from file ,and sub menu, anybody have idea?

http://i.stack.imgur.com/uQjsa.jpg[^]

1. we have two users
2. user (Admin, Customer)
3. Admin able to (Add,remove,search)
4. Customer able to (search)
5. when customer select search must see another menu and select (Ram
,Hard Disk ،CPU ،Main Board),
6. after select hardware able to see another menu e.g. select CPU(AMD
,Intel)
7. after select Intel see another menu e.g. select CPU Type
(3.2 GHz , 2.8 GHz)
8. after select type see full description of hardware.
9. all data must save on a file , and query from that file.



Here is my code:


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication2

{
    class Inventory

    {
        string[] productNames = new string[100];
        string[] productModels = new string[100];
        string[] manufacterNames = new string[100];
        int productID;
        string productName;
        string Model;
        string Manufacture;
        string CPU;
        int CPUType;
        string RAM;
        string RAMType;
        string HDD;
        string ODD;
        string VGA;
        string Description;
        int quantity ;

        int n = 0;

        public void Add()
        {
            Console.Write("Enter Product Name : ");
            productNames[n] = Console.ReadLine();
            Console.Write("Enter Product Model : ");
            productModels[n] = (Console.ReadLine());
            Console.Write("Enter Manufacter : ");
            manufacterNames[n] = (Console.ReadLine());

        }
        public void file()
        {
            for (int i = 0; i < n; i++)
            {
                string[] lines = { productNames[i], productModels[i], manufacterNames[i] };
                System.IO.File.WriteAllLines(@"WriteLines.txt", lines);
                Console.ReadKey();
            }
        }
        public void Search()

        {
            Console.Clear();
            Console.Write("\n Select your hardware: \n \n 5.MainBoard \n 6.CPU \n 7.Hard Disk \n 8.Ram \n * Back (Press ESC) ");

      Console.ReadKey();
        }

        public void Print()
        {

            for (int i = 0; i < n; i++)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(" Product Name = " + productNames[i] +"\n Product Model =" + productModels[i] +"\n Manufacture =" + manufacterNames[i]+"\n");
                Console.ResetColor();

            }

            Console.ReadKey();
        }
    }
    class users
    {
        int userID;
        string userName;
        string password;
        bool loginstatus;


    }
    class Menu
    {
        int choice;
        public int Show()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(20, 0); Console.WriteLine("Welcome To System Support");
            Console.SetCursorPosition(18, 1); Console.WriteLine("Developers: XX");
            Console.ResetColor();
            Console.WriteLine();
            Console.Write("Please Enter Your Choice: \n\n\n 1. Add New Product \n 2. Search Product  \n 3. Print Product List \n 4. Save \n 5. Exit \n ");
            Console.WriteLine("------------------");
            choice = Convert.ToInt32(Console.ReadLine());
            return choice;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "System Support";
            Menu menu = new Menu();
            Inventory productList = new Inventory();
            int choice;
            do
            {
                choice = menu.Show();
                switch (choice)
                {
                    case 1:
                        {
                            productList.Add();
                        }
                        break;
                    case 2:
                        {
                            productList.Search();
                        }
                        break;
                    case 3:
                        {
                            productList.Print();
                        }
                        break;

                    case 4:
                        {
                            productList.file();
                        }
                        break;

                }
            } while (choice != 5);






        }
    }



}
Posted
Comments
CPallini 24-Nov-15 3:05am    
You should be more specific. What is, for instance, your problem with 'user login' mechanism? At application startup, iteratively ask the user for name and password until a match happens. Then display the main menu.

1 solution

We can't tell what you are trying to do and without running your code (which I'm not about to do) we can't tell what problems you are having with it.

But..."i want to observance OOP , functionality ,Abstraction, Encapsulation, Inheritance , Polymorphic ,code style , working with file." - and you don't seem to be doing any of that.

Start thinking about what you need to do to implement a product and what an Inventory is.
An inventory is a collection of Products - not a list of names, models, etc.: The Product "knows" what type of item is it "Laptop" or "Desktop" say, and the Laptop knows what model it is: 17 inch, or 18 inch for example. So a Model would be derived from an ItemType, which would be derived from a Product.
And the product should know how to write itself to a file, (via the inherited classes) so your Inventory should be able to write itself by writing each Product.
Then loading the Inventory from the file when the program starts is a similar operation, which needs to create instances of the right Model from the data.

What you have uses classes, but doesn't use them in an OOPs manner, or show any of the features you say you want to use!

Me? I'd start again, and think carefully about what data I need first then design my classes around that.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900