Example #1
0
        private void FormCheckuser_Load(object sender, EventArgs e)
        {
            string str =//创建查询字符串
                         "select Tea_id as '教师编号', Tea_name as '教师姓名',Tea_Dept '部门',Tea_Birthday as '生日',Tea_Nation as '民族',Tea_Marriage as '婚否',Tea_MCCP as '政治面貌',Tea_Phone as '电话',Tea_Accession as '就职日期',Tea_Pay as '薪资' from Teacher";

            operate.BindDataGridView(dataGridView1, str);     //将查询信息绑定到DATAGRIDVIEW控件
            dataGridView1.Columns[0].Width = 60;              //定义数据列宽度
            dataGridView1.Columns[1].Width = 100;             //定义数据列宽度
            treeView1.Nodes.Add("所有学生");                      //添加根节点
            TreeNode      tn   = treeView1.Nodes.Add("所有教师"); //添加根节点
            SqlConnection conn = DBConnection.MyConnection(); //创建数据库连接对象

            conn.Open();
            SqlCommand    cmd = new SqlCommand("select distinct tea_dept from Teacher", conn); //创建命令对象
            SqlDataReader sdr = cmd.ExecuteReader();                                           //创建数据阅读器

            while (sdr.Read())
            {
                tn.Nodes.Add(sdr[0].ToString());                         //添加节点
            }
            sdr.Close();                                                 //关闭数据读取器
            conn.Close();                                                //关闭数据连接
            treeView1.ExpandAll();                                       //展开所有节点
            string sql = "select DISTINCT count(tea_dept) from Teacher"; //定义sql字符串

            Text = "当前教师编号:" + dataGridView1.SelectedCells[0].Value.ToString();
            string TeaId = dataGridView1.SelectedCells[0].Value.ToString(); //得到编号(学生或者教师编号)

            operate.TeaGet_Image(TeaId, pictureBox1);                       //显示图片信息
            treeView1.SelectedNode = treeView1.Nodes[0];
            if (FormMain.Power == "教师")
            {
                delete.Enabled = false;
                ADD.Enabled    = false;
                treeView1.CollapseAll();
            }
        }
Example #2
0
 DBOperate operate = new DBOperate(); //创建操作数据库对象
 private void FormCheckuser_G_Load(object sender, EventArgs e)
 {
     try
     {
         if (XG == "所有学生")
         {
             tabControl1.SelectTab("学生");
             string  str = "select * from student where stu_id='" + XGID + "'";
             DataSet ds  = operate.GetTable(str);
             ds.Dispose();
             //学生表不用给专业赋初值,后已经将班级与专业关联
             TB_stu_ID.Text      = ds.Tables[0].Rows[0][0].ToString();
             CBB_stu_class.Text  = ds.Tables[0].Rows[0][1].ToString();
             TB_stu_name.Text    = ds.Tables[0].Rows[0][2].ToString();
             CBB_stu_sex.Text    = ds.Tables[0].Rows[0][3].ToString();
             Time_stu_birth.Text = ds.Tables[0].Rows[0][4].ToString();
             CBB_stu_MCCP.Text   = ds.Tables[0].Rows[0][5].ToString();
             TB_stu_enter.Text   = ds.Tables[0].Rows[0][6].ToString();
             CBB_stu_nation.Text = ds.Tables[0].Rows[0][8].ToString();
             operate.StuGet_Image(XGID, pictureBox_stu);
         }
         else
         {
             tabControl1.SelectTab("老师");
             string  str = "select * from teacher where tea_id='" + XGID + "'";
             DataSet ds  = operate.GetTable(str);
             ds.Dispose();
             TB_tea_ID.Text      = ds.Tables[0].Rows[0][0].ToString();;
             TB_tea_name.Text    = ds.Tables[0].Rows[0][1].ToString();;
             CBB_tea_sex.Text    = ds.Tables[0].Rows[0][2].ToString();;
             CBB_tea_dept.Text   = ds.Tables[0].Rows[0][3].ToString();;
             Time_tea_birth.Text = ds.Tables[0].Rows[0][4].ToString();;
             CBB_tea_nation.Text = ds.Tables[0].Rows[0][5].ToString();;
             CBB_tea_marry.Text  = ds.Tables[0].Rows[0][6].ToString();;
             CBB_tea_MCCP.Text   = ds.Tables[0].Rows[0][7].ToString();;
             TB_tea_phone.Text   = ds.Tables[0].Rows[0][8].ToString();;
             Time_tea_enter.Text = ds.Tables[0].Rows[0][9].ToString();;
             operate.TeaGet_Image(XGID, pictureBox_tea);
             TB_tea_pay.Text = ds.Tables[0].Rows[0][11].ToString();;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);//弹出消息对话框
     }
 }