|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using CommonFunc;
|
|
|
|
|
|
using MySql.Data.MySqlClient;
|
|
|
|
|
|
using XGL.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace XGL.Data
|
|
|
|
|
|
{
|
|
|
|
|
|
//user
|
|
|
|
|
|
public class userDB : IDisposable
|
|
|
|
|
|
{
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dispose(true);
|
|
|
|
|
|
GC.SuppressFinalize(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!disposing)
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Exists(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("select count(1) from user");
|
|
|
|
|
|
strSql.Append(" where ");
|
|
|
|
|
|
strSql.Append(" id = @id ");
|
|
|
|
|
|
MySqlParameter[] parameters = {
|
|
|
|
|
|
new MySqlParameter("@id", MySqlDbType.Int32)
|
|
|
|
|
|
};
|
|
|
|
|
|
parameters[0].Value = id;
|
|
|
|
|
|
|
|
|
|
|
|
return DbHelperSQLServer.Exists(strSql.ToString(), parameters);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 增加一条数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int Add(XGL.Models.user model)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("insert into user(");
|
|
|
|
|
|
strSql.Append("userno,username,birthdate,infactorydate,teamid,isdeleted,password,phone,email,userkey");
|
|
|
|
|
|
strSql.Append(") values (");
|
|
|
|
|
|
strSql.Append("@userno,@username,@birthdate,@infactorydate,@teamid,@isdeleted,@password,@phone,@email,@userkey");
|
|
|
|
|
|
strSql.Append(") ");
|
|
|
|
|
|
strSql.Append(";select @@IDENTITY");
|
|
|
|
|
|
MySqlParameter[] parameters = {
|
|
|
|
|
|
new MySqlParameter("@userno", MySqlDbType.VarChar,20) ,
|
|
|
|
|
|
new MySqlParameter("@username", MySqlDbType.VarChar,40) ,
|
|
|
|
|
|
new MySqlParameter("@birthdate", MySqlDbType.VarChar,20) ,
|
|
|
|
|
|
new MySqlParameter("@infactorydate", MySqlDbType.VarChar,20) ,
|
|
|
|
|
|
new MySqlParameter("@teamid", MySqlDbType.Int32,11) ,
|
|
|
|
|
|
new MySqlParameter("@isdeleted", MySqlDbType.VarChar,1) ,
|
|
|
|
|
|
new MySqlParameter("@password", MySqlDbType.VarChar,50) ,
|
|
|
|
|
|
new MySqlParameter("@phone", MySqlDbType.VarChar,50) ,
|
|
|
|
|
|
new MySqlParameter("@email", MySqlDbType.VarChar,50) ,
|
|
|
|
|
|
new MySqlParameter("@userkey", MySqlDbType.VarChar,200)
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
parameters[0].Value = model.userno;
|
|
|
|
|
|
parameters[1].Value = model.username;
|
|
|
|
|
|
parameters[2].Value = model.birthdate;
|
|
|
|
|
|
parameters[3].Value = model.infactorydate;
|
|
|
|
|
|
parameters[4].Value = model.teamid;
|
|
|
|
|
|
parameters[5].Value = model.isdeleted;
|
|
|
|
|
|
parameters[6].Value = model.password;
|
|
|
|
|
|
parameters[7].Value = model.phone;
|
|
|
|
|
|
parameters[8].Value = model.email;
|
|
|
|
|
|
parameters[9].Value = model.userkey;
|
|
|
|
|
|
|
|
|
|
|
|
object obj = DbHelperSQLServer.ExecuteScalar(strSql.ToString(), parameters);
|
|
|
|
|
|
if (obj == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return Convert.ToInt32(obj);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新一条数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool Update(XGL.Models.user model)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("update user set ");
|
|
|
|
|
|
|
|
|
|
|
|
strSql.Append(" userno = @userno , ");
|
|
|
|
|
|
strSql.Append(" username = @username , ");
|
|
|
|
|
|
strSql.Append(" birthdate = @birthdate , ");
|
|
|
|
|
|
strSql.Append(" infactorydate = @infactorydate , ");
|
|
|
|
|
|
strSql.Append(" teamid = @teamid , ");
|
|
|
|
|
|
strSql.Append(" isdeleted = @isdeleted , ");
|
|
|
|
|
|
strSql.Append(" password = @password , ");
|
|
|
|
|
|
strSql.Append(" phone = @phone , ");
|
|
|
|
|
|
strSql.Append(" email = @email , ");
|
|
|
|
|
|
strSql.Append(" userkey = @userkey ");
|
|
|
|
|
|
strSql.Append(" where id=@id ");
|
|
|
|
|
|
|
|
|
|
|
|
MySqlParameter[] parameters = {
|
|
|
|
|
|
new MySqlParameter("@id", MySqlDbType.Int32,11) ,
|
|
|
|
|
|
new MySqlParameter("@userno", MySqlDbType.VarChar,20) ,
|
|
|
|
|
|
new MySqlParameter("@username", MySqlDbType.VarChar,40) ,
|
|
|
|
|
|
new MySqlParameter("@birthdate", MySqlDbType.VarChar,20) ,
|
|
|
|
|
|
new MySqlParameter("@infactorydate", MySqlDbType.VarChar,20) ,
|
|
|
|
|
|
new MySqlParameter("@teamid", MySqlDbType.Int32,11) ,
|
|
|
|
|
|
new MySqlParameter("@isdeleted", MySqlDbType.VarChar,1) ,
|
|
|
|
|
|
new MySqlParameter("@password", MySqlDbType.VarChar,50) ,
|
|
|
|
|
|
new MySqlParameter("@phone", MySqlDbType.VarChar,50) ,
|
|
|
|
|
|
new MySqlParameter("@email", MySqlDbType.VarChar,50) ,
|
|
|
|
|
|
new MySqlParameter("@userkey", MySqlDbType.VarChar,200)
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
parameters[0].Value = model.id;
|
|
|
|
|
|
parameters[1].Value = model.userno;
|
|
|
|
|
|
parameters[2].Value = model.username;
|
|
|
|
|
|
parameters[3].Value = model.birthdate;
|
|
|
|
|
|
parameters[4].Value = model.infactorydate;
|
|
|
|
|
|
parameters[5].Value = model.teamid;
|
|
|
|
|
|
parameters[6].Value = model.isdeleted;
|
|
|
|
|
|
parameters[7].Value = model.password;
|
|
|
|
|
|
parameters[8].Value = model.phone;
|
|
|
|
|
|
parameters[9].Value = model.email;
|
|
|
|
|
|
parameters[10].Value = model.userkey;
|
|
|
|
|
|
int rows = DbHelperSQLServer.ExecuteNonQuery(strSql.ToString(), parameters);
|
|
|
|
|
|
if (rows > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除一条数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool Delete(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("delete from user ");
|
|
|
|
|
|
strSql.Append(" where id=@id");
|
|
|
|
|
|
MySqlParameter[] parameters = {
|
|
|
|
|
|
new MySqlParameter("@id", MySqlDbType.Int32)
|
|
|
|
|
|
};
|
|
|
|
|
|
parameters[0].Value = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int rows = DbHelperSQLServer.ExecuteNonQuery(strSql.ToString(), parameters);
|
|
|
|
|
|
if (rows > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 批量删除一批数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool DeleteList(string idlist)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("delete from user ");
|
|
|
|
|
|
strSql.Append(" where ID in (" + idlist + ") ");
|
|
|
|
|
|
int rows = DbHelperSQLServer.ExecuteNonQuery(strSql.ToString());
|
|
|
|
|
|
if (rows > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 得到一个对象实体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public XGL.Models.user GetModel(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("select id, userno, username, birthdate, infactorydate, teamid, isdeleted, password, phone, email, userkey ");
|
|
|
|
|
|
strSql.Append(" from user ");
|
|
|
|
|
|
strSql.Append(" where id=@id");
|
|
|
|
|
|
MySqlParameter[] parameters = {
|
|
|
|
|
|
new MySqlParameter("@id", MySqlDbType.Int32)
|
|
|
|
|
|
};
|
|
|
|
|
|
parameters[0].Value = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XGL.Models.user model = new XGL.Models.user();
|
|
|
|
|
|
DataSet ds = DbHelperSQLServer.Query(strSql.ToString(), parameters);
|
|
|
|
|
|
|
|
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
model.userno = ds.Tables[0].Rows[0]["userno"].ToString();
|
|
|
|
|
|
model.username = ds.Tables[0].Rows[0]["username"].ToString();
|
|
|
|
|
|
model.birthdate = ds.Tables[0].Rows[0]["birthdate"].ToString();
|
|
|
|
|
|
model.infactorydate = ds.Tables[0].Rows[0]["infactorydate"].ToString();
|
|
|
|
|
|
if (ds.Tables[0].Rows[0]["teamid"].ToString() != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
model.teamid = int.Parse(ds.Tables[0].Rows[0]["teamid"].ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
model.isdeleted = ds.Tables[0].Rows[0]["isdeleted"].ToString();
|
|
|
|
|
|
model.password = ds.Tables[0].Rows[0]["password"].ToString();
|
|
|
|
|
|
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
|
|
|
|
|
|
model.email = ds.Tables[0].Rows[0]["email"].ToString();
|
|
|
|
|
|
model.userkey = ds.Tables[0].Rows[0]["userkey"].ToString();
|
|
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获得数据列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DataSet GetList(string strWhere)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("select * ");
|
|
|
|
|
|
strSql.Append(" FROM user ");
|
|
|
|
|
|
if (strWhere.Trim() != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
strSql.Append(" where " + strWhere);
|
|
|
|
|
|
}
|
|
|
|
|
|
return DbHelperSQLServer.Query(strSql.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获得数据列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<user> GetModelList(string strWhere)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<user> Results = new List<user>();
|
|
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
|
|
|
strSql.Append("select * ");
|
|
|
|
|
|
strSql.Append(" FROM user ");
|
|
|
|
|
|
if (strWhere.Trim() != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
strSql.Append(" where " + strWhere);
|
|
|
|
|
|
}
|
|
|
|
|
|
DataSet ds = DbHelperSQLServer.Query(strSql.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (user model in ds.Tables[0].Rows)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
model.userno = ds.Tables[0].Rows[0]["userno"].ToString();
|
|
|
|
|
|
model.username = ds.Tables[0].Rows[0]["username"].ToString();
|
|
|
|
|
|
model.birthdate = ds.Tables[0].Rows[0]["birthdate"].ToString();
|
|
|
|
|
|
model.infactorydate = ds.Tables[0].Rows[0]["infactorydate"].ToString();
|
|
|
|
|
|
if (ds.Tables[0].Rows[0]["teamid"].ToString() != "")
|
|
|
|
|
|
{
|
|
|
|
|
|
model.teamid = int.Parse(ds.Tables[0].Rows[0]["teamid"].ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
model.isdeleted = ds.Tables[0].Rows[0]["isdeleted"].ToString()=="1"?"有效":"无效";
|
|
|
|
|
|
model.password = ds.Tables[0].Rows[0]["password"].ToString();
|
|
|
|
|
|
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
|
|
|
|
|
|
model.email = ds.Tables[0].Rows[0]["email"].ToString();
|
|
|
|
|
|
model.userkey = ds.Tables[0].Rows[0]["userkey"].ToString();
|
|
|
|
|
|
Results.Add(model);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return Results;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|