diff --git a/ClockApp.csproj b/ClockApp.csproj index 7b4d11c..816e397 100644 --- a/ClockApp.csproj +++ b/ClockApp.csproj @@ -53,8 +53,15 @@ Form1.cs + + + Form + + + TimerOverForm.cs + Form1.cs @@ -67,6 +74,9 @@ True Resources.resx + + TimerOverForm.cs + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/ClockTypes.cs b/ClockTypes.cs index 6297469..ab6005e 100644 --- a/ClockTypes.cs +++ b/ClockTypes.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace ClockApp { @@ -15,12 +16,57 @@ class Alarm public string Text; } - class Timer + public class Timer { + TimeSpan SaveTime; public TimeSpan InitialTime; public TimeSpan TimeLeft = new TimeSpan(); - public bool IsActive = false; + public bool IsActive = true; public string Text; + public GroupBox Box; + public Label LabelTimer; + public Button PauseBtn; + public Button ResetBtn; + + private TimeSpan GetNowTimeSpan() + { + DateTime dt = DateTime.Now; + TimeSpan result = new TimeSpan(dt.Hour, dt.Minute, dt.Second); + return result; + } + public Timer() + { + SaveTime = GetNowTimeSpan(); + } + + public void Pause() + { + IsActive = false; + + } + + public void Unpause() + { + IsActive=true; + SaveTime = GetNowTimeSpan(); + } + + public void TimeTick() + { + if(IsActive) + { + TimeSpan newTimeSpan = GetNowTimeSpan(); + TimeLeft -= newTimeSpan - SaveTime; + SaveTime = newTimeSpan; + } + } + public void Reset() + { + TimeLeft = InitialTime; + Unpause(); + LabelTimer.Text = TimeLeft.ToString(); + } + } class Stopwatch diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 5b93302..7f17188 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -29,12 +29,34 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPageClocks = new System.Windows.Forms.TabPage(); + this.flowLayoutPanelTimezones = new System.Windows.Forms.FlowLayoutPanel(); + this.groupBoxAddTimezone = new System.Windows.Forms.GroupBox(); + this.buttonAddTimezone = new System.Windows.Forms.Button(); + this.comboBoxAddTimezone = new System.Windows.Forms.ComboBox(); this.tabPageAlarms = new System.Windows.Forms.TabPage(); - this.tabPageCountdowns = new System.Windows.Forms.TabPage(); + this.timerTabPageCountdowns = new System.Windows.Forms.TabPage(); + this.timerMesssengLabel = new System.Windows.Forms.Label(); + this.timerMessageTextBox = new System.Windows.Forms.TextBox(); + this.timerFlowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.timerAddButton = new System.Windows.Forms.Button(); + this.timerSecondLabel = new System.Windows.Forms.Label(); + this.timerMinuteLabel = new System.Windows.Forms.Label(); + this.timerHourLabel = new System.Windows.Forms.Label(); + this.secondNumeric = new System.Windows.Forms.NumericUpDown(); + this.minuteNumeric = new System.Windows.Forms.NumericUpDown(); + this.hourNumeric = new System.Windows.Forms.NumericUpDown(); this.tabPageStopwatches = new System.Windows.Forms.TabPage(); + this.timer1 = new System.Windows.Forms.Timer(this.components); this.tabControl1.SuspendLayout(); + this.tabPageClocks.SuspendLayout(); + this.groupBoxAddTimezone.SuspendLayout(); + this.timerTabPageCountdowns.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.secondNumeric)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.minuteNumeric)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.hourNumeric)).BeginInit(); this.SuspendLayout(); // // tabControl1 @@ -44,62 +66,242 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Right))); this.tabControl1.Controls.Add(this.tabPageClocks); this.tabControl1.Controls.Add(this.tabPageAlarms); - this.tabControl1.Controls.Add(this.tabPageCountdowns); + this.tabControl1.Controls.Add(this.timerTabPageCountdowns); this.tabControl1.Controls.Add(this.tabPageStopwatches); this.tabControl1.Location = new System.Drawing.Point(0, 0); this.tabControl1.Margin = new System.Windows.Forms.Padding(0); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(802, 452); + this.tabControl1.Size = new System.Drawing.Size(1203, 695); this.tabControl1.TabIndex = 0; // // tabPageClocks // - this.tabPageClocks.Location = new System.Drawing.Point(4, 22); + this.tabPageClocks.Controls.Add(this.flowLayoutPanelTimezones); + this.tabPageClocks.Controls.Add(this.groupBoxAddTimezone); + this.tabPageClocks.Location = new System.Drawing.Point(4, 29); + this.tabPageClocks.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.tabPageClocks.Name = "tabPageClocks"; - this.tabPageClocks.Padding = new System.Windows.Forms.Padding(3); - this.tabPageClocks.Size = new System.Drawing.Size(794, 426); + this.tabPageClocks.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.tabPageClocks.Size = new System.Drawing.Size(1195, 662); this.tabPageClocks.TabIndex = 0; this.tabPageClocks.Text = "Мировое время"; this.tabPageClocks.UseVisualStyleBackColor = true; // + // flowLayoutPanelTimezones + // + this.flowLayoutPanelTimezones.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.flowLayoutPanelTimezones.Location = new System.Drawing.Point(14, 86); + this.flowLayoutPanelTimezones.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.flowLayoutPanelTimezones.Name = "flowLayoutPanelTimezones"; + this.flowLayoutPanelTimezones.Size = new System.Drawing.Size(1162, 554); + this.flowLayoutPanelTimezones.TabIndex = 1; + // + // groupBoxAddTimezone + // + this.groupBoxAddTimezone.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBoxAddTimezone.Controls.Add(this.buttonAddTimezone); + this.groupBoxAddTimezone.Controls.Add(this.comboBoxAddTimezone); + this.groupBoxAddTimezone.Location = new System.Drawing.Point(4, 9); + this.groupBoxAddTimezone.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxAddTimezone.Name = "groupBoxAddTimezone"; + this.groupBoxAddTimezone.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBoxAddTimezone.Size = new System.Drawing.Size(1172, 68); + this.groupBoxAddTimezone.TabIndex = 0; + this.groupBoxAddTimezone.TabStop = false; + this.groupBoxAddTimezone.Text = "Добавление новой временной зоны"; + // + // buttonAddTimezone + // + this.buttonAddTimezone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAddTimezone.Location = new System.Drawing.Point(1036, 25); + this.buttonAddTimezone.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.buttonAddTimezone.Name = "buttonAddTimezone"; + this.buttonAddTimezone.Size = new System.Drawing.Size(112, 35); + this.buttonAddTimezone.TabIndex = 1; + this.buttonAddTimezone.Text = "Добавить"; + this.buttonAddTimezone.UseVisualStyleBackColor = true; + this.buttonAddTimezone.Click += new System.EventHandler(this.buttonAddTimezone_Click); + // + // comboBoxAddTimezone + // + this.comboBoxAddTimezone.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxAddTimezone.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxAddTimezone.FormattingEnabled = true; + this.comboBoxAddTimezone.Location = new System.Drawing.Point(9, 26); + this.comboBoxAddTimezone.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.comboBoxAddTimezone.Name = "comboBoxAddTimezone"; + this.comboBoxAddTimezone.Size = new System.Drawing.Size(1016, 28); + this.comboBoxAddTimezone.TabIndex = 0; + // // tabPageAlarms // - this.tabPageAlarms.Location = new System.Drawing.Point(4, 22); + this.tabPageAlarms.Location = new System.Drawing.Point(4, 29); + this.tabPageAlarms.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.tabPageAlarms.Name = "tabPageAlarms"; - this.tabPageAlarms.Padding = new System.Windows.Forms.Padding(3); - this.tabPageAlarms.Size = new System.Drawing.Size(767, 399); + this.tabPageAlarms.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.tabPageAlarms.Size = new System.Drawing.Size(1195, 662); this.tabPageAlarms.TabIndex = 1; this.tabPageAlarms.Text = "Будильники"; this.tabPageAlarms.UseVisualStyleBackColor = true; // - // tabPageCountdowns + // timerTabPageCountdowns + // + this.timerTabPageCountdowns.Controls.Add(this.timerMesssengLabel); + this.timerTabPageCountdowns.Controls.Add(this.timerMessageTextBox); + this.timerTabPageCountdowns.Controls.Add(this.timerFlowLayoutPanel); + this.timerTabPageCountdowns.Controls.Add(this.timerAddButton); + this.timerTabPageCountdowns.Controls.Add(this.timerSecondLabel); + this.timerTabPageCountdowns.Controls.Add(this.timerMinuteLabel); + this.timerTabPageCountdowns.Controls.Add(this.timerHourLabel); + this.timerTabPageCountdowns.Controls.Add(this.secondNumeric); + this.timerTabPageCountdowns.Controls.Add(this.minuteNumeric); + this.timerTabPageCountdowns.Controls.Add(this.hourNumeric); + this.timerTabPageCountdowns.Location = new System.Drawing.Point(4, 29); + this.timerTabPageCountdowns.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.timerTabPageCountdowns.Name = "timerTabPageCountdowns"; + this.timerTabPageCountdowns.Size = new System.Drawing.Size(1195, 662); + this.timerTabPageCountdowns.TabIndex = 2; + this.timerTabPageCountdowns.Text = "Таймеры"; + this.timerTabPageCountdowns.UseVisualStyleBackColor = true; + // + // timerMesssengLabel + // + this.timerMesssengLabel.AutoSize = true; + this.timerMesssengLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.timerMesssengLabel.Location = new System.Drawing.Point(349, 76); + this.timerMesssengLabel.Name = "timerMesssengLabel"; + this.timerMesssengLabel.Size = new System.Drawing.Size(195, 37); + this.timerMesssengLabel.TabIndex = 9; + this.timerMesssengLabel.Text = "Сообщение:"; + // + // timerMessageTextBox + // + this.timerMessageTextBox.Location = new System.Drawing.Point(114, 116); + this.timerMessageTextBox.Multiline = true; + this.timerMessageTextBox.Name = "timerMessageTextBox"; + this.timerMessageTextBox.Size = new System.Drawing.Size(653, 67); + this.timerMessageTextBox.TabIndex = 8; // - this.tabPageCountdowns.Location = new System.Drawing.Point(4, 22); - this.tabPageCountdowns.Name = "tabPageCountdowns"; - this.tabPageCountdowns.Size = new System.Drawing.Size(767, 399); - this.tabPageCountdowns.TabIndex = 2; - this.tabPageCountdowns.Text = "Таймеры"; - this.tabPageCountdowns.UseVisualStyleBackColor = true; + // timerFlowLayoutPanel + // + this.timerFlowLayoutPanel.Location = new System.Drawing.Point(0, 197); + this.timerFlowLayoutPanel.Name = "timerFlowLayoutPanel"; + this.timerFlowLayoutPanel.Size = new System.Drawing.Size(1195, 465); + this.timerFlowLayoutPanel.TabIndex = 7; + // + // timerAddButton + // + this.timerAddButton.Location = new System.Drawing.Point(955, 110); + this.timerAddButton.Name = "timerAddButton"; + this.timerAddButton.Size = new System.Drawing.Size(85, 39); + this.timerAddButton.TabIndex = 6; + this.timerAddButton.Text = "Запуск"; + this.timerAddButton.UseVisualStyleBackColor = true; + this.timerAddButton.Click += new System.EventHandler(this.timerAddButton_Click); + // + // timerSecondLabel + // + this.timerSecondLabel.AutoSize = true; + this.timerSecondLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.timerSecondLabel.Location = new System.Drawing.Point(807, 29); + this.timerSecondLabel.Name = "timerSecondLabel"; + this.timerSecondLabel.Size = new System.Drawing.Size(155, 37); + this.timerSecondLabel.TabIndex = 5; + this.timerSecondLabel.Text = "Секунда:"; + // + // timerMinuteLabel + // + this.timerMinuteLabel.AutoSize = true; + this.timerMinuteLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.timerMinuteLabel.Location = new System.Drawing.Point(471, 29); + this.timerMinuteLabel.Name = "timerMinuteLabel"; + this.timerMinuteLabel.Size = new System.Drawing.Size(137, 37); + this.timerMinuteLabel.TabIndex = 4; + this.timerMinuteLabel.Text = "Минута:"; + // + // timerHourLabel + // + this.timerHourLabel.AutoSize = true; + this.timerHourLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.timerHourLabel.Location = new System.Drawing.Point(119, 29); + this.timerHourLabel.Name = "timerHourLabel"; + this.timerHourLabel.Size = new System.Drawing.Size(84, 37); + this.timerHourLabel.TabIndex = 3; + this.timerHourLabel.Text = "Час:"; + // + // secondNumeric + // + this.secondNumeric.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.secondNumeric.Location = new System.Drawing.Point(996, 27); + this.secondNumeric.Maximum = new decimal(new int[] { + 59, + 0, + 0, + 0}); + this.secondNumeric.Name = "secondNumeric"; + this.secondNumeric.Size = new System.Drawing.Size(81, 44); + this.secondNumeric.TabIndex = 2; + // + // minuteNumeric + // + this.minuteNumeric.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.minuteNumeric.Location = new System.Drawing.Point(641, 27); + this.minuteNumeric.Maximum = new decimal(new int[] { + 59, + 0, + 0, + 0}); + this.minuteNumeric.Name = "minuteNumeric"; + this.minuteNumeric.Size = new System.Drawing.Size(81, 44); + this.minuteNumeric.TabIndex = 1; + // + // hourNumeric + // + this.hourNumeric.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.hourNumeric.Location = new System.Drawing.Point(236, 27); + this.hourNumeric.Name = "hourNumeric"; + this.hourNumeric.Size = new System.Drawing.Size(81, 44); + this.hourNumeric.TabIndex = 0; // // tabPageStopwatches // - this.tabPageStopwatches.Location = new System.Drawing.Point(4, 22); + this.tabPageStopwatches.Location = new System.Drawing.Point(4, 29); + this.tabPageStopwatches.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.tabPageStopwatches.Name = "tabPageStopwatches"; - this.tabPageStopwatches.Size = new System.Drawing.Size(767, 399); + this.tabPageStopwatches.Size = new System.Drawing.Size(1195, 662); this.tabPageStopwatches.TabIndex = 3; this.tabPageStopwatches.Text = "Секундомеры"; this.tabPageStopwatches.UseVisualStyleBackColor = true; // + // timer1 + // + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(1200, 692); this.Controls.Add(this.tabControl1); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.Name = "Form1"; this.Text = "ClockApp"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + this.Load += new System.EventHandler(this.Form1_Load); this.tabControl1.ResumeLayout(false); + this.tabPageClocks.ResumeLayout(false); + this.groupBoxAddTimezone.ResumeLayout(false); + this.timerTabPageCountdowns.ResumeLayout(false); + this.timerTabPageCountdowns.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.secondNumeric)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.minuteNumeric)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.hourNumeric)).EndInit(); this.ResumeLayout(false); } @@ -109,8 +311,23 @@ private void InitializeComponent() private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPageClocks; private System.Windows.Forms.TabPage tabPageAlarms; - private System.Windows.Forms.TabPage tabPageCountdowns; + private System.Windows.Forms.TabPage timerTabPageCountdowns; private System.Windows.Forms.TabPage tabPageStopwatches; + private System.Windows.Forms.GroupBox groupBoxAddTimezone; + private System.Windows.Forms.Button buttonAddTimezone; + private System.Windows.Forms.ComboBox comboBoxAddTimezone; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanelTimezones; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.NumericUpDown hourNumeric; + private System.Windows.Forms.Label timerHourLabel; + private System.Windows.Forms.NumericUpDown secondNumeric; + private System.Windows.Forms.NumericUpDown minuteNumeric; + private System.Windows.Forms.FlowLayoutPanel timerFlowLayoutPanel; + private System.Windows.Forms.Button timerAddButton; + private System.Windows.Forms.Label timerSecondLabel; + private System.Windows.Forms.Label timerMinuteLabel; + private System.Windows.Forms.Label timerMesssengLabel; + private System.Windows.Forms.TextBox timerMessageTextBox; } } diff --git a/Form1.cs b/Form1.cs index 05ee509..e278b7b 100644 --- a/Form1.cs +++ b/Form1.cs @@ -1,5 +1,7 @@ -using System; +using ClockApp.models; +using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Drawing; @@ -7,14 +9,253 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using System.Xml.Linq; namespace ClockApp { public partial class Form1 : Form { + private ObservableCollection items; + private TimeSpan zeroTimeSpan = TimeSpan.Zero; public Form1() { InitializeComponent(); + items = new ObservableCollection(); + + } + + private void Form1_Load(object sender, EventArgs e) + { + var tz = TimeZoneInfo.GetSystemTimeZones(); + comboBoxAddTimezone.DataSource = tz; + comboBoxAddTimezone.DisplayMember = "DisplayName"; + comboBoxAddTimezone.ValueMember = "Id"; + items.CollectionChanged += Items_CollectionChanged; + timer1.Start(); + } + + private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) + { + switch (e.Action) + { + case System.Collections.Specialized.NotifyCollectionChangedAction.Add: + AddTime((WorldTimeItem)e.NewItems[0]); + break; + case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: + RemoveTime((WorldTimeItem)e.OldItems[0]); + break; + } + } + private void AddTime(WorldTimeItem item) + { + string tzName = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(i => i.Id == item.Id).DisplayName; + GroupBox gb = new GroupBox(); + gb.Height = 50; + gb.Width = 770; + gb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + Label name = new Label(); + name.Text = tzName; + name.Location = new Point(5, 10); + name.Width = 700; + name.Height = 20; + Label time = new Label(); + time.Text = ""; + time.Location = new Point(5, 30); + time.Width = 700; + time.Height = 20; + time.Tag = gb; + Button btn = new Button(); + btn.Text = "X"; + btn.Location = new Point(740, 10); + btn.Width = 20; + btn.Height = 20; + btn.Tag = gb; + btn.Click += BtnRemoveTZ_Click; + + gb.Controls.Add(name); + gb.Controls.Add(time); + gb.Controls.Add(btn); + gb.Tag = (string)comboBoxAddTimezone.SelectedValue; + flowLayoutPanelTimezones.Controls.Add(gb); + item.control = time; + } + private void RemoveTime(WorldTimeItem item) + { + var gb = (GroupBox)((Label)item.control).Tag; + gb.Dispose(); + } + + private void buttonAddTimezone_Click(object sender, EventArgs ev) + { + if (comboBoxAddTimezone.SelectedIndex != -1) + { + items.Add(new WorldTimeItem() { Id = (string)comboBoxAddTimezone.SelectedValue }); + } + } + + private void BtnRemoveTZ_Click(object sender, EventArgs e) + { + var gb = (GroupBox)((Button)sender).Tag; + string id = (string)gb.Tag; + var item = items.FirstOrDefault(i => i.Id == id); + items.Remove(item); + } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + timer1.Stop(); + } + //Серьгей савельев Иллюзия моделирования мозга + private void timer1_Tick(object sender, EventArgs e) + { + foreach (var item in items) + { + var tz = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(i => i.Id == item.Id); + item.control.Text = (DateTime.UtcNow + tz.BaseUtcOffset).ToString(); + } + foreach(var timer in Program.Timers) + { + if (timer.IsActive) + { + timer.TimeTick(); + timer.LabelTimer.Text = timer.TimeLeft.ToString(); + if (timer.TimeLeft <= zeroTimeSpan) + { + timer.Pause(); + //MessageBox.Show(timer.Text); + TimerOverForm timerOverForm = new TimerOverForm(timer); + } + } + } + } + + private void addTimer(int hour, int minute, int seconds, string text) + { + GroupBox gb = new GroupBox(); + Button pauseBtn = new Button(); + Button resetBtn = new Button(); + + Timer timer = new Timer() + { + Text = text, + InitialTime = new TimeSpan(hour, minute, seconds), + TimeLeft = new TimeSpan(hour, minute, seconds), + Box= gb, + IsActive = true, + PauseBtn = pauseBtn, + ResetBtn = resetBtn + }; + Program.Timers.Add(timer); + + gb.Height = 60; + gb.Width = 770; + gb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + + Label name = new Label(); + name.Text = timer.TimeLeft.ToString(); + name.Location = new Point(5, 10); + name.Width = 300; + name.Height = 20; + Label time = new Label(); + time.Text = text; + time.Location = new Point(5, 40); + time.Width = 700; + time.Height = 20; + time.Tag = gb; + + Button btn = new Button(); + btn.Text = "X"; + btn.Location = new Point(740, 10); + btn.Width = 20; + btn.Height = 20; + btn.Tag = gb; + btn.Click += deleteTimer; + + + pauseBtn.Text = "| |"; + pauseBtn.Location = new Point (700, 15); + pauseBtn.Width = 25; + pauseBtn.Height = 25; + pauseBtn.Tag = timer; + pauseBtn.Click += pauseTimerBtn_Click; + + resetBtn.Text = "R"; + resetBtn.Location = new Point(665, 15); + resetBtn.Width = 25; + resetBtn.Height = 25; + resetBtn.Tag = timer; + resetBtn.Click += resetTimerBtn_Click; + + gb.Controls.Add(name); + gb.Controls.Add(time); + gb.Controls.Add(btn); + gb.Controls.Add(pauseBtn); + gb.Controls.Add(resetBtn); + gb.Tag = (string)comboBoxAddTimezone.SelectedValue; + timerFlowLayoutPanel.Controls.Add(gb); + + timer.LabelTimer = name; + //timerFlowLayoutPanel.Controls.Remove(gb); + } + + private void resetTimerBtn_Click(object sender, EventArgs e) + { + Timer timer = (Timer)((Button)sender).Tag; + timer.Reset(); + if (!timer.PauseBtn.Enabled) + { + timer.PauseBtn.Show(); + timer.PauseBtn.Enabled = true; + } + } + + private void pauseTimerBtn_Click(object sender, EventArgs e) + { + Button btn = ((Button)sender); + ((Timer)btn.Tag).Pause(); + btn.Text = "|>"; + btn.Click -= pauseTimerBtn_Click; + btn.Click += unpauseTimerBtn_Click; + } + private void unpauseTimerBtn_Click(object sender, EventArgs e) + { + Button btn = ((Button)sender); + ((Timer)btn.Tag).Unpause(); + btn.Text = "||"; + btn.Click -= unpauseTimerBtn_Click; + btn.Click += pauseTimerBtn_Click; + } + private void deleteTimer(object sender, EventArgs e) + { + var gb = (GroupBox)((Button)sender).Tag; + foreach (var i in Program.Timers) + { + if (i.Box == gb) + { + Program.Timers.Remove(i); + break; + } + + } + timerFlowLayoutPanel.Controls.Remove(gb); + } + private void deleteTimer(GroupBox sender) + { + var gb = sender; + foreach (var i in Program.Timers) + { + if (i.Box == gb) + { + Program.Timers.Remove(i); + break; + } + + } + timerFlowLayoutPanel.Controls.Remove(gb); + } + private void timerAddButton_Click(object sender, EventArgs e) + { + addTimer((int)hourNumeric.Value, (int)minuteNumeric.Value, (int)secondNumeric.Value, timerMessageTextBox.Text); } } } diff --git a/Form1.resx b/Form1.resx index 1af7de1..1f666f2 100644 --- a/Form1.resx +++ b/Form1.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/TimerOverForm.Designer.cs b/TimerOverForm.Designer.cs new file mode 100644 index 0000000..bf01531 --- /dev/null +++ b/TimerOverForm.Designer.cs @@ -0,0 +1,86 @@ +namespace ClockApp +{ + partial class TimerOverForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.TimerTextLabel = new System.Windows.Forms.Label(); + this.TimerOverResetBtn = new System.Windows.Forms.Button(); + this.TimerOverCloseBtn = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // TimerTextLabel + // + this.TimerTextLabel.Dock = System.Windows.Forms.DockStyle.Top; + this.TimerTextLabel.Location = new System.Drawing.Point(0, 0); + this.TimerTextLabel.Name = "TimerTextLabel"; + this.TimerTextLabel.Size = new System.Drawing.Size(410, 71); + this.TimerTextLabel.TabIndex = 0; + this.TimerTextLabel.Text = "text"; + // + // TimerOverResetBtn + // + this.TimerOverResetBtn.Location = new System.Drawing.Point(36, 90); + this.TimerOverResetBtn.Name = "TimerOverResetBtn"; + this.TimerOverResetBtn.Size = new System.Drawing.Size(95, 31); + this.TimerOverResetBtn.TabIndex = 1; + this.TimerOverResetBtn.Text = "Заново"; + this.TimerOverResetBtn.UseVisualStyleBackColor = true; + this.TimerOverResetBtn.Click += new System.EventHandler(this.TimerOverResetBtn_Click); + // + // TimerOverCloseBtn + // + this.TimerOverCloseBtn.Location = new System.Drawing.Point(242, 90); + this.TimerOverCloseBtn.Name = "TimerOverCloseBtn"; + this.TimerOverCloseBtn.Size = new System.Drawing.Size(95, 31); + this.TimerOverCloseBtn.TabIndex = 2; + this.TimerOverCloseBtn.Text = "Закрыть"; + this.TimerOverCloseBtn.UseVisualStyleBackColor = true; + this.TimerOverCloseBtn.Click += new System.EventHandler(this.TimerOverCloseBtn_Click); + // + // TimerOverForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(410, 133); + this.Controls.Add(this.TimerOverCloseBtn); + this.Controls.Add(this.TimerOverResetBtn); + this.Controls.Add(this.TimerTextLabel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + this.Name = "TimerOverForm"; + this.Text = "TimerOver"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Label TimerTextLabel; + private System.Windows.Forms.Button TimerOverResetBtn; + private System.Windows.Forms.Button TimerOverCloseBtn; + } +} \ No newline at end of file diff --git a/TimerOverForm.cs b/TimerOverForm.cs new file mode 100644 index 0000000..0bcf82a --- /dev/null +++ b/TimerOverForm.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ClockApp +{ + public partial class TimerOverForm : Form + { + Timer timer; + public TimerOverForm(Timer timer) + { + InitializeComponent(); + this.FormClosing += TimerOverForm_FormClosing; + this.timer = timer; + TimerTextLabel.Text = timer.Text; + ResetBtnHide(); + PauseBtnHide(); + this.Show(); + } + + void ResetBtnShow() + { + timer.ResetBtn.Show(); + timer.ResetBtn.Enabled = true; + } + void ResetBtnHide() + { + timer.ResetBtn.Hide(); + timer.ResetBtn.Enabled = false; + } + void PauseBtnShow() + { + timer.PauseBtn.Show(); + timer.PauseBtn.Enabled = true; + } + void PauseBtnHide() + { + timer.PauseBtn.Hide(); + timer.PauseBtn.Enabled = false; + } + private void TimerOverForm_FormClosing(object sender, FormClosingEventArgs e) + { + ResetBtnShow(); + } + + private void TimerOverResetBtn_Click(object sender, EventArgs e) + { + timer.Reset(); + timer.IsActive = true; + ResetBtnShow(); + PauseBtnShow(); + this.Close(); + } + + private void TimerOverCloseBtn_Click(object sender, EventArgs e) + { + this.Close(); + ResetBtnShow(); + } + } +} diff --git a/TimerOverForm.resx b/TimerOverForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TimerOverForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/models/WorldTimeItem.cs b/models/WorldTimeItem.cs new file mode 100644 index 0000000..fd31e69 --- /dev/null +++ b/models/WorldTimeItem.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClockApp.models +{ + class WorldTimeItem + { + public string Id { set; get; } + public System.Windows.Forms.Control control { set; get; } + } +}