窗口上的【增加】【修改】【删除】【查询】【刷新】【查看】【退出】按钮的实现方法

刚才从网上下载了一个旅游的管理系统,其中有一个页面上有【增加】【修改】【删除【刷新】【查看】【退出】这几个按钮,感觉很有用,所以拿来和大家分享一下。

1.【增加】:

private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Form35 form35 = new Form35();
            form35.ShowDialog();
        }
这里调用了另一个窗口,就是跳出一个让你填写各项信息的窗口Form35,填写完各项信息之后,点击【保存】按钮就行了。【保存】按钮方法如下:

private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                OleDbConnection conn = new OleDbConnection(dataconn.myconn);
                conn.Open();
                string str = "insert into travelline values('" + this.textBox1.Text + "','" + this.textBox3.Text + "','" + this.textBox2.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "')";
                OleDbCommand ole = new OleDbCommand(str, conn);
                int i = ole.ExecuteNonQuery();
                if (i == 1)
                {
                                                  
                    dataconn.form5.showdate();
                    MessageBox.Show("添加成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    
                }
                else
                {
                    MessageBox.Show("添加失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                conn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

2.【修改】:

主程序代码如下:

private void toolStripButton2_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(dataconn.myconn);
            conn.Open();
            string str = "select * from travelline where lno='" + this.dataGridView1.SelectedCells[0].Value.ToString().Trim() + "'";
            OleDbCommand ole1 = new OleDbCommand(str, conn);
            OleDbDataReader read = ole1.ExecuteReader();
            if (read.Read())
            {
                dataconn.data_lno = read["lno"].ToString().Trim();
                dataconn.data_jumping = read["jumping"].ToString().Trim();
                dataconn.data_endpoint = read["endpoint"].ToString().Trim();
                dataconn.data_lday = read["lday"].ToString().Trim();
                dataconn.data_sight = read["sight"].ToString().Trim();
                Form36 form36 = new Form36();
                form36.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择数据!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            conn.Close();
            
        }
至于他调用的Form36窗口中,主要有【保存】和【退出】两个按钮,当你修改完毕各个文本框里的信息之后,点击保存或者退出即可,【保存】按钮代码如下:

 private void toolStripButton1_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(dataconn.myconn);
            conn.Open();
            string str = "update travelline set lno='" + this.textBox1.Text.Trim() + "',jumping='" +
                this.textBox2.Text.Trim() + "',endpoint='" +
                this.textBox3.Text.Trim() + "',lday='" +
                this.textBox4.Text.Trim() + "',sight='" +
                this.textBox5.Text.Trim() + "' where lno='" + dataconn.data_lno + "'";
            OleDbCommand ole = new OleDbCommand(str, conn);
            int i = ole.ExecuteNonQuery();
            if (i == 1)
            {
                dataconn.form5.showdate();
                MessageBox.Show("修改成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("修改失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
3.【删除】:

private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认删除", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                OleDbConnection conn = new OleDbConnection(dataconn.myconn);
                conn.Open();
                string str = "delete from travelline where lno='" + this.dataGridView1.SelectedCells[0].Value .ToString ().Trim () + "'";
                OleDbCommand ole1 = new OleDbCommand(str ,conn );
                int i = ole1.ExecuteNonQuery();
                if (i == 1)
                {
                    showdate();
                    MessageBox.Show("删除成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                conn.Close();
            }
        }
其中showdate()的定义为:

private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确认删除", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                OleDbConnection conn = new OleDbConnection(dataconn.myconn);
                conn.Open();
                string str = "delete from travelline where lno='" + this.dataGridView1.SelectedCells[0].Value .ToString ().Trim () + "'";
                OleDbCommand ole1 = new OleDbCommand(str ,conn );
                int i = ole1.ExecuteNonQuery();
                if (i == 1)
                {
                    showdate();
                    MessageBox.Show("删除成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                conn.Close();
            }
        }

4.【刷新】:

private void toolStripButton5_Click(object sender, EventArgs e)
        {
            showdate();
        }
其中showdate()的定义在上面写了。

5.【查看】:

private void toolStripButton6_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(dataconn.myconn);
            conn.Open();
            string str = "select * from travelline where lno='" + this.dataGridView1.SelectedCells[0].Value.ToString().Trim() + "'";
            OleDbCommand ole1 = new OleDbCommand(str, conn);
            OleDbDataReader read = ole1.ExecuteReader();
            if (read.Read())
            {
                dataconn.data_lno = read["lno"].ToString().Trim();
                dataconn.data_jumping = read["jumping"].ToString().Trim();
                dataconn.data_endpoint = read["endpoint"].ToString().Trim();
                dataconn.data_lday = read["lday"].ToString().Trim();
                dataconn.data_sight = read["sight"].ToString().Trim();
                Form37 form37 = new Form37();
                form37.ShowDialog();
            }
            else
            {
                MessageBox.Show("请选择数据!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            conn.Close();
            
        }
其中Form37窗口的出程序为:

private void Form37_Load(object sender, EventArgs e)
        {
            this.textBox1.Text = dataconn.data_lno;
            this.textBox2.Text = dataconn.data_jumping;
            this.textBox3.Text = dataconn.data_endpoint;
            this.textBox4.Text = dataconn.data_lday;
            this.textBox5.Text = dataconn.data_sight;
        }
6.【退出】:

private void toolStripButton7_Click(object sender, EventArgs e)
        {
            this.Close();
        }

以上还有一些对数据库的操作,目前还正在研究当中,还不是很懂。。。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值