context: using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using OpenDentBusiness;
  using OpenDental.UI;
  
  namespace OpenDental{
  	/// <summary>
  	/// Summary description for FormBasicTemplate.
  	/// </summary>
  	public class FormClinics:System.Windows.Forms.Form {
  		private OpenDental.UI.Button butAdd;
  		private OpenDental.UI.Button butClose;
  		/// <summary>
  		/// Required designer variable.
  		/// </summary>
  		private System.ComponentModel.Container components = null;
  		private System.Windows.Forms.Label label1;
  		private bool changed;
  		private UI.ODGrid gridMain;
  		public bool IsSelectionMode;
  		public long SelectedClinicNum;
  		private UI.Button butOK;
  		///<summary>Set this array prior to loading this window to use a custom list of clinics.  Otherwise, uses the cache.</summary>
  		public Clinic[] ArrayClinics;
  
  		///<summary></summary>
  		public FormClinics()
  		{
  			//
  			// Required for Windows Form Designer support
  			//
  			InitializeComponent();
  			Lan.F(this);
  		}
  
  		/// <summary>
  		/// Clean up any resources being used.
  		/// </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(FormClinics));
  			this.label1 = new System.Windows.Forms.Label();
  			this.gridMain = new OpenDental.UI.ODGrid();
  			this.butAdd = new OpenDental.UI.Button();
  			this.butClose = new OpenDental.UI.Button();
  			this.butOK = new OpenDental.UI.Button();
  			this.SuspendLayout();
  			// 
  			// label1
  			// 
  			this.label1.Location = new System.Drawing.Point(9, 9);
  			this.label1.Name = "label1";
  			this.label1.Size = new System.Drawing.Size(378, 24);
  			this.label1.TabIndex = 11;
  			this.label1.Text = "This is usually only used if you have multiple locations";
  			// 
  			// gridMain
  			// 
  			this.gridMain.AllowSortingByColumn = true;
  			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.HasMultilineHeaders = false;
  			this.gridMain.HScrollVisible = false;
  			this.gridMain.Location = new System.Drawing.Point(12, 37);
  			this.gridMain.Name = "gridMain";
  			this.gridMain.ScrollValue = 0;
  			this.gridMain.Size = new System.Drawing.Size(278, 561);
  			this.gridMain.TabIndex = 12;
  			this.gridMain.Title = "Clinics";
  			this.gridMain.TranslationName = "TableClinics";
  			this.gridMain.CellDoubleClick += new OpenDental.UI.ODGridClickEventHandler(this.gridMain_CellDoubleClick);
  			// 
  			// butAdd
  			// 
  			this.butAdd.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  			this.butAdd.Autosize = true;
  			this.butAdd.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butAdd.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butAdd.CornerRadius = 4F;
  			this.butAdd.Image = global::OpenDental.Properties.Resources.Add;
  			this.butAdd.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
  			this.butAdd.Location = new System.Drawing.Point(307, 37);
  			this.butAdd.Name = "butAdd";
  			this.butAdd.Size = new System.Drawing.Size(80, 26);
  			this.butAdd.TabIndex = 10;
  			this.butAdd.Text = "&Add";
  			this.butAdd.Click += new System.EventHandler(this.butAdd_Click);
  			// 
  			// butClose
  			// 
  			this.butClose.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  			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.Location = new System.Drawing.Point(312, 572);
  			this.butClose.Name = "butClose";
  			this.butClose.Size = new System.Drawing.Size(75, 26);
  			this.butClose.TabIndex = 0;
  			this.butClose.Text = "&Close";
  			this.butClose.Click += new System.EventHandler(this.butClose_Click);
  			// 
  			// butOK
  			// 
  			this.butOK.AdjustImageLocation = new System.Drawing.Point(0, 0);
  			this.butOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  			this.butOK.Autosize = true;
  			this.butOK.BtnShape = OpenDental.UI.enumType.BtnShape.Rectangle;
  			this.butOK.BtnStyle = OpenDental.UI.enumType.XPStyle.Silver;
  			this.butOK.CornerRadius = 4F;
  			this.butOK.Location = new System.Drawing.Point(312, 540);
  			this.butOK.Name = "butOK";
  			this.butOK.Size = new System.Drawing.Size(75, 26);
  			this.butOK.TabIndex = 13;
  			this.butOK.Text = "&OK";
  			this.butOK.Visible = false;
  			this.butOK.Click += new System.EventHandler(this.butOK_Click);
  			// 
  			// FormClinics
  			// 
  			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  			this.ClientSize = new System.Drawing.Size(399, 610);
  			this.Controls.Add(this.butOK);
  			this.Controls.Add(this.gridMain);
  			this.Controls.Add(this.label1);
  			this.Controls.Add(this.butAdd);
  			this.Controls.Add(this.butClose);
  			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  			this.MaximizeBox = false;
  			this.MinimizeBox = false;
  			this.MinimumSize = new System.Drawing.Size(415, 271);
  			this.Name = "FormClinics";
  			this.ShowInTaskbar = false;
  			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  			this.Text = "Clinics";
  			this.Closing += new System.ComponentModel.CancelEventHandler(this.FormClinics_Closing);
  			this.Load += new System.EventHandler(this.FormClinics_Load);
  			this.ResumeLayout(false);
  
  		}
  		#endregion
  
  		private void FormClinics_Load(object sender, System.EventArgs e) {
  			if(ArrayClinics==null) {
  				Clinics.RefreshCache();
  				ArrayClinics=Clinics.GetList();
  			}
  			if(IsSelectionMode) {
  				butAdd.Visible=false;
  				butOK.Visible=true;
  			}
  			FillGrid();
  		}
  
  		private void FillGrid() {
  			gridMain.BeginUpdate();
  			gridMain.Columns.Clear();
  			ODGridColumn col=new ODGridColumn(Lan.g("TableClinics","Description"),145);
  			gridMain.Columns.Add(col);
  			gridMain.Rows.Clear();
  			ODGridRow row;
  			for(int i=0;i<ArrayClinics.Length;i++) {
  				row=new ODGridRow();
  				row.Tag=ArrayClinics[i];
  				row.Cells.Add(ArrayClinics[i].Description);
  				gridMain.Rows.Add(row);
  			}
  			gridMain.EndUpdate();
  		}
  
  		private void butAdd_Click(object sender, System.EventArgs e) {
  			Clinic ClinicCur=new Clinic();
  			if(PrefC.GetBool(PrefName.PracticeIsMedicalOnly)) {
  				ClinicCur.IsMedicalOnly=true;
  			}
  			FormClinicEdit FormCE=new FormClinicEdit(ClinicCur);
  			FormCE.IsNew=true;
  			FormCE.ShowDialog();
  			Clinics.RefreshCache();
  			ArrayClinics=Clinics.GetList();
  			FillGrid();
  			changed=true;
  		}
  
  		private void gridMain_CellDoubleClick(object sender,ODGridClickEventArgs e) {
  			if(gridMain.Rows.Count==0){
  				return;
  			}
  			if(IsSelectionMode) {
  				SelectedClinicNum=((Clinic)gridMain.Rows[e.Row].Tag).ClinicNum;
  				DialogResult=DialogResult.OK;
  				return;
  			}
  			FormClinicEdit FormCE=new FormClinicEdit(ArrayClinics[e.Row]);
  			FormCE.ShowDialog();
  			Clinics.RefreshCache();
  			ArrayClinics=Clinics.GetList();
  			FillGrid();
  			changed=true;
  		}
  
  		private void butOK_Click(object sender,EventArgs e) {
  
gt: 			if(IsSelectionMode && gridMain.SelectedIndices.Length>0) {