Exemplo n.º 1
0
        private void PatronToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryPatron> patrons; // List of patrons

            patrons = _lib.GetPatronsList();

            if ((patrons.Count() == 0))
            {
                MessageBox.Show("Must have a patron to edit!");
            }
            else
            {
                PatronSelectionForm patronSelectionForm = new PatronSelectionForm(patrons);
                DialogResult        result = patronSelectionForm.ShowDialog(); // Show form as dialog and store result

                if (result == DialogResult.OK)
                {
                    LibraryPatron p  = _lib._patrons[patronSelectionForm.PatronIndex];
                    PatronForm    pf = new PatronForm();
                    pf.PatronName = p.PatronName;
                    pf.PatronID   = p.PatronID;

                    DialogResult result1 = pf.ShowDialog();

                    if (result1 == DialogResult.OK)
                    {
                        p.PatronName = pf.PatronName;
                        p.PatronID   = pf.PatronID;
                    }
                }
                patronSelectionForm.Dispose();
            }
        }
Exemplo n.º 2
0
        // Precondition: clicked on edit patron on menu
        // Postcondition: dialog box will appear to choose patron that is going to be edited
        //                user will make selection, then patron form will appear that is populated
        //                with patron data that is to be edited
        private void patronToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            PatronSelectionForm editPatronForm = new PatronSelectionForm(_lib.GetPatronsList()); // form to choose patron
            DialogResult        result         = editPatronForm.ShowDialog();                    // result from patron selection form
            int patronIndex;                                                                     // selected patron index

            if (result == DialogResult.OK)                                                       // did they click ok?
            {
                patronIndex = editPatronForm.SelectedPatronIndex;
                LibraryPatron patron     = _lib._patrons[patronIndex]; // selected library patron
                PatronForm    patronForm = new PatronForm();           // patron form to edit data with

                // passing object data to form
                patronForm.PatronID   = patron.PatronID;
                patronForm.PatronName = patron.PatronName;

                DialogResult result2 = patronForm.ShowDialog(); // patron form with data loaded into it
                if (result2 == DialogResult.OK)                 // did they click ok?
                {
                    // get edited data from form and update object data
                    patron.PatronID   = patronForm.PatronID;
                    patron.PatronName = patronForm.PatronName;
                }
            }
        }