context: using System;
  using System.Drawing;
  using System.Drawing.Printing;
  using System.Collections;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Windows.Forms;
  using OpenDentBusiness;
  using OpenDental.UI;
  
  namespace OpenDental{
  ///<summary></summary>
  	public class FormASAP:System.Windows.Forms.Form {
  		private System.ComponentModel.Container components = null;
  		private OpenDental.UI.Button butClose;
  		///<summary></summary>
  		public bool PinClicked=false;		
  		///<summary></summary>
  		public static string procsForCur;
  		private OpenDental.UI.ODGrid grid;
  		private OpenDental.UI.Button butPrint;
  		private List<Appointment> ListASAP;
  		private PrintDocument pd;
  		private bool headingPrinted;
  		private int headingPrintH;
  		private int pagesPrinted;
  		///<summary>Only used if PinClicked=true</summary>
  		public long AptSelected;
  		private ComboBox comboProv;
  		private Label label4;
  		private OpenDental.UI.Button butRefresh;
  		private ComboBox comboSite;
  		private Label labelSite;
  		///<summary>When this form closes, this will be the patNum of the last patient viewed.  The calling form should then make use of this to refresh to that patient.  If 0, then calling form should not refresh.</summary>
  		public long SelectedPatNum;
  		private ComboBox comboClinic;
  		private Label labelClinic;
  		private Dictionary<long,string> patientNames;
  		private List<Clinic> _listUserClinics;
  
  		///<summary></summary>
  		public FormASAP() {
  			InitializeComponent();// Required for Windows Form Designer support
  			Lan.F(this);
  		}
  
  		///<summary></summary>
  		protected override void Dispose( bool disposing ){
  			if( disposing ){
  				if(components != null){
  					components.Dispose();
  				}
  			}
  			base.Dispose( disposing );
  		}
  
  		#region Windows Form Designer generated code
  		/// <summary>
  		/// Required method for Designer support - do not modify
  		/// the contents of this method with the code editor.
  		/// </summary>
  		private void InitializeComponent()
  		{
  			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormASAP));
  			this.butClose = new OpenDental.UI.Button();
  			this.grid = new OpenDental.UI.ODGrid();
  			this.butPrint = new OpenDental.UI.Button();
  			this.comboProv = new System.Windows.Forms.ComboBox();
  			this.label4 = new System.Windows.Forms.Label();
  			this.butRefresh = new OpenDental.UI.Button();
  			this.comboSite = new System.Windows.Forms.ComboBox();
  			this.labelSite = new System.Windows.Forms.Label();
  			this.comboClinic = new System.Windows.Forms.ComboBox();
  			this.labelClinic = new System.Windows.Forms.Label();
  			this.SuspendLayout();
  			// 
  			// butClose
  			// 
  			this.butClose.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butClose.Autosize = true;
  			this.butClose.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butClose.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butClose.CornerRadius = 4F;
  			this.butClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  			this.butClose.Location = new System.Drawing.Point(761, 631);
  			this.butClose.Name = "butClose";
  			this.butClose.Size = new System.Drawing.Size(87, 24);
  			this.butClose.TabIndex = 7;
  			this.butClose.Text = "&Close";
  			this.butClose.Click += new System.EventHandler(this.butClose_Click);
  			// 
  			// grid
  			// 
  			this.grid.HScrollVisible = false;
  			this.grid.Location = new System.Drawing.Point(10, 57);
  			this.grid.Name = "grid";
  			this.grid.ScrollValue = 0;
  			this.grid.Size = new System.Drawing.Size(734, 598);
  			this.grid.TabIndex = 8;
  			this.grid.Title = "ASAP List";
  			this.grid.TranslationName = "TableASAP";
  			this.grid.CellDoubleClick += new OpenDental.UI.ODGridClickEventHandler(this.grid_CellDoubleClick);
  			// 
  			// butPrint
  			// 
  			this.butPrint.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  			this.butPrint.Autosize = true;
  			this.butPrint.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butPrint.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butPrint.CornerRadius = 4F;
  			this.butPrint.Image = global::OpenDental.Properties.Resources.butPrintSmall;
  			this.butPrint.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  			this.butPrint.Location = new System.Drawing.Point(761, 583);
  			this.butPrint.Name = "butPrint";
  			this.butPrint.Size = new System.Drawing.Size(87, 24);
  			this.butPrint.TabIndex = 21;
  			this.butPrint.Text = "Print List";
  			this.butPrint.Click += new System.EventHandler(this.butPrint_Click);
  			// 
  			// comboProv
  			// 
  			this.comboProv.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  			this.comboProv.Location = new System.Drawing.Point(319, 7);
  			this.comboProv.MaxDropDownItems = 40;
  			this.comboProv.Name = "comboProv";
  			this.comboProv.Size = new System.Drawing.Size(181, 21);
  			this.comboProv.TabIndex = 33;
  			// 
  			// label4
  			// 
  			this.label4.Location = new System.Drawing.Point(248, 11);
  			this.label4.Name = "label4";
  			this.label4.Size = new System.Drawing.Size(69, 14);
  			this.label4.TabIndex = 32;
  			this.label4.Text = "Provider";
  			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			// 
  			// butRefresh
  			// 
  			this.butRefresh.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  			this.butRefresh.Autosize = true;
  			this.butRefresh.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butRefresh.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butRefresh.CornerRadius = 4F;
  			this.butRefresh.Location = new System.Drawing.Point(762, 6);
  			this.butRefresh.Name = "butRefresh";
  			this.butRefresh.Size = new System.Drawing.Size(86, 24);
  			this.butRefresh.TabIndex = 31;
  			this.butRefresh.Text = "&Refresh";
  			this.butRefresh.Click += new System.EventHandler(this.butRefresh_Click);
  			// 
  			// comboSite
  			// 
  			this.comboSite.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  			this.comboSite.Location = new System.Drawing.Point(584, 32);
  			this.comboSite.MaxDropDownItems = 40;
  			this.comboSite.Name = "comboSite";
  			this.comboSite.Size = new System.Drawing.Size(160, 21);
  			this.comboSite.TabIndex = 37;
  			// 
  			// labelSite
  			// 
  			this.labelSite.Location = new System.Drawing.Point(512, 36);
  			this.labelSite.Name = "labelSite";
  			this.labelSite.Size = new System.Drawing.Size(71, 14);
  			this.labelSite.TabIndex = 36;
  			this.labelSite.Text = "Site";
  			this.labelSite.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			// 
  			// comboClinic
  			// 
  			this.comboClinic.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  			this.comboClinic.Location = new System.Drawing.Point(584, 7);
  			this.comboClinic.MaxDropDownItems = 40;
  			this.comboClinic.Name = "comboClinic";
  			this.comboClinic.Size = new System.Drawing.Size(160, 21);
  			this.comboClinic.TabIndex = 39;
  			// 
  			// labelClinic
  			// 
  			this.labelClinic.Location = new System.Drawing.Point(506, 11);
  			this.labelClinic.Name = "labelClinic";
  			this.labelClinic.Size = new System.Drawing.Size(77, 14);
  			this.labelClinic.TabIndex = 38;
  			this.labelClinic.Text = "Clinic";
  			this.labelClinic.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			// 
  			// FormASAP
  			// 
  			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  			this.CancelButton = this.butClose;
  			this.ClientSize = new System.Drawing.Size(858, 672);
  			this.Controls.Add(this.comboClinic);
  			this.Controls.Add(this.labelClinic);
  			this.Controls.Add(this.comboSite);
  			this.Controls.Add(this.labelSite);
  			this.Controls.Add(this.comboProv);
  			this.Controls.Add(this.label4);
  			this.Controls.Add(this.butRefresh);
  			this.Controls.Add(this.butPrint);
  			this.Controls.Add(this.grid);
  			this.Controls.Add(this.butClose);
  			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  			this.MaximizeBox = false;
  			this.MinimizeBox = false;
  			this.Name = "FormASAP";
  			this.ShowInTaskbar = false;
  			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  			this.Text = "ASAP List";
  			this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormASAP_FormClosing);
  			this.Load += new System.EventHandler(this.FormASAP_Load);
  			this.ResumeLayout(false);
  
  		}
  		#endregion
  
  		private void FormASAP_Load(object sender, System.EventArgs e) {
  			patientNames=Patients.GetAllPatientNames();
  			/*comboOrder.Items.Add(Lan.g(this,"Status"));
  			comboOrder.Items.Add(Lan.g(this,"Alphabetical"));
  			comboOrder.Items.Add(Lan.g(this,"Date"));
  			comboOrder.SelectedIndex=0;*/
  			comboProv.Items.Add(Lan.g(this,"All"));
  			comboProv.SelectedIndex=0;
  			for(int i=0;i<ProviderC.ListShort.Count;i++) {
  				comboProv.Items.Add(ProviderC.ListShort[i].GetLongDesc());
  			}
  			if(PrefC.GetBool(PrefName.EasyHidePublicHealth)){
  				comboSite.Visible=false;
  				labelSite.Visible=false;
  			}
  			else{
  				comboSite.Items.Add(Lan.g(this,"All"));
  				comboSite.SelectedIndex=0;
  				for(int i=0;i<SiteC.List.Length;i++) {
  					comboSite.Items.Add(SiteC.List[i].Description);
  				}
  			}
  			if(PrefC.GetBool(PrefName.EasyNoClinics)) {
  				comboClinic.Visible=false;
  				labelClinic.Visible=false;
  			}
  			else {
  				if(!Security.CurUser.ClinicIsRestricted) {
  					comboClinic.Items.Add(Lan.g(this,"All"));
  					comboClinic.SelectedIndex=0;
  				}
  				_listUserClinics=Clinics.GetForUserod(Security.CurUser);
  				for(int i=0;i<_listUserClinics.Count;i++) {
  					comboClinic.Items.Add(_listUserClinics[i].Description);
  					if(_listUserClinics[i].ClinicNum==FormOpenDental.ClinicNum) {
  						comboClinic.SelectedIndex=i;
  						if(!Security.CurUser.ClinicIsRestricted) {
  							comboClinic.SelectedIndex++;//add 1 for "All"
  						}
  					}
  				}
  			}
  			FillGrid();
  		}
  
  		private void FillGrid(){
  			this.Cursor=Cursors.WaitCursor;
  			/*string order="";
  			switch(comboOrder.SelectedIndex) {
  				case 0:
  					order="status";
  					break;
  				case 1:
  					order="alph";
  					break;
  				case 2:
  					order="date";
  					break;
  			}*/
  			long provNum=0;
  			if(comboProv.SelectedIndex!=0) {
  				provNum=ProviderC.ListShort[comboProv.SelectedIndex-1].ProvNum;
  			}
  			long siteNum=0;
  			if(!PrefC.GetBool(PrefName.EasyHidePublicHealth) && comboSite.SelectedIndex!=0) {
  				siteNum=SiteC.List[comboSite.SelectedIndex-1].SiteNum;
  			}
  			long clinicNum=0;
  			//if clinics are not enabled, comboClinic.SelectedIndex will be -1, so clinicNum will be 0 and list will not be filtered by clinic
  			if(Security.CurUser.ClinicIsRestricted && comboClinic.SelectedIndex>-1) {
  				clinicNum=_listUserClinics[comboClinic.SelectedIndex].ClinicNum;
  			}
  			else if(comboClinic.SelectedIndex > 0) {//if user is not restricted, clinicNum will be 0 and the query will get all clinic data
  				clinicNum=_listUserClinics[comboClinic.SelectedIndex-1].ClinicNum;//if user is not restricted, comboClinic will contain "All" so minus 1
  			}
  			ListASAP=Appointments.RefreshASAP(provNum,siteNum,clinicNum);
  			int scrollVal=grid.ScrollValue;
  			grid.BeginUpdate();
  			grid.Columns.Clear();
  			ODGridColumn col=new ODGridColumn(Lan.g("TableASAP","Patient"),140);
  			grid.Columns.Add(col);
  			col=new ODGridColumn(Lan.g("TableASAP","Date"),65);
  			grid.Columns.Add(col);
  			col=new ODGridColumn(Lan.g("TableASAP","Status"),110);
  			grid.Columns.Add(col);
  			col=new ODGridColumn(Lan.g("TableASAP","Prov"),50);
  			grid.Columns.Add(col);
  			col=new ODGridColumn(Lan.g("TableASAP","Procedures"),150);
  			grid.Columns.Add(col);
  			col=new ODGridColumn(Lan.g("TableASAP","Notes"),200);
  			grid.Columns.Add(col);
  			grid.Rows.Clear();
  			ODGridRow row;
  			for(int i=0;i<ListASAP.Count;i++) {
  				row=new ODGridRow();
  				row.Cells.Add(patientNames[ListASAP[i].PatNum]);
  
gt: 				if(ListASAP[i].AptDateTime.Year < 1880){//shouldn't be possible.