context: using System;
  using System.Diagnostics;
  using System.Drawing;
  using System.Drawing.Imaging;
  using System.Drawing.Printing;
  using System.Collections;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Globalization;
  using System.Runtime.InteropServices;
  using System.Text.RegularExpressions;
  using System.Windows.Forms;
  using Microsoft.Win32;
  using System.Data;
  using OpenDentBusiness.DataAccess;
  using OpenDentBusiness;
  using OpenDental.UI;
  using CodeBase;
  using System.IO;
  
  namespace OpenDental {
  	public class FormAnestheticRecord:System.Windows.Forms.Form {
  		public static Userod CurUser;
  		private bool IsStartingUp;
  		private bool IsUpdate;
  		private AnestheticRecord AnestheticRecordCur;
  		public AnestheticData AnesthDataCur;
  		public Patient PatCur;
  		public bool IsNew;
  		private GroupBox groupBoxVS;
  		private Label labelVSM;
  		private TextBox textVSMName;
  		private Label labelVSMSerNum;
  		private TextBox textVSMSerNum;
  		private GroupBox groupBoxSidebarRt;
  		private Label labelASA;
  		private ComboBox comboASA;
  		private Label labelInh;
  		private Label labelLperMinN2O;
  		private Label labelLperMinO2;
  		private ComboBox comboO2LMin;
  		private ComboBox comboN2OLMin;
  		private Label labelIVF;
  		private ComboBox comboIVF;
  		private Label labelIVFVol;
  		private TextBox textIVFVol;
  		private ComboBox comboIVSite;
  		private Label labelIVAtt;
  		private ComboBox comboIVAtt;
  		private RadioButton radIVSiteL;
  		private RadioButton radIVSiteR;
  		private OpenDental.UI.Button butAnesthScore;
  		private GroupBox groupBoxNotes;
  		private RichTextBox richTextNotes;
  		private Label labelEscortName;
  		private TextBox textEscortName;
  		private TextBox textEscortRel;
  		private Label labelEscortRel;
  		private GroupBox groupBoxHgtWgt;
  		private GroupBox groupBoxDeliveryMethod;
  		private RadioButton radRteETT;
  		private RadioButton radRteNasCan;
  		private RadioButton radRteNasHood;
  		private GroupBox groupBoxIVSite;
  		private GroupBox groupBoxMedRoute;
  		private RadioButton radMedRouteIVButtFly;
  		private RadioButton radMedRouteIVCath;
  		private Label labelEMod;
  		private ComboBox comboASA_EModifier;
  		private Label labelEscortCellNum;
  		private TextBox textEscortCellNum;
  		private RadioButton radMedRouteIM;
  		private RadioButton radMedRoutePO;
  		private RadioButton radMedRouteRectal;
  		private GroupBox groupBoxTimes;
  		private TextBox textAnesthOpen;
  		private OpenDental.UI.Button butSurgClose;
  		private TextBox textSurgClose;
  		private TextBox textAnesthClose;
  		private OpenDental.UI.Button butAnesthOpen;
  		private OpenDental.UI.Button butAnesthClose;
  		private OpenDental.UI.Button butSurgOpen;
  		private TextBox textSurgOpen;
  		private Label labelIVAnesthetics;
  		private Label labelAsst;
  		private ComboBox comboCirc;
  		private OpenDental.UI.Button butDelAnesthetic;
  		private Label labelCirc;
  		private ComboBox comboAsst;
  		private OpenDental.UI.Button butAddAnesthetic;
  		private ListBox listAnesthetics;
  		private Label labelAnesthMed;
  		private ODGrid gridAnesthMeds;
  		private GroupBox groupBoxDoseCalc;
  		private OpenDental.UI.Button butDose20;
  		private OpenDental.UI.Button butDose10;
  		private OpenDental.UI.Button butDose7;
  		private OpenDental.UI.Button butDose8;
  		private OpenDental.UI.Button butDose9;
  		private OpenDental.UI.Button butDose6;
  		private OpenDental.UI.Button butDose5;
  		private OpenDental.UI.Button butDose4;
  		private OpenDental.UI.Button butDose3;
  		private OpenDental.UI.Button butDose2;
  		private OpenDental.UI.Button butDose1;
  		private OpenDental.UI.Button butDose0;
  		private OpenDental.UI.Button butDose25;
  		private OpenDental.UI.Button butDose50;
  		private OpenDental.UI.Button butDoseEnter;
  		private OpenDental.UI.Button butDoseDecPoint;
  		private ComboBox comboAnesthMed;
  		private ComboBox comboSurgeon;
  		private Label labelSurgeon;
  		private ComboBox comboAnesthetist;
  		private TextBox textAnesthDose;
  		private Label labelDose;
  		private Label labelAnesthetist;
  		private TextBox textPatient;
  		private Label labelPatient;
  		private Label labelPatID;
  		private TextBox textPatID;
  		private GroupBox groupBoxAnesthMeds;
  		private Label label1;
  		private RadioButton radWgtUnitsKgs;
  		private ComboBox comboNPOTime;
  		private RadioButton radWgtUnitsLbs;
  		private TextBox textPatHgt;
  		private Label labelPatWgt;
  		private Label labelPatHgt;
  		private TextBox textPatWgt;
  		private ODGrid gridVSData;
  		private RadioButton radMedRouteNasal;
  		private GroupBox groupBoxMonitors;
  		private CheckBox checkMonPrecordial;
  		private CheckBox checkMonEtCO2;
  		private CheckBox checkMonSpO2;
  		private CheckBox checkMonBP;
  		private Label labelGauge;
  		private Label labelIVGauge;
  		private ComboBox comboIVGauge;
  		private RadioButton radIVSideL;
  		private RadioButton radIVSideR;
  		private CheckBox checkMonEKG;
  		private CheckBox checkMonTemp;
  		private IContainer components;
  		private bool SigChanged;
  		private Control sigBoxTopaz;
  		private bool allowTopaz;
  		private bool inputStatus = true; //if the decimal button is clicked
  		private bool hasDecimal = false; //if the dose text has the decimal
  		public int anestheticRecordCur;
  		private List<AnestheticMedsGiven> listAnesthMedsGiven;
  		private List<AnestheticVSData> listAnesthVSData;
  		public List<Anes_hl7data> listAnes_hl7data;
  		public string AnesthScore;
  		public int anesthScore;
  		public int CurPatNum;
  		public int SelectedPatNum;
  		//private PrintDialog printDialog;
  		private ToolStripMenuItem providersToolStripMenuItem;
  		private ToolStripSeparator toolStripSeparator4;
  		private RadioButton radHgtUnitsCm;
  		private RadioButton radHgtUnitsIn;
  		private GroupBox groupBoxWgt;
  		private GroupBox groupBoxHgt;
  		private int patNum;
  		private Label labelInstrux;
  		private Label labelAnesthScore;
  		private OpenDental.UI.Button butOK;
  		private Label labelInvalidSig;
  		private OpenDental.UI.Button butCancel;
  		private SignatureBox sigBox;
  		private OpenDental.UI.Button butSignTopaz;
  		private OpenDental.UI.Button butClose;
  		private OpenDental.UI.Button butClearSig;
  		private MenuStrip menuStrip1;
  		private ToolStripMenuItem filesToolStripMenuItem;
  		private ToolStripMenuItem saveToolStripMenuItem;
  		private ToolStripMenuItem exitToolStripMenuItem;
  		private ToolStripMenuItem reportsToolStripMenuItem;
  		private ToolStripMenuItem checkInventoryLevelsToolStripMenuItem;
  		private ToolStripMenuItem suppliersToolStripMenuItem;
  		private ToolStripMenuItem saveToolStripMenuItem2;
  		private ToolStripMenuItem saveAndCloseToolStripMenuItem1;
  		private ToolStripMenuItem printToolStripMenuItem;
  		private ToolStripMenuItem exitToolStripMenuItem2;
  		private ToolStripMenuItem addEditSuppliersToolStripMenuItem1;
  		private ToolStripMenuItem checkInventoryToolStripMenuItem1;
  		private ToolStripSeparator toolStripSeparator1;
  		private ToolStripSeparator toolStripSeparator2;
  		private ToolStripMenuItem selectPatientToolStripMenuItem;
  		private ToolStripSeparator toolStripSeparator3;
  		public Patient pat;
  		public int PatNum;
  		public HorizontalAlignment textAlign;
  		public PrintWindowL printWindow;
  
  		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);
  			}
  		}
  
  		/// <summary>Clean up any resources being used.</summary>
  		protected override void Dispose(bool disposing) {
  			if(disposing) {
  				if(components != null) {
  					components.Dispose();
  				}
  			}
  			base.Dispose(disposing);
  		}
  
  		private void InitializeComponent() {
  			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAnestheticRecord));
  			this.labelVSM = new System.Windows.Forms.Label();
  			this.labelVSMSerNum = new System.Windows.Forms.Label();
  			this.richTextNotes = new System.Windows.Forms.RichTextBox();
  			this.textEscortName = new System.Windows.Forms.TextBox();
  			this.labelEscortName = new System.Windows.Forms.Label();
  			this.textEscortRel = new System.Windows.Forms.TextBox();
  			this.labelEscortRel = new System.Windows.Forms.Label();
  			this.groupBoxSidebarRt = new System.Windows.Forms.GroupBox();
  			this.labelAnesthScore = new System.Windows.Forms.Label();
  			this.groupBoxMonitors = new System.Windows.Forms.GroupBox();
  			this.checkMonTemp = new System.Windows.Forms.CheckBox();
  			this.checkMonEKG = new System.Windows.Forms.CheckBox();
  			this.checkMonPrecordial = new System.Windows.Forms.CheckBox();
  			this.checkMonEtCO2 = new System.Windows.Forms.CheckBox();
  			this.checkMonSpO2 = new System.Windows.Forms.CheckBox();
  			this.checkMonBP = new System.Windows.Forms.CheckBox();
  			this.labelEMod = new System.Windows.Forms.Label();
  			this.comboASA_EModifier = new System.Windows.Forms.ComboBox();
  			this.groupBoxIVSite = new System.Windows.Forms.GroupBox();
  			this.radIVSideL = new System.Windows.Forms.RadioButton();
  			this.radIVSideR = new System.Windows.Forms.RadioButton();
  			this.labelGauge = new System.Windows.Forms.Label();
  			this.labelIVGauge = new System.Windows.Forms.Label();
  			this.comboIVGauge = new System.Windows.Forms.ComboBox();
  			this.comboIVSite = new System.Windows.Forms.ComboBox();
  			this.radIVSiteR = new System.Windows.Forms.RadioButton();
  			this.radIVSiteL = new System.Windows.Forms.RadioButton();
  			this.comboIVAtt = new System.Windows.Forms.ComboBox();
  			this.labelIVAtt = new System.Windows.Forms.Label();
  			this.groupBoxMedRoute = new System.Windows.Forms.GroupBox();
  			this.radMedRouteRectal = new System.Windows.Forms.RadioButton();
  			this.radMedRouteNasal = new System.Windows.Forms.RadioButton();
  			this.radMedRouteIM = new System.Windows.Forms.RadioButton();
  			this.radMedRoutePO = new System.Windows.Forms.RadioButton();
  			this.radMedRouteIVButtFly = new System.Windows.Forms.RadioButton();
  			this.radMedRouteIVCath = new System.Windows.Forms.RadioButton();
  			this.groupBoxDeliveryMethod = new System.Windows.Forms.GroupBox();
  			this.radRteETT = new System.Windows.Forms.RadioButton();
  			this.radRteNasCan = new System.Windows.Forms.RadioButton();
  			this.radRteNasHood = new System.Windows.Forms.RadioButton();
  			this.labelLperMinN2O = new System.Windows.Forms.Label();
  			this.labelLperMinO2 = new System.Windows.Forms.Label();
  			this.butAnesthScore = new OpenDental.UI.Button();
  			this.comboO2LMin = new System.Windows.Forms.ComboBox();
  			this.labelIVFVol = new System.Windows.Forms.Label();
  			this.textIVFVol = new System.Windows.Forms.TextBox();
  			this.labelIVF = new System.Windows.Forms.Label();
  			this.comboIVF = new System.Windows.Forms.ComboBox();
  			this.labelInh = new System.Windows.Forms.Label();
  			this.comboN2OLMin = new System.Windows.Forms.ComboBox();
  			this.comboASA = new System.Windows.Forms.ComboBox();
  			this.labelASA = new System.Windows.Forms.Label();
  			this.groupBoxNotes = new System.Windows.Forms.GroupBox();
  			this.groupBoxWgt = new System.Windows.Forms.GroupBox();
  			this.radWgtUnitsKgs = new System.Windows.Forms.RadioButton();
  			this.radWgtUnitsLbs = new System.Windows.Forms.RadioButton();
  			this.groupBoxHgt = new System.Windows.Forms.GroupBox();
  			this.radHgtUnitsCm = new System.Windows.Forms.RadioButton();
  			this.radHgtUnitsIn = new System.Windows.Forms.RadioButton();
  			this.label1 = new System.Windows.Forms.Label();
  			this.comboNPOTime = new System.Windows.Forms.ComboBox();
  			this.textPatHgt = new System.Windows.Forms.TextBox();
  			this.labelPatWgt = new System.Windows.Forms.Label();
  			this.labelPatHgt = new System.Windows.Forms.Label();
  			this.textPatWgt = new System.Windows.Forms.TextBox();
  			this.groupBoxHgtWgt = new System.Windows.Forms.GroupBox();
  			this.labelEscortCellNum = new System.Windows.Forms.Label();
  			this.textEscortCellNum = new System.Windows.Forms.TextBox();
  			this.groupBoxVS = new System.Windows.Forms.GroupBox();
  			this.gridVSData = new OpenDental.UI.ODGrid();
  			this.textVSMSerNum = new System.Windows.Forms.TextBox();
  			this.textVSMName = new System.Windows.Forms.TextBox();
  			this.groupBoxTimes = new System.Windows.Forms.GroupBox();
  			this.textAnesthOpen = new System.Windows.Forms.TextBox();
  			this.butSurgClose = new OpenDental.UI.Button();
  			this.textSurgClose = new System.Windows.Forms.TextBox();
  			this.textAnesthClose = new System.Windows.Forms.TextBox();
  			this.butAnesthOpen = new OpenDental.UI.Button();
  			this.butAnesthClose = new OpenDental.UI.Button();
  			this.butSurgOpen = new OpenDental.UI.Button();
  			this.textSurgOpen = new System.Windows.Forms.TextBox();
  			this.labelIVAnesthetics = new System.Windows.Forms.Label();
  			this.labelAsst = new System.Windows.Forms.Label();
  			this.comboCirc = new System.Windows.Forms.ComboBox();
  			this.labelCirc = new System.Windows.Forms.Label();
  			this.comboAsst = new System.Windows.Forms.ComboBox();
  			this.listAnesthetics = new System.Windows.Forms.ListBox();
  			this.labelAnesthMed = new System.Windows.Forms.Label();
  			this.groupBoxDoseCalc = new System.Windows.Forms.GroupBox();
  			this.butDose20 = new OpenDental.UI.Button();
  			this.labelInstrux = new System.Windows.Forms.Label();
  			this.butDose10 = new OpenDental.UI.Button();
  			this.butDose7 = new OpenDental.UI.Button();
  			this.butDose8 = new OpenDental.UI.Button();
  			this.butDose9 = new OpenDental.UI.Button();
  			this.butDose6 = new OpenDental.UI.Button();
  			this.butDose5 = new OpenDental.UI.Button();
  			this.butDose4 = new OpenDental.UI.Button();
  			this.butDose3 = new OpenDental.UI.Button();
  			this.butDose2 = new OpenDental.UI.Button();
  			this.butDose1 = new OpenDental.UI.Button();
  			this.butDose0 = new OpenDental.UI.Button();
  			this.butDose25 = new OpenDental.UI.Button();
  			this.butDose50 = new OpenDental.UI.Button();
  			this.butDoseEnter = new OpenDental.UI.Button();
  			this.butDoseDecPoint = new OpenDental.UI.Button();
  			this.comboAnesthMed = new System.Windows.Forms.ComboBox();
  			this.comboSurgeon = new System.Windows.Forms.ComboBox();
  			this.labelSurgeon = new System.Windows.Forms.Label();
  			this.comboAnesthetist = new System.Windows.Forms.ComboBox();
  			this.textAnesthDose = new System.Windows.Forms.TextBox();
  			this.labelDose = new System.Windows.Forms.Label();
  			this.labelAnesthetist = new System.Windows.Forms.Label();
  			this.textPatient = new System.Windows.Forms.TextBox();
  			this.labelPatient = new System.Windows.Forms.Label();
  			this.labelPatID = new System.Windows.Forms.Label();
  			this.textPatID = new System.Windows.Forms.TextBox();
  			this.groupBoxAnesthMeds = new System.Windows.Forms.GroupBox();
  			this.gridAnesthMeds = new OpenDental.UI.ODGrid();
  			this.butAddAnesthetic = new OpenDental.UI.Button();
  			this.butDelAnesthetic = new OpenDental.UI.Button();
  			this.labelInvalidSig = new System.Windows.Forms.Label();
  			this.menuStrip1 = new System.Windows.Forms.MenuStrip();
  			this.filesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.selectPatientToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
  			this.saveToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
  			this.saveAndCloseToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  			this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
  			this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
  			this.exitToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
  			this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.addEditSuppliersToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  			this.checkInventoryToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
  			this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
  			this.providersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.checkInventoryLevelsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.suppliersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
  			this.butOK = new OpenDental.UI.Button();
  			this.butCancel = new OpenDental.UI.Button();
  			this.sigBox = new OpenDental.UI.SignatureBox();
  
gt: 			this.butSignTopaz = new OpenDental.UI.Button();