Guest User

Untitled

a guest
Jun 19th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Threading;
  11.  
  12. namespace Alarm
  13. {
  14.     public partial class MainForm : Form
  15.     {
  16.         private Thread _clockThread;
  17.         private bool _clockWork;
  18.  
  19.         //private DateTime _time;
  20.         private Clock _cl;
  21.         private delegate void SetLabel(string str);
  22.         private delegate void ShowForm();
  23.  
  24.         public MainForm()
  25.         {
  26.             InitializeComponent();
  27.  
  28.             try
  29.             {
  30.                 //_time = DateTime.Now;
  31.                 _cl = new Clock();
  32.                 _clockWork = true;
  33.                 _clockThread = new Thread(ShowTime);
  34.                 _clockThread.Start();
  35.  
  36.                
  37.             }
  38.             catch (Exception ex)
  39.             {
  40.                 System.Windows.Forms.Application.Exit();
  41.             }
  42.         }
  43.        
  44.         AlarmForm af;
  45.  
  46.         private void SetLabelTime(string time)
  47.         {
  48.             labelTime.Text = time;
  49.  
  50.  
  51.             if(_cl.AlarmEnable)
  52.             {
  53.                 toolStripAlarmTime.Text = _cl.GetAlarmTime;
  54.                 toolStripAlarmStatus.Text = "Включен";
  55.             }
  56.             else
  57.             {
  58.                 toolStripAlarmTime.Text = "";
  59.                 toolStripAlarmStatus.Text = "Выключен";
  60.             }
  61.  
  62.             toolStripStatusLabel1.Text = "Текущее время " + _cl.GetTime;
  63.         }
  64.         private void ShowAlarmForm()
  65.         {
  66.             af = new AlarmForm();
  67.             af.Owner = this;
  68.             af.StartPosition = FormStartPosition.CenterParent;
  69.             af.ShowDialog(this);
  70.         }
  71.  
  72.         private void ShowTime()
  73.         {
  74.             string time;
  75.  
  76.             while (_clockWork)
  77.             {
  78.                 //_time.AddTicks(1);
  79.                 //DateTime.
  80.                 time = _cl.GetTime;
  81.  
  82.                 if (this.InvokeRequired)
  83.                 {
  84.                     this.Invoke(new SetLabel(SetLabelTime), time);
  85.                 }
  86.                 else
  87.                 {
  88.                     SetLabelTime(time);
  89.                 }
  90.                
  91.                 if(_cl.AlarmSignal)
  92.                 {
  93.                     _cl.AlarmOff();
  94.            
  95.                     this.BeginInvoke(new ShowForm(ShowAlarmForm), null);
  96.                 }
  97.  
  98.                 Thread.Sleep(500);
  99.             }
  100.         }
  101.  
  102.         private void MainForm_Load(object sender, EventArgs e)
  103.         {
  104.  
  105.         }
  106.  
  107.         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
  108.         {
  109.             _clockWork = false;
  110.             _clockThread.Abort();
  111.             _clockThread.Join(10000);
  112.         }
  113.  
  114.         private void toolStripMenuItem1_Click(object sender, EventArgs e)
  115.         {
  116.  
  117.         }
  118.  
  119.         private void toolStripMenuItem5_Click_1(object sender, EventArgs e)
  120.         {
  121.             this.Close();
  122.         }
  123.  
  124.         private void показатьToolStripMenuItem_Click(object sender, EventArgs e)
  125.         {
  126.             labelTime.Visible = true;
  127.             SetPosForm spf = new SetPosForm(this.Size.Width, this.Size.Height);
  128.            
  129.             spf.Owner = this;
  130.             spf.StartPosition = FormStartPosition.CenterParent;
  131.  
  132.             if(spf.ShowDialog(this) == DialogResult.OK)
  133.             {
  134.                 labelTime.Left = spf.PosX ;
  135.                 labelTime.Top = spf.PosY + 23;
  136.             }
  137.         }
  138.  
  139.         private void скрытьToolStripMenuItem_Click(object sender, EventArgs e)
  140.         {
  141.             labelTime.Visible = false;
  142.         }
  143.  
  144.         private void установитьВремяToolStripMenuItem_Click(object sender, EventArgs e)
  145.         {
  146.             try
  147.             {
  148.                 SetTimeForm tf = new SetTimeForm(_cl.Value);
  149.                 tf.Owner = this;
  150.                 tf.StartPosition = FormStartPosition.CenterParent;
  151.                 if (tf.ShowDialog(this) == DialogResult.OK)
  152.                 {
  153.                     _cl.Value = tf.NewDate;
  154.                 }
  155.             }
  156.             catch(Exception ex)
  157.             {
  158.  
  159.             }
  160.              
  161.         }
  162.  
  163.         private void установитьВремяToolStripMenuItem1_Click(object sender, EventArgs e)
  164.         {
  165.             try
  166.             {
  167.                 SetTimeForm tf = new SetTimeForm(_cl.Value);
  168.                 tf.Owner = this;
  169.                 tf.StartPosition = FormStartPosition.CenterParent;
  170.                 if (tf.ShowDialog(this) == DialogResult.OK)
  171.                 {
  172.  
  173.                     _cl.AlarmOn(tf.NewDate);
  174.                 }
  175.             }
  176.             catch (Exception ex)
  177.             {
  178.  
  179.             }
  180.              
  181.         }
  182.  
  183.         private void toolStripStatusLabel1_Click(object sender, EventArgs e)
  184.         {
  185.  
  186.         }
  187.  
  188.         private void выключитьToolStripMenuItem_Click(object sender, EventArgs e)
  189.         {
  190.             _cl.AlarmOff();
  191.         }
  192.  
  193.         private void включитьToolStripMenuItem_Click(object sender, EventArgs e)
  194.         {
  195.             if (!_cl.AlarmInstall)
  196.                 this.установитьВремяToolStripMenuItem1_Click(sender, e);
  197.             _cl.AlarmOn();
  198.         }
  199.  
  200.         private void инструкцияToolStripMenuItem_Click(object sender, EventArgs e)
  201.         {
  202.             TextForm tf = new TextForm("ИНСТРУКЦИЯ и прочие бла бла бла вставляются сюда текстом. В эту строку!");
  203.  
  204.             tf.Owner = this;
  205.             tf.StartPosition = FormStartPosition.CenterParent;
  206.  
  207.             tf.ShowDialog();
  208.         }
  209.  
  210.         private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)
  211.         {
  212.             TextForm tf = new TextForm("О программе и прочие бла бла бла вставляются сюда текстом. В эту строку!");
  213.  
  214.             tf.Owner = this;
  215.             tf.StartPosition = FormStartPosition.CenterParent;
  216.  
  217.             tf.ShowDialog();
  218.         }
  219.  
  220.         private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  221.         {
  222.  
  223.         }
  224.     }
  225.  
  226. }
Advertisement
Add Comment
Please, Sign In to add comment