最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實現DVD借出歸還管理系統(tǒng)

 更新時間:2021年06月24日 11:50:33   作者:老明宇.  
這篇文章主要介紹了C#實現DVD借出歸還管理系統(tǒng),類似DVD管理器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

用C#寫的一個DVD管理器,供大家參考,具體內容如下

(大神勿噴,初學者以借鑒為主)

一共分為三個類分別是:DVD(啟動類),XinXi(信息類),GongNeng(功能類)

代碼部分(如下):

DVD(啟動類):

class DVD
    {
        static void Main(string[] args)
        {
            GongNeng gongNeng = new GongNeng();
            gongNeng.initial();  //初始化
            gongNeng.XianShi();  //遍歷初始化信息
            gongNeng.CaiDan();  //選項菜單
        }
    }

XinXi(信息類):

class XinXi
    {
        private string _name;//名稱
        private int state;//借出狀態(tài)
        private string date;//時間
 
        //屬性封裝
        public string Name { get => _name; set => _name = value; }//名稱
        public int State { get => state; set => state = value; }//借出狀態(tài)
        public string Date { get => date; set => date = value; }//時間
    }

GongNeng(功能類):

因為功能類使用了正則表達式來判斷日期格式,所以在使用的時候頭部還需加上:

using System.Text.RegularExpressions;     // RegularExpressions為正則表達式,Text為文本

class GongNeng
    {
        XinXi[] xinxi = new XinXi[10];//對象數組存儲數據
        //初始化信息
        #region  初始化信息
        public void initial() {
            xinxi[0] = new XinXi();
            xinxi[0].Name = "羅馬假日";
            xinxi[0].State = 0;
            xinxi[0].Date = "2010-7-1";
 
            xinxi[1] = new XinXi();
            xinxi[1].Name = "風聲鶴唳";
            xinxi[1].State = 1;
            xinxi[1].Date = "";
 
            xinxi[2] = new XinXi();
            xinxi[2].Name = "浪漫滿屋";
            xinxi[2].State = 1;
            xinxi[2].Date = "";
        }
        #endregion
 
        //顯示初始化信息
        #region  顯示初始化信息
        public void XianShi() {
            Console.WriteLine("********初始化信息如下:********");
            foreach (XinXi item in xinxi) {
                if (item != null) {
                    Console.WriteLine(item.Name+"\t"+item.State+"\t"+item.Date);
                }
            }
            Console.WriteLine("********************************");
        }
        #endregion
 
        //DVD菜單
        #region  DVD菜單
        public void CaiDan()
        {
                Console.WriteLine("------------歡迎使用明宇迷你DVD管理器------------");
                Console.WriteLine("1.新增DVD\n2.查看DVD\n3.刪除DVD\n4.借出DVD\n5.歸還DVD\n6.退出");
                Console.WriteLine("-------------------------------------------------");
                Console.Write("請輸入您的選擇:");
                int xuanZe = int.Parse(Console.ReadLine());
                switch (xuanZe)
                {
                    case 1:
                    //新增DVD
                        XinZeng();
                        break;
                    case 2:
                    //查看DVD
                        ChaXun();
                        break;
                    case 3:
                    //刪除DVD
                        ShanChu();
                        break;
                    case 4:
                    //借出DVD
                        JieChu();
                        break;
                    case 5:
                    //歸還DVD
                        GuiHuan();
                        break;
                    case 6:
                        //退出
                        Console.WriteLine("歡迎下次光臨!");
                        break;
                    default:
                        //無選項
                        Console.WriteLine("對不起,沒有該選項!");
                        break;
                }
        }
        #endregion
 
        //輸入0,返回
        #region  輸入0,返回
        public void FanHui() {
            do {
                Console.WriteLine("輸入0,返回:");
                string Ling = Console.ReadLine();
                if (Ling.Equals("0")) {
                    CaiDan();
                }
            } while (true);
        }
        #endregion
 
        //新增DVD
        #region  新增DVD
        public void XinZeng() {
            bool flag = true;
            Console.WriteLine("此處實現新增DVD----->");
            Console.WriteLine("請輸入DVD名稱:");
            string dvdName = Console.ReadLine();
            for (int i=0; i< xinxi.Length; i++) {
                if (xinxi[i] == null) {
                    flag = false;
                    xinxi[i] = new XinXi();
                    xinxi[i].Name = dvdName;
                    xinxi[i].State = 1;
                    xinxi[i].Date = "";
                    Console.WriteLine("名稱為{0}的DVD添加成功!", xinxi[i].Name);
                    break;
                }
            }
            if (flag) {
                Console.WriteLine("對不起,存儲空間已滿");
            }
            FanHui();//返回
        }
        #endregion
 
        //查詢DVD
        #region  查詢DVD
        public void ChaXun() {
            Console.WriteLine("此處實現查詢DVD----->");
            Console.WriteLine("{0,-8}{1,-10}{2,-8}", "名稱","狀態(tài)","時間");
            string zhuangTai = String.Empty;
            foreach (XinXi item in xinxi)
            {
                if (item != null)
                {
                    if (item.State == 0) {
                        zhuangTai = "以借出";
                    } else if (item.State == 1) {
                        zhuangTai = "未借出";
                    }
                    Console.WriteLine("{0,-8}{1,-10}{2,-8}",item.Name, zhuangTai, item.Date);
                }
            }
            FanHui();//返回
        }
        #endregion
 
        //判斷對應下標
        #region  判斷對應下標
        public XinXi Duan(string dvdName) {
            foreach (XinXi item in xinxi) {
                if (item != null && item.Name.Equals(dvdName)) {
                    return item;
                }
            }
            return null;
        }
        #endregion
 
        //刪除DVD
        #region  刪除DVD
        public void ShanChu() {
            Console.WriteLine("此處實現刪除DVD----->");
            Console.WriteLine("請輸入DVD名稱:");
            string dvdName = Console.ReadLine();
            XinXi renWu = Duan(dvdName);
            if (renWu == null) {
                Console.WriteLine("對不起,沒有該DVD");
                return;
            }
            for (int i=0; i< xinxi.Length; i++) {
                if (renWu == xinxi[i] && xinxi[i].State == 1) {
                    for (int j = i; j < xinxi.Length-1; j++) {
                        xinxi[j] = xinxi[j + 1];
                    }
                    int nu = xinxi.Length - 1;
                    xinxi[nu] = null;
                    Console.WriteLine("訂單刪除成功!");
                    break;
                } else if (renWu == xinxi[i] && xinxi[i].State == 0) {
                    Console.WriteLine("對不起,訂單為以借出狀態(tài)不能刪除!");
                    break;
                }
            }
            FanHui();//返回
        }
        #endregion
 
        //借出DVD
        #region  借出DVD
        public void JieChu() {
            Console.WriteLine("此處實現借出DVD----->");
            Console.WriteLine("請輸入DVD名稱:");
            string dvdName = Console.ReadLine();
            XinXi renWu = Duan(dvdName);
            if (renWu == null)
            {
                Console.WriteLine("對不起,沒有該DVD");
                FanHui();//返回
            }
            if (renWu.State == 0) {
                Console.WriteLine("對不起,該DVD以被人搶先借走了!");
                FanHui();//返回
            }
            Console.WriteLine("請輸入借出日期(年-月-日):");
            string riQi = Console.ReadLine();
            bool flag = Money(riQi);
            if (!flag)
            {
                Console.WriteLine("對不起,您輸入的日期不正確!");
                FanHui();//返回
            }
            else {
                renWu.State = 0;
                renWu.Date = riQi;
                Console.WriteLine("借出DVD成功!");
            }
            FanHui();//返回
        }
        #endregion
 
        //判斷借出日期格式
        #region  判斷借出日期格式
        public bool Money(string riQi)
        {
            string monval = @"^\d{4}-\d{1,2}-\d{1,2}$";
            return Regex.IsMatch(riQi, monval);
        }
        #endregion
 
        //歸還DVD
        #region  歸還DVD
        public void GuiHuan() {
            Console.WriteLine("此處實現歸還DVD----->");
            Console.WriteLine("請輸入DVD名稱:");
            string dvdName = Console.ReadLine();
            XinXi renWu = Duan(dvdName);
            if (renWu == null)
            {
                Console.WriteLine("對不起,沒有該DVD");
                FanHui();//返回
            }
            if (renWu.State == 1)
            {
                Console.WriteLine("對不起,該DVD還沒有借出不可歸還!");
                FanHui();//返回
            }
            Console.WriteLine("請輸入歸還日期(年-月-日):");
            string riQi = Console.ReadLine();
            bool flag = Money(riQi);
            if (!flag)
            {
                Console.WriteLine("對不起,您輸入的日期不正確!");
                FanHui();//返回
            }
            else
            {
                string jieChu = renWu.Date;
                if (String.Compare(jieChu, riQi) < 0)
                {
                    //字符串轉換為日期格式
                    DateTime dat1 = Convert.ToDateTime(jieChu);//借出
                    DateTime dat2 = Convert.ToDateTime(riQi);//日期
                    TimeSpan span = dat2.Subtract(dat1);
 
                    //求借出與歸還之間的差值
                    int cha = span.Days + 1;
 
                    renWu.State = 1;
                    renWu.Date = "";
                    Console.WriteLine("\n歸還《{0}》成功!", renWu.Name);
                    Console.WriteLine("借出日期為:{0}", dat1);
                    Console.WriteLine("歸還日期為:{0}", dat2);
                    Console.WriteLine("應付租金為:{0}",cha);
                }
                else {
                    Console.WriteLine("對不起,歸還日期不能小于借出日期!");
                    FanHui();//返回
                }
            }
            FanHui();//返回
        }
        #endregion
    }

代碼展示完畢!

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • C#基礎:基于const與readonly的深入研究

    C#基礎:基于const與readonly的深入研究

    本篇文章是對c#中const與readonly進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • C# 中使用 Exceptionless的方法

    C# 中使用 Exceptionless的方法

    這篇文章主要介紹了C# 中使用 Exceptionless的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • C#使用控制臺列出當前所有可用的打印機列表

    C#使用控制臺列出當前所有可用的打印機列表

    這篇文章主要介紹了C#使用控制臺列出當前所有可用的打印機列表,涉及C#操作計算機硬件的相關使用技巧,非常具有實用價值,需要的朋友可以參考下
    2015-04-04
  • C#使用正則表達式實現漢字轉拼音

    C#使用正則表達式實現漢字轉拼音

    這篇文章主要為大家詳細介紹了C#如何使用正則表達式實現漢字轉拼音的功能,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-01-01
  • C#中子類調用父類的實現方法

    C#中子類調用父類的實現方法

    這篇文章主要介紹了C#中子類調用父類的實現方法,通過實例逐步分析了類中初始化構造函數的執(zhí)行順序問題,有助于加深對C#面向對象程序設計的理解,需要的朋友可以參考下
    2014-09-09
  • C#多線程之線程池(ThreadPool)

    C#多線程之線程池(ThreadPool)

    這篇文章介紹了C#多線程之線程池(ThreadPool)的用法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • c#基礎學習之封裝

    c#基礎學習之封裝

    說到封裝,其實是比較基礎類的問題,它為程序設計提供了系統(tǒng)與系統(tǒng),模塊與模塊,類與類之間交互的實現手段
    2013-09-09
  • C#中調用DLL時未能加載文件或程序集錯誤的處理方法(詳解)

    C#中調用DLL時未能加載文件或程序集錯誤的處理方法(詳解)

    下面小編就為大家?guī)硪黄狢#中調用DLL時未能加載文件或程序集錯誤的處理方法(詳解)。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • 基于C#實現XML文件讀取工具類

    基于C#實現XML文件讀取工具類

    這篇文章主要介紹了基于C#實現XML文件讀取工具類,涉及C#針對XML文件各節(jié)點獲取的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • C#實現移除字符串末尾指定字符的方法

    C#實現移除字符串末尾指定字符的方法

    這篇文章主要介紹了C#實現移除字符串末尾指定字符的方法,十分常見且重要的一個應用技巧,需要的朋友可以參考下
    2014-08-08

最新評論

巴彦淖尔市| 曲阳县| 图们市| 星座| 永春县| 渝中区| 门源| 尉犁县| 修水县| 丹东市| 内黄县| 营口市| 桐梓县| 上蔡县| 峡江县| 淮北市| 杭锦后旗| 灌阳县| 嘉定区| 苏尼特左旗| 扶沟县| 象山县| 朔州市| 张家口市| 大足县| 合水县| 年辖:市辖区| 庄河市| 贡山| 芜湖县| 商洛市| 龙川县| 静海县| 大同县| 新巴尔虎左旗| 平阴县| 饶河县| 玉环县| 咸丰县| 德令哈市| 禄丰县|