主窗体:frmMain,登录窗体:frmLogin
Program.cs代码:
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- frmLogin f = new frmLogin();
- f.ShowDialog();
- if (f.DialogResult == DialogResult.OK)
- {
- Application.Run(new frmMain());
- }
- }
- }
登录窗体代码:
- public partial class frmLogin : Form
- {
- public frmLogin()
- {
- InitializeComponent();
- }
- private void btnOK_Click(object sender, EventArgs e)
- {
- string sql="select count(*) from t_User where zh='"+txtZH.Text.Trim()+"' and mm='"+txtMM.Text.Trim()+"'";
- int n = (int)DbHelper.executeScalar(sql);
- if (n != 0)
- {
- DialogResult = DialogResult.OK;
- this.Close();
- this.Dispose();
- }
- else
- {
- MessageBox.Show("账号或密码错误!","提示:");
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- this.Dispose();
- }
- }