mahan206
جمعه 25 مهر 1393, 01:41 صبح
سلام دوستان و اساتید گرامی من تو پروژم چنین کدهای دارم میخواستم همین کدها رو برای بانک sqlبنویسم اما بلد نیستم اگه کسی بلده لطف کنه و بگه کجاش باید تغییر کنه یا تغیرات رو اعمال کنه و کدش رو بزاره ممنون میشم کسی کمکم کنه
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
// if (Session["userLogin"] != null)
// {
// lblStatus.Text = Session["userLogin"].ToString() + "خوش آمدید";
// lblStatus.Text += "<a href=\"logout.aspx\">خروج</a>";
// }
// else
// {
// Response.Redirect("Login2.aspx");
// }
string MyPage = System.IO.Path.GetFileName(Request.Path).ToLower() ;
using (OleDbConnection Con = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString1"].ConnectionString))
{
OleDbCommand cmd = new OleDbCommand("select * from tbl_pages where PageName=?", Con);
cmd.Parameters.AddWithValue("PageNam", MyPage);
Con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (Page.User.Identity.IsAuthenticated)
{
if (!Page.User.IsInRole(dr["PageRole"].ToString()))
{
Response.Redirect("MsgPage.aspx");
}
}
else
{
FormsAuthentication.RedirectToLoginPage();
}
}
Con.Close();
}
if (Page.User.Identity.IsAuthenticated)
{
Button1.Visible = true;
}
else
{
Button1.Visible = false;
}
}
protected void HiddenField1_ValueChanged(object sender, EventArgs e)
{
}
private string GetMemberRoleByID(string UID)
{
using (OleDbConnection Con = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString1"].ConnectionString))
{
OleDbCommand cmd = new OleDbCommand("select roles from tb_admin where uid=?", Con);
cmd.Parameters.AddWithValue("uid", UID);
Con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
string RetVal = "NA";
if (dr.Read())
{
RetVal = dr["Roles"].ToString();
}
Con.Close();
return RetVal;
}
}
private bool GetMemberAuthenticate(string UID, string PWD)
{
using (OleDbConnection Con = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString1"].ConnectionString))
{
bool RetVal=false;
OleDbCommand cmd = new OleDbCommand("select count(*) from tbl_members where (uid=? And Pwd=?)", Con);
cmd.Parameters.AddWithValue("uid", UID);
cmd.Parameters.AddWithValue("Pwd", PWD);
Con.Open();
RetVal= Convert.ToBoolean(cmd.ExecuteScalar());
Con.Close();
return RetVal;
}
}
}
اینم یکی دیگش همینه تبدیل بشه کارم راه میفته دوستان
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string GetMemberRoleByID(string UID)
{
using (OleDbConnection ConnectionString = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString"].ConnectionString))
{
OleDbCommand cmd = new OleDbCommand("select roles from tb_admin where uid=?", ConnectionString);
cmd.Parameters.AddWithValue("uid", UID);
ConnectionString.Open();
OleDbDataReader dr = cmd.ExecuteReader();
string RetVal = "NA";
if (dr.Read())
{
RetVal = dr["Roles"].ToString();
}
ConnectionString.Close();
return RetVal;
}
}
private bool GetMemberAuthenticate(string UID, string PWD)
{
using (OleDbConnection ConnectionString = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString"].ConnectionString))
{
bool RetVal=false;
OleDbCommand cmd = new OleDbCommand("select count(*) from tb_admin where (uid=? And Pwd=?)", ConnectionString);
cmd.Parameters.AddWithValue("uid", UID);
cmd.Parameters.AddWithValue("Pwd", PWD);
ConnectionString.Open();
RetVal= Convert.ToBoolean(cmd.ExecuteScalar());
ConnectionString.Close();
return RetVal;
}
}
protected void btn_submit_Click(object sender, EventArgs e)
{
if (GetMemberAuthenticate(txt_uid.Text, txt_pwd.Text))
{
string role = GetMemberRoleByID(txt_uid.Text);
FormsAuthenticationTicket AuthTicket = new FormsAuthenticationTicket(1, txt_uid.Text, DateTime.Now, DateTime.Now.AddHours(1), false, role);
string encryptedTicket = FormsAuthentication.Encrypt(AuthTicket);
HttpCookie AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(AuthCookie);
Response.Redirect(FormsAuthentication.GetRedirectU rl(txt_uid.Text, chk_member.Checked));
}
else
{
lbl.Visible = true;
}
}
}
ممنون دوستان
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
// if (Session["userLogin"] != null)
// {
// lblStatus.Text = Session["userLogin"].ToString() + "خوش آمدید";
// lblStatus.Text += "<a href=\"logout.aspx\">خروج</a>";
// }
// else
// {
// Response.Redirect("Login2.aspx");
// }
string MyPage = System.IO.Path.GetFileName(Request.Path).ToLower() ;
using (OleDbConnection Con = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString1"].ConnectionString))
{
OleDbCommand cmd = new OleDbCommand("select * from tbl_pages where PageName=?", Con);
cmd.Parameters.AddWithValue("PageNam", MyPage);
Con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (Page.User.Identity.IsAuthenticated)
{
if (!Page.User.IsInRole(dr["PageRole"].ToString()))
{
Response.Redirect("MsgPage.aspx");
}
}
else
{
FormsAuthentication.RedirectToLoginPage();
}
}
Con.Close();
}
if (Page.User.Identity.IsAuthenticated)
{
Button1.Visible = true;
}
else
{
Button1.Visible = false;
}
}
protected void HiddenField1_ValueChanged(object sender, EventArgs e)
{
}
private string GetMemberRoleByID(string UID)
{
using (OleDbConnection Con = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString1"].ConnectionString))
{
OleDbCommand cmd = new OleDbCommand("select roles from tb_admin where uid=?", Con);
cmd.Parameters.AddWithValue("uid", UID);
Con.Open();
OleDbDataReader dr = cmd.ExecuteReader();
string RetVal = "NA";
if (dr.Read())
{
RetVal = dr["Roles"].ToString();
}
Con.Close();
return RetVal;
}
}
private bool GetMemberAuthenticate(string UID, string PWD)
{
using (OleDbConnection Con = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString1"].ConnectionString))
{
bool RetVal=false;
OleDbCommand cmd = new OleDbCommand("select count(*) from tbl_members where (uid=? And Pwd=?)", Con);
cmd.Parameters.AddWithValue("uid", UID);
cmd.Parameters.AddWithValue("Pwd", PWD);
Con.Open();
RetVal= Convert.ToBoolean(cmd.ExecuteScalar());
Con.Close();
return RetVal;
}
}
}
اینم یکی دیگش همینه تبدیل بشه کارم راه میفته دوستان
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private string GetMemberRoleByID(string UID)
{
using (OleDbConnection ConnectionString = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString"].ConnectionString))
{
OleDbCommand cmd = new OleDbCommand("select roles from tb_admin where uid=?", ConnectionString);
cmd.Parameters.AddWithValue("uid", UID);
ConnectionString.Open();
OleDbDataReader dr = cmd.ExecuteReader();
string RetVal = "NA";
if (dr.Read())
{
RetVal = dr["Roles"].ToString();
}
ConnectionString.Close();
return RetVal;
}
}
private bool GetMemberAuthenticate(string UID, string PWD)
{
using (OleDbConnection ConnectionString = new OleDbConnection(ConfigurationManager.ConnectionStr ings["ConnectionString"].ConnectionString))
{
bool RetVal=false;
OleDbCommand cmd = new OleDbCommand("select count(*) from tb_admin where (uid=? And Pwd=?)", ConnectionString);
cmd.Parameters.AddWithValue("uid", UID);
cmd.Parameters.AddWithValue("Pwd", PWD);
ConnectionString.Open();
RetVal= Convert.ToBoolean(cmd.ExecuteScalar());
ConnectionString.Close();
return RetVal;
}
}
protected void btn_submit_Click(object sender, EventArgs e)
{
if (GetMemberAuthenticate(txt_uid.Text, txt_pwd.Text))
{
string role = GetMemberRoleByID(txt_uid.Text);
FormsAuthenticationTicket AuthTicket = new FormsAuthenticationTicket(1, txt_uid.Text, DateTime.Now, DateTime.Now.AddHours(1), false, role);
string encryptedTicket = FormsAuthentication.Encrypt(AuthTicket);
HttpCookie AuthCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
Response.Cookies.Add(AuthCookie);
Response.Redirect(FormsAuthentication.GetRedirectU rl(txt_uid.Text, chk_member.Checked));
}
else
{
lbl.Visible = true;
}
}
}
ممنون دوستان