我做了一个登录窗口,输入编号和密码能够转到主窗口。我一运行直接就执行到主窗口了,登录窗口不是第一个弹出来的,请问咋回事?
public Login()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=.\\sqlexpress;Initial Catalog=酒店前台管理系统;Integrated Security=True";
cn.Open();
string check = "select count(*) from 前台登录 where 员工编号='"+ textBox1.Text +"' and 密码='"+ textBox2.Text +"'";
SqlCommand cmd = new SqlCommand(check, cn);
int count = (int)cmd.ExecuteScalar();
if (textBox1.Text==""||textBox2.Text=="")
{
MessageBox.Show("请输入完整信息");
}
else if(count==0)
{
MessageBox.Show("编号或密码错误,请重新输入");
}
else
{
MainForm m = new MainForm();
m.Show();
}
cn.Close();
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public Login()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "server=.\\sqlexpress;Initial Catalog=酒店前台管理系统;Integrated Security=True";
cn.Open();
string check = "select count(*) from 前台登录 where 员工编号='"+ textBox1.Text +"' and 密码='"+ textBox2.Text +"'";
SqlCommand cmd = new SqlCommand(check, cn);
int count = (int)cmd.ExecuteScalar();
if (textBox1.Text==""||textBox2.Text=="")
{
MessageBox.Show("请输入完整信息");
}
else if(count==0)
{
MessageBox.Show("编号或密码错误,请重新输入");
}
else
{
MainForm m = new MainForm();
m.Show();
}
cn.Close();
} private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;namespace WindowsApplication3
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
把Form1()改为你要的窗口的名字
我再给你补充下吧[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());//把这里的Form1改成你的登录窗体的名字
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Application.Run(new Form1());把红色里面换成登录窗口的名字。
比如你的登录窗口是Login。
则修改成
Application.Run(new Login());