brk5000
Picopat
- Katılım
- 27 Şubat 2024
- Mesajlar
- 98
- Çözümler
- 1
Daha fazla
- Cinsiyet
- Erkek
C#:
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 System.Data.OleDb;
using System.Configuration;
namespace Teknisyen_Talep_Takip_Bilgi_Sistemi
{
public partial class frmTalepleriListeleme : Form
{
OleDbConnection baglanti = new OleDbConnection(ConfigurationManager.ConnectionStrings["Teknisyen_Talep_Takip_Bilgi_Sistemi.Properties.Settings.Teknisyen_Talep_Bilgi_SistemiConnectionString"].ConnectionString);
DataTable tablo = new DataTable();
public frmTalepleriListeleme()
{
InitializeComponent();
}
private void FillDataGridView()
{
// Veritabanından verileri çekerek DataGridView'i doldur
try
{
baglanti.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Talep_Takip", baglanti);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
dataGridView1.DataSource = dataTable;
baglanti.Close();
}
catch (Exception ex)
{
MessageBox.Show("Hata: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DataGridViewColorize()
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// Sadece "Talep_Durumu" sütununu kontrol et
DataGridViewCell talepDurumuCell = row.Cells["Talep_Durumu"];
if (talepDurumuCell.Value != null && talepDurumuCell.Value.ToString() == "Devam Ediyor")
{
// "Talep_Durumu" hücresini yeşil yap
talepDurumuCell.Style.BackColor = Color.Yellow;
talepDurumuCell.Style.ForeColor = Color.White;
}
else if (talepDurumuCell.Value != null && talepDurumuCell.Value.ToString() == "AÇIK")
{
// "Talep_Durumu" hücresini yeşil yap
talepDurumuCell.Style.BackColor = Color.Green;
talepDurumuCell.Style.ForeColor = Color.White;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
baglanti.Open();
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from Talep_Takip order by Talep_Durumu", baglanti);
adapter.Fill(tablo);
dataGridView1.DataSource = tablo;
baglanti.Close();
pictureBox1.SendToBack();
DataGridViewColorize();
DataGridViewColorize2();
FillDataGridView();
}
private void dataGridView1_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
{
try
{
if (e.RowIndex >= 0 && e.RowIndex < dataGridView1.Rows.Count)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
string talepDurumu = row.Cells["Talep_Durumu"].Value.ToString();
if (talepDurumu == "AÇIK")
{
// Detay sayfasına hangi satıra tıklandı ise o satırdaki talebin numarasını gönderiyoruz.
// Bu sayede detay sayfasında seçilen talebin detaylarını database den çekmek için sorguda bu numarayı kullanacağız
frmTalepDetay form = new frmTalepDetay(Convert.ToInt32(row.Cells["Talep_Numarasi"].Value));
form.ShowDialog();
}
else if (talepDurumu == "KAPALI")
{
DialogResult result = MessageBox.Show("Seçili talep kapalı durumda. Detayları görmek istiyor musunuz?", "Talep Kapalı", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
frmTalepDetay form = new frmTalepDetay(Convert.ToInt32(row.Cells["Talep_Numarasi"].Value));
form.ShowDialog();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Hata: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnSil_Click_1(object sender, EventArgs e)
{
{
if (dataGridView1.SelectedRows.Count > 0)
{
DialogResult cevap = MessageBox.Show("Seçili satırı silmek istiyor musunuz?", "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (cevap == DialogResult.Yes)
{
int rowIndex = dataGridView1.SelectedRows[0].Index;
int talepNumarasi = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells["Talep_Numarasi"].Value);
try
{
baglanti.Open();
OleDbCommand komut = new OleDbCommand("DELETE FROM Talep_Takip WHERE Talep_Numarasi = @Talep_Numarasi", baglanti);
komut.Parameters.AddWithValue("@Talep_Numarasi", talepNumarasi);
int affectedRows = komut.ExecuteNonQuery();
baglanti.Close();
if (affectedRows > 0)
{
MessageBox.Show("Seçili satır başarıyla silindi.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
dataGridView1.Rows.RemoveAt(rowIndex);
}
else
{
MessageBox.Show("Silme işlemi başarısız oldu.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("Hata: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else
{
MessageBox.Show("silmek istediğiniz satırı seçin.", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
private void btnEkle_Click(object sender, EventArgs e)
{
// Talep Numarasını al
if (!int.TryParse(txtTalepNumarasi.Text, out int talepNumarasi))
{
MessageBox.Show("Talep numarası geçerli bir sayı değil.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
// Veritabanı bağlantısını aç
baglanti.Open();
// Talebi seçmek için sorgu oluştur
OleDbCommand selectCommand = new OleDbCommand("SELECT * FROM Talep_Takip WHERE Talep_Numarasi = @Talep_Numarasi", baglanti);
selectCommand.Parameters.AddWithValue("@Talep_Numarasi", talepNumarasi);
// Sorguyu çalıştır ve sonucu al
OleDbDataReader reader = selectCommand.ExecuteReader();
// Eğer talep bulunursa
if (reader.Read())
{
// Boş sütunları güncelle
;
DateTime AtamaTarihi = DateTime.Now;
string sadeceTarih2 = AtamaTarihi.ToShortDateString();
DateTime tamamlanmaTarihi = DateTime.Parse(txtTamamlanmaTarihi.Text);
string sadeceTarih = tamamlanmaTarihi.ToShortDateString();
OleDbCommand updateCommand = new OleDbCommand("UPDATE Talep_Takip SET Atanan_Teknisyen = @Atanan_Teknisyen, Atama_Tarihi = @Atama_Tarihi, Tahmini_Tamamlanma_Tarihi = @Tahmini_Tamamlanma_Tarihi,Tamamlanma_Tarihi=@Tamamlanma_Tarihi,Talep_Durumu=@Talep_Durumu WHERE Talep_Numarasi = @Talep_Numarasi", baglanti);
updateCommand.Parameters.AddWithValue("@Atanan_Teknisyen", txtAtananTeknisyen.Text);
updateCommand.Parameters.AddWithValue("@Atama_Tarihi", AtamaTarihi);
updateCommand.Parameters.AddWithValue("@Tahmini_Tamamlanma_Tarihi", txtTahminiTamamlanmaTarihi.Text);
updateCommand.Parameters.AddWithValue("@Tamamlanma_Tarihi", tamamlanmaTarihi);
updateCommand.Parameters.AddWithValue("@Talep_Durumu", "Devam Ediyor");
updateCommand.Parameters.AddWithValue("@Talep_Numarasi", talepNumarasi);
// Güncelleme komutunu çalıştır
int affectedRows = updateCommand.ExecuteNonQuery();
// Etkilenen satır sayısına göre işlem sonucunu kontrol et
if (affectedRows > 0)
{
MessageBox.Show("Talep başarıyla güncellendi.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Talep güncelleme işlemi başarısız oldu.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Belirtilen Talep Numarasına sahip bir talep bulunamadı.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// Veritabanı bağlantısını kapat
baglanti.Close();
}
catch (Exception ex)
{
MessageBox.Show("Hata: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Form_Load(object sender, EventArgs e)
{
// Form yüklenirken DataGridView'i doldur
// DataGridView'i renklendir
DataGridViewColorize();
}
private void btnKapat_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
DialogResult cevap = MessageBox.Show("Seçili satırın talep durumunu 'KAPALI' olarak güncellemek istiyor musunuz?", "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (cevap == DialogResult.Yes)
{
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
selectedRow.Cells["Talep_Durumu"].Value = "KAPALI"; // Talep durumu "KAPALI" olarak güncelleniyor
// Seçili satırın sadece "Talep_Durumu" hücresinin arka planını kırmızı yap
selectedRow.Cells["Talep_Durumu"].Style.BackColor = Color.Red;
selectedRow.Cells["Talep_Durumu"].Style.ForeColor = Color.White;
// Hücrenin stil özelliklerini sakla
selectedRow.Cells["Talep_Durumu"].Tag = "KIRMIZI";
DataGridViewColorize2();
// Değişiklikleri veritabanına kaydet
Kaydet();
}
}
else
{
MessageBox.Show("kapatmak istediğiniz talebi seçin.", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void DataGridViewColorize2()
{
// DataGridView'in satırlarını renklendir
foreach (DataGridViewRow row in dataGridView1.Rows)
{
DataGridViewCell talepDurumuCell = row.Cells["Talep_Durumu"];
if (talepDurumuCell.Value != null && talepDurumuCell.Value.ToString() == "KAPALI")
{
talepDurumuCell.Style.BackColor = Color.Red;
talepDurumuCell.Style.ForeColor = Color.White;
}
}
}
private void Kaydet()
{
try
{
// Veritabanı bağlantısını aç
baglanti.Open();
// Talep durumunu güncelle
OleDbCommand updateCommand = new OleDbCommand("UPDATE Talep_Takip SET Talep_Durumu = @Talep_Durumu WHERE Talep_Numarasi = @Talep_Numarasi", baglanti);
updateCommand.Parameters.AddWithValue("@Talep_Durumu", "KAPALI");
// Seçilen satırın talep numarasını al
int talepNumarasi = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Talep_Numarasi"].Value);
updateCommand.Parameters.AddWithValue("@Talep_Numarasi", talepNumarasi);
// Komutu çalıştır
int affectedRows = updateCommand.ExecuteNonQuery();
// Etkilenen satır sayısına göre işlem sonucunu kontrol et
if (affectedRows > 0)
{
// Kullanıcıya başarı mesajı göster
MessageBox.Show("Değişiklikler başarıyla kaydedildi.", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Kaydetme işlemi başarısız oldu.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// Veritabanı bağlantısını kapat
baglanti.Close();
}
catch (Exception ex)
{
MessageBox.Show("Hata: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Taleplerlistesi diye formum var. Formun içinde kapat butonu var butona basınca DataGridView'deki verinin talep durumu sütunu kapalıya dönüyor kırmızı arka plan rengi oluyor. Fakat programı tekrar çalıştırıp baktıgımda talep durumu kapalı yazıyor ama arka plan kırmızı rengi gözükmüyor nasıl çözebilirim?
@TheAny hocam düzelttim yenı bir konu açarak sende bakabılırsın istersen.
Son düzenleme: