private void Setup(string path = "default.cstp") { string pathDisp = path; // Get and customize Console arguments path = Application.StartupPath + "\\" + path; string[] args = Environment.GetCommandLineArgs(); if (!(args.Length <= 1 || args == null || String.IsNullOrWhiteSpace(args[1]) || args[1] == "")) { // Filter out just the filename (without path) string[] argArr = args[1].Split('\\'); argArr[argArr.Length - 1] = argArr[argArr.Length - 1].Replace(".cstp", ""); path = Application.StartupPath + "\\" + argArr[argArr.Length - 1] + ".cstp"; pathDisp = argArr[argArr.Length - 1] + ".cstp"; } // Create the DataManager on the file representation in the Application Path dataManager = new DataManager(path); lblFile.Text = "Time File: " + pathDisp; TimeSpan timeCount = new TimeSpan(); int count = dataManager.GetJsonObject().timeItems.Count; for (int i = 0; i < count; i++) { // Read all TimeSplits in the Time file TimeItem tI = dataManager.GetJsonObject().timeItems[i]; TimeItem _tI = new TimeItem { Name = tI.Name, dateStart = tI.dateStart, dateStop = tI.dateStop, description = tI.description }; // Calculate time delta TimeSpan span = _tI.dateStop - _tI.dateStart; _tI.timeDifference = $"{span.Hours}:{span.Minutes}:{span.Seconds}"; tI.timeDifference = _tI.timeDifference; dataManager.Save(); timeCount += span; // Create the final Row Control object string startTime = $"{_tI.dateStart.Hour}:{_tI.dateStart.Minute}:{_tI.dateStart.Second} {_tI.dateStart.ToString("dd/MM")}"; string stopTime = $"{_tI.dateStop.Hour}:{_tI.dateStop.Minute}:{_tI.dateStop.Second} {_tI.dateStop.ToString("dd/MM")}"; TimeRowPanel rowPanel = CreateNewRow(i, _tI.Name, startTime, stopTime, _tI.timeDifference, _tI.description); panel_time.Controls.Add(rowPanel); rowPanel.Location = new Point(0, i * rowPanel.Height); } // Update the total Time totalTime = timeCount; dataManager.GetJsonObject().totalTime = timeCount; dataManager.Save(); lblTotalTime.Text = $"{totalTime.Days}d:{totalTime.Hours}h:{totalTime.Minutes}m:{totalTime.Seconds}s"; }
// Returns a new TimeRowPanel object private TimeRowPanel CreateNewRow(int index, string name, string startTime, string stopTime, string delta, string description) { TimeRowPanel rowPanel = new TimeRowPanel { Index = index, SplitName = name, StartTime = startTime, StopTime = stopTime, Delta = delta, SplitDescription = description, Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left), Width = panel_time.Width, OnActiveChanged = CalcActivatedTimes }; return(rowPanel); }
private void AddTime_click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(txtB_startTime.Text) || txtB_startTime.Text == "" || String.IsNullOrWhiteSpace(txtB_stopTime.Text) || txtB_stopTime.Text == "" || timerRunning) { MessageBox.Show("No Timer entry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Create new TimerRowPanel Control object TimeSpan span = stopTime - startTime; TimeRowPanel rowPanel = CreateNewRow(panel_time.Controls.Count, txtB_name.Text, txtB_startTime.Text, txtB_stopTime.Text, $"{span.Hours}:{span.Minutes}:{span.Seconds}", txtB_description.Text); if (panel_time.Controls.Count > 0) { rowPanel.Location = new Point(0, panel_time.Controls[panel_time.Controls.Count - 1].Location.Y + rowPanel.Height); } else { rowPanel.Location = new Point(0, 0); } panel_time.Controls.Add(rowPanel); // Create an entry in the Time file TimeItem tI = new TimeItem { Name = txtB_name.Text, timeDifference = $"{span.Hours}:{span.Minutes}:{span.Seconds}", description = txtB_description.Text, dateStart = startTime, dateStop = stopTime }; dataManager.GetJsonObject().timeItems.Add(tI); // update total time totalTime += span; lblTotalTime.Text = $"{totalTime.Days}d:{totalTime.Hours}h:{totalTime.Minutes}m:{totalTime.Seconds}s"; dataManager.GetJsonObject().totalTime = totalTime; dataManager.Save(); // Reset timer text boxes txtB_description.Text = ""; txtB_name.Text = ""; txtB_startTime.Text = ""; txtB_stopTime.Text = ""; }