I dette afsnit vises eksempler på hvordan servicen kan kaldes fra et C# program. Der ligges til grund, at der er oprettet en reference til servicen.
Download Testprogram
Testprogrammer giver mulighed for at afprøve de forskellige kald og viser output.
Download her
Eksempel 1 - Hent aktive sagsbehandlere
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
|
private void button_GetActiveOffcers_Click( object sender, EventArgs e) { try { listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); var officers = (from officer in svc.Officers where officer.Active == "1" orderby (officer.OfficerName) select officer).ToList(); listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3}" , "OfficerId" .PadRight(9), "OfficerName" .PadRight(60), "DepartmentId" .PadRight(12), "TeamId" .PadRight(6))); foreach (var officer in officers) { listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3}" , officer.OfficerId.PadRight(9), officer.OfficerName.PadRight(60), (officer.DepartmentId ?? "" ).PadRight(12), (officer.TeamId ?? "" ).PadRight(6))); } } catch (Exception ex) { listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); } } } |
Eksempel 2 - Hent aktive landbrugs aktiviteter
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
|
private void button_GetActiveTimeRecAgricultureActivities_Click( object sender, EventArgs e) { try { listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); var activities = (from activity in svc.TimeRecAgricultureActivities where activity.Active == "1" orderby (activity.ActivityName) select activity).ToList(); listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , "ActivityId" .PadRight(10), "ActivityName" .PadRight(40), "Description" .PadRight(40), "DepartmentId" .PadRight(12), "TeamId" .PadRight(6), "BillingRate" .PadLeft(11), "BillingType" .PadRight(63))); foreach (var activity in activities) { listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , activity.ActivityId.PadRight(10), activity.ActivityName.PadRight(40), ((activity.Description ?? "" ).Length > 40 ? activity.Description.Substring(0, 37) + "..." : (activity.Description ?? "" )).PadRight(40), (activity.DepartmentId ?? "" ).PadRight(12), (activity.TeamId ?? "" ).PadRight(6), activity.BillingRate.ToString().PadLeft(11), activity.BillingType.PadRight(63))); } } catch (Exception ex) { listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); } } } |
Eksempel 3 - Hent viirksomheder omfattet af brugerbetaling
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
|
private void button_GetCompaniesWhereLiableToPayEqYes_Click( object sender, EventArgs e) { try { listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); var companies = (from company in svc.Companies where company.LiableToPay == "1" orderby (company.Name) select company).ToList(); listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , "SiteSeqNo" .PadLeft(9), "Id" .PadRight(20), "Name" .PadRight(50), "Address" .PadRight(60), "PostalCode" .PadRight(10), "PostalCodeName" .PadRight(30), "Status" .PadRight(31))); foreach (var company in companies) { listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , company.SiteSeqNo.ToString().PadLeft(9), company.Id.PadRight(20), (company.Name ?? "" ).PadRight(50), (company.Address ?? "" ).PadRight(60), (company.PostalCode ?? "" ).PadRight(10), (company.PostalCodeName ?? "" ).PadRight(30), company.Status.PadRight(31))); } } catch (Exception ex) { listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); } } } |
Eksempel 4 - hent landbrug omfattet af brugerbaling
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
|
private void button_GetAgriculturesWhereLiableToPayEqYes_Click( object sender, EventArgs e) { try { listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); var agricultures = (from agriculture in svc.Agricultures where agriculture.LiableToPay == "1" orderby (agriculture.Name) select agriculture).ToList(); listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , "SiteSeqNo" .PadLeft(9), "Id" .PadRight(20), "Name" .PadRight(50), "Address" .PadRight(60), "PostalCode" .PadRight(10), "PostalCodeName" .PadRight(30), "Status" .PadRight(31))); foreach (var agriculture in agricultures) { listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , agriculture.SiteSeqNo.ToString().PadLeft(9), agriculture.Id.PadRight(20), (agriculture.Name ?? "" ).PadRight(50), (agriculture.Address ?? "" ).PadRight(60), (agriculture.PostalCode ?? "" ).PadRight(10), (agriculture.PostalCodeName ?? "" ).PadRight(30), agriculture.Status.PadRight(31))); } } catch (Exception ex) { listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); } } } |
Eksempel 5 - Hent aktive virksomheds aktiviteter
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
|
private void button_GetActiveTimeRecCompanyActivities_Click( object sender, EventArgs e) { try { listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); var activities = (from activity in svc.TimeRecCompanyActivities where activity.Active == "1" orderby (activity.ActivityName) select activity).ToList(); listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , "ActivityId" .PadRight(10), "ActivityName" .PadRight(40), "Description" .PadRight(40), "DepartmentId" .PadRight(12), "TeamId" .PadRight(6), "BillingRate" .PadLeft(11), "BillingType" .PadRight(60))); foreach (var activity in activities) { listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4} {5} {6}" , activity.ActivityId.PadRight(10), activity.ActivityName.PadRight(40), ((activity.Description ?? "" ).Length > 40 ? activity.Description.Substring(0, 37) + "..." : (activity.Description ?? "" )).PadRight(40), (activity.DepartmentId ?? "" ).PadRight(12), (activity.TeamId ?? "" ).PadRight(6), activity.BillingRate.ToString().PadLeft(11), activity.BillingType.PadRight(60))); } } catch (Exception ex) { listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); } } } |
Eksempel 6 - Hent tidsregistreringer
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
|
private void button_GetTimeRecordings_Click( object sender, EventArgs e) { try { listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); var timeRecordings = (from timeRecording in svc.TimeRecordings select timeRecording).OrderBy(x => x.OfficerId).ThenBy(x => x.RecDate).ToList(); listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4}" , "OfficerId" .PadRight(9), "SiteSeqNo" .PadLeft(9), "ActivityId" .PadRight(10), "RecDate" .PadRight(10), "RecHours" .PadLeft(8))); foreach (var timeRecirding in timeRecordings) { listBox_Output.Items.Add( string .Format( "{0} {1} {2} {3} {4}" , timeRecirding.OfficerId.PadRight(9), timeRecirding.SiteSeqNo.ToString().PadLeft(9), timeRecirding.ActivityId.PadRight(10), timeRecirding.RecDate.ToString( "dd.MM.yyyy" ).PadRight(10), timeRecirding.RecHours.ToString().PadLeft(8))); } } catch (Exception ex) { listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); } } } |
Eksempel 7 - Opret / Rediger tidsregistreringer
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
|
private void button_CreateOrUpdateTimeRecording_Click( object sender, EventArgs e) { string officerId; decimal siteSeqNo; string activityId; DateTime recDate; decimal recHours; listBox_Output.Items.Clear(); webBrowser.Navigate( "about:blank" ); try { officerId = textBox_OfficerId.Text; if (! decimal .TryParse(textBox_SiteSeqNo.Text, out siteSeqNo)) throw new Exception( "SiteSeqNo skal angives på formen xxxxxxxxx" ); activityId = textBox_ActivityId.Text; if (!DateTime.TryParse(textBox_RecDate.Text, out recDate)) throw new Exception( "RecDate skal angives på formen yyyy-MM-dd" ); if (! decimal .TryParse(textBox_RecHours.Text, out recHours)) throw new Exception( "RecHours skal angives på formen x,x (fx 3,5 timer)" ); } catch (Exception ex) { listBox_Output.Items.Add( "Fejl i input parametre!" ); listBox_Output.Items.Add( "Exception: " + ex.Message); return ; } try { //Registrer TimeRecording var svc = new GeoEnvironODataServiceContext( new Uri(textBox_UriString.Text)); TimeRecording newTimeRecording = new TimeRecording() { OfficerId = officerId, SiteSeqNo = siteSeqNo, ActivityId = activityId, RecDate = recDate, RecHours = recHours }; svc.AddToTimeRecordings(newTimeRecording); svc.SaveChanges(); //Verificer at timeRecording blev registreret TimeRecording tr = (from timeRecording in svc.TimeRecordings where timeRecording.OfficerId == newTimeRecording.OfficerId && timeRecording.SiteSeqNo == newTimeRecording.SiteSeqNo && timeRecording.ActivityId == newTimeRecording.ActivityId && timeRecording.RecDate.Year == newTimeRecording.RecDate.Year && timeRecording.RecDate.Month == newTimeRecording.RecDate.Month && timeRecording.RecDate.Day == newTimeRecording.RecDate.Day && timeRecording.RecHours == newTimeRecording.RecHours select timeRecording).SingleOrDefault(); if (tr == null ) throw new Exception( "Den nye TimeRecording er ikke blevet registreret" ); listBox_Output.Items.Add( "TimeRecording registreret" ); } catch (Exception ex) { listBox_Output.Items.Add( "TimeRecording ikke registreret!" ); listBox_Output.Items.Add( "Exception: " + ex.Message); if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<?xml version=\"1.0\" encoding=\"utf-8\"?>" )) { string temp = ex.InnerException.Message.Substring(ex.InnerException.Message.IndexOf( "<m:innererror><m:message>" ) + 25); listBox_Output.Items.Add( "InnerException: " + temp.Substring(0, temp.IndexOf( "</m:message>" ))); return ; } if (ex.InnerException != null && ex.InnerException.Message.StartsWith( "<!DOCTYPE html" )) { string fileName = System.IO.Path.GetTempPath() + "error.htm" ; using (System.IO.StreamWriter sw = new System.IO.StreamWriter(fileName)) sw.WriteLine(ex.InnerException.Message); webBrowser.Navigate(fileName); return ; } if (ex.InnerException != null ) listBox_Output.Items.Add( "InnerException: " + ex.InnerException.Message); } } |
Kommentarer
0 kommentarer
Artiklen er lukket for kommentarer.