ユーザーがログインする必要があるプログラムがあるため、IDとパスワードがあります。ユーザー ログインの詳細を含むデータベースは、ローカルの .mdf ファイルに保存されます。
ユーザーがログインしている間、プログラムの残りの部分が右上隅に詳細を表示するように設定したいと思います。たとえば、名前やIDなどです。
残念ながら、これを行う方法がわかりません。ブラウジング中に見たのは、実際のシステムログインを使用している人だけでした。これは私が望んでいるものではありません.
ログインフォームのコード:
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 System.Data.SqlClient;
namespace InventoryManager
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void frmLogin_Load(object sender, EventArgs e)
{
this.AcceptButton = btnSubmit;
}
string cs = @"Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|Users.mdf;Integrated Security = True;";
private void btnSubmit_Click(object sender, EventArgs e)
{
if (txtUserID.Text == "" || txtPassword.Text == "")
{
MessageBox.Show("Please enter a User ID and Password");
return;
}
try
{
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("SELECT * FROM tbl_Login WHERE UserID = @userid AND Password = @password", con);
cmd.Parameters.AddWithValue("@userid", txtUserID.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
con.Close();
int count = ds.Tables[0].Rows.Count;
if (count == 1)
{
MessageBox.Show("Login Successful!");
this.Hide();
frmOverview fo = new frmOverview();
fo.Show();
}
else
{
MessageBox.Show("Login Failed");
txtPassword.Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}