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

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

namespace HISClinic
{
	/// <summary>
	/// frmSelectMedicine 的摘要说明。
	/// </summary>
	public class frmSelectMedicine : System.Windows.Forms.Form
	{
		private DataView _dvMedcines;
		private PrescriptionsEx.t_PrescriptionDetailRow _PrescriptionDetailRow;

		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label lblbopomofo;
		private System.Windows.Forms.TextBox txtbopomofo;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.DataGrid grdMedicine;
		private System.Windows.Forms.ComboBox cboCommonUsage;
		private System.Windows.Forms.Label lblSubTotalValue;
		private System.Windows.Forms.Label lblUnitPriceValue;
		private System.Windows.Forms.Label lblSubTotal;
		private System.Windows.Forms.TextBox txtDosageEverytimeValue;
		private System.Windows.Forms.Label lblCommonUsage;
		private System.Windows.Forms.Label lblDosageEverytime;
		private System.Windows.Forms.TextBox txtDailyTimesValue;
		private System.Windows.Forms.Label lblDailyTimes;
		private System.Windows.Forms.Label lblUnitPrice;
		private System.Windows.Forms.TextBox txtQuantityValue;
		private System.Windows.Forms.Label lblQuantity;
		private System.Windows.Forms.Label lblMedicineNameValue;
		private System.Windows.Forms.Label lblMedicineName;
		private System.Windows.Forms.Label lblMedicineSpecValue;
		private System.Windows.Forms.Label lblMedicineSpec;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.PictureBox pictureBox3;
		private System.Windows.Forms.PictureBox pictureBox2;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.PictureBox pictureBox4;
		private System.Windows.Forms.PictureBox pictureBox5;
		private System.Windows.Forms.PictureBox pictureBox6;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Panel panel2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public PrescriptionsEx.t_PrescriptionDetailRow PrescriptionDetailRow
		{
			set
			{
				if(value!=null)
				{
					_PrescriptionDetailRow=value;
					DisplayMedicineInfo(_PrescriptionDetailRow);
					SetButtonEnabled();
				}
			}
			get
			{
				return _PrescriptionDetailRow;
			}
		}

		public frmSelectMedicine()
		{
			//
			// 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(frmSelectMedicine));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.pictureBox2 = new System.Windows.Forms.PictureBox();
			this.pictureBox3 = new System.Windows.Forms.PictureBox();
			this.button1 = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.button2 = new System.Windows.Forms.Button();
			this.pictureBox5 = new System.Windows.Forms.PictureBox();
			this.lblMedicineSpecValue = new System.Windows.Forms.Label();
			this.lblMedicineSpec = new System.Windows.Forms.Label();
			this.lblMedicineNameValue = new System.Windows.Forms.Label();
			this.lblMedicineName = new System.Windows.Forms.Label();
			this.cboCommonUsage = new System.Windows.Forms.ComboBox();
			this.lblSubTotalValue = new System.Windows.Forms.Label();
			this.lblUnitPriceValue = new System.Windows.Forms.Label();
			this.lblSubTotal = new System.Windows.Forms.Label();
			this.txtDosageEverytimeValue = new System.Windows.Forms.TextBox();
			this.lblCommonUsage = new System.Windows.Forms.Label();
			this.lblDosageEverytime = new System.Windows.Forms.Label();
			this.txtDailyTimesValue = new System.Windows.Forms.TextBox();
			this.lblDailyTimes = new System.Windows.Forms.Label();
			this.lblUnitPrice = new System.Windows.Forms.Label();
			this.txtQuantityValue = new System.Windows.Forms.TextBox();
			this.lblQuantity = new System.Windows.Forms.Label();
			this.txtbopomofo = new System.Windows.Forms.TextBox();
			this.lblbopomofo = new System.Windows.Forms.Label();
			this.grdMedicine = new System.Windows.Forms.DataGrid();
			this.pictureBox4 = new System.Windows.Forms.PictureBox();
			this.pictureBox6 = new System.Windows.Forms.PictureBox();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.panel2 = new System.Windows.Forms.Panel();
			this.groupBox1.SuspendLayout();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.grdMedicine)).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.pictureBox1);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.panel1);
			this.groupBox1.Controls.Add(this.txtbopomofo);
			this.groupBox1.Controls.Add(this.lblbopomofo);
			this.groupBox1.Controls.Add(this.grdMedicine);
			this.groupBox1.Controls.Add(this.pictureBox4);
			this.groupBox1.Controls.Add(this.pictureBox6);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(656, 360);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(0, 25);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(656, 6);
			this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox1.TabIndex = 18;
			this.pictureBox1.TabStop = false;
			// 
			// pictureBox2
			// 
			this.pictureBox2.Dock = System.Windows.Forms.DockStyle.Right;
			this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
			this.pictureBox2.Location = new System.Drawing.Point(536, 0);
			this.pictureBox2.Name = "pictureBox2";
			this.pictureBox2.Size = new System.Drawing.Size(120, 25);
			this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
			this.pictureBox2.TabIndex = 17;
			this.pictureBox2.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(536, 25);
			this.pictureBox3.TabIndex = 15;
			this.pictureBox3.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(304, 40);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 23);
			this.button1.TabIndex = 3;
			this.button1.Text = "查 找";
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.SystemColors.ControlLightLight;
			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panel1.Controls.Add(this.button2);
			this.panel1.Controls.Add(this.pictureBox5);
			this.panel1.Controls.Add(this.lblMedicineSpecValue);
			this.panel1.Controls.Add(this.lblMedicineSpec);
			this.panel1.Controls.Add(this.lblMedicineNameValue);
			this.panel1.Controls.Add(this.lblMedicineName);
			this.panel1.Controls.Add(this.cboCommonUsage);
			this.panel1.Controls.Add(this.lblSubTotalValue);
			this.panel1.Controls.Add(this.lblUnitPriceValue);
			this.panel1.Controls.Add(this.lblSubTotal);
			this.panel1.Controls.Add(this.txtDosageEverytimeValue);
			this.panel1.Controls.Add(this.lblCommonUsage);
			this.panel1.Controls.Add(this.lblDosageEverytime);
			this.panel1.Controls.Add(this.txtDailyTimesValue);
			this.panel1.Controls.Add(this.lblDailyTimes);
			this.panel1.Controls.Add(this.lblUnitPrice);
			this.panel1.Controls.Add(this.txtQuantityValue);
			this.panel1.Controls.Add(this.lblQuantity);
			this.panel1.Location = new System.Drawing.Point(368, 72);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(287, 287);
			this.panel1.TabIndex = 2;
			// 
			// button2
			// 
			this.button2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button2.BackgroundImage")));
			this.button2.Cursor = System.Windows.Forms.Cursors.No;
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.button2.Location = new System.Drawing.Point(-1, -1);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(80, 23);
			this.button2.TabIndex = 23;
			this.button2.Text = "填写药单";
			this.button2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			// 
			// pictureBox5
			// 
			this.pictureBox5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox5.BackgroundImage")));
			this.pictureBox5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox5.Location = new System.Drawing.Point(0, -1);
			this.pictureBox5.Name = "pictureBox5";
			this.pictureBox5.Size = new System.Drawing.Size(288, 23);
			this.pictureBox5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox5.TabIndex = 22;
			this.pictureBox5.TabStop = false;
			// 
			// lblMedicineSpecValue
			// 
			this.lblMedicineSpecValue.Location = new System.Drawing.Point(85, 72);
			this.lblMedicineSpecValue.Name = "lblMedicineSpecValue";
			this.lblMedicineSpecValue.Size = new System.Drawing.Size(139, 17);
			this.lblMedicineSpecValue.TabIndex = 21;
			this.lblMedicineSpecValue.Text = "[规格]";
			// 
			// lblMedicineSpec
			// 
			this.lblMedicineSpec.AutoSize = true;
			this.lblMedicineSpec.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblMedicineSpec.Location = new System.Drawing.Point(13, 72);
			this.lblMedicineSpec.Name = "lblMedicineSpec";
			this.lblMedicineSpec.Size = new System.Drawing.Size(54, 17);
			this.lblMedicineSpec.TabIndex = 20;
			this.lblMedicineSpec.Text = "规  格：";
			// 
			// lblMedicineNameValue
			// 
			this.lblMedicineNameValue.Location = new System.Drawing.Point(85, 40);
			this.lblMedicineNameValue.Name = "lblMedicineNameValue";
			this.lblMedicineNameValue.Size = new System.Drawing.Size(139, 17);
			this.lblMedicineNameValue.TabIndex = 19;
			this.lblMedicineNameValue.Text = "[药品名]";
			// 
			// lblMedicineName
			// 
			this.lblMedicineName.AutoSize = true;
			this.lblMedicineName.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblMedicineName.Location = new System.Drawing.Point(13, 40);
			this.lblMedicineName.Name = "lblMedicineName";
			this.lblMedicineName.Size = new System.Drawing.Size(54, 17);
			this.lblMedicineName.TabIndex = 18;
			this.lblMedicineName.Text = "药品名：";
			// 
			// cboCommonUsage
			// 
			this.cboCommonUsage.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.cboCommonUsage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboCommonUsage.Location = new System.Drawing.Point(85, 192);
			this.cboCommonUsage.Name = "cboCommonUsage";
			this.cboCommonUsage.Size = new System.Drawing.Size(155, 20);
			this.cboCommonUsage.TabIndex = 3;
			this.cboCommonUsage.SelectedValueChanged += new System.EventHandler(this.cboCommonUsage_SelectedValueChanged);
			// 
			// lblSubTotalValue
			// 
			this.lblSubTotalValue.Location = new System.Drawing.Point(85, 256);
			this.lblSubTotalValue.Name = "lblSubTotalValue";
			this.lblSubTotalValue.Size = new System.Drawing.Size(155, 17);
			this.lblSubTotalValue.TabIndex = 17;
			this.lblSubTotalValue.Text = "[小计]";
			this.lblSubTotalValue.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// lblUnitPriceValue
			// 
			this.lblUnitPriceValue.Location = new System.Drawing.Point(85, 224);
			this.lblUnitPriceValue.Name = "lblUnitPriceValue";
			this.lblUnitPriceValue.Size = new System.Drawing.Size(155, 17);
			this.lblUnitPriceValue.TabIndex = 16;
			this.lblUnitPriceValue.Text = "[单价]";
			this.lblUnitPriceValue.TextAlign = System.Drawing.ContentAlignment.TopRight;
			// 
			// lblSubTotal
			// 
			this.lblSubTotal.AutoSize = true;
			this.lblSubTotal.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblSubTotal.Location = new System.Drawing.Point(13, 256);
			this.lblSubTotal.Name = "lblSubTotal";
			this.lblSubTotal.Size = new System.Drawing.Size(54, 17);
			this.lblSubTotal.TabIndex = 12;
			this.lblSubTotal.Text = "小  计：";
			// 
			// txtDosageEverytimeValue
			// 
			this.txtDosageEverytimeValue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.txtDosageEverytimeValue.Location = new System.Drawing.Point(85, 160);
			this.txtDosageEverytimeValue.MaxLength = 4;
			this.txtDosageEverytimeValue.Name = "txtDosageEverytimeValue";
			this.txtDosageEverytimeValue.Size = new System.Drawing.Size(155, 21);
			this.txtDosageEverytimeValue.TabIndex = 2;
			this.txtDosageEverytimeValue.Text = "";
			this.txtDosageEverytimeValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.txtDosageEverytimeValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnlyInputNumberInTextBox);
			this.txtDosageEverytimeValue.TextChanged += new System.EventHandler(this.txtDosageEverytimeValue_TextChanged);
			// 
			// lblCommonUsage
			// 
			this.lblCommonUsage.AutoSize = true;
			this.lblCommonUsage.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblCommonUsage.Location = new System.Drawing.Point(13, 192);
			this.lblCommonUsage.Name = "lblCommonUsage";
			this.lblCommonUsage.Size = new System.Drawing.Size(54, 17);
			this.lblCommonUsage.TabIndex = 10;
			this.lblCommonUsage.Text = "用  法：";
			// 
			// lblDosageEverytime
			// 
			this.lblDosageEverytime.AutoSize = true;
			this.lblDosageEverytime.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblDosageEverytime.Location = new System.Drawing.Point(13, 160);
			this.lblDosageEverytime.Name = "lblDosageEverytime";
			this.lblDosageEverytime.Size = new System.Drawing.Size(66, 17);
			this.lblDosageEverytime.TabIndex = 8;
			this.lblDosageEverytime.Text = "每次用量：";
			// 
			// txtDailyTimesValue
			// 
			this.txtDailyTimesValue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.txtDailyTimesValue.Location = new System.Drawing.Point(85, 128);
			this.txtDailyTimesValue.MaxLength = 2;
			this.txtDailyTimesValue.Name = "txtDailyTimesValue";
			this.txtDailyTimesValue.Size = new System.Drawing.Size(155, 21);
			this.txtDailyTimesValue.TabIndex = 1;
			this.txtDailyTimesValue.Text = "";
			this.txtDailyTimesValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.txtDailyTimesValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnlyInputNumberInTextBox);
			this.txtDailyTimesValue.TextChanged += new System.EventHandler(this.txtDailyTimesValue_TextChanged);
			// 
			// lblDailyTimes
			// 
			this.lblDailyTimes.AutoSize = true;
			this.lblDailyTimes.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblDailyTimes.Location = new System.Drawing.Point(13, 136);
			this.lblDailyTimes.Name = "lblDailyTimes";
			this.lblDailyTimes.Size = new System.Drawing.Size(66, 17);
			this.lblDailyTimes.TabIndex = 6;
			this.lblDailyTimes.Text = "每日次数：";
			// 
			// lblUnitPrice
			// 
			this.lblUnitPrice.AutoSize = true;
			this.lblUnitPrice.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblUnitPrice.Location = new System.Drawing.Point(13, 224);
			this.lblUnitPrice.Name = "lblUnitPrice";
			this.lblUnitPrice.Size = new System.Drawing.Size(54, 17);
			this.lblUnitPrice.TabIndex = 5;
			this.lblUnitPrice.Text = "单  价：";
			// 
			// txtQuantityValue
			// 
			this.txtQuantityValue.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.txtQuantityValue.Location = new System.Drawing.Point(85, 96);
			this.txtQuantityValue.MaxLength = 4;
			this.txtQuantityValue.Name = "txtQuantityValue";
			this.txtQuantityValue.Size = new System.Drawing.Size(155, 21);
			this.txtQuantityValue.TabIndex = 0;
			this.txtQuantityValue.Text = "";
			this.txtQuantityValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			this.txtQuantityValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.OnlyInputNumberInTextBox);
			this.txtQuantityValue.TextChanged += new System.EventHandler(this.txtQuantityValue_TextChanged);
			// 
			// lblQuantity
			// 
			this.lblQuantity.AutoSize = true;
			this.lblQuantity.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblQuantity.Location = new System.Drawing.Point(13, 104);
			this.lblQuantity.Name = "lblQuantity";
			this.lblQuantity.Size = new System.Drawing.Size(54, 17);
			this.lblQuantity.TabIndex = 3;
			this.lblQuantity.Text = "数  量：";
			// 
			// txtbopomofo
			// 
			this.txtbopomofo.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.txtbopomofo.Location = new System.Drawing.Point(48, 41);
			this.txtbopomofo.Name = "txtbopomofo";
			this.txtbopomofo.Size = new System.Drawing.Size(255, 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)(186)), ((System.Byte)(209)), ((System.Byte)(247)));
			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(4, 43);
			this.lblbopomofo.Name = "lblbopomofo";
			this.lblbopomofo.Size = new System.Drawing.Size(42, 17);
			this.lblbopomofo.TabIndex = 1;
			this.lblbopomofo.Text = "拼音：";
			// 
			// grdMedicine
			// 
			this.grdMedicine.BackgroundColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.grdMedicine.CaptionVisible = false;
			this.grdMedicine.DataMember = "";
			this.grdMedicine.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grdMedicine.Location = new System.Drawing.Point(0, 64);
			this.grdMedicine.Name = "grdMedicine";
			this.grdMedicine.Size = new System.Drawing.Size(358, 293);
			this.grdMedicine.TabIndex = 1;
			this.grdMedicine.DoubleClick += new System.EventHandler(this.grdMedicine_DoubleClick);
			// 
			// pictureBox4
			// 
			this.pictureBox4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox4.Location = new System.Drawing.Point(0, 64);
			this.pictureBox4.Name = "pictureBox4";
			this.pictureBox4.Size = new System.Drawing.Size(360, 295);
			this.pictureBox4.TabIndex = 19;
			this.pictureBox4.TabStop = false;
			// 
			// pictureBox6
			// 
			this.pictureBox6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox6.BackgroundImage")));
			this.pictureBox6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox6.Location = new System.Drawing.Point(0, 40);
			this.pictureBox6.Name = "pictureBox6";
			this.pictureBox6.Size = new System.Drawing.Size(655, 24);
			this.pictureBox6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
			this.pictureBox6.TabIndex = 21;
			this.pictureBox6.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.Flat;
			this.btnCancel.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnCancel.Location = new System.Drawing.Point(592, 372);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(64, 23);
			this.btnCancel.TabIndex = 5;
			this.btnCancel.Text = "取 消";
			this.btnCancel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			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.Flat;
			this.btnOK.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnOK.Location = new System.Drawing.Point(512, 372);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(64, 23);
			this.btnOK.TabIndex = 4;
			this.btnOK.Text = "确 定";
			this.btnOK.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// 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(656, 25);
			this.panel2.TabIndex = 22;
			// 
			// frmSelectMedicine
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.ClientSize = new System.Drawing.Size(674, 400);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnOK);
			this.ForeColor = System.Drawing.SystemColors.Desktop;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmSelectMedicine";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "选择药品";
			this.Load += new System.EventHandler(this.frmSelectMedicine_Load);
			this.groupBox1.ResumeLayout(false);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.grdMedicine)).EndInit();
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void frmSelectMedicine_Load(object sender, System.EventArgs e)
		{
			try
			{
				lblMedicineNameValue.Text="";
				lblMedicineSpecValue.Text="";
				txtDailyTimesValue.Text="";
				txtDosageEverytimeValue.Text="";
				txtQuantityValue.Text="";
				lblUnitPriceValue.Text="";
				lblSubTotalValue.Text="";

				SetgrdMedicineStyle();
				
				//从缓存中获取药品信息
				_dvMedcines=new DataView(((MedicinesEx)CacheDataManager.GetCacheData(MedicinesEx.t_MedicineDataTableEx.TableName_Medicine)).t_Medicine,"",MedicinesEx.t_MedicineDataTableEx.FIELD_Bopomofo,DataViewRowState.CurrentRows);
				grdMedicine.SetDataBinding(_dvMedcines,string.Empty);

				//从缓存中获取用品用法的信息
				CommonUsages commonUsage=(CommonUsagesEx)CacheDataManager.GetCacheData(CommonUsagesEx.t_CommonUsageDataTableEx.TableName_CommonUsage);
				cboCommonUsage.DataSource=commonUsage.t_CommonUsage.DefaultView;
				cboCommonUsage.DisplayMember=CommonUsagesEx.t_CommonUsageDataTableEx.FIELD_Name;
				cboCommonUsage.ValueMember=CommonUsagesEx.t_CommonUsageDataTableEx.FIELD_CommonUsageID;
			}
			catch(Exception ex)
			{
				MessageProcess.ShowError(ex.Message);
			}
		}

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

			//增加一列用于显示Name
			DataGridTextBoxColumnEx columnStyleName=new DataGridTextBoxColumnEx();			
			columnStyleName.HeaderText="药品名";
			columnStyleName.MappingName=MedicinesEx.t_MedicineDataTableEx.FIELD_Name;			
			columnStyleName.Width=100;				
			tableStyle.GridColumnStyles.Add(columnStyleName);

			//增加一列用于显示Spec
			DataGridTextBoxColumnEx columnStyleSpec=new DataGridTextBoxColumnEx();			
			columnStyleSpec.HeaderText="规格";
			columnStyleSpec.MappingName=MedicinesEx.t_MedicineDataTableEx.FIELD_Spec;			
			columnStyleSpec.Width=90;
			tableStyle.GridColumnStyles.Add(columnStyleSpec);

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

			tableStyle.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			tableStyle.MappingName = MedicinesEx.t_MedicineDataTableEx.TableName_Medicine;
			tableStyle.RowHeadersVisible = false;		

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

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

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

		private void grdMedicine_DoubleClick(object sender, System.EventArgs e)
		{
			if(this._dvMedcines.Count>0)
			{
				//创建可以保存药品信息的行
				if(PrescriptionDetailRow == null)
				{
					PrescriptionsEx prescriptionsEx=new PrescriptionsEx();
					_PrescriptionDetailRow=prescriptionsEx.t_PrescriptionDetail.Newt_PrescriptionDetailRow();
				}

				int RowIndex=grdMedicine.CurrentCell.RowNumber;

				if(_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_RxID] == DBNull.Value )
				{
					_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_RxID]=0;
				}

				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_MedicineID]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_MedicineID];				
				if(_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_LineNumber] == DBNull.Value)
				{
					_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_LineNumber]=0;
				}
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_MedicineName]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_Name];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_MedicineSpec]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_Spec];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_DailyTimes]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_Dailytimes];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_DosageEverytime]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_DosageEveryTime];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_CommomUsage]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_CommonUsageName];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_Quantity]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_CommonUseQuantity];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_UnitName]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_UnitName];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_UnitPrice]=_dvMedcines[RowIndex][MedicinesEx.t_MedicineDataTableEx.FIELD_UnitPrice];
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_SubTotal]=Prescription.CalculateSubTotal(_PrescriptionDetailRow);

				DisplayMedicineInfo(_PrescriptionDetailRow);	
				SetButtonEnabled();
			}
		}

		/// <summary>
		/// 显示药品的信息
		/// </summary>
		/// <param name="prescriptionDetailRow"></param>
		private void DisplayMedicineInfo(PrescriptionsEx.t_PrescriptionDetailRow prescriptionDetailRow)
		{
			lblMedicineNameValue.Text=prescriptionDetailRow.MedicineName;
			lblMedicineSpecValue.Text=prescriptionDetailRow.MedicineSpec;
			txtQuantityValue.Text=prescriptionDetailRow.Quantity.ToString();
			txtDailyTimesValue.Text=prescriptionDetailRow.DailyTimes.ToString();
			txtDosageEverytimeValue.Text=prescriptionDetailRow.DosageEverytime.ToString();
			cboCommonUsage.Text=prescriptionDetailRow.CommomUsage;

			//药品价格截取两位小数显示
			string UnitPrice=prescriptionDetailRow.UnitPrice.ToString("0.00");
			string UnitName=prescriptionDetailRow.UnitName;
			lblUnitPriceValue.Text=UnitName.Trim().Length>0?UnitPrice + "元" + "/" + UnitName:UnitPrice;
			lblSubTotalValue.Text=prescriptionDetailRow.SubTotal.ToString("0.00") + "元";
		}

		private void SetButtonEnabled()
		{
			btnOK.Enabled=(_PrescriptionDetailRow != null );
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{			
			this.DialogResult=DialogResult.OK;
		}

		private void txtQuantityValue_TextChanged(object sender, System.EventArgs e)
		{
			if(_PrescriptionDetailRow != null)
			{
				if(txtQuantityValue.Text != String.Empty)
				{
					_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_Quantity]=Convert.ToInt32(txtQuantityValue.Text);
					_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_SubTotal]=Prescription.CalculateSubTotal(_PrescriptionDetailRow);
					DisplayMedicineInfo(_PrescriptionDetailRow);
				}
				else
				{
					txtQuantityValue.Text=_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_Quantity].ToString();
				}
			}
		}

		private void OnlyInputNumberInTextBox(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(!(Char.IsNumber(e.KeyChar) || Char.IsControl(e.KeyChar)))
			{
				e.Handled=true;
			}
		}

		private void txtDailyTimesValue_TextChanged(object sender, System.EventArgs e)
		{
			if(_PrescriptionDetailRow != null)
			{
				if(txtDailyTimesValue.Text != String.Empty)
				{
					_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_DailyTimes]=Convert.ToInt32(txtDailyTimesValue.Text);										
				}
				else
				{
					txtDailyTimesValue.Text=_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_DailyTimes].ToString();
				}
			}
		}

		private void txtDosageEverytimeValue_TextChanged(object sender, System.EventArgs e)
		{
			if(_PrescriptionDetailRow != null)
			{
				if(txtDosageEverytimeValue.Text != String.Empty)
				{
					_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_DosageEverytime]=Convert.ToDecimal(txtDosageEverytimeValue.Text);										
				}
				else
				{
					txtDosageEverytimeValue.Text=_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_DosageEverytime].ToString();
				}
			}
		}

		private void cboCommonUsage_SelectedValueChanged(object sender, System.EventArgs e)
		{
			if(_PrescriptionDetailRow != null)
			{
				_PrescriptionDetailRow[PrescriptionsEx.t_PrescriptionDetailDataTableEx.FIELD_CommomUsage]=cboCommonUsage.Text;
			}
		}		
	}
}
