Exemple #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text.Trim() == "")
                {
                    MessageBox.Show("请输入用户名!", "错误提示");
                    textBox1.Focus();
                }
                else if (textBox2.Text.Trim() == "")
                {
                    MessageBox.Show("请输入密码!", "错误提示");
                    textBox2.Focus();
                }
                else
                {
                    //账号 密码
                    string user = textBox1.Text;
                    string pwd  = textBox2.Text;

                    //连接数据库
                    string         counstr = "Server=.;user=sa;pwd=15570104841;database=xscjglxt";
                    SqlConnection  mycon   = new SqlConnection(counstr);
                    string         sql1    = "Select * from 学生信息表";
                    SqlDataAdapter da      = new SqlDataAdapter(sql1, mycon);
                    DataSet        ds      = new DataSet();
                    da.Fill(ds, "学生信息表");

                    mycon.Open();
                    //查询是否存在这个账户
                    string     sql   = string.Format("Select count(用户名) from 用户信息表 where 用户名='{0}' and 密码='{1}'", user, pwd);
                    SqlCommand mycom = new SqlCommand(sql, mycon);
                    //是否存在第一个值!
                    int i = Convert.ToInt32(mycom.ExecuteScalar());
                    //大于零则是存在
                    if (i > 0)
                    {
                        MessageBox.Show("登录成功!", "登录提示");
                        flmlogin fl = new flmlogin();
                        fl.Show();
                        fl.dataGridView1.DataSource = ds;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("登录失败!", "错误提示");
                        textBox1.Text = "";
                        textBox2.Text = "";
                        textBox1.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
            }
        }
Exemple #2
0
        private void flmlogin_Load(object sender, EventArgs e)
        {
            this.Text           = "学生成绩管理系统";
            this.IsMdiContainer = true;
            //登录界面
            flmlogin flom1 = new flmlogin();

            flom1.TopMost = true;
            flom1.Show();
            toolStripStatusLabel1.Text = "欢迎使用本系统......";
            toolStripStatusLabel2.Text = "";
            toolStripStatusLabel3.Text = DateTime.Now.ToString();
        }