Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: None  |  size: 7.44 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.Windows.Forms;
  9. using Oracle.DataAccess.Client;
  10. using System.IO;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         String filtre = " ";
  17.         bool key = true;
  18.         List<int> sayilar = new List<int>();
  19.         List<string> joblar = new List<string>();
  20.         List<string> tarih = new List<string>();
  21.         double baslangic, bitis;
  22.         OracleConnection conn = new OracleConnection();
  23.         OracleCommand cmd;
  24.         OracleDataReader reader;
  25.  
  26.         public Form1()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.         private void Form1_Load(object sender, EventArgs e)
  32.         {
  33.             dosyadanOku("C://jobTakip.txt");
  34.         }
  35.  
  36.         private void radioButton1_CheckedChanged(object sender, EventArgs e)
  37.         {
  38.             filtre = radioButton1.Text;
  39.         }
  40.  
  41.         private void radioButton2_CheckedChanged(object sender, EventArgs e)
  42.         {
  43.             filtre = radioButton2.Text;
  44.         }
  45.  
  46.         public void button1_Click(object sender, EventArgs e)
  47.         {//TARIHLER KARSILASTIRIP KISITLAMADAN GECERSE KEY DEGERI TRUE OLMAKTA VE BU ISLEME DEVAM EDILMEKTEDIR.
  48.             //PROGRAMIN ILK KONTROLU BURADA YAPILMAKTADIR VE TARIH ARALIGINDA HATA VARSA ISLEM YAPILMAMAKTADIR.
  49.             tarihKarsilastir();
  50.             if (key)
  51.             {
  52.                 sorgula();
  53.                 //SECILEN BILGILER DOGRULTUSUNDA OLUSTURULACAK GRAFIGIN OZELLIKLERI BUTONA AKTARILMAKTADIR.
  54.                 button1.Text = comboBox1.Text + "\n" + filtre + "\n" + dateTimePicker1.Text + "---" + dateTimePicker2.Text;
  55.             }
  56.             key = true;
  57.         }
  58.  
  59.         public void dosyadanOku(string path)
  60.         {
  61.             //SISTEM JOBLARI VERITABANINDAN OKUNACAK VE COMBOBOX MENUSUNE AKTARILACAK.
  62.             StreamReader reader = new StreamReader(path);
  63.             string yazi;
  64.             yazi = reader.ReadLine();
  65.  
  66.             while (yazi != null)
  67.             {
  68.                 comboBox1.Items.Add(yazi);
  69.                 yazi = reader.ReadLine();
  70.             }
  71.             reader.Close();
  72.         }
  73.  
  74.         public void guncelle()
  75.         {
  76.             conn.ConnectionString = "User ID=********; Password=**********; Data Source=********";
  77.             conn.Open();
  78.             //SISTEM JOBLARININ ISTENILDIGINDE VEYA HERHANGI BIR DEGISIKLIKTE
  79.             //GUNCELLE BUTONUYLA ISLEME ALINMASI VE YENILENMESI AMACIYLA YAPILACAK OLAN BIR SORGUDUR.
  80.             cmd = new OracleCommand("SELECT DISTINCT OBJE_ADI FROM ***** WHERE OBJE_ADI LIKE ************%'");
  81.             cmd.Connection = conn;
  82.             reader = cmd.ExecuteReader();
  83.             while (reader.Read())
  84.             {
  85.                 joblar.Add(reader["OBJE_ADI"].ToString());
  86.             }
  87.             //GUNCELLEME SONUCUNDA DOSYAYA VERITABANINDAN CEKILEN BUTUN JOBLAR EKLENMEKTEDIR.
  88.             dosyayaEkle("C://jobTakip.txt", joblar);
  89.             conn.Close();
  90.         }
  91.  
  92.         public void dosyayaEkle(string path, List<string> veri)
  93.         {
  94.             //VERILEN YOLDAKI DOSYAYA SINIRSIZ BOYUTLU OLARAK VERILEN DIZIDEKI BILGILER WRITELINE KOMUTU ILE ALTALTA YAZDIRILMAKTA.
  95.             StreamWriter dosya = new StreamWriter(path);
  96.             foreach (string satir in veri)
  97.             {
  98.                 dosya.WriteLine(satir);
  99.             }
  100.             dosya.Close();
  101.             dosyadanOku(path);
  102.         }
  103.  
  104.         private void button2_Click(object sender, EventArgs e)
  105.         {
  106.             System.IO.File.Delete("C://jobTakip.txt");
  107.             guncelle();
  108.         }
  109.  
  110.         public void sorgula()
  111.         {
  112.             conn.ConnectionString = "User ID=*********; Password=*****; Data Source=******";
  113.             conn.Open();
  114.             //AYLIK ORTALAMA
  115.             if (filtre.Equals(radioButton1.Text))
  116.             {//AY SECIMI YAPILIRSA BU IF BLOGUNA GIRILECEK VE AYLIK ORTALAMA ICIN ASAGIDAKI SORGU YAPILACAK.
  117.                 cmd = new OracleCommand(
  118.                     "SELECT TARIH,ORTALAMA FROM( SELECT TO_CHAR(BASLANGIC,'MM/YYYY') AS TARIH , ROUND(AVG(GECEN_SURE_DAKIKA+GECEN_SURE_SANIYE/60),0) AS ORTALAMA" +
  119.                     " FROM ********WHERE OBJE_ADI = '" + comboBox1.Text + "' AND BASLANGIC BETWEEN '" + dateTimePicker1.Value.ToShortDateString() +
  120.                     "' AND '" + dateTimePicker2.Value.ToShortDateString() + "' GROUP BY TO_CHAR(BASLANGIC,'MM/YYYY')) ORDER BY TARIH"
  121.                     );
  122.                 cmd.Connection = conn;
  123.                 reader = cmd.ExecuteReader();
  124.                 //GRAFIK ICIN GEREKLI ARRAYLAR DOLDURULMAKTA.
  125.                 while (reader.Read())
  126.                 {
  127.                     sayilar.Add(int.Parse(reader["ORTALAMA"] + ""));
  128.                     tarih.Add(reader["TARIH"].ToString());
  129.                 }
  130.                 int j = 0;
  131.                 //BU ARRAYLAR GRAFIGIN UZERINE AKTARILMAKTA.
  132.                 foreach (int i in sayilar)
  133.                 {
  134.                     chart1.Series["AYLIK ORTALAMA"].Points.AddXY(tarih[j],i);
  135.                     j++;
  136.                 }
  137.             }
  138.             //GUN GUN ISLEM SURESI
  139.             else if (filtre.Equals(radioButton2.Text))
  140.             {
  141.                 //GUN SECIMI YAPILIRSA BU ELSE BLOGUNA GIRIS YAPILACAK VE SORGUDAKI FARKLILIK ORTAYA BURADA CIKACAK.
  142.                 cmd = new OracleCommand
  143.                     (
  144.                     "SELECT TO_CHAR(BASLANGIC,'DD.MM.YYYY') AS TARIH,ROUND(GECEN_SURE_DAKIKA+GECEN_SURE_SANIYE/60,0) AS GUNLUK_DAKIKA"
  145.                     +" FROM ****** WHERE OBJE_ADI = '"+ comboBox1.Text + "' AND TO_DATE(BASLANGIC,'DD.MM.YYYY') BETWEEN '"
  146.                     + dateTimePicker1.Value.ToShortDateString() + "' AND '" + dateTimePicker2.Value.ToShortDateString() + "' ORDER BY BASLANGIC"
  147.                     );
  148.                 cmd.Connection = conn;
  149.                 reader = cmd.ExecuteReader();
  150.                 //GRAFIK ICIN X VE Y EKSENINI DOLUDRACAK OLAN BILGILER BURADA VERITABANINDAN OKUNMAKTA VE GEREKLI DIZILERE ATILMAKTADIR.
  151.                 while (reader.Read())
  152.                 {
  153.                     sayilar.Add(int.Parse(reader["GUNLUK_DAKIKA"] + ""));
  154.                     tarih.Add(reader["TARIH"].ToString());
  155.                 }
  156.                 int j = 0;
  157.                 //VERITABANINDAN CEKILEN VERILER GRAFIGIN UZERINE AKTARILMAKTADIR.
  158.                 foreach (int i in sayilar)
  159.                 {
  160.                     chart1.Series["GUNLUK DAKIKA"].Points.AddXY(tarih[j], i);
  161.                     j++;
  162.                 }
  163.             }          
  164.             conn.Close();
  165.         }
  166.  
  167.         public void tarihKarsilastir()
  168.         {
  169.             //SECILEN ZAMANLAR ARADAKI FARK IICN UYGUN BOYUTA DONUSTURULMEKTE.
  170.             baslangic = Math.Round(dateTimePicker1.Value.ToOADate(), 0);
  171.             bitis = Math.Round(dateTimePicker2.Value.ToOADate(), 0);
  172.             int fark = int.Parse(bitis - baslangic + "");
  173.             //SECILEN FILTREYEE GORE ZAMAN KISITLAMASI UYGULANMAKTA.
  174.             if (filtre.Equals(radioButton1.Text))
  175.             {
  176.                 if (fark < 30)
  177.                 {
  178.                     MessageBox.Show("Girdiğiniz ay aralığı uygun değildir");
  179.                     key = false;
  180.                 }
  181.             }
  182.             if (filtre.Equals(radioButton2.Text))
  183.             {
  184.                 if (fark < 1)
  185.                 {
  186.                     MessageBox.Show("Girdiğiniz gün aralığı uygun değildir");
  187.                     key = false;
  188.                 }
  189.             }
  190.         }
  191.     }
  192. }