| | |
| | | using System; |
| | | using Dapper; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Linq; |
| | |
| | | public static ToMessage mes = new ToMessage(); //定义全局返回信息对象 |
| | | |
| | | #region【Excel模板上传验证】 |
| | | #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 != 6) |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[0].ColumnName != "序号") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[1].ColumnName != "用户编号(唯一)") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[2].ColumnName != "用户姓名") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[3].ColumnName != "密码") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[4].ColumnName != "手机号") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[5].ColumnName != "邮箱") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[6].ColumnName != "所属组织") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[7].ColumnName != "在职状态") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[8].ColumnName != "工资类型") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else |
| | | { |
| | | code = "200"; |
| | | Message = "模板检验通过"; |
| | | } |
| | | return Message; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel模板上传验证,角色权限模板】 |
| | | public static string One(string FileCode, out string code) |
| | | { |
| | |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[3].ColumnName != "角色类型") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else |
| | | { |
| | | code = "200"; |
| | | Message = "模板检验通过"; |
| | | } |
| | | return Message; |
| | | } |
| | | #endregion |
| | | |
| | | #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 != 6) |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[0].ColumnName != "序号") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[1].ColumnName != "用户编号(唯一)") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[2].ColumnName != "用户姓名") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[3].ColumnName != "所属组织") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[4].ColumnName != "在职状态") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | | } |
| | | else if (excelTable.Columns[5].ColumnName != "工资类型") |
| | | { |
| | | code = "300"; |
| | | Message = "模板不符合规范,请检查列名"; |
| | |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证】 |
| | | #region【Excel上传数据验证,角色权限】 |
| | | public static List<ExcelErro> OneData(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 = ""; |
| | | count = 0; |
| | | string sql = ""; |
| | | var dynamicParams = new DynamicParameters(); |
| | | DataTable dt; |
| | | 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 TUser 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 (excelTable.Rows[i][6].ToString().Trim() != null && excelTable.Rows[i][6].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from( |
| | | select org_code,org_name from TOrganization where description='D' and parent_id in (select id from TOrganization where description='F') |
| | | union |
| | | select org_code,org_name from TOrganization where parent_id in(select id |
| | | from TOrganization where description='D' and parent_id in (select id from TOrganization where description='F')) |
| | | ) as AA where AA.org_name=:name"; |
| | | dynamicParams.Add("@code", excelTable.Rows[i][3].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.Rows[i][3].ToString().Trim() + "不存在"; |
| | | list.Add(erro); |
| | | } |
| | | } |
| | | } |
| | | if (list.Count > 0) |
| | | { |
| | | int index = 0; |
| | | foreach (ExcelErro item in list) |
| | | { |
| | | index++; |
| | | item.Seq = index.ToString(); |
| | | } |
| | | StuCode = "300"; |
| | | message = "数据验证失败"; |
| | | } |
| | | else |
| | | { |
| | | StuCode = "200"; |
| | | message = "数据验证成功"; |
| | | count = excelTable.Rows.Count; |
| | | } |
| | | return list; |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel上传数据验证,用户角色】 |
| | | public static List<ExcelErro> TwoData(string FileCode, out string StuCode, out string message, out int count) |
| | | #region【Excel上传数据验证,角色权限】 |
| | | public static List<ExcelErro> OneData(string FileCode, out string StuCode, out string message, out int count) |
| | | { |
| | | message = ""; |
| | | StuCode = ""; |
| | |
| | | #endregion |
| | | |
| | | #region[Excel上传数据提交] |
| | | #region[Excel数据上传,角色权限] |
| | | public static string OneSubmit(string FileCode, string User, out string StuCode) |
| | | #region【Excel数据上传,用户角色】 |
| | | public static string TwoSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |
| | | string sql = ""; |
| | | string ZZName = "", Enable = "", WageType = ""; |
| | | 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++) |
| | | { |
| | | if (excelTable.Rows[i][7].ToString().Trim() == "在职") |
| | | { |
| | | Enable = "Y"; |
| | | } |
| | | else |
| | | { |
| | | Enable = "N"; |
| | | } |
| | | //点检管控 |
| | | switch (excelTable.Rows[i][8].ToString().Trim()) |
| | | { |
| | | case "计件制": |
| | | WageType = "1"; |
| | | break; |
| | | case "计时制": |
| | | WageType = "2"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | if (excelTable.Rows[i][6].ToString().Trim() != null && excelTable.Rows[i][6].ToString().Trim() != "") |
| | | { |
| | | sql = @"select * from( |
| | | select org_code,org_name from TOrganization where description='D' and parent_id in (select id from TOrganization where description='F') |
| | | union |
| | | select org_code,org_name from TOrganization where parent_id in(select id |
| | | from TOrganization where description='D' and parent_id in (select id from TOrganization where description='F')) |
| | | ) as AA where AA.org_name=:name"; |
| | | dynamicParams.Add("@code", excelTable.Rows[i][3].ToString().Trim()); |
| | | dt = DapperHelper.selectdata(sql, dynamicParams); |
| | | ZZName = dt.Rows[0]["CODE"].ToString().Trim(); |
| | | } |
| | | |
| | | sql = @"insert into TUser(usercode,username,password,enable,mobile,lm_date,email,lm_user,stu_torgcode,wagetype) |
| | | values(@UserCode,@UserName,@password,@Enable,@Mobile,@CreateDate,@Email,@Operator,@StuOrg,@wagetype)"; |
| | | dynamicParams.Add("@UserCode", excelTable.Rows[i][1].ToString().Trim()); |
| | | dynamicParams.Add("@UserName", excelTable.Rows[i][2].ToString().Trim()); |
| | | dynamicParams.Add("@password", excelTable.Rows[i][3].ToString().Trim()); |
| | | dynamicParams.Add("@Enable", excelTable.Rows[i][7].ToString().Trim()); |
| | | dynamicParams.Add("@Mobile", excelTable.Rows[i][4].ToString().Trim()); |
| | | dynamicParams.Add("@CreateDate", DateTime.Now.ToString()); |
| | | dynamicParams.Add("@Email", excelTable.Rows[i][5].ToString().Trim()); |
| | | dynamicParams.Add("@Operator", User); |
| | | dynamicParams.Add("@StuOrg", ZZName); |
| | | dynamicParams.Add("@wagetype", WageType); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | StuCode = "300"; |
| | | message = "导入失败!"; |
| | | } |
| | | else |
| | | { |
| | | StuCode = "200"; |
| | | message = "导入成功!"; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region【Excel数据上传,用户角色】 |
| | | public static string TwoSubmit(string FileCode, string User, out string StuCode) |
| | | #region[Excel数据上传,角色权限] |
| | | public static string OneSubmit(string FileCode, string User, out string StuCode) |
| | | { |
| | | string message = ""; |
| | | StuCode = ""; |