public bool GetPasswordStateUsers(Guid transactionid, AdminInfo admin, int curpage, int pagesize, string searchstr, PasswordType type, out string strJsonResult) { bool result = true; strJsonResult = string.Empty; ErrorCodeInfo error = new ErrorCodeInfo(); string paramstr = string.Empty; paramstr += $"userID:{admin.UserID}"; paramstr += $"||UserAccount:{admin.UserAccount}"; paramstr += $"||curpage:{curpage}"; paramstr += $"||pagesize:{pagesize}"; paramstr += $"||searchstr:{searchstr}"; paramstr += $"||PasswordType:{type}"; string funname = "GetPasswordStateUsers"; try { do { BaseListInfo lists = new BaseListInfo(); SystemReportDBProvider Provider = new SystemReportDBProvider(); if (!Provider.GetPasswordStateUsers(transactionid, admin, curpage, pagesize, searchstr, type, out lists, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } error.Code = ErrorCode.None; string json = JsonConvert.SerializeObject(lists); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid); strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info, json); result = true; } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("SystemReportManager调用GetPasswordStateUsers异常", paramstr, ex.ToString(), transactionid); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); result = false; } return(result); }
public bool ExportPasswordStateUsersToExcel(Guid transactionid, AdminInfo admin, int curpage, int pagesize, string searchstr, PasswordType type, out byte[] filebyte, out string strJsonResult) { bool result = true; strJsonResult = string.Empty; ErrorCodeInfo error = new ErrorCodeInfo(); filebyte = new byte[0]; string paramstr = string.Empty; paramstr += $"userID:{admin.UserID}"; paramstr += $"||UserAccount:{admin.UserAccount}"; paramstr += $"||curpage:{curpage}"; paramstr += $"||pagesize:{pagesize}"; paramstr += $"||searchstr:{searchstr}"; paramstr += $"||PasswordType:{type}"; string funname = "ExportPasswordStateUsersToExcel"; try { do { BaseListInfo lists = new BaseListInfo(); SystemReportDBProvider Provider = new SystemReportDBProvider(); if (!Provider.GetPasswordStateUsers(transactionid, admin, curpage, pagesize, searchstr, type, out lists, out error)) { strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); result = false; break; } using (ExcelPackage package = new ExcelPackage()) { ExcelWorksheet sheet = package.Workbook.Worksheets.Add("密码有效期统计统计"); sheet.Cells[1, 1].Value = "显示名称"; sheet.Column(1).Width = 30; //设置列宽 sheet.Cells[1, 2].Value = "邮箱"; sheet.Column(2).Width = 50; //设置列宽 sheet.Cells[1, 3].Value = "创建时间"; sheet.Column(3).Width = 30; //设置列宽 sheet.Cells[1, 4].Value = "密码过期时间"; sheet.Column(4).Width = 30; //设置列宽 sheet.Cells[1, 5].Value = "密码状态"; sheet.Column(5).Width = 30; //设置列宽 sheet.Cells[1, 6].Value = "所在路径"; sheet.Column(6).Width = 150; //设置列宽 for (int i = 0; i < lists.Lists.Count; i++) { SystemReportInfo info = (SystemReportInfo)lists.Lists[i]; sheet.Cells[i + 2, 1].Value = info.DisplayName; sheet.Cells[i + 2, 2].Value = info.UserAccount; sheet.Cells[i + 2, 3].Value = info.CreateTimeName; if (info.Type != PasswordType.Expired && info.Type != PasswordType.NerverExpire) { sheet.Cells[i + 2, 4].Value = info.PasswordExpireTimeName; } else { sheet.Cells[i + 2, 4].Value = "-"; } sheet.Cells[i + 2, 5].Value = info.PasswordTypeName; sheet.Cells[i + 2, 6].Value = info.DistinguishedName; } filebyte = package.GetAsByteArray(); } error.Code = ErrorCode.None; string json = JsonConvert.SerializeObject(lists); LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), true, transactionid); strJsonResult = JsonHelper.ReturnJson(true, Convert.ToInt32(error.Code), error.Info, json); result = true; } while (false); } catch (Exception ex) { error.Code = ErrorCode.Exception; LoggerHelper.Info(admin.UserAccount, funname, paramstr, Convert.ToString(error.Code), false, transactionid); LoggerHelper.Error("SystemReportManager调用ExportPasswordStateUsersToExcel异常", paramstr, ex.ToString(), transactionid); strJsonResult = JsonHelper.ReturnJson(false, Convert.ToInt32(error.Code), error.Info); result = false; } return(result); }