关于名片管理系统的编程思想总结

名片管理系统

简单架构:

分析名片的特点和作用来设计类,以及用到的成员:

后台:

l  一张名片包含的内容:名称,公司名,地址,联系方式,职位,网址等信息,因此可以考虑把名片做成一个类,名片里的这些包含的内容做为名片类的字段。这些字段里面要限制格式可以考虑用正则表达式。

l  名片的作用:方便联系,联系方式就作为主要的内容了可能有电话,手机,QQmsn,邮箱等各种联系方式中的一个或者几个,因此可以把联系方式分离出来 做一个泛型集合 实现动态的增删改查。又因为电话手机QQ这些联系方式中有共同的内容 也由自己不同的内容,可以把电话手机等做成一个类来继承联系方式,这里我们把联系方式分为及时通信方式包括MSNQQEmail;和电话类:包括手机,固话

l  名片的信息录入要由一个格式的限制,我们会多次限定异常,这里做一个异常类,凡是用到的地方依赖这个异常类。

l  因为我们这里是再做系统可以考虑给名片加一个类型 方便查找,名片的类型可以是名片的一部分但是查找起来不是很方便,也把名片类型作为一个类来处理。

这样我们的后台处理就由CardSet,Card,Iconnect接口,Phone抽象类,IM抽象类,Mobile,Tel,QQ,MSN,Email类组成。

 

下面介绍一下前台程序的布局和管理:

菜单的布局:1.查询名片 2.管理名片

其中查询又分为:1全部查,2按名称查询,3按分类查询3个子菜单

为了方便操作把名片的查询处理为一个类,类的内部写对名片查询的方法,这个方法最好定义为静态的,因为静态的方法可以直接用类名调用,

管理名片分为:1.添加名片 2.更新名片 3.删除名片

名片的添加和更新,删除都要面临联系人的添加和更新和删除,这里把联系人的管理也处理成一个类,对联系人进行管理,联系人的添加用到了抽象工厂(以后还会学)的思想,个人觉得很巧妙,我是想到不会这样用:

//添加联系方式

    public static void AddConnect()

        {

            #region   添加联系方式

         while (true)

            {

                IConnect connect = null;

//do..while来控制循环

                do

                {

                    Console.WriteLine("添加联系方式:");

                    Console.WriteLine("1、手机  2、固定电话  3QQ  4、邮箱地址");

                    switch (Console.ReadLine())

                    {

                        case "1":

                            connect = new Mobile();//直接把具体的对象用联系方式这个抽象的对象保存起来,就可以对connect的操作就是对所有不同类别的联系方式的操作

                            break;

                        case "2":

                            connect = new Tel();

                            break;

                        case "3":

                            connect = new QQ();

                            break;

                        case "4":

                            connect = new Email();

                            break;

                        default:

                            connect = null;

                            break;

                    }

                    if (connect != null)

                    {

                        Console.WriteLine("请输入{0}号码:", connect.Name);

                        connect.Number = Console.ReadLine();

                    }

                } while (connect == null);//要考虑联系方式是否为空的情况

                card.Connects.Add(connect);

 

                Console.WriteLine("继续添加请按Y,否则请按其他键!");

                if (Console.ReadLine().ToUpper() != "Y")

                {

                    break;

                }

            }            #endregion

        }

MangeConnect:

/// <summary>

    /// 联系方式管理

    /// </summary>

    static class ManageConnect

    {

        static Card card;

        /// <summary>

        /// 联系方式管理菜单

        /// </summary>

        /// <param name="card">名片</param>

        public static void Menu(Card card)

        {

            ManageConnect.card = card;

            Console.WriteLine("联系方式修改,请选择操作编号:");

            Console.WriteLine("1、添加  2、修改  3、删除  4、退出");

 

            switch (Console.ReadLine())

            {

                case "1":

                    AddConnect();

                    break;

 

                case "2":

                    ModifyConnect();

                    break;

 

                case "3":

                    RemoveConnect();

                    break;

 

                case "4":

                    return;

            }

 

        }

        /// <summary>

        /// 添加联系方式

        /// </summary> 

        public static void AddConnect()

        {

            #region 添加连系方式

            while (true)

            {

                IConnect connect = null;

                do

                {

                    Console.WriteLine("添加联系方式:");

                    Console.WriteLine("1、手机  2、固定电话  3QQ  4、邮箱地址");

                    switch (Console.ReadLine())

                    {

                        case "1":

                            connect = new Mobile();

                            break;

                        case "2":

                            connect = new Tel();

                            break;

                        case "3":

                            connect = new QQ();

                            break;

                        case "4":

                            connect = new Email();

                            break;

                        default:

                            connect = null;

                            break;

                    }

                    if (connect != null)

                    {

                        Console.WriteLine("请输入{0}号码:", connect.Name);

                        connect.Number = Console.ReadLine();

                    }

                } while (connect == null);

                card.Connects.Add(connect);

 

                Console.WriteLine("继续添加请按Y,否则请按其他键!");

                if (Console.ReadLine().ToUpper() != "Y")

                {

                    break;

                }

            }

 

            #endregion

        }

        /// <summary>

        /// 添加联系方式

        /// </summary>

        /// <param name="card">名片</param>

        public static void AddConnect(Card card)

        {

            #region 添加连系方式

            while (true)

            {

                IConnect connect = null;

                do

                {

                    Console.WriteLine("添加联系方式:");

                    Console.WriteLine("1、手机  2、固定电话  3QQ  4、邮箱地址");

                    switch (Console.ReadLine())

                    {

                        case "1":

                            connect = new Mobile();

                            break;

                        case "2":

                            connect = new Tel();

                            break;

                        case "3":

                            connect = new QQ();

                            break;

                        case "4":

                            connect = new Email();

                            break;

                        default:

                            connect = null;

                            break;

                    }

                    if (connect != null)

                    {

                        Console.WriteLine("请输入{0}号码:", connect.Name);

                        connect.Number = Console.ReadLine();

                    }

                } while (connect == null);

                card.Connects.Add(connect);

 

                Console.WriteLine("继续添加请按Y,否则请按其他键!");

                if (Console.ReadLine().ToUpper() != "Y")

                {

                    break;

                }

            }

 

            #endregion

        }

        /// <summary>

        /// 修改联系方式

        /// </summary>

        public static void ModifyConnect()

        {

            int conindex = 1;//引入编号,根据编号来修改联系方式

            foreach (IConnect connect in card.Connects)

            {

                Console.WriteLine("{0}{1}-{2}", conindex++, connect.Name, connect.Number);

            }

            Console.WriteLine("请选择要修改的联系方式编号:");

            int num = int.Parse(Console.ReadLine()) - 1;

            IConnect oldconnect = card.Connects[num];

            Console.WriteLine("请输入新号码:");

            oldconnect.Number = Console.ReadLine();

        }

        /// <summary>

        /// 联系方式

        /// </summary>

        private static void RemoveConnect()

        {

            int conindex = 1;

            foreach (IConnect connect in card.Connects)

            {

                Console.WriteLine("{0}{1}-{2}", conindex++, connect.Name, connect.Number);

            }

            Console.WriteLine("请选择要修改的联系方式编号:");

            int num = int.Parse(Console.ReadLine()) - 1;

            IConnect oldconnect = card.Connects[num];

            card.Connects.Remove(oldconnect);

        }

}

}

 

MangeCard:

/// <summary>

    /// 名片管理

    /// </summary>

    static class ManageCard

    {

        /// <summary>

        ///名片类型

        /// </summary>

        static List<CardType> cardtypes;

        static CardSet cardset;

        /// <summary>

        /// ¨¹¤¨ª???Ì£¤

        /// </summary>

        /// <param name="cardset">??¨¢</param>

        /// <param name="cardtypes">??¤¨¤¨ª¡¥?</param>

        public static void Menu(CardSet cardset, List<CardType> cardtypes)

        {

            ManageCard.cardtypes = cardtypes;

            ManageCard.cardset = cardset;

            Console.WriteLine("1¡é¬¨ª¨®??  2¡éT???  3¡é¦?y??  4¡é退ª????¨¹¤¨ª");

            switch (Console.ReadLine())

            {

                case "1":

                    Add();

                    break;

                case "2":

                    Update();

                    break;

                case "3":

                    Delete();

                    break;

                case "4":

                    return;

            }

 

        }

        /// <summary>

        /// ¨´Y??Ì?Ì????¡¥?

        /// </summary>

        /// <param name="name">??</param>

        /// <returns>??¡¥?</returns>

        static List<Card> GetCardByName(string name)

        {

            List<Card> newcards = new List<Card>();

            foreach (Card oldcard in cardset.Cards)

            {

                if (oldcard.Name.Contains(name))

                {

                    newcards.Add(oldcard);

                }

            }

            return newcards;

        }

        /// <summary>

        /// Ì?Ì??¡¥?DÌ???

        /// </summary>

        /// <param name="newcards">???¡¥?</param>

        /// <returns>??</returns>

        static Card GetCard(List<Card> newcards)

        {

            int index = 1;

            foreach (Card oldcard in newcards)

            {

                Console.WriteLine("{0}¡é??êo{1} ??êo{2} ¡ã?êo{3} Ì?¡¤êo{4}", index, oldcard.Name, oldcard.Company, oldcard.Position, oldcard.Address);

                index++;

            }

            Console.WriteLine("???T???êo");

            int num = int.Parse(Console.ReadLine()) - 1;

 

            Card card = newcards[num];

            Console.WriteLine(card.ToString());

            return card;

        }

        /// <summary>

        /// T???

        /// </summary>

        /// <param name="cardset">??¨¢</param>

        private static void Update()

        {

            try

            {

                Console.WriteLine("?º?¨?°aT???¨?Ì???êo");

                string name = Console.ReadLine();

                //????¨¤ª?Ì???

                List<Card> newcards = GetCardByName(name);

                //????¬?Ì???

                Card card = GetCard(newcards);

 

                //T?¡Â?º??

                string cardname;

                if (IsModify("??", out cardname))

                {

                    card.Name = cardname;

                }

                string cardcompany;

                if (IsModify("??", out cardcompany))

                {

                    card.Company = cardcompany;

                }

 

                string cardposition;

                if (IsModify("¡ã?", out cardposition))

                {

                    card.Position = cardposition;

                }

                string cardaddress;

                if (IsModify("Ì?¡¤", out cardaddress))

                {

                    card.Address = cardaddress;

                }

 

                string cardwebsit;

                if (IsModify("ª?¡¤", out cardwebsit))

                {

                    card.Websit = cardwebsit;

                }

 

                int typeid;

                if (IsModify("??¤¨¤¨ª", out typeid))

                {

                    card.TypeID = typeid;

                }

 

                //T?¢a¦Ì¤?º?

                ManageConnect.Menu(card);

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

        /// <summary>

        /// º?¤?T?

        /// </summary>

        /// <param name="proname">T?º??¦Ì¡Â</param>

        /// <param name="provalue">T?¨®Ì?º??¦Ì</param>

        /// <returns>º?¤?T?</returns>

        static bool IsModify(string proname, out string provalue)

        {

            Console.WriteLine("º?¤?°aT?{0}ê?º??ã¡äY", proname);

            if (Console.ReadLine().ToUpper() == "Y")

            {

                Console.WriteLine("{0}êo", proname);

                provalue = Console.ReadLine();

                return true;

            }

            provalue = null;

            return false;

        }

        /// <summary>

        /// º?¤?T?

        /// </summary>

        /// <param name="proname">T?º??¦Ì¡Â</param>

        /// <param name="id">°aT?¤¨¤¨ªID</param>

        /// <returns>º?¤?T?</returns>

        static bool IsModify(string proname, out int id)

        {

            Console.WriteLine("º?¤?°aT?{0}ê?º??ã¡äY", proname);

            if (Console.ReadLine().ToUpper() == "Y")

            {

                foreach (CardType cardtype in cardtypes)

                {

                    Console.WriteLine("{0}¡é{1}", cardtype.ID, cardtype.TypeName);

                }

                Console.WriteLine("???À¨¤?êo");

                id = int.Parse(Console.ReadLine());

                return true;

            }

            id = 0;

            return false;

        }

        /// <summary>

        /// ¦?y??

        /// </summary>

        /// <param name="cardset">??¨¢</param>

        private static void Delete()

        {

            try

            {

                Console.WriteLine("?º?¨?°aT???¨?Ì???êo");

                string name = Console.ReadLine();

                //????¨¤ª?Ì???

                List<Card> newcards = GetCardByName(name);

                //????¬?Ì???

                Card card = GetCard(newcards);

                //¦?y??

                cardset.RemoveCard(card);

 

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

        /// <summary>

        /// ¬¨ª¨®??

        /// </summary>

        /// <param name="cardset">??¨¢</param>

        public static void Add()

        {

            try

            {

                //ä¡ä¡§????¨®ê?¡é?¡Âº??3¦Ì

                Card card = new Card();

                Console.WriteLine("??êo");

                card.Name = Console.ReadLine();

                Console.WriteLine("??êo");

                card.Company = Console.ReadLine();

                Console.WriteLine("¡ã?êo");

                card.Position = Console.ReadLine();

                Console.WriteLine("Ì?¡¤êo");

                card.Address = Console.ReadLine();

                Console.WriteLine("ª?¡¤êo");

                card.Websit = Console.ReadLine();

 

                foreach (CardType ct in cardtypes)

                {

                    Console.WriteLine("{0}¡é{1}", ct.ID, ct.TypeName);

                }

                Console.WriteLine("¤¨¤¨ªÀ¨¤?êo");

                card.TypeID = int.Parse(Console.ReadLine());

                //¬¨ª¨®¢a¦Ì¤?º?

                ManageConnect.AddConnect(card);

 

                //¬¨ª¨®??Ì???¨¢

                cardset.AddCard(card);

            }

            catch (Exception e)

            {

                Console.WriteLine(e.Message);

            }

        }

 

 

    }

QueryCard:

 

    /// <summary>

    /// ??¨¦¡¥

    /// </summary>

    static class QueryCard

    {

        /// <summary>

        /// ??¨¢

        /// </summary>

        static CardSet cardset;

        /// <summary>

        /// ??¤¨¤¨ª

        /// </summary>

        static List<CardType> cardtypes;

        /// <summary>

        /// ¨¦¡¥???Ì£¤

        /// </summary>

        /// <param name="cardset">??¨¢</param>

        /// <param name="cardtypes">??¤¨¤¨ª¡¥?</param>

        public static void Menu(CardSet cardset, List<CardType> cardtypes)

        {

            QueryCard.cardset = cardset;

            QueryCard.cardtypes = cardtypes;

            Console.WriteLine("1¡é¨??¨¦  2¡éã¡ä??¨¦¡¥  3¡éã¡ä¤?¤¨¤¨¦¡¥  4¡é退ª??¨¦¡¥");

            switch (Console.ReadLine())

            {

                case "1":

                    QueryAllCard();

                    break;

                case "2":

                    QueryCardByName();

                    break;

                case "3":

                    QueryCardByType();

                    break;

                case "4":

                    return;

            }

            Console.WriteLine("¨¬??ã¡ä¨?°a¨¹ê?");

            Console.ReadLine();

        }

        /// <summary>

        /// ã¡ä??¤¨¤¨ª¨¦¡¥

        /// </summary>

        private static void QueryCardByType()

        {

            string typename = "";

            foreach (CardType cardtype in cardtypes)

            {

                Console.WriteLine("{0}¡é{1}", cardtype.ID, cardtype.TypeName);

 

 

            }

            int typeid = int.Parse(Console.ReadLine());

            typename = cardtypes.Single(ct => ct.ID == typeid).TypeName;

            Console.WriteLine("¤¨¤¨ªêo{0}", typename);

            bool mark = false;//®DTºyYÀ¨º?

            foreach (Card oldcard in cardset.Cards)

            {

                if (oldcard.TypeID == typeid)

                {

                    Console.WriteLine(oldcard.ToString());

                    mark = true;

                }

            }

 

            if (!mark)

            {

                Console.WriteLine("TºyYê?");

            }

        }

        /// <summary>

        /// ã¡ä??¨¦¡¥

        /// </summary>  

        private static void QueryCardByName()

        {

            Console.WriteLine("¦¥Ì???(¡êy¨¦¡¥)êo");

            string name = Console.ReadLine();

            bool mark = false;////有无据标?

 

            foreach (Card oldcard in cardset.Cards)

            {

                if (oldcard.Name.Contains(name))

                {

                    foreach (CardType ct in cardtypes)

                    {

                        if (ct.ID == oldcard.TypeID)

                        {

                            Console.Write("¨{0} ", ct.TypeName);

                            mark = true;

                        }

                    }

                    Console.WriteLine(oldcard.ToString());

                }

            }

            if (!mark)

            {

                Console.WriteLine("");

            }

        }

        /// <summary>

        /// ¨¦¡¥¨????

        /// </summary>

        private static void QueryAllCard()

        {

            bool mark = false;

            foreach (Card oldcard in cardset.Cards)

            {

                foreach (CardType ct in cardtypes)

                {

                    if (ct.ID == oldcard.TypeID)

                    {

                        Console.Write("¨{0} ", ct.TypeName);

                        break;

                    }

                }

                mark = true;

                Console.WriteLine(oldcard.ToString());

            }

            if (!mark)

            {

                Console.WriteLine("");

            }

        }

    }

}

 

 

 

你可能感兴趣的:(职场,休闲,名片管理系统)