Beispiel #1
0
 private bool ValidateInput()
 {
     if (TxtTcId.Text == "")
     {
         MessageBox.Show("请输入教师号", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         TxtTcId.Focus();
         return(false);
     }
     if (TxtLoPwd.Text == "")
     {
         MessageBox.Show("请输入密码", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         TxtLoPwd.Focus();
         return(false);
     }
     if (TxtLoAgainPwd.Text == "")
     {
         MessageBox.Show("请输入密码", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         TxtLoAgainPwd.Focus();
         return(false);
     }
     if (!(TxtLoPwd.Text == TxtLoAgainPwd.Text))
     {
         MessageBox.Show("两次输入密码不一致", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         TxtLoAgainPwd.Focus();
         return(false);
     }
     if (TxtTcName.Text == "")
     {
         MessageBox.Show("请输入姓名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         TxtTcName.Focus();
         return(false);
     }
     if (CboDep.Text == "")
     {
         MessageBox.Show("请输入系部名", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         CboDep.Focus();
         return(false);
     }
     if (CboName.Text == "")
     {
         MessageBox.Show("请输入所授课程", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         CboName.Focus();
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// 专业管理部分
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            if (TxtCId.Text == "")
            {
                MessageBox.Show("请输入专业号!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtCId.Focus();
            }
            else if (TxtCName.Text == "")
            {
                MessageBox.Show("请输入专业名称!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtCName.Focus();
            }
            else if (CboDep.Text == "")
            {
                MessageBox.Show("请选择所在院系!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                CboDep.Focus();
            }
            else
            {
                try
                {
                    string sql1 = string.Format("select depID from tbdepartment where depname='{0}'", CboDep.Text);
                    if (DBHelper.conn.State == ConnectionState.Open)
                    {
                        DBHelper.conn.Close();
                        DBHelper.conn.Open();
                    }
                    else if (DBHelper.conn.State == ConnectionState.Closed)
                    {
                        DBHelper.conn.Open();
                    }
                    SqlCommand    command = new SqlCommand(sql1, DBHelper.conn);
                    SqlDataReader reader  = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Status.sql = (string)reader["depID"];
                    }
                    DBHelper.conn.Close();

                    string sql = string.Format("insert into tbclass(classID,classname,depId) values('{0}','{1}','{2}')", TxtCId.Text, TxtCName.Text, Status.sql);
                    DBHelper.conn.Open();
                    SqlCommand cmd     = new SqlCommand(sql, DBHelper.conn);
                    int        result1 = cmd.ExecuteNonQuery();
                    if (result1 < 1)
                    {
                        MessageBox.Show("添加失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        DBHelper.conn.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        DBHelper.conn.Close();
                        this.ViewInfo1();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("数据库操作出错:" + ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }