系统支持(使用C#的控制台应用程序) [英] System Support (console application with C#)

查看:54
本文介绍了系统支持(使用C#的控制台应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我厌倦了用C#编写控制台应用程序,我想遵守OOP,功能,抽象,封装,继承,多态,代码风格,使用文件。



这是我的项目的描述,



这是一个销售笔记本电脑的公司的支持应用程序,客户购买笔记本电脑后可以查看硬件在他们的笔记本电脑中使用。



我在用户登录,搜索和查询文件以及子菜单时遇到问题,有人有想法吗?



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



1.我们有两个用户

2.用户(管理员,客户)

3.管理员能够(添加,删除,搜索)

4.客户能够(搜索)

5.当客户选择搜索时必须看到另一个菜单并选择(Ram

,硬盘,CPU,主板),

6.选择硬件后能看到另一个菜单,例如选择CPU(AMD

,英特尔)

7.选择英特尔后再看另一个菜单,例如选择CPU类型

(3.2 GHz,2.8 GHz)

8.选择类型后查看硬件的完整描述。

9.所有数据必须保存在文件上,并从该文件中查询。







这是我的代码:





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






        }
    }



}

推荐答案

我们无法告诉你要做什么,也没有运行你的代码(我是我们不知道你有什么问题。



但是...... 我想遵守OOP,功能,抽象,封装,继承,多态,代码风格,使用文件。 - 你似乎没有做任何一件事。



开始考虑实施产品需要做什么以及库存是什么。

库存是产品的集合 - 而不是名称,型号等的列表:产品知道什么类型的项目是笔记本电脑或桌面说,并且笔记本电脑知道它是什么型号:例如17英寸或18英寸。因此,模型将从ItemType派生而来,该类型将从产品派生。

产品应该知道如何将自己写入文件(通过继承的类),因此您的库存应该是能够通过编写每个产品来编写自己。

然后在程序启动时从文件加载Inventory是一个类似的操作,需要从数据中创建正确模型的实例。



您所使用的课程,但不以OOP方式使用,或显示您想要使用的任何功能!



我?我重新开始,仔细考虑我需要的数据,然后围绕它设计我的课程。
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.


这篇关于系统支持(使用C#的控制台应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆