You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
414 lines
15 KiB
C#
414 lines
15 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using CommonFunc;
|
|
using MySql.Data.MySqlClient;
|
|
using XGL.Models;
|
|
using XGL.Models.Model;
|
|
using CommonFunc.Tools;
|
|
using System.Linq;
|
|
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 登录
|
|
/// </summary>
|
|
/// <param name="usercode"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public bool Login(string usercode, string pwd)
|
|
{
|
|
string sql = $"select * from sys_user WHERE user_name='{usercode}'";
|
|
DataTable dt = Utils.cloudDBHelper.getDataSet(sql).Tables[0];
|
|
bool issuccess = false;
|
|
|
|
var lst = Utils.ToDataList<sys_user>(dt);
|
|
if (lst.Count > 0)
|
|
{
|
|
var info = lst.FirstOrDefault();
|
|
issuccess = Utils.VerifyPassword(pwd, info.password);
|
|
LoginUser.UserId = info.user_id;
|
|
LoginUser.UserCode = info.user_name;
|
|
LoginUser.UserName = info.nick_name;
|
|
//待补充班组班次
|
|
}
|
|
return issuccess;//lst.Count > 0 ? true : false;
|
|
}
|
|
|
|
|
|
|
|
//public List<base_user> GetUsersLst(int page, int pageSize, string phone, string name)
|
|
//{
|
|
// string where = " 1=1 ";
|
|
// if (!string.IsNullOrEmpty(phone))
|
|
// {
|
|
// where += $" and User_Telephone like '%{phone}%'";
|
|
// }
|
|
// if (!string.IsNullOrEmpty(name))
|
|
// {
|
|
// where += $" and User_Name like '%{name}%'";
|
|
// }
|
|
// int pz = page * pageSize;
|
|
// string sql = $@"select * from base_user where {where} ORDER BY Create_Time DESC limit {pz},{pageSize}";
|
|
// DataTable dt = MySqlHelper.GetDataTable(sql);
|
|
// var lst = Utils.ToDataList<base_user>(dt);
|
|
// return lst;
|
|
//}
|
|
|
|
//public DataTable GetUsersExcelLst(string phone, string name)
|
|
//{
|
|
// string where = " Active='1' ";
|
|
// if (!string.IsNullOrEmpty(phone))
|
|
// {
|
|
// where += $" and User_Telephone like '%{phone}%'";
|
|
// }
|
|
// if (!string.IsNullOrEmpty(name))
|
|
// {
|
|
// where += $" and User_Name like '%{name}%'";
|
|
// }
|
|
|
|
// string sql = $@"select (@i:=@i+1) as xuhao,User_Code,User_Name,User_Telephone,Create_Time from base_user,(select @i:=0) as it where {where} ORDER BY Create_Time DESC ";
|
|
// DataTable dt = MySqlHelper.GetDataTable(sql);
|
|
|
|
// return dt;
|
|
//}
|
|
|
|
//public base_user GetUserInfo(int id)
|
|
//{
|
|
|
|
// string sql = $@"select * from base_user where id={id}";
|
|
// DataTable dt = MySqlHelper.GetDataTable(sql);
|
|
// var lst = Utils.ToDataList<base_user>(dt);
|
|
// if (lst != null && lst.Count > 0)
|
|
// {
|
|
// var info = lst.FirstOrDefault();
|
|
// return info;
|
|
// }
|
|
// return null;
|
|
//}
|
|
|
|
//public bool InsertUserExcel(base_user user)
|
|
//{
|
|
// try
|
|
// {
|
|
// string selectuser = $"select * from base_user where User_Code='{user.User_Code}' and Active='1'";
|
|
// DataTable dt = MySqlHelper.GetDataTable(selectuser);
|
|
// if (dt != null && dt.Rows.Count > 0)
|
|
// {
|
|
// return false;
|
|
// }
|
|
// string sql = $@"INSERT INTO base_user( Production_Line_Code, Production_Line_Name, User_Code, User_Name, User_PWD, User_Telephone, Active, Create_User, Create_Time)
|
|
// VALUES ('{user.Production_Line_Code}', '{user.Production_Line_Name}', '{user.User_Code}',
|
|
// '{user.User_Name}', '{user.User_PWD}', '{user.User_Telephone}', {user.Active}, '{user.Create_User}', '{user.Create_Time}');Select @@Identity";
|
|
// int row = MySqlHelper.InsertReturnId(sql).ToInt();
|
|
|
|
// return true;
|
|
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// Log.WriteLog(LogFile.Error, "添加用户异常:" + ex.Message);
|
|
// return false;
|
|
// }
|
|
|
|
//}
|
|
|
|
}
|
|
}
|
|
|