PDA

View Full Version : سوال: ایجاد فرم لاگین برای نرم افزار



alifamoor
پنج شنبه 28 اسفند 1393, 08:31 صبح
من یک تازه وارد هستم و یه علت علا در حال کار در سی شارپ هستم
تا به حال برای من اتفاق نیوفتاده بود که از دیتا بیس استفاده کنم اما من حالا میخواهم یک صفحه لاگین درست کنم که نام کاربری و رمز عبور میخواهد
میخواهم بتوانم نام کاربری جدید تعریف کرد ورمز عبور هر نام کاربری را هم بتوان تغییر داد
در اینترنت هم چیزی که میخواستم پیدا نکردم
امیوارم شما به من کمک کنید

j_naroogha@yahoo.com
پنج شنبه 28 اسفند 1393, 10:18 صبح
واقعا پیدا نشد؟؟؟؟!!!!!!!!!!!!!!!!!!


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace ModatManteghe.modules
{
public class user
{
public string username { get; set; }
public string password { get; set; }
public string name { get; set; }
public string family { get; set; }
public int type { get; set; }
public string reg_date { get; set; }

public Boolean _Add()
{
DBconnection de = new DBconnection();
String strsql = "insert into tbl_user values('" + username + "',N'" + password + "',N'" + name + "',N'" + family +
"',N'" + type + "',N'" + reg_date + "')";
SqlCommand cmd = new SqlCommand(strsql, de._Connect());
int rst = cmd.ExecuteNonQuery();
if (rst > 0)
return true;
return false;
}
public Boolean _Delete()
{
DBconnection de = new DBconnection();
String strsql = "delete from tbl_user where username=N'" + username + "'";
SqlCommand cmd = new SqlCommand(strsql, de._Connect());
int rst = cmd.ExecuteNonQuery();
if (rst > 0)
return true;
return false;
}
public Boolean _Edite()
{
DBconnection de = new DBconnection();
String strsql = "update tbl_user set password=N'"+password+"',name=N'"+name+"',family=N'"+
family+"',type=N'"+type+"',reg_date=N'"+reg_date+"' where username=N'"+username +"'";
SqlCommand cmd = new SqlCommand(strsql, de._Connect());
int rst = cmd.ExecuteNonQuery();
if (rst > 0)
return true;
return false;
}
public String _GetUsernamefamily(String _User)
{
String str = "select * from tbl_user where username=N'" + _User + "'";
DBconnection dcnn = new DBconnection();
SqlCommand scmd = new SqlCommand(str, dcnn._Connect());
SqlDataReader dr = scmd.ExecuteReader();
String rst = "";
if (dr.Read())
{
rst = dr["name"].ToString() + " " + dr["family"].ToString();
dr.Close();
return rst;
}
dr.Close();
return "";
}
public String _GetUserType(String _User)
{
String str = "select type from tbl_user where username=N'" + _User + "'";
DBconnection dcnn = new DBconnection();
SqlCommand scmd = new SqlCommand(str,dcnn._Connect());
SqlDataReader dr = scmd.ExecuteReader();
String rst = "";
if (dr.Read())
{
rst = dr[0].ToString();
dr.Close();
return rst;
}
dr.Close();
return "";
}
public Boolean _checklogin(string _username,string _password)
{
DBconnection d = new DBconnection();
string strsql = "select * from tbl_user where username=N'" + _username + "' and password=N'"+_password +"'";
SqlCommand cmd = new SqlCommand(strsql ,d._Connect());
SqlDataReader dr=cmd.ExecuteReader ();
if (dr.Read() )
{
return true;
}
return false;
}
public Boolean _checkExist(String _username)
{
DBconnection dbcnn = new DBconnection();
String strsql = "select username from tbl_user where username=N'" + _username + "'";
SqlCommand scmd = new SqlCommand(strsql, dbcnn._Connect());
SqlDataReader dr = scmd.ExecuteReader();
if (dr.HasRows)
{
dr.Close();
return true;
}
dr.Close();
return false;
}
public int _Gettypenumber(String _type)
{
String str = "select ID from tbl_user_type where des=N'" + _type + "'";
DBconnection dcnn = new DBconnection();
SqlCommand scmd = new SqlCommand(str, dcnn._Connect());
SqlDataReader dr = scmd.ExecuteReader();
int rst = -1;
if (dr.Read())
{
rst = int.Parse(dr[0].ToString());
dr.Close();
return rst;
}
dr.Close();
return -1;
}
}
}

j_naroogha@yahoo.com
پنج شنبه 28 اسفند 1393, 10:20 صبح
اینم واسه اتصال دیتابیس

public SqlConnection _Connect()
{

string strSC = "Data Source=" + Server + ";Initial Catalog=" + DB + ";Integrated Security=True";
SqlConnection SC = new SqlConnection(strSC);
if (SC.State == ConnectionState.Closed)
{
try
{
SC.Open();
return SC;
}
catch(Exception e)
{
MessageBox.Show(e.Message);
return SC;
}
}
else
return SC;
}
}

همه چی آمادس فقط ازش استفاده کنین.....

ghasem110deh
پنج شنبه 28 اسفند 1393, 11:28 صبح
سلام
یه توضیحی هم در مورد کدها میدین !