Example #1
0
 //修改
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnUpdate.Text == "修改")
         {
             btnUpdate.Text    = "确定";
             btnAdd.Enabled    = false;
             btnDelete.Enabled = false;
             txtSno.Enabled    = false;
             txtCno.Enabled    = false;
             txtGarde.Enabled  = true;
             txtGarde.Text     = "";
             txtGarde.Focus();
         }
         else
         {
             btnUpdate.Text    = "修改";
             btnAdd.Enabled    = true;
             btnDelete.Enabled = true;
             txtSno.Enabled    = false;
             txtCno.Enabled    = false;
             txtGarde.Enabled  = false;
             string sqlStr;
             sqlStr = "update tb_grade set grade='" + txtGarde.Text.Trim() + "'where sno='" + txtSno.Text.Trim() + "'";
             CDataBase.UpdateDB(sqlStr);
             RefreshData();
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #2
0
 private void btnSelect_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgrdvCourse.DataSource == null)
         {
             MessageBox.Show("没有课程可选", "提示");
             return;
         }
         int    n = dgrdvCourse.CurrentCell.RowIndex;
         int    i = dgrdvclass.CurrentCell.RowIndex;
         string selectCno, classno;
         classno   = dgrdvclass[0, i].Value.ToString().Trim();
         selectCno = dgrdvCourse[0, n].Value.ToString().Trim();
         string sqlStr;
         sqlStr = "select * from tb_select where classno='" + classno + "'" + "and Cno='" + selectCno + "'";
         if (CDataBase.GetDataFromDB(sqlStr) != null)
         {
             MessageBox.Show("已选该课程!", "不能重选", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         sqlStr = "insert into tb_select (classNo,Cno) values ('" + classno + "','" + selectCno + "')";
         CDataBase.UpdateDB(sqlStr);
         RefreshSelcetCourseData();
         MessageBox.Show("选课成功", "提示");
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #3
0
 //删除
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("确定要删除“" + txtSno.Text.Trim() + "”的资料吗?", "提示", MessageBoxButtons.YesNo,
                             MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
         {
             string sqlStr = "delete from tb_grade where sno='" + txtSno.Text.Trim() + "'";
             CDataBase.UpdateDB(sqlStr);
             int n = dgrdvGrade.CurrentCell.RowIndex;
             dgrdvGrade.Rows.RemoveAt(n);
             if (dgrdvGrade.Rows.Count == 1)
             {
                 cleraAll();
                 dgrdvGrade.DataSource = null;
             }
             else
             {
                 dgrdvGrade_RowHeaderMouseClick(null, null);
             }
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #4
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgrdvSelectCourse.DataSource == null)
         {
             MessageBox.Show("没有可删除的选课记录!", "提示");
             return;
         }
         int    n = dgrdvSelectCourse.CurrentCell.RowIndex;
         string classNo, selectCno, selectCname;
         classNo     = dgrdvSelectCourse[0, n].Value.ToString().Trim();
         selectCno   = dgrdvSelectCourse[2, n].Value.ToString().Trim();
         selectCname = dgrdvSelectCourse[3, n].Value.ToString().Trim();
         if (MessageBox.Show("确定要删除“" + classNo + "”的所选课程《" + selectCname + "》吗?", "删除选课记录",
                             MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
         {
             string sqlStr;
             sqlStr = "delete from tb_select where classno='" + classNo + "'" + "and Cno='" + selectCno + "'";
             CDataBase.UpdateDB(sqlStr);
             dgrdvSelectCourse.Rows.RemoveAt(n);
             if (dgrdvSelectCourse.Rows.Count == 1)
             {
                 dgrdvSelectCourse.DataSource = null;
             }
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
 private void btnAlter_Click(object sender, EventArgs e)
 {
     try
     {
         string sqlStr = "update tb_user set userPurview='" + cmbPurivew.Text.Trim() + "'" + "where userName='******'";
         CDataBase.UpdateDB(sqlStr);
         RefreshData();
         SetHeadText();
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #6
0
        //窗体载入



        private void btnRegedit_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (btnRegedit.Text == "注册")
                {
                    btnRegedit.Text = "确定";
                    ObjOpen();
                }
                else if (txtUserName.Text.Trim() == "")
                {
                    MessageBox.Show("用户名不能为空!", "提示");
                    txtUserName.Focus();
                }

                else if (txtUserPasswors.Text.Trim() == "")
                {
                    MessageBox.Show("用户名不能为空!", "提示");
                    txtUserPasswors.Focus();
                }
                else if (!UserName(txtUserName.Text.Trim()))
                {
                    MessageBox.Show("该用户已存在,请使用其他账号注册!", "提示");
                    txtUserName.Text = "";
                    ClearAll();
                }
                else
                {
                    btnRegedit.Text = "注册";
                    string sqlStr = "insert into tb_User values('" + txtUserName.Text.Trim() + "','" + txtUserPasswors.Text.Trim() + "','" + cmbPurview1.Text.Trim() + "','是')";
                    if (CDataBase.UpdateDB(sqlStr))
                    {
                        MessageBox.Show(cmbPurview1.Text + " " + txtUserName.Text + "注册成功!", "注册用户");
                    }
                    ClearAll();
                    ObjClose();
                    //btnCancel.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                CDataBase.conn.Close();
                MessageBox.Show(ex.Message);
                ClearAll();
                ObjClose();
            }
        }
 //修改
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnUpdate.Text.Trim() == "修改")
         {
             MessageBox.Show("学号不能修改", "注意");
             btnUpdate.Text     = "确定";
             btnCancel2.Visible = true;
             btnAdd.Enabled     = false;
             btnDelete.Enabled  = false;
             btnClose.Enabled   = false;
             cmbSelect.Enabled  = false;
             btnSelect.Enabled  = false;
             txtSelect.Enabled  = false;
             txtName.Enabled    = true;
             txtAge.Enabled     = true;
             txtClass.Enabled   = true;
             txtDept.Enabled    = true;
             cmbSex.Enabled     = true;
             txtName.Focus();
         }
         else
         {
             btnUpdate.Text     = "修改";
             btnCancel2.Visible = false;
             btnAdd.Enabled     = true;
             btnDelete.Enabled  = true;
             btnClose.Enabled   = true;
             cmbSelect.Enabled  = true;
             btnSelect.Enabled  = true;
             Objclose();
             string sqlStr;
             sqlStr = "update tb_student set Sname='" + txtName.Text.Trim() + "',Ssex='" + cmbSex.Text.Trim() + "',Sage='"
                      + txtAge.Text.Trim() + "',Sclass='" + txtClass.Text.Trim() + "',Sdept='" + txtDept.Text.Trim() + "'where sno='"
                      + txtNo.Text.Trim() + "'";
             CDataBase.UpdateDB(sqlStr);
             RefreshData();
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
 //删除
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         //RefreshData();
         string userName;
         int    n = this.dataGridView1.CurrentCell.RowIndex;
         userName = this.dataGridView1.Rows[n].Cells[0].Value.ToString().Trim();
         if (MessageBox.Show("确认删除 " + userName + " 吗?", "删除用户", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
         {
             string sqlStr = "delete from tb_User where userName='******'";
             CDataBase.UpdateDB(sqlStr);
             dataGridView1.Rows.RemoveAt(n);
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #9
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtNo.Text.Trim() == "")
         {
             MessageBox.Show("木有可删除的记录", "提示");
             return;
         }
         string sqlStr;
         sqlStr = "select * from tb_Select where cno='" + txtNo.Text.Trim() + "'";
         if (CDataBase.GetDataFromDB(sqlStr) != null)
         {
             MessageBox.Show("已有该课程的选课信息,拒绝删除!", "删除出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (MessageBox.Show("确定删除课程“" + txtName.Text.Trim() + "”吗?", "删除课程信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                  MessageBoxDefaultButton.Button2) == DialogResult.Yes)
         {
             sqlStr = "delete from tb_course where cno='" + txtNo.Text.Trim() + "'";
             CDataBase.UpdateDB(sqlStr);
             int n = dgrdvCourse.CurrentCell.RowIndex;
             dgrdvCourse.Rows.RemoveAt(n);
             if (dgrdvCourse.Rows.Count == 1)
             {
                 ClearAll();
                 dgrdvCourse.DataSource = null;
             }
             else
             {
                 dgrdvCourse_RowHeaderMouseClick(null, null);
             }
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #10
0
 //修改
 private void btnUpdata_Click(object sender, EventArgs e)  //为什么课程号不能修改?——要用课程号作为修改条件
 {
     try
     {
         if (btnUpdata.Text == "修改")
         {
             btnUpdata.Text     = "确定";
             btnCancel2.Visible = true;
             ObjOpen();
             txtNo.Enabled       = false;
             btnAdd.Enabled      = false;
             btnDelete.Enabled   = false;
             dgrdvCourse.Enabled = false;
             txtName.Focus();
         }
         else
         {
             btnUpdata.Text      = "修改";
             btnCancel2.Visible  = false;
             btnAdd.Enabled      = true;
             btnDelete.Enabled   = true;
             dgrdvCourse.Enabled = true;
             ObjClose();
             string sqlStr;
             sqlStr = "update tb_Course set Cname='" + txtName.Text.Trim() + "',Ccredit='" + txtCredit.Text.Trim()
                      + "',Cperiod='" + txtPeriod.Text.Trim() + "',Csemester='" + cmbSemester.Text.Trim() + "'where Cno='" + txtNo.Text.Trim() + "'";
             CDataBase.UpdateDB(sqlStr);
             RefreshData();
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }
Example #11
0
        //录入
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string  sql = "select sno,cno from tb_grade where sno='" + txtSno.Text.Trim() + "' and cno='" + txtCno.Text.Trim() + "'";
                DataSet ds  = new DataSet();
                ds = CDataBase.GetDataFromDB(sql);
                if (btnAdd.Text == "录入")
                {
                    btnAdd.Text = "确定";
                    cleraAll();
                    txtSno.Text   = "";
                    txtCno.Text   = "";
                    txtGarde.Text = "";
                    objOpen();
                    btnUpdate.Enabled = false;
                    btnDelete.Enabled = false;
                    return;
                }
                else if (txtSno.Text == "")
                {
                    MessageBox.Show("学号不能为空!", "提示");
                    txtSno.Focus();
                    return;
                }
                else if (txtCno.Text == "")
                {
                    MessageBox.Show("课程号不能为空", "提示");
                    txtCno.Focus();
                    return;
                }
                else if (ds != null)
                {
                    MessageBox.Show("该学生此成绩已存在,不能重复录入", "提示");
                    cleraAll();
                    txtSno.Focus();
                }

                btnAdd.Text = "录入";
                string sqlStr;
                sqlStr = "insert into tb_grade (Sno,Cno,grade) values ('" + txtSno.Text.Trim() + "','" + txtCno.Text.Trim()
                         + "','" + txtGarde.Text.Trim() + "')";
                CDataBase.UpdateDB(sqlStr);
                RefreshData();
                if (MessageBox.Show("录入成功,继续录入吗?", "录入成绩", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    cleraAll();
                    objOpen();
                    btnAdd.Text = "确定";
                    btnAll_Click(sender, e);
                }
                else
                {
                    objClose();
                    btnUpdate.Enabled = true;
                    btnDelete.Enabled = true;
                    btnAll_Click(sender, e);
                }
            }
            catch (Exception ex)
            {
                CDataBase.conn.Close();
                MessageBox.Show(ex.Message);
                cleraAll();
                objClose();
                btnAdd.Enabled    = true;
                btnUpdate.Enabled = true;
                btnDelete.Enabled = true;
                dgrdvGrade_RowHeaderMouseClick(null, null);
            }
        }
        //添加
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (btnAdd.Text == "添加")
                {
                    btnCancel.Visible = true;
                    btnAdd.Text       = "确定";

                    ClearAll();      //这句无法工作

                    cmbSex.SelectedIndex = -1;

                    ObjOpen();
                    RefreshData();
                    btnUpdate.Enabled    = false;
                    btnDelete.Enabled    = false;
                    btnSelect.Enabled    = false;
                    cmbSelect.Enabled    = false;
                    txtSelect.Enabled    = false;
                    dgrdvStudent.Enabled = false;
                    return;
                }
                else if (txtNo.Text.Trim() == "")
                {
                    MessageBox.Show("学号不能为空!", "提示");
                    txtNo.Focus();
                    return;
                }
                else if (txtName.Text.Trim() == "")
                {
                    MessageBox.Show("姓名不能为空!", "提示");
                    txtName.Focus();
                    return;
                }
                else if (txtClass.Text.Trim() == "")
                {
                    MessageBox.Show("班级不能为空!", "提示");
                    txtClass.Focus();
                    return;
                }
                else if (cmbSex.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择性别", "提示");
                    cmbSex.Focus();
                    return;
                }
                else if (txtDept.Text == "")
                {
                    MessageBox.Show("所属学院(系别)不能为空!", "提示");
                    txtDept.Focus();
                    return;
                }
                else if (txtAge.Text.Trim() == "")
                {
                    MessageBox.Show("年龄不能为空!", "提示");
                    txtAge.Focus();
                    return;
                }
                else if (!No(txtNo.Text.Trim()))
                {
                    MessageBox.Show("该学号已存在,请重新输入!", "提示");
                    txtNo.Focus();
                    return;
                }

                btnAdd.Text        = "添加";
                btnCancel.Visible  = false;
                btnCancel2.Visible = false;

                string sqlStr;
                sqlStr = "insert into tb_Student values('" + txtNo.Text.Trim() + "','" + txtName.Text.Trim() + "','" + cmbSex.Text.Trim() + "','" + txtAge.Text.Trim() + "','" + txtClass.Text.Trim() + "','" + txtDept.Text.Trim() + "')";
                CDataBase.UpdateDB(sqlStr);
                RefreshData();

                if (MessageBox.Show("添加成功,继续添加吗?", "添加学生信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    btnCancel.Visible = true;
                    ClearAll();
                    ObjOpen();
                    btnAdd.Text = "确定";
                }
                else
                {
                    Objclose();
                    btnUpdate.Enabled    = true;
                    btnDelete.Enabled    = true;
                    btnSelect.Enabled    = true;
                    cmbSelect.Enabled    = true;
                    txtSelect.Enabled    = true;
                    dgrdvStudent.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                CDataBase.conn.Close();
                MessageBox.Show(ex.Message);
                ClearAll();
                Objclose();
                btnUpdate.Enabled    = true;
                btnDelete.Enabled    = true;
                btnSelect.Enabled    = true;
                cmbSelect.Enabled    = true;
                txtSelect.Enabled    = true;
                dgrdvStudent.Enabled = true;
                dgrdvStudent_RowHeaderMouseClick(null, null);
            }
        }
Example #13
0
 //添加
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnAdd.Text.Trim() == "添加")
         {
             btnAdd.Text        = "确定";
             btnCancel1.Visible = true;
             ObjOpen();
             ClearAll();
             RefreshData();
             btnUpdata.Enabled   = false;
             btnDelete.Enabled   = false;
             dgrdvCourse.Enabled = false;
             return;
         }
         else if (txtNo.Text.Trim() == "")
         {
             MessageBox.Show("课程号不能为空", "提示");
             txtNo.Focus();
             return;
         }
         else if (txtName.Text.Trim() == "")
         {
             MessageBox.Show("课程名不能为空", "提示");
             txtName.Focus();
             return;
         }
         else if (txtCredit.Text.Trim() == "")
         {
             MessageBox.Show("课程学分不能为空", "提示");
             txtCredit.Focus();
             return;
         }
         else if (txtPeriod.Text.Trim() == "")
         {
             MessageBox.Show("课程学时不能为空", "提示");
             txtPeriod.Focus();
             return;
         }
         else if (cmbSemester.SelectedIndex == -1)
         {
             MessageBox.Show("请选择开课学期", "提示");
             cmbSemester.Focus();
             return;
         }
         else if (!No(txtNo.Text.Trim()))
         {
             MessageBox.Show("该课程已有", "提示");
             txtNo.Text = "";
             txtNo.Focus();
             return;
         }
         btnCancel1.Visible = false;
         btnAdd.Text        = "添加";
         string sqlStr;
         sqlStr = "insert into tb_Course values('" + txtNo.Text.Trim() + "','" + txtName.Text.Trim() + "','"
                  + txtCredit.Text.Trim() + "','" + txtPeriod.Text.Trim() + "','" + cmbSemester.Text.Trim() + "')";
         CDataBase.UpdateDB(sqlStr);
         RefreshData();
         if (MessageBox.Show("添加成功,继续添加吗?", "添加课程信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                             MessageBoxDefaultButton.Button1) == DialogResult.Yes)
         {
             btnCancel1.Visible = true;
             ClearAll();
             ObjOpen();
             btnAdd.Text = "确定";
         }
         else
         {
             ObjClose();
             btnUpdata.Enabled   = false;
             btnDelete.Enabled   = false;
             dgrdvCourse.Enabled = false;
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
         ObjClose();
         btnUpdata.Enabled   = true;
         btnDelete.Enabled   = true;
         dgrdvCourse.Enabled = true;
         dgrdvCourse_RowHeaderMouseClick(null, null);
     }
 }
Example #14
0
 private void btnEnter_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtOldPassWord.Text == "")
         {
             MessageBox.Show("请输入原密码!", "提示");
             txtOldPassWord.Focus();
         }
         else if (txtNewPassWord.Text == "")
         {
             MessageBox.Show("请输入新密码", "提示");
             txtNewPassWord.Focus();
         }
         else if (txtMatcPassWord.Text == "")
         {
             MessageBox.Show("请再次输入密码", "提示");
             txtMatcPassWord.Focus();
         }
         else if (txtNewPassWord.Text.Trim() == txtMatcPassWord.Text.Trim())
         {
             string  sql = "select userpassword from tb_User where username='******'";
             DataSet ds  = new DataSet();
             CDataBase.conn.ConnectionString = CDataBase.connStr;
             CDataBase.conn.Open();
             //SqlCommand cmd = new SqlCommand(sql, CDataBase.conn);
             //SqlDataReader sdr = cmd.ExecuteReader();
             SqlDataAdapter adapter = new SqlDataAdapter(sql, CDataBase.conn);
             adapter.Fill(ds);
             if (ds.Tables[0].Rows[0].ItemArray[0].ToString().Trim() == txtOldPassWord.Text.Trim())
             {
                 string sqlStr;
                 CDataBase.conn.Close();
                 sqlStr = "update tb_User set userPassword='******'"
                          + "where userName ='******'";
                 if (CDataBase.UpdateDB(sqlStr))
                 {
                     MessageBox.Show("修改成功!", "提示");
                 }
                 CleaAll();
             }
             else
             {
                 MessageBox.Show("原密码错误", "提示");
                 CleaAll();
                 txtOldPassWord.Focus();
             }
         }
         else
         {
             MessageBox.Show("两次密码输入不一样,重新输入!", "提示");
             txtNewPassWord.Text  = "";
             txtMatcPassWord.Text = "";
             txtNewPassWord.Focus();
         }
     }
     catch (Exception ex)
     {
         CDataBase.conn.Close();
         MessageBox.Show(ex.Message);
     }
 }