Example #1
0
 //添加按钮
 private void button1_Click(object sender, EventArgs e)
 {
     if (TB_course_ID.Text.Trim() == "" || TB_course_NAME.Text.Trim() == "")
     {
         MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     else
     {
         try
         {
             string count = "select count(*) from SC_result where cour_id='" + TB_course_ID.Text + "'";
             if (operate.HumanNum(count) == 0)
             {
                 MessageBox.Show("此课程为此学期的一个新课程");
                 string strAdd = "insert into Coures values ('" + TB_course_ID.Text + "','" + TB_course_NAME.Text + "','" + CBB_semester.Text + "')";
                 operate.OperateData(strAdd);
             }
             string sqlstr = "INSERT into [dbo].[SC_result] ([Stu_Id],[Cour_Id],[Cour_Name]) select distinct A.Stu_Id,'" + TB_course_ID.Text + "','" + TB_course_NAME.Text + "' from Student as A join SC_result AS B on A.Stu_Id=B.stu_id join Coures AS C on B.Cour_Id=C.Cour_Id where C.Cour_Semester='" + CBB_semester.Text.ToString() + "' and A.stu_class='" + CBB_class.Text.ToString() + "'";
             int    i      = operate.OperateData(sqlstr);//更新数据库内容
             if (i > 0)
             {
                 MessageBox.Show("添加用户信息成功", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 button2_Click(sender, e);
                 return;//关闭事件
             }
         }
         catch
         {
             MessageBox.Show("此班本学期已使用此课程号", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Example #2
0
        //删除按钮
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.SelectedCells.Count == 0)
                {
                    MessageBox.Show("请选择要删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    string stuclass = dataGridView1.SelectedCells[0].Value.ToString(); //得到班级信息
                    string CourID   = dataGridView1.SelectedCells[1].Value.ToString(); //得到课程信息

                    //string count = "select count(*) from SC_result join student on student.stu_id=SC_result.stu_id join Coures on Coures.cour_id=SC_result.cour_id where SC_result.Cour_Id='" + CourID + "' and student.stu_class='" + cbbClass.SelectedItem.ToString() + "' and Coures.Cour_Semester='" + cbbSemester.SelectedItem.ToString() + "'";
                    string count  = "select count(*) from SC_result where cour_id='" + CourID + "'";
                    string Delsql = "delete from SC_result where Cour_Id='" + CourID + "' and Stu_Id in (select stu_id from Student where stu_class='" + stuclass + "')";
                    operate.OperateData(Delsql);//删除成绩信息
                    if (operate.HumanNum(count) == 0)
                    {
                        string delCID = "delete from Coures where Cour_Id='" + CourID + "'";
                        operate.OperateData(delCID);//删除课程信息
                    }
                    MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #3
0
 //保存按钮(老师)
 private void btn_keep_tea_Click(object sender, EventArgs e)
 {
     if (TB_tea_ID.Text.Trim() == "" || TB_tea_name.Text.Trim() == "" || TB_tea_pay.Text.Trim() == "" || TB_tea_phone.Text.Trim() == "")
     {
         MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     else
     {
         if (TB_tea_phone.Text.Length != 11)
         {
             MessageBox.Show("手机号码为11位");
             return;
         }
         else
         {
             try
             {
                 string strsql = "update [dbo].[Teacher] set [Tea_Name]='" + TB_tea_name.Text.ToString() + "',[Tea_Sex]='" + CBB_tea_sex.Text.ToString() + "',[Tea_Dept]='" + CBB_tea_dept.Text.ToString() + "',[Tea_Birthday]='" + Time_tea_birth.Value.ToString("yyyy年MM月d日") + "',[Tea_Nation]='" + CBB_tea_nation.Text.ToString() + "',[Tea_Marriage]='" + CBB_tea_marry.Text.ToString() + "',[Tea_MCCP]='" + CBB_tea_MCCP.Text.ToString() + "',[Tea_Phone]='" + TB_tea_phone.Text.ToString() + "',[Tea_Accession]='" + Time_tea_enter.Value.ToString("yyyy年MM月d日") + "',[Tea_Pay]='" + TB_tea_pay.Text.ToString() + "' where [Tea_Id]='" + TB_tea_ID.Text.ToString() + "' ";
                 int    num    = operate.OperateData(strsql);
                 operate.TeaSaveImages(this.TB_tea_ID.Text.Trim(), openFileDialog1);
                 if (num > 0)
                 {
                     MessageBox.Show("教师信息修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.Close();
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("你的输入有误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }
Example #4
0
        //删除按钮
        private void delete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.SelectedCells.Count == 0)
                {
                    MessageBox.Show("请选择要删除的数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    string YGID = dataGridView1.SelectedCells[0].Value.ToString();//学生号或者教师号码

                    string table; string ID_name;
                    if (treeView1.SelectedNode.Text == "所有学生")
                    {
                        table   = "student";
                        ID_name = "stu_id";
                    }
                    else
                    {
                        table   = "teacher";
                        ID_name = "tea_id";
                    }
                    operate.DeleUserInfo(YGID);  //删除相关信息
                    string Delsql = "delete from " + table + " where " + ID_name + "='" + YGID + "'";
                    operate.OperateData(Delsql); //删除(教师表/学生表)信息
                    MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch
            {
                MessageBox.Show("删除操作失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #5
0
 //保存按钮(老师)
 private void btn_keep_tea_Click(object sender, EventArgs e)
 {
     if (TB_tea_ID.Text.Trim() == "" || TB_tea_name.Text.Trim() == "" || TB_tea_pay.Text.Trim() == "" || TB_tea_phone.Text.Trim() == "")
     {
         MessageBox.Show("请将信息填写完整", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     else
     {
         if (TB_tea_phone.Text.Length != 11)
         {
             MessageBox.Show("手机号码为11位");
             return;
         }
         else
         {
             try
             {
                 string strsql = "INSERT INTO [dbo].[Teacher] ([Tea_Id],[Tea_Name],[Tea_Sex],[Tea_Dept],[Tea_Birthday],[Tea_Nation],[Tea_Marriage],[Tea_MCCP],[Tea_Phone],[Tea_Accession],[Tea_Pay]) VALUES ('" + TB_tea_ID.Text.ToString() + "','" + TB_tea_name.Text.ToString() + "','" + CBB_tea_sex.Text.ToString() + "','" + CBB_tea_dept.Text.ToString() + "','" + Time_tea_birth.Value.ToString("yyyy年MM月d日") + "','" + CBB_tea_nation.Text.ToString() + "','" + CBB_tea_marry.Text.ToString() + "','" + CBB_tea_MCCP.Text.ToString() + "','" + TB_tea_phone.Text.ToString() + "','" + Time_tea_enter.Value.ToString("yyyy年MM月d日") + "','" + TB_tea_pay.Text.ToString() + "')";
                 int    num    = operate.OperateData(strsql);
                 operate.TeaSaveImages(this.TB_tea_ID.Text.Trim(), openFileDialog1);
                 //同时创建一个新的教师登录账户(密码默认为123456)
                 string time = DateTime.Now.ToString(); //获取当前系统事件字符串
                 string sql  = "insert into wang_User values('" + TB_tea_ID.Text.ToString() + "','" + password + "','" + "教师" + "','" + time + "')";
                 operate.OperateData(sql);              //更新数据库内容
                 if (num > 0)
                 {
                     MessageBox.Show("教师信息添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     this.Close();
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("填写信息有误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }
Example #6
0
 //修改按钮
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (textBox1.Text.Trim() == "")
         {
             MessageBox.Show("请填写新密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             string strUpdateSql = "update wang_User set UserPwd='" + textBox1.Text + "' where UserName='******'";
             operate.OperateData(strUpdateSql);
             MessageBox.Show("修改密码成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();//关闭窗体
         }
     }
     catch (Exception ex)                                                                     //捕获异常
     {
         MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //弹出消息对话框
     }
 }
Example #7
0
 //删除记录(将选中记录的登录事件重置为'2012/01/01 0:00:00')
 private void delete_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.dataGridView1.SelectedCells.Count == 0)
         {
             MessageBox.Show("请选择要删除的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else
         {
             string user_name = dataGridView1.SelectedCells[0].Value.ToString(); //得到用户名
             string delUser   = "******" + user_name + "'";
             operate.OperateData(delUser);                                       //删除用户信息
             operate.DeleUserInfo(user_name);
             MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch
     {
         MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #8
0
        DBOperate operate = new DBOperate();//创建操作数据库对象
        //登录按钮的事件
        private void btnlogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (textname.Text == "" || textpassword.Text == "")//判断文本框内容
                {
                    MessageBox.Show("用户名或密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;  //退出事件
                }
                else
                {
                    string name     = textname.Text.Trim();
                    string password = textpassword.Text.Trim();

                    string power = "";
                    if (Rbtnstu.Checked)
                    {
                        power = "学生";
                    }
                    if (rbtntea.Checked)
                    {
                        power = "教师";
                    }
                    if (rbtnmaster.Checked)
                    {
                        power = "管理员";
                    }

                    SqlConnection conn = PMSClass.DBConnection.MyConnection();//创建连接对象
                    conn.Open();
                    SqlCommand    cmd = new SqlCommand("select UserName,UserPwd from wang_User where UserName='******' and UserPwd='" + password + "' and UserPower='" + power + "'", conn);
                    SqlDataReader sdr = cmd.ExecuteReader();   //得到数据库读取的对象
                    sdr.Read();                                //读取一行数据
                    if (sdr.HasRows)                           //判断行是否包含数据
                    {
                        string time = DateTime.Now.ToString(); //获取当前系统事件字符串
                        string sql  = "UPDATE wang_User SET LoginTime='" + time + "' WHERE UserName='******' and UserPwd='" + password + "'";
                        operate.OperateData(sql);              //更新数据库内容
                        conn.Close();
                        this.Hide();                           //隐藏当前窗体
                        //传值
                        FormMain Main = new FormMain();        //创建主窗体对象
                        FormMain.User  = name.ToString();
                        Main.Logintime = time.ToString();
                        FormMain.Power = power.ToString();
                        Main.Show();//显示主窗体
                    }
                    else
                    {
                        textname.Text     = ""; //清空用户名
                        textpassword.Text = ""; //清空密码
                        MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    conn.Close();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }