Example #1
0
        /*
         *   When the "Add Doctor" button is clicked,
         *   then dispose of the search form and create and show the form for an individual doctor (with fields blank)
         */
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            this.Dispose();                                 // get rid of search form
            frmDoctor newDoctor = new frmDoctor(null);      // create an empty doctor form

            newDoctor.Show();                               // display the new (empty) doctor form
        }
Example #2
0
        /*
         *  When the View/Edit button is clicked,
         *  then dispose of the search form and display the form for an individual doctor of
         *  the row selected in the datagrid
         */
        private void btnEdit_Click(object sender, EventArgs e)
        {
            int     doctorID;
            int     currentRow;
            DataRow dRow;                                                           // row of a table in the dataset

            try
            {
                currentRow = this.dataGridView1.CurrentRow.Index;                   // detect the currently selected row
                doctorID   = (int)this.dataGridView1.CurrentRow.Cells[0].Value;     // get the doctorID of the current selected row
                dRow       = dataSet1.Tables[0].Rows[currentRow];                   //  get the row of the table (in dataset) that is selected
            } catch (Exception e1)                                                  // if any problem,
            {                                                                       // display an error message and exit method
                MessageBox.Show("Unable to edit.\n\nYou must first select a single row from the grid of doctors.", "No doctor selected");
                return;
            }
            Doctor editDoc = new Doctor();                                          // new Doctor object for the selected doctor

            editDoc.DocId       = doctorID;                                         // populate the doctor ID
            editDoc.DocSurname  = dRow.ItemArray.GetValue(2).ToString();            // populate the other fields of Doctor object from the
            editDoc.DocForename = dRow.ItemArray.GetValue(1).ToString();            //    Row of the table in the dataset
            Object objPhoto = dRow.ItemArray.GetValue(3);

            if (objPhoto.Equals(System.DBNull.Value))           // cannot cast null to a byte array
            {
                editDoc.DocPhoto = null;
            }
            else
            {
                editDoc.DocPhoto = (byte[])objPhoto;
            }
            editDoc.DocGender        = (bool)dRow.ItemArray.GetValue(4);
            editDoc.DocAddress       = dRow.ItemArray.GetValue(5).ToString();
            editDoc.DocPhoneNumber   = dRow.ItemArray.GetValue(6).ToString();
            editDoc.DocQualification = dRow.ItemArray.GetValue(7).ToString();
            editDoc.DeptId           = (int)dRow.ItemArray.GetValue(8);
            this.Dispose();                                                         // dispose the search form
            frmDoctor editDoctor = new frmDoctor(editDoc);                          // create doctor form from the editDoctor object

            editDoctor.Show();                                                      // display the doctor object
        }