public IHttpActionResult Export() { try { var request = Context.GetCurrentRequest(); var formInfo = FormManager.GetFormInfoByPost(request); if (formInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.PluginId)) { return(Unauthorized()); } var fieldInfoList = FieldManager.GetFieldInfoList(formInfo.Id); var logs = LogDao.GetLogInfoList(formInfo.Id, false, 0, formInfo.TotalCount); var head = new List <string> { "序号" }; foreach (var fieldInfo in fieldInfoList) { head.Add(fieldInfo.Title); } head.Add("添加时间"); var rows = new List <List <string> >(); var index = 1; foreach (var log in logs) { var row = new List <string> { index++.ToString() }; foreach (var fieldInfo in fieldInfoList) { row.Add(log.GetString(fieldInfo.Title)); } row.Add(log.AddDate.ToString("yyyy-MM-dd HH:mm")); rows.Add(row); } var relatedPath = "表单数据.csv"; CsvUtils.Export(Context.PluginApi.GetPluginPath(FormUtils.PluginId, relatedPath), head, rows); var downloadUrl = Context.PluginApi.GetPluginUrl(FormUtils.PluginId, relatedPath); return(Ok(new { Value = downloadUrl })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static void CreateExcelFileForComments(string filePath, PublishmentSystemInfo publishmentSystemInfo, int nodeId, int contentId) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); head.Add("用户"); head.Add("评论"); head.Add("添加时间"); var commentInfoList = DataProvider.CommentDao.GetCommentInfoListChecked(publishmentSystemInfo.PublishmentSystemId, nodeId, contentId, 10000, 0); foreach (var commentInfo in commentInfoList) { var row = new List <string> { commentInfo.UserName, StringUtils.StripTags(commentInfo.Content), DateUtils.GetDateAndTimeString(commentInfo.AddDate) }; rows.Add(row); } CsvUtils.Export(filePath, head, rows); }
public async Task CreateExcelFileForAdministratorsAsync(string filePath) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string> { "用户名", "姓名", "邮箱", "手机", "添加时间", "最后一次活动时间" }; var rows = new List <List <string> >(); var userIdList = await _databaseManager.AdministratorRepository.GetUserIdsAsync(); foreach (var userId in userIdList) { var administrator = await _databaseManager.AdministratorRepository.GetByUserIdAsync(userId); rows.Add(new List <string> { administrator.UserName, administrator.DisplayName, administrator.Email, administrator.Mobile, DateUtils.GetDateAndTimeString(administrator.CreatedDate), DateUtils.GetDateAndTimeString(administrator.LastActivityDate) }); } CsvUtils.Export(filePath, head, rows); }
public async Task <ActionResult <StringResult> > Export([FromBody] FormRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, FormManager.PermissionsForms)) { return(Unauthorized()); } var formInfo = await _formRepository.GetFormInfoAsync(request.SiteId, request.FormId); if (formInfo == null) { return(NotFound()); } var styles = await _formManager.GetTableStylesAsync(formInfo.Id); var logs = await _dataRepository.GetAllDataInfoListAsync(formInfo); var head = new List <string> { "编号" }; foreach (var style in styles) { head.Add(style.DisplayName); } head.Add("添加时间"); var rows = new List <List <string> >(); foreach (var log in logs) { var row = new List <string> { log.Guid }; foreach (var style in styles) { row.Add(_dataRepository.GetValue(style, log)); } if (log.CreatedDate.HasValue) { row.Add(log.CreatedDate.Value.ToString("yyyy-MM-dd HH:mm")); } rows.Add(row); } var fileName = $"{formInfo.Title}.csv"; CsvUtils.Export(_pathManager.GetTemporaryFilesPath(fileName), head, rows); var downloadUrl = _pathManager.GetTemporaryFilesUrl(fileName); return(new StringResult { Value = downloadUrl }); }
public static void CreateExcelFileForContents(string filePath, PublishmentSystemInfo publishmentSystemInfo, NodeInfo nodeInfo, List <int> contentIdList, List <string> displayAttributes, bool isPeriods, string startDate, string endDate, ETriState checkedState) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var relatedidentityes = RelatedIdentities.GetChannelRelatedIdentities(publishmentSystemInfo.PublishmentSystemId, nodeInfo.NodeId); var modelInfo = ContentModelManager.GetContentModelInfo(publishmentSystemInfo, nodeInfo.ContentModelId); var tableStyle = NodeManager.GetTableStyle(publishmentSystemInfo, nodeInfo); var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(tableStyle, modelInfo.TableName, relatedidentityes); tableStyleInfoList = ContentUtility.GetAllTableStyleInfoList(publishmentSystemInfo, tableStyle, tableStyleInfoList); var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeInfo); foreach (var tableStyleInfo in tableStyleInfoList) { if (displayAttributes.Contains(tableStyleInfo.AttributeName)) { head.Add(tableStyleInfo.DisplayName); } } if (contentIdList == null || contentIdList.Count == 0) { contentIdList = BaiRongDataProvider.ContentDao.GetContentIdList(tableName, nodeInfo.NodeId, isPeriods, startDate, endDate, checkedState); } foreach (var contentId in contentIdList) { var contentInfo = DataProvider.ContentDao.GetContentInfo(tableStyle, tableName, contentId); if (contentInfo != null) { var row = new List <string>(); foreach (var tableStyleInfo in tableStyleInfoList) { if (displayAttributes.Contains(tableStyleInfo.AttributeName)) { var value = contentInfo.GetExtendedAttribute(tableStyleInfo.AttributeName); row.Add(StringUtils.StripTags(value)); } } rows.Add(row); } } CsvUtils.Export(filePath, head, rows); }
public void ExportLotteryCsv(string filePath, List <LotteryWinnerInfo> winnerInfoList) { var head = new List <string>(); head.Add("序号"); head.Add("奖项"); head.Add("姓名"); head.Add("手机"); head.Add("邮箱"); head.Add("地址"); head.Add("状态"); head.Add("中奖时间"); head.Add("兑奖码"); head.Add("兑奖时间"); var rows = new List <List <string> >(); var index = 1; foreach (var winnerInfo in winnerInfoList) { LotteryAwardInfo awardInfo = null; if (_awardInfoMap.ContainsKey(winnerInfo.AwardId)) { awardInfo = _awardInfoMap[winnerInfo.AwardId]; } else { awardInfo = DataProviderWx.LotteryAwardDao.GetAwardInfo(winnerInfo.AwardId); _awardInfoMap.Add(winnerInfo.AwardId, awardInfo); } var award = string.Empty; if (awardInfo != null) { award = awardInfo.AwardName + ":" + awardInfo.Title; } var row = new List <string>(); row.Add((index++).ToString()); row.Add(award); row.Add(winnerInfo.RealName); row.Add(winnerInfo.Mobile); row.Add(winnerInfo.Email); row.Add(winnerInfo.Address); row.Add(EWinStatusUtils.GetText(EWinStatusUtils.GetEnumType(winnerInfo.Status))); row.Add(DateUtils.GetDateAndTimeString(winnerInfo.AddDate)); row.Add(winnerInfo.CashSn); row.Add(DateUtils.GetDateAndTimeString(winnerInfo.CashDate)); rows.Add(row); } CsvUtils.Export(filePath, head, rows); }
public static void CreateExcelFileForTrackingHours(string filePath, int publishmentSystemId) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var trackingHourHashtable = DataProvider.TrackingDao.GetTrackingHourHashtable(publishmentSystemId); var uniqueTrackingHourHashtable = DataProvider.TrackingDao.GetUniqueTrackingHourHashtable(publishmentSystemId); head.Add("时间段"); head.Add("访问量"); head.Add("访客数"); var maxAccessNum = 0; var uniqueMaxAccessNum = 0; var now = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0); for (var i = 0; i < 24; i++) { var datetime = now.AddHours(-i); var accessNum = 0; if (trackingHourHashtable[datetime] != null) { accessNum = (int)trackingHourHashtable[datetime]; } if (accessNum > maxAccessNum) { maxAccessNum = accessNum; } var uniqueAccessNum = 0; if (uniqueTrackingHourHashtable[datetime] != null) { uniqueAccessNum = (int)uniqueTrackingHourHashtable[datetime]; } if (uniqueAccessNum > uniqueMaxAccessNum) { uniqueMaxAccessNum = uniqueAccessNum; } var row = new List <string> { datetime.Hour.ToString(), accessNum.ToString(), uniqueAccessNum.ToString() }; rows.Add(row); } CsvUtils.Export(filePath, head, rows); }
public static void CreateExcelFileForContents(string filePath, SiteInfo siteInfo, ChannelInfo channelInfo, List <int> contentIdList, List <string> displayAttributes, bool isPeriods, string startDate, string endDate, ETriState checkedState) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var tableName = ChannelManager.GetTableName(siteInfo, channelInfo); var styleInfoList = ContentUtility.GetAllTableStyleInfoList(TableStyleManager.GetContentStyleInfoList(siteInfo, channelInfo)); foreach (var styleInfo in styleInfoList) { if (displayAttributes.Contains(styleInfo.AttributeName)) { head.Add(styleInfo.DisplayName); } } if (contentIdList == null || contentIdList.Count == 0) { contentIdList = DataProvider.ContentDao.GetContentIdList(tableName, channelInfo.Id, isPeriods, startDate, endDate, checkedState); } foreach (var contentId in contentIdList) { var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId); if (contentInfo != null) { var row = new List <string>(); foreach (var styleInfo in styleInfoList) { if (displayAttributes.Contains(styleInfo.AttributeName)) { var value = contentInfo.GetString(styleInfo.AttributeName); row.Add(StringUtils.StripTags(value)); } } rows.Add(row); } } CsvUtils.Export(filePath, head, rows); }
public async Task CreateExcelFileForContentsAsync(string filePath, Site site, Channel channel, IEnumerable <int> contentIdList, List <string> displayAttributes, bool isPeriods, string startDate, string endDate, bool?checkedState) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var styles = ColumnsManager.GetContentListStyles(await _databaseManager.TableStyleRepository.GetContentStylesAsync(site, channel)); foreach (var style in styles) { if (displayAttributes.Contains(style.AttributeName)) { head.Add(style.DisplayName); } } if (contentIdList == null) { contentIdList = await _databaseManager.ContentRepository.GetContentIdsAsync(site, channel, isPeriods, startDate, endDate, checkedState); } foreach (var contentId in contentIdList) { var contentInfo = await _databaseManager.ContentRepository.GetAsync(site, channel, contentId); if (contentInfo != null) { var row = new List <string>(); foreach (var style in styles) { if (displayAttributes.Contains(style.AttributeName)) { var value = contentInfo.Get <string>(style.AttributeName); row.Add(StringUtils.StripTags(value)); } } rows.Add(row); } } CsvUtils.Export(filePath, head, rows); }
public async Task CreateExcelFileForUsersAsync(string filePath, bool?checkedState) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string> { "用户名", "姓名", "邮箱", "手机", "注册时间", "最后一次活动时间" }; var rows = new List <List <string> >(); List <int> userIdList; if (checkedState.HasValue) { userIdList = (await _databaseManager.UserRepository.GetUserIdsAsync(checkedState.Value)).ToList(); } else { userIdList = (await _databaseManager.UserRepository.GetUserIdsAsync(true)).ToList(); userIdList.AddRange(await _databaseManager.UserRepository.GetUserIdsAsync(false)); } foreach (var userId in userIdList) { var userInfo = await _databaseManager.UserRepository.GetByUserIdAsync(userId); rows.Add(new List <string> { userInfo.UserName, userInfo.DisplayName, userInfo.Email, userInfo.Mobile, DateUtils.GetDateAndTimeString(userInfo.CreatedDate), DateUtils.GetDateAndTimeString(userInfo.LastActivityDate) }); } CsvUtils.Export(filePath, head, rows); }
public void BtnExport_Click(object sender, EventArgs e) { int totalCount; var itemInfoList = Main.ItemDao.GetItemInfoList(_pollInfo.Id, out totalCount); var head = new List <string> { "序号", "标题", "票数", "占比" }; var rows = new List <List <string> >(); var index = 1; foreach (var itemInfo in itemInfoList) { double percent; if (totalCount == 0) { percent = 0; } else { var d = Convert.ToDouble(itemInfo.Count) / Convert.ToDouble(totalCount) * 100; percent = Math.Round(d, 2); } var row = new List <string> { index++.ToString(), itemInfo.Title, itemInfo.Count.ToString(), percent + "%" }; rows.Add(row); } var relatedPath = "投票统计.csv"; CsvUtils.Export(Main.FilesApi.GetPluginPath(relatedPath), head, rows); HttpContext.Current.Response.Redirect(Main.FilesApi.GetPluginUrl(relatedPath)); }
public static void CreateExcelFileForUsers(string filePath, ETriState checkedState) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string> { "用户名", "姓名", "邮箱", "手机", "用户组", "注册时间", "最后一次活动时间" }; var rows = new List <List <string> >(); var userIdList = BaiRongDataProvider.UserDao.GetUserIdList(checkedState != ETriState.False); if (checkedState == ETriState.All) { userIdList.AddRange(BaiRongDataProvider.UserDao.GetUserIdList(false)); } foreach (var userId in userIdList) { var userInfo = BaiRongDataProvider.UserDao.GetUserInfo(userId); rows.Add(new List <string> { userInfo.UserName, userInfo.DisplayName, userInfo.Email, userInfo.Mobile, UserGroupManager.GetGroupName(userInfo.GroupId), DateUtils.GetDateAndTimeString(userInfo.CreateDate), DateUtils.GetDateAndTimeString(userInfo.LastActivityDate) }); } CsvUtils.Export(filePath, head, rows); }
public async Task <ActionResult <StringResult> > Export([FromBody] CommentRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, CommentManager.PermissionsManage)) { return(Unauthorized()); } var comments = await _commentRepository.GetCommentsAsync(request.SiteId, request.ChannelId, request.ContentId); var head = new List <string> { "编号", "评论", "添加时间" }; var rows = new List <List <string> >(); foreach (var comment in comments) { var row = new List <string> { comment.Guid, comment.Content }; if (comment.CreatedDate.HasValue) { row.Add(comment.CreatedDate.Value.ToString("yyyy-MM-dd HH:mm")); } rows.Add(row); } const string fileName = "评论.csv"; CsvUtils.Export(_pathManager.GetTemporaryFilesPath(fileName), head, rows); var downloadUrl = _pathManager.GetTemporaryFilesUrl(fileName); return(new StringResult { Value = downloadUrl }); }
public void BtnExport_Click(object sender, EventArgs e) { var logs = Main.Instance.LogDao.GetAllFormLogInfoList(FormInfo.Id); var head = new List <string> { "序号" }; foreach (var fieldInfo in _fieldInfoList) { head.Add(fieldInfo.Title); } head.Add("提交时间"); var rows = new List <List <string> >(); var index = 1; foreach (var log in logs) { var row = new List <string> { index++.ToString() }; foreach (var fieldInfo in _fieldInfoList) { row.Add(log.GetString(fieldInfo.Title)); } row.Add(log.AddDate.ToString("yyyy-MM-dd HH:mm")); rows.Add(row); } var relatedPath = "表单清单.csv"; CsvUtils.Export(Main.Instance.PluginApi.GetPluginPath(relatedPath), head, rows); HttpContext.Current.Response.Redirect(Main.Instance.PluginApi.GetPluginUrl(relatedPath)); }
public async Task CreateExcelFileForContentsAsync(string filePath, Site site, Channel channel, List <Content> contentInfoList, List <string> columnNames) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var columnsManager = new ColumnsManager(_databaseManager, _pathManager); var columns = await columnsManager.GetContentListColumnsAsync(site, channel, ColumnsManager.PageType.Contents); foreach (var column in columns) { if (ListUtils.ContainsIgnoreCase(columnNames, column.AttributeName)) { head.Add(column.DisplayName); } } foreach (var contentInfo in contentInfoList) { var row = new List <string>(); foreach (var column in columns) { if (ListUtils.ContainsIgnoreCase(columnNames, column.AttributeName)) { var value = contentInfo.Get <string>(column.AttributeName); row.Add(StringUtils.StripTags(value)); } } rows.Add(row); } CsvUtils.Export(filePath, head, rows); }
public static void CreateExcelFileForContents(string filePath, SiteInfo siteInfo, ChannelInfo channelInfo, List <ContentInfo> contentInfoList, List <string> columnNames) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var columns = ContentManager.GetContentColumns(siteInfo, channelInfo, true); foreach (var column in columns) { if (StringUtils.ContainsIgnoreCase(columnNames, column.AttributeName)) { head.Add(column.DisplayName); } } foreach (var contentInfo in contentInfoList) { var row = new List <string>(); foreach (var column in columns) { if (StringUtils.ContainsIgnoreCase(columnNames, column.AttributeName)) { var value = contentInfo.GetString(column.AttributeName); row.Add(StringUtils.StripTags(value)); } } rows.Add(row); } CsvUtils.Export(filePath, head, rows); }
public void ExportAppointmentContentCsv(string filePath, List <AppointmentContentInfo> appointmentContentInfolList, string appointmentTitle, int appointmentId) { var appointmentInfo = DataProviderWx.AppointmentDao.GetAppointmentInfo(appointmentId); var head = new List <string>(); head.Add("序号"); head.Add("预约名称"); if (appointmentInfo.IsFormRealName == "True") { head.Add(appointmentInfo.FormRealNameTitle); } if (appointmentInfo.IsFormMobile == "True") { head.Add(appointmentInfo.FormMobileTitle); } if (appointmentInfo.IsFormEmail == "True") { head.Add(appointmentInfo.FormEmailTitle); } head.Add("预约时间"); head.Add("预约状态"); head.Add("留言"); var configExtendInfoList = DataProviderWx.ConfigExtendDao.GetConfigExtendInfoList(PublishmentSystemId, appointmentId, EKeywordTypeUtils.GetValue(EKeywordType.Appointment)); foreach (var cList in configExtendInfoList) { head.Add(cList.AttributeName); } var rows = new List <List <string> >(); var index = 1; foreach (var applist in appointmentContentInfolList) { var row = new List <string>(); row.Add((index++).ToString()); row.Add(appointmentTitle); if (appointmentInfo.IsFormRealName == "True") { row.Add(applist.RealName); } if (appointmentInfo.IsFormMobile == "True") { row.Add(applist.Mobile); } if (appointmentInfo.IsFormEmail == "True") { row.Add(applist.Email); } row.Add(DateUtils.GetDateAndTimeString(applist.AddDate)); row.Add(EAppointmentStatusUtils.GetText(EAppointmentStatusUtils.GetEnumType(applist.Status))); row.Add(applist.Message); var settingsXml = applist.SettingsXml.Replace("{", "").Replace("}", ""); var arr = settingsXml.Split(','); if (arr[0] != "") { for (var i = 0; i < arr.Length; i++) { var arr1 = arr[i].Replace("\"", "").Split(':'); row.Add(arr1[1]); } } rows.Add(row); } CsvUtils.Export(filePath, head, rows); }
public IHttpActionResult Export() { try { var request = Context.AuthenticatedRequest; var formInfo = FormManager.GetFormInfoByPost(request); if (formInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(formInfo.SiteId, FormUtils.MenuFormsPermission)) { return(Unauthorized()); } var fieldInfoList = FieldManager.GetFieldInfoList(formInfo.Id); var logs = LogManager.Repository.GetAllLogInfoList(formInfo); var head = new List <string> { "编号" }; foreach (var fieldInfo in fieldInfoList) { head.Add(fieldInfo.Title); } head.Add("添加时间"); var rows = new List <List <string> >(); foreach (var log in logs) { var row = new List <string> { log.Guid }; foreach (var fieldInfo in fieldInfoList) { row.Add(LogManager.GetValue(fieldInfo, log)); } if (log.AddDate.HasValue) { row.Add(log.AddDate.Value.ToString("yyyy-MM-dd HH:mm")); } rows.Add(row); } var fileName = $"{formInfo.Title}.csv"; CsvUtils.Export(Context.PluginApi.GetPluginPath(FormUtils.PluginId, fileName), head, rows); var downloadUrl = Context.PluginApi.GetPluginUrl(FormUtils.PluginId, fileName); return(Ok(new { Value = downloadUrl })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public void BtnExport_Click(object sender, EventArgs e) { var head = new List <string> { "标题", "序号", "选项", "票数", "占比" }; var rows = new List <List <string> >(); var index = 1; foreach (var fieldInfo in _fieldInfoList) { if (fieldInfo.Items == null || fieldInfo.Items.Count == 0) { continue; } if (Utils.IsSelectFieldType(fieldInfo.FieldType)) { continue; } rows.Add(new List <string> { fieldInfo.Title, string.Empty, string.Empty, string.Empty, string.Empty }); var logTotalCount = GetLogTotalCount(fieldInfo, _logInfoList); var isMultiple = fieldInfo.FieldType == InputType.CheckBox.Value || fieldInfo.FieldType == InputType.SelectMultiple.Value; foreach (var itemInfo in fieldInfo.Items) { var itemCount = 0; foreach (var logInfo in _logInfoList) { var value = logInfo.GetString(fieldInfo.Title); if (isMultiple) { List <string> values = null; try { values = JsonConvert.DeserializeObject <List <string> >(value); } catch { // ignored } if (values != null) { if (values.Contains(itemInfo.Value)) { itemCount++; } } } else { if (value == itemInfo.Value) { itemCount++; } } } double percent; if (logTotalCount == 0) { percent = 0; } else { var d = Convert.ToDouble(itemCount) / Convert.ToDouble(logTotalCount) * 100; percent = Math.Round(d, 2); } rows.Add(new List <string> { string.Empty, index++.ToString(), itemInfo.Value, itemCount.ToString(), percent + "%" }); } } var relatedPath = "数据统计.csv"; CsvUtils.Export(Main.Instance.PluginApi.GetPluginPath(relatedPath), head, rows); HttpContext.Current.Response.Redirect(Main.Instance.PluginApi.GetPluginUrl(relatedPath)); }
public IHttpActionResult Export() { try { var request = Context.AuthenticatedRequest; var pollInfo = PollManager.GetPollInfo(request); if (pollInfo == null) { return(NotFound()); } if (!request.IsAdminLoggin || !request.AdminPermissions.HasSitePermissions(pollInfo.SiteId, PollUtils.PluginId)) { return(Unauthorized()); } var itemInfoList = ItemManager.GetItemInfoList(pollInfo.Id); var totalCount = itemInfoList.Sum(x => x.Count); var head = new List <string> { "序号", "标题", "票数", "占比" }; var rows = new List <List <string> >(); var index = 1; foreach (var itemInfo in itemInfoList) { double percent; if (totalCount == 0) { percent = 0; } else { var d = Convert.ToDouble(itemInfo.Count) / Convert.ToDouble(totalCount) * 100; percent = Math.Round(d, 2); } var row = new List <string> { index++.ToString(), itemInfo.Title, itemInfo.Count.ToString(), percent + "%" }; rows.Add(row); } var fileName = "投票统计.csv"; var filePath = Context.UtilsApi.GetTemporaryFilesPath(fileName); CsvUtils.Export(filePath, head, rows); var url = Context.UtilsApi.GetRootUrl($"SiteFiles/TemporaryFiles/{fileName}"); return(Ok(new { Value = url })); } catch (Exception ex) { return(InternalServerError(ex)); } }
public static void CreateExcelFileForInputContents(string filePath, PublishmentSystemInfo publishmentSystemInfo, InputInfo inputInfo) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string>(); var rows = new List <List <string> >(); var relatedidentityes = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent, publishmentSystemInfo.PublishmentSystemId, inputInfo.InputID); var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent, DataProvider.InputContentDao.TableName, relatedidentityes); if (tableStyleInfoList.Count == 0) { throw new Exception("表单无字段,无法导出"); } foreach (var tableStyleInfo in tableStyleInfoList) { head.Add(tableStyleInfo.DisplayName); } if (inputInfo.IsReply) { head.Add("回复"); } head.Add("添加时间"); var contentIdList = DataProvider.InputContentDao.GetContentIdListWithChecked(inputInfo.InputID); foreach (var contentId in contentIdList) { var contentInfo = DataProvider.InputContentDao.GetContentInfo(contentId); if (contentInfo != null) { var row = new List <string>(); foreach (var tableStyleInfo in tableStyleInfoList) { var value = contentInfo.Attributes.Get(tableStyleInfo.AttributeName); if (!string.IsNullOrEmpty(value)) { value = InputParserUtility.GetContentByTableStyle(value, publishmentSystemInfo, ETableStyle.InputContent, tableStyleInfo); } row.Add(StringUtils.StripTags(value)); } if (inputInfo.IsReply) { row.Add(StringUtils.StripTags(contentInfo.Reply)); } row.Add(DateUtils.GetDateAndTimeString(contentInfo.AddDate)); rows.Add(row); } } CsvUtils.Export(filePath, head, rows); }
public static void CreateExcelFileForTrackingContents(string filePath, string startDateString, string endDateString, PublishmentSystemInfo publishmentSystemInfo, int nodeId, int contentId, int totalNum, bool isDelete) { DirectoryUtils.CreateDirectoryIfNotExists(DirectoryUtils.GetDirectoryPath(filePath)); FileUtils.DeleteFileIfExists(filePath); var head = new List <string> { "目标页面", "上级栏目", "上上级栏目", "IP地址", "访问时间", "访问来源" }; var rows = new List <List <string> >(); var target = string.Empty; var upChannel = string.Empty; var upupChannel = string.Empty; if (contentId != 0) { var tableName = NodeManager.GetTableName(publishmentSystemInfo, nodeId); target = BaiRongDataProvider.ContentDao.GetValue(tableName, contentId, ContentAttribute.Title); upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, nodeId); if (nodeId != publishmentSystemInfo.PublishmentSystemId) { upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, nodeId)); } } var begin = DateUtils.SqlMinValue; if (!string.IsNullOrEmpty(startDateString)) { begin = TranslateUtils.ToDateTime(startDateString); } var end = TranslateUtils.ToDateTime(endDateString); var ipAddresses = DataProvider.TrackingDao.GetContentIpAddressArrayList(publishmentSystemInfo.PublishmentSystemId, nodeId, contentId, begin, end); var trackingInfoArrayList = DataProvider.TrackingDao.GetTrackingInfoArrayList(publishmentSystemInfo.PublishmentSystemId, nodeId, contentId, begin, end); var ipAddressWithNumSortedList = new SortedList(); foreach (string ipAddress in ipAddresses) { if (ipAddressWithNumSortedList[ipAddress] != null) { ipAddressWithNumSortedList[ipAddress] = (int)ipAddressWithNumSortedList[ipAddress] + 1; } else { ipAddressWithNumSortedList[ipAddress] = 1; } } foreach (TrackingInfo trackingInfo in trackingInfoArrayList) { if (contentId == 0) { if (trackingInfo.PageContentId != 0) { var tableName = NodeManager.GetTableName(publishmentSystemInfo, trackingInfo.PageNodeId); target = BaiRongDataProvider.ContentDao.GetValue(tableName, trackingInfo.PageContentId, ContentAttribute.Title); upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, trackingInfo.PageNodeId); if (trackingInfo.PageNodeId != publishmentSystemInfo.PublishmentSystemId) { upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, trackingInfo.PageNodeId)); } } else if (trackingInfo.PageNodeId != 0) { target = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, trackingInfo.PageNodeId); if (trackingInfo.PageNodeId != publishmentSystemInfo.PublishmentSystemId) { var upChannelId = NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, trackingInfo.PageNodeId); upChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, upChannelId); if (upChannelId != publishmentSystemInfo.PublishmentSystemId) { upupChannel = NodeManager.GetNodeName(publishmentSystemInfo.PublishmentSystemId, NodeManager.GetParentId(publishmentSystemInfo.PublishmentSystemId, upChannelId)); } } } } var ipAddress = trackingInfo.IpAddress; var accessDate = trackingInfo.AccessDateTime.ToString(DateUtils.FormatStringDateTime); var referrer = trackingInfo.Referrer; rows.Add(new List <string> { target, upChannel, upupChannel, ipAddress, accessDate, referrer }); } CsvUtils.Export(filePath, head, rows); if (isDelete) { DataProvider.TrackingDao.DeleteAll(publishmentSystemInfo.PublishmentSystemId); } }