File: dlgSchedule.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (859 lines) | stat: -rw-r--r-- 21,438 bytes parent folder | download
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgSchedule.cpp - PostgreSQL Schedule Property
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

// App headers
#include "utils/misc.h"
#include "agent/dlgSchedule.h"
#include "agent/pgaSchedule.h"

// image for de/-select all
#include "images/check.pngc"
#include "images/uncheck.pngc"

// pointer to controls
#define	txtID				CTRL_TEXT("txtID")
#define chkEnabled          CTRL_CHECKBOX("chkEnabled")
#define calStart            CTRL_CALENDAR("calStart")
#define timStart            CTRL_TIME("timStart")
#define calEnd              CTRL_CALENDAR("calEnd")
#define timEnd              CTRL_TIME("timEnd")
#define chkWeekdays			CTRL_CHECKLISTBOX("chkWeekdays")
#define chkMonthdays		CTRL_CHECKLISTBOX("chkMonthdays")
#define chkMonths			CTRL_CHECKLISTBOX("chkMonths")
#define chkHours			CTRL_CHECKLISTBOX("chkHours")
#define chkMinutes			CTRL_CHECKLISTBOX("chkMinutes")
#define lstExceptions       CTRL_LISTVIEW("lstExceptions")
#define timException     	CTRL_TIME("timException")
#define calException    	CTRL_CALENDAR("calException")
#define btnAddException     CTRL_BUTTON("btnAddException")
#define btnChangeException  CTRL_BUTTON("btnChangeException")
#define btnRemoveException  CTRL_BUTTON("btnRemoveException")
#define btnWeekdays  		CTRL_BUTTON("btnWeekdays")
#define btnMonthdays  		CTRL_BUTTON("btnMonthdays")
#define btnMonths  		CTRL_BUTTON("btnMonths")
#define btnHours  			CTRL_BUTTON("btnHours")
#define btnMinutes  		CTRL_BUTTON("btnMinutes")

BEGIN_EVENT_TABLE(dlgSchedule, dlgAgentProperty)
	EVT_CHECKBOX(XRCID("chkEnabled"),                dlgSchedule::OnChangeCom)
	EVT_CALENDAR_SEL_CHANGED(XRCID("calStart"),      dlgSchedule::OnChangeCal)
	EVT_TEXT(XRCID("timStart"),                      dlgSchedule::OnChangeCom)
	EVT_CALENDAR_SEL_CHANGED(XRCID("calEnd"),        dlgSchedule::OnChangeCal)
	EVT_TEXT(XRCID("timEnd"),                        dlgSchedule::OnChangeCom)
	EVT_LIST_ITEM_SELECTED(XRCID("lstExceptions"),   dlgSchedule::OnSelChangeException)
	EVT_BUTTON(XRCID("btnAddException"),             dlgSchedule::OnAddException)
	EVT_BUTTON(XRCID("btnChangeException"),          dlgSchedule::OnChangeException)
	EVT_BUTTON(XRCID("btnRemoveException"),          dlgSchedule::OnRemoveException)
	EVT_BUTTON(XRCID("btnWeekdays"),        	     dlgSchedule::OnSelectAllWeekdays)
	EVT_BUTTON(XRCID("btnMonthdays"),		         dlgSchedule::OnSelectAllMonthdays)
	EVT_BUTTON(XRCID("btnMonths"), 				     dlgSchedule::OnSelectAllMonths)
	EVT_BUTTON(XRCID("btnHours"),  			         dlgSchedule::OnSelectAllHours)
	EVT_BUTTON(XRCID("btnMinutes"),			         dlgSchedule::OnSelectAllMinutes)
	EVT_CHECKLISTBOX(XRCID("chkWeekdays"),           dlgSchedule::OnChangeCom)
	EVT_CHECKLISTBOX(XRCID("chkMonthdays"),          dlgSchedule::OnChangeCom)
	EVT_CHECKLISTBOX(XRCID("chkMonths"),             dlgSchedule::OnChangeCom)
	EVT_CHECKLISTBOX(XRCID("chkHours"),              dlgSchedule::OnChangeCom)
	EVT_CHECKLISTBOX(XRCID("chkMinutes"),            dlgSchedule::OnChangeCom)
#ifdef __WXMAC__
	EVT_SIZE(                                        dlgSchedule::OnChangeSize)
#endif
END_EVENT_TABLE();


dlgProperty *pgaScheduleFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
	return new dlgSchedule(this, frame, (pgaSchedule *)node, (pgaJob *)parent);
}


dlgSchedule::dlgSchedule(pgaFactory *f, frmMain *frame, pgaSchedule *node, pgaJob *j)
	: dlgAgentProperty(f, frame, wxT("dlgSchedule"))
{
	schedule = node;
	job = j;
	if (job)
		jobId = job->GetRecId();
	else
		jobId = 0;

	lstExceptions->CreateColumns(0, _("Date"), _("Time"), 90);
	lstExceptions->AddColumn(wxT("dirty"), 0);
	lstExceptions->AddColumn(wxT("id"), 0);

	txtID->Disable();

	btnChangeException->Disable();
	btnRemoveException->Disable();

	int i;

	for (i = 0 ; i < 24 ; i++)
		chkHours->Append(wxString::Format(wxT("%02d"), i));

	for (i = 0 ; i < 60 ; i++)
		chkMinutes->Append(wxString::Format(wxT("%02d"), i));
}


pgObject *dlgSchedule::GetObject()
{
	return schedule;
}


#ifdef __WXMAC__
void dlgSchedule::OnChangeSize(wxSizeEvent &ev)
{
	lstExceptions->SetSize(wxDefaultCoord, wxDefaultCoord,
	                       ev.GetSize().GetWidth(), ev.GetSize().GetHeight() - 350);
	if (GetAutoLayout())
	{
		Layout();
	}
}
#endif


int dlgSchedule::Go(bool modal)
{
	int returncode;

	if (schedule)
	{
		// edit mode
		recId = schedule->GetRecId();
		txtID->SetValue(NumToStr(recId));
		chkEnabled->SetValue(schedule->GetEnabled());
		calStart->SetValue(schedule->GetStart().GetDateOnly());
		timStart->SetTime(schedule->GetStart());
		if (schedule->GetEnd().IsValid())
		{
			calEnd->SetValue(schedule->GetEnd().GetDateOnly());
			timEnd->SetTime(schedule->GetEnd());
		}
		else
		{
			calEnd->SetValue(wxInvalidDateTime);
			timEnd->SetTime(wxInvalidDateTime);
			timEnd->Disable();
		}

		unsigned int x;
		for (x = 0; x < schedule->GetMonths().Length(); x++ )
			if (schedule->GetMonths()[x] == 't') chkMonths->Check(x, true);

		for (x = 0; x < schedule->GetMonthdays().Length(); x++ )
			if (schedule->GetMonthdays()[x] == 't') chkMonthdays->Check(x, true);

		for (x = 0; x < schedule->GetWeekdays().Length(); x++ )
			if (schedule->GetWeekdays()[x] == 't') chkWeekdays->Check(x, true);

		for (x = 0; x < schedule->GetHours().Length(); x++ )
			if (schedule->GetHours()[x] == 't') chkHours->Check(x, true);

		for (x = 0; x < schedule->GetMinutes().Length(); x++ )
			if (schedule->GetMinutes()[x] == 't') chkMinutes->Check(x, true);

		wxString id, dateToken, timeToken;
		wxDateTime val;
		long pos = 0;
		wxStringTokenizer tkz(schedule->GetExceptions(), wxT("|"));

		while (tkz.HasMoreTokens() )
		{
			dateToken.Empty();
			timeToken.Empty();

			// First is the ID
			id = tkz.GetNextToken();

			// Look for a date
			if (tkz.HasMoreTokens())
				dateToken = tkz.GetNextToken();

			// Look for a time
			if (tkz.HasMoreTokens())
				timeToken = tkz.GetNextToken();

			if (!dateToken.IsEmpty() && !timeToken.IsEmpty())
			{
				val.ParseDate(dateToken);
				val.ParseTime(timeToken);
				pos = lstExceptions->AppendItem(0, val.FormatDate(), val.FormatTime());
			}
			else if (!dateToken.IsEmpty() && timeToken.IsEmpty())
			{
				val.ParseDate(dateToken);
				pos = lstExceptions->AppendItem(0, val.FormatDate(), _("<any>"));
			}
			else if (dateToken.IsEmpty() && !timeToken.IsEmpty())
			{
				val.ParseTime(timeToken);
				pos = lstExceptions->AppendItem(0, _("<any>"), val.FormatTime());
			}

			lstExceptions->SetItem(pos, 2, BoolToStr(false));
			lstExceptions->SetItem(pos, 3, id);

		}

		wxNotifyEvent ev;
	}
	else
	{
		// create mode
	}

	// setup de-/select buttons
	InitSelectAll();

	returncode = dlgProperty::Go(modal);

	SetSqlReadOnly(true);

	return returncode;
}


pgObject *dlgSchedule::CreateObject(pgCollection *collection)
{
	pgObject *obj = scheduleFactory.CreateObjects(collection, 0, wxT("   AND jscid=") + NumToStr(recId) + wxT("\n"));
	return obj;
}


void dlgSchedule::OnChangeCal(wxCalendarEvent &ev)
{
	CheckChange();
}


void dlgSchedule::OnChangeCom(wxCommandEvent &ev)
{
	CheckChange();
}


void dlgSchedule::CheckChange()
{
	timEnd->Enable(calEnd->GetValue().IsValid());

	wxString name = GetName();
	bool enable = true;

	if (statusBar)
		statusBar->SetStatusText(wxEmptyString);

	InitSelectAll();

	CheckValid(enable, !name.IsEmpty(), _("Please specify name."));
	CheckValid(enable, calStart->GetValue().IsValid(), _("Please specify start date."));

	if (enable)
	{
		EnableOK(!GetSql().IsEmpty());
	}
	else
		EnableOK(false);
}


void dlgSchedule::OnSelChangeException(wxListEvent &ev)
{
	int sel = lstExceptions->GetSelection();
	if (sel >= 0)
	{
		wxString exDate = lstExceptions->GetText(sel, 0);
		wxString exTime = lstExceptions->GetText(sel, 1);
		wxDateTime val, null;

		if (exDate == _("<any>"))
			calException->SetValue(null);
		else
		{
			val.ParseDate(exDate);
			calException->SetValue(val);
		}
		if (exTime == _("<any>"))
			timException->SetTime(null);
		else
		{
			val.ParseTime(exTime);
			timException->SetTime(val);
		}

		btnChangeException->Enable();
		btnRemoveException->Enable();
	}
}


void dlgSchedule::OnAddException(wxCommandEvent &ev)
{
	if (!calException->GetValue().IsValid() && timException->GetValue().IsNull())
	{
		wxMessageBox(_("You must enter a valid date and/or time!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
		return;
	}

	wxString exDate, exTime;

	if (calException->GetValue().IsValid())
		exDate = calException->GetValue().FormatDate();
	else
		exDate = _("<any>");

	if (!timException->GetValue().IsNull())
		exTime = timException->GetValue().Format();
	else
		exTime = _("<any>");

	for (int pos = 0; pos < lstExceptions->GetItemCount(); pos++)
	{

		if (lstExceptions->GetText(pos, 0) == exDate &&
		        lstExceptions->GetText(pos, 1) == exTime)
		{
			wxMessageBox(_("The specified exception already exists!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
			return;
		}

		if (lstExceptions->GetText(pos, 0) == exDate &&
		        lstExceptions->GetText(pos, 1) == _("<any>"))
		{
			wxMessageBox(_("An exception already exists for any time on this date!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
			return;
		}

		if (lstExceptions->GetText(pos, 1) == exTime &&
		        lstExceptions->GetText(pos, 0) == _("<any>"))
		{
			wxMessageBox(_("An exception already exists for this time on any date!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
			return;
		}
	}

	lstExceptions->AppendItem(0, exDate, exTime);
	CheckChange();
}


void dlgSchedule::OnChangeException(wxCommandEvent &ev)
{
	if (!calException->GetValue().IsValid() && timException->GetValue().IsNull())
	{
		wxMessageBox(_("You must enter a valid date and/or time!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
		return;
	}

	wxString exDate, exTime;

	if (calException->GetValue().IsValid())
		exDate = calException->GetValue().FormatDate();
	else
		exDate = _("<any>");

	if (!timException->GetValue().IsNull())
		exTime = timException->GetValue().Format();
	else
		exTime = _("<any>");

	long item = lstExceptions->GetFocusedItem();

	for (int pos = 0; pos < lstExceptions->GetItemCount(); pos++)
	{
		if (item != pos)
		{
			if (lstExceptions->GetText(pos, 0) == exDate &&
			        lstExceptions->GetText(pos, 1) == exTime)
			{
				wxMessageBox(_("The specified exception already exists!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
				return;
			}

			if (lstExceptions->GetText(pos, 0) == exDate &&
			        lstExceptions->GetText(pos, 1) == _("<any>"))
			{
				wxMessageBox(_("An exception already exists for any time on this date!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
				return;
			}

			if (lstExceptions->GetText(pos, 1) == exTime &&
			        lstExceptions->GetText(pos, 0) == _("<any>"))
			{
				wxMessageBox(_("An exception already exists for this time on any date!"), _("Add exception"), wxICON_EXCLAMATION | wxOK, this);
				return;
			}
		}
	}

	lstExceptions->SetItem(item, 0, exDate);
	lstExceptions->SetItem(item, 1, exTime);
	lstExceptions->SetItem(item, 2, BoolToStr(true));
	CheckChange();
}


void dlgSchedule::OnRemoveException(wxCommandEvent &ev)
{
	if (lstExceptions->GetText(lstExceptions->GetFocusedItem(), 3) != wxEmptyString)
	{
		deleteExceptions.Add(lstExceptions->GetText(lstExceptions->GetFocusedItem(), 3));
	}
	lstExceptions->DeleteCurrentItem();

	btnChangeException->Disable();
	btnRemoveException->Disable();

	CheckChange();
}


wxString dlgSchedule::GetComment()
{
	return txtComment->GetValue();
}


wxString dlgSchedule::GetInsertSql()
{
	wxString sql;
	if (!schedule)
	{
		wxString name = GetName();
		wxString jscjobid, list = wxT("NULL");
		if (jobId)
			jscjobid = NumToStr(jobId);
		else
			jscjobid = wxT("<JobId>");

		// Build the various arrays of values
		sql = wxT("INSERT INTO pgagent.pga_schedule (jscid, jscjobid, jscname, jscdesc, jscminutes, jschours, jscweekdays, jscmonthdays, jscmonths, jscenabled, jscstart, jscend)\n")
		      wxT("VALUES(<SchId>, ") + jscjobid + wxT(", ") + qtDbString(name) + wxT(", ") + qtDbString(txtComment->GetValue()) + wxT(", ")
		      + wxT("'") + ChkListBox2PgArray(chkMinutes) + wxT("', ")
		      + wxT("'") + ChkListBox2PgArray(chkHours) + wxT("', ")
		      + wxT("'") + ChkListBox2PgArray(chkWeekdays) + wxT("', ")
		      + wxT("'") + ChkListBox2PgArray(chkMonthdays) + wxT("', ")
		      + wxT("'") + ChkListBox2PgArray(chkMonths) + wxT("', ")
		      + BoolToStr(chkEnabled->GetValue()) + wxT(", ")
		      + wxT("'") + DateToAnsiStr(calStart->GetValue() + timStart->GetValue()) + wxT("'");

		if (calEnd->GetValue().IsValid())
			sql += wxT(", '") + DateToAnsiStr(calEnd->GetValue() + timEnd->GetValue()) + wxT("'");
		else
			sql += wxT(", NULL");

		sql += wxT(");\n");
	}

	return sql;
}


wxString dlgSchedule::GetUpdateSql()
{
	wxString sql, name;
	name = GetName();

	if (schedule)
	{
		// edit mode
		wxString vars;

		if (name != schedule->GetName())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscname = ") + qtDbString(name));
		}
		if (txtComment->GetValue() != schedule->GetComment())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscdesc = ") + qtDbString(txtComment->GetValue()));
		}

		if ((!chkEnabled->IsChecked() && schedule->GetEnabled()) || (chkEnabled->IsChecked() && !schedule->GetEnabled()))
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscenabled = ") + BoolToStr(chkEnabled->IsChecked()));
		}

		if (calStart->GetValue() + timStart->GetValue() != schedule->GetStart())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscstart = '") + DateToAnsiStr(calStart->GetValue() + timStart->GetValue()) + wxT("'"));
		}

		if (calEnd->GetValue().IsValid())
		{
			if (schedule->GetEnd().IsValid())
			{
				if (calEnd->GetValue() + timEnd->GetValue() != schedule->GetEnd())
				{
					if (!vars.IsEmpty())
						vars.Append(wxT(", "));
					vars.Append(wxT("jscend = '") + DateToAnsiStr(calEnd->GetValue() + timEnd->GetValue()) + wxT("'"));
				}
			}
			else
			{
				if (!vars.IsEmpty())
					vars.Append(wxT(", "));
				vars.Append(wxT("jscend = '") + DateToAnsiStr(calEnd->GetValue() + wxTimeSpan()) + wxT("'"));
			}
		}
		else
		{
			if (schedule->GetEnd().IsValid())
			{
				if (!vars.IsEmpty())
					vars.Append(wxT(", "));
				vars.Append(wxT("jscend = NULL"));
			}
		}

		if (ChkListBox2StrArray(chkMinutes) != schedule->GetMinutes())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscminutes = '") + ChkListBox2PgArray(chkMinutes) + wxT("'"));
		}

		if (ChkListBox2StrArray(chkHours) != schedule->GetHours())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jschours = '") + ChkListBox2PgArray(chkHours) + wxT("'"));
		}

		if (ChkListBox2StrArray(chkWeekdays) != schedule->GetWeekdays())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscweekdays = '") + ChkListBox2PgArray(chkWeekdays) + wxT("'"));
		}

		if (ChkListBox2StrArray(chkMonthdays) != schedule->GetMonthdays())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscmonthdays = '") + ChkListBox2PgArray(chkMonthdays) + wxT("'"));
		}

		if (ChkListBox2StrArray(chkMonths) != schedule->GetMonths())
		{
			if (!vars.IsEmpty())
				vars.Append(wxT(", "));
			vars.Append(wxT("jscmonths = '") + ChkListBox2PgArray(chkMonths) + wxT("'"));
		}

		if (!vars.IsEmpty())
			sql = wxT("UPDATE pgagent.pga_schedule SET ") + vars + wxT("\n")
			      wxT(" WHERE jscid=") + NumToStr(recId) + wxT(";\n");
	}
	else
	{
		// create mode
		// Handled by GetInsertSQL
	}

	unsigned int x = 0;
	int y = 0;
	wxDateTime tmpDateTime;
	wxString newDate, newTime;

	// Remove old exceptions
	for (x = 0; x < deleteExceptions.Count(); x++)
	{
		sql += wxT("DELETE FROM pgagent.pga_exception\n  WHERE jexid = ") + deleteExceptions[x] + wxT(";\n");
	}

	// Update dirty exceptions
	for (y = 0; y < lstExceptions->GetItemCount(); y++)
	{
		if (lstExceptions->GetText(y, 2) == BoolToStr(true) &&
		        lstExceptions->GetText(y, 3) != wxEmptyString)
		{
			if (lstExceptions->GetText(y, 0) == _("<any>"))
				newDate = wxT("null");
			else
			{
				tmpDateTime.ParseFormat(lstExceptions->GetText(y, 0), wxT("%x"));
				newDate = wxT("'") + tmpDateTime.FormatISODate() + wxT("'");
			}

			if (lstExceptions->GetText(y, 1) == _("<any>"))
				newTime = wxT("null");
			else
			{
				tmpDateTime.ParseTime(lstExceptions->GetText(y, 1));
				newTime = wxT("'") + tmpDateTime.FormatISOTime() + wxT("'");
			}

			sql += wxT("UPDATE pgagent.pga_exception SET jexdate = ") + newDate +
			       wxT(", jextime = ") + newTime + wxT("\n  WHERE jexid = ") +
			       lstExceptions->GetText(y, 3) + wxT(";\n");
		}
	}

	// Insert new exceptions
	for (y = 0; y < lstExceptions->GetItemCount(); y++)
	{
		if (lstExceptions->GetText(y, 2) == wxEmptyString &&
		        lstExceptions->GetText(y, 3) == wxEmptyString)
		{
			if (lstExceptions->GetText(y, 0) == _("<any>"))
				newDate = wxT("null");
			else
			{
				tmpDateTime.ParseFormat(lstExceptions->GetText(y, 0), wxT("%x"));
				newDate = wxT("'") + tmpDateTime.FormatISODate() + wxT("'");
			}

			if (lstExceptions->GetText(y, 1) == _("<any>"))
				newTime = wxT("null");
			else
			{
				tmpDateTime.ParseTime(lstExceptions->GetText(y, 1));
				newTime = wxT("'") + tmpDateTime.FormatISOTime() + wxT("'");
			}

			sql += wxT("INSERT INTO pgagent.pga_exception (jexscid, jexdate, jextime)\n  VALUES (")
			       + NumToStr(recId) + wxT(", ") + newDate + wxT(", ") + newTime + wxT(");\n");

		}
	}



	return sql;
}


const wxString dlgSchedule::ChkListBox2PgArray(wxCheckListBox *lb)
{
	wxString res = wxT("{");

	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (lb->IsChecked(x))
			res += wxT("t,");
		else
			res += wxT("f,");
	}
	if (res.Length() > 1)
		res.RemoveLast();

	res += wxT("}");

	return res;
}


const wxString dlgSchedule::ChkListBox2StrArray(wxCheckListBox *lb)
{
	wxString res;

	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (lb->IsChecked(x))
			res += wxT("t");
		else
			res += wxT("f");
	}

	return res;
}


void dlgSchedule::OnSelectAll(wxCommandEvent &ev, int origin)
{
	bool check = false;
	wxBitmapButton *btn;
	wxCheckListBox *lb;
	wxString tooltip;

	switch (origin)
	{
		case 1:
			btn = ((wxBitmapButton *)btnWeekdays);
			lb = chkWeekdays;
			break;
		case 2:
			btn = ((wxBitmapButton *)btnMonthdays);
			lb = chkMonthdays;
			break;
		case 3:
			btn = ((wxBitmapButton *)btnMonths);
			lb = chkMonths;
			break;
		case 4:
			btn = ((wxBitmapButton *)btnHours);
			lb = chkHours;
			break;
		case 5:
			btn = ((wxBitmapButton *)btnMinutes);
			lb = chkMinutes;
			break;
		default:
			return;
			break;
	}

	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (!lb->IsChecked(x))
		{
			check = true;
			break;
		}
	}
	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		lb->Check(x, check);
	}

	CheckChange();
}


void dlgSchedule::InitSelectAll()
{
	bool check = false;
	wxBitmapButton *btn;
	wxCheckListBox *lb;
	wxString tooltip;

	btn = ((wxBitmapButton *)btnWeekdays);
	lb = chkWeekdays;
	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (!lb->IsChecked(x))
		{
			check = true;
			break;
		}
	}

	if (check)
	{
		btn->SetBitmapLabel(*check_png_bmp);
		tooltip = _("Select all week days");
	}
	else
	{
		btn->SetBitmapLabel(*uncheck_png_bmp);
		tooltip = _("Deselect all week days");
	}
	btn->SetToolTip(tooltip);

	check = false;
	btn = ((wxBitmapButton *)btnMonthdays);
	lb = chkMonthdays;
	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (!lb->IsChecked(x))
		{
			check = true;
			break;
		}
	}

	if (check)
	{
		btn->SetBitmapLabel(*check_png_bmp);
		tooltip = _("Select all month days");
	}
	else
	{
		btn->SetBitmapLabel(*uncheck_png_bmp);
		tooltip = _("Deselect all month days");
	}
	btn->SetToolTip(tooltip);

	check = false;
	btn = ((wxBitmapButton *)btnMonths);
	lb = chkMonths;
	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (!lb->IsChecked(x))
		{
			check = true;
			break;
		}
	}

	if (check)
	{
		btn->SetBitmapLabel(*check_png_bmp);
		tooltip = _("Select all months");
	}
	else
	{
		btn->SetBitmapLabel(*uncheck_png_bmp);
		tooltip = _("Deselect all months");
	}
	btn->SetToolTip(tooltip);

	check = false;
	btn = ((wxBitmapButton *)btnHours);
	lb = chkHours;
	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (!lb->IsChecked(x))
		{
			check = true;
			break;
		}
	}

	if (check)
	{
		btn->SetBitmapLabel(*check_png_bmp);
		tooltip = _("Select all hours");
	}
	else
	{
		btn->SetBitmapLabel(*uncheck_png_bmp);
		tooltip = _("Deselect all hours");
	}
	btn->SetToolTip(tooltip);


	check = false;
	btn = ((wxBitmapButton *)btnMinutes);
	lb = chkMinutes;
	for (unsigned int x = 0; x < lb->GetCount(); x++)
	{
		if (!lb->IsChecked(x))
		{
			check = true;
			break;
		}
	}

	if (check)
	{
		btn->SetBitmapLabel(*check_png_bmp);
		tooltip = _("Select all minutes");
	}
	else
	{
		btn->SetBitmapLabel(*uncheck_png_bmp);
		tooltip = _("Deselect all minutes");
	}
	btn->SetToolTip(tooltip);
}