using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;

using HISClinic.UIProcess;
using HISClinic.BLL;
using HISClinic.DataModel;

namespace HISClinic
{
	/// <summary>
	/// frmMainForm 的摘要说明。
	/// </summary>
	public class frmMainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu PrescriptionMainMenu;
		private System.Windows.Forms.ToolBar tlbPrescriptionTop;
		private System.Windows.Forms.ToolBarButton btnPrescription;
		private System.Windows.Forms.StatusBar staPrescriptionBottom;
		private System.Windows.Forms.MainMenu RegistrationMainMenu;		
		private System.Windows.Forms.ToolBarButton btnRegistration;
		private System.Windows.Forms.ToolBarButton btnPatientNew;
		private System.Windows.Forms.ToolBarButton btnPatientEdit;
		private System.Windows.Forms.ToolBar tlbRegistrationTop;
		private System.Windows.Forms.StatusBar staRegistrationBottom;
		private System.Windows.Forms.MainMenu BillOfPrescriptionMainMenu;
		private System.Windows.Forms.ToolBar tlbBillOfPrescriptionTop;
		private System.Windows.Forms.ToolBarButton btnBillOfPrescrition;
		private System.Windows.Forms.StatusBar staBillOfPrescritptionBottom;
		private System.Windows.Forms.MenuItem mnuPrescription;
		private System.Windows.Forms.MenuItem mitmPrescription;
		private System.Windows.Forms.MenuItem mnuRegistration;
		private System.Windows.Forms.MenuItem mitmRegistration;
		private System.Windows.Forms.MenuItem mitmPatientNew;
		private System.Windows.Forms.MenuItem mitmPatientEdit;
		private System.Windows.Forms.MenuItem mitmBillOfPrescritption;
		private System.Windows.Forms.MenuItem mnuBillOfPrescription;
		private System.Windows.Forms.MenuItem mitmBillOfPrescription;
		private System.Windows.Forms.MenuItem mitmS1;
		private System.Windows.Forms.StatusBarPanel pnlDoctorName;
		private System.Windows.Forms.StatusBarPanel pnlDepartmentName;
		private System.Windows.Forms.StatusBarPanel pnlCashierName;
		private System.Windows.Forms.StatusBarPanel p31;
		private System.Windows.Forms.StatusBarPanel p32;
		private System.Windows.Forms.StatusBarPanel p33;
		private System.Windows.Forms.StatusBarPanel p11;
		private System.Windows.Forms.StatusBarPanel pnlRegistrarName;
		private System.Windows.Forms.StatusBarPanel p13;
		private System.Windows.Forms.StatusBarPanel p21;
		private System.Windows.Forms.StatusBarPanel p22;
		private System.Windows.Forms.MainMenu AdmintratormainMenu;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem mitmShowRegistrarUI;
		private System.Windows.Forms.MenuItem mitmShowDoctorUI;
		private System.Windows.Forms.MenuItem mitmShowCashierUI;
		private System.Windows.Forms.MenuItem mitmReLogin;
		private System.Windows.Forms.MenuItem mitmQuit;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MainMenu SystemMainmenu;
		private System.Windows.Forms.MenuItem mnuSystem;
		private System.Windows.Forms.MainMenu DislpayMainmen;

		private SelfUpdater updater;
		private System.Windows.Forms.MenuItem mnuSetInterval;
		private System.Windows.Forms.MenuItem mnuStartUpdate;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.ImageList imgList;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.MenuItem mnuLog;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.ComponentModel.IContainer components;

		public frmMainForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			//Init update obeject
			updater=new SelfUpdater();
			updater.MsgBoxOwner=this;
			updater.UpdaterStateCallBack=new UpdaterCallBackHandle(UpdateMenuState);
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}
		/// <summary>
		/// 重新启动更新
		/// </summary>
		private void ReStartUpdate(){
			updater.ReStartUpdate();
		}
		private void UpdateMenuState(object sender,UpdaterArgs args){
			if(args.IsRunning)
				mnuStartUpdate.Text="停止更新";
			else
				mnuStartUpdate.Text="开始更新";
		}
		/// <summary>
		/// 停止更新
		/// </summary>
		private void StopUpdater(){
			if(null!=updater){
				updater.StopUpdate();
			}
		}
		

		/// <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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMainForm));
			this.PrescriptionMainMenu = new System.Windows.Forms.MainMenu();
			this.mnuPrescription = new System.Windows.Forms.MenuItem();
			this.mitmPrescription = new System.Windows.Forms.MenuItem();
			this.tlbPrescriptionTop = new System.Windows.Forms.ToolBar();
			this.btnPrescription = new System.Windows.Forms.ToolBarButton();
			this.imgList = new System.Windows.Forms.ImageList(this.components);
			this.staPrescriptionBottom = new System.Windows.Forms.StatusBar();
			this.p31 = new System.Windows.Forms.StatusBarPanel();
			this.pnlDoctorName = new System.Windows.Forms.StatusBarPanel();
			this.p32 = new System.Windows.Forms.StatusBarPanel();
			this.pnlDepartmentName = new System.Windows.Forms.StatusBarPanel();
			this.p33 = new System.Windows.Forms.StatusBarPanel();
			this.RegistrationMainMenu = new System.Windows.Forms.MainMenu();
			this.mnuRegistration = new System.Windows.Forms.MenuItem();
			this.mitmRegistration = new System.Windows.Forms.MenuItem();
			this.mitmS1 = new System.Windows.Forms.MenuItem();
			this.mitmPatientNew = new System.Windows.Forms.MenuItem();
			this.mitmPatientEdit = new System.Windows.Forms.MenuItem();
			this.tlbRegistrationTop = new System.Windows.Forms.ToolBar();
			this.btnRegistration = new System.Windows.Forms.ToolBarButton();
			this.btnPatientNew = new System.Windows.Forms.ToolBarButton();
			this.btnPatientEdit = new System.Windows.Forms.ToolBarButton();
			this.staRegistrationBottom = new System.Windows.Forms.StatusBar();
			this.p11 = new System.Windows.Forms.StatusBarPanel();
			this.pnlRegistrarName = new System.Windows.Forms.StatusBarPanel();
			this.p13 = new System.Windows.Forms.StatusBarPanel();
			this.BillOfPrescriptionMainMenu = new System.Windows.Forms.MainMenu();
			this.mnuBillOfPrescription = new System.Windows.Forms.MenuItem();
			this.mitmBillOfPrescription = new System.Windows.Forms.MenuItem();
			this.mitmBillOfPrescritption = new System.Windows.Forms.MenuItem();
			this.tlbBillOfPrescriptionTop = new System.Windows.Forms.ToolBar();
			this.btnBillOfPrescrition = new System.Windows.Forms.ToolBarButton();
			this.staBillOfPrescritptionBottom = new System.Windows.Forms.StatusBar();
			this.p21 = new System.Windows.Forms.StatusBarPanel();
			this.pnlCashierName = new System.Windows.Forms.StatusBarPanel();
			this.p22 = new System.Windows.Forms.StatusBarPanel();
			this.AdmintratormainMenu = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.mitmShowRegistrarUI = new System.Windows.Forms.MenuItem();
			this.mitmShowDoctorUI = new System.Windows.Forms.MenuItem();
			this.mitmShowCashierUI = new System.Windows.Forms.MenuItem();
			this.SystemMainmenu = new System.Windows.Forms.MainMenu();
			this.mnuSystem = new System.Windows.Forms.MenuItem();
			this.mitmReLogin = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.mnuSetInterval = new System.Windows.Forms.MenuItem();
			this.mnuLog = new System.Windows.Forms.MenuItem();
			this.mnuStartUpdate = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.mitmQuit = new System.Windows.Forms.MenuItem();
			this.DislpayMainmen = new System.Windows.Forms.MainMenu();
			this.panel1 = new System.Windows.Forms.Panel();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			((System.ComponentModel.ISupportInitialize)(this.p31)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlDoctorName)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.p32)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlDepartmentName)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.p33)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.p11)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlRegistrarName)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.p13)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.p21)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlCashierName)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.p22)).BeginInit();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// PrescriptionMainMenu
			// 
			this.PrescriptionMainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																								 this.mnuPrescription});
			// 
			// mnuPrescription
			// 
			this.mnuPrescription.Index = 0;
			this.mnuPrescription.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							this.mitmPrescription});
			this.mnuPrescription.Text = "[&C].门诊就诊";
			this.mnuPrescription.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// mitmPrescription
			// 
			this.mitmPrescription.Index = 0;
			this.mitmPrescription.Text = "就诊(&P)";
			this.mitmPrescription.Click += new System.EventHandler(this.mitmPrescription_Click);
			// 
			// tlbPrescriptionTop
			// 
			this.tlbPrescriptionTop.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tlbPrescriptionTop.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																								  this.btnPrescription});
			this.tlbPrescriptionTop.ButtonSize = new System.Drawing.Size(55, 35);
			this.tlbPrescriptionTop.Divider = false;
			this.tlbPrescriptionTop.DropDownArrows = true;
			this.tlbPrescriptionTop.ImageList = this.imgList;
			this.tlbPrescriptionTop.Location = new System.Drawing.Point(0, 0);
			this.tlbPrescriptionTop.Name = "tlbPrescriptionTop";
			this.tlbPrescriptionTop.ShowToolTips = true;
			this.tlbPrescriptionTop.Size = new System.Drawing.Size(635, 42);
			this.tlbPrescriptionTop.TabIndex = 6;
			this.tlbPrescriptionTop.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
			this.tlbPrescriptionTop.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tlbPrescriptionTop_ButtonClick);
			// 
			// btnPrescription
			// 
			this.btnPrescription.ImageIndex = 4;
			this.btnPrescription.Text = "门诊就诊";
			this.btnPrescription.ToolTipText = "门诊就诊";
			// 
			// imgList
			// 
			this.imgList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
			this.imgList.ImageSize = new System.Drawing.Size(32, 32);
			this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
			this.imgList.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// staPrescriptionBottom
			// 
			this.staPrescriptionBottom.Location = new System.Drawing.Point(0, 403);
			this.staPrescriptionBottom.Name = "staPrescriptionBottom";
			this.staPrescriptionBottom.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																									 this.p31,
																									 this.pnlDoctorName,
																									 this.p32,
																									 this.pnlDepartmentName,
																									 this.p33});
			this.staPrescriptionBottom.ShowPanels = true;
			this.staPrescriptionBottom.Size = new System.Drawing.Size(635, 22);
			this.staPrescriptionBottom.TabIndex = 7;
			// 
			// p31
			// 
			this.p31.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
			this.p31.Text = "当前用户：";
			// 
			// p32
			// 
			this.p32.Alignment = System.Windows.Forms.HorizontalAlignment.Center;
			this.p32.Text = "所属部门：";
			// 
			// p33
			// 
			this.p33.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.p33.Width = 219;
			// 
			// RegistrationMainMenu
			// 
			this.RegistrationMainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																								 this.mnuRegistration});
			// 
			// mnuRegistration
			// 
			this.mnuRegistration.Index = 0;
			this.mnuRegistration.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																							this.mitmRegistration,
																							this.mitmS1,
																							this.mitmPatientNew,
																							this.mitmPatientEdit});
			this.mnuRegistration.Text = "[&C].门诊挂号";
			// 
			// mitmRegistration
			// 
			this.mitmRegistration.Index = 0;
			this.mitmRegistration.Text = "挂号(&R)";
			this.mitmRegistration.Click += new System.EventHandler(this.mitmRegistration_Click);
			// 
			// mitmS1
			// 
			this.mitmS1.Index = 1;
			this.mitmS1.Text = "-";
			// 
			// mitmPatientNew
			// 
			this.mitmPatientNew.Index = 2;
			this.mitmPatientNew.Text = "注册病人信息(&N)";
			this.mitmPatientNew.Click += new System.EventHandler(this.mitmPatientNew_Click);
			// 
			// mitmPatientEdit
			// 
			this.mitmPatientEdit.Index = 3;
			this.mitmPatientEdit.Text = "修改病人信息(&E) ";
			this.mitmPatientEdit.Click += new System.EventHandler(this.mitmPatientEdit_Click);
			// 
			// tlbRegistrationTop
			// 
			this.tlbRegistrationTop.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tlbRegistrationTop.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																								  this.btnRegistration,
																								  this.btnPatientNew,
																								  this.btnPatientEdit});
			this.tlbRegistrationTop.ButtonSize = new System.Drawing.Size(100, 35);
			this.tlbRegistrationTop.Divider = false;
			this.tlbRegistrationTop.DropDownArrows = true;
			this.tlbRegistrationTop.ImageList = this.imgList;
			this.tlbRegistrationTop.Location = new System.Drawing.Point(0, 42);
			this.tlbRegistrationTop.Name = "tlbRegistrationTop";
			this.tlbRegistrationTop.ShowToolTips = true;
			this.tlbRegistrationTop.Size = new System.Drawing.Size(635, 42);
			this.tlbRegistrationTop.TabIndex = 9;
			this.tlbRegistrationTop.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
			this.tlbRegistrationTop.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tlbRegistrationTop_ButtonClick);
			// 
			// btnRegistration
			// 
			this.btnRegistration.ImageIndex = 0;
			this.btnRegistration.Text = "门诊挂号";
			this.btnRegistration.ToolTipText = "门诊挂号";
			// 
			// btnPatientNew
			// 
			this.btnPatientNew.ImageIndex = 1;
			this.btnPatientNew.Text = "注册病人";
			this.btnPatientNew.ToolTipText = "注册病人信息";
			// 
			// btnPatientEdit
			// 
			this.btnPatientEdit.ImageIndex = 5;
			this.btnPatientEdit.Text = "修改病人";
			this.btnPatientEdit.ToolTipText = "修改病人信息";
			// 
			// staRegistrationBottom
			// 
			this.staRegistrationBottom.Location = new System.Drawing.Point(0, 380);
			this.staRegistrationBottom.Name = "staRegistrationBottom";
			this.staRegistrationBottom.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																									 this.p11,
																									 this.pnlRegistrarName,
																									 this.p13});
			this.staRegistrationBottom.ShowPanels = true;
			this.staRegistrationBottom.Size = new System.Drawing.Size(635, 23);
			this.staRegistrationBottom.TabIndex = 10;
			// 
			// p11
			// 
			this.p11.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
			this.p11.Text = "当前用户：";
			// 
			// p13
			// 
			this.p13.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.p13.Width = 419;
			// 
			// BillOfPrescriptionMainMenu
			// 
			this.BillOfPrescriptionMainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																									   this.mnuBillOfPrescription});
			// 
			// mnuBillOfPrescription
			// 
			this.mnuBillOfPrescription.Index = 0;
			this.mnuBillOfPrescription.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																								  this.mitmBillOfPrescription});
			this.mnuBillOfPrescription.Text = "[&C].门诊收费";
			// 
			// mitmBillOfPrescription
			// 
			this.mitmBillOfPrescription.Index = 0;
			this.mitmBillOfPrescription.Text = "收费(&B)";
			this.mitmBillOfPrescription.Click += new System.EventHandler(this.mitmBillOfPrescription_Click);
			// 
			// mitmBillOfPrescritption
			// 
			this.mitmBillOfPrescritption.Index = -1;
			this.mitmBillOfPrescritption.Text = "收费(&B)";
			// 
			// tlbBillOfPrescriptionTop
			// 
			this.tlbBillOfPrescriptionTop.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tlbBillOfPrescriptionTop.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																										this.btnBillOfPrescrition});
			this.tlbBillOfPrescriptionTop.Divider = false;
			this.tlbBillOfPrescriptionTop.DropDownArrows = true;
			this.tlbBillOfPrescriptionTop.ImageList = this.imgList;
			this.tlbBillOfPrescriptionTop.Location = new System.Drawing.Point(0, 84);
			this.tlbBillOfPrescriptionTop.Name = "tlbBillOfPrescriptionTop";
			this.tlbBillOfPrescriptionTop.ShowToolTips = true;
			this.tlbBillOfPrescriptionTop.Size = new System.Drawing.Size(635, 42);
			this.tlbBillOfPrescriptionTop.TabIndex = 11;
			this.tlbBillOfPrescriptionTop.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
			this.tlbBillOfPrescriptionTop.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tlbBillOfPrescriptionTop_ButtonClick);
			// 
			// btnBillOfPrescrition
			// 
			this.btnBillOfPrescrition.ImageIndex = 2;
			this.btnBillOfPrescrition.Text = "门诊收费";
			// 
			// staBillOfPrescritptionBottom
			// 
			this.staBillOfPrescritptionBottom.Location = new System.Drawing.Point(0, 359);
			this.staBillOfPrescritptionBottom.Name = "staBillOfPrescritptionBottom";
			this.staBillOfPrescritptionBottom.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																											this.p21,
																											this.pnlCashierName,
																											this.p22});
			this.staBillOfPrescritptionBottom.ShowPanels = true;
			this.staBillOfPrescritptionBottom.Size = new System.Drawing.Size(635, 21);
			this.staBillOfPrescritptionBottom.TabIndex = 12;
			// 
			// p21
			// 
			this.p21.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
			this.p21.Text = "当前用户：";
			// 
			// p22
			// 
			this.p22.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.p22.Width = 419;
			// 
			// AdmintratormainMenu
			// 
			this.AdmintratormainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																								this.menuItem1});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.mitmShowRegistrarUI,
																					  this.mitmShowDoctorUI,
																					  this.mitmShowCashierUI});
			this.menuItem1.Text = "[&T].切换";
			// 
			// mitmShowRegistrarUI
			// 
			this.mitmShowRegistrarUI.Index = 0;
			this.mitmShowRegistrarUI.Text = "挂号界面(&R)";
			this.mitmShowRegistrarUI.Click += new System.EventHandler(this.mitmShowRegistrarUI_Click);
			// 
			// mitmShowDoctorUI
			// 
			this.mitmShowDoctorUI.Index = 1;
			this.mitmShowDoctorUI.Text = "就诊界面(&P)";
			this.mitmShowDoctorUI.Click += new System.EventHandler(this.mitmShowDoctorUI_Click);
			// 
			// mitmShowCashierUI
			// 
			this.mitmShowCashierUI.Index = 2;
			this.mitmShowCashierUI.Text = "收费界面(&B)";
			this.mitmShowCashierUI.Click += new System.EventHandler(this.mitmShowCashierUI_Click);
			// 
			// SystemMainmenu
			// 
			this.SystemMainmenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						   this.mnuSystem});
			// 
			// mnuSystem
			// 
			this.mnuSystem.Index = 0;
			this.mnuSystem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.mitmReLogin,
																					  this.menuItem4,
																					  this.mnuSetInterval,
																					  this.mnuLog,
																					  this.mnuStartUpdate,
																					  this.menuItem5,
																					  this.mitmQuit});
			this.mnuSystem.Text = "[&S].系统";
			// 
			// mitmReLogin
			// 
			this.mitmReLogin.Index = 0;
			this.mitmReLogin.Text = "重新登录(&R)";
			this.mitmReLogin.Click += new System.EventHandler(this.mitmReLogin_Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 1;
			this.menuItem4.Text = "-";
			// 
			// mnuSetInterval
			// 
			this.mnuSetInterval.Index = 2;
			this.mnuSetInterval.MdiList = true;
			this.mnuSetInterval.Text = "更新间隔";
			this.mnuSetInterval.Click += new System.EventHandler(this.mnuSetInterval_Click);
			// 
			// mnuLog
			// 
			this.mnuLog.Index = 3;
			this.mnuLog.Text = "更新日志";
			this.mnuLog.Click += new System.EventHandler(this.mnuLog_Click);
			// 
			// mnuStartUpdate
			// 
			this.mnuStartUpdate.Index = 4;
			this.mnuStartUpdate.Text = "停止更新";
			this.mnuStartUpdate.Click += new System.EventHandler(this.mnuStartUpdate_Click);
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 5;
			this.menuItem5.Text = "-";
			// 
			// mitmQuit
			// 
			this.mitmQuit.Index = 6;
			this.mitmQuit.Text = "退出(&Q)";
			this.mitmQuit.Click += new System.EventHandler(this.mitmQuit_Click);
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.SystemColors.ControlLightLight;
			this.panel1.Controls.Add(this.pictureBox1);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel1.Location = new System.Drawing.Point(0, 126);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(635, 233);
			this.panel1.TabIndex = 14;
			// 
			// pictureBox1
			// 
			this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(0, 0);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(635, 233);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			// 
			// frmMainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.ClientSize = new System.Drawing.Size(635, 425);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.staBillOfPrescritptionBottom);
			this.Controls.Add(this.tlbBillOfPrescriptionTop);
			this.Controls.Add(this.staRegistrationBottom);
			this.Controls.Add(this.tlbRegistrationTop);
			this.Controls.Add(this.staPrescriptionBottom);
			this.Controls.Add(this.tlbPrescriptionTop);
			this.IsMdiContainer = true;
			this.Name = "frmMainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "医院信息系统--门诊部";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.frmMainForm_Load);
			this.Closed += new System.EventHandler(this.frmMainForm_Closed);
			((System.ComponentModel.ISupportInitialize)(this.p31)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlDoctorName)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.p32)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlDepartmentName)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.p33)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.p11)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlRegistrarName)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.p13)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.p21)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.pnlCashierName)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.p22)).EndInit();
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
		
		}

		private void frmMainForm_Load(object sender, System.EventArgs e)
		{	
			ShowLoginForm();
			updater.StartUpdate();
		}

		private void ShowLoginForm()
		{
			this.Hide();

			frmLogin frmlogin=new frmLogin();

			if(frmlogin.ShowDialog()==DialogResult.OK)
			{
				frmlogin.Dispose();
				SettingUIAndLoadCacheData();
				this.Show();
			}
			else
			{
				frmlogin.Dispose();
				this.Close();
			}	
		}

		private void SettingUIAndLoadCacheData()
		{
			if(CacheDataManager.GetCacheData(UsersEx.t_UserDataTableEx.TableName_User) != null)
			{
				int RoleID=Convert.ToInt32(((UsersEx)CacheDataManager.GetCacheData(UsersEx.t_UserDataTableEx.TableName_User)).t_User.Rows[0][UsersEx.t_UserDataTableEx.FIELD_RoleID]);
					
				switch((UsersEx.RoleEnum)RoleID)
				{
					case UsersEx.RoleEnum.RegisterPerson:	
						ShowRegistrarUI(false);
						break;

					case UsersEx.RoleEnum.Doctor:						
						LoadDoctorCacheData();
						ShowDoctorUI(false);
						break;

					case UsersEx.RoleEnum.Cashier:
						ShowCashierUI(false);
						break;

					case UsersEx.RoleEnum.Administrator:
						LoadDoctorCacheData();
						ShowAdminitratorUI();
						break;

					default:
						this.Close();
						break;
				}
			}
		}

		private void LoadDoctorCacheData()
		{
			//将药品信息缓存起来

			Thread thread1=new  Thread(new ThreadStart(LoadMedicineInfoToCache));
			thread1.Start();
							
			//将药品用法缓存起来
							
			Thread thread2=new Thread(new ThreadStart(LoadMedicineCommonUsageToCache));
			thread2.Start();							
							
			//将疾病信息缓存起来
							
			Thread thread3=new Thread(new ThreadStart(LoadDiseaseToCache));
			thread3.Start();
							
			//将登录医生的信息缓存起来
			Thread thread4=new Thread(new ThreadStart(LoadDoctorInfoToCache));
			thread4.Start();
		}

		/// <summary>
		/// 将药品信息Load入缓存
		/// </summary>
		private void LoadMedicineInfoToCache()
		{
			MedicinesEx medicinesEx=(new Medicine()).GetMedicine();
			
			if(medicinesEx != null)
			{
				CacheDataManager.SetCacheData(MedicinesEx.t_MedicineDataTableEx.TableName_Medicine,medicinesEx);
			}
		}

		/// <summary>
		/// 将药品用法Load入缓存
		/// </summary>
		private void LoadMedicineCommonUsageToCache()
		{
			CommonUsagesEx commonUsagesEx=(new Medicine.CommonUsage()).GetCommonUsage();

			if(commonUsagesEx != null)
			{
				CacheDataManager.SetCacheData(CommonUsagesEx.t_CommonUsageDataTableEx.TableName_CommonUsage,commonUsagesEx);
			}
		}

		/// <summary>
		/// 将疾病信息Load入缓存
		/// </summary>
		private void LoadDiseaseToCache()
		{
			DiseasesEx diseasesEx=(new Disease()).GetDisease();

			if(diseasesEx != null)
			{
				CacheDataManager.SetCacheData(DiseasesEx.t_DiseaseDataTableEx.TableName_Disease,diseasesEx);
			}
		}

		/// <summary>
		/// 将登录系统的医生个人信息Load入缓存
		/// </summary>
		private void LoadDoctorInfoToCache()
		{
			UsersEx usersEx=(UsersEx)CacheDataManager.GetCacheData(UsersEx.t_UserDataTableEx.TableName_User);
			int UserID=Convert.ToInt32(usersEx.t_User.Rows[0][UsersEx.t_UserDataTableEx.FIELD_UserID]);
			DoctorsEx doctorsEx=(new User.Doctor()).GetDoctor(UserID);

			if(doctorsEx != null)
			{
				CacheDataManager.SetCacheData(DoctorsEx.t_DoctorDataTableEx.TableName_Doctor,doctorsEx);
			}
		}

		
		private void ShowAdminitratorUI()
		{
			ShowRegistrarUI(true);
		}

		private void ShowRegistrarUI(bool showAdministratorMenu)
		{
			this.DislpayMainmen.MenuItems.Clear();
			this.DislpayMainmen.MergeMenu(RegistrationMainMenu);
			if(showAdministratorMenu)
			{
				this.DislpayMainmen.MergeMenu(AdmintratormainMenu);
			}
			this.DislpayMainmen.MergeMenu(SystemMainmenu);

			this.Menu=DislpayMainmen;

			this.Controls.Remove(tlbBillOfPrescriptionTop);
			this.Controls.Remove(tlbPrescriptionTop);
			this.Controls.Remove(staPrescriptionBottom);
			this.Controls.Remove(staBillOfPrescritptionBottom);
			this.Controls.Add(tlbRegistrationTop);
			this.Controls.Add(staRegistrationBottom);
			pnlRegistrarName.Text=((UsersEx)CacheDataManager.GetCacheData(UsersEx.t_UserDataTableEx.TableName_User)).t_User.Rows[0][UsersEx.t_UserDataTableEx.FIELD_Name].ToString();
		}

		private void ShowDoctorUI(bool showAdministratorMenu)
		{
			this.DislpayMainmen.MenuItems.Clear();
			this.DislpayMainmen.MergeMenu(PrescriptionMainMenu);
			if(showAdministratorMenu)
			{
				this.DislpayMainmen.MergeMenu(AdmintratormainMenu);
			}
			this.DislpayMainmen.MergeMenu(SystemMainmenu);
			this.Menu=DislpayMainmen;

			this.Controls.Remove(tlbBillOfPrescriptionTop);
			this.Controls.Remove(tlbRegistrationTop);
			this.Controls.Remove(staRegistrationBottom);
			this.Controls.Remove(staBillOfPrescritptionBottom);

			this.Controls.Add(tlbPrescriptionTop);
			this.Controls.Add(staPrescriptionBottom);

			UsersEx usersEx=(UsersEx)CacheDataManager.GetCacheData(UsersEx.t_UserDataTableEx.TableName_User);
			pnlDoctorName.Text=usersEx.t_User.Rows[0][UsersEx.t_UserDataTableEx.FIELD_Name].ToString();
			pnlDepartmentName.Text=usersEx.t_User.Rows[0][UsersEx.t_UserDataTableEx.FIELD_DepartmentName].ToString();
		}

		private void ShowCashierUI(bool showAdministratorMenu)
		{
			this.DislpayMainmen.MenuItems.Clear();
			this.DislpayMainmen.MergeMenu(BillOfPrescriptionMainMenu);
			if(showAdministratorMenu)
			{
				this.DislpayMainmen.MergeMenu(AdmintratormainMenu);
			}
			this.DislpayMainmen.MergeMenu(SystemMainmenu);
			this.Menu=DislpayMainmen;

			this.Controls.Remove(tlbRegistrationTop);
			this.Controls.Remove(tlbPrescriptionTop);
			this.Controls.Remove(staPrescriptionBottom);
			this.Controls.Remove(staRegistrationBottom);

			this.Controls.Add(tlbBillOfPrescriptionTop);
			this.Controls.Add(staBillOfPrescritptionBottom);

			pnlCashierName.Text=((UsersEx)CacheDataManager.GetCacheData(UsersEx.t_UserDataTableEx.TableName_User)).t_User.Rows[0][UsersEx.t_UserDataTableEx.FIELD_Name].ToString();			
		}

		/// <summary>
		/// 打开注册病人信息的窗口
		/// </summary>
		private void ShowPatientNewForm()
		{
			frmPatientNew frmpatientNew=new frmPatientNew();
			frmpatientNew.ShowDialog();
			frmpatientNew.Dispose();
		}

		/// <summary>
		/// 打开修改病人信息的窗口
		/// </summary>
		private void ShowPatientEditForm()
		{
			frmPatientEdit frmpatientEdit=new frmPatientEdit();
			frmpatientEdit.ShowDialog();
			frmpatientEdit.Dispose();
		}

		/// <summary>
		/// 打开挂号窗口
		/// </summary>
		private void ShowRegistrationNewForm()
		{
			frmRegistrationNew frmregistrationNew=new frmRegistrationNew();
			frmregistrationNew.ShowDialog();
			frmregistrationNew.Dispose();
		}

		private void tlbRegistrationTop_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(tlbRegistrationTop.Buttons.IndexOf(e.Button))
			{
					//打开挂号窗口
				case 0:
					ShowRegistrationNewForm();
					break;

					//打开注册病人窗口
				case 1:
					ShowPatientNewForm();
					break;

					//打开修改病人信息窗口
				case 2:
					ShowPatientEditForm();
					break;

				default:
					break;
			}
		}

		private void mitmRegistration_Click(object sender, System.EventArgs e)
		{
			ShowRegistrationNewForm();
		}

		private void mitmPatientNew_Click(object sender, System.EventArgs e)
		{
			ShowPatientNewForm();
		}

		private void mitmPatientEdit_Click(object sender, System.EventArgs e)
		{
			ShowPatientEditForm();
		}

		private void tlbPrescriptionTop_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(tlbPrescriptionTop.Buttons.IndexOf(e.Button))
			{
				case 0:
					ShowPrescriptionNewForm();
					break;	
				default:
					break;
			}
		}
		/// <summary>
		/// 打开开处方的窗口
		/// </summary>
		private void ShowPrescriptionNewForm()
		{
			frmPrescriptionNew frmprescriptionNew=new frmPrescriptionNew();
			frmprescriptionNew.ShowDialog();
			frmprescriptionNew.Dispose();
		}

		private void mitmPrescription_Click(object sender, System.EventArgs e)
		{
			ShowPrescriptionNewForm();
		}

		/// <summary>
		/// 打开门诊收费的窗口
		/// </summary>
		private void ShowBillOfPrescriptionNewForm()
		{
			frmBillOfPrescriptionNew frmbillOfPrescriptionNew=new frmBillOfPrescriptionNew();
			frmbillOfPrescriptionNew.ShowDialog();
			frmbillOfPrescriptionNew.Dispose();
		}

		private void tlbBillOfPrescriptionTop_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(tlbBillOfPrescriptionTop.Buttons.IndexOf(e.Button))
			{
					//打开门诊收费窗口
				case 0:
					ShowBillOfPrescriptionNewForm();
					break;

				default:
					break;
			}
		}

		private void mitmBillOfPrescription_Click(object sender, System.EventArgs e)
		{
			ShowBillOfPrescriptionNewForm();
		}

		private void mitmShowRegistrarUI_Click(object sender, System.EventArgs e)
		{
			ShowRegistrarUI(true);
		}

		private void mitmShowDoctorUI_Click(object sender, System.EventArgs e)
		{
			ShowDoctorUI(true);
		}

		private void mitmShowCashierUI_Click(object sender, System.EventArgs e)
		{	
			ShowCashierUI(true);
		}

		private void mitmReLogin_Click(object sender, System.EventArgs e)
		{
			ShowLoginForm();
		}

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

		private void frmMainForm_Closed(object sender, System.EventArgs e)
		{
			StopUpdater();
			Environment.Exit(0);
		}

		private void mnuStartUpdate_Click(object sender, System.EventArgs e)
		{
			try
			{
				
				if((sender as MenuItem).Text=="停止更新"){
					StopUpdater();
					(sender as MenuItem).Text="开始更新";
					
				}
				else{
					updater.ReStartUpdate();
					(sender as MenuItem).Text="停止更新";
					}
			}
			catch(Exception ex){
				MessageBox.Show(ex.Message,"",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}
		private void mnuSetInterval_Click(object sender, System.EventArgs e)
		{
			frmSetInterval frm=new frmSetInterval(updater.Interval);
			frm.ShowDialog();
			if(frm.DialogResult==DialogResult.OK){
				int interval=frm.UpdateInterval;
				updater.Interval =interval;
			}
			frm.Dispose();
		}

		private void mnuLog_Click(object sender, System.EventArgs e)
		{
			frmLog frm=new frmLog();
			frm.LogFile=updater.LogFile;
			frm.ShowDialog();
			if(frm.DialogResult==DialogResult.OK){
				updater.LogFile=frm.LogFile;
			}
			frm.Dispose();
		}
	}
}
