SoFunction
Updated on 2025-03-09

C# implements DVD lending and return management system

A DVD manager written in C# for your reference. The specific content is as follows

(Don't criticize me, beginners mainly use reference)

It is divided into three categories: DVD (start class), XinXi (information class), and GongNeng (function class)

The code part (as follows):

DVD (start class):

class DVD
    {
        static void Main(string[] args)
        {
            GongNeng gongNeng = new GongNeng();
            ();  //initialization            ();  //Travel the initialization information            ();  //Options menu        }
    }

XinXi (information class):

class XinXi
    {
        private string _name;//name        private int state;//Lend status        private string date;//time 
        //Attribute encapsulation        public string Name { get => _name; set => _name = value; }//name        public int State { get => state; set => state = value; }//Lend status        public string Date { get => date; set => date = value; }//time    }

GongNeng (functional class):

Because the function class uses regular expressions to judge the date format, the header needs to be added:

using ;     // RegularExpressions is a regular expression, Text is text

class GongNeng
    {
        XinXi[] xinxi = new XinXi[10];//Object array stores data        //Initialization information        #region Initialization Information        public void initial() {
            xinxi[0] = new XinXi();
            xinxi[0].Name = "Roman Holiday";
            xinxi[0].State = 0;
            xinxi[0].Date = "2010-7-1";
 
            xinxi[1] = new XinXi();
            xinxi[1].Name = "The wind and the cranes";
            xinxi[1].State = 1;
            xinxi[1].Date = "";
 
            xinxi[2] = new XinXi();
            xinxi[2].Name = "Full House";
            xinxi[2].State = 1;
            xinxi[2].Date = "";
        }
        #endregion
 
        //Show initialization information        #region Display initialization information        public void XianShi() {
            ("****** Initialization information is as follows: **********");
            foreach (XinXi item in xinxi) {
                if (item != null) {
                    (+"\t"++"\t"+);
                }
            }
            ("********************************");
        }
        #endregion
 
        //DVD menu        #region DVD Menu        public void CaiDan()
        {
                ("------------------------------------------------------------------------------------------------------------------------------);
                ("1. Add DVD\n2. View DVD\n3. Delete DVD\n4. Lend DVD\n5. Return DVD\n6. Exit");
                ("-------------------------------------------------");
                ("Please enter your selection:");
                int xuanZe = (());
                switch (xuanZe)
                {
                    case 1:
                    //Added DVD                        XinZeng();
                        break;
                    case 2:
                    //View DVD                        ChaXun();
                        break;
                    case 3:
                    //Delete DVD                        ShanChu();
                        break;
                    case 4:
                    //Lend DVD                        JieChu();
                        break;
                    case 5:
                    //Return DVD                        GuiHuan();
                        break;
                    case 6:
                        //quit                        ("Welcome next time!");
                        break;
                    default:
                        //No option                        ("Sorry, there is no option!");
                        break;
                }
        }
        #endregion
 
        //Enter 0 and return        #region Enter 0, return        public void FanHui() {
            do {
                ("Enter 0, return:");
                string Ling = ();
                if (("0")) {
                    CaiDan();
                }
            } while (true);
        }
        #endregion
 
        //Added DVD        #region Added DVD        public void XinZeng() {
            bool flag = true;
            ("Added new DVD here----->");
            ("Please enter the DVD name:");
            string dvdName = ();
            for (int i=0; i< ; i++) {
                if (xinxi[i] == null) {
                    flag = false;
                    xinxi[i] = new XinXi();
                    xinxi[i].Name = dvdName;
                    xinxi[i].State = 1;
                    xinxi[i].Date = "";
                    ("Name is{0}ofDVDAdded successfully!", xinxi[i].Name);
                    break;
                }
            }
            if (flag) {
                ("Sorry, the storage space is full");
            }
            FanHui();//return        }
        #endregion
 
        //Query DVD        #region query DVD        public void ChaXun() {
            ("Implement query DVD here----->");
            ("{0,-8}{1,-10}{2,-8}", "name","state","time");
            string zhuangTai = ;
            foreach (XinXi item in xinxi)
            {
                if (item != null)
                {
                    if ( == 0) {
                        zhuangTai = "By Lending";
                    } else if ( == 1) {
                        zhuangTai = "Not Lending";
                    }
                    ("{0,-8}{1,-10}{2,-8}",, zhuangTai, );
                }
            }
            FanHui();//return        }
        #endregion
 
        //Judge the corresponding subscript        #region judges the corresponding subscript        public XinXi Duan(string dvdName) {
            foreach (XinXi item in xinxi) {
                if (item != null && (dvdName)) {
                    return item;
                }
            }
            return null;
        }
        #endregion
 
        //Delete DVD        #region Delete DVD        public void ShanChu() {
            ("Implementation of delete DVD here----->");
            ("Please enter the DVD name:");
            string dvdName = ();
            XinXi renWu = Duan(dvdName);
            if (renWu == null) {
                ("Sorry, there is no DVD");
                return;
            }
            for (int i=0; i< ; i++) {
                if (renWu == xinxi[i] && xinxi[i].State == 1) {
                    for (int j = i; j < -1; j++) {
                        xinxi[j] = xinxi[j + 1];
                    }
                    int nu =  - 1;
                    xinxi[nu] = null;
                    ("Order deleted successfully!");
                    break;
                } else if (renWu == xinxi[i] && xinxi[i].State == 0) {
                    ("Sorry, the order cannot be deleted in the lending status!");
                    break;
                }
            }
            FanHui();//return        }
        #endregion
 
        //Lend DVD        #region Lend DVD        public void JieChu() {
            ("Implement the lent DVD here----->");
            ("Please enter the DVD name:");
            string dvdName = ();
            XinXi renWu = Duan(dvdName);
            if (renWu == null)
            {
                ("Sorry, there is no DVD");
                FanHui();//return            }
            if ( == 0) {
                ("Sorry, the DVD was borrowed first!");
                FanHui();//return            }
            ("Please enter the loan date (year-month-day):");
            string riQi = ();
            bool flag = Money(riQi);
            if (!flag)
            {
                ("Sorry, the date you entered is incorrect!");
                FanHui();//return            }
            else {
                 = 0;
                 = riQi;
                ("Lending DVD successfully!");
            }
            FanHui();//return        }
        #endregion
 
        //Judge the loan date format        #region Determine the lending date format        public bool Money(string riQi)
        {
            string monval = @"^\d{4}-\d{1,2}-\d{1,2}$";
            return (riQi, monval);
        }
        #endregion
 
        //Return DVD        #region Return DVD        public void GuiHuan() {
            ("Return DVD here----->");
            ("Please enter the DVD name:");
            string dvdName = ();
            XinXi renWu = Duan(dvdName);
            if (renWu == null)
            {
                ("Sorry, there is no DVD");
                FanHui();//return            }
            if ( == 1)
            {
                ("Sorry, this DVD has not been loaned yet and cannot be returned!");
                FanHui();//return            }
            ("Please enter the return date (year-month-day):");
            string riQi = ();
            bool flag = Money(riQi);
            if (!flag)
            {
                ("Sorry, the date you entered is incorrect!");
                FanHui();//return            }
            else
            {
                string jieChu = ;
                if ((jieChu, riQi) < 0)
                {
                    //Convert string to date format                    DateTime dat1 = (jieChu);//lend                    DateTime dat2 = (riQi);//date                    TimeSpan span = (dat1);
 
                    // Find the difference between lending and return                    int cha =  + 1;
 
                     = 1;
                     = "";
                    ("\nreturn《{0}》success!", );
                    ("The loan date is:{0}", dat1);
                    ("return日期为:{0}", dat2);
                    ("Rent payable is:{0}",cha);
                }
                else {
                    ("Sorry, the return date cannot be less than the loan date!");
                    FanHui();//return                }
            }
            FanHui();//return        }
        #endregion
    }

The code is displayed!

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.