//Allows user to change to a different patient by clicking 'Select Patient' in the File menu dropdown
		public void selectPatientToolStripMenuItem_Click(object sender,EventArgs e) {
			FormPatientSelect FormPS = new FormPatientSelect();
			FormPS.ShowDialog();
			if(FormPS.DialogResult == DialogResult.OK) {
				this.Hide();
				CurPatNum = FormPS.SelectedPatNum;
				pat = Patients.GetPat(CurPatNum);
				Patient PatNum = Patients.GetPat(CurPatNum);
				AnestheticData AnestheticDataCur;
				AnestheticDataCur = new AnestheticData();
				FormAnestheticRecord FormAR = new FormAnestheticRecord(pat,AnestheticDataCur);
				FormAR.ShowDialog();
				//Catches exception: If patient we are switching from has no saved aneshetics, FillControls will generate a null ref exception 
				try {
					FillControls(CurPatNum,AnestheticRecords.GetRecordNumByDate(listAnesthetics.SelectedItem.ToString()));
				}
				catch {
				}
				//changes the patient in the underlying module to the newly selected patient
				PatCur.PatNum = CurPatNum;
			}
		}
		/// <summary> Load saved data into form for selected Anesthetic Record/// </summary>
		private void FillControls(int PatNum,int anestheticRecordCur) {
			if(listAnesthetics.SelectedIndex == -1) {
				//prevents user from generating an exception when no record exists yet
				butDoseEnter.Enabled = false;
				//prevents exception if user tries to save to db with no items in list
				butOK.Enabled = false;
				butClose.Enabled = false;
				butSignTopaz.Enabled = false;
				butClearSig.Enabled = false;
			}
			else {
				butDoseEnter.Enabled = true;
				butOK.Enabled = true;
				butClose.Enabled = true;
				butSignTopaz.Enabled = true;
				butClearSig.Enabled = true;
			}
			DataTable table = AnestheticQueries.GetAnestheticData(anestheticRecordCur);
			AnestheticData Cur;
			for(int i = 0;i < table.Rows.Count;i++) {
				Cur = new AnestheticData();
				AnesthDataCur = Cur;
				Cur.AnestheticDataNum = PIn.PInt(table.Rows[i][0].ToString());
				Cur.AnestheticRecordNum = PIn.PInt(table.Rows[i][1].ToString());
				Cur.AnesthOpen = PIn.PString(table.Rows[i][2].ToString());
				Cur.AnesthClose = PIn.PString(table.Rows[i][3].ToString());
				Cur.SurgOpen = PIn.PString(table.Rows[i][4].ToString());
				Cur.SurgClose = PIn.PString(table.Rows[i][5].ToString());
				Cur.Anesthetist = PIn.PString(table.Rows[i][6].ToString());
				Cur.Surgeon = PIn.PString(table.Rows[i][7].ToString());
				Cur.Asst = PIn.PString(table.Rows[i][8].ToString());
				Cur.Circulator = PIn.PString(table.Rows[i][9].ToString());
				Cur.VSMName = PIn.PString(table.Rows[i][10].ToString());
				Cur.VSMSerNum = PIn.PString(table.Rows[i][11].ToString());
				Cur.ASA = PIn.PString(table.Rows[i][12].ToString());
				Cur.ASA_EModifier = PIn.PString(table.Rows[i][13].ToString());
				Cur.O2LMin = PIn.PInt(table.Rows[i][14].ToString());
				Cur.N2OLMin = PIn.PInt(table.Rows[i][15].ToString());
				Cur.RteNasCan = PIn.PBool(table.Rows[i][16].ToString());
				Cur.RteNasHood = PIn.PBool(table.Rows[i][17].ToString());
				Cur.RteETT = PIn.PBool(table.Rows[i][18].ToString());
				Cur.MedRouteIVCath = PIn.PBool(table.Rows[i][19].ToString());
				Cur.MedRouteIVButtFly = PIn.PBool(table.Rows[i][20].ToString());
				Cur.MedRouteIM = PIn.PBool(table.Rows[i][21].ToString());
				Cur.MedRoutePO = PIn.PBool(table.Rows[i][22].ToString());
				Cur.MedRouteNasal = PIn.PBool(table.Rows[i][23].ToString());
				Cur.MedRouteRectal = PIn.PBool(table.Rows[i][24].ToString());
				Cur.IVSite = PIn.PString(table.Rows[i][25].ToString());
				Cur.IVGauge = PIn.PInt(table.Rows[i][26].ToString());
				Cur.IVSideR = PIn.PBool(table.Rows[i][27].ToString());
				Cur.IVSideL = PIn.PBool(table.Rows[i][28].ToString());
				Cur.IVAtt = PIn.PInt(table.Rows[i][29].ToString());
				Cur.IVF = PIn.PString(table.Rows[i][30].ToString());
				Cur.IVFVol = PIn.PInt(table.Rows[i][31].ToString());
				Cur.MonBP = PIn.PBool(table.Rows[i][32].ToString());
				Cur.MonSpO2 = PIn.PBool(table.Rows[i][33].ToString());
				Cur.MonEtCO2 = PIn.PBool(table.Rows[i][34].ToString());
				Cur.MonTemp = PIn.PBool(table.Rows[i][35].ToString());
				Cur.MonPrecordial = PIn.PBool(table.Rows[i][36].ToString());
				Cur.MonEKG = PIn.PBool(table.Rows[i][37].ToString());
				Cur.Notes = PIn.PString(table.Rows[i][38].ToString());
				Cur.PatWgt = PIn.PInt(table.Rows[i][39].ToString());
				Cur.WgtUnitsLbs = PIn.PBool(table.Rows[i][40].ToString());
				Cur.WgtUnitsKgs = PIn.PBool(table.Rows[i][41].ToString());
				Cur.PatHgt = PIn.PInt(table.Rows[i][42].ToString());
				Cur.EscortName = PIn.PString(table.Rows[i][43].ToString());
				Cur.EscortCellNum = PIn.PString(table.Rows[i][44].ToString());
				Cur.EscortRel = PIn.PString(table.Rows[i][45].ToString());
				Cur.NPOTime = PIn.PString(table.Rows[i][46].ToString());
				Cur.HgtUnitsIn = PIn.PBool(table.Rows[i][47].ToString());
				Cur.HgtUnitsCm = PIn.PBool(table.Rows[i][48].ToString());
				Cur.Signature = PIn.PString(table.Rows[i][49].ToString());
				Cur.SigIsTopaz = PIn.PBool(table.Rows[i][50].ToString());
				//Populate controls from db
				textAnesthOpen.Text = Cur.AnesthOpen;
				textSurgOpen.Text = Cur.SurgOpen;
				textSurgClose.Text = Cur.SurgClose;
				textAnesthClose.Text = Cur.AnesthClose;
				//comboAnesthetist
				comboAnesthetist.SelectedItem = Cur.Anesthetist.ToString();
				//comboSurgeon
				comboSurgeon.SelectedItem = Cur.Surgeon.ToString();
				//comboAsst
				comboAsst.SelectedItem = Cur.Asst.ToString();
				//comboCirc
				comboCirc.SelectedItem = Cur.Circulator.ToString();
				//VSM, set to "" if no networked monitor has written its name to the db
				if(Cur.VSMName == null) {
					textVSMName.Text = "";
				}
				else {
					textVSMName.Text = Cur.VSMName;
				}
				//VSMSerNum, set to "" if no networked monitor has written its serial number to the db
				if(Cur.VSMSerNum == null) {
					textVSMSerNum.Text = "";
				}
				else {
					textVSMSerNum.Text = Cur.VSMSerNum;
				}
				//load comboASA
				comboASA.SelectedItem = Cur.ASA;
				//load comboASA_EModifier
				if(Cur.ASA_EModifier == "E") {
					comboASA_EModifier.SelectedIndex = 1;
				}
				//comboO2LMin
				comboO2LMin.SelectedItem = Cur.O2LMin.ToString();
				//comboN2OLMin
				comboN2OLMin.SelectedItem = Cur.N2OLMin.ToString();
				//radRteNasCan
				if(Cur.RteNasCan == true) {
					radRteNasCan.Checked = true;
				}
				//radNasHood
				if(Cur.RteNasHood == true) {
					radRteNasHood.Checked = true;
				}
				//radRteETT
				if(Cur.RteETT == true) {
					radRteETT.Checked = true;
				}
				//radMedRouteIVCath
				if(Cur.MedRouteIVCath == true) {
					radMedRouteIVCath.Checked = true;
				}
				//radMedRouteIVButtFly
				if(Cur.MedRouteIVButtFly == true) {
					radMedRouteIVButtFly.Checked = true;
				}
				//radMedRouteIM
				if(Cur.MedRouteIM == true) {
					radMedRouteIM.Checked = true;
				}
				//radMedRoutePO
				if(Cur.MedRoutePO == true) {
					radMedRoutePO.Checked = true;
				}
				//radMedRouteNasal
				if(Cur.MedRouteNasal == true) {
					radMedRouteNasal.Checked = true;
				}
				//radMedRouteRectal
				if(Cur.MedRouteRectal == true) {
					radMedRouteRectal.Checked = true;
				}
				//comboIVSite
				comboIVSite.SelectedItem = Cur.IVSite.ToString();
				//combIVGauge
				comboIVGauge.SelectedItem = Cur.IVGauge.ToString();
				//radIVSideR
				if(Cur.IVSideR == true) {
					radIVSideR.Checked = true;
				}
				//radIVSideL
				if(Cur.IVSideL == true) {
					radIVSideL.Checked = true;
				}
				//comboIVAtt
				comboIVAtt.SelectedItem = Cur.IVAtt.ToString();
				//comboIVF
				comboIVF.SelectedItem = Cur.IVF.ToString();
				//textIVFVol
				textIVFVol.Text = Cur.IVFVol.ToString();
				//checkMonBP
				if(Cur.MonBP == true) {
					checkMonBP.Checked = true;
				}
				//checkMonSpO2
				if(Cur.MonSpO2 == true) {
					checkMonSpO2.Checked = true;
				}
				//checkMonEtCO2
				if(Cur.MonEtCO2 == true) {
					checkMonEtCO2.Checked = true;
				}
				//checkMonTemp
				if(Cur.MonTemp == true) {
					checkMonTemp.Checked = true;
				}
				//checkMonPrecordial
				if(Cur.MonPrecordial == true) {
					checkMonPrecordial.Checked = true;
				}
				//checkMonEKG
				if(Cur.MonEKG == true) {
					checkMonEKG.Checked = true;
				}
				//notes
				richTextNotes.Text = Cur.Notes;
				//PatWgt
				textPatWgt.Text = Cur.PatWgt.ToString();
				//radWgtUnitsLbs
				if(Cur.WgtUnitsLbs == true) {
					radWgtUnitsLbs.Checked = true;
				}
				//comboWgtUnitsKgs
				if(Cur.WgtUnitsKgs == true) {
					radWgtUnitsKgs.Checked = true;
				}
				textPatHgt.Text = Cur.PatHgt.ToString();
				//radHgtUnitsIn
				if(Cur.HgtUnitsIn == true) {
					radHgtUnitsIn.Checked = true;
				}
				//radHgtUnitsCm
				textEscortName.Text = Cur.EscortName;
				textEscortCellNum.Text = Cur.EscortCellNum;
				textEscortRel.Text = Cur.EscortRel;
				//comboNPOTime
				comboNPOTime.SelectedItem = Cur.NPOTime.ToString();
				//labelAnesthScore
				try {
					anesthScore = AnestheticRecords.GetAnesthScore(AnestheticRecords.GetRecordNumByDate(listAnesthetics.SelectedItem.ToString()));
					AnesthScore = Convert.ToString(anesthScore);
				}
				catch {
					AnesthScore = "0";
				}
				this.labelAnesthScore.Text = Convert.ToString(AnesthScore);
			}
			labelInvalidSig.Visible = false;
			sigBox.Visible = true;
			if(listAnesthetics.SelectedIndex != -1) //catches exception when no Anesthetic Records saved yet
			{
				if(AnesthDataCur.SigIsTopaz) {
					if(AnesthDataCur.Signature != "") {
						if(allowTopaz) {
							sigBox.Visible = false;
							sigBoxTopaz.Visible = true;
							CodeBase.TopazWrapper.ClearTopaz(sigBoxTopaz);
							CodeBase.TopazWrapper.SetTopazCompressionMode(sigBoxTopaz,0);
							CodeBase.TopazWrapper.SetTopazEncryptionMode(sigBoxTopaz,0);
							CodeBase.TopazWrapper.SetTopazKeyString(sigBoxTopaz,"0000000000000000");
							CodeBase.TopazWrapper.SetTopazAutoKeyData(sigBoxTopaz,AnesthDataCur.Notes + AnestheticRecordCur.ProvNum.ToString());
							CodeBase.TopazWrapper.SetTopazEncryptionMode(sigBoxTopaz,2);//high encryption
							CodeBase.TopazWrapper.SetTopazCompressionMode(sigBoxTopaz,2);//high compression
							CodeBase.TopazWrapper.SetTopazSigString(sigBoxTopaz,AnesthDataCur.Signature);
							sigBoxTopaz.Refresh();
							if(CodeBase.TopazWrapper.GetTopazNumberOfTabletPoints(sigBoxTopaz) == 0) {
								labelInvalidSig.Visible = true;
							}
						}
					}
				}
				else {
					if(AnesthDataCur.Signature != null && AnesthDataCur.Signature != "") {
						sigBox.Visible = true;
						sigBoxTopaz.Visible = false;
						sigBox.ClearTablet();
						//sigBox.SetSigCompressionMode(0);
						//sigBox.SetEncryptionMode(0);
						sigBox.SetKeyString("0000000000000000");
						sigBox.SetAutoKeyData(AnesthDataCur.Notes + AnestheticRecordCur.ProvNum.ToString());
						//sigBox.SetEncryptionMode(2);//high encryption
						//sigBox.SetSigCompressionMode(2);//high compression
						sigBox.SetSigString(AnesthDataCur.Signature);
						if(sigBox.NumberOfTabletPoints() == 0) {
							labelInvalidSig.Visible = true;
						}
						sigBox.SetTabletState(0);//not accepting input.  To accept input, change the note, or clear the sig.
					}
				}
			}

		}
		private void SaveSignature(AnestheticData AnesthDataCur) {
			if(SigChanged) {
				//Topaz boxes are written in Windows native code.
				if(allowTopaz && sigBoxTopaz.Visible) {
					AnesthDataCur.SigIsTopaz = true;
					if(CodeBase.TopazWrapper.GetTopazNumberOfTabletPoints(sigBoxTopaz) == 0) {
						AnesthDataCur.Signature = "";
					}
					CodeBase.TopazWrapper.SetTopazCompressionMode(sigBoxTopaz,0);
					CodeBase.TopazWrapper.SetTopazEncryptionMode(sigBoxTopaz,0);
					CodeBase.TopazWrapper.SetTopazKeyString(sigBoxTopaz,"0000000000000000");
					CodeBase.TopazWrapper.SetTopazAutoKeyData(sigBoxTopaz,AnesthDataCur.Notes + AnestheticRecordCur.ProvNum.ToString());
					CodeBase.TopazWrapper.SetTopazEncryptionMode(sigBoxTopaz,2);
					CodeBase.TopazWrapper.SetTopazCompressionMode(sigBoxTopaz,2);
					AnesthDataCur.Signature = CodeBase.TopazWrapper.GetTopazString(sigBoxTopaz);
				}
				else {
					AnesthDataCur.SigIsTopaz = false;
					if(sigBox.NumberOfTabletPoints() == 0) {
						AnesthDataCur.Signature = "";
						return;
					}
					//sigBox.SetSigCompressionMode(0);
					//sigBox.SetEncryptionMode(0);
					sigBox.SetKeyString("0000000000000000");
					sigBox.SetAutoKeyData(AnesthDataCur.Notes + AnestheticRecordCur.ProvNum.ToString());
					//sigBox.SetEncryptionMode(2);
					//sigBox.SetSigCompressionMode(2);
					AnesthDataCur.Signature = sigBox.GetSigString();
				}
			}
		}
		public FormAnestheticRecord(Patient patCur,AnestheticData AnestheticDataCur) {
			components=new System.ComponentModel.Container();
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			Lan.F(this);
			PatCur = patCur;
			AnestheticRecord anestheticRecordCur = new AnestheticRecord();
			AnestheticRecordCur = anestheticRecordCur;
			Lan.F(this);
			allowTopaz = (Environment.OSVersion.Platform != PlatformID.Unix && !CodeBase.ODEnvironment.Is64BitOperatingSystem());
			sigBox.SetTabletState(1);
			if(!allowTopaz) {
				butSignTopaz.Visible = false;
				sigBox.Visible = true;
			}
			else {
				//Add signature box for Topaz signatures.
				sigBoxTopaz = CodeBase.TopazWrapper.GetTopaz();
				sigBoxTopaz.Location = sigBox.Location;//this puts both boxes in the same spot.
				sigBoxTopaz.Name = "sigBoxTopaz";
				sigBoxTopaz.Size = new System.Drawing.Size(168,85);
				sigBoxTopaz.TabIndex = 92;
				sigBoxTopaz.Text = "sigPlusNET1";
				sigBoxTopaz.Visible = false;
				Controls.Add(sigBoxTopaz);
				//It starts out accepting input. It will be set to 0 if a sig is already present.  It will be set back to 1 if note changes or if user clicks Clear.
				CodeBase.TopazWrapper.SetTopazState(sigBoxTopaz,1);
			}
		}