示例#1
0
        // Precondition:  PatronEdit, Edit menu item activated
        // Postcondition: The PatronEdit dialog box is displayed. If data entered
        //                are OK, file is opened
        private void patronToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryPatron> patrons; //list of patrons

            patrons = _lib.GetPatronsList();

            if (patrons.Count == 0)
            {
                MessageBox.Show("Must select a patron!");
            }
            else
            {
                PatronEdit   pEdit  = new PatronEdit(patrons);
                DialogResult result = pEdit.ShowDialog(); // Displays form as dialogbox

                if (result == DialogResult.OK)            //Only allows selection if ok
                {
                    LibraryPatron libraryPatron = patrons[pEdit.PatronIndex];
                    PatronForm    patronEditor  = new PatronForm();          //seperate form but same format from patron form
                    DialogResult  edited        = patronEditor.ShowDialog(); //Opens the patron form to edit
                    if (edited == DialogResult.OK)                           //If Ok only
                    {
                        libraryPatron.PatronName = patronEditor.PatronName;
                        libraryPatron.PatronID   = patronEditor.PatronID;
                    }
                    patronEditor.Dispose();
                }
            }
        }
示例#2
0
        private void patronToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List<LibraryPatron> patrons = new List<LibraryPatron>(); // list to hold patrons

            patrons = lib.GetPatronsList(); //get list of current patrons

            PatronEdit patronEditForm = new PatronEdit(patrons); // The patron dialog box form

            DialogResult result = patronEditForm.ShowDialog(); // Show form as dialog and store result

            if (result == DialogResult.OK) // Only add if OK
            {
                //hold patron selected to edit
                LibraryPatron selectedPatron = lib._patrons[patronEditForm.ItemIndex];

                PatronForm pform = new PatronForm(); //patron form to load current patron data into

                pform.PatronName = selectedPatron.PatronName;   //current patron name
                pform.PatronID = selectedPatron.PatronID;       //current patron ID

                result = pform.ShowDialog(); //show to the patron dialog with the current data

                if (result == DialogResult.OK) //only add if OK
                {
                    selectedPatron.PatronName = pform.PatronName;   //set new patron name
                    selectedPatron.PatronID = pform.PatronID;       //set new patron ID
                }
            }
        }