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;
namespace Proje
{
public partial class Form1 : Form
{
DataSet ds = new DataSet();
SqlConnection baglanti = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\çağdaş\Desktop\Proje\Proje\Proje.mdf;Integrated Security=True;Connect Timeout=30");
SqlDataAdapter da = new SqlDataAdapter();
BindingSource tablename = new BindingSource();
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'projeDataSet.proje' table. You can move, or remove it, as needed.
// this.projeTableAdapter.Fill(this.projeDataSet.proje);
}
private void btnekle_Click(object sender, EventArgs e)//ekle butonu...
{
da.InsertCommand = new SqlCommand("insert into proje values (@Adi,@Soyadi)", baglanti);
da.InsertCommand.Parameters.Add("@Adi", SqlDbType.NVarChar).Value = txtisim.Text;
da.InsertCommand.Parameters.Add("@Soyadi", SqlDbType.NVarChar).Value = txtsoy.Text;
baglanti.Open();
da.InsertCommand.ExecuteNonQuery();
baglanti.Close();
ds.Clear();//dataset boşaltılıp yeniden yüklendi...
da.Fill(ds);
}
private void btnlsitele_Click(object sender, EventArgs e)
{
da.SelectCommand= new SqlCommand("select * from proje", baglanti);
ds.Clear();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
tablename.DataSource = ds.Tables[0];
//txtisim.DataBindings.Add(new Binding("Text", tablename, "Adi"));
//txtsoy.DataBindings.Add(new Binding("Text", tablename, "Soyadi"));
record();
}
private void btnileri_Click(object sender, EventArgs e)
{
tablename.MoveNext();//ileri butonu
datagridview();//oluşturulan metod
record();
}
private void btngeri_Click(object sender, EventArgs e)
{
tablename.MovePrevious();//geri butonu..
datagridview();
record();
}
private void button2_Click(object sender, EventArgs e)
{
tablename.MoveLast();
datagridview();
record();
}
private void btnilk_Click(object sender, EventArgs e)
{
tablename.MoveFirst();//ilk başa dön butonu...
datagridview();
record();
}
private void datagridview() {
dataGridView1.ClearSelection();
dataGridView1.Rows[tablename.Position].Selected = true;
}
private void record() {//kayıt sayısını bir labelde gösteren metod...
label3.Text = "Record " + tablename.Position + " of " + (tablename.Count - 1);
}
private void btnduzenle_Click(object sender, EventArgs e)//düzenle butonu...
{
int x;
da.UpdateCommand = new SqlCommand("UPDATE proje SET Adi = @Adi,Soyadi = @Soyadi WHERE Id = @Id", baglanti);
da.UpdateCommand.Parameters.Add("@Adi", SqlDbType.NVarChar).Value = txtisim.Text;
da.UpdateCommand.Parameters.Add("@Soyadi", SqlDbType.NVarChar).Value = txtsoy.Text;
da.UpdateCommand.Parameters.Add("@Id", SqlDbType.Int).Value = ds.Tables[0].Rows[tablename.Position][0];
baglanti.Open();
x = da.UpdateCommand.ExecuteNonQuery();
baglanti.Close();
ds.Clear();
da.Fill(ds);
if (x >= 1)
{
MessageBox.Show("Kayıt Güncellendi");
}
}
private void btnsil_Click(object sender, EventArgs e)//sil butonu..
{
DialogResult dr;
dr = MessageBox.Show("Kayıt Silinecek!!!\nTablodan Kaydı Silmek İstediğinizden Emin Misiniz?","Kayıt Sil", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
da.DeleteCommand = new SqlCommand("DELETE FROM proje WHERE Id=@Id", baglanti);
da.DeleteCommand.Parameters.Add("@Id", SqlDbType.Int).Value = ds.Tables[0].Rows[tablename.Position][0];
baglanti.Open();
da.DeleteCommand.ExecuteNonQuery();
baglanti.Close();
ds.Clear();
da.Fill(ds);
}
else
{
MessageBox.Show("Silme İptal Edildi...!!!","İptal",MessageBoxButtons.OK,MessageBoxIcon.Hand);
}
}
private void btnisim_Click(object sender, EventArgs e)//isimleri combobox a aktaran buton...
{
da.SelectCommand = new SqlCommand("select * from proje order by Adi", baglanti);
da.Fill(dt);
for (int i = 0; i <dt.Rows.Count; i++)
{
comboBox1.Items.Add(dt.Rows[i]["Adi"]);
}
}
private void btnsoyisim_Click(object sender, EventArgs e)//soyadları combobox a atan buton..
{
da.SelectCommand = new SqlCommand("select * from proje order by Soyadi", baglanti);
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox2.Items.Add(dt.Rows[i]["Soyadi"]);
}
}
}
}