?? form1.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; //傳遞給控制臺登陸用戶的操作權(quán)限
private bool winClose;
private bool flag;
private bool Rg;
public string name;
public bool getWin //屬性的設(shè)置
{
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 //更改用戶時(shí),若成功,就關(guān)閉主控窗口
{
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();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -