一共寫了三天終於寫完了.廢話少說,源代碼如下,主要要求用MVC實現,老師還叫我稍微擴展了一下這個系統的功能
主要是數據的導入導出(保存為XML,TXT) .
1.主界面
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace train
...{
/**//// <summary>
/// Form1 的摘要說明。
/// </summary>
public class frmMain : System.Windows.Forms.Form
...{
private System.Windows.Forms.Label lblbeginstation;
private System.Windows.Forms.Label lblmidstation;
private System.Windows.Forms.Label lblfinalstation;
private System.Windows.Forms.Label lbltrainnum;
private System.Windows.Forms.TextBox txtbeginstation;
private System.Windows.Forms.TextBox txtfinalstation;
private System.Windows.Forms.TextBox txttrainnum;
private System.Windows.Forms.Button btnquery1;
&nbs
p; private System.Windows.Forms.Button btnquery2;
private System.Windows.Forms.Panel panel1;
public System.Windows.Forms.TabControl tabdisplay;
private System.Windows.Forms.TabPage tabmap;
private System.Windows.Forms.TabPage tabtrainresult;
private System.Windows.Forms.TabPage tabtraindetails;
public System.Windows.Forms.DataGrid dgtrainresult;
public System.Windows.Forms.DataGrid dgtraindetails;
private System.Windows.Forms.Label lblwlmq;
private System.Windows.Forms.Label lblhm;
private System.Windows.Forms.Label lblgel;
private System.Windows.Forms.Label lblym;
private System.Windows.Forms.Label lblxl;
private System.Windows.Forms.Label lbllz;
private System.Windows.Forms.Label lblxa;
private System.Windows.Forms.Label lblcd;
private System.Windows.Forms.Label lblkm;
private System.Windows.Forms.Label lbllogo;
private ScheduleSystem schedulesystem;
private DataGridPrinter printer;
public System.Windows.Forms.Button btnprint;
public System.Windows.Forms.ComboBox cboMdiStation;
public System.Windows.Forms.Button btnexport;
private ExportData export;
public System.Windows.Forms.Button btnexportXML;
private System.Windows.Forms.Button btnImportData;
/**//// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmMain()
...{
//
// Windows 窗體設計器支持所必需的
//
Application.EnableVisualStyles();
InitializeComponent();
schedulesystem=new ScheduleSystem(this);
export=new ExportData();
//
// TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
//
}
/**//// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
...{
if( disposing )
...{
if (components != null)
...{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗體設計器生成的代碼#region Windows 窗體設計器生成的代碼
/**//// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
...{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.lblbeginstation = new System.Windows.Forms.Label();
this.lblmidstation = new System.Windows.Forms.Label();
this.lblfinalstation = new System.Windows.Forms.Label();
this.txtbeginstation = new System.Windows.Forms.TextBox();
this.txtfinalstation = new System.Windows.Forms.TextBox();
this.cboMdiStation = new System.Windows.Forms.ComboBox();
this.txttrainnum = new System.Windows.Forms.TextBox();
this.lbltrainnum = new System.Windows.Forms.Label();
this.btnquery1 = new System.Windows.Forms.Button();
this.btnquery2 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.tabdisplay = new System.Windows.Forms.TabControl();
this.tabmap = new System.Windows.Forms.TabPage();
this.lbllogo = new System.Windows.Forms.Label();
this.lbllz = new System.Windows.Forms.Label();
this.lblkm = new System.Windows.Forms.Label();
this.lblcd = new System.Windows.Forms.Label();
this.lblxa = new System.Windows.Forms.Label();
this.lblxl = new System.Windows.Forms.Label();
this.lblym = new System.Windows.Forms.Label();
this.lblgel = new System.Windows.Forms.Label();
this.lblhm = new System.Windows.Forms.Label();
this.lblwlmq = new System.Windows.Forms.Label();
this.tabtrainresult = new System.Windows.Forms.TabPage();
this.dgtrainresult = new System.Windows.Forms.DataGrid();
this.tabtraindetails = new System.Windows.Forms.TabPage();
this.dgtraindetails = new System.Windows.Forms.DataGrid();
this.btnprint = new System.Windows.Forms.Button();
this.btnexport = new System.Windows.Forms.Button();
this.btnexportXML = new System.Windows.Forms.Button();
this.btnImportData = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.tabdisplay.SuspendLayout();
this.tabmap.SuspendLayout();
this.tabtrainresult.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgtrainresult)).BeginInit();
this.tabtraindetails.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgtraindetails)).BeginInit();
this.SuspendLayout();
//
// lblbeginstation
//
this.lblbeginstation.Location = new System.Drawing.Point(8, 16);
this.lblbeginstation.Name = "lblbeginstation";
this.lblbeginstation.Size = new System.Drawing.Size(56, 16);
this.lblbeginstation.TabIndex = 0;
this.lblbeginstation.Text = "起始站";
//
// lblmidstation
//
this.lblmidstation.Location = new System.Drawing.Point(112, 16);
this.lblmidstation.Name = "lblmidstation";
this.lblmidstation.Size = new System.Drawing.Size(56, 16);
this.lblmidstation.TabIndex = 1;
this.lblmidstation.Text = "中轉站";
//
// lblfinalstation
//
this.lblfinalstation.Location = new System.Drawing.Point(216, 16);
this.lblfinalstation.Name = "lblfinalstation";
this.lblfinalstation.Size = new System.Drawing.Size(56, 16);
this.lblfinalstation.TabIndex = 2;
this.lblfinalstation.Text = "終點站";
//
// txtbeginstation
//
this.txtbeginstation.Location = new System.Drawing.Point(8, 40);
this.txtbeginstation.Name = "txtbeginstation";
this.txtbeginstation.TabIndex = 3;
this.txtbeginstation.Text = "";
this.txtbeginstation.Enter += new System.EventHandler(this.txtbeginstation_Enter);
//
// txtfinalstation
//
this.txtfinalstation.Location = new System.Drawing.Point(216, 40);
this.txtfinalstation.Name = "txtfinalstation";
this.txtfinalstation.TabIndex = 4;
this.txtfinalstation.Text = "";
this.txtfinalstation.Enter += new System.EventHandler(this.txtbeginstation_Enter);
//
// cboMdiStation
//
this.cboMdiStation.Location = new System.Drawing.Point(112, 40);
this.cboMdiStation.Name = "cboMdiStation";
this.cboMdiStation.Size = new System.Drawing.Size(100, 20);
this.cboMdiStation.TabIndex = 5;
this.cboMdiStation.SelectionChangeCommitted += new System.EventHandler(this.cboMdiStation_SelectionChangeCommitted);
//
// txttrainnum
//
this.txttrainnum.Location = new System.Drawing.Point(400, 40);
this.txttrainnum.Name = "txttrainnum";
this.txttrainnum.Size = new System.Drawing.Size(56, 21);
this.txttrainnum.TabIndex = 6;
this.txttrainnum.Text = "";
this.txttrainnum.Enter += new System.EventHandler(this.txttrainnum_Enter);
//
// lbltrainnum
//
this.lbltrainnum.Location = new System.Drawing.Point(392, 16);
this.lbltrainnum.Name = "lbltrainnum";
this.lbltrainnum.Size = new System.Drawing.Size(56, 16);
this.lbltrainnum.TabIndex = 7;
this.lbltrainnum.Text = "車次";
//
// btnquery1
//
this.btnquery1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnquery1.Location = new System.Drawing.Point(320, 40);
this.btnquery1.Name = "btnquery1";
this.btnquery1.TabIndex = 8;
this.btnquery1.Text = "確定";
this.btnquery1.Click += new System.EventHandler(this.btnquery1_Click);
//
// btnquery2
//
this.btnquery2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnquery2.Location = new System.Drawing.Point(464, 40);
this.btnquery2.Name = "btnquery2";
this.btnquery2.TabIndex = 9;
this.btnquery2.Text = "確定";
this.btnquery2.Click += new System.EventHandler(this.btnquery2_Click);
//
// panel1
//
&n
bsp; this.panel1.Controls.Add(this.tabdisplay);
this.panel1.Location = new System.Drawing.Point(0, 96);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(728, 416);
this.panel1.TabIndex = 10;
//
// tabdisplay
//
this.tabdisplay.Controls.Add(this.tabmap);
this.tabdisplay.Controls.Add(this.tabtrainresult);
this.tabdisplay.Controls.Add(this.tabtraindetails);
this.tabdisplay.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabdisplay.Location = new System.Drawing.Point(0, 0);
this.tabdisplay.Name = "tabdisplay";
this.tabdisplay.SelectedIndex = 0;
this.tabdisplay.Size = new System.Drawing.Size(728, 416);
this.tabdisplay.TabIndex = 0;
this.tabdisplay.SelectedIndexChanged += new System.EventHandler(this.tabdisplay_SelectedIndExchanged);
//
// tabmap
//
this.tabmap.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabmap.BackgroundImage")));
this.tabmap.Controls.Add(this.lbllogo);
this.tabmap.Controls.Add(this.lbllz);
this.tabmap.Controls.Add(this.lblkm);
this.tabmap.Controls.Add(this.lblcd);
this.tabmap.Controls.Add(this.lblxa);
&nbs
p; this.tabmap.Controls.Add(this.lblxl);
this.tabmap.Controls.Add(this.lblym);
this.tabmap.Controls.Add(this.lblgel);
this.tabmap.Controls.Add(this.lblhm);
this.tabmap.Controls.Add(this.lblwlmq);
this.tabmap.Location = new System.Drawing.Point(4, 21);
this.tabmap.Name = "tabmap";
this.tabmap.Size = new System.Drawing.Size(720, 391);
this.tabmap.TabIndex = 0;
this.tabmap.Text = "中國鐵路干線圖";
//
// lbllogo
//
this.lbllogo.BackColor = System.Drawing.Color.Transparent;
this.lbllogo.Font = new System.Drawing.Font("宋體", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.lbllogo.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.lbllogo.Location = new System.Drawing.Point(584, 72);
this.lbllogo.Name = "lbllogo";
this.lbllogo.Size = new System.Drawing.Size(40, 304);
this.lbllogo.TabIndex = 31;
this.lbllogo.Text = "列車時刻查詢系統";
//
// lbllz
//
this.lbllz.BackColor = System.Drawing.Color.Transparent;
this.lbllz.Location = new System.Drawing.Point(296, 200);
this.lbllz.Name = "lbllz";
this.lbllz.Size = new System.Drawing.Size(24, 24);
this.lbllz.TabIndex = 30;
this.lbllz.Tag = "蘭州";
this.lbllz.Click += new System.EventHandler(this.lblwlmq_Click);
//
// lblkm
//
this.lblkm.BackColor = System.Drawing.Color.Transparent;
this.lblkm.Location = new System.Drawing.Point(280, 328);
this.lblkm.Name = "lblkm";
this.lblkm.Size = new System.Drawing.Size(24, 24);
this.lblkm.TabIndex = 29;
this.lblkm.Tag = "昆明";
this.lblkm.Click += new System.EventHandler(this.lblwlmq_Click);
//
// lblcd
//
this.lblcd.BackColor = System.Drawing.Color.Transparent;
this.lblcd.Location = new System.Drawing.Point(296, 256);
this.lblcd.Name = "lblcd";
this.lblcd.Size = new System.Drawing.Size(24, 24);
this.lblcd.TabIndex = 17;
this.lblcd.Tag = "成都";
this.lblcd.Click += new System.EventHandler(this.lblwlmq_Click);
//
// lblxa
//
this.lblxa.BackColor = System.Drawing.Color.Transparent;
this.lblxa.Location = new System.Drawing.Point(320, 216);
this.lblxa.Name = "lblxa";
this.lblxa.Size = new System.Drawing.Size(24, 24);
this.lblxa.TabIndex = 16;
this.lblxa.Tag = "西安";
this.lblxa.Click += new System.EventHandler(this.lblwlmq_Click);
//