using System using System Collections Generic using System ServiceMode

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.Data.SqlClient;
using OfficeData;
using OfficeData.Report;
using OfficeServiceLibrary.OfficeModelTableAdapters;
namespace OfficeServiceLibrary
{
[ServiceBehavior(
InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class OfficeService : IOfficeContract
{
#region IOfficeService Members
private Dictionary<string, INotificationCallback> _clientpool
= new Dictionary<string, INotificationCallback>();
public void Register()
{
string sessionId = OperationContext.Current.SessionId;
INotificationCallback callback =
OperationContext.Current.
GetCallbackChannel<INotificationCallback>();
_clientpool.Add(sessionId, callback);
}
public void Unregister()
{
string sessionId = OperationContext.Current.SessionId;
_clientpool.Remove(sessionId);
}
public void AddDoctor(Doctor doctor)
{
DoctorTableAdapter adapter =
new DoctorTableAdapter();
adapter.Add(doctor.FirstName, doctor.LastName);
//TODO: Notify clients
SendUpdateNotification();
}
public void AddPatient(Patient patient)
{
PatientTableAdapter adapter =
new PatientTableAdapter();
adapter.Add(patient.FirstName, patient.LastName);
//TODO: Notify clients
SendUpdateNotification();
}
public void AddAppointment(Appointment apmt)
{
AppointmentTableAdapter adapter =
new AppointmentTableAdapter();
try
{
adapter.Add(apmt.Doctor.Id,
apmt.Patient.Id, apmt.Date, apmt.Duration);
}catch(SqlException e)
{
throw new FaultException<DuplicateMsg>(
new DuplicateMsg(){Reason = e.Message});
}
//TODO: Notify clients
SendUpdateNotification();
}
public List<Doctor> GetDoctors()
{
DoctorTableAdapter adapter
= new DoctorTableAdapter();
return adapter.GetAll().ToDataList();
}
public List<Patient> GetPatients()
{
PatientTableAdapter adapter
= new PatientTableAdapter();
return adapter.GetAll().ToDataList();
}
public List<Patient> GetPatientsByDoctor(Doctor doctor)
{
PatientTableAdapter adapter
= new PatientTableAdapter();
return adapter.GetByDoctor(doctor.Id).ToDataList();
}
public List<Appointment> GetApmtByDate(DateTime date)
{
ApmtByDateTableAdapter adapter =
new ApmtByDateTableAdapter();
return adapter.GetData(date).ToDataList();
}
public List<Appointment> GetApmtByRelation(
Doctor doctor, Patient patient)
{
AppointmentTableAdapter adapter =
new AppointmentTableAdapter();
return adapter.GetByRelation(
doctor.Id, patient.Id).ToDataList();
}
public List<DoctorCount> DoctorCountReport()
{
DoctorCntReportTableAdapter adapter =
new DoctorCntReportTableAdapter();
return adapter.GetData().ToDataList();
}
public List<ApmtPercent> ApmtPercentReport(
DateTime beginDate, DateTime endDate)
{
ApmtPercentReportTableAdapter adapter =
new ApmtPercentReportTableAdapter();
return adapter.GetData(
beginDate.Date, endDate.Date).ToDataList();
}
public List<ApmtConflict> ApmtConflictReport()
{
ApmtConflictReportTableAdapter adapter =
new ApmtConflictReportTableAdapter();
return adapter.GetData().ToDataList();
}
private void SendUpdateNotification()
{
foreach (INotificationCallback cb in _clientpool.Values)
{
cb.OnUpdateNotification();
}
}
#endregion
}
}