context: using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Drawing.Printing;
  using System.Text;
  using System.Windows.Forms;
  using System.IO;
  using OpenDentBusiness;
  using System.Collections;
  using OpenDental.UI;
  
  namespace OpenDental {
  	public partial class FormRpOutstandingIns:Form {
  		private ODGrid gridMain;
  		private CheckBox checkPreauth;
  		private Label labelProv;
  		private ValidNum textDaysOldMin;
  		private Label labelDaysOldMin;
  		private UI.Button butCancel;
  		private ValidNum textDaysOldMax;
  		private Label labelDaysOldMax;
      private DateTime dateMin;
      private DateTime dateMax;
      private List<long> provNumList;
      private bool isAllProv;
      private bool isPreauth;
  		private DataTable Table;
  		private UI.Button butPrint;
  		private ComboBoxMulti comboBoxMultiProv;
  		private bool headingPrinted;
  		private int pagesPrinted;
  		private Label label1;
  		private Label label2;
  		private TextBox textBox1;
  		private UI.Button butExport;
  		private int headingPrintH;
  		private UI.Button butRefresh;
  		private decimal total;
  
  
  		public FormRpOutstandingIns() {
  			InitializeComponent();
  			Lan.F(this);
  		}
  
  		private void InitializeComponent() {
  			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormRpOutstandingIns));
  			this.checkPreauth = new System.Windows.Forms.CheckBox();
  			this.labelProv = new System.Windows.Forms.Label();
  			this.labelDaysOldMin = new System.Windows.Forms.Label();
  			this.labelDaysOldMax = new System.Windows.Forms.Label();
  			this.label1 = new System.Windows.Forms.Label();
  			this.label2 = new System.Windows.Forms.Label();
  			this.textBox1 = new System.Windows.Forms.TextBox();
  			this.butRefresh = new OpenDental.UI.Button();
  			this.butExport = new OpenDental.UI.Button();
  			this.comboBoxMultiProv = new OpenDental.UI.ComboBoxMulti();
  			this.butPrint = new OpenDental.UI.Button();
  			this.textDaysOldMax = new OpenDental.ValidNum();
  			this.textDaysOldMin = new OpenDental.ValidNum();
  			this.butCancel = new OpenDental.UI.Button();
  			this.gridMain = new OpenDental.UI.ODGrid();
  			this.SuspendLayout();
  			// 
  			// checkPreauth
  			// 
  			this.checkPreauth.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
  			this.checkPreauth.Checked = true;
  			this.checkPreauth.CheckState = System.Windows.Forms.CheckState.Checked;
  			this.checkPreauth.FlatStyle = System.Windows.Forms.FlatStyle.System;
  			this.checkPreauth.Location = new System.Drawing.Point(296, 9);
  			this.checkPreauth.Name = "checkPreauth";
  			this.checkPreauth.Size = new System.Drawing.Size(113, 18);
  			this.checkPreauth.TabIndex = 51;
  			this.checkPreauth.Text = "Include Preauths";
  			this.checkPreauth.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			this.checkPreauth.CheckedChanged += new System.EventHandler(this.checkPreauth_CheckedChanged);
  			// 
  			// labelProv
  			// 
  			this.labelProv.Location = new System.Drawing.Point(412, 8);
  			this.labelProv.Name = "labelProv";
  			this.labelProv.Size = new System.Drawing.Size(87, 16);
  			this.labelProv.TabIndex = 48;
  			this.labelProv.Text = "Treat Provs";
  			this.labelProv.TextAlign = System.Drawing.ContentAlignment.BottomRight;
  			// 
  			// labelDaysOldMin
  			// 
  			this.labelDaysOldMin.Location = new System.Drawing.Point(9, 7);
  			this.labelDaysOldMin.Name = "labelDaysOldMin";
  			this.labelDaysOldMin.Size = new System.Drawing.Size(93, 18);
  			this.labelDaysOldMin.TabIndex = 46;
  			this.labelDaysOldMin.Text = "Days Old (min)";
  			this.labelDaysOldMin.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			// 
  			// labelDaysOldMax
  			// 
  			this.labelDaysOldMax.Location = new System.Drawing.Point(163, 7);
  			this.labelDaysOldMax.Name = "labelDaysOldMax";
  			this.labelDaysOldMax.Size = new System.Drawing.Size(53, 18);
  			this.labelDaysOldMax.TabIndex = 46;
  			this.labelDaysOldMax.Text = "(max)";
  			this.labelDaysOldMax.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			// 
  			// label1
  			// 
  			this.label1.Location = new System.Drawing.Point(100, 25);
  			this.label1.Name = "label1";
  			this.label1.Size = new System.Drawing.Size(175, 18);
  			this.label1.TabIndex = 54;
  			this.label1.Text = "(leave both blank to show all)";
  			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  			// 
  			// label2
  			// 
  			this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  			this.label2.Location = new System.Drawing.Point(520, 480);
  			this.label2.Name = "label2";
  			this.label2.Size = new System.Drawing.Size(69, 18);
  			this.label2.TabIndex = 46;
  			this.label2.Text = "Total";
  			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  			// 
  			// textBox1
  			// 
  			this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  			this.textBox1.Location = new System.Drawing.Point(595, 479);
  			this.textBox1.Name = "textBox1";
  			this.textBox1.Size = new System.Drawing.Size(61, 20);
  			this.textBox1.TabIndex = 56;
  			// 
  			// 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(670, 5);
  			this.butRefresh.Name = "butRefresh";
  			this.butRefresh.Size = new System.Drawing.Size(82, 24);
  			this.butRefresh.TabIndex = 58;
  			this.butRefresh.Text = "&Refresh";
  			this.butRefresh.Click += new System.EventHandler(this.butRefresh_Click);
  			// 
  			// butExport
  			// 
  			this.butExport.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
  			this.butExport.Autosize = true;
  			this.butExport.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butExport.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butExport.CornerRadius = 4F;
  			this.butExport.Image = global::OpenDental.Properties.Resources.butExport;
  			this.butExport.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  			this.butExport.Location = new System.Drawing.Point(97, 476);
  			this.butExport.Name = "butExport";
  			this.butExport.Size = new System.Drawing.Size(79, 24);
  			this.butExport.TabIndex = 57;
  			this.butExport.Text = "&Export";
  			this.butExport.Click += new System.EventHandler(this.butExport_Click);
  			// 
  			// comboBoxMultiProv
  			// 
  			this.comboBoxMultiProv.BackColor = System.Drawing.SystemColors.Window;
  			this.comboBoxMultiProv.DroppedDown = false;
  			this.comboBoxMultiProv.Items = ((System.Collections.ArrayList)(resources.GetObject("comboBoxMultiProv.Items")));
  			this.comboBoxMultiProv.Location = new System.Drawing.Point(498, 7);
  			this.comboBoxMultiProv.Name = "comboBoxMultiProv";
  			this.comboBoxMultiProv.SelectedIndices = ((System.Collections.ArrayList)(resources.GetObject("comboBoxMultiProv.SelectedIndices")));
  			this.comboBoxMultiProv.Size = new System.Drawing.Size(160, 21);
  			this.comboBoxMultiProv.TabIndex = 53;
  			this.comboBoxMultiProv.UseCommas = true;
  			this.comboBoxMultiProv.Leave += new System.EventHandler(this.comboBoxMultiProv_Leave);
  			// 
  			// 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.Left)));
  			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(12, 476);
  			this.butPrint.Name = "butPrint";
  			this.butPrint.Size = new System.Drawing.Size(79, 24);
  			this.butPrint.TabIndex = 52;
  			this.butPrint.Text = "&Print";
  			this.butPrint.Click += new System.EventHandler(this.butPrint_Click);
  			// 
  			// textDaysOldMax
  			// 
  			this.textDaysOldMax.Location = new System.Drawing.Point(219, 7);
  			this.textDaysOldMax.MaxVal = 255;
  			this.textDaysOldMax.MinVal = 0;
  			this.textDaysOldMax.Name = "textDaysOldMax";
  			this.textDaysOldMax.Size = new System.Drawing.Size(60, 20);
  			this.textDaysOldMax.TabIndex = 47;
  			this.textDaysOldMax.TextChanged += new System.EventHandler(this.textDaysOldMax_TextChanged);
  			// 
  			// textDaysOldMin
  			// 
  			this.textDaysOldMin.Location = new System.Drawing.Point(106, 7);
  			this.textDaysOldMin.MaxVal = 255;
  			this.textDaysOldMin.MinVal = 0;
  			this.textDaysOldMin.Name = "textDaysOldMin";
  			this.textDaysOldMin.Size = new System.Drawing.Size(60, 20);
  			this.textDaysOldMin.TabIndex = 47;
  			this.textDaysOldMin.Text = "30";
  			this.textDaysOldMin.TextChanged += new System.EventHandler(this.textDaysOldMin_TextChanged);
  			// 
  			// butCancel
  			// 
  			this.butCancel.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  			this.butCancel.Autosize = true;
  			this.butCancel.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butCancel.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butCancel.CornerRadius = 4F;
  			this.butCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  			this.butCancel.Location = new System.Drawing.Point(670, 476);
  			this.butCancel.Name = "butCancel";
  			this.butCancel.Size = new System.Drawing.Size(75, 24);
  			this.butCancel.TabIndex = 45;
  			this.butCancel.Text = "&Close";
  			this.butCancel.Click += new System.EventHandler(this.butCancel_Click);
  			// 
  			// gridMain
  			// 
  			this.gridMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
              | System.Windows.Forms.AnchorStyles.Left) 
              | System.Windows.Forms.AnchorStyles.Right)));
  			this.gridMain.HScrollVisible = false;
  			this.gridMain.Location = new System.Drawing.Point(12, 46);
  			this.gridMain.Name = "gridMain";
  			this.gridMain.ScrollValue = 0;
  			this.gridMain.Size = new System.Drawing.Size(740, 416);
  			this.gridMain.TabIndex = 1;
  			this.gridMain.Title = null;
  			this.gridMain.TranslationName = null;
  			this.gridMain.CellDoubleClick += new OpenDental.UI.ODGridClickEventHandler(this.gridMain_CellDoubleClick);
  			this.gridMain.CellClick += new OpenDental.UI.ODGridClickEventHandler(this.gridMain_CellClick);
  			// 
  			// FormRpOutstandingIns
  			// 
  			this.ClientSize = new System.Drawing.Size(764, 512);
  			this.Controls.Add(this.butRefresh);
  			this.Controls.Add(this.butExport);
  			this.Controls.Add(this.textBox1);
  			this.Controls.Add(this.label1);
  			this.Controls.Add(this.labelDaysOldMin);
  			this.Controls.Add(this.comboBoxMultiProv);
  			this.Controls.Add(this.butPrint);
  			this.Controls.Add(this.checkPreauth);
  			this.Controls.Add(this.labelProv);
  			this.Controls.Add(this.textDaysOldMax);
  			this.Controls.Add(this.textDaysOldMin);
  			this.Controls.Add(this.label2);
  			this.Controls.Add(this.labelDaysOldMax);
  			this.Controls.Add(this.butCancel);
  			this.Controls.Add(this.gridMain);
  			this.Name = "FormRpOutstandingIns";
  			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  			this.Text = "Outstanding Insurance Claims";
  			this.Load += new System.EventHandler(this.FormRpOutIns_Load);
  			this.ResumeLayout(false);
  			this.PerformLayout();
  
  		}
  
  		private void FormRpOutIns_Load(object sender,EventArgs e) {
  			FillProvs();
  			FillGrid();
  		}
  
  		private void FillProvs() {
  			comboBoxMultiProv.Items.Add("All");
  			for(int i=0;i<ProviderC.ListShort.Count;i++) {
  				comboBoxMultiProv.Items.Add(ProviderC.ListShort[i].GetLongDesc());
  			}
  			comboBoxMultiProv.SetSelected(0,true);
  			comboBoxMultiProv.RefreshText();
  			isAllProv=true;
  		}
  
  		private void FillGrid() {
  			if(textDaysOldMin.Text.Trim()=="" || PIn.Double(textDaysOldMin.Text)==0) {
  				dateMin=DateTime.MinValue;
  			}
  			else {
  				dateMin = DateTimeOD.Today.AddDays(-1 * PIn.Int(textDaysOldMin.Text));
  			}
  			if(textDaysOldMax.Text.Trim()=="" || PIn.Double(textDaysOldMax.Text)==0) {
  				dateMax=DateTime.MinValue;
  			}
  			else {
  				dateMax = DateTimeOD.Today.AddDays(-1 * PIn.Int(textDaysOldMax.Text));
  			}
  			if(comboBoxMultiProv.SelectedIndices[0].ToString()=="0") {
  				isAllProv=true;
  			}
  			else {
  				isAllProv=false;
  				provNumList=new List<long>();
  
gt: 				for(int i=0;i<comboBoxMultiProv.SelectedIndices.Count;i++) {