3 Mart 2015 Salı

C# ta Alarm Yapma Kodları



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;



namespace Alarm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
         
        }
        int sayac=0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            int saat, dk;
            saat = System.DateTime.Now.Hour;
            dk = System.DateTime.Now.Minute;
            if (saat.ToString() == textBox1.Text && dk.ToString() == textBox2.Text)
            {
                timer3.Start();
                this.Show();
             
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            label3.Text = System.DateTime.Now.ToLongTimeString();
            int saatt = Convert.ToInt32(textBox1.Text);
            int dkk = Convert.ToInt32(textBox2.Text);
            if (saatt >= 24)
            {
                textBox1.Text = "0";
            }
            if (saatt < 0)
            {
                textBox1.Text = "23";
            }
            if (dkk > 59)
            {
                textBox2.Text = "0";
            }
            if (dkk < 0)
            {
                textBox2.Text = "59";
            }
        }
     
        private void label4_Click(object sender, EventArgs e)
        {
            try
            {
                int saatt = Convert.ToInt32(textBox1.Text);
                saatt++;
                textBox1.Text = saatt.ToString();
            }
            catch
            {
                textBox1.Text = "0";
                int saatt = Convert.ToInt32(textBox1.Text);
                saatt++;
                textBox1.Text = saatt.ToString();
            }
        }

        private void label6_Click(object sender, EventArgs e)
        {
            try
            {
                int saatt = Convert.ToInt32(textBox2.Text);
                saatt++;
                textBox2.Text = saatt.ToString();
            }
            catch
            {
                textBox2.Text = "0";
                int saatt = Convert.ToInt32(textBox2.Text);
                saatt++;
                textBox2.Text = saatt.ToString();
            }
        }

        private void label5_Click(object sender, EventArgs e)
        {
            try
            {
                int saatt = Convert.ToInt32(textBox1.Text);
                saatt--;
                textBox1.Text = saatt.ToString();
            }
            catch
            {
                textBox1.Text = "0";
                int saatt = Convert.ToInt32(textBox1.Text);
                saatt++;
                textBox1.Text = saatt.ToString();
            }
        }

        private void label7_Click(object sender, EventArgs e)
        {
            try
            {
                int saatt = Convert.ToInt32(textBox2.Text);
                saatt--;
                textBox2.Text = saatt.ToString();
            }
            catch
            {
                textBox2.Text = "0";
                int saatt = Convert.ToInt32(textBox2.Text);
                saatt++;
                textBox2.Text = saatt.ToString();
            }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            try
            {
                StreamReader oku = new StreamReader("C:\\alarm\\yol.txt", true);
                gelenyol = oku.ReadLine();
                oku.Close();
            }
            catch
            {
                StreamWriter SW;
                //dosyayı olustur
                SW = File.CreateText("C:\\alarm\\yol.txt");
                SW.Close();
            }

            if (gelenyol != null)
            {
                timer4.Start();
            }
            else
            {
                System.Media.SystemSounds.Asterisk.Play();
            }
            sayac++;
            if (sayac >= 60)
            {
                timer3.Stop();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
        string gelenyol;
        string dosyaadi;
        private void button3_Click(object sender, EventArgs e)
        {
            StreamWriter SW;
            //dosyayı olustur
            SW = File.CreateText("C:\\alarm\\yol.txt");
            SW.Close();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                 dosyaadi = openFileDialog1.FileName.ToString();
                string yol = Path.GetFullPath(dosyaadi);
            }
         
            try
            {
                StreamReader oku = new StreamReader("C:\\alarm\\yol.txt", true);
                gelenyol = oku.ReadLine();
                oku.Close();
                StreamWriter txtyaz = new StreamWriter("C:\\alarm\\yol.txt", true);
                txtyaz.WriteLine(dosyaadi);
                txtyaz.Close();
             
            }
            catch
            {

                string path = @"c:\alarm\"; // or whatever
                if (!Directory.Exists(path))
                {
                    DirectoryInfo di = Directory.CreateDirectory(path);
                    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                }
                StreamWriter SW1;
                //dosyayı olustur
                SW1 = File.CreateText("C:\\alarm\\yol.txt");
                SW1.Close();

                StreamWriter txtyaz = new StreamWriter("C:\\alarm\\yol.txt", true);
                txtyaz.WriteLine(dosyaadi);
                txtyaz.Close();
            }


        }

        int say = 0;
        private void timer4_Tick(object sender, EventArgs e)
        {

            if (say == 1)
            {
                timer4.Interval = 100000;
            }
            axWindowsMediaPlayer1.URL = gelenyol;
            if (say == 2)
            {
                timer4.Stop();
                axWindowsMediaPlayer1.Ctlcontrols.stop();
            }
                say++;
        }
    }
}



















Paylaş:

0 yorum:

Yorum Gönder

Popüler

Son

Kategoriler