1、用户导入;
2、用户角色支持多个; 3、单位资质;
This commit is contained in:
@@ -6,6 +6,8 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web.UI;
|
||||
using BLL;
|
||||
using FineUIPro.Web.HSSE.PostTraining;
|
||||
using Model;
|
||||
|
||||
namespace FineUIPro.Web.SysManage
|
||||
{
|
||||
@@ -22,10 +24,17 @@ namespace FineUIPro.Web.SysManage
|
||||
/// </summary>
|
||||
public static List<Model.View_Sys_User> userViews = new List<Model.View_Sys_User>();
|
||||
|
||||
///// <summary>
|
||||
///// 错误集合
|
||||
///// </summary>
|
||||
//public static string errorInfos = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 错误集合
|
||||
/// </summary>
|
||||
public static string errorInfos = string.Empty;
|
||||
public static List<Model.ErrorInfo> errorInfos = new List<Model.ErrorInfo>();
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 加载页面
|
||||
@@ -44,7 +53,11 @@ namespace FineUIPro.Web.SysManage
|
||||
{
|
||||
userViews.Clear();
|
||||
}
|
||||
errorInfos = string.Empty;
|
||||
if (errorInfos != null)
|
||||
{
|
||||
errorInfos.Clear();
|
||||
}
|
||||
//errorInfos = string.Empty;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -74,10 +87,14 @@ namespace FineUIPro.Web.SysManage
|
||||
{
|
||||
userViews.Clear();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(errorInfos))
|
||||
if (errorInfos != null)
|
||||
{
|
||||
errorInfos = string.Empty;
|
||||
errorInfos.Clear();
|
||||
}
|
||||
//if (!string.IsNullOrWhiteSpace(errorInfos))
|
||||
//{
|
||||
// errorInfos = string.Empty;
|
||||
//}
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initFullPath = rootPath + initPath;
|
||||
if (!Directory.Exists(initFullPath))
|
||||
@@ -159,6 +176,7 @@ namespace FineUIPro.Web.SysManage
|
||||
ir = pds.Rows.Count;
|
||||
if (pds != null && ir > 0)
|
||||
{
|
||||
var users = from x in Funs.DB.View_Sys_User select x;
|
||||
var units = from x in Funs.DB.Base_Unit select x;
|
||||
var roles = from x in Funs.DB.Sys_Role select x;
|
||||
var departs = from x in Funs.DB.Base_Depart select x;
|
||||
@@ -183,22 +201,44 @@ namespace FineUIPro.Web.SysManage
|
||||
ViceCNProfessionalName = pds.Rows[i][11].ToString().Trim()
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(newSysUser.UserName))
|
||||
if (string.IsNullOrWhiteSpace(newSysUser.UserCode))
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "人员姓名" + "," + "此项为必填项!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "员工编号", Reason = "此项为必填项!" });
|
||||
}
|
||||
if (string.IsNullOrEmpty(newSysUser.Account))
|
||||
else
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "登录账号" + "," + "此项为必填项!" + "|";
|
||||
//判断人员编号是否存在
|
||||
bool isexist = users.Where(x => x.UserCode == newSysUser.UserCode).Any();
|
||||
if (isexist)
|
||||
{
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "员工编号", Reason = $"已存在编号为[{newSysUser.UserCode}]的人员!" });
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(newSysUser.IdentityCard))
|
||||
{
|
||||
//判断人员编号是否存在
|
||||
bool isexist = users.Where(x => x.IdentityCard == newSysUser.IdentityCard).Any();
|
||||
if (isexist)
|
||||
{
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "身份证号", Reason = $"已存在身份证号为[{newSysUser.IdentityCard}]的人员!" });
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(newSysUser.UserName))
|
||||
{
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "人员姓名", Reason = "此项为必填项!" });
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(newSysUser.Account))
|
||||
{
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "登录账号", Reason = "此项为必填项!" });
|
||||
}
|
||||
|
||||
string unitName = newSysUser.UnitName;
|
||||
if (!string.IsNullOrEmpty(unitName))
|
||||
if (!string.IsNullOrWhiteSpace(unitName))
|
||||
{
|
||||
var unit = units.FirstOrDefault(e => e.UnitName == unitName);
|
||||
if (unit == null)
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "单位" + "," + "[" + unitName + "]不在单位表中!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "单位", Reason = $"[{unitName}]不在单位表中!" });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -208,52 +248,78 @@ namespace FineUIPro.Web.SysManage
|
||||
}
|
||||
else
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "单位" + "," + "此项为必填项!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "单位", Reason = "此项为必填项!" });
|
||||
}
|
||||
|
||||
string departName = newSysUser.DepartName;
|
||||
if (!string.IsNullOrEmpty(departName))
|
||||
if (!string.IsNullOrWhiteSpace(departName))
|
||||
{
|
||||
var depart = departs.FirstOrDefault(e => e.DepartName == departName);
|
||||
if (depart == null)
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "部门" + "," + "[" + departName + "]不在部门表中!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "部门", Reason = $"[{departName}]不在部门表中!" });
|
||||
}
|
||||
else
|
||||
{
|
||||
newSysUser.DepartId = depart.DepartId;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "部门" + "," + "此项为必填项!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "部门", Reason = "此项为必填项!" });
|
||||
}
|
||||
|
||||
string roleName = newSysUser.RoleName;
|
||||
var role = roles.FirstOrDefault(e => e.RoleName == roleName);
|
||||
if (role == null)
|
||||
string roleIds = string.Empty;
|
||||
string roleNames = string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(roleName))
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "角色" + "," + "[" + roleName + "]错误!" + "|";
|
||||
}
|
||||
else
|
||||
{
|
||||
newSysUser.RoleId = role.RoleId;
|
||||
newSysUser.RoleName = role.RoleName;
|
||||
var roleNameList = roleName.Split(',');
|
||||
string errRoleName = string.Empty;
|
||||
foreach (var rol in roleNameList)
|
||||
{
|
||||
var role = roles.FirstOrDefault(e => e.RoleName == rol);
|
||||
if (role == null)
|
||||
{
|
||||
errRoleName = !string.IsNullOrWhiteSpace(errRoleName) ? $"{errRoleName},{rol}" : rol;
|
||||
}
|
||||
else
|
||||
{
|
||||
roleIds = !string.IsNullOrWhiteSpace(roleIds) ? $"{roleIds},{role.RoleId}" : role.RoleId;
|
||||
roleNames = !string.IsNullOrWhiteSpace(roleNames) ? $"{roleNames},{role.RoleName}" : role.RoleName;
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(errRoleName))
|
||||
{
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "角色", Reason = $"[{errRoleName}]不在角色表中!" });
|
||||
}
|
||||
}
|
||||
newSysUser.RoleId = roleIds;
|
||||
newSysUser.RoleName = roleNames;
|
||||
|
||||
//var role = roles.FirstOrDefault(e => e.RoleName == roleName);
|
||||
//if (role == null)
|
||||
//{
|
||||
// result += "第" + (i + 2).ToString() + "行," + "角色" + "," + "[" + roleName + "]错误!" + "|";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// newSysUser.RoleId = role.RoleId;
|
||||
// newSysUser.RoleName = role.RoleName;
|
||||
//}
|
||||
|
||||
if (!newSysUser.IsPost.HasValue)
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "在岗" + "," + "此项为必填项!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "在岗", Reason = "此项为必填项!" });
|
||||
}
|
||||
|
||||
string mainCNProfessionalName = newSysUser.MainCNProfessionalName;
|
||||
if (!string.IsNullOrEmpty(mainCNProfessionalName))
|
||||
if (!string.IsNullOrWhiteSpace(mainCNProfessionalName))
|
||||
{
|
||||
var cNProfessional = cNProfessionals.FirstOrDefault(e => e.ProfessionalName == mainCNProfessionalName);
|
||||
if (cNProfessional == null)
|
||||
{
|
||||
result += "第" + (i + 2).ToString() + "行," + "主专业" + "," + "[" + mainCNProfessionalName + "]不在专业表中!" + "|";
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "主专业", Reason = $"[{mainCNProfessionalName}]不在专业表中!" });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -262,20 +328,22 @@ namespace FineUIPro.Web.SysManage
|
||||
}
|
||||
|
||||
string viceCNProfessionalName = newSysUser.ViceCNProfessionalName;
|
||||
if (!string.IsNullOrEmpty(viceCNProfessionalName))
|
||||
if (!string.IsNullOrWhiteSpace(viceCNProfessionalName))
|
||||
{
|
||||
string viceCNProfessionalId = string.Empty;
|
||||
bool hasErr = false;
|
||||
string[] strs = viceCNProfessionalName.Split(',');
|
||||
string errViceCNProfessionalName = string.Empty;
|
||||
foreach (var item in strs)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(item))
|
||||
if (!string.IsNullOrWhiteSpace(item))
|
||||
{
|
||||
var cNProfessional = cNProfessionals.FirstOrDefault(e => e.ProfessionalName == item);
|
||||
if (cNProfessional == null)
|
||||
{
|
||||
hasErr = true;
|
||||
result += "第" + (i + 2).ToString() + "行," + "副专业" + "," + "[" + item + "]不在专业表中!" + "|";
|
||||
//result += "第" + (i + 2).ToString() + "行," + "副专业" + "," + "[" + item + "]不在专业表中!" + "|";
|
||||
errViceCNProfessionalName = !string.IsNullOrWhiteSpace(errViceCNProfessionalName) ? $"{errViceCNProfessionalName},{item}" : item;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -283,7 +351,11 @@ namespace FineUIPro.Web.SysManage
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(viceCNProfessionalId))
|
||||
if (!string.IsNullOrWhiteSpace(errViceCNProfessionalName))
|
||||
{
|
||||
errorInfos.Add(new ErrorInfo { Row = (i + 2).ToString(), Column = "副专业", Reason = $"[{errViceCNProfessionalName}]不在专业表中!" });
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(viceCNProfessionalId))
|
||||
{
|
||||
viceCNProfessionalId = viceCNProfessionalId.Substring(0, viceCNProfessionalId.Length - 1);
|
||||
}
|
||||
@@ -296,31 +368,22 @@ namespace FineUIPro.Web.SysManage
|
||||
///加入用户视图
|
||||
userViews.Add(newSysUser);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
if (errorInfos.Any())
|
||||
{
|
||||
userViews.Clear();
|
||||
result = result.Substring(0, result.LastIndexOf("|"));
|
||||
errorInfos = result;
|
||||
Alert alert = new Alert
|
||||
{
|
||||
Message = result,
|
||||
Target = Target.Self
|
||||
};
|
||||
alert.Show();
|
||||
this.gvErrorInfo.DataSource = errorInfos;
|
||||
this.gvErrorInfo.DataBind();
|
||||
}
|
||||
else
|
||||
{
|
||||
errorInfos = string.Empty;
|
||||
if (userViews.Count > 0)
|
||||
errorInfos.Clear();
|
||||
if (!userViews.Any())
|
||||
{
|
||||
this.Grid1.Hidden = false;
|
||||
this.Grid1.DataSource = userViews;
|
||||
this.Grid1.DataBind();
|
||||
Alert.ShowInTop("审核完成,请点击保存!", MessageBoxIcon.Success);
|
||||
Alert.ShowInTop("导入数据为空!", MessageBoxIcon.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert.ShowInTop("导入数据为空!", MessageBoxIcon.Warning);
|
||||
ShowNotify("审核完成,请点击导入!", MessageBoxIcon.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -341,7 +404,7 @@ namespace FineUIPro.Web.SysManage
|
||||
/// <param name="e"></param>
|
||||
protected void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(errorInfos))
|
||||
if (!errorInfos.Any())
|
||||
{
|
||||
int a = userViews.Count();
|
||||
int insertCount = 0;
|
||||
@@ -354,19 +417,19 @@ namespace FineUIPro.Web.SysManage
|
||||
UserName = userViews[i].UserName,
|
||||
Account = userViews[i].Account,
|
||||
UnitId = userViews[i].UnitId,
|
||||
DepartId=userViews[i].DepartId,
|
||||
DepartId = userViews[i].DepartId,
|
||||
RoleId = userViews[i].RoleId,
|
||||
IdentityCard = userViews[i].IdentityCard,
|
||||
Telephone = userViews[i].Telephone,
|
||||
IsPost = userViews[i].IsPost,
|
||||
IsOffice = userViews[i].IsOffice,
|
||||
MainCNProfessionalId=userViews[i].MainCNProfessionalId,
|
||||
ViceCNProfessionalId=userViews[i].ViceCNProfessionalId,
|
||||
MainCNProfessionalId = userViews[i].MainCNProfessionalId,
|
||||
ViceCNProfessionalId = userViews[i].ViceCNProfessionalId,
|
||||
};
|
||||
var getUser = Funs.DB.Sys_User.FirstOrDefault(x => x.Account == userViews[i].Account);
|
||||
if (getUser == null)
|
||||
{
|
||||
newUser.Password = Funs.EncryptionPassword(Const.Password);
|
||||
newUser.Password = Funs.EncryptionPassword(Const.Password);
|
||||
newUser.RawPassword = Const.Password;
|
||||
BLL.UserService.AddUser(newUser);
|
||||
insertCount++;
|
||||
@@ -396,24 +459,24 @@ namespace FineUIPro.Web.SysManage
|
||||
#endregion
|
||||
|
||||
#region 关闭弹出窗口
|
||||
/// <summary>
|
||||
/// 关闭导入弹出窗口
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Window2_Close(object sender, WindowCloseEventArgs e)
|
||||
{
|
||||
if (Session["sysUsers"] != null)
|
||||
{
|
||||
userViews = Session["sysUsers"] as List<Model.View_Sys_User>;
|
||||
}
|
||||
if (userViews.Count > 0)
|
||||
{
|
||||
this.Grid1.Hidden = false;
|
||||
this.Grid1.DataSource = userViews;
|
||||
this.Grid1.DataBind();
|
||||
}
|
||||
}
|
||||
///// <summary>
|
||||
///// 关闭导入弹出窗口
|
||||
///// </summary>
|
||||
///// <param name="sender"></param>
|
||||
///// <param name="e"></param>
|
||||
//protected void Window2_Close(object sender, WindowCloseEventArgs e)
|
||||
//{
|
||||
// if (Session["sysUsers"] != null)
|
||||
// {
|
||||
// userViews = Session["sysUsers"] as List<Model.View_Sys_User>;
|
||||
// }
|
||||
// if (userViews.Count > 0)
|
||||
// {
|
||||
// this.Grid1.Hidden = false;
|
||||
// this.Grid1.DataSource = userViews;
|
||||
// this.Grid1.DataBind();
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in New Issue
Block a user