/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { ConnectionMgr.closeConnection(); if (components != null) { components.Dispose(); } } base.Dispose(disposing); }
/************************************************************************* * The purpose of this method is to close the Oracle connection and exit * the application. * ***********************************************************************/ private void btnExit_Click(object sender, System.EventArgs e) { ConnectionMgr.closeConnection(); Application.Exit(); }
/******************************************************************************* * The purpose of this method is to establish a database connection based on the * connection parameters entered in the textboxes and then populate the datagrid * and generate XML. The "getDBConnection" method of "ConnectionMgr.cs" class is * used to establish connection. Methods from "ManageEmp.cs" class are called * to populate datagrid and generate XML. *******************************************************************************/ private void btnConnect_Click(object sender, System.EventArgs e) { if (conStatus == "N") { // Set cursor to hour glass Cursor.Current = Cursors.WaitCursor; // Establish connection String ConStatus = ConnectionMgr.getDBConnection (txtName.Text, txtPwd.Text, txtConStr.Text); // If connection is established if (ConStatus == "Connected") { // Populate empDataGrid with data DataSet empDataSet = new DataSet(); empDataSet = manageEmp.populateEmpDataGrid(); empDataGrid.SetDataBinding(empDataSet, "Emp"); // Populate empRichTextBox with generated XML empRichTextBox.Text = manageEmp.generateEmpXml(); // Populate Deptno list DataSet deptDataSet = new DataSet(); deptDataSet = manageEmp.populateDeptno(); listDeptno.DisplayMember = deptDataSet.Tables[0].Columns["Deptno"].ToString(); listDeptno.DataSource = deptDataSet.Tables["Dept"].DefaultView; listDeptno.Visible = true; // Enable UI controls empRichTextBox.Enabled = true; btnNewRec.Enabled = true; listDeptno.Enabled = true; btnUpdate.Enabled = true; delBtn.Enabled = true; // Connection status lblStatus.Text = "Connected"; lblStatus.ForeColor = Color.Green; // Set btnConnect label to disconnect btnConnect.Text = "Disconnect"; conStatus = "Y"; // Disable connection information textboxes txtName.Enabled = false; txtPwd.Enabled = false; txtConStr.Enabled = false; // Text for hintTextBox hintTextBox.Text = "To insert a new record - click on the 'Create New Record' button. " + "To update the records - modify XML data and click on the 'Update' " + "button. Empno is a key column, so do not change this. " + "View valid values for deptno from the listbox. " + "To delete record - select a record from the datagrid and " + "click on the 'Delete' button. "; // Set cursor to default Cursor.Current = Cursors.Default; } } else { // Set cursor to default Cursor.Current = Cursors.Default; // If not connected // Disable UI controls btnNewRec.Enabled = false; btnInsert.Enabled = false; delBtn.Enabled = false; listDeptno.Enabled = false; btnUpdate.Enabled = false; empRichTextBox.Enabled = false; // Enable connection information textboxes txtName.Enabled = true; txtPwd.Enabled = true; txtConStr.Enabled = true; lblStatus.Text = "Not Connected"; lblStatus.ForeColor = Color.Red; btnConnect.Text = "Connect"; // Once disconnected, clear contents of UI controls conStatus = "N"; empRichTextBox.Text = ""; empDataGrid.SetDataBinding(null, ""); listDeptno.DisplayMember = null; listDeptno.Visible = false; listDeptno.DataSource = null; // Hint message hintTextBox.Text = "Enter valid connection details to connect to an Oracle database"; } }