Index: Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs
===================================================================
--- Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1512)
+++ Scheduling/trunk/cs/bsdx0200GUISourceCode/CGView.cs	(revision 1728)
@@ -11,4 +11,9 @@
 using System.Drawing.Printing;
 using System.Linq;
+using System.Text;
+using System.Net.Mail;
+using System.Configuration;
+using System.Net;
+using System.IO;
 
 namespace IndianHealthService.ClinicalScheduling
@@ -94,5 +99,4 @@
 		private System.Windows.Forms.MenuItem sepApptMenu2;
 		private System.Windows.Forms.MenuItem ctxCalGridWalkin;
-		private System.Windows.Forms.MenuItem ctxCalGridSep1;
 		private System.Windows.Forms.MenuItem ctxCalGridSep2;
 		private System.Windows.Forms.MenuItem mnuOpenMultipleSchedules;
@@ -115,4 +119,8 @@
         private MenuItem mnuReprintApptSlip;
         private MenuItem mnuViewBrokerLog;
+        private MenuItem ctxCalGridSep1;
+        private MenuItem ctxCalGridCloneForward;
+        private MenuItem ctxCalGridExportInvite;
+        private MenuItem ctxCopyAppointment;
         private IContainer components;
 
@@ -255,4 +263,5 @@
             this.lblResource = new System.Windows.Forms.Label();
             this.panelCenter = new System.Windows.Forms.Panel();
+            this.calendarGrid1 = new IndianHealthService.ClinicalScheduling.CalendarGrid();
             this.ctxCalendarGrid = new System.Windows.Forms.ContextMenu();
             this.ctxCalGridAdd = new System.Windows.Forms.MenuItem();
@@ -261,9 +270,12 @@
             this.ctxCalGridDelete = new System.Windows.Forms.MenuItem();
             this.ctxCalGridCancelRadAppt = new System.Windows.Forms.MenuItem();
+            this.ctxCalGridCloneForward = new System.Windows.Forms.MenuItem();
+            this.ctxCopyAppointment = new System.Windows.Forms.MenuItem();
             this.ctxCalGridCheckIn = new System.Windows.Forms.MenuItem();
             this.ctxCalGridUndoCheckin = new System.Windows.Forms.MenuItem();
-            this.ctxCalGridSep1 = new System.Windows.Forms.MenuItem();
             this.ctxCalGridNoShow = new System.Windows.Forms.MenuItem();
             this.ctxCalGridNoShowUndo = new System.Windows.Forms.MenuItem();
+            this.ctxCalGridSep1 = new System.Windows.Forms.MenuItem();
+            this.ctxCalGridExportInvite = new System.Windows.Forms.MenuItem();
             this.ctxCalGridSep2 = new System.Windows.Forms.MenuItem();
             this.ctxCalGridWalkin = new System.Windows.Forms.MenuItem();
@@ -274,5 +286,4 @@
             this.splitter1 = new System.Windows.Forms.Splitter();
             this.splitter2 = new System.Windows.Forms.Splitter();
-            this.calendarGrid1 = new IndianHealthService.ClinicalScheduling.CalendarGrid();
             this.panelRight.SuspendLayout();
             this.panelClip.SuspendLayout();
@@ -716,5 +727,5 @@
             this.tvSchedules.Location = new System.Drawing.Point(0, 0);
             this.tvSchedules.Name = "tvSchedules";
-            this.tvSchedules.Size = new System.Drawing.Size(128, 347);
+            this.tvSchedules.Size = new System.Drawing.Size(128, 305);
             this.tvSchedules.Sorted = true;
             this.tvSchedules.TabIndex = 1;
@@ -785,5 +796,5 @@
             this.panelRight.Location = new System.Drawing.Point(996, 0);
             this.panelRight.Name = "panelRight";
-            this.panelRight.Size = new System.Drawing.Size(128, 347);
+            this.panelRight.Size = new System.Drawing.Size(128, 305);
             this.panelRight.TabIndex = 3;
             this.panelRight.Visible = false;
@@ -881,141 +892,6 @@
             this.panelCenter.Location = new System.Drawing.Point(136, 24);
             this.panelCenter.Name = "panelCenter";
-            this.panelCenter.Size = new System.Drawing.Size(857, 299);
+            this.panelCenter.Size = new System.Drawing.Size(857, 257);
             this.panelCenter.TabIndex = 7;
-            // 
-            // ctxCalendarGrid
-            // 
-            this.ctxCalendarGrid.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
-            this.ctxCalGridAdd,
-            this.ctxCalGridMkRadAppt,
-            this.ctxCalGridEdit,
-            this.ctxCalGridDelete,
-            this.ctxCalGridCancelRadAppt,
-            this.ctxCalGridCheckIn,
-            this.ctxCalGridUndoCheckin,
-            this.ctxCalGridSep1,
-            this.ctxCalGridNoShow,
-            this.ctxCalGridNoShowUndo,
-            this.ctxCalGridSep2,
-            this.ctxCalGridWalkin,
-            this.ctxCalGridSep3,
-            this.ctxCalGridReprintApptSlip});
-            this.ctxCalendarGrid.Popup += new System.EventHandler(this.ctxCalendarGrid_Popup);
-            // 
-            // ctxCalGridAdd
-            // 
-            this.ctxCalGridAdd.Index = 0;
-            this.ctxCalGridAdd.Text = "Add Appointment";
-            this.ctxCalGridAdd.Click += new System.EventHandler(this.ctxCalGridAdd_Click);
-            // 
-            // ctxCalGridMkRadAppt
-            // 
-            this.ctxCalGridMkRadAppt.Index = 1;
-            this.ctxCalGridMkRadAppt.Text = "Make Radiology Appointment";
-            this.ctxCalGridMkRadAppt.Click += new System.EventHandler(this.ctxCalGridMkRadAppt_Click);
-            // 
-            // ctxCalGridEdit
-            // 
-            this.ctxCalGridEdit.Index = 2;
-            this.ctxCalGridEdit.Text = "Edit Appointment";
-            this.ctxCalGridEdit.Click += new System.EventHandler(this.ctxCalGridEdit_Click);
-            // 
-            // ctxCalGridDelete
-            // 
-            this.ctxCalGridDelete.Index = 3;
-            this.ctxCalGridDelete.Text = "Cancel Appointment";
-            this.ctxCalGridDelete.Click += new System.EventHandler(this.ctxCalGridDelete_Click);
-            // 
-            // ctxCalGridCancelRadAppt
-            // 
-            this.ctxCalGridCancelRadAppt.Index = 4;
-            this.ctxCalGridCancelRadAppt.Text = "Cancel Radiology Appointment";
-            this.ctxCalGridCancelRadAppt.Click += new System.EventHandler(this.ctxCalGridCancelRadAppt_Click);
-            // 
-            // ctxCalGridCheckIn
-            // 
-            this.ctxCalGridCheckIn.Index = 5;
-            this.ctxCalGridCheckIn.Text = "Check In Patient";
-            this.ctxCalGridCheckIn.Click += new System.EventHandler(this.ctxCalGridCheckIn_Click);
-            // 
-            // ctxCalGridUndoCheckin
-            // 
-            this.ctxCalGridUndoCheckin.Index = 6;
-            this.ctxCalGridUndoCheckin.Text = "&Undo Check In";
-            this.ctxCalGridUndoCheckin.Click += new System.EventHandler(this.ctxCalGridUndoCheckin_Click);
-            // 
-            // ctxCalGridSep1
-            // 
-            this.ctxCalGridSep1.Index = 7;
-            this.ctxCalGridSep1.Text = "-";
-            // 
-            // ctxCalGridNoShow
-            // 
-            this.ctxCalGridNoShow.Index = 8;
-            this.ctxCalGridNoShow.Text = "Mark as No Show";
-            this.ctxCalGridNoShow.Click += new System.EventHandler(this.ctxCalGridNoShow_Click);
-            // 
-            // ctxCalGridNoShowUndo
-            // 
-            this.ctxCalGridNoShowUndo.Index = 9;
-            this.ctxCalGridNoShowUndo.Text = "Undo NoShow";
-            this.ctxCalGridNoShowUndo.Click += new System.EventHandler(this.ctxCalGridNoShowUndo_Click);
-            // 
-            // ctxCalGridSep2
-            // 
-            this.ctxCalGridSep2.Index = 10;
-            this.ctxCalGridSep2.Text = "-";
-            // 
-            // ctxCalGridWalkin
-            // 
-            this.ctxCalGridWalkin.Index = 11;
-            this.ctxCalGridWalkin.Text = "Create Wal&k-In Appointment";
-            this.ctxCalGridWalkin.Click += new System.EventHandler(this.ctxCalGridWalkin_Click);
-            // 
-            // ctxCalGridSep3
-            // 
-            this.ctxCalGridSep3.Index = 12;
-            this.ctxCalGridSep3.Text = "-";
-            // 
-            // ctxCalGridReprintApptSlip
-            // 
-            this.ctxCalGridReprintApptSlip.Index = 13;
-            this.ctxCalGridReprintApptSlip.Text = "&Reprint Appointment Slip";
-            this.ctxCalGridReprintApptSlip.Click += new System.EventHandler(this.ctxCalGridReprintApptSlip_Click);
-            // 
-            // panelBottom
-            // 
-            this.panelBottom.Controls.Add(this.statusBar1);
-            this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
-            this.panelBottom.Location = new System.Drawing.Point(136, 323);
-            this.panelBottom.Name = "panelBottom";
-            this.panelBottom.Size = new System.Drawing.Size(857, 24);
-            this.panelBottom.TabIndex = 8;
-            // 
-            // statusBar1
-            // 
-            this.statusBar1.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.statusBar1.Location = new System.Drawing.Point(0, 0);
-            this.statusBar1.Name = "statusBar1";
-            this.statusBar1.Size = new System.Drawing.Size(857, 24);
-            this.statusBar1.SizingGrip = false;
-            this.statusBar1.TabIndex = 0;
-            // 
-            // splitter1
-            // 
-            this.splitter1.Location = new System.Drawing.Point(128, 24);
-            this.splitter1.Name = "splitter1";
-            this.splitter1.Size = new System.Drawing.Size(8, 323);
-            this.splitter1.TabIndex = 9;
-            this.splitter1.TabStop = false;
-            // 
-            // splitter2
-            // 
-            this.splitter2.Dock = System.Windows.Forms.DockStyle.Right;
-            this.splitter2.Location = new System.Drawing.Point(993, 24);
-            this.splitter2.Name = "splitter2";
-            this.splitter2.Size = new System.Drawing.Size(3, 323);
-            this.splitter2.TabIndex = 10;
-            this.splitter2.TabStop = false;
             // 
             // calendarGrid1
@@ -1038,5 +914,5 @@
             this.calendarGrid1.Resources = ((System.Collections.ArrayList)(resources.GetObject("calendarGrid1.Resources")));
             this.calendarGrid1.SelectedAppointment = 0;
-            this.calendarGrid1.Size = new System.Drawing.Size(857, 299);
+            this.calendarGrid1.Size = new System.Drawing.Size(857, 257);
             this.calendarGrid1.StartDate = new System.DateTime(2003, 1, 27, 0, 0, 0, 0);
             this.calendarGrid1.TabIndex = 0;
@@ -1048,8 +924,164 @@
             this.calendarGrid1.MouseEnter += new System.EventHandler(this.calendarGrid1_MouseEnter);
             // 
+            // ctxCalendarGrid
+            // 
+            this.ctxCalendarGrid.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
+            this.ctxCalGridAdd,
+            this.ctxCalGridMkRadAppt,
+            this.ctxCalGridEdit,
+            this.ctxCalGridDelete,
+            this.ctxCalGridCancelRadAppt,
+            this.ctxCalGridCloneForward,
+            this.ctxCopyAppointment,
+            this.ctxCalGridCheckIn,
+            this.ctxCalGridUndoCheckin,
+            this.ctxCalGridNoShow,
+            this.ctxCalGridNoShowUndo,
+            this.ctxCalGridSep1,
+            this.ctxCalGridExportInvite,
+            this.ctxCalGridSep2,
+            this.ctxCalGridWalkin,
+            this.ctxCalGridSep3,
+            this.ctxCalGridReprintApptSlip});
+            this.ctxCalendarGrid.Popup += new System.EventHandler(this.ctxCalendarGrid_Popup);
+            // 
+            // ctxCalGridAdd
+            // 
+            this.ctxCalGridAdd.Index = 0;
+            this.ctxCalGridAdd.Text = "Add Appointment";
+            this.ctxCalGridAdd.Click += new System.EventHandler(this.ctxCalGridAdd_Click);
+            // 
+            // ctxCalGridMkRadAppt
+            // 
+            this.ctxCalGridMkRadAppt.Index = 1;
+            this.ctxCalGridMkRadAppt.Text = "Make Radiology Appointment";
+            this.ctxCalGridMkRadAppt.Click += new System.EventHandler(this.ctxCalGridMkRadAppt_Click);
+            // 
+            // ctxCalGridEdit
+            // 
+            this.ctxCalGridEdit.Index = 2;
+            this.ctxCalGridEdit.Text = "Edit Appointment";
+            this.ctxCalGridEdit.Click += new System.EventHandler(this.ctxCalGridEdit_Click);
+            // 
+            // ctxCalGridDelete
+            // 
+            this.ctxCalGridDelete.Index = 3;
+            this.ctxCalGridDelete.Text = "Cancel Appointment";
+            this.ctxCalGridDelete.Click += new System.EventHandler(this.ctxCalGridDelete_Click);
+            // 
+            // ctxCalGridCancelRadAppt
+            // 
+            this.ctxCalGridCancelRadAppt.Index = 4;
+            this.ctxCalGridCancelRadAppt.Text = "Cancel Radiology Appointment";
+            this.ctxCalGridCancelRadAppt.Click += new System.EventHandler(this.ctxCalGridCancelRadAppt_Click);
+            // 
+            // ctxCalGridCloneForward
+            // 
+            this.ctxCalGridCloneForward.Index = 5;
+            this.ctxCalGridCloneForward.Text = "Copy/Forward Appointment";
+            this.ctxCalGridCloneForward.Click += new System.EventHandler(this.ctxCalGridCloneForward_Click);
+            // 
+            // ctxCopyAppointment
+            // 
+            this.ctxCopyAppointment.Index = 6;
+            this.ctxCopyAppointment.Text = "Copy to Clipboard";
+            this.ctxCopyAppointment.Click += new System.EventHandler(this.ctxCopyAppointment_Click);
+            // 
+            // ctxCalGridCheckIn
+            // 
+            this.ctxCalGridCheckIn.Index = 7;
+            this.ctxCalGridCheckIn.Text = "Check In Patient";
+            this.ctxCalGridCheckIn.Click += new System.EventHandler(this.ctxCalGridCheckIn_Click);
+            // 
+            // ctxCalGridUndoCheckin
+            // 
+            this.ctxCalGridUndoCheckin.Index = 8;
+            this.ctxCalGridUndoCheckin.Text = "&Undo Check In";
+            this.ctxCalGridUndoCheckin.Click += new System.EventHandler(this.ctxCalGridUndoCheckin_Click);
+            // 
+            // ctxCalGridNoShow
+            // 
+            this.ctxCalGridNoShow.Index = 9;
+            this.ctxCalGridNoShow.Text = "Mark as No Show";
+            this.ctxCalGridNoShow.Click += new System.EventHandler(this.ctxCalGridNoShow_Click);
+            // 
+            // ctxCalGridNoShowUndo
+            // 
+            this.ctxCalGridNoShowUndo.Index = 10;
+            this.ctxCalGridNoShowUndo.Text = "Undo NoShow";
+            this.ctxCalGridNoShowUndo.Click += new System.EventHandler(this.ctxCalGridNoShowUndo_Click);
+            // 
+            // ctxCalGridSep1
+            // 
+            this.ctxCalGridSep1.Index = 11;
+            this.ctxCalGridSep1.Text = "-";
+            // 
+            // ctxCalGridExportInvite
+            // 
+            this.ctxCalGridExportInvite.Index = 12;
+            this.ctxCalGridExportInvite.Text = "Export Canendar Invite";
+            this.ctxCalGridExportInvite.Click += new System.EventHandler(this.ctxExportInvite_Click);
+            // 
+            // ctxCalGridSep2
+            // 
+            this.ctxCalGridSep2.Index = 13;
+            this.ctxCalGridSep2.Text = "-";
+            // 
+            // ctxCalGridWalkin
+            // 
+            this.ctxCalGridWalkin.Index = 14;
+            this.ctxCalGridWalkin.Text = "Create Wal&k-In Appointment";
+            this.ctxCalGridWalkin.Click += new System.EventHandler(this.ctxCalGridWalkin_Click);
+            // 
+            // ctxCalGridSep3
+            // 
+            this.ctxCalGridSep3.Index = 15;
+            this.ctxCalGridSep3.Text = "-";
+            // 
+            // ctxCalGridReprintApptSlip
+            // 
+            this.ctxCalGridReprintApptSlip.Index = 16;
+            this.ctxCalGridReprintApptSlip.Text = "&Reprint Appointment Slip";
+            this.ctxCalGridReprintApptSlip.Click += new System.EventHandler(this.ctxCalGridReprintApptSlip_Click);
+            // 
+            // panelBottom
+            // 
+            this.panelBottom.Controls.Add(this.statusBar1);
+            this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
+            this.panelBottom.Location = new System.Drawing.Point(136, 281);
+            this.panelBottom.Name = "panelBottom";
+            this.panelBottom.Size = new System.Drawing.Size(857, 24);
+            this.panelBottom.TabIndex = 8;
+            // 
+            // statusBar1
+            // 
+            this.statusBar1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.statusBar1.Location = new System.Drawing.Point(0, 0);
+            this.statusBar1.Name = "statusBar1";
+            this.statusBar1.Size = new System.Drawing.Size(857, 24);
+            this.statusBar1.SizingGrip = false;
+            this.statusBar1.TabIndex = 0;
+            // 
+            // splitter1
+            // 
+            this.splitter1.Location = new System.Drawing.Point(128, 24);
+            this.splitter1.Name = "splitter1";
+            this.splitter1.Size = new System.Drawing.Size(8, 281);
+            this.splitter1.TabIndex = 9;
+            this.splitter1.TabStop = false;
+            // 
+            // splitter2
+            // 
+            this.splitter2.Dock = System.Windows.Forms.DockStyle.Right;
+            this.splitter2.Location = new System.Drawing.Point(993, 24);
+            this.splitter2.Name = "splitter2";
+            this.splitter2.Size = new System.Drawing.Size(3, 281);
+            this.splitter2.TabIndex = 10;
+            this.splitter2.TabStop = false;
+            // 
             // CGView
             // 
             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
-            this.ClientSize = new System.Drawing.Size(1124, 347);
+            this.ClientSize = new System.Drawing.Size(1124, 305);
             this.Controls.Add(this.panelCenter);
             this.Controls.Add(this.panelBottom);
@@ -1212,4 +1244,5 @@
                     lstClip.Items.Add(a);
 				}
+                copyAppointmentToClipBoard();
 			}
 			catch (Exception ex)
@@ -1398,7 +1431,35 @@
 		}
 
-		#endregion ctxApptClipMenu Handlers
-
-		#region ctxCalGridMenu Handlers
+        #endregion ctxApptClipMenu Handlers
+
+        #region ctxCalGridMenu Handlers
+
+        private Configuration GetConfiguration() {
+            Configuration conf = null;
+            var fileName = Path.Combine(Environment.GetFolderPath(
+    Environment.SpecialFolder.ApplicationData), "ClinicalScheduling.exe.config");
+            if (!File.Exists(fileName))
+            {
+                try
+                {
+                    Configuration temp = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
+                    File.Copy(temp.FilePath, fileName);
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show(ex.Message);
+                    return conf;
+                }
+            }
+            if (!File.Exists(fileName))
+            {
+                MessageBox.Show("Unable to locate the app.config file.");
+                return conf;
+            }
+            ExeConfigurationFileMap mapping = new ExeConfigurationFileMap();
+            mapping.ExeConfigFilename = fileName;
+            conf = ConfigurationManager.OpenMappedExeConfiguration(mapping, ConfigurationUserLevel.None);
+            return conf;
+        }
 
 		private void ctxCalendarGrid_Popup(object sender, System.EventArgs e)
@@ -1411,4 +1472,7 @@
             bool _noShowEnabled = NoShowEnabled();
             bool _undoCheckinEnabled = UndoCheckinEnabled();
+            bool _cloneForwardEnabled = CloneForwardEnabled();
+            bool _exportCalendarInviteEnabled = ExportCalendarInviteEnabled();
+            bool _copyAppointmentEnabled = CopyAppointmentEnabled();
             //end flags
 
@@ -1423,6 +1487,9 @@
                 ctxCalGridWalkin.Visible = false;
                 ctxCalGridUndoCheckin.Visible = false;
+                ctxCalGridSep2.Visible = false;
+                ctxCalGridCloneForward.Visible = false;
+                ctxCalGridExportInvite.Visible = false;
                 ctxCalGridSep1.Visible = false;
-                ctxCalGridSep2.Visible = false;
+                ctxCopyAppointment.Visible = false;
 
                 ctxCalGridMkRadAppt.Visible = true;
@@ -1442,6 +1509,9 @@
                 ctxCalGridWalkin.Visible = true;
                 ctxCalGridUndoCheckin.Visible = true;
+                ctxCalGridSep2.Visible = true;
+                ctxCalGridCloneForward.Visible = true;
+                ctxCalGridExportInvite.Visible = true;
                 ctxCalGridSep1.Visible = true;
-                ctxCalGridSep2.Visible = true;
+                ctxCopyAppointment.Visible = true;
 
                 ctxCalGridMkRadAppt.Visible = false;
@@ -1465,4 +1535,15 @@
             ctxCalGridMkRadAppt.Enabled = _isRadAppt && _addApptsEnabled;
             ctxCalGridCancelRadAppt.Enabled = _isRadAppt && _editApptsEnabled;
+
+            ctxCalGridCloneForward.Enabled = !_isRadAppt && _cloneForwardEnabled;
+            ctxCalGridExportInvite.Enabled = !_isRadAppt && _exportCalendarInviteEnabled;
+            ctxCopyAppointment.Enabled = !_isRadAppt && _copyAppointmentEnabled;
+            //Configuration conf = GetConfiguration();            
+            //MessageBox.Show(conf.ConnectionStrings["useEmail"]);
+            Configuration conf = GetConfiguration();
+            if (conf.AppSettings.Settings["useEmail"].Value == "true")
+            {
+                ctxCalGridExportInvite.Text = "Email Canlendar Invite";
+            }
         }
 
@@ -1677,4 +1758,49 @@
             CGAppointment appt = (CGAppointment)this.Appointments.AppointmentTable[calendarGrid1.SelectedAppointment];
             return !appt.NoShow;
+        }
+
+        private bool CloneForwardEnabled() {
+            if (calendarGrid1.SelectedAppointment < 1)
+                return false;
+            return true;
+        }
+
+        private bool CopyAppointmentEnabled()
+        {
+            return EditAppointmentEnabled();
+        }
+
+        private bool ExportCalendarInviteEnabled()
+        {
+            if (calendarGrid1.SelectedAppointment < 1)
+                return false;
+            CGAppointment appt = (CGAppointment)this.Appointments.AppointmentTable[calendarGrid1.SelectedAppointment];
+            if (appt.StartTime < DateTime.Now)
+            {
+                return false;
+            }
+            if (appt.Patient.Email == null)
+            {
+                try
+                {
+                    string sSql;
+                    sSql = "BSDX GET BASIC REG INFO^" + appt.PatientID.ToString();
+
+                    DataTable tb = m_DocManager.RPMSDataTable(sSql, "PatientRegInfo");
+
+                    Debug.Assert(tb.Rows.Count == 1);
+                    DataRow r = tb.Rows[0];
+                    appt.Patient.Email = r["EMAIL ADDRESS"].ToString();
+                }
+                catch (Exception e)
+                {                    
+                    MessageBox.Show("DAppointPage::InitializePage -- Unable to retrieve patient information from VistA.  " + e.Message);
+                }
+                if (appt.Patient.Email == "")
+                {
+                    return false;
+                }
+            }
+            return true;
         }
 
@@ -2047,4 +2173,5 @@
 				dAppt.DocManager = this.m_DocManager;
 				dAppt.InitializePage(a);
+                dAppt.HideCloneForwardTab();
 
 				calendarGrid1.CGToolTip.Active = false;
@@ -2078,4 +2205,60 @@
 			}
 		}
+
+        private void AppointmentCloneForward(ArrayList alResources)
+        {
+            try
+            {
+                int nApptID = this.calendarGrid1.SelectedAppointment;
+                Debug.Assert(nApptID != 0);
+
+                CGAppointment a = (CGAppointment)this.Appointments.AppointmentTable[nApptID];
+
+                DAppointPage dAppt = new DAppointPage();
+                dAppt.DocManager = this.m_DocManager;
+                dAppt.InitializePage(a);
+
+                calendarGrid1.CGToolTip.Active = false;
+
+                dAppt.SetCloneForwardable(alResources, a);
+                
+
+                if (dAppt.ShowDialog(this) == DialogResult.Cancel)
+                {
+                    calendarGrid1.CGToolTip.Active = true;
+                    return;
+                }
+                calendarGrid1.CGToolTip.Active = true;
+
+                string sNote = dAppt.Note;
+
+                CGAppointment appt = dAppt.Appointment;
+
+                //Call Document to add a new appointment. Document adds appointment to CGAppointments array.
+                this.Document.CreateAppointment(appt);
+
+
+                if (dAppt.PrintAppointmentSlip)
+                {
+                    PrintAppointmentSlip(appt);
+                }
+
+                //Show the new set of appointments by calling UpdateArrays. Fetches Document's CGAppointments
+                this.UpdateArrays();
+
+                RaiseRPMSEvent("BSDX SCHEDULE", appt.Resource);
+            }
+            catch (Exception ex)
+            {
+                string msg;
+                if (M.Piece(ex.Message, "~", 1) == "-10") // -10 means that BSDXAPI reported an error.
+                    msg = M.Piece(ex.Message, "~", 4);
+                else
+                    msg = ex.Message;
+
+                MessageBox.Show("VISTA says: \r\n" + msg, "Unable to Make Appointment");
+                return;
+            }
+        }
 
 		/// <summary>
@@ -2590,5 +2773,6 @@
                 m_nSlots = m_Document.SlotsAvailable(dStart, dEnd, sResource, this.calendarGrid1.TimeScale, out resultantAvail);
 
-				if (m_nSlots < 1)
+				/* Faisal Don't show overbood popup
+                if (m_nSlots < 1)
 				{
 					DialogResult dr = MessageBox.Show(this, "There are no slots available at the selected time.  Do you want to overbook this appointment?", "Clinical Scheduling",MessageBoxButtons.YesNo);
@@ -2597,5 +2781,5 @@
 						return;
 					}
-				}
+				}*/
 
 				//Display a dialog to collect Patient Name
@@ -2617,4 +2801,5 @@
 				string sNote = "";
                 dAppt.InitializePage(dPat.PatientIEN, dStart, dEnd, sResource, sNote, nAccessTypeID);
+                dAppt.HideCloneForwardTab();
 
 				if (dAppt.ShowDialog(this) == DialogResult.Cancel)
@@ -3215,5 +3400,12 @@
 				CGDocumentManager.Current.RemoteSession.EventServices.RpmsEvent -= BMXNetEventHandler;
 				this.calendarGrid1.CloseGrid();
-			}
+                if (this.DocManager.m_SsshProcess != null)
+                {
+                    if (!this.DocManager.m_SsshProcess.HasExited)
+                    {
+                        this.DocManager.m_SsshProcess.Kill();
+                    }                    
+                }
+            }
 			catch (Exception ex)
 			{
@@ -3966,5 +4158,130 @@
         }
 
-
+        private void ctxCalGridCloneForward_Click(object sender, EventArgs e)
+        {
+            AppointmentCloneForward(m_alSelectedTreeResourceArray);
+        }
+
+        private void menuItem8_Click(object sender, EventArgs e)
+        {
+
+        }
+
+        private StringBuilder GetCalendarInvite(CGAppointment appt, String emailSubject, String emailBody)
+        {
+            StringBuilder sb = new StringBuilder();
+            Configuration conf = GetConfiguration();
+            sb.AppendLine("BEGIN:VCALENDAR");
+            sb.AppendLine(string.Format("PRODID:-//{0}//BSDX Scheduling 1.7//EN", conf.AppSettings.Settings["organization"].Value));
+            sb.AppendLine("VERSION:2.0");
+            sb.AppendLine("CALSCALE:GREGORIAN");
+            sb.AppendLine("METHOD:REQUEST");
+            sb.AppendLine("X-WR-CALDESC:");
+            sb.AppendLine("BEGIN:VEVENT");
+            sb.AppendLine(string.Format("DTSTART;VALUE=DATE-TIME:{0:yyyyMMddTHHmmssZ}", appt.StartTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
+            sb.AppendLine(string.Format("DTEND;VALUE=DATE-TIME:{0:yyyyMMddTHHmmssZ}", appt.EndTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
+            sb.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.Now.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z")));
+            sb.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
+            sb.AppendLine(string.Format("DESCRIPTION:{0}", emailBody));
+            sb.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", emailBody));
+            sb.AppendLine(string.Format("SUMMARY:{0}", emailSubject));
+            sb.AppendLine(string.Format("ORGANIZER:MAILTO:{0}", conf.AppSettings.Settings["userEmail"].Value)); //
+            sb.AppendLine(string.Format("ATTENDEE;CN=\"{0}\";RSVP=TRUE:mailto:{1}", appt.Patient.Name, appt.Patient.Email));
+            sb.AppendLine("LOCATION:" + appt.Resource + ", " + conf.AppSettings.Settings["address"].Value); //appt.Resource);
+            sb.AppendLine("SEQUENCE:0");
+            sb.AppendLine("STATUS:CONFIRMED");
+            sb.AppendLine("TRANSP:TRANSPARENT");
+            sb.AppendLine("END:VEVENT");
+            sb.AppendLine("END:VCALENDAR");
+            return sb;
+        }
+
+        private void ExportCalendarInvite(CGAppointment appt, string emailSubject, string emailBody)
+        {
+            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
+            saveFileDialog1.Filter = "iCalendar File|*.ics";
+            saveFileDialog1.Title = "Save Calendar Invite";
+            saveFileDialog1.ShowDialog();
+            if (saveFileDialog1.FileName != "")
+            {
+                StringBuilder str = GetCalendarInvite(appt, emailSubject, emailBody);
+                FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);
+                StreamWriter sw = new StreamWriter(fs);
+                sw.Write(str.ToString());
+                sw.Close();
+                fs.Close();
+            }
+        }
+
+        private void EmailCalendarInvite(CGAppointment appt, String emailSubject, String emailBody)
+        {
+            Configuration conf = GetConfiguration();
+            SmtpClient sc = new SmtpClient(conf.AppSettings.Settings["smtpHost"].Value);
+
+            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
+
+            msg.From = new MailAddress(conf.AppSettings.Settings["userEmail"].Value);
+            msg.To.Add(new MailAddress(appt.Patient.Email, appt.Patient.Name));
+            msg.Bcc.Add(new MailAddress(conf.AppSettings.Settings["userEmail"].Value));
+            msg.Subject = emailSubject;
+            msg.IsBodyHtml = true;
+            msg.Body = emailBody;
+            StringBuilder str = GetCalendarInvite(appt, emailSubject, emailBody);
+            System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
+            ct.Parameters.Add("method", "REQUEST");
+            //ct.Parameters.Add("name", "meeting.ics");
+            AlternateView avCal = AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
+            msg.AlternateViews.Add(avCal);
+            NetworkCredential nc = new NetworkCredential(conf.AppSettings.Settings["userEmail"].Value, conf.AppSettings.Settings["userPassword"].Value);
+            sc.Port = Convert.ToInt32(conf.AppSettings.Settings["smtpPort"].Value);
+            sc.EnableSsl = Convert.ToBoolean(conf.AppSettings.Settings["enableSSL"].Value);
+            sc.Credentials = nc;
+            try
+            {
+                sc.Send(msg);
+            }
+            catch (Exception e)
+            {
+                MessageBox.Show("Unable to send email.  " + e.Message);
+            }
+        }
+
+        private void copyAppointmentToClipBoard() {            
+            int apptID = this.CGrid.SelectedAppointment;
+            Configuration conf = GetConfiguration();
+            if (apptID <= 0) return;
+            CGAppointment a = (CGAppointment)this.Appointments.AppointmentTable[apptID];
+
+            string str = "Clinic Title: " + a.Resource + "\n" +
+                            "Date/Time: " + a.StartTime.ToString() + "\n" +
+                            "Location: " + conf.AppSettings.Settings["address"].Value + "\n" +
+                            "Phone: " + conf.AppSettings.Settings["phone"].Value;
+            Clipboard.SetText(str);
+        }
+
+        private void ctxExportInvite_Click(object sender, EventArgs e)
+        {
+            Configuration conf = GetConfiguration();
+            String emailBody = "Your Appointment is Scheduled.";
+            String emailSubject = conf.AppSettings.Settings["inviteSubject"].Value;
+            int apptID = this.CGrid.SelectedAppointment;
+            if (apptID <= 0) return;
+
+            CGAppointment a = (CGAppointment)this.Appointments.AppointmentTable[apptID];
+
+            if (conf.AppSettings.Settings["useEmail"].Value == "true")
+            {
+                EmailCalendarInvite(a, emailSubject, emailBody);
+            }
+            else
+            {
+                ExportCalendarInvite(a, emailSubject, emailBody);
+            }
+        }
+
+        private void ctxCopyAppointment_Click(object sender, EventArgs e)
+        {
+            copyAppointmentToClipBoard();
+        }
     }//End class
 }
