首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#2010设计机票预订管理系统两个有关问题 求解!

2012-12-26 
C#2010设计机票预订管理系统两个问题 求解!!!using Systemusing System.Collections.Genericusing Syste

C#2010设计机票预订管理系统两个问题 求解!!!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 航空机票预订管理系统
{
    public partial class booking : Form
    {
        LinkDatabase link = new LinkDatabase();
        public booking()
        {
            InitializeComponent();
        }
        private bool checkEmpty()
        {
            bool result=true;
            if(addTno.Text.Trim()==string.Empty)
                result=false;
            else if(Pno.Text.Trim()==string.Empty)
                result=false;
            else if(Pseat.Text.Trim()==string.Empty)
                result=false;
            else if(Pleave.Text.Trim()==string.Empty)
                result=false;
            else if(Parrive.Text.Trim()==string.Empty)
                result=false;
            else if(Ptime.Text.Trim()==string.Empty)
                result=false;
            else if(Cname.Text.Trim()==string.Empty)
                result=false;
            else if(Csex.Text.Trim()==string.Empty)
                result=false;
            else if(Cno.Text.Trim()==string.Empty)
                result=false;
            else if(Ctele.Text.Trim()==string.Empty)
                result=false;
            else if(Ttime.Text.Trim()==string.Empty)
                result=false;
            else if(Tsum.Text.Trim()==string.Empty)
                result=false;
            else if(Sno.Text.Trim()==string.Empty)


                result=false;
            return result;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(checkEmpty()==true)
            {try{
                string sendstrsql="INSERT INTO 订单 VALUES('"+addTno.Text+"','"+Pno.Text+"','"+Pseat.Text+"','"+Pleave.Text+"','"+Parrive.Text+"','"+Ptime.Text+"','"+Cname.Text+"','"+Csex.Text+"','"+Cno.Text+"','"+Ctele.Text+"','"+Ttime.Text+"','"+Tsum.Text+"','"+Sno.Text+"')";
                link.updatedb(sendstrsql);
                MessageBox.Show("成功添加");}
                catch(System.Exception ex)
            {
                    MessageBox.Show(ex.Message,"警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);}
            }
            else MessageBox.Show("输入不能为空!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string sendstrsql="SELECT 订单号,航班号,座位号,起飞地,目的地,起飞时间,旅客姓名,性别,身份证号,电话号码,订票时间,订票数量,员工编号 FROM 订单 WHERE 订单号=' + selTno.Text +'";
                DataTable dt1=link.dsresult(sendstrsql);
            dataGridView2.DataSource=dt1.DefaultView;
     
        }

        private void 删除_Click(object sender, EventArgs e)
        {
        try{
            string sendstrsql="DELETE FROM 订单 WHERE 订单号="+Convert.ToString(dataGridView2[0,dataGridView2.CurrentCell.RowIndex].Value).Trim()+"";
            link.updatedb(sendstrsql);
            MessageBox.Show("删除成功!","信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }catch(System.Exception ex)
        {
            MessageBox.Show(ex.Message,"警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
        }
        }

        private void 返回_Click(object sender, EventArgs e)


        {
            this.Close();
            return;
        }
问题1:想按返回键后返回下面这一页(Management),但是现在点返回键页面就直接消失,求问怎么修改代码?????

问题2:查询之后,连接到的数据库表并没有显示出来结果不知道为什么,可是DataSource已经添加了数据连接
代码:using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 航空机票预订管理系统
{
    public partial class ticket : Form
    {
        LinkDatabase link = new LinkDatabase();
        public ticket()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
       
            string sendstrsql = "SELECT 航班号,座位号,机票类型 FROM 机票 WHERE 航班号='+ sel_Pno.Text +' AND 座位号='+ sel_Pseat.Text +'";
            DataTable dt1 = link.dsresult(sendstrsql);
            dataGridView2.DataSource = dt1.DefaultView;
        }
        private bool checkEmpty()
        {
            bool result = true;
            if (add_Pseat.Text.Trim() == string.Empty)
                result = false;
            else if (add_Tno.Text.Trim() == string.Empty)
                result = false;
            else if (add_Ttype.Text.Trim() == string.Empty)
                result = false;
            return result;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkEmpty() == true)
            {
                try
                {
                    string sendstrsql = "INSERT INTO 机票 VALUES('" + add_Pseat.Text + "','" + add_Tno + "','" + add_Ttype + "')";


                    link.updatedb(sendstrsql);
                    MessageBox.Show("成功添加数据");
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else MessageBox.Show("输入不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
        
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string sendstrsql = "DELETE FROM 机票 WHERE 座位号=" + Convert.ToString(dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value).Trim() + "AND 座位号=" + Convert.ToString(dataGridView1[2,dataGridView1.CurrentCell.RowIndex].Value).Trim() + "";
                link.updatedb(sendstrsql);
                MessageBox.Show("记录删除成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

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

[最优解释]
1、你的那个Mangement如果之前已经关闭了,那就show(),如果之前就存在就Activate()
2、dataGridView2.DataBind()
[其他解释]
返回事件里不能this.Close();
可以thsi.Hide();
之后在打开你想要的窗体

楼主你的datagridview控件绑定每个字段的时候给它的DataPropertyName属性绑值了吗?
DataPropertyName这个属性绑定的是与你数据库查询表相对应的字段的,如果有实体类,绑定你实体类相对应的字段
[其他解释]
你的“订单信息管理”页面是怎么出来的 在主界面点击“订单信息管理”后showdialog()就可以了


“返回”还用你的方法 楼主试验下?
[其他解释]
既然你的sql语句为string sendstrsql = "SELECT 航班号,座位号,机票类型 FROM 机票 WHERE 航班号='+ sel_Pno.Text +' AND 座位号='+ sel_Pseat.Text +'";
那说明你的数据库中的字段名就是中文的 那就不需要在datagridview中在手动添加字段了 直接datagridview.datasource=dt;就好了 当然前提是你的dt是要有数据的。
[其他解释]
1.窗体跳转回去 
2. 参考楼上。

[其他解释]

  bool result=true;
             if(addTno.Text.Trim()==string.Empty)
                 result=false;
             else if(Pno.Text.Trim()==string.Empty)
                 result=false;
             else if(Pseat.Text.Trim()==string.Empty)
                 result=false;
             else if(Pleave.Text.Trim()==string.Empty)
                 result=false;
             else if(Parrive.Text.Trim()==string.Empty)
                 result=false;
             else if(Ptime.Text.Trim()==string.Empty)
                 result=false;
             else if(Cname.Text.Trim()==string.Empty)
                 result=false;
             else if(Csex.Text.Trim()==string.Empty)
                 result=false;
             else if(Cno.Text.Trim()==string.Empty)
                 result=false;
             else if(Ctele.Text.Trim()==string.Empty)
                 result=false;
             else if(Ttime.Text.Trim()==string.Empty)
                 result=false;
             else if(Tsum.Text.Trim()==string.Empty)
                 result=false;
             else if(Sno.Text.Trim()==string.Empty)
                 result=false;
             return result;



你这代码真 Nb 
[其他解释]
form1.Show();
form2.Hide();
[其他解释]
帅哥,求源代码和数据库文件
356618217@qq.com
[其他解释]
引用:
帅哥,求源代码和数据库文件
356618217@qq.com

这个童鞋一看就知道想用楼主的作为毕业论文
[其他解释]
引用:
C# code?12345678910111213141516171819202122232425262728  bool result=true;             if(addTno.Text.Trim()==string.Empty)                 result=false;             else if(Pno.Text.Trim……


- -不会用 && 的淫儿。。
很可爱

热点排行