//Kütüphaneler
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Net;
/// <summary>
/// Summary description for User
/// </summary>
public class User
{
public enum loginresult { success, failure, notqueried, notfound };
public enum registerresult { success, failure, notqueried, already };
public enum usertype { client, admin, notdefined };
public int ID = 1;
public string email = string.Empty;
public string username = string.Empty;
public string password = string.Empty;
public string name = string.Empty;
public string surname = string.Empty;
public string birthdate = string.Empty;
public string city = string.Empty;
public string country = string.Empty;
public string gender = string.Empty;
public string reference = string.Empty;
public string epass = string.Empty;
public int roleID = 0;
public usertype usrtype = usertype.notdefined;
public loginresult usrloginstatus = loginresult.notqueried;
public registerresult usrregisterstatus = registerresult.notqueried;
public int uyari = 0;
public User()
{
//
// TODO: Add constructor logic here
//
}
public void RegisterUser(User currentUser)
{
try
{
//DBTagName web.config in içinde ConnectionString tag 'inin içinde tanımlanmıştır.
// şeklinde ayrılmış kodlar web.config içine doğru parametereleri ile yerleştirilecektir.
//<connectionStrings>
// <add name="DBTagName" connectionString="Data Source=SunucuAdresi;Initial Catalog=DatabaseAdı;User ID=KullanıcıAdı;Password=Şifre" providerName="System.Data.SqlClient"/>
// </connectionStrings>
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["[B]DBTagName[/B]"].ConnectionString))
{
//Database'de daha önce aynı email veya kullanıcı adıan sahip kullanıcı varmı yokmu kontrolü, varsa hata dön yoksa kayıt işlemini yap
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = String.Format("select * from [User] where (username=@username OR email=@email)");
conn.Open();
cmd.Parameters.AddWithValue("email", currentUser.email);
cmd.Parameters.AddWithValue("username", currentUser.username);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Close();
conn.Close();
currentUser.usrregisterstatus = User.registerresult.already;
}
else
{
dr.Close();
cmd.Cancel();
//Kayıt işlemi
SqlCommand cmdnew = conn.CreateCommand();
cmdnew.CommandText = String.Format("insert into [User] (email,username,password,name,surname,birthdate,city,country,gender,reference,epass,roleID) values (@email,@username,@password,@name,@surname,@birthdate,@city,@country,@gender,@reference,@epass,'1')");
cmdnew.Parameters.AddWithValue("email", currentUser.email);
cmdnew.Parameters.AddWithValue("username", currentUser.username);
cmdnew.Parameters.AddWithValue("password", currentUser.password);
cmdnew.Parameters.AddWithValue("name", currentUser.name);
cmdnew.Parameters.AddWithValue("surname", currentUser.surname);
cmdnew.Parameters.AddWithValue("birthdate", currentUser.birthdate);
cmdnew.Parameters.AddWithValue("city", currentUser.city);
cmdnew.Parameters.AddWithValue("country", currentUser.country);
cmdnew.Parameters.AddWithValue("gender", currentUser.gender);
cmdnew.Parameters.AddWithValue("reference", currentUser.reference);
cmdnew.Parameters.AddWithValue("epass",currentUser.epass);
int i = cmdnew.ExecuteNonQuery();
if (i == 1)
{
uyari = 1;
currentUser.usrregisterstatus = User.registerresult.success;
}
else
{
uyari = 2;
currentUser.usrregisterstatus = User.registerresult.failure;
}
cmdnew.Cancel();
}
conn.Close();
}
}
catch (Exception e)
{
uyari = 3;
currentUser.usrregisterstatus = User.registerresult.failure;
}
}
}