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.SqlClient;
using System.Data.Sql;
namespace StokTakipOtomasyonu
{
public partial class FrmMusteriListelemecs : Form
{
public FrmMusteriListelemecs()
{
InitializeComponent();
}
SqlConnection baglanti = new SqlConnection("Data Source=DESKTOP-9IIMV9N\\SQLEXPRESS;Initial Catalog=StokTakipUyg;Integrated Security=True");
DataSet daset = new DataSet();
private void FrmMusteriListelemecs_Load(object sender, EventArgs e)
{
kayit_goster();
}
private void kayit_goster()
{
baglanti.Open();
SqlDataAdapter adtr = new SqlDataAdapter("select *from musteribilgi", baglanti);
adtr.Fill(daset, "musteribilgi");
dataGridView1.DataSource = daset.Tables["musteribilgi"];
baglanti.Close();
}
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
txtTc.Text = dataGridView1.CurrentRow.Cells["tc"].Value.ToString();
txtAdSoyad.Text = dataGridView1.CurrentRow.Cells["adsoyad"].Value.ToString();
txtTelefon.Text = dataGridView1.CurrentRow.Cells["telefon"].Value.ToString();
txtAdres.Text = dataGridView1.CurrentRow.Cells["adres"].Value.ToString();
txtEmail.Text = dataGridView1.CurrentRow.Cells["email"].Value.ToString();
}
private void txtTcAra_TextChanged(object sender, EventArgs e)
{
DataTable tablo = new DataTable();
baglanti.Open();
SqlDataAdapter adtr = new SqlDataAdapter("select *from musteribilgi where tc like '%" + txtTcAra.Text + "%'", baglanti);
adtr.Fill(tablo);
dataGridView1.DataSource = tablo;
baglanti.Close();
}
private void btnSil_Click(object sender, EventArgs e)
{
baglanti.Open();
SqlCommand komut = new SqlCommand("delete from musteribilgi where tc='" + dataGridView1.CurrentRow.Cells["tc"].Value.ToString() + "'", baglanti);
komut.ExecuteNonQuery();
baglanti.Close();
daset.Tables["musteribilgi"].Clear();
kayit_goster();
MessageBox.Show("Kayıt silindi");
}
private void btnGuncelle_Click(object sender, EventArgs e)
{
baglanti.Open();
SqlCommand komut = new SqlCommand("update musteribilgi set adsoyad=@adsoyad,telefon=@telefon,adres=@adres,email=@email where tc=@tc", baglanti);
komut.Parameters.AddWithValue("@adsoyad", txtAdSoyad.Text);
komut.Parameters.AddWithValue("@telefon", txtTelefon.Text);
komut.Parameters.AddWithValue("@adres", txtAdres.Text);
komut.Parameters.AddWithValue("@email", txtEmail.Text);
komut.Parameters.AddWithValue("@tc", txtTc.Text);
komut.ExecuteNonQuery();
baglanti.Close();
daset.Tables["musteribilgi"].Clear();
kayit_goster();
MessageBox.Show("Müşteri kaydı güncellendi");
foreach (Control item in groupBox1.Controls)
{
if (item is TextBox)
{
item.Text = "";
}
}
}
}
}