NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

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 MySql.Data;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

MySqlConnection bag = new MySqlConnection("server=localhost;Database=20210517vt ;Uid=20210517vt; Pwd=123; charset=utf8");

void listele()
{
try
{
MySqlCommand komut=new MySqlCommand("SELECT * FROM KAYIT", bag);
MySqlDataAdapter adp=new MySqlDataAdapter(komut);
DataTable tablo=new DataTable();
adp.Fill(tablo);
dataGridView1.DataSource = tablo;
}
catch(Exception hata)
{
if (bag.State == ConnectionState.Open) bag.Close();

MessageBox.Show(hata.Message);
}
}

void listele(params string[] p)
{
try
{
string sorgu = "SELECT * FROM KAYIT WHERE ";

if (p[0] != "") sorgu += "NUMARA = @n AND ";
if (p[1] != "") sorgu += "AD LIKE @ad AND ";
if (p[2] != "") sorgu += "ADRES LIKE @adr AND ";
if (p[3] != "") sorgu += "BÖLÜM LIKE @bol AND ";

sorgu = sorgu.Substring(0, sorgu.Length - 5);

sorgu += " ORDER BY NUMARA";

MySqlCommand komut = new MySqlCommand(sorgu, bag);
if (p[0] != "") komut.Parameters.AddWithValue("@n", p[0]);
if (p[1] != "") komut.Parameters.AddWithValue("@ad", p[1]);
if (p[2] != "") komut.Parameters.AddWithValue("@adr", p[2]);
if (p[3] != "") komut.Parameters.AddWithValue("@bol", p[3]);

MySqlDataAdapter adp = new MySqlDataAdapter(komut);
DataTable tablo = new DataTable();
adp.Fill(tablo);
dataGridView1.DataSource = tablo;
}
catch (Exception hata)
{
if (bag.State == ConnectionState.Open) bag.Close();

MessageBox.Show(hata.Message);
}
}

private void Form1_Load(object sender, EventArgs e)
{
listele();
}

// KAYIT EKLEME
private void button1_Click(object sender, EventArgs e)
{
try
{
string sorgu;
sorgu = "INSERT INTO KAYIT VALUES(@n,@ad,@adr,@bol)";
MySqlCommand komut = new MySqlCommand(sorgu,bag);
komut.Parameters.AddWithValue("@n", textBox1.Text);
komut.Parameters.AddWithValue("@ad", textBox2.Text);
komut.Parameters.AddWithValue("@adr", textBox3.Text);
komut.Parameters.AddWithValue("@bol", textBox4.Text);

bag.Open();
komut.ExecuteNonQuery();
bag.Close();

listele();
textBox1.Clear(); textBox2.Clear();
textBox3.Clear(); textBox4.Clear();
textBox1.Focus();
}
catch (Exception hata)
{
if (bag.State == ConnectionState.Open) bag.Close();
MessageBox.Show(hata.Message);
}
}

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar)&& !char.IsSeparator(e.KeyChar);
}

private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar) && !char.IsSeparator(e.KeyChar);

}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
}

//ARAMA
private void button2_Click(object sender, EventArgs e)
{
string n, ad, adr, bol;

n = textBox1.Text;
ad = textBox2.Text;
adr = textBox3.Text;
bol = textBox4.Text;

listele(n, ad, adr, bol);

}


string num;
int satir;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
satir = dataGridView1.SelectedCells[0].RowIndex;
num = dataGridView1.Rows[satir].Cells[0].Value.ToString();
textBox1.Text = num;
textBox2.Text = dataGridView1.Rows[satir].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[satir].Cells[2].Value.ToString();
textBox4.Text = dataGridView1.Rows[satir].Cells[3].Value.ToString();


}

// GÜNCELLEME
private void button3_Click(object sender, EventArgs e)
{
try
{
string sorgu;
sorgu = "UPDATE KAYIT SET NUMARA=@n, AD=@ad, ADRES=@adr, BÖLÜM=@bol WHERE NUMARA = @gn";
MySqlCommand komut = new MySqlCommand(sorgu, bag);
komut.Parameters.AddWithValue("@n", textBox1.Text);
komut.Parameters.AddWithValue("@ad", textBox2.Text);
komut.Parameters.AddWithValue("@adr", textBox3.Text);
komut.Parameters.AddWithValue("@bol", textBox4.Text);
komut.Parameters.AddWithValue("@gn", num);


bag.Open();
komut.ExecuteNonQuery();
bag.Close();

listele();
textBox1.Clear(); textBox2.Clear();
textBox3.Clear(); textBox4.Clear();
textBox1.Focus();
}
catch (Exception hata)
{
if (bag.State == ConnectionState.Open) bag.Close();
MessageBox.Show(hata.Message);
}
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.