Realization of Personnel Management System (3)

As the carrier of communication with users, the main form has been preliminarily designed. When we press a function button, we can get a form with corresponding functions. We call these forms as sub-forms for the time being.

10 sub-forms are designed to implement the corresponding functions. The 10 sub-forms are placed in the PerForm folder. The names of the 10 forms are F_AddressList, F_ClearData, F_Find, F_HaveBack, F_ManFile, F_Stat, F_User, F_UserAdd, F_UserPope, F_WordPad. Address query, data clearance and personnel query are implemented respectively. data base Restore, recognize browsing, personnel statistics, user information, add users, user rights settings and notepad functions.

In this section, firstly, we design F_AddressList to query according to query conditions and query types, and find the desired data. The relevant knowledge of SQL query will be used. If you can supplement the relevant knowledge, it will be very helpful for understanding.

The design interface is as follows:

                     

                      

Grid'View control is used to display the inquired data in the form, a ComBox control is used to provide the user with the choice of the inquiry type, a TextBox control is used to receive the inquiry conditions, and four Button buttons are designed to realize the functions of adding, modifying, deleting and exiting.

When the interface is designed, various functions are implemented:

1. Define two instantiated objects, MyClass and MyModule

[csharp] view plain copy

  1. DataClass.MyMeans MyDataClass = new DataClass.MyMeans();  
  2. ModuleClass.MyModule MyMC = new ModuleClass.MyModule();  

Declare a DataSet "data container" for querying results through the SqlDataReader class

  1. public static DataSet MyDS_Grid;  

// Query to get all the items in tb_AddressBook table to add information.

  1. public static string AllSql = "Select ID,Name as Full name, Sex as Gender , Phone as Telephone,WordPhone as Work phone,Handset as Mobile phone, QQ as QQ Number,E_Mail as E-mail address from tb_AddressBook";  

// Find_Field--> stores query fields corresponding to TextBox controls

  1. public static string Find_Field = "";  

  2. When a form is generated, it needs to call the LOAD event of the form to complete the corresponding work. It needs to call a showAll () method. The invocation and design of this method are as follows:
  1. public void ShowAll()  
  2. {  
  3.     ModuleClass.MyModule.Address_ID = "";  
  4.     //Explicit Employee Name with dataGridView Control  
  5.     MyDS_Grid = MyDataClass.GetDataSet(AllSql, "tb_AddressBook");  
  6.     //Set the data source of the control, data source  
  7.     dataGridView1.DataSource = MyDS_Grid.Tables[0];  
  8.     //Set the first column invisible  
  9.     dataGridView1.Columns[0].Visible = false;  
  10.   
  11.   
  12.     //Controlling Button's usability based on query results  
  13.     if (dataGridView1.RowCount > 1)  
  14.     {  
  15.         Address_Amend.Enabled = true;  
  16.         Address_Delete.Enabled = false;  
  17.   
  18.   
  19.     }  
  20.     else  
  21.     {  
  22.         Address_Amend.Enabled = false;  
  23.         Address_Delete.Enabled = false;  
  24.   
  25.   
  26.     }  
  27. }  

The showAll () method is called in the load event:

  1. private void F_AddressList_Load(object sender, EventArgs e)  
  2. {  
  3.     ShowAll();  
  4. }  

3. When the query button is clicked, the query operation is needed to complete the function by implementing Button's Click event.

  1. private void button5_Click(object sender, EventArgs e)  
  2. {  
  3.     //Determine whether the query condition is empty  
  4.     if (textBox1.Text == "")  
  5.     {  
  6.         MessageBox.Show("Please enter the query conditions.");  
  7.         return;  
  8.     }  
  9.     ModuleClass.MyModule.Address_ID = "";  
  10.     //Use datagridview to display the employee's name  
  11.     MyDS_Grid = MyDataClass.GetDataSet(AllSql + " where " + Find_Field + " like '%" + textBox1.Text.Trim() + "%'""tb_AddressBook");  
  12.     dataGridView1.DataSource = MyDS_Grid.Tables[0];  
  13.     dataGridView1.Columns[0].Visible = false;  
  14.     //When the query result exists  
  15.     if (dataGridView1.RowCount > 1)  
  16.     {  
  17.         Address_Amend.Enabled = true;  
  18.         Address_Delete.Enabled = true;  
  19.     }  
  20.     else  
  21.     {  
  22.         Address_Amend.Enabled = false;  
  23.         Address_Delete.Enabled = false;  
  24.   
  25.   
  26.     }  
  27. }  

4. The implementation code of query condition selection in ComBox control is as follows:

  1. private void comboBox1_TextChanged(object sender, EventArgs e)  
  2. {  
  3.     //ComBox controls that set query type conditions to implement queries according to conditions  
  4.     switch (((ComboBox)sender).SelectedIndex)  
  5.     {  
  6.         case 0:  
  7.             {  
  8.                 Find_Field = "Name";  
  9.                 break;  
  10.             }  
  11.         case 1:  
  12.             {  
  13.                 Find_Field = "Sex";  
  14.                 break;  
  15.   
  16.             }  
  17.         case 2:  
  18.             {  
  19.                 Find_Field = "E_Mail";  
  20.                 break;  
  21.             }  
  22.     }  
  23. }  

5. When all buttons are clicked, the corresponding code for the Click event is:

  1. private void button1_Click(object sender, EventArgs e)  
  2. {  
  3.     ShowAll();  
  4. }  


6. When we need to add data to this table, we need to click the "Add Button", which is the code for the triggered Click event.

  1. private void Address_Add_Click(object sender, EventArgs e)  
  2. {  
  3.     //At this point, another form needs to be invoked, which will be detailed in a later article.  
  4.     InfoAddForm.F_Address FrmAddress = new InfoAddForm.F_Address();  
  5.     FrmAddress.Text = "Address Book addition operation";  
  6.     FrmAddress.Tag = 1;  
  7.     FrmAddress.ShowDialog(this);  
  8.     ShowAll();  
  9. }  

7. When clicking the modification button, the existing data can be modified, which is also realized by clicking the button to trigger the Click event of the button:

  1. private void Address_Amend_Click(object sender, EventArgs e)  
  2. {  
  3.     //Call F_Address form to modify address book information, the same form, different ways of using  
  4.     InfoAddForm.F_Address FrmAddress = new InfoAddForm.F_Address();  
  5.     FrmAddress.Text = "Address Book Modification Operation";  
  6.     FrmAddress.Tag = 2;  
  7.     FrmAddress.ShowDialog(this);  
  8.     ShowAll();  
  9. }  


8. When the delete button is clicked, the existing data is deleted. The Click event implementation code is as follows:

  1. private void Address_Delete_Click(object sender, EventArgs e)  
  2. {  
  3.     if (MessageBox.Show("Are you sure you want to delete this information?""Tips", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)  
  4.     {  
  5.         MyDataClass.GetA_M_D_command("Delete tb_AddressBook where ID='" + ModuleClass.MyModule.Address_ID + "'");  
  6.         ShowAll();  
  7.     }  
  8. }  

When you click to exit, you need to add this.Clsoe(); that's all.

9. However, what really shows us the results of the query is the GridView control, which implements its cell enter event here:

  1. private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)  
  2. {  
  3.     if (dataGridView1.RowCount > 1)  
  4.     {  
  5.         ModuleClass.MyModule.Address_ID = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString();  
  6.         Address_Amend.Enabled = true;  
  7.         Address_Delete.Enabled = true;  
  8.     }  
  9.     else  
  10.     {  
  11.         Address_Amend.Enabled = false;  
  12.         Address_Delete.Enabled = false;  
  13.     }  
  14. }  

At this point, the form design is basically completed, and the F_ClearData form will be designed in the next section.

Tags: DNS MySQL SQL Mobile

Posted on Sun, 24 Mar 2019 08:09:30 -0400 by soccerstar_23