C# Veritabanına Bağlanarak Giriş Yapma

Nazlıcan

Çalışkan Üye
Katılım
10 Mar 2018
Mesajlar
200
Beğeniler
0
Problem şu;

Program 3 kere ücretsiz çalışacak ve 4. açılışta

KEY Sormasını istiyorum Database daha önce girilen KEY'le eşleşirse giriş yapsın.

Girilen KEY Doğru ise Zaten Bir daha sormasına gerek yok.
Kod:
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;

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

OleDbConnection con;
OleDbDataAdapter da;
OleDbCommand cmd;
DataSet ds;
string key;
string date;
public static string sonuc;


public void veritabani()
{
try
{
con = new OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0 ;Data Source=cdkey.accdb");
con.Open();
//MessageBox.Show("Veritabanına bağlandınız");
}
catch (Exception e)
{

MessageBox.Show("Veritabanına bağlanırken hata oluştu" + e);
}


}



public void User()
{
OleDbCommand komut;
OleDbDataReader oku;


try
{

komut = new OleDbCommand();
komut.CommandText = "Select * from users where user_id =1";
komut.Connection = con;
oku = komut.ExecuteReader();
while (oku.Read())
{

key = oku[1].ToString();
date = oku[2].ToString();
}
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}
}


public void Keys()
{
OleDbCommand komut;
OleDbDataReader oku;

try
{

komut = new OleDbCommand();
komut.CommandText = "Select count(*) from cdkeys where key_number = '"+key+"' and key_date > '"+date+"'";
komut.Connection = con;
oku = komut.ExecuteReader();
while (oku.Read())
{

sonuc = oku[0].ToString();


}
con.Close();
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
}

con.Close();
}

public void Kontrol()
{
if(sonuc == 1.ToString())
{

MessageBox.Show("Sisteme Kayitli");

Form2 form2 = new Form2();
form2.Show();
this.Size = new Size(0, 0);
Opacity = -999;

return;
}if(sonuc == 0.ToString())
{
MessageBox.Show("CD Key Süreniz Doldu ya da lisans key girmediniz.");
return;
}
}

public void Lisanskey()
{

cmd = new OleDbCommand();
//con.Open();
cmd.Connection = con;
cmd.CommandText = "update users set user_key='" + user_newkey + "', user_lasttime ='" + tumparcalar + "' where user_id= 1";
cmd.ExecuteNonQuery();
con.Close();
veritabani();
}









string tumparcalar;
string user_newkey;
private void Form1_Load(object sender, EventArgs e)
{

timer1.Start();
veritabani();

User();
Keys();

Kontrol();
string[] parcalar;

parcalar = label1.Text.Split('.');

tumparcalar = parcalar[2] + parcalar[1] + parcalar[0];

user_newkey = textBox1.Text;




}


private void button1_Click(object sender, EventArgs e)
{





veritabani();

string[] parcalar;

parcalar = label1.Text.Split('.');

tumparcalar = parcalar[2] + parcalar[1] + parcalar[0];
user_newkey = textBox1.Text;
Lisanskey();
User();
Keys();
Kontrol();




}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToShortDateString();
}
}
}
 

Şu anda bu konu'yu okuyan kullanıcılar

Benzer konular

Üst