Exemple #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            int flag = 0;

            try
            {
                conn.Open();
                string     select_id    = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();                                                       //选择的当前行第一列的值,也就是学生学号
                string     delete_by_id = "delete from student where stuxuehao=" + "'" + select_id + "'";                                                //sql删除语句,根据stuxuehao删除
                SqlCommand cmd          = new SqlCommand(delete_by_id, conn);
                cmd.ExecuteNonQuery();                                                                                                                   //执行命令

                String     sql        = "insert into SysLog values ( '" + FrmLogin.getid() + "' , '" + DateTime.Now + "' , '" + "Delete student" + "')"; //编写SQL命令
                SqlCommand sqlCommand = new SqlCommand(sql, conn);                                                                                       //记录日志
                sqlCommand.ExecuteNonQuery();
            }
            catch
            {
                flag = 1;
                MessageBox.Show("请正确选择行!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
            this.studentTableAdapter.Fill(this.exampleDBDataSet4.student);//使其显示更新后的表
            if (flag == 0)
            {
                MessageBox.Show("成功删除!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            conn.Open();
            string sql = "";

            if (textBox1.Text == "" || comboBox1.Text == "")
            {
                MessageBox.Show("请将信息填写完整!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                string gender = radioButton1.Checked ? "女" : "男";
                int    mima   = 123456;
                sql             = "insert into teacher(tname,teachpasswd,telephone,addr,teachsort,tsex)values('" + textBox1.Text.Trim() + "'," + mima + ",'" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + comboBox1.Text.Trim() + "','" + gender + "')";
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
                MessageBox.Show("添加用户成功!");
            }
            sql = "insert into SysLog values ( '" + FrmLogin.getid() + "' , '" + DateTime.Now + "' , '" + "insert Teacher" + "')"; //编写SQL命令
            SqlCommand sqlCommand = new SqlCommand(sql, conn);                                                                     //记录日志

            sqlCommand.ExecuteNonQuery();
            conn.Close();
        }
Exemple #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            string sql;

            conn.Open();
            if (watermarkTextBox1.Text == "" || comboBox1.Text == "" || watermarkTextBox2.Text == "")
            {
                MessageBox.Show("请将信息填写完整!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (radioButton1.Checked == false && radioButton2.Checked == false)
            {
                MessageBox.Show("请将信息填写完整!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                string gender = radioButton1.Checked ? "女" : "男";
                int    mima   = 123456;
                sql             = "insert into student(stuname,stupasswd,stugrade ,stubanji,stusex)values('" + watermarkTextBox1.Text.Trim() + "','" + mima + "','" + comboBox1.Text.Trim() + "','" + watermarkTextBox2.Text.Trim() + "','" + gender + "')";
                cmd.CommandText = sql;
                cmd.ExecuteNonQuery();
                MessageBox.Show("添加用户成功!");
            }
            sql = "insert into SysLog values ( '" + FrmLogin.getid() + "' , '" + DateTime.Now + "' , '" + "insert Student" + "')"; //编写SQL命令
            SqlCommand sqlCommand = new SqlCommand(sql, conn);                                                                     //记录日志

            sqlCommand.ExecuteNonQuery();
            conn.Close();
        }
Exemple #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(updatepswd.connectionString);
            int           flag = 0;

            try
            {
                conn.Open();
                string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是课程号
                string selectif  = "select * from sctime where claid='" + select_id + "'";

                SqlCommand    sqlCommand     = new SqlCommand(selectif, conn);
                SqlDataReader sqlDataReader2 = sqlCommand.ExecuteReader();
                if (sqlDataReader2.HasRows)
                {
                    string     real = "delete from sctime where claid=" + "'" + select_id + "'"; //sql删除语句
                    SqlCommand cmd1 = new SqlCommand(real, conn);
                    cmd1.ExecuteNonQuery();                                                      //执行命令

                    /*BindingSource bindingSource = new BindingSource();
                     * bindingSource.DataSource = sqlDataReader;
                     * dataGridView1.DataSource = bindingSource;*/
                }
                else
                {
                    string     del  = "delete from class where claid='" + select_id + "'";
                    SqlCommand sckb = new SqlCommand(del, conn);
                    sckb.ExecuteNonQuery();
                }



                String     sql     = "insert into SysLog values ( '" + FrmLogin.getid() + "' , '" + DateTime.Now + "' , '" + "Delete class" + "')"; //编写SQL命令
                SqlCommand sqlComm = new SqlCommand(sql, conn);                                                                                     //记录日志
                sqlComm.ExecuteNonQuery();
            }
            catch
            {
                flag = 1;
                MessageBox.Show("请正确选择行!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
            this.teachclass1TableAdapter.Fill(this.exampleDBDataSet9.teachclass1);//使其显示更新后的表
            if (flag == 0)
            {
                MessageBox.Show("成功删除!", "Tips", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            string        passwd    = textBox2.Text;
            string        quepasswd = textBox3.Text;
            SqlConnection sqlCnt    = new SqlConnection(connectionString);

            sqlCnt.Open();

            if (passwd == "" || quepasswd == "")
            {
                MessageBox.Show("请将信息填写完整!");
            }
            else
            {
                if (quepasswd != passwd)
                {
                    MessageBox.Show("两次输入的密码不一致!");
                }
                else
                {
                    if (FrmLogin.getRole() == "学生")
                    {
                        SqlCommand command = new SqlCommand();
                        command.Connection = sqlCnt;
                        string sql = "update student set stupasswd ='" + passwd + "' where stuxuehao = '" + FrmLogin.getStudent() + "'";
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改密码成功!");
                        this.Close();
                    }
                    else if (FrmLogin.getRole() == "教师")
                    {
                        SqlCommand command = new SqlCommand();
                        command.Connection = sqlCnt;
                        string sql = "update Teacher set teachpasswd ='" + passwd + "' where teachbm = '" + FrmLogin.gettid() + "'";
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改密码成功!");
                        this.Close();
                    }
                    else
                    {
                        SqlCommand command = new SqlCommand();
                        command.Connection = sqlCnt;
                        string sql = "update Users set userpassword ='******' where userid = '" + FrmLogin.getid() + "'";
                        command.CommandText = sql;
                        command.ExecuteNonQuery();
                        MessageBox.Show("修改密码成功!");
                        this.Close();
                    }
                }
                sqlCnt.Close();
            }
        }