Exemplo n.º 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
                {
                    string key = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    string value_1 = "'" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";
                    string value_2 = "'" + dataGridView1.CurrentRow.Cells[1].Value.ToString() + "'";
                    string value_3 = "'" + dataGridView1.CurrentRow.Cells[2].Value.ToString() + "'";
                    string value_4 = "'" + dataGridView1.CurrentRow.Cells[3].Value.ToString() + "'";
                    string value_5 = "'" + dataGridView1.CurrentRow.Cells[4].Value.ToString() + "'";
                    string value_6 = "'" + dataGridView1.CurrentRow.Cells[5].Value.ToString() + "'";
                    string value_7 = "'" + dataGridView1.CurrentRow.Cells[6].Value.ToString() + "'";
                    string value_8 = "'" + dataGridView1.CurrentRow.Cells[7].Value.ToString() + "'";
                    string sql_up = "UPDATE book SET " + "bname =" + value_2 + "," + "bwriter =" + value_3 + "," + "bpulisher =" + value_4 + "," +"btmpublished"+value_5+ "bclass =" + value_6 + "," +"bsum"+value_7+ "bkejie =" + value_8 + "WHERE bnum=" + "'" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'" + ";";
                    ConnDb conn_up = new ConnDb();
                    conn_up.update(sql_up);
                    dataGridView1.DataSource = null;//刷新datagridview
                    dataGridView1.Rows.Clear();
                    dataGridView1.Columns.Clear();
                    DataSet ds = new DataSet();
                    string sql = "Select * from book";
                    ConnDb conn1 = new ConnDb();
                    ds = conn1.query(sql);
                    dataGridView1.DataSource = ds.Tables[0];

                }
            if (radioButton2.Checked == true) {
                string key = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                string value_1 = "'" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";
                string value_2 = "'" + dataGridView1.CurrentRow.Cells[1].Value.ToString() + "'";
                string value_3 = "'" + dataGridView1.CurrentRow.Cells[2].Value.ToString() + "'";
                string value_4 = "'" + dataGridView1.CurrentRow.Cells[3].Value.ToString() + "'";
                string sql_up = "UPDATE [user] SET " + "uname =" + value_2 + "," + "upasswd =" + value_3 + "," + "ubrwalready ="+value_4+" WHERE bnum=" + "'" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'" + ";";
                ConnDb conn_up = new ConnDb();
                conn_up.update(sql_up);
                dataGridView1.DataSource = null;//刷新datagridview
                dataGridView1.Rows.Clear();
                dataGridView1.Columns.Clear();
                DataSet ds = new DataSet();
                string sql = "Select * from [user]";
                ConnDb conn1 = new ConnDb();
                ds = conn1.query(sql);
                dataGridView1.DataSource = ds.Tables[0];
            }
            if (radioButton3.Checked == true) {
                string key = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                string value_1 = "'" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";
                string value_2 = "'" + dataGridView1.CurrentRow.Cells[1].Value.ToString() + "'";
                string value_3 = "'" + dataGridView1.CurrentRow.Cells[2].Value.ToString() + "'";
                string value_4 = "'" + dataGridView1.CurrentRow.Cells[3].Value.ToString() + "'";
                string value_5 = "'" + dataGridView1.CurrentRow.Cells[4].Value.ToString() + "'";

                string sql_up = "UPDATE borrowinfo SET " + "tmbrw" + value_3 + "tmlimit" + value_5 + "WHERE bnum=" + "'" + dataGridView1.CurrentRow.Cells[1].Value.ToString() + "' and unum='" + dataGridView1.CurrentRow.Cells[0].Value.ToString() + "';";
                ConnDb conn_up = new ConnDb();
                conn_up.update(sql_up);
                dataGridView1.DataSource = null;//刷新datagridview
                dataGridView1.Rows.Clear();
                dataGridView1.Columns.Clear();
                DataSet ds = new DataSet();
                string sql = "Select * from borrowinfo";
                ConnDb conn1 = new ConnDb();
                ds = conn1.query(sql);
                dataGridView1.DataSource = ds.Tables[0];
            }
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //bool valid = true;
            if (radioButton1.Checked == true) {
                //string sql
                string value_1 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[0].Value.ToString() + "'";
                string value_2 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[1].Value.ToString() + "'";
                string value_3 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[2].Value.ToString() + "'";
                string value_4 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[3].Value.ToString() + "'";
                string value_5 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[4].Value.ToString() + "'";
                string value_6 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[5].Value.ToString() + "'";
                string value_7 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[6].Value.ToString() + "'";
                string value_8 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[7].Value.ToString() + "'";
                string value = value_1 + "," + value_2 + "," + value_3 + "," + value_4 + "," + value_5 + "," + value_6 +","+ value_7 + "," + value_8;
                string sql_in = "INSERT INTO book VALUES" + "(" + value + ")";//将datagridview行抽取成sql语句
                /*for (int i = 0; i < dataGridView1.Rows.Count-2; i++) {
                    if (dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[0].Value.ToString().Equals(dataGridView1.Rows[i].Cells[0].Value.ToString()))
                    {
                        MessageBox.Show("输入数据错误,请重新编辑");
                        sql_in = "select * from book";
                        valid = false;
                    }
                  }
                */

                //if (valid == true)
                try
                {
                    ConnDb conn_2 = new ConnDb();
                    conn_2.update(sql_in);
                    dataGridView1.DataSource = null;//刷新datagridview
                    dataGridView1.Rows.Clear();
                    dataGridView1.Columns.Clear();
                    DataSet ds = new DataSet();
                    string sql = "Select * from book";
                    ConnDb conn1 = new ConnDb();
                    ds = conn1.query(sql);
                    dataGridView1.DataSource = ds.Tables[0];
                }
                catch (Exception e5) {
                    MessageBox.Show("输入数据错误,请重新编辑("+e5.Message+")");
                    }
            }
            if (radioButton2.Checked == true) {

                string value_1 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[0].Value.ToString() + "'";
                string value_2 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[1].Value.ToString() + "'";
                string value_3 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[2].Value.ToString() + "'";
                string value_4 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[3].Value.ToString() + "'";
                //string value_5 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[4].Value.ToString();
                //string value_6 = "'" + dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[5].Value.ToString();
                string value = value_1 + "," + value_2 + "," + value_3 + "," + value_4;
                string sql_in = "INSERT INTO [user] VALUES" + "(" + value + ")" + ";";
                /*for (int i = 0; i < dataGridView1.Rows.Count - 2; i++)
                {
                    if (dataGridView1.Rows[dataGridView1.Rows.Count - 2].Cells[0].Value.ToString().Equals(dataGridView1.Rows[i].Cells[0].Value.ToString()))
                    {
                        MessageBox.Show("输入数据错误,请重新编辑");
                        sql_in = "select * from [user]";
                        valid = false;
                    }
                }*/

                //if (valid == true)
                try
                {
                    ConnDb conn_2 = new ConnDb();
                    conn_2.update(sql_in);
                    dataGridView1.DataSource = null;//刷新datagridview
                    dataGridView1.Rows.Clear();
                    dataGridView1.Columns.Clear();
                    DataSet ds = new DataSet();
                    string sql = "Select * from [user]";
                    ConnDb conn1 = new ConnDb();
                    ds = conn1.query(sql);
                    dataGridView1.DataSource = ds.Tables[0];
                }
                catch (Exception e4) {
                    MessageBox.Show("输入数据错误,请重新编辑("+e4.Message+")");
                }
                //string sql
            }
            if (radioButton3.Checked == true) {
                //string sql
            }
        }
Exemplo n.º 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                if (MessageBox.Show("确定删除此记录?", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {   //delete
                    string key = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();//获取当前光标所在行的主键
                    string KEY = "'" + key + "'";
                    string sql_del = "delete from book where bnum=" + KEY;
                    ConnDb conn_del = new ConnDb();
                    conn_del.update(sql_del);
                    MessageBox.Show("删除成功!");
                    dataGridView1.DataSource = null;
                    dataGridView1.Rows.Clear();
                    dataGridView1.Columns.Clear();
                    DataSet ds = new DataSet();
                    string sql = "Select bnum 图序号,bname 图书名,bwriter 作者,bpulisher 出版社,btmpublished 出版日期,bclass 类型,bsum 总数,bkejie 是否可借 from book";
                    ConnDb conn1 = new ConnDb();
                    ds = conn1.query(sql);
                    dataGridView1.DataSource = ds.Tables[0];
                    //string sql
                }
            }
            if (radioButton2.Checked == true)
            {
                if (MessageBox.Show("确定删除此记录?", "确认信息", MessageBoxButtons.OKCancel) == DialogResult.OK)

                {
                    //delete
                    string key = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                    string KEY = "'" + key + "'";
                    string sql_del = "delete from [user] where unum=" + KEY;
                    ConnDb conn_del = new ConnDb();
                    conn_del.update(sql_del);
                    MessageBox.Show("删除成功!");
                    dataGridView1.DataSource = null;
                    dataGridView1.Rows.Clear();
                    dataGridView1.Columns.Clear();
                    DataSet ds = new DataSet();
                    string sql = "Select * from [user]";
                    ConnDb conn1 = new ConnDb();
                    ds = conn1.query(sql);
                    dataGridView1.DataSource = ds.Tables[0];

                    //string sql
                }
            }
            if (radioButton3.Checked == true)
            {
                MessageBox.Show("您无权修改此记录");
                //string key = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
                //string KEY = "'" + key + "'";
                //string sql_del = "delete from borrowinfo where =" + KEY;
               // ConnDb conn_del = new ConnDb();
               // conn_del.update(sql_del);
                //string sql
            }
        }