⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 由于本系统为一个公司销售管理系统
💻 CS
字号:
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
    public partial class Login : Form
    {
        private bool winOpen;   //传递消息给控制台
        public string limit;   //传递给控制台登陆用户的操作权限
        private bool winClose;
        private bool flag;
        private bool Rg;
        public string name;

        public bool getWin    //属性的设置
        {
            get
            {
                return winOpen;
            }
        }
        public bool getFlag
        {
            get
            {
                return flag;
            }
        }
        public bool getRg
        {
            get
            {
                return Rg;
            }
        }

        public string getlimit
        {
            get
            {
                return limit;
            }
        }
      
        public string getname
        {
            get
            {
                return name;
            }
        }
        public bool closeWin       //更改用户时,若成功,就关闭主控窗口
        {
            get
            {
                return winClose;
            }
        }

        public Login()
        {
            InitializeComponent();
            limit = "";
            winOpen = false;
            winClose = false;
            Rg = false;
            flag = false;
        }
        DataSet ds = new DataSet();
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text =="")
                MessageBox.Show("Username can not null!");
            else  if ( textBox2.Text =="")
                MessageBox.Show("Password can not null!");
           else 
            {
              SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
              string select = "select * from users where username='" + textBox1.Text + "'and password ='" + textBox2.Text + "'";
              SqlDataAdapter q0 = new SqlDataAdapter(select, conn);
              q0.Fill(ds, "users");

              try
              {
                  limit = ds.Tables["users"].Rows[0]["limit"].ToString();
               
              }
              catch (IndexOutOfRangeException)
              {
                  MessageBox.Show("Username do not exist or password is error!");
                  textBox2.Text = "";
                  textBox1.Text = "";
                  return;
              }
              winOpen = true;
              winClose = true;
              name = textBox1.Text;
              this.Close();

          }
        }

        private void button2_Click(object sender, EventArgs e)
        {

            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            flag = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(flag==true)
                try
                {
                    SqlConnection conn = new SqlConnection("server=;database=ll;uid=sa;pwd=;");
                    string select1 = "create table users (username char(10) PRIMARY   KEY,password char(10) not null,limit char(1) default 1 CHECK (limit in (1,2)) ,phone char(15),sex char(10) CHECK (users.sex in ('male','female')))";
                    string select2 = "create table sell (wname char(15) references storage(wname) ,cname varchar(10)  ,price float(10) not null,sdate datetime ,uname char(10) not null,foreign key(uname) references users(username),company varchar(30),scount int,sumprice int )";
                    string select3 = "create table storage ( wname char(15) PRIMARY   KEY ,price float not null,pdate datetime,count int)";
                    SqlDataAdapter q1 = new SqlDataAdapter(select1, conn);
                    SqlDataAdapter q3 = new SqlDataAdapter(select3, conn);
                    SqlDataAdapter q2 = new SqlDataAdapter(select2, conn);
                   
                    q1.Fill(ds, "users");
                    q3.Fill(ds, "storage");
                    q2.Fill(ds, "sell");
                    
                }
                catch (IndexOutOfRangeException)
                {
                    MessageBox.Show("Can not connect the database server or the tables have existed!");
                }
             Rg = true;
            this.Close();
        }

            

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -