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:
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);
}
}
}