|
|
|
จะเอาข้อมูลที่ล็อกอินไปมาโชว์ในหน้าต่อไปได้ยังไงครับ |
|
|
|
|
|
|
|
นี่โค้ดล็อกอิน
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace DataBoss
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string constr = ("host=localhost;user=root;password=123456;");
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("select * from game_data.member where Username='" + txtuser.Text + "' and Password = '" + txtpass.Text + "'; ", con);
MySqlDataReader reader;
con.Open();
reader = cmd.ExecuteReader();
int count = 0;
while (reader.Read())
{
count = count + 1;
}
if (count == 1)
{
Game games = new Game(txtuser.Text);
games.Show();
this.Hide();
}
else if (count > 1)
{
MessageBox.Show("Username/Password ผิดลพลาด");
}
else
{
MessageBox.Show("Username/Password ผิดลพลาด");
con.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
Register reg = new Register();
reg.Show();
}
private void Login_Load(object sender, EventArgs e)
{
groupBox1.Parent = pictureBox1;
groupBox1.BackColor = Color.Transparent;
}
public string sendtext
{
get
{
return txtuser.Text;
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
}
}
โค้ดหน้าที่จะให้โชว์ข้อมูลล็อกอิน เช่น id,username,email
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace DataBoss
{
public partial class Game : Form
{
public Game(String Str_Name)
{
InitializeComponent();
Lname.Text = Str_Name;
}
private void Game_Load(object sender, EventArgs e)
{
string constr = ("host=localhost;user=root;password=123456;");
string query = ("select * from game_data.game_data join game_data.member on (member_id = id_member) ;");
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
string ssName = reader.GetString("Game_Name");
comboBox1.Items.Add(ssName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string constr = ("host=localhost;user=root;password=123456;");
string query = ("select * from game_data.game_data g join game_data.member on (member_id = id_member) where g.Game_Name = '" + comboBox1.Text + "';");
//query = ("select * from game_data.member;");
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
string sLink = reader.GetString("Game_Link");
//string sDate = reader.GetString("Date");
string sName = reader.GetString("Username");
string sEmail = reader.GetString("Email");
textBox1.Text = sLink;
// label1.Text = sDate;
label2.Text = sName;
label1.Text = sEmail;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("ลิ้งเกมส์ผิดพลาด");
}
else
{
Clipboard.SetText(textBox1.Text);
}
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("ลิ้งเกมส์ผิดพลาด");
}
else
{
System.Diagnostics.Process.Start(textBox1.Text);
}
}
private void button3_Click(object sender, EventArgs e)
{
}
private void เพมเกมสToolStripMenuItem_Click(object sender, EventArgs e)
{
AddGames agame = new AddGames(Lname.Text,lblid.Text);
agame.Show();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
}
}
Tag : .NET, VB.NET, C#
|
ประวัติการแก้ไข 2015-05-21 10:47:06
|
|
|
|
|
Date :
2015-05-21 10:46:21 |
By :
meatspin |
View :
728 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
string[] arr = new string[3] { reader["id"].ToString(), reader["username"].ToString(), reader["email"].ToString() };
Game games = new Game(arr);
Code (C#)
public Game(String[] arr)
{
InitializeComponent();
Lname.Text = arr[1];
}
|
|
|
|
|
Date :
2015-05-21 11:36:24 |
By :
ipstarone |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูเรื่องการใช้ตัวแปรแบบ Global ดูครับ
|
|
|
|
|
Date :
2015-05-21 12:00:52 |
By :
fonfire |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|