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

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

namespace HISClinic
{
	/// <summary>
	/// frmSelectDisease 的摘要说明。
	/// </summary>
	public class frmSelectDisease : System.Windows.Forms.Form
	{

		private DataView _dvDiseases;
		private DiseasesEx.t_DiseaseRow _DiseaseRow;

		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox txtbopomofo;
		private System.Windows.Forms.Label lblbopomofo;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.DataGrid grdDisease;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.PictureBox pictureBox11;
		private System.Windows.Forms.PictureBox pictureBox2;
		private System.Windows.Forms.PictureBox pictureBox3;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.PictureBox pictureBox4;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public DiseasesEx.t_DiseaseRow DiseaseRow
		{
			get
			{
				return _DiseaseRow;
			}
		}

		public frmSelectDisease()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmSelectDisease));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.pictureBox3 = new System.Windows.Forms.PictureBox();
			this.pictureBox2 = new System.Windows.Forms.PictureBox();
			this.pictureBox11 = new System.Windows.Forms.PictureBox();
			this.button1 = new System.Windows.Forms.Button();
			this.txtbopomofo = new System.Windows.Forms.TextBox();
			this.lblbopomofo = new System.Windows.Forms.Label();
			this.grdDisease = new System.Windows.Forms.DataGrid();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.pictureBox4 = new System.Windows.Forms.PictureBox();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.panel2 = new System.Windows.Forms.Panel();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.grdDisease)).BeginInit();
			this.panel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.BackColor = System.Drawing.Color.AliceBlue;
			this.groupBox1.Controls.Add(this.panel2);
			this.groupBox1.Controls.Add(this.pictureBox11);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.txtbopomofo);
			this.groupBox1.Controls.Add(this.lblbopomofo);
			this.groupBox1.Controls.Add(this.grdDisease);
			this.groupBox1.Controls.Add(this.pictureBox1);
			this.groupBox1.Controls.Add(this.pictureBox4);
			this.groupBox1.Location = new System.Drawing.Point(7, 7);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(440, 305);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// pictureBox3
			// 
			this.pictureBox3.BackColor = System.Drawing.SystemColors.ControlLightLight;
			this.pictureBox3.Dock = System.Windows.Forms.DockStyle.Left;
			this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));
			this.pictureBox3.Location = new System.Drawing.Point(0, 0);
			this.pictureBox3.Name = "pictureBox3";
			this.pictureBox3.Size = new System.Drawing.Size(320, 25);
			this.pictureBox3.TabIndex = 14;
			this.pictureBox3.TabStop = false;
			// 
			// pictureBox2
			// 
			this.pictureBox2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox2.BackgroundImage")));
			this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Right;
			this.pictureBox2.Location = new System.Drawing.Point(320, 0);
			this.pictureBox2.Name = "pictureBox2";
			this.pictureBox2.Size = new System.Drawing.Size(120, 25);
			this.pictureBox2.TabIndex = 13;
			this.pictureBox2.TabStop = false;
			// 
			// pictureBox11
			// 
			this.pictureBox11.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox11.Image")));
			this.pictureBox11.Location = new System.Drawing.Point(0, 25);
			this.pictureBox11.Name = "pictureBox11";
			this.pictureBox11.Size = new System.Drawing.Size(440, 6);
			this.pictureBox11.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox11.TabIndex = 12;
			this.pictureBox11.TabStop = false;
			// 
			// button1
			// 
			this.button1.BackColor = System.Drawing.SystemColors.InactiveBorder;
			this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.ForeColor = System.Drawing.SystemColors.Desktop;
			this.button1.Location = new System.Drawing.Point(248, 40);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 23);
			this.button1.TabIndex = 2;
			this.button1.Text = "查 找";
			// 
			// txtbopomofo
			// 
			this.txtbopomofo.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.txtbopomofo.Location = new System.Drawing.Point(48, 40);
			this.txtbopomofo.Name = "txtbopomofo";
			this.txtbopomofo.Size = new System.Drawing.Size(200, 21);
			this.txtbopomofo.TabIndex = 0;
			this.txtbopomofo.Text = "";
			this.txtbopomofo.TextChanged += new System.EventHandler(this.txtbopomofo_TextChanged);
			// 
			// lblbopomofo
			// 
			this.lblbopomofo.AutoSize = true;
			this.lblbopomofo.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(193)), ((System.Byte)(215)), ((System.Byte)(248)));
			this.lblbopomofo.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblbopomofo.ForeColor = System.Drawing.SystemColors.Desktop;
			this.lblbopomofo.Location = new System.Drawing.Point(8, 42);
			this.lblbopomofo.Name = "lblbopomofo";
			this.lblbopomofo.Size = new System.Drawing.Size(42, 17);
			this.lblbopomofo.TabIndex = 1;
			this.lblbopomofo.Text = "拼音：";
			this.lblbopomofo.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
			// 
			// grdDisease
			// 
			this.grdDisease.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.grdDisease.CaptionVisible = false;
			this.grdDisease.DataMember = "";
			this.grdDisease.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grdDisease.Location = new System.Drawing.Point(1, 64);
			this.grdDisease.Name = "grdDisease";
			this.grdDisease.Size = new System.Drawing.Size(437, 237);
			this.grdDisease.TabIndex = 1;
			// 
			// pictureBox1
			// 
			this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox1.Location = new System.Drawing.Point(0, 63);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(439, 240);
			this.pictureBox1.TabIndex = 15;
			this.pictureBox1.TabStop = false;
			// 
			// pictureBox4
			// 
			this.pictureBox4.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox4.BackgroundImage")));
			this.pictureBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox4.Location = new System.Drawing.Point(0, 40);
			this.pictureBox4.Name = "pictureBox4";
			this.pictureBox4.Size = new System.Drawing.Size(439, 24);
			this.pictureBox4.TabIndex = 16;
			this.pictureBox4.TabStop = false;
			// 
			// btnCancel
			// 
			this.btnCancel.BackColor = System.Drawing.SystemColors.InactiveBorder;
			this.btnCancel.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnCancel.BackgroundImage")));
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnCancel.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnCancel.ForeColor = System.Drawing.SystemColors.Desktop;
			this.btnCancel.Location = new System.Drawing.Point(360, 316);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(64, 23);
			this.btnCancel.TabIndex = 2;
			this.btnCancel.Text = "取 消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnOK
			// 
			this.btnOK.BackColor = System.Drawing.SystemColors.InactiveBorder;
			this.btnOK.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnOK.BackgroundImage")));
			this.btnOK.Enabled = false;
			this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.btnOK.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnOK.ForeColor = System.Drawing.SystemColors.Desktop;
			this.btnOK.Location = new System.Drawing.Point(280, 316);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(64, 23);
			this.btnOK.TabIndex = 1;
			this.btnOK.Text = "确 定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// panel1
			// 
			this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel1.ForeColor = System.Drawing.SystemColors.Desktop;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(454, 344);
			this.panel1.TabIndex = 3;
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.pictureBox3);
			this.panel2.Controls.Add(this.pictureBox2);
			this.panel2.Location = new System.Drawing.Point(0, 0);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(440, 25);
			this.panel2.TabIndex = 17;
			// 
			// frmSelectDisease
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.ClientSize = new System.Drawing.Size(454, 344);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.panel1);
			this.ForeColor = System.Drawing.SystemColors.ControlText;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmSelectDisease";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.Text = "确定病症";
			this.Load += new System.EventHandler(this.frmSelectDisease_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.grdDisease)).EndInit();
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void SetgrdDiseaseStyle()
		{
			DataGridTableStyle tableStyle=new DataGridTableStyle();

			//增加一列用于显示Name
			DataGridTextBoxColumnEx columnStyleName=new DataGridTextBoxColumnEx();			
			columnStyleName.HeaderText="疾病名";
			columnStyleName.MappingName=DiseasesEx.t_DiseaseDataTableEx.FIELD_Name;			
			columnStyleName.Width=180;				
			tableStyle.GridColumnStyles.Add(columnStyleName);

			//增加一列用于显示拼音码
			DataGridTextBoxColumnEx columnStyleBopomofo=new DataGridTextBoxColumnEx();			
			columnStyleBopomofo.HeaderText="拼音码";
			columnStyleBopomofo.MappingName=MedicinesEx.t_MedicineDataTableEx.FIELD_Bopomofo;			
			columnStyleBopomofo.Width=grdDisease.Width-columnStyleName.Width- 26;
			tableStyle.GridColumnStyles.Add(columnStyleBopomofo);

			tableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			tableStyle.MappingName = DiseasesEx.t_DiseaseDataTableEx.TableName_Disease;
			tableStyle.RowHeadersVisible = false;		

			tableStyle.AlternatingBackColor = System.Drawing.Color.LightGray;
			tableStyle.AllowSorting=false;
		
			grdDisease.TableStyles.Add(tableStyle);	
			grdDisease.ReadOnly=true;
		}

		private void frmSelectDisease_Load(object sender, System.EventArgs e)
		{
			try
			{
				SetgrdDiseaseStyle();
				
				//从缓存中获取药品信息
				_dvDiseases=new DataView(((DiseasesEx)CacheDataManager.GetCacheData(DiseasesEx.t_DiseaseDataTableEx.TableName_Disease)).t_Disease,"",DiseasesEx.t_DiseaseDataTableEx.FIELD_Bopomofo,DataViewRowState.CurrentRows);
				grdDisease.SetDataBinding(_dvDiseases,string.Empty);
				SetButtonEnabled();

			}
			catch(Exception ex)
			{
				MessageProcess.ShowError(ex.Message);
			}
		}

		private void txtbopomofo_TextChanged(object sender, System.EventArgs e)
		{
			if(_dvDiseases != null)
			{
				_dvDiseases.RowFilter= DiseasesEx.t_DiseaseDataTableEx.FIELD_Bopomofo + " Like '" + txtbopomofo.Text + "%'";
				SetButtonEnabled();
			}
		}

		private void SetButtonEnabled()
		{
			btnOK.Enabled=(_dvDiseases.Count>0);
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			DiseasesEx diseaseEx=new DiseasesEx();
			_DiseaseRow = diseaseEx.t_Disease.Newt_DiseaseRow();

			_DiseaseRow[DiseasesEx.t_DiseaseDataTableEx.FIELD_DiseaseID]=_dvDiseases[grdDisease.CurrentCell.RowNumber][DiseasesEx.t_DiseaseDataTableEx.FIELD_DiseaseID];
			_DiseaseRow[DiseasesEx.t_DiseaseDataTableEx.FIELD_Name]=_dvDiseases[grdDisease.CurrentCell.RowNumber][DiseasesEx.t_DiseaseDataTableEx.FIELD_Name];				

			this.DialogResult=DialogResult.OK;
		}

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