| | |
| | | public static ToMessage mes = new ToMessage(); //定义全局返回信息对象 |
| | | |
| | | #region【Excel模板上传验证】 |
| | | #region【Excel模板上传验证,用户清单模板】 |
| | | public static string Two(string FileCode, out string code) |
| | | |
| | | #region【Excel模板上传验证,组织架构模板】 |
| | | public static string Zerro(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | | code = ""; |
| | | List<DataTable> excelTable = new List<DataTable>(); |
| | | excelTable = ImportExcel.ExcelToTableList(FileCode); |
| | | if (excelTable.Count != 4) |
| | | { |
| | | code = "300"; |
| | | Message = "导入模板不符合规范,请检查sheet数"; |
| | | return Message; |
| | | |
| | | } |
| | | else if (excelTable[0].Columns.Count != 5) |
| | | { |
| | | code = "300"; |
| | | Message = "用户班组模板不符合规范,请检查列名字段数"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns.Count != 10) |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板不符合规范,请检查列名字段数"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[0].ColumnName != "序号") |
| | | { |
| | | code = "300"; |
| | | Message = "用户班组模板:表头信息不符合规范,第1列应为{序号}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[1].ColumnName != "组织编码") |
| | | { |
| | | code = "300"; |
| | | Message = "用户班组模板:表头信息不符合规范,第2列应为{组织编码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[2].ColumnName != "班组编号(唯一)") |
| | | { |
| | | code = "300"; |
| | | Message = "用户班组模板:表头信息不符合规范,第2列应为{班组编号(唯一)}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[3].ColumnName != "班组名称") |
| | | { |
| | | code = "300"; |
| | | Message = "用户班组模板:表头信息不符合规范,第3列应为{班组名称}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[4].ColumnName != "班组描述") |
| | | { |
| | | code = "300"; |
| | | Message = "用户班组模板:表头信息不符合规范,第4列应为{班组描述}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[0].ColumnName != "序号") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第1列应为{序号}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[1].ColumnName != "用户编号(唯一)") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第2列应为{用户编号(唯一)}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[2].ColumnName != "用户姓名") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第3列应为{用户姓名}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[3].ColumnName != "在职状态") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第4列应为{在职状态}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[4].ColumnName != "密码") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第5列应为{密码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[5].ColumnName != "手机号") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第6列应为{手机号}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[6].ColumnName != "邮箱") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第7列应为{邮箱}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[7].ColumnName != "组织编码") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第8列应为{组织编码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[8].ColumnName != "工资类型") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第9列应为{工资类型}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[1].Columns[9].ColumnName != "用户组编码") |
| | | { |
| | | code = "300"; |
| | | Message = "用户清单模板:表头信息不符合规范,第10列应为{用户组编码}"; |
| | | return Message; |
| | | } |
| | | else |
| | | { |
| | | code = "200"; |
| | | Message = "模板检验通过"; |
| | | } |
| | | |
| | | return Message; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,角色权限模板】 |
| | | #region【Excel模板上传验证,岗位管理模板】 |
| | | public static string One(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,工位清单模板】 |
| | | public static string Three(string FileCode, out string code) |
| | | #region【Excel模板上传验证,班组管理模板】 |
| | | public static string Two(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | | code = ""; |
| | | DataTable excelTable = new DataTable(); |
| | | excelTable = ImportExcel.ExcelToTable(FileCode); |
| | | if (excelTable.Columns.Count != 9) |
| | | |
| | | return Message; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,人员管理模板】 |
| | | public static string Three(List<DataTable> excelTable, out string code) |
| | | { |
| | | string Message = ""; |
| | | code = ""; |
| | | if (excelTable.Count != 1) |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "导入模板不符合规范,请检查sheet数"; |
| | | return Message; |
| | | |
| | | } |
| | | else if (excelTable.Columns[0].ColumnName != "序号") |
| | | else if (excelTable[0].Columns.Count != 10) |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板不符合规范,请检查列名字段数"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[1].ColumnName != "工位编号(唯一)") |
| | | else if (excelTable[0].Columns[0].ColumnName != "*用户编号(唯一)") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第1列应为{*用户编号(唯一)}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[2].ColumnName != "工位名称(唯一)") |
| | | else if (excelTable[0].Columns[1].ColumnName != "*用户姓名") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第2列应为{*用户姓名}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[3].ColumnName != "工位类型") |
| | | else if (excelTable[0].Columns[2].ColumnName != "*密码") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第3列应为{*密码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[4].ColumnName != "所属车间") |
| | | else if (excelTable[0].Columns[3].ColumnName != "*在职状态") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第4列应为{*在职状态}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[5].ColumnName != "所属产线") |
| | | else if (excelTable[0].Columns[4].ColumnName != "手机号") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第5列应为{手机号}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[6].ColumnName != "使用状态") |
| | | else if (excelTable[0].Columns[5].ColumnName != "邮箱") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第6列应为{邮箱}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[7].ColumnName != "数采标识1") |
| | | else if (excelTable[0].Columns[6].ColumnName != "*所属组织编码") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第7列应为{*所属组织编码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable.Columns[8].ColumnName != "数采标识2") |
| | | else if (excelTable[0].Columns[7].ColumnName != "所属岗位编码") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第8列应为{所属岗位编码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[8].ColumnName != "所属角色编码") |
| | | { |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第9列应为{所属角色编码}"; |
| | | return Message; |
| | | } |
| | | else if (excelTable[0].Columns[9].ColumnName != "所属班组编码") |
| | | { |
| | | code = "301"; |
| | | Message = "用户清单模板:表头信息不符合规范,第10列应为{所属班组编码}"; |
| | | return Message; |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,往来单位清单模板】 |
| | | #region【Excel模板上传验证,角色管单模板】 |
| | | public static string Four(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,仓库、库位定义模板】 |
| | | public static string SixOne(string FileCode, out string code) |
| | | #region【Excel模板上传验证,往来单位模板】 |
| | | public static string Five(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | | code = ""; |
| | | |
| | | return Message; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,仓库设置模板】 |
| | | public static string Six(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | | code = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,容器定义模板】 |
| | | #region【Excel模板上传验证,库位设置模板】 |
| | | public static string Seven(string FileCode, out string code) |
| | | { |
| | | string Message = ""; |
| | |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证】 |
| | | #region【Excel上传数据验证,用户角色】 |
| | | public static List<ExcelErro> TwoData(string FileCode, out string StuCode, out string message, out int count) |
| | | #region【Excel上传数据验证,组织架构】 |
| | | public static List<ExcelErro> ZerroData(string savePath, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | | StuCode = ""; |
| | |
| | | var dynamicParams = new DynamicParameters(); |
| | | DataTable dt; |
| | | List<ExcelErro> list = new List<ExcelErro>(); |
| | | List<DataTable> excelTable = new List<DataTable>(); |
| | | list = ImportExcel.ExcelToTableListErro(FileCode); //验证Excel数据必填字段是否为空、唯一字段是否重复 |
| | | excelTable = ImportExcel.ExcelToTableList(FileCode); //获取Excel数据 |
| | | //主表 |
| | | for (int j = 0; j < excelTable[0].Rows.Count; j++) |
| | | { |
| | | if (excelTable[0].Rows[j][2].ToString().Trim() != null && excelTable[0].Rows[j][2].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from TGroup where group_code=@group_code"; |
| | | dynamicParams.Add("@group_code", excelTable[0].Rows[j][2].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{班组编码(唯一)}"; |
| | | erro.ErrorCont = "班组表:{班组编码(唯一)}字段" + excelTable[0].Rows[j][2].ToString().Trim() + "已存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | } |
| | | //子表 |
| | | for (int k = 0; k < excelTable[1].Rows.Count; k++) |
| | | { |
| | | if (excelTable[1].Rows[k][1].ToString().Trim() != null && excelTable[1].Rows[k][1].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from TUser where usercode=@usercode"; |
| | | dynamicParams.Add("@usercode", excelTable[1].Rows[k][1].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{用户编码(唯一)}"; |
| | | erro.ErrorCont = "用户表:{用户编码(唯一)}字段" + excelTable[1].Rows[k][1].ToString().Trim() + "已存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[1].Rows[k][7].ToString().Trim() != null && excelTable[1].Rows[k][7].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from TOrganization where org_code=@org_code"; |
| | | dynamicParams.Add("@org_code", excelTable[1].Rows[k][7].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt == null || dt.Rows.Count <= 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{组织编码}"; |
| | | erro.ErrorCont = "用户表:{组织编码}字段" + excelTable[1].Rows[k][7].ToString().Trim() + "不存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[1].Rows[k][9].ToString().Trim() != null && excelTable[1].Rows[k][9].ToString().Trim() != "") |
| | | { |
| | | sql = @"select torg_code from TGroup where group_code=@group_code"; |
| | | dynamicParams.Add("@group_code", excelTable[1].Rows[k][9].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt != null && dt.Rows.Count > 0) |
| | | { |
| | | if (dt.Rows[0]["torg_code"].ToString() != excelTable[1].Rows[k][7].ToString().Trim()) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{用户组编码}"; |
| | | erro.ErrorCont = "用户表:{用户组编码}字段" + excelTable[1].Rows[k][9].ToString().Trim() + " 不是组织编码:" + excelTable[1].Rows[k][7].ToString().Trim() + "下的用户组"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //判断子表组织编码不存在于主表组织编码中的数据 |
| | | var dt2 = from r in excelTable[1].AsEnumerable() |
| | | where !( |
| | | from rr in excelTable[0].AsEnumerable() |
| | | select rr.Field<string>("组织编码") |
| | | ).Contains(r.Field<string>("组织编码")) |
| | | select r; |
| | | List<DataRow> listRow2 = dt2.ToList(); |
| | | if (listRow2.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{组织编码}"; |
| | | erro.ErrorCont = "用户表:{组织编码}字段中有值在班组表:{组织编码}中不存在"; |
| | | list.Add(erro); |
| | | } |
| | | //判断子表外键不存在于主表主键中的数据 |
| | | var dt3 = from r in excelTable[1].AsEnumerable() |
| | | where !( |
| | | from rr in excelTable[0].AsEnumerable() |
| | | select rr.Field<string>("班组编号(唯一)") |
| | | ).Contains(r.Field<string>("用户组编码")) |
| | | select r; |
| | | List<DataRow> listRow = dt3.ToList(); |
| | | if (listRow.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{用户组编码}"; |
| | | erro.ErrorCont = "用户表:{用户组编码}字段中有值在班组表:{班组编号(唯一)}中不存在"; |
| | | list.Add(erro); |
| | | } |
| | | |
| | | if (list.Count > 0) |
| | | { |
| | | int index = 0; |
| | |
| | | { |
| | | StuCode = "200"; |
| | | message = "数据验证成功"; |
| | | count = excelTable[0].Rows.Count + excelTable[1].Rows.Count; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,角色权限】 |
| | | #region【Excel上传数据验证,岗位管理】 |
| | | public static List<ExcelErro> OneData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | |
| | | { |
| | | StuCode = "200"; |
| | | message = "数据验证成功"; |
| | | count = excelTable[0].Rows.Count + excelTable[1].Rows.Count; |
| | | count = excelTable[0].Rows.Count; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,工位清单】 |
| | | public static List<ExcelErro> ThreeData(string FileCode, out string StuCode, out string message, out int count) |
| | | #region【Excel上传数据验证,班组管理】 |
| | | public static List<ExcelErro> TwoData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | | StuCode = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,往来单位清单】 |
| | | #region【Excel上传数据验证,人员管理】 |
| | | public static List<ExcelErro> ThreeData(List<DataTable> excelTable, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | | StuCode = ""; |
| | | count = 0; |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | DataTable dt; |
| | | List<ExcelErro> list = new List<ExcelErro>(); |
| | | list = ImportExcel.InportExcelToTableListErro(excelTable); //验证Excel数据必填字段是否为空、唯一字段是否重复 |
| | | //用户表 |
| | | for (int k = 0; k < excelTable[0].Rows.Count; k++) |
| | | { |
| | | if (excelTable[0].Rows[k][0].ToString().Trim() != null && excelTable[0].Rows[k][0].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from TUser where usercode=@usercode"; |
| | | dynamicParams.Add("@usercode", excelTable[0].Rows[k][0].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "*用户编码(唯一)"; |
| | | erro.ErrorCont = "用户表:*用户编码(唯一)字段" + excelTable[0].Rows[k][0].ToString().Trim() + "已存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[0].Rows[k][1].ToString().Trim() != null && excelTable[0].Rows[k][1].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from TUser where username=@username"; |
| | | dynamicParams.Add("@username", excelTable[0].Rows[k][1].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "*用户名称"; |
| | | erro.ErrorCont = "用户表:*用户名称字段" + excelTable[0].Rows[k][1].ToString().Trim() + "已存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[0].Rows[k][6].ToString().Trim() != null && excelTable[0].Rows[k][6].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from TOrganization where torg_code=@torg_code"; |
| | | dynamicParams.Add("@torg_code", excelTable[0].Rows[k][6].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt == null || dt.Rows.Count <= 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "*组织编码"; |
| | | erro.ErrorCont = "用户表:*组织编码字段" + excelTable[0].Rows[k][6].ToString().Trim() + "不存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[0].Rows[k][7].ToString().Trim() != null && excelTable[0].Rows[k][7].ToString().Trim() != "") |
| | | { |
| | | string[] postcode = Array.ConvertAll<string, string>(excelTable[0].Rows[k][7].ToString().Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] |
| | | sql = @"select postcode from TPost where postcode in @postcode"; |
| | | dynamicParams.Add("@postcode", postcode); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt != null && dt.Rows.Count > 0) |
| | | { |
| | | string[] values = excelTable[0].Rows[k][7].ToString().Trim().Split(','); |
| | | var unmatchedValues = values.Except(dt.AsEnumerable().Select(row => row.Field<string>("postcode"))); |
| | | foreach (var value in unmatchedValues) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "{所属岗位编码}"; |
| | | erro.ErrorCont = "用户表:{所属岗位编码}字段" + value + " 不是有效的岗位编码"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "{所属岗位编码}"; |
| | | erro.ErrorCont = "用户表:{所属岗位编码}字段" + excelTable[0].Rows[k][7].ToString().Trim() + " 不是有效的岗位编码"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[0].Rows[k][8].ToString().Trim() != null && excelTable[0].Rows[k][8].ToString().Trim() != "") |
| | | { |
| | | string[] rolecode = Array.ConvertAll<string, string>(excelTable[0].Rows[k][8].ToString().Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] |
| | | sql = @"select rolecode from TRole where rolecode in @rolecode"; |
| | | dynamicParams.Add("@rolecode", rolecode); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt != null && dt.Rows.Count > 0) |
| | | { |
| | | string[] values = excelTable[0].Rows[k][8].ToString().Trim().Split(','); |
| | | var unmatchedValues = values.Except(dt.AsEnumerable().Select(row => row.Field<string>("rolecode"))); |
| | | foreach (var value in unmatchedValues) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "{所属角色编码}"; |
| | | erro.ErrorCont = "用户表:{所属角色编码}字段" + value + " 不是有效的角色编码"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "{所属角色编码}"; |
| | | erro.ErrorCont = "用户表:{所属角色编码}字段" + excelTable[0].Rows[k][8].ToString().Trim() + " 不是有效的角色编码"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | if (excelTable[0].Rows[k][9].ToString().Trim() != null && excelTable[0].Rows[k][9].ToString().Trim() != "") |
| | | { |
| | | string[] usergroupcode = Array.ConvertAll<string, string>(excelTable[0].Rows[k][9].ToString().Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] |
| | | sql = @"select usergroupcode from TGroup where usergroupcode in @usergroupcode"; |
| | | dynamicParams.Add("@usergroupcode", usergroupcode); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt != null && dt.Rows.Count > 0) |
| | | { |
| | | string[] values = excelTable[0].Rows[k][9].ToString().Trim().Split(','); |
| | | var unmatchedValues = values.Except(dt.AsEnumerable().Select(row => row.Field<string>("usergroupcode"))); |
| | | foreach (var value in unmatchedValues) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "{所属班组编码}"; |
| | | erro.ErrorCont = "用户表:{所属班组编码}字段" + value + " 不是有效的班组编码"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = (k + 1).ToString(); |
| | | erro.ErrorField = "{所属班组编码}"; |
| | | erro.ErrorCont = "用户表:{所属班组编码}字段" + excelTable[0].Rows[k][9].ToString().Trim() + " 不是有效的班组编码"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | } |
| | | if (list.Count > 0) |
| | | { |
| | | int index = 0; |
| | | foreach (ExcelErro item in list) |
| | | { |
| | | index++; |
| | | item.Seq = index.ToString(); |
| | | } |
| | | StuCode = "301"; |
| | | message = "数据验证失败"; |
| | | } |
| | | else |
| | | { |
| | | StuCode = "200"; |
| | | message = "数据验证成功"; |
| | | count = excelTable[0].Rows.Count; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,角色管理】 |
| | | public static List<ExcelErro> FourData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,仓库、库位定义】 |
| | | public static List<ExcelErro> SixOneData(string FileCode, out string StuCode, out string message, out int count) |
| | | #region【Excel上传数据验证,往来单位】 |
| | | public static List<ExcelErro> FiveData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | | StuCode = ""; |
| | | count = 0; |
| | | string sql = ""; |
| | | DataTable dt; |
| | | var dynamicParams = new DynamicParameters(); |
| | | List<ExcelErro> list = new List<ExcelErro>(); |
| | | DataTable excelTable = new DataTable(); |
| | | list = ImportExcel.ExcelToTableErro(FileCode); //验证Excel数据必填字段是否为空、唯一字段是否重复 |
| | | excelTable = ImportExcel.ExcelToTable(FileCode); //获取Excel数据 |
| | | for (int i = 0; i < excelTable.Rows.Count; i++) |
| | | { |
| | | if (excelTable.Rows[i][1].ToString().Trim() != null && excelTable.Rows[i][1].ToString().Trim() != "") |
| | | { |
| | | sql = @"select code from TCustomer where code=@code"; |
| | | |
| | | dynamicParams.Add("@code", excelTable.Rows[i][1].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | ExcelErro erro = new ExcelErro(); |
| | | erro.RoeNumber = "/"; |
| | | erro.ErrorField = "{往来单位编码(唯一)}"; |
| | | erro.ErrorCont = "往来单位表:{往来单位编码(唯一)}字段" + excelTable.Rows[i][1].ToString().Trim() + "已存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | } |
| | | if (list.Count > 0) |
| | | { |
| | | int index = 0; |
| | | foreach (ExcelErro item in list) |
| | | { |
| | | index++; |
| | | item.Seq = index.ToString(); |
| | | } |
| | | StuCode = "301"; |
| | | message = "数据验证失败"; |
| | | } |
| | | else |
| | | { |
| | | StuCode = "200"; |
| | | message = "数据验证成功"; |
| | | count = excelTable.Rows.Count; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,仓库设置】 |
| | | public static List<ExcelErro> SixData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | | StuCode = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,容器定义】 |
| | | #region【Excel上传数据验证,库位设置】 |
| | | public static List<ExcelErro> SevenData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | |
| | | #endregion |
| | | |
| | | #region[Excel上传数据提交] |
| | | #region【Excel数据上传,用户角色】 |
| | | public static string TwoSubmit(string FileCode, string User, out string StuCode) |
| | | #region【Excel数据上传,组织架构】 |
| | | public static string ZerroSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |
| | |
| | | list.Clear(); |
| | | List<DataTable> excelTable = new List<DataTable>(); |
| | | excelTable = ImportExcel.ExcelToTableList(FileCode); |
| | | //导入班组 |
| | | //导入角色类型 |
| | | for (int k = 0; k < excelTable[0].Rows.Count; k++) |
| | | { |
| | | sql = @"select * from TGroup where group_code=@group_code"; |
| | | dynamicParams.Add("@group_code", excelTable[0].Rows[k][2].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | sql = @"insert into TGroup(group_code,group_name,description,lm_user,lm_date,torg_code) |
| | | values(@group_code,@group_name,@description,@Operator,@CreateDate,@torg_code)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | group_code = excelTable[0].Rows[k][2].ToString().Trim(), |
| | | group_name = excelTable[0].Rows[k][3].ToString().Trim(), |
| | | description = excelTable[0].Rows[k][4].ToString().Trim(), |
| | | CreateDate = DateTime.Now.ToString(), |
| | | Operator = User, |
| | | torg_code = excelTable[0].Rows[k][1].ToString().Trim() |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | //导入用户 |
| | | for (int i = 0; i < excelTable[1].Rows.Count; i++) |
| | | { |
| | | if (excelTable[1].Rows[i][3].ToString().Trim() == "在职") |
| | | { |
| | | Enable = "Y"; |
| | | } |
| | | else |
| | | { |
| | | Enable = "N"; |
| | | } |
| | | //工资类型 |
| | | switch (excelTable[1].Rows[i][8].ToString().Trim()) |
| | | { |
| | | case "计件制": |
| | | WageType = "2"; |
| | | break; |
| | | case "计时制": |
| | | WageType = "1"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | sql = @"select * from TUser where usercode=@usercode"; |
| | | dynamicParams.Add("@usercode", excelTable[1].Rows[i][1].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (dt.Rows.Count > 0) |
| | | { |
| | | continue; |
| | | } |
| | | sql = @"insert into TUser(usercode,username,password,enable,mobile,lm_date,email,lm_user,stu_torgcode,wagetype,usergroup_code) |
| | | values(@UserCode,@UserName,@password,@Enable,@Mobile,@CreateDate,@Email,@Operator,@StuOrg,@wagetype,@usergroup_code)"; |
| | | sql = @"insert into TRoleType(roletype_code,roletype_name,torg_code) |
| | | values(@roletype_code,@roletype_name,@torg_code)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | UserCode = excelTable[1].Rows[i][1].ToString().Trim(), |
| | | UserName = excelTable[1].Rows[i][2].ToString().Trim(), |
| | | password = excelTable[1].Rows[i][4].ToString().Trim(), |
| | | Enable = Enable, |
| | | Mobile = excelTable[1].Rows[i][5].ToString().Trim(), |
| | | CreateDate = DateTime.Now.ToString(), |
| | | Email = excelTable[1].Rows[i][6].ToString().Trim(), |
| | | roletype_code = excelTable[0].Rows[k][2].ToString().Trim(), |
| | | roletype_name = excelTable[0].Rows[k][3].ToString().Trim(), |
| | | torg_code = excelTable[0].Rows[k][1].ToString().Trim() |
| | | } |
| | | }); |
| | | } |
| | | //导入角色 |
| | | for (int i = 0; i < excelTable[1].Rows.Count; i++) |
| | | { |
| | | sql = @"insert into TRole(role_code,role_name,roletype_code,description,lm_user,lm_date,torg_code) |
| | | values(@role_code,@role_name,@roletype_code,@description,@Operator,@CreateDate,@torg_code)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | role_code = excelTable[1].Rows[i][2].ToString().Trim(), |
| | | role_name = excelTable[1].Rows[i][3].ToString().Trim(), |
| | | roletype_code = excelTable[1].Rows[i][4].ToString().Trim(), |
| | | description = excelTable[1].Rows[i][5].ToString().Trim(), |
| | | Operator = User, |
| | | StuOrg = excelTable[1].Rows[i][7].ToString().Trim(), |
| | | wagetype = WageType, |
| | | usergroup_code = excelTable[1].Rows[i][9].ToString().Trim() |
| | | CreateDate = DateTime.Now.ToString(), |
| | | torg_code = excelTable[1].Rows[i][1].ToString().Trim() |
| | | } |
| | | }); |
| | | } |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,角色权限】 |
| | | #region【Excel数据上传,岗位管理】 |
| | | public static string OneSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,工位清单】 |
| | | public static string ThreeSubmit(string FileCode, string User, out string StuCode) |
| | | #region【Excel数据上传,分组管理】 |
| | | public static string TwoSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,往来单位清单】 |
| | | #region【Excel数据上传,人员管理】 |
| | | public static string ThreeSubmit(List<DataTable> excelTable, User us, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |
| | | string sql = ""; |
| | | DataTable dt; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | list.Clear(); |
| | | //导入用户 |
| | | for (int i = 0; i < excelTable[0].Rows.Count; i++) |
| | | { |
| | | //sql = @"select * from TUser where usercode=@usercode"; |
| | | //dynamicParams.Add("@usercode", excelTable[1].Rows[i][1].ToString().Trim()); |
| | | //dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | //if (dt.Rows.Count > 0) |
| | | //{ |
| | | // continue; |
| | | //} |
| | | sql = @"insert into TUser(usercode,username,password,status,mobile,email,storg_code,post_code,role_code,group_code,is_system_admin,lm_user,lm_date) |
| | | values(@usercode,@username,@password,@status,@mobile,@email,@storg_code,@post_code,@role_code,@group_code,@is_system_admin,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | usercode = excelTable[0].Rows[i][0].ToString().Trim(), |
| | | username = excelTable[0].Rows[i][1].ToString().Trim(), |
| | | password = excelTable[0].Rows[i][2].ToString().Trim(), |
| | | status = excelTable[0].Rows[i][3].ToString().Trim(), |
| | | mobile = excelTable[0].Rows[i][4].ToString().Trim(), |
| | | email = excelTable[0].Rows[i][5].ToString().Trim(), |
| | | storg_code = excelTable[0].Rows[i][6].ToString().Trim(), |
| | | post_code = excelTable[0].Rows[i][7].ToString().Trim(), |
| | | role_code = excelTable[0].Rows[i][8].ToString().Trim(), |
| | | group_code = excelTable[0].Rows[i][9].ToString().Trim(), |
| | | is_system_admin = "N", |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | StuCode = "200"; |
| | | message = "导入成功!"; |
| | | } |
| | | else |
| | | { |
| | | StuCode = "300"; |
| | | message = "导入失败!"; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | StuCode = "300"; |
| | | message = e.Message; |
| | | } |
| | | return message; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,角色管理】 |
| | | public static string FourSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,仓库、库位定义】 |
| | | public static string SixOneSubmit(string FileCode, string User, out string StuCode) |
| | | #region【Excel数据上传,往来单位】 |
| | | public static string FiveSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |
| | | string sql = ""; |
| | | DataTable dt; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | list.Clear(); |
| | | DataTable excelTable = new DataTable(); |
| | | excelTable = ImportExcel.ExcelToTable(FileCode); |
| | | //导入往来单位表 |
| | | for (int i = 0; i < excelTable.Rows.Count; i++) |
| | | { |
| | | string Type = ""; |
| | | switch (excelTable.Rows[i][3].ToString().Trim()) |
| | | { |
| | | case "供应商": |
| | | Type = "226"; |
| | | break; |
| | | case "客户": |
| | | Type = "211"; |
| | | break; |
| | | case "客户/供应商": |
| | | Type = "228"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | sql = @"insert into TCustomer(code,name,type,conttacts,conttphone,addr,lm_user,lm_date) |
| | | values(@code,@name,@type,@conttacts,@conttphone,@addr,@Operator,@CreateDate)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = excelTable.Rows[i][1].ToString().Trim(), |
| | | name = excelTable.Rows[i][2].ToString().Trim(), |
| | | type = Type, |
| | | conttacts = excelTable.Rows[i][4].ToString().Trim(), |
| | | conttphone = excelTable.Rows[i][5].ToString().Trim(), |
| | | addr = excelTable.Rows[i][6].ToString().Trim(), |
| | | Operator = User, |
| | | CreateDate = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | StuCode = "200"; |
| | | message = "导入成功!"; |
| | | } |
| | | else |
| | | { |
| | | StuCode = "300"; |
| | | message = "导入失败!"; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | StuCode = "300"; |
| | | message = e.Message; |
| | | } |
| | | return message; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,仓库设置】 |
| | | public static string SixSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,容器定义】 |
| | | #region【Excel数据上传,库位设置】 |
| | | public static string SevenSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |