private void btnLogin_Click(object sender, EventArgs e) { SqlConnection myConnection = default(SqlConnection); connection NewConnection = new connection(); NewConnection.Connection_Today(); connection.myConnection.Open(); dt = new DataTable(); SqlDataAdapter Adapter = default(SqlDataAdapter); SqlCommand myCommand = connection.myConnection.CreateCommand(); myCommand.CommandText = "SELECT * FROM member WHERE username = '" + txtuser.Text + "' and password = '" + txtpass.Text + "' "; myCommand.CommandType = CommandType.Text; Adapter = new SqlDataAdapter(myCommand); Adapter.Fill(dt); connection.myConnection.Close(); string user = ""; string pass = ""; string uread = ""; string uwrite = ""; string uedit = ""; string udel = ""; string role = ""; if (dt.Rows.Count > 0) { user = dt.Rows[0]["username"].ToString().Trim(); pass = dt.Rows[0]["password"].ToString().Trim(); uread = dt.Rows[0]["viewdata"].ToString().Trim(); uwrite = dt.Rows[0]["write"].ToString().Trim(); uedit = dt.Rows[0]["edit"].ToString().Trim(); udel = dt.Rows[0]["del"].ToString().Trim(); } if (user != "" && pass != "") { if (uread == "Y") { if (uwrite == "Y") { if (uedit == "Y") { if (udel == "Y") { role = "all"; } else { role = "third"; } } else { role = "second"; } } else { role = "first"; } } else { Application.Exit(); } //MessageBox.Show(role); // มองเห็นค่า แต่ส่งไปอีกฟอร์มไม่เห็น this.Hide(); Customer d = new Customer(); d.Show(); roles pre = new roles(); pre.setRoles(role); } else { MessageBox.Show("Wrong username or password!!"); } session usr = new session(); usr.setUser(this.txtuser.Text); language langs = new language(); langs.setLang(this.listLanguage.SelectedValue.ToString()); }
class roles { private static string strRoles = ""; public void setRoles(String authen) { strRoles = authen; } public static string getRoles() { return strRoles; } }
public Customer() { InitializeComponent(); } string user = session.getUser(); string premit = roles.getRoles(); private void Customer_Load(object sender, EventArgs e) { MessageBox.Show(premit); if (premit == "third") { btnDelete.Enabled = false; } System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); listSearch.Items.Add("custcode"); listSearch.Items.Add("custgroupcode"); listSearch.Items.Add("taxid"); listSearch.SelectedIndex = 0; BindDataGrid(); }
Quote:session usr = new session();
namespace test01 { class session { private static string strUser = ""; public void setUser(String user) { strUser = user; } public static string getUser() { return strUser; } } }
Customer d = new Customer(); d._StrRoles = role; d.Show();
string StrRoles = ""; public string _StrRoles { get { return StrRoles; } set { StrRoles = value; } }
private void btnLogin_Click(object sender, EventArgs e) { SqlConnection myConnection = default(SqlConnection); connection NewConnection = new connection(); NewConnection.Connection_Today(); connection.myConnection.Open(); dt = new DataTable(); SqlDataAdapter Adapter = default(SqlDataAdapter); SqlCommand myCommand = connection.myConnection.CreateCommand(); myCommand.CommandText = "SELECT * FROM member WHERE username = '" + txtuser.Text + "' and password = '" + txtpass.Text + "' "; myCommand.CommandType = CommandType.Text; Adapter = new SqlDataAdapter(myCommand); Adapter.Fill(dt); connection.myConnection.Close(); string user = ""; string pass = ""; string uread = ""; string uwrite = ""; string uedit = ""; string udel = ""; string role = ""; if (dt.Rows.Count > 0) { user = dt.Rows[0]["username"].ToString().Trim(); pass = dt.Rows[0]["password"].ToString().Trim(); uread = dt.Rows[0]["viewdata"].ToString().Trim(); uwrite = dt.Rows[0]["write"].ToString().Trim(); uedit = dt.Rows[0]["edit"].ToString().Trim(); udel = dt.Rows[0]["del"].ToString().Trim(); } if (user != "" && pass != "") { if (uread == "Y") { if (uwrite == "Y") { if (uedit == "Y") { if (udel == "Y") { role = "all"; } else { role = "third"; } } else { role = "second"; } } else { role = "first"; } } else { Application.Exit(); } //MessageBox.Show(role); // มองเห็นค่า แต่ส่งไปอีกฟอร์มไม่เห็น session usr = new session(); usr.setUser(this.txtuser.Text); language langs = new language(); langs.setLang(this.listLanguage.SelectedValue.ToString()); roles pre = new roles(); pre.setRoles(role); this.Hide(); Customer d = new Customer(); d.Show(); } else { MessageBox.Show("Wrong username or password!!"); } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง