C# Student Management System - [Part Code 2]

1.

Another management page for students:

 After the Political Appearance Label control is the ComboBox control, click the small triangle in the upper right corner and edit the item inside

After the label age control is a NumericUpDown control that can add or subtract age

Interests and hobbies is a GroupBox control, the Text property is changed to interests and hobbies, there are 5 CheckBox controls in it, and the Text property is changed to the name of the response

Double-click the button to confirm, and write the code in it:

private void btnOk_Click(object sender, EventArgs e)
        {
            string no = txtStuNo.Text;
            string name = txtName.Text;
            string address = txtJG.Text;
            string sex;
            if (radbtnMan.Checked == true)
            {
                sex = radbtnMan.Text;
            }
            else
            {
                sex = radbtnWoman.Text;
            }
            string zhengzhi = cboZZ.Text;
            string aihao = "";
            if (cekRead.Checked== true)
            {
                aihao = cekRead.Text;
            }
            if (cekSport.Checked == true)
            {
                aihao += cekSport.Text;
            }
            if (cekTravel.Checked == true)
            {
                aihao += cekTravel.Text;
            }
            if (cekGame.Checked == true)
            {
                aihao += cekGame.Text;
            }
            if (cekAnother.Checked == true)
            {
                aihao += cekAnother.Text;
            }
            MessageBox.Show(no + name + address + sex + zhengzhi + aihao);
        
        }

The function is to prompt to fill in the information:

Click OK:

 

 Double click on exit code:

 private void btnClose_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

The page loading male is selected by default, double-click the periphery of the page, and fill in the code:

private void frmInformation_Load(object sender, EventArgs e)
        {
            radbtnMan.Checked= true;
        }

2. 

Edit class page:

Add a DataGridView data control, click the small triangle in the upper right corner to connect to the table in the database:

Double-click to update, the code inside:

 private void btnNew_Click(object sender, EventArgs e)
        {
            try
            {
                DBhelp.conn.Open();
                string sqlstr = string.Format("update tb_Class set ClassName='{0}' where ClassID='{1}'", txtClassName.Text, txtClassID.Text);
                DBhelp.comm.CommandText = sqlstr;
                DBhelp.comm.Connection = DBhelp.conn;

                if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("更新成功");

                }
                else
                {
                    MessageBox.Show("更新失败");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBhelp.conn.Close();
            }
        }

change 1 to 2 

 Double-click to delete, the code inside:

 private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DBhelp.conn.Open();
                string sqlstr = string.Format("delete from tb_Class where ClassID='{0}'", txtClassID.Text);
                DBhelp.comm.CommandText = sqlstr;
                DBhelp.comm.Connection = DBhelp.conn;

                if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("删除成功");

                }
                else
                {
                    MessageBox.Show("删除失败");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBhelp.conn.Close();
            }
        }

Double click to close, code:

private void btnClose_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

 When clicking on a data to display in the lower input box, you need to add a click event to the CellClick property of the DataGridView control, and double-click that property:

code show as below:

 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txtClassID.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
            txtClassName.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
        }

 Student information edit page:

 The 2 GroupBox group controls contain other controls. If you do not want to display the name of the group control, delete the content of the Text property.

Double plus query, the code inside:

 private void btnSelect_Click(object sender, EventArgs e)
        {
            string conn = "Data Source=.;Initial Catalog=studentInf;Integrated Security=True";
            SqlConnection a = new SqlConnection(conn);

            try
            {
                a.Open();
                string sqlstr = string.Format("select * from tb_Student where StudentID='{0}'", txtStudentNo.Text);
                SqlCommand comm = new SqlCommand();
                comm.Connection = a;
                comm.CommandText = sqlstr;

                SqlDataReader read = comm.ExecuteReader();
                if (read.Read())
                {
                    txtStudentID.Text = read[0].ToString();
                    txtStudentName.Text = read[1].ToString();
                    txtStudentGender.Text = read[2].ToString();
                    txtBirthday.Text = read[3].ToString();
                    txtClassID.Text = read[4].ToString();
                    txtMobilePhone.Text = read[5].ToString();
                    txtAddress.Text = read[6].ToString();

                }
                else
                {
                    MessageBox.Show("学号不存在!");
                }



            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                a.Close();
            }
        }

Double-click to modify, the code inside:

 private void btnAlter_Click(object sender, EventArgs e)
        {
            try
            {
                DBhelp.conn.Open();
                string sqlstr = string.Format("update tb_Student set StudentName='{0}',Birthday='{1}',ClassID='{2}',MobilePhone='{3}',Gender='{4}',Address='{5}' where StudentID='{6}'", txtStudentName.Text, txtBirthday.Text, txtClassID.Text, txtMobilePhone.Text, txtStudentGender.Text, txtAddress.Text, txtStudentNo.Text);
                DBhelp.comm.CommandText = sqlstr;
                DBhelp.comm.Connection = DBhelp.conn;

                if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("修改成功");

                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBhelp.conn.Close();
            }
        }

Modify the phone: 

Double-click to delete, the code inside:

private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DBhelp.conn.Open();
                string sqlstr = string.Format("delete from tb_Student where StudentID='{0}'", txtStudentNo.Text);
                DBhelp.comm.CommandText = sqlstr;
                DBhelp.comm.Connection = DBhelp.conn;

                if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("删除成功");

                }
                else
                {
                    MessageBox.Show("删除失败");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBhelp.conn.Close();
            }
        }

Double-click to close, the code inside:

 private void btnClose_Click(object sender, EventArgs e)
        {
            this.Hide();

        }

3. 

User change password page:

Double-click to confirm the modification, the code inside:

private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                DBhelp.conn.Open();
                string sqlstr = string.Format("update tb_User set UserName='{0}',UserPasswd='{1}' where UserID='{2}'", txtUserName.Text,txtUserPasswd.Text, txtUserID.Text);
                DBhelp.comm.CommandText = sqlstr;
                DBhelp.comm.Connection = DBhelp.conn;

                if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
                {
                    MessageBox.Show("修改成功");

                }
                else
                {
                    MessageBox.Show("修改失败");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            finally
            {
                DBhelp.conn.Close();
            }
        }

4. 

 home page:

GroupBox controls are often used to logically group a group of controls. Container   Panel controls: also used to partition

TabControl control: multi-tab, multi-partition control property TabPages can add multiple members

RadioButton: radio control starts with rbtn

RadioButton properties:

    1. Text : the text to display on the control
    2. Checked : This property can be read or set to read or modify the RadioButton checked state

CheckBox: multi-select control  

  1. Properties and Events:
      1. Text property
      2. Checked property
      3. CheckedChanged event

ComboBox control: the user selects the options listed in the control, the Items edit item, the drop-down box option

NumericUpDown control: Numeric selection control (NumericUpDown control) is a control for displaying and entering numerical values. The control provides a pair of up and down arrows, the user can click the up and down arrows to select the value, or directly input

ListBox Control: A list control is used to display a list from which the user can select one or more items. The control automatically adds a scroll bar if the total number of options exceeds the number of items that can be displayed

Tablcontrol: Paging options

Menu bar controls: MenuStrip is named after mus

The project name starts with tsm The project in the project is named with tsmi

Toolbar controls: ToolStrip items display pictures and text to change the property DisplayStyle, Toolbar: Start with tst

Status bar control: StatusStrip, status bar: start with the name of tss

First add a menu bar control MenuStrip: add items 

Add another toolbar control: ToolStrip: Add items,

If the button is selected, the font to be displayed is set:

 

 Status bar control: StatusStrip, you can choose from the following:

 Add a TreeView control to display hierarchical information

 Click the small triangle in the upper right to edit the node

Add another DataGridView control: display the tables in the database:

 

Click the small triangle in the upper right corner:

 

 Tables in the database:

 

 

 

... 

Guess you like

Origin blog.csdn.net/dengfengling999/article/details/124206249