コード例 #1
0
        private void Button_RefreshMagazine_Click(object sender, EventArgs e)
        {
            if (_dal == null)
            {
                return;
            }
            if ((sender == null && e == null) || (textBox_Name.Text.Trim() == String.Empty && textBox_Publisher.Text.Trim() == String.Empty &&
                                                  textBox_IssueNumber.Text.Trim() == String.Empty))
            {
                _magazines = _dal.GetAllMagazines();
                if (_magazines == null || _magazines.Count == 0)
                {
                    dataGridView_Magazines.DataSource = null;
                    return;
                }

                dataGridView_Magazines.DataSource = _magazines;
                var dataGridViewColumn = dataGridView_Magazines.Columns["ItemFields"];
                if (dataGridViewColumn != null)
                {
                    dataGridViewColumn.Visible = false;
                }
                var gridViewColumn = dataGridView_Magazines.Columns["MagazineFields"];
                if (gridViewColumn != null)
                {
                    gridViewColumn.Visible = false;
                }
                return;
            }

            var searchedMagazine = new Magazine(textBox_Name.Text.Trim(), textBox_Publisher.Text.Trim(),
                                                String.Empty, textBox_IssueNumber.Text.Trim());

            _magazines = _dal.SearchedMagazines(searchedMagazine);
            if (_magazines == null)
            {
                dataGridView_Magazines.DataSource = null;
            }
            else
            {
                dataGridView_Magazines.DataSource = _magazines;
                var dataGridViewColumn = dataGridView_Magazines.Columns["ItemFields"];
                if (dataGridViewColumn != null)
                {
                    dataGridViewColumn.Visible = false;
                }
                var gridViewColumn = dataGridView_Magazines.Columns["MagazineFields"];
                if (gridViewColumn != null)
                {
                    gridViewColumn.Visible = false;
                }
            }
        }
コード例 #2
0
        public void CreateItem(string parameter, out bool success)
        {
            if (string.IsNullOrEmpty(parameter))
            {
                success = false; return;
            }

            CommandParametersSplit(parameter, out var textFileType, out var parameters);

            var parametersDictionary = SplitCommand(parameters);

            if (parametersDictionary == null)
            {
                success = false;
                return;
            }

            switch (textFileType.ToLower())
            {
            case "-b":
            {
                var book = new Book();
                book.FillFields(parametersDictionary, out var fillFieldsWarning);

                if (string.IsNullOrEmpty(fillFieldsWarning))
                {
                    FilesList.Add(book);
                    Console.WriteLine("Книга добавлена");
                    success = true;
                    return;
                }

                Console.WriteLine(fillFieldsWarning);
                success = false;
                break;
            }

            case "-m":
            {
                var magazine = new Magazine();
                magazine.FillFields(parametersDictionary, out var fillFieldsWarning);
                if (string.IsNullOrEmpty(fillFieldsWarning))
                {
                    FilesList.Add(magazine);
                    Console.WriteLine("Журнал добавлен");
                    success = true;
                    return;
                }

                Console.WriteLine(fillFieldsWarning);
                success = false;
                break;
            }

            default:
            {
                success = false;
                break;
            }
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //set the rental dates for each type via a static field
            //implement

            //create a list a propulate it with the date in our file
            FileIO getFile = new FileIO();

            //populate mediaToRent with the values returned from getFile instead of an empty list e.g. "new List<string>();"
            //implement
            List <string> mediaToRent = getFile.ReturnMediaFile(@"..\..\media.txt"); // @"..\..\name.txt"

            //create a new list for us to use to store our media objects to rent
            List <Media> rentedMedia = new List <Media>();

            //for each line from the rental
            foreach (string s in mediaToRent)
            {
                //match each needed component
                //populae with your regex to match the format

                Match match = Regex.Match(s, @"^Type:\s*(.*),Title:\s*(.*),Length:\s*([\w ]*)$", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    //populate each component with the values from your capture groups
                    string type   = match.Groups[1].ToString();
                    string title  = match.Groups[2].ToString();
                    string length = match.Groups[3].ToString();

                    //using the components we got figure out which type of object we should create and insert
                    if (type.Equals("Book"))
                    {
                        //create a book object
                        Book newBook = new Book();
                        //populate the book object with a title and length
                        newBook.Title  = title;
                        newBook.Length = length;
                        //then add the newly created book to rentedMedia
                        rentedMedia.Add(newBook);
                    }
                    //complete for the DVD and Magazine media types
                    //implement
                    else if (type.Equals("DVD"))
                    {
                        DVD newDvd = new DVD();
                        newDvd.Title  = title;
                        newDvd.Length = length;
                        rentedMedia.Add(newDvd);
                    }
                    else if (type.Equals("Magazine"))
                    {
                        Magazine newMagazine = new Magazine();
                        newMagazine.Title  = title;
                        newMagazine.Length = length;
                        rentedMedia.Add(newMagazine);
                    }
                    else
                    {
                        Console.WriteLine("Not a valid Type");
                    }
                }
            }

            //for each media item we have in the list print the details for each
            foreach (Media mediaItem in rentedMedia)
            {
                //for each mediaItem call PrintMediaDetails()
                //implement
                mediaItem.PrintMediaDetails();
                Console.WriteLine();
            }

            //halt the program so we can read the output
            Console.ReadKey();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            //set the rental dates for each type via a static field
            //implement

            //create a list a propulate it with the date in our file
            FileIO getFile = new FileIO();

            //populate mediaToRent with the values returned from getFile instead of an empty list e.g. "new List<string>();"
            //implement

            List <string> mediaToRent = getFile.ReturnMediaFile(@"..\..\Media.txt");

            //create a new list for us to use to store our media objects to rent
            List <Media> rentedMedia = new List <Media>();

            //for each line from the rental
            foreach (string s in mediaToRent)
            {
                //match each needed component
                //populae with your regex to match the format

                Match match = Regex.Match(s, @"Type\:\s*(.*),Title\:\s*(.*),Length\:\s*(.*)");
                if (match.Success)
                {
                    //populate each component with the values from your capture groups
                    string type   = match.Groups[1].ToString();
                    string title  = match.Groups[2].ToString();
                    string length = match.Groups[3].ToString();

                    //using the components we got figure out which type of object we should create and insert
                    if (type.Equals("Book"))
                    {
                        //create a book object
                        Book newBook = new Book();
                        //populate the book object with a title and length
                        newBook.Title  = title;
                        newBook.Length = length;
                        rentedMedia.Add(newBook);
                    }

                    if (type.Equals("DVD"))
                    {
                        DVD newDVD = new DVD();

                        newDVD.Title  = title;
                        newDVD.Length = length;
                        rentedMedia.Add(newDVD);
                    }

                    if (type.Equals("Magazine"))
                    {
                        Magazine newMagazine = new Magazine();

                        newMagazine.Title  = title;
                        newMagazine.Length = length;
                        rentedMedia.Add(newMagazine);
                    }
                }
            }

            //for each media item we have in the list print the details for each
            foreach (Media mediaItem in rentedMedia)
            {
                mediaItem.PrintMediaDetails();
            }

            // output the rented list to a file
            // get number of newMedia items
            int numberOfItems = rentedMedia.Count;

            // initialize the array according to the number of items
            String[] allRecords = new string[numberOfItems];

            // for each item in the newMedia object put the information
            // in the array
            int i = 0;

            foreach (Media eachMedia in rentedMedia)
            {
                allRecords[i] = rentedMedia.ToString();
                i++;
            }
            getFile.UpdateMediaFile(allRecords);

            //halt the program so we can read the output
            Console.ReadKey();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //set the rental dates for each type via a static field
            //implement

            //create a list a propulate it with the date in our file
            FileIO getFile = new FileIO();

            //populate mediaToRent with the values returned from getFile instead of an empty list e.g. "new List<string>();"
            //implement
            //List<string> mediaToRent = new List<string>();

            List <string> mediaToRent = getFile.ReturnMediaFile(@"..\..\Media.txt");

            //create a new list for us to use to store our media objects to rent
            List <Media> rentedMedia = new List <Media>();

            //for each line from the rental
            foreach (string s in mediaToRent) //each string in the list of strings from the media file
            {
                //match each needed component
                //populae with your regex to match the format

                Match match = Regex.Match(s, @"^Type:\s*(.*),Title:\s*(.*),Length:\s*([\w ]*)$");
                if (match.Success)
                {
                    //populate each component with the values from your capture groups
                    string type   = match.Groups[1].ToString();
                    string title  = match.Groups[2].ToString();
                    string length = match.Groups[3].ToString();

                    //using the components we got figure out which type of object we should create and insert
                    if (type.Equals("Book"))
                    {
                        //create a book object
                        //populate the book object with a title and length
                        //then add the newly created book to rentedMedia

                        Book booksMedia = new Book(title, length); //Could put in the parenthesis if you create a constructor

                        //OR YOU CAN DO IT THIS WAY:
                        booksMedia.Title  = title; //Populating book object with title and length
                        booksMedia.Length = length;
                        rentedMedia.Add(booksMedia);
                    }
                    //complete for the DVD and Magazine media types
                    //implement
                    else if (type.Equals("DVD"))
                    {
                        DVD dvdMedia = new DVD(title, length);
                        rentedMedia.Add(dvdMedia);
                    }
                    else if (type.Equals("Magazine"))
                    {
                        Magazine magMedia = new Magazine("Cosmo", "100 pages");
                        rentedMedia.Add(magMedia);
                    }
                }
            }

            //for each media item we have in the list print the details for each
            foreach (Media mediaItem in rentedMedia)
            {
                //for each mediaItem call PrintMediaDetails()
                //implement
                mediaItem.PrintMediaDetails();
            }

            //halt the program so we can read the output
            Console.ReadKey();
        }