[717] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
[752] | 30 | using System.Diagnostics;
|
---|
| 31 | using System.Threading;
|
---|
[906] | 32 | using ZedGraph;
|
---|
[973] | 33 | using HeuristicLab.Hive.Client.Console.ClientService;
|
---|
[953] | 34 | using System.ServiceModel;
|
---|
[973] | 35 | using System.Net;
|
---|
[1138] | 36 | using Calendar;
|
---|
[1163] | 37 | using System.Globalization;
|
---|
[717] | 38 |
|
---|
| 39 | namespace HeuristicLab.Hive.Client.Console {
|
---|
[752] | 40 |
|
---|
[1027] | 41 | #region Delegates
|
---|
| 42 |
|
---|
[911] | 43 | delegate void UpdateTextDelegate(EventLogEntry ev);
|
---|
[752] | 44 |
|
---|
[1027] | 45 | #endregion
|
---|
| 46 |
|
---|
[717] | 47 | public partial class HiveClientConsole : Form {
|
---|
[752] | 48 |
|
---|
[1027] | 49 | #region Declarations
|
---|
| 50 |
|
---|
| 51 | private const string ENDPOINTADRESS = "net.tcp://127.0.0.1:8000/ClientConsole/ClientConsoleCommunicator";
|
---|
| 52 | private const string EVENTLOGNAME = "Hive Client";
|
---|
| 53 |
|
---|
[1002] | 54 | private EventLog HiveClientEventLog;
|
---|
| 55 | private ClientConsoleCommunicatorClient cccc;
|
---|
| 56 | private System.Windows.Forms.Timer refreshTimer;
|
---|
| 57 | private ListViewColumnSorterDate lvwColumnSorter;
|
---|
[752] | 58 |
|
---|
[1138] | 59 | private List<Appointment> onlineTimes = new List<Appointment>();
|
---|
| 60 |
|
---|
[1027] | 61 | #endregion
|
---|
[1002] | 62 |
|
---|
[1027] | 63 | #region Constructor
|
---|
| 64 |
|
---|
[717] | 65 | public HiveClientConsole() {
|
---|
| 66 | InitializeComponent();
|
---|
[1002] | 67 | lvwColumnSorter = new ListViewColumnSorterDate();
|
---|
| 68 | lvLog.ListViewItemSorter = lvwColumnSorter;
|
---|
| 69 | lvwColumnSorter.SortColumn = 3;
|
---|
| 70 | lvwColumnSorter.Order = SortOrder.Descending;
|
---|
[973] | 71 | InitTimer();
|
---|
| 72 | ConnectToClient();
|
---|
| 73 | RefreshGui();
|
---|
[906] | 74 | GetEventLog();
|
---|
[1138] | 75 | InitCalender();
|
---|
[973] | 76 | }
|
---|
[911] | 77 |
|
---|
[1027] | 78 | #endregion
|
---|
| 79 |
|
---|
| 80 | #region Methods
|
---|
| 81 |
|
---|
[973] | 82 | private void InitTimer() {
|
---|
| 83 | refreshTimer = new System.Windows.Forms.Timer();
|
---|
| 84 | refreshTimer.Interval = 1000;
|
---|
| 85 | refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
|
---|
| 86 | refreshTimer.Start();
|
---|
[906] | 87 | }
|
---|
| 88 |
|
---|
[973] | 89 | private void RefreshGui() {
|
---|
| 90 | try {
|
---|
[1002] | 91 | cccc.GetStatusInfosAsync();
|
---|
[973] | 92 | }
|
---|
| 93 | catch (Exception ex) {
|
---|
| 94 | refreshTimer.Stop();
|
---|
| 95 | DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 96 | if (res == DialogResult.OK)
|
---|
| 97 | this.Close();
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | private void ConnectToClient() {
|
---|
| 102 | try {
|
---|
[1027] | 103 | cccc = new ClientConsoleCommunicatorClient(new NetTcpBinding(), new EndpointAddress(ENDPOINTADRESS));
|
---|
[1002] | 104 | cccc.GetStatusInfosCompleted += new EventHandler<GetStatusInfosCompletedEventArgs>(cccc_GetStatusInfosCompleted);
|
---|
| 105 | cccc.GetCurrentConnectionCompleted += new EventHandler<GetCurrentConnectionCompletedEventArgs>(cccc_GetCurrentConnectionCompleted);
|
---|
[973] | 106 | }
|
---|
| 107 | catch (Exception) {
|
---|
| 108 | refreshTimer.Stop();
|
---|
| 109 | DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running!", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 110 | if (res == DialogResult.OK)
|
---|
| 111 | this.Close();
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[1027] | 115 | private void GetEventLog() {
|
---|
| 116 | HiveClientEventLog = new EventLog(EVENTLOGNAME);
|
---|
| 117 | HiveClientEventLog.Source = EVENTLOGNAME;
|
---|
| 118 | HiveClientEventLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
|
---|
| 119 | HiveClientEventLog.EnableRaisingEvents = true;
|
---|
| 120 |
|
---|
| 121 | ListViewItem curEventLogEntry;
|
---|
| 122 |
|
---|
[1080] | 123 | //databinding on listview?
|
---|
| 124 | if (HiveClientEventLog != null && HiveClientEventLog.Entries != null) {
|
---|
| 125 | foreach (EventLogEntry ele in HiveClientEventLog.Entries) {
|
---|
| 126 | curEventLogEntry = GenerateEventEntry(ele);
|
---|
| 127 | lvLog.Items.Add(curEventLogEntry);
|
---|
| 128 | }
|
---|
| 129 | lvJobDetail.Sort();
|
---|
[1027] | 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | private ListViewItem GenerateEventEntry(EventLogEntry ele) {
|
---|
| 134 | ListViewItem curEventLogEntry;
|
---|
| 135 | curEventLogEntry = new ListViewItem("", 0);
|
---|
| 136 | if (ele.EntryType == EventLogEntryType.Error)
|
---|
| 137 | curEventLogEntry = new ListViewItem("", 1);
|
---|
| 138 | curEventLogEntry.SubItems.Add(ele.InstanceId.ToString());
|
---|
| 139 | curEventLogEntry.SubItems.Add(ele.Message);
|
---|
| 140 | curEventLogEntry.SubItems.Add(ele.TimeGenerated.ToString());
|
---|
| 141 | return curEventLogEntry;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[1080] | 144 | private void UpdateGraph(JobStatus[] jobs) {
|
---|
[1027] | 145 | ZedGraphControl zgc = new ZedGraphControl();
|
---|
| 146 | GraphPane myPane = zgc.GraphPane;
|
---|
| 147 | myPane.GraphObjList.Clear();
|
---|
| 148 |
|
---|
| 149 | myPane.Title.IsVisible = false; // no title
|
---|
| 150 | myPane.Border.IsVisible = false; // no border
|
---|
| 151 | myPane.Chart.Border.IsVisible = false; // no border around the chart
|
---|
| 152 | myPane.XAxis.IsVisible = false; // no x-axis
|
---|
| 153 | myPane.YAxis.IsVisible = false; // no y-axis
|
---|
| 154 | myPane.Legend.IsVisible = false; // no legend
|
---|
| 155 |
|
---|
[1080] | 156 | myPane.Fill.Color = this.BackColor;
|
---|
[1027] | 157 |
|
---|
| 158 | myPane.Chart.Fill.Type = FillType.None;
|
---|
| 159 | myPane.Fill.Type = FillType.Solid;
|
---|
| 160 |
|
---|
[1080] | 161 | double allProgress = 0;
|
---|
| 162 | double done = 0;
|
---|
[1027] | 163 |
|
---|
[1080] | 164 | if (jobs.Length == 0) {
|
---|
| 165 | myPane.AddPieSlice(100, Color.Green, 0.1, "");
|
---|
| 166 | } else {
|
---|
| 167 | for (int i = 0; i < jobs.Length; i++) {
|
---|
[1138] | 168 | allProgress += jobs[i].Progress;
|
---|
[1080] | 169 | }
|
---|
[1027] | 170 |
|
---|
[1080] | 171 | done = allProgress / jobs.Length;
|
---|
| 172 |
|
---|
[1087] | 173 | myPane.AddPieSlice(done, Color.Green, 0, "");
|
---|
[1138] | 174 | myPane.AddPieSlice(1 - done, Color.Red, 0, "");
|
---|
[1080] | 175 | }
|
---|
[1027] | 176 | //Hides the slice labels
|
---|
| 177 | PieItem.Default.LabelType = PieLabelType.None;
|
---|
| 178 |
|
---|
| 179 | myPane.AxisChange();
|
---|
| 180 |
|
---|
| 181 | pbGraph.Image = zgc.GetImage();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
[1138] | 184 | private void InitCalender() {
|
---|
| 185 | dvOnline.StartDate = DateTime.Now;
|
---|
| 186 | dvOnline.OnNewAppointment += new EventHandler<NewAppointmentEventArgs>(DvOnline_OnNewAppointment);
|
---|
| 187 | dvOnline.OnResolveAppointments += new EventHandler<ResolveAppointmentsEventArgs>(DvOnline_OnResolveAppointments);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[1163] | 190 | private Appointment CreateAppointment(DateTime startDate, DateTime endDate, bool allDay) {
|
---|
| 191 | Appointment App = new Appointment();
|
---|
| 192 | App.StartDate = startDate;
|
---|
| 193 | App.EndDate = endDate;
|
---|
| 194 | App.AllDayEvent = allDay;
|
---|
| 195 | App.BorderColor = Color.Red;
|
---|
| 196 | App.Locked = true;
|
---|
| 197 | App.Subject = "Online";
|
---|
| 198 | return App;
|
---|
[1138] | 199 | }
|
---|
| 200 |
|
---|
[1333] | 201 | //private ConvertToAppointments(List<
|
---|
| 202 |
|
---|
[1027] | 203 | #endregion
|
---|
| 204 |
|
---|
| 205 | #region Events
|
---|
| 206 |
|
---|
| 207 | private void refreshTimer_Tick(object sender, EventArgs e) {
|
---|
| 208 | RefreshGui();
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | private void cccc_GetCurrentConnectionCompleted(object sender, GetCurrentConnectionCompletedEventArgs e) {
|
---|
[1002] | 212 | if (e.Error == null) {
|
---|
| 213 | ConnectionContainer curConnection = e.Result;
|
---|
| 214 | tbIPAdress.Text = curConnection.IPAdress;
|
---|
| 215 | tbPort.Text = curConnection.Port.ToString();
|
---|
[1028] | 216 | } else {
|
---|
[1138] | 217 | refreshTimer.Stop();
|
---|
[1028] | 218 | DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running! - " + e.Error.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 219 | if (res == DialogResult.OK)
|
---|
| 220 | this.Close();
|
---|
[1002] | 221 | }
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[1027] | 224 | private void cccc_GetStatusInfosCompleted(object sender, GetStatusInfosCompletedEventArgs e) {
|
---|
[1002] | 225 |
|
---|
| 226 | if (e.Error == null) {
|
---|
| 227 | StatusCommons sc = e.Result;
|
---|
| 228 |
|
---|
| 229 | lbGuid.Text = sc.ClientGuid.ToString();
|
---|
| 230 | lbConnectionStatus.Text = sc.Status.ToString();
|
---|
| 231 | lbJobdone.Text = sc.JobsDone.ToString();
|
---|
| 232 | lbJobsAborted.Text = sc.JobsAborted.ToString();
|
---|
| 233 | lbJobsFetched.Text = sc.JobsFetched.ToString();
|
---|
| 234 |
|
---|
| 235 | this.Text = "Client Console (" + sc.Status.ToString() + ")";
|
---|
| 236 |
|
---|
| 237 | ListViewItem curJobStatusItem;
|
---|
| 238 |
|
---|
| 239 | if (sc.Jobs != null) {
|
---|
| 240 | lvJobDetail.Items.Clear();
|
---|
| 241 | double progress;
|
---|
| 242 | foreach (JobStatus curJob in sc.Jobs) {
|
---|
| 243 | curJobStatusItem = new ListViewItem(curJob.JobId.ToString());
|
---|
| 244 | curJobStatusItem.SubItems.Add(curJob.Since.ToString());
|
---|
| 245 | progress = curJob.Progress * 100;
|
---|
| 246 | curJobStatusItem.SubItems.Add(progress.ToString());
|
---|
| 247 | lvJobDetail.Items.Add(curJobStatusItem);
|
---|
| 248 | }
|
---|
| 249 | lvJobDetail.Sort();
|
---|
| 250 | }
|
---|
| 251 |
|
---|
[1080] | 252 | UpdateGraph(sc.Jobs);
|
---|
[1002] | 253 |
|
---|
[1259] | 254 | if (sc.Status == NetworkEnumWcfConnState.Connected || sc.Status == NetworkEnumWcfConnState.Loggedin) {
|
---|
[1002] | 255 | btConnect.Enabled = false;
|
---|
| 256 | btnDisconnect.Enabled = true;
|
---|
[1016] | 257 | lbCs.Text = sc.ConnectedSince.ToString();
|
---|
[1002] | 258 | cccc.GetCurrentConnectionAsync();
|
---|
| 259 | } else if (sc.Status == NetworkEnumWcfConnState.Disconnected) {
|
---|
| 260 | btConnect.Enabled = true;
|
---|
| 261 | btnDisconnect.Enabled = false;
|
---|
[1016] | 262 | lbCs.Text = String.Empty;
|
---|
[1002] | 263 | } else if (sc.Status == NetworkEnumWcfConnState.Failed) {
|
---|
| 264 | btConnect.Enabled = true;
|
---|
| 265 | btnDisconnect.Enabled = false;
|
---|
[1016] | 266 | lbCs.Text = String.Empty;
|
---|
[1002] | 267 | }
|
---|
[1259] | 268 |
|
---|
| 269 | cccc.GetCurrentConnection();
|
---|
[1028] | 270 | } else {
|
---|
| 271 | refreshTimer.Stop();
|
---|
| 272 | DialogResult res = MessageBox.Show("Connection Error, check if Hive Client is running! - " + e.Error.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 273 | if (res == DialogResult.OK)
|
---|
| 274 | this.Close();
|
---|
[1002] | 275 | }
|
---|
| 276 | }
|
---|
| 277 |
|
---|
[906] | 278 | private void HiveClientConsole_Load(object sender, EventArgs e) {
|
---|
[1027] | 279 | //nothing to do
|
---|
[906] | 280 | }
|
---|
| 281 |
|
---|
[911] | 282 | private void UpdateText(EventLogEntry ev) {
|
---|
[906] | 283 | if (this.lvLog.InvokeRequired) {
|
---|
| 284 | this.lvLog.Invoke(new
|
---|
[752] | 285 | UpdateTextDelegate(UpdateText), new object[] { ev });
|
---|
| 286 | } else {
|
---|
[1027] | 287 | ListViewItem curEventLogEntry = GenerateEventEntry(ev);
|
---|
[973] | 288 | lvLog.Items.Add(curEventLogEntry);
|
---|
[1002] | 289 | lvJobDetail.Sort();
|
---|
[752] | 290 | }
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[906] | 293 | public void OnEntryWritten(object source, EntryWrittenEventArgs e) {
|
---|
[911] | 294 | UpdateText(e.Entry);
|
---|
[717] | 295 | }
|
---|
| 296 |
|
---|
[906] | 297 | private void lvLog_DoubleClick(object sender, EventArgs e) {
|
---|
| 298 | ListViewItem lvi = lvLog.SelectedItems[0];
|
---|
[1002] | 299 | HiveEventEntry hee = new HiveEventEntry(lvi.SubItems[2].Text, lvi.SubItems[3].Text, lvi.SubItems[1].Text);
|
---|
[1027] | 300 |
|
---|
[906] | 301 | Form EventlogDetails = new EventLogEntryForm(hee);
|
---|
| 302 | EventlogDetails.Show();
|
---|
| 303 | }
|
---|
[973] | 304 |
|
---|
| 305 | private void btConnect_Click(object sender, EventArgs e) {
|
---|
| 306 | IPAddress ipAdress;
|
---|
| 307 | int port;
|
---|
| 308 | ConnectionContainer cc = new ConnectionContainer();
|
---|
| 309 | if (IPAddress.TryParse(tbIPAdress.Text, out ipAdress) && int.TryParse(tbPort.Text, out port)) {
|
---|
| 310 | cc.IPAdress = tbIPAdress.Text;
|
---|
| 311 | cc.Port = port;
|
---|
[1010] | 312 | cccc.SetConnectionAsync(cc);
|
---|
[973] | 313 | } else {
|
---|
| 314 | MessageBox.Show("IP Adress and/or Port Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | private void btnDisconnect_Click(object sender, EventArgs e) {
|
---|
[1010] | 319 | cccc.DisconnectAsync();
|
---|
[973] | 320 | }
|
---|
[1002] | 321 |
|
---|
| 322 | private void lvLog_ColumnClick(object sender, ColumnClickEventArgs e) {
|
---|
| 323 | // Determine if clicked column is already the column that is being sorted.
|
---|
| 324 | if (e.Column == lvwColumnSorter.SortColumn) {
|
---|
| 325 | // Reverse the current sort direction for this column.
|
---|
| 326 | if (lvwColumnSorter.Order == SortOrder.Ascending) {
|
---|
| 327 | lvwColumnSorter.Order = SortOrder.Descending;
|
---|
| 328 | } else {
|
---|
| 329 | lvwColumnSorter.Order = SortOrder.Ascending;
|
---|
| 330 | }
|
---|
| 331 | } else {
|
---|
| 332 | // Set the column number that is to be sorted; default to ascending.
|
---|
| 333 | lvwColumnSorter.SortColumn = e.Column;
|
---|
| 334 | lvwColumnSorter.Order = SortOrder.Ascending;
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | // Perform the sort with these new sort options.
|
---|
| 338 | lvLog.Sort();
|
---|
| 339 | }
|
---|
[1027] | 340 |
|
---|
[1087] | 341 | private void btn_clientShutdown_Click(object sender, EventArgs e) {
|
---|
| 342 | DialogResult res = MessageBox.Show("Do you really want to shutdown the Hive Client?", "Hive Client Console", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
---|
| 343 | if (res == DialogResult.Yes) {
|
---|
| 344 | cccc.ShutdownClient();
|
---|
| 345 | this.Close();
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 |
|
---|
[1163] | 349 | private void btbDelete_Click(object sender, EventArgs e) {
|
---|
| 350 | if (dvOnline.SelectedAppointment != null)
|
---|
| 351 | onlineTimes.Remove(dvOnline.SelectedAppointment);
|
---|
| 352 | dvOnline.Invalidate();
|
---|
| 353 | }
|
---|
[1087] | 354 |
|
---|
[1163] | 355 | private void chbade_CheckedChanged(object sender, EventArgs e) {
|
---|
[1333] | 356 | //if (chbade.Checked) {
|
---|
| 357 | // txttimeFrom.Visible = false;
|
---|
| 358 | // txttimeTo.Visible = false;
|
---|
| 359 | //} else {
|
---|
| 360 | // txttimeFrom.Visible = true;
|
---|
| 361 | // txttimeTo.Visible = true;
|
---|
| 362 | //}
|
---|
| 363 | txttimeFrom.Visible = !chbade.Checked;
|
---|
| 364 | txttimeTo.Visible = !chbade.Checked;
|
---|
[1163] | 365 | }
|
---|
| 366 |
|
---|
| 367 | private void dvOnline_OnSelectionChanged(object sender, EventArgs e) {
|
---|
| 368 | if (dvOnline.Selection == SelectionType.DateRange) {
|
---|
[1258] | 369 | dtpFrom.Text = dvOnline.SelectionStart.ToShortDateString();
|
---|
| 370 | dtpTo.Text = dvOnline.SelectionEnd.Date.ToShortDateString();
|
---|
[1163] | 371 | txttimeFrom.Text = dvOnline.SelectionStart.ToShortTimeString();
|
---|
[1333] | 372 | txttimeTo.Text = dvOnline.SelectionEnd.ToShortTimeString();
|
---|
[1163] | 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | private void Connection_KeyPress(object sender, KeyPressEventArgs e) {
|
---|
| 377 | if (e.KeyChar == (char)Keys.Return)
|
---|
| 378 | btConnect_Click(null, null);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[1138] | 381 | private void mcOnline_DateChanged(object sender, DateRangeEventArgs e) {
|
---|
| 382 | dvOnline.StartDate = mcOnline.SelectionStart;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | private void btCreate_Click(object sender, EventArgs e) {
|
---|
[1163] | 386 | DateTime from, to;
|
---|
[1138] | 387 |
|
---|
[1258] | 388 | if (!string.IsNullOrEmpty(dtpFrom.Text) && !string.IsNullOrEmpty(dtpTo.Text)) {
|
---|
[1163] | 389 | if (chbade.Checked) {
|
---|
| 390 | //whole day appointment, only dates are visible
|
---|
[1333] | 391 | if (DateTime.TryParse(dtpFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(dtpTo.Text + " " + txttimeTo.Text, out to) && from < to)
|
---|
[1163] | 392 | onlineTimes.Add(CreateAppointment(from, to.AddDays(1), true));
|
---|
| 393 | else
|
---|
| 394 | MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
[1333] | 395 | } else if (!string.IsNullOrEmpty(txttimeFrom.Text) && !string.IsNullOrEmpty(txttimeTo.Text)) {
|
---|
[1163] | 396 | //Timeframe appointment
|
---|
[1333] | 397 | if (DateTime.TryParse(dtpFrom.Text + " " + txttimeFrom.Text, out from) && DateTime.TryParse(dtpTo.Text + " " + txttimeTo.Text, out to) && from < to) {
|
---|
[1163] | 398 | if (from.Date == to.Date)
|
---|
| 399 | onlineTimes.Add(CreateAppointment(from, to, false));
|
---|
| 400 | else {
|
---|
| 401 | //more than 1 day selected
|
---|
| 402 | while (from.Date != to.Date) {
|
---|
| 403 | onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
|
---|
| 404 | from = from.AddDays(1);
|
---|
| 405 | }
|
---|
| 406 | onlineTimes.Add(CreateAppointment(from, new DateTime(from.Year, from.Month, from.Day, to.Hour, to.Minute, 0, 0), false));
|
---|
| 407 | }
|
---|
| 408 | } else
|
---|
| 409 | MessageBox.Show("Incorrect date format", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 410 | }
|
---|
| 411 | dvOnline.Invalidate();
|
---|
[1138] | 412 | } else {
|
---|
[1163] | 413 | MessageBox.Show("Error in create appointment, please fill out all textboxes!", "Schedule Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
[1138] | 414 | }
|
---|
| 415 | }
|
---|
| 416 |
|
---|
[1163] | 417 | void DvOnline_OnResolveAppointments(object sender, ResolveAppointmentsEventArgs e) {
|
---|
| 418 | List<Appointment> Apps = new List<Appointment>();
|
---|
| 419 |
|
---|
| 420 | foreach (Appointment m_App in onlineTimes)
|
---|
| 421 | if ((m_App.StartDate >= e.StartDate) &&
|
---|
| 422 | (m_App.StartDate <= e.EndDate))
|
---|
| 423 | Apps.Add(m_App);
|
---|
| 424 | e.Appointments = Apps;
|
---|
[1138] | 425 | }
|
---|
| 426 |
|
---|
[1163] | 427 | void DvOnline_OnNewAppointment(object sender, NewAppointmentEventArgs e) {
|
---|
| 428 | Appointment Appointment = new Appointment();
|
---|
| 429 |
|
---|
| 430 | Appointment.StartDate = e.StartDate;
|
---|
| 431 | Appointment.EndDate = e.EndDate;
|
---|
| 432 |
|
---|
| 433 | onlineTimes.Add(Appointment);
|
---|
| 434 | }
|
---|
| 435 |
|
---|
[1256] | 436 | private void btnRecurrence_Click(object sender, EventArgs e) {
|
---|
| 437 | Form recurrence = new Recurrence();
|
---|
| 438 | recurrence.Show();
|
---|
| 439 | }
|
---|
[1333] | 440 |
|
---|
| 441 | #endregion
|
---|
| 442 |
|
---|
[717] | 443 | }
|
---|
[752] | 444 | } |
---|