网站开发人员 怎么保存,上网行为管理系统,找工作下载什么软件,嘉定集团网站建设City城市表#xff0c;id ,name,password,address,phone; 1.新建一个windows窗体应用程序#xff0c;CitySys 2.文件–》添加–》新建项目–》类库#xff08;CitySysModel#xff09;–》重命名class1.cs的类#xff08;CityModel#xff09;。 3.根据数据表里面的字段id ,name,password,address,phone; 1.新建一个windows窗体应用程序CitySys 2.文件–》添加–》新建项目–》类库CitySysModel–》重命名class1.cs的类CityModel。 3.根据数据表里面的字段在Model里面创建字段。proptab tab.
egpublic int Id{get;set;}public string Name{get;set;}public string Password{get;set;}public string Address{get;set;}public string Phone{get;set;}4.创建DLL层CitySysDLL。–重命名Class1.cs,CityDLL。 5.创建BLL层CitySysBLL。–》重命名Class1.cs,CityBLL。 6.添加引用表示层引用–》Model层和BLL层 BLL层引用DLL层和MOdel层 DLL层引用Model层 7.去DLL层里面写两个方法登陆[Login]和AddCity[添加]。 8.DLL层里面的代码
public string constr 数据库连接字符串;
//登陆
public bool Login(string name,string password){string sql select * from city where name name and password password;SqlParameter [] param new Sqlparameter[]{new Sqlparameter(name,name),new SqlParameter(password,password)};using(SqlConnection conn new SqlConnection(constr)){SqlCommand cmd new SqlCommand (sql,conn);cmd.Parameters.AddRange(param);conn.Open();SqlDataReader dr cmd.ExecuteReader();if(dr.Read()){dr.Close();conn.Close();return true;}else{dr.Close();conn.Close();return false;}}
}
//添加的方法
public int AddCity(City city ){string sqlinsert into city values(name,password,address,phone);SqlParameter [] param new Sqlparameter[]{
new Sqlparameter(name,city.name),
new SqlParameter(password,city.password),
new SqlParameter(address,city.address),
new SqlParameter(phone,city.phone)};using(SqlConnection conn new SqlConnection(constr)){SqlCommand cmd new SqlCommand(sql,conn);cmd.Parameters.AddRange(param );conn.Open();return cmd.ExecuteNonQuery();}
}9.写BLL层。给BLL层里面写登陆的方法和添加的方法
public CityDLL cdll new CityDLL();
//登陆
public bool Login(string name ,string password){return cdll.Login(name,password);
}
//添加
public int AddCity(City city){return cdll.AddCity(city);
}10.开始在默认的窗体里面拉几个lable和button label 欢迎进入某某系统 lable2 名称 textbox Name lable3 密码 textbox Password button1 登陆 button2 取消 11.双击登陆进去。写登陆的方法
public CityBLL cbll new CityBLL();//获取值
string name this.Name.Text;
string password this.Password.Text;
if(cbll.Login(name,password)){MessageBox.Show(登陆成功);FrmMain fm new FrmMain();fm.Show();this.Hide();
} else{MessageBox.Show(登陆失败);
}12.创建一个主窗体右击–》添加–》windows窗体–》FrmMain.–》拉四个Button分别是添加信息查询信息修改信息删除信息 13.双击添加信息进去写代码 //打开添加的窗体 addCity ac new addcity(); ac.Show(); this.Hide(); 14.拉一个添加的窗体。双击添加按钮进去写代码
//获取值City city new City();city.Name this.name.Text;city.Password this.Password.Text;city.Address this.Address.Text;city.Phone this.Phone.Text;//调用bll里面添加方法int rel cbll.AddCity(city);if(rel0){MessageBox.Show(添加成功);}else{MessageBox.Show(添加失败);}