⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teacher_information.cs

📁 不错的班级管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace _7计应的班级管理系统
{
    public partial class teacher_information : Form
    {
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox textBoxname;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.RadioButton radioButtonadd;
        private System.Windows.Forms.RadioButton radioButtonchange;
        private System.Windows.Forms.RadioButton radioButtondelete;
        private System.Windows.Forms.Button buttonsave;
        private System.Windows.Forms.Button buttonclear;
        private System.Windows.Forms.Button buttonfresh;
        private System.Windows.Forms.Button buttonexit;
        private System.Windows.Forms.ListView listViewdisplay;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.TextBox textBoxtext;
        private System.Windows.Forms.TextBox textBoxteach;
        private System.Windows.Forms.TextBox textBoxtel;
        private System.Windows.Forms.TextBox textBoxzhicheng;
        private System.Windows.Forms.TextBox textBoxsex;

        private BindingManagerBase bmgr;
        private System.Windows.Forms.Button buttonleft;
        private System.Windows.Forms.Button buttonright;


        DataSet dbrs = new DataSet();
        public teacher_information()
        {
            InitializeComponent();
        }

        private void buttonsave_Click(object sender, EventArgs e)
        {
            Form1 load = new Form1();
            if (load.Nowpower != "学生")
            {
                string strconn = "user id=sa;data source=localhost;integrated security=false;initial catalog=学生数据库1";
                SqlConnection conn = new SqlConnection(strconn);
                SqlCommand cmd = conn.CreateCommand();
                conn.Open();

                string name = textBoxname.Text.Trim();
                string sex = textBoxsex.Text.Trim();
                string tel = textBoxtel.Text.Trim();
                string zhicheng = textBoxzhicheng.Text.Trim();
                string teach = textBoxteach.Text.Trim();
                string beizhu = textBoxtext.Text.Trim();
                try
                {
                    if (radioButtonadd.Checked)
                    {
                        cmd.CommandText = "insert into teacher_information values('" + name + "','" + sex + "','" + tel + "','" + zhicheng + "','" + teach + "','" + beizhu + "')";

                    }
                    else if (radioButtonchange.Checked)
                    {
                        cmd.CommandText = "update teacher_information set 姓别='" + sex + "',联系电话='" + tel + "',担任科目='" + teach + "',备注='" + beizhu + "',职称='" + zhicheng + "' where 姓名='" + name + "' ";

                        //cmd.CommandText="delete from teacher_information where 姓名='"+name+"'";
                        //cmd.ExecuteNonQuery();
                        //cmd.CommandText="insert into teacher_information values('"+name+"','"+sex+"','"+tel+"','"+zhicheng+"','"+teach+"','"+beizhu+"')";
                    }
                    else if (radioButtondelete.Checked)
                    {
                        cmd.CommandText = "delete from teacher_information where 姓名='" + name + "'";
                    }
                    else
                        MessageBox.Show("请选择一个功能!");
                    SqlDataReader dr = cmd.ExecuteReader();
                    for (int i = 0; i < dr.FieldCount; i++)
                    {
                        ColumnHeader ch = new ColumnHeader();
                        ch.Text = dr.GetName(i);
                        listViewdisplay.Columns.Add(ch);
                    }
                    while (dr.Read())
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text = dr.GetValue(0).ToString();
                        for (int i = 1; i < dr.FieldCount; i++)
                        {
                            item.SubItems.Add(dr.GetValue(i).ToString());
                        }
                        listViewdisplay.Items.Add(item);
                    }
                    dr.Close();
                    refresh();
                }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
            else
                MessageBox.Show("只有管理员有此权限!");
        }

        private void teacher_information_Load(object sender, EventArgs e)
        {
            refresh();
            bind();
        }

        void refresh()
        {
            listViewdisplay.Clear();
            SqlConnection conn = new SqlConnection("user id=sa;data source=localhost;integrated security=false;initial catalog=学生数据库1");
            SqlCommand cmd = new SqlCommand();
            cmd = conn.CreateCommand();
            cmd.CommandText = "select * from teacher_information";
            conn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            //if(dr==null)
            //{
            for (int i = 0; i < dr.FieldCount; i++)
            {
                ColumnHeader ch = new ColumnHeader();
                ch.Text = dr.GetName(i);
                listViewdisplay.Columns.Add(ch);
            }
            while (dr.Read())
            {
                ListViewItem item = new ListViewItem();
                item.Text = dr.GetValue(0).ToString();
                for (int i = 1; i < dr.FieldCount; i++)
                {
                    item.SubItems.Add(dr.GetValue(i).ToString());
                }
                listViewdisplay.Items.Add(item);
            }
            //}
            //else 
            //	MessageBox.Show("没有这样的记录!");
            dr.Close();
            conn.Close();
        }
        void bind()
        {
            SqlConnection conn = new SqlConnection("user id=sa;data source=localhost;integrated security=false;initial catalog=学生数据库1");
            SqlDataAdapter da = new SqlDataAdapter("select * from teacher_information", conn);
            dbrs = new DataSet();
            textBoxname.DataBindings.Clear();
            textBoxsex.DataBindings.Clear();
            textBoxtel.DataBindings.Clear();
            textBoxzhicheng.DataBindings.Clear();
            textBoxteach.DataBindings.Clear();
            textBoxtext.DataBindings.Clear();
            da.Fill(dbrs, "teacher_information");
            textBoxname.DataBindings.Add("text", dbrs, "teacher_information.姓名");
            textBoxsex.DataBindings.Add("text", dbrs, "teacher_information.姓别");
            textBoxtel.DataBindings.Add("text", dbrs, "teacher_information.联系电话");
            textBoxzhicheng.DataBindings.Add("text", dbrs, "teacher_information.职称");
            textBoxteach.DataBindings.Add("text", dbrs, "teacher_information.担任科目");
            textBoxtext.DataBindings.Add("text", dbrs, "teacher_information.备注");
        }

        private void buttonclear_Click(object sender, EventArgs e)
        {
            textBoxname.Clear();
            textBoxsex.Clear();
            textBoxtel.Clear();
            textBoxzhicheng.Clear();
            textBoxteach.Clear();
            textBoxtext.Clear();
            listViewdisplay.Clear();
        }

        private void buttonfresh_Click(object sender, EventArgs e)
        {
            refresh();
            bind();
        }

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

        private void buttonleft_Click(object sender, EventArgs e)
        {

            bmgr = this.BindingContext[dbrs, "teacher_information"];
            bmgr.Position -= 1;
        }

        private void buttonright_Click(object sender, EventArgs e)
        {

            bmgr = this.BindingContext[dbrs, "teacher_information"];
            bmgr.Position += 1;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -