- 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 Oracle.DataAccess.Client;
- using System.IO;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- String filtre = " ";
- bool key = true;
- List<int> sayilar = new List<int>();
- List<string> joblar = new List<string>();
- List<string> tarih = new List<string>();
- double baslangic, bitis;
- OracleConnection conn = new OracleConnection();
- OracleCommand cmd;
- OracleDataReader reader;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- dosyadanOku("C://jobTakip.txt");
- }
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- filtre = radioButton1.Text;
- }
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- filtre = radioButton2.Text;
- }
- public void button1_Click(object sender, EventArgs e)
- {//TARIHLER KARSILASTIRIP KISITLAMADAN GECERSE KEY DEGERI TRUE OLMAKTA VE BU ISLEME DEVAM EDILMEKTEDIR.
- //PROGRAMIN ILK KONTROLU BURADA YAPILMAKTADIR VE TARIH ARALIGINDA HATA VARSA ISLEM YAPILMAMAKTADIR.
- tarihKarsilastir();
- if (key)
- {
- sorgula();
- //SECILEN BILGILER DOGRULTUSUNDA OLUSTURULACAK GRAFIGIN OZELLIKLERI BUTONA AKTARILMAKTADIR.
- button1.Text = comboBox1.Text + "\n" + filtre + "\n" + dateTimePicker1.Text + "---" + dateTimePicker2.Text;
- }
- key = true;
- }
- public void dosyadanOku(string path)
- {
- //SISTEM JOBLARI VERITABANINDAN OKUNACAK VE COMBOBOX MENUSUNE AKTARILACAK.
- StreamReader reader = new StreamReader(path);
- string yazi;
- yazi = reader.ReadLine();
- while (yazi != null)
- {
- comboBox1.Items.Add(yazi);
- yazi = reader.ReadLine();
- }
- reader.Close();
- }
- public void guncelle()
- {
- conn.ConnectionString = "User ID=********; Password=**********; Data Source=********";
- conn.Open();
- //SISTEM JOBLARININ ISTENILDIGINDE VEYA HERHANGI BIR DEGISIKLIKTE
- //GUNCELLE BUTONUYLA ISLEME ALINMASI VE YENILENMESI AMACIYLA YAPILACAK OLAN BIR SORGUDUR.
- cmd = new OracleCommand("SELECT DISTINCT OBJE_ADI FROM ***** WHERE OBJE_ADI LIKE ************%'");
- cmd.Connection = conn;
- reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- joblar.Add(reader["OBJE_ADI"].ToString());
- }
- //GUNCELLEME SONUCUNDA DOSYAYA VERITABANINDAN CEKILEN BUTUN JOBLAR EKLENMEKTEDIR.
- dosyayaEkle("C://jobTakip.txt", joblar);
- conn.Close();
- }
- public void dosyayaEkle(string path, List<string> veri)
- {
- //VERILEN YOLDAKI DOSYAYA SINIRSIZ BOYUTLU OLARAK VERILEN DIZIDEKI BILGILER WRITELINE KOMUTU ILE ALTALTA YAZDIRILMAKTA.
- StreamWriter dosya = new StreamWriter(path);
- foreach (string satir in veri)
- {
- dosya.WriteLine(satir);
- }
- dosya.Close();
- dosyadanOku(path);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- System.IO.File.Delete("C://jobTakip.txt");
- guncelle();
- }
- public void sorgula()
- {
- conn.ConnectionString = "User ID=*********; Password=*****; Data Source=******";
- conn.Open();
- //AYLIK ORTALAMA
- if (filtre.Equals(radioButton1.Text))
- {//AY SECIMI YAPILIRSA BU IF BLOGUNA GIRILECEK VE AYLIK ORTALAMA ICIN ASAGIDAKI SORGU YAPILACAK.
- cmd = new OracleCommand(
- "SELECT TARIH,ORTALAMA FROM( SELECT TO_CHAR(BASLANGIC,'MM/YYYY') AS TARIH , ROUND(AVG(GECEN_SURE_DAKIKA+GECEN_SURE_SANIYE/60),0) AS ORTALAMA" +
- " FROM ********WHERE OBJE_ADI = '" + comboBox1.Text + "' AND BASLANGIC BETWEEN '" + dateTimePicker1.Value.ToShortDateString() +
- "' AND '" + dateTimePicker2.Value.ToShortDateString() + "' GROUP BY TO_CHAR(BASLANGIC,'MM/YYYY')) ORDER BY TARIH"
- );
- cmd.Connection = conn;
- reader = cmd.ExecuteReader();
- //GRAFIK ICIN GEREKLI ARRAYLAR DOLDURULMAKTA.
- while (reader.Read())
- {
- sayilar.Add(int.Parse(reader["ORTALAMA"] + ""));
- tarih.Add(reader["TARIH"].ToString());
- }
- int j = 0;
- //BU ARRAYLAR GRAFIGIN UZERINE AKTARILMAKTA.
- foreach (int i in sayilar)
- {
- chart1.Series["AYLIK ORTALAMA"].Points.AddXY(tarih[j],i);
- j++;
- }
- }
- //GUN GUN ISLEM SURESI
- else if (filtre.Equals(radioButton2.Text))
- {
- //GUN SECIMI YAPILIRSA BU ELSE BLOGUNA GIRIS YAPILACAK VE SORGUDAKI FARKLILIK ORTAYA BURADA CIKACAK.
- cmd = new OracleCommand
- (
- "SELECT TO_CHAR(BASLANGIC,'DD.MM.YYYY') AS TARIH,ROUND(GECEN_SURE_DAKIKA+GECEN_SURE_SANIYE/60,0) AS GUNLUK_DAKIKA"
- +" FROM ****** WHERE OBJE_ADI = '"+ comboBox1.Text + "' AND TO_DATE(BASLANGIC,'DD.MM.YYYY') BETWEEN '"
- + dateTimePicker1.Value.ToShortDateString() + "' AND '" + dateTimePicker2.Value.ToShortDateString() + "' ORDER BY BASLANGIC"
- );
- cmd.Connection = conn;
- reader = cmd.ExecuteReader();
- //GRAFIK ICIN X VE Y EKSENINI DOLUDRACAK OLAN BILGILER BURADA VERITABANINDAN OKUNMAKTA VE GEREKLI DIZILERE ATILMAKTADIR.
- while (reader.Read())
- {
- sayilar.Add(int.Parse(reader["GUNLUK_DAKIKA"] + ""));
- tarih.Add(reader["TARIH"].ToString());
- }
- int j = 0;
- //VERITABANINDAN CEKILEN VERILER GRAFIGIN UZERINE AKTARILMAKTADIR.
- foreach (int i in sayilar)
- {
- chart1.Series["GUNLUK DAKIKA"].Points.AddXY(tarih[j], i);
- j++;
- }
- }
- conn.Close();
- }
- public void tarihKarsilastir()
- {
- //SECILEN ZAMANLAR ARADAKI FARK IICN UYGUN BOYUTA DONUSTURULMEKTE.
- baslangic = Math.Round(dateTimePicker1.Value.ToOADate(), 0);
- bitis = Math.Round(dateTimePicker2.Value.ToOADate(), 0);
- int fark = int.Parse(bitis - baslangic + "");
- //SECILEN FILTREYEE GORE ZAMAN KISITLAMASI UYGULANMAKTA.
- if (filtre.Equals(radioButton1.Text))
- {
- if (fark < 30)
- {
- MessageBox.Show("Girdiğiniz ay aralığı uygun değildir");
- key = false;
- }
- }
- if (filtre.Equals(radioButton2.Text))
- {
- if (fark < 1)
- {
- MessageBox.Show("Girdiğiniz gün aralığı uygun değildir");
- key = false;
- }
- }
- }
- }
- }