📄 chaxunform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using DataAccess;
using System.Data;
using System.Text;
using BusinessRule.Tables;
using BusinessRule.TablesBusines;
using BusinessRule.Table;
using System.Data.SqlClient;
namespace FromZhuJieMian
{
/// <summary>
/// ChaXunForm 的摘要说明。
/// </summary>
public class ChaXunForm : System.Windows.Forms.Form
{
//定义Grid1变量
DataSet Grid;
string from;
string to;
private System.Windows.Forms.DataGrid Grid1;
private System.Windows.Forms.Button bntGouMai;
private System.Windows.Forms.Button bntNET;
private System.Windows.Forms.Button bntQuXiao;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
ArrayList arr;
int flag;
public ChaXunForm(DataSet Grid1,string from,string to,int flag)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
//没有查到
this.Grid=Grid1;
this.from = from;
this.to = to;
this.arr = arr;
this.flag = flag;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Grid1 = new System.Windows.Forms.DataGrid();
this.bntGouMai = new System.Windows.Forms.Button();
this.bntNET = new System.Windows.Forms.Button();
this.bntQuXiao = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.Grid1)).BeginInit();
this.SuspendLayout();
//
// Grid1
//
this.Grid1.DataMember = "";
this.Grid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.Grid1.Location = new System.Drawing.Point(0, 0);
this.Grid1.Name = "Grid1";
this.Grid1.Size = new System.Drawing.Size(768, 440);
this.Grid1.TabIndex = 0;
//
// bntGouMai
//
this.bntGouMai.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.bntGouMai.ForeColor = System.Drawing.Color.Red;
this.bntGouMai.Location = new System.Drawing.Point(352, 480);
this.bntGouMai.Name = "bntGouMai";
this.bntGouMai.Size = new System.Drawing.Size(104, 48);
this.bntGouMai.TabIndex = 1;
this.bntGouMai.Text = " 购买";
this.bntGouMai.Click += new System.EventHandler(this.bntGouMai_Click);
//
// bntNET
//
this.bntNET.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.bntNET.ForeColor = System.Drawing.Color.Red;
this.bntNET.Location = new System.Drawing.Point(88, 480);
this.bntNET.Name = "bntNET";
this.bntNET.Size = new System.Drawing.Size(120, 48);
this.bntNET.TabIndex = 2;
this.bntNET.Text = "上一步";
this.bntNET.Click += new System.EventHandler(this.bntNET_Click);
//
// bntQuXiao
//
this.bntQuXiao.Font = new System.Drawing.Font("宋体", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.bntQuXiao.ForeColor = System.Drawing.Color.Red;
this.bntQuXiao.Location = new System.Drawing.Point(600, 480);
this.bntQuXiao.Name = "bntQuXiao";
this.bntQuXiao.Size = new System.Drawing.Size(104, 48);
this.bntQuXiao.TabIndex = 3;
this.bntQuXiao.Text = "取消";
this.bntQuXiao.Click += new System.EventHandler(this.bntQuXiao_Click);
//
// ChaXunForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(776, 558);
this.Controls.Add(this.bntQuXiao);
this.Controls.Add(this.bntNET);
this.Controls.Add(this.bntGouMai);
this.Controls.Add(this.Grid1);
this.Name = "ChaXunForm";
this.Text = "查询列车详细表";
this.Load += new System.EventHandler(this.ChaXunForm_Load);
((System.ComponentModel.ISupportInitialize)(this.Grid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 单击上一步单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bntNET_Click(object sender, System.EventArgs e)
{
//隐藏当前界面
this.Close();
}
/// <summary>
/// 购买火车票单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bntGouMai_Click(object sender, System.EventArgs e)
{
//点击Grid1的某行时获得焦点
int row = this.Grid1.CurrentCell.RowNumber;
int col = this.Grid1.CurrentCell.ColumnNumber;
//if(this.Grid1[0,0].ToString().Equals(null))
//if(row>=0 || col>=0)
//{
//MessageBox.Show("您选择的车次不存在,请核实后在操作!!!!!!");
// MessageBox.Show("您购买的是:"+this.Grid1[row,col].ToString()+"列车。请点击'确定'按钮进入网上银行!!!");
//}
//else
//{
MessageBox.Show("您购买的是:"+this.Grid1[row,col].ToString()+"列车。请点击'确定'按钮进入网上银行!!!");
//MessageBox.Show("您选择的车次不存在,请核实后在操作!!!!!!");
//获得车次
string schedulecode=Convert.ToString(this.Grid1[row,0].ToString());
//获得起始站
string fromcity=Convert.ToString(this.Grid1[row,1].ToString());
//获得终点站
string tocity=Convert.ToString(this.Grid1[row,2].ToString());
//获得开车时间
string leavetime=Convert.ToString(this.Grid1[row,4].ToString());
//获得车次类型
string speed=Convert.ToString(this.Grid1[row,5].ToString());
//获得票价
double price = Convert.ToDouble(this.Grid1[row,6].ToString());
//MessageBox.Show("您购买的是:"+this.Grid1[row,col].ToString()+"列车。请点击'确定'按钮进入网上银行!!!");
//隐藏当前界面
this.Hide();
this.Visible=false;
//显示交易界面
WangShangJiaoYi jiaoyi=new WangShangJiaoYi(price,speed,leavetime,tocity,fromcity,schedulecode);
jiaoyi.Show();
}
/// <summary>
/// 取消单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void bntQuXiao_Click(object sender, System.EventArgs e)
{
//隐藏当前界面
this.Hide();
this.Visible=false;
Form2 f=new Form2();
f.Show();
}
T_schedule_detail schedule=new T_schedule_detail();
TrainBussiness1 trainbussiness=new TrainBussiness1();
/// <summary>
/// 加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChaXunForm_Load(object sender, System.EventArgs e)
{
if(flag == 1)
{
//没有查询到
if(this.Grid.Tables[0].Rows.Count==0)
{
//调用业务逻辑层的车次业务处理方法:查询中转站
DataSet ds=trainbussiness.GetZhongZhuanzhan(from,to);
//声明数组
// for(int i=0;i<strArr.Length;++i)
// {
// strArr[i] = new string();
// }
string str="";
//循环遍历
for(int i=0;i<ds.Tables[0].Rows.Count;++i)
{
string s = ds.Tables[0].Rows[i][1].ToString();
str = str + s + "\n";
Form2.arr.Add(s);
}
MessageBox.Show("没有查询到您到达的城市!!!\n请点上一步换成列车(选择中转站)到达!!!\n中转站为:\n"+str);
this.bntGouMai.Enabled = false;
}
else
{
Grid1.DataSource=this.Grid.Tables [0];
}
}
else //根据中转站查询
{
string code1 = this.Grid.Tables[0].Rows[0][0].ToString();
string from1 = this.Grid.Tables[0].Rows[0][1].ToString();
string to1 = this.Grid.Tables[0].Rows[0][2].ToString();
string num1 = this.Grid.Tables[0].Rows[0][3].ToString();
string price1 = this.Grid.Tables[0].Rows[0][4].ToString();
string code2 = this.Grid.Tables[1].Rows[0][0].ToString();
string from2 = this.Grid.Tables[1].Rows[0][1].ToString();
string to2 = this.Grid.Tables[1].Rows[0][2].ToString();
string num2 = this.Grid.Tables[1].Rows[0][3].ToString();
string price2 = this.Grid.Tables[1].Rows[0][4].ToString();
DataTable dt = new DataTable();
dt.Columns.Add("车次",typeof(string));
dt.Columns.Add("始发站",typeof(string));
dt.Columns.Add("到站",typeof(string));
dt.Columns.Add("经过站数",typeof(string));
dt.Columns.Add("票价",typeof(string));
DataRow row = dt.NewRow();
row[0] = code1;
row[1] = from1;
row[2] = to1;
row[3] = num1;
row[4] = price1;
dt.Rows.Add(row);
row = dt.NewRow();
row[0] = code2;
row[1] = from2;
row[2] = to2;
row[3] = num2;
row[4] = price2;
dt.Rows.Add(row);
this.Grid1.DataSource = dt;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -