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;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Ajanda
{
public partial class Form1 : Form
{
public MySqlConnection baglanti = new MySqlConnection( "Server=localhost;Database=ajanda; Uid=root;Pwd=''; AllowUserVariables=True; UseCompression=True" );
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ListeYukle();
timer1.Start();
}
private void button1_Click(object sender, EventArgs e)
{
Not_Ekle frm = new Not_Ekle();
frm.Tarih = dateTimePicker1.Text;
frm.Guncelle = false;
frm.Gun = dateTimePicker1.Value.Day.ToString();
frm.Ay = dateTimePicker1.Value.Month.ToString();
frm.Yil = dateTimePicker1.Value.Year.ToString();
frm.Saat = dateTimePicker1.Value.ToShortTimeString();
frm.ShowDialog();
ListeYukle();
}
private void button3_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0) return;
ListViewItem item = listView1.SelectedItems[0];
if (MessageBox.Show("Silmek İstediğinize Emin Misiniz?", "Soru", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
if (baglanti.State != ConnectionState.Open)
baglanti.Open();
MySqlCommand komut2 = new MySqlCommand("Delete From ajanda Where id = " + Convert.ToUInt32(item.SubItems[0].Text) + "", baglanti);
komut2.ExecuteNonQuery();
MessageBox.Show("Not Kaydı Silindi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (baglanti.State != ConnectionState.Closed)
baglanti.Close();
}
ListeYukle();
}
}
private void button4_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0) return;
ListViewItem item = listView1.SelectedItems[0];
string drm;
if (item.SubItems[3].Text == "Evet") drm = "Hayir";
else drm = "Evet";
try
{
if (baglanti.State != ConnectionState.Open)
baglanti.Open();
MySqlCommand komut2 = new MySqlCommand("Update ajanda Set alarm='"+drm+"' Where id = " + Convert.ToUInt32(item.SubItems[0].Text) + "", baglanti);
komut2.ExecuteNonQuery();
MessageBox.Show("Not İçin Hatırlatıcı Durumu Değiştirildi.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (baglanti.State != ConnectionState.Closed)
baglanti.Close();
}
ListeYukle();
}
private void button2_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count == 0) return;
ListViewItem item = listView1.SelectedItems[0];
Not_Ekle frm = new Not_Ekle();
frm.Tarih = dateTimePicker1.Text;
frm.ID= item.SubItems[0].Text;
frm.Notlar= item.SubItems[1].Text;
frm.Alarm= item.SubItems[3].Text;
frm.Guncelle = true;
frm.Gun = dateTimePicker1.Value.Day.ToString();
frm.Ay = dateTimePicker1.Value.Month.ToString();
frm.Yil = dateTimePicker1.Value.Year.ToString();
frm.Saat = item.SubItems[2].Text;
frm.ShowDialog();
ListeYukle();
}
private void ListeYukle()
{
listView1.Items.Clear();
try
{
if (baglanti.State != ConnectionState.Open)
baglanti.Open();
string gun, ay, yil;
gun = dateTimePicker1.Value.Day.ToString();
ay = dateTimePicker1.Value.Month.ToString();
yil = dateTimePicker1.Value.Year.ToString();
MySqlCommand komut = new MySqlCommand("Select * From ajanda Where gun='"+gun+"' And ay='"+ay+"' And yil='"+yil+"'", baglanti);
MySqlDataReader oku = komut.ExecuteReader();
while (oku.Read())
{
ListViewItem satis = new ListViewItem(new string[]
{
oku["id"].ToString(),
oku["notlar"].ToString(),
oku["saat"].ToString(),
oku["alarm"].ToString()
}
);
listView1.Items.Add(satis);
}
oku.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (baglanti.State != ConnectionState.Closed )
baglanti.Close();
}
ListeYukle1();
}
private void ListeYukle1()
{
try
{
if (baglanti.State != ConnectionState.Open)
baglanti.Open();
string gun, ay, yil;
gun = dateTimePicker1.Value.Day.ToString();
ay = dateTimePicker1.Value.Month.ToString();
yil = dateTimePicker1.Value.Year.ToString();
MySqlCommand komut = new MySqlCommand("Select * From ajanda Where gun='" + gun + "' And ay='" + ay + "' And alarm='Evet'", baglanti);
MySqlDataReader oku = komut.ExecuteReader();
bool varmi=false;
while (oku.Read())
{
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].SubItems[0].Text == oku["id"].ToString())
{
varmi = true;
}
}
if(varmi==false)
{
ListViewItem satis = new ListViewItem(new string[]
{
oku["id"].ToString(),
oku["notlar"].ToString(),
oku["saat"].ToString(),
oku["alarm"].ToString()
}
);
listView1.Items.Add(satis);
}
}
oku.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (baglanti.State != ConnectionState.Closed)
baglanti.Close();
}
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
ListeYukle();
}
string saat;
int say = 0;
private void timer1_Tick(object sender, EventArgs e)
{
saat = DateTime.Now.ToShortTimeString();
say++;
if(say==30)
{
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].SubItems[3].Text == "Evet" && listView1.Items[i].SubItems[2].Text == saat && dateTimePicker1.Value.ToShortDateString() == DateTime.Now.ToShortDateString())
{
listView1.Items[i].Selected = true;
System.Media.SoundPlayer player = new System.Media.SoundPlayer();
player.SoundLocation = Application.StartupPath + "/alarm.wav";
player.Play();
MessageBox.Show(listView1.Items[i].SubItems[1].Text, "Hatırlatıcı");
}
}
say = 0;
}
}
}
}
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;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace Ajanda
{
public partial class Not_Ekle : Form
{
public Not_Ekle()
{
InitializeComponent();
}
public string Tarih
{
get { return label1.Text; }
set { label1.Text = value; }
}
public string Gun
{
get { return gun; }
set { gun = value; }
}
public string Ay
{
get { return ay; }
set { ay = value; }
}
public string Yil
{
get { return yil; }
set { yil = value; }
}
public string Saat
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
public string ID
{
get { return id; }
set { id = value; }
}
public string Notlar
{
get { return richTextBox1.Text; }
set { richTextBox1.Text = value; }
}
public string Alarm
{
get { return comboBox1.SelectedItem.ToString(); }
set { comboBox1.SelectedItem = value; }
}
public bool Guncelle
{
get { return guncelle; }
set { guncelle = value; }
}
bool guncelle;
string gun, ay, yil,id;
public MySqlConnection baglanti = new MySqlConnection( "Server=localhost;Database=ajanda; Uid=root;Pwd=''; AllowUserVariables=True;UseCompression=True" );
private void Not_Ekle_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (baglanti.State != ConnectionState.Open) baglanti.Open();
if (Guncelle == true)
{
MySqlCommand ekle = new MySqlCommand("update ajanda set notlar='"+Notlar+ "', gun='" + Gun + "', ay='" + Ay + "', yil='" + Yil + "', saat='" + Saat + "', alarm='" + Alarm + "' where id="+ID+"", baglanti);
object sonuc = null;
sonuc = ekle.ExecuteNonQuery();
if (sonuc != null)
{
MessageBox.Show("Veritabanında başarıyla güncellendi");
}
else
{
MessageBox.Show("Veritabanında güncellenemedi.");
baglanti.Close();
}
}
else
{
MySqlCommand ekle = new MySqlCommand("insert into ajanda (notlar,gun,ay,yil,saat,alarm) values ('" + Notlar + "','" + Gun + "','" + Ay + "','" + Yil + "','" + Saat + "','" + Alarm + "')", baglanti);
object sonuc = null;
sonuc = ekle.ExecuteNonQuery();
if (sonuc != null)
{
MessageBox.Show("Veritabanına başarıyla eklendi");
}
else
{
MessageBox.Show("Veritabanına eklenemedi.");
baglanti.Close();
}
}
}
catch (Exception Hata)
{
MessageBox.Show("Hata: " + Hata.Message);
}
}
}
}