Windows窗体应用程序

窗体(Form)是一个窗口或对话框,是存放各种控件(包括标签、文本框、命令按钮等)的容器,可用来向客户显示信息

 一个Windows程序可以包含多个窗体,

登录页面代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

 

using Model;

using BLL;

using System.IO;

 

namespace UI

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void button1_Click(object sender, EventArgs e)

        {

 

            try

            {

                //非空判断

                if (txtname.Text == "" || txtpwd.Text == "")

                {

                    MessageBox.Show("用户信息不完整");

                }

                else

                {

                    //判断是否登录(传递参数)

                    Model.student s = new Model.student();

                    s.account = txtname.Text;

                    s.password = txtpwd.Text;

                    //调用bll完成功能

                    stubll sbll = new stubll();

                    if ((int)sbll.sellog(s) == 1)

                    {

                        MessageBox.Show("登录成功");

 

                        //跳转显示信息

                        Class1.uaccount = txtname.Text;  //记录当前登录账号

                        Class1.upass = txtpwd.Text;

                        showstudent s1 = new showstudent();

                        s1.Show();

                    }

                    else

                    {

                        MessageBox.Show("用户名或密码出错");

                    }

 

 

                }

            }

            catch(Exception  y)

            {

                  //写入文件

                StreamWriter w = new StreamWriter("log.txt", true, Encoding.UTF8);

                w.WriteLine(DateTime.Now + "Message:" + y.Message);

                w.Close();

            }

            

            

          

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            label4.Text = DateTime.Now.ToString("yyyy年MM月dd日");

        }

    }

}

 

 

显示信息代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using BLL;

using Model;

 

namespace UI

{

    public partial class showstudent : Form

    {

        public showstudent()

        {

            InitializeComponent();

        }

 

        private void showstudent_Load(object sender, EventArgs e)

        {

            //显示日期

            label13.Text = "登录日期:" + DateTime.Now.ToString("yyyy年MM月dd");

 

            //查询

            Model.student s = new Model.student();

            s.account = Class1.uaccount;

            s.password = Class1.upass;

 

            stubll sbll=new stubll();

            

            label8.Text = sbll.selstu (s).Rows [0]["name"].ToString();

            label9 .Text =sbll.selstu (s).Rows [0]["sex"].ToString();

            label10 .Text =sbll.selstu (s).Rows [0]["hiredate"].ToString();

            label11 .Text =sbll.selstu (s).Rows [0]["integral"].ToString();

            label12 .Text =sbll.selstu (s).Rows [0]["content"].ToString();

 

 

        }

 

        private void groupBox1_Enter(object sender, EventArgs e)

        {

 

        }

    }

}

 

DAl里面

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Model;

using System.Data;

using System.IO;

using System.Threading;

 

 

namespace DAL

{

  

    public class studal

    {

 

        /// <summary>

        /// 判断是否登录

        /// </summary>

        /// 

        public Object  sellog(Model.student  s )

        {

            try

            {

               string str = string.Format ("select COUNT(*) from student where account='{0}' and password='{1}'",s.account ,s.password );

               return   DBhelper.Scalar(str);

 

            }

            catch(Exception  t )

            {

                throw t;

                yshow(t);

 

               

            }

 

        }

 

        private static void yshow(Exception t)

        {

            //写入文件

            StreamWriter w = new StreamWriter("log.txt", true, Encoding.UTF8);

            w.WriteLine(DateTime.Now + "Message:" + t.Message);

            w.Close();

            

        }

 

 

        /// <summary>

        /// 查询信息

        /// </summary>

        /// 

 

        public DataTable  selstu(Model.student  s)

        {

            string str =string.Format ( "select * from student where account='{0}' and password='{1}'",s.account,s.password  );

            return  DBhelper.GetTable(str);

 

        }

    }

}

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值