Example #1
0
        public async Task <IActionResult> GetFormOptions(Guid id)
        {
            var options = await _formDesignOptionsRepository.FindAsIQueryable(x => x.FormId == id)
                          .Select(s => new { s.Title, s.FormOptions })
                          .FirstOrDefaultAsync();

            return(Json(new { data = options }));
        }
Example #2
0
        public override WebResponseContent Export(PageDataOptions pageData)
        {
            string             path        = null;
            string             fileName    = null;
            WebResponseContent webResponse = new WebResponseContent();

            ExportOnExecuting = (List <FormCollectionObject> list, List <string> columns) =>
            {
                var formId = list[0].FormId;
                var data   = _designOptionsRepository.FindAsIQueryable(x => x.FormId == formId)
                             .Select(s => new { s.Title, s.FormConfig }).FirstOrDefault();
                try
                {
                    List <FormOptions> formObj = data.FormConfig.DeserializeObject <List <FormOptions> >();
                    List <Dictionary <string, object> > listDic = new List <Dictionary <string, object> >();
                    foreach (var item in list)
                    {
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        var formData = item.FormData.DeserializeObject <Dictionary <string, string> >();
                        dic.Add("标题", data.Title);

                        dic.Add("提交人", item.Creator);
                        dic.Add("提交时间", item.CreateDate.ToString("yyyy-MM-dd HH:mm:sss"));
                        foreach (var obj in formObj)
                        {
                            dic.Add(obj.Title, formData.Where(x => x.Key == obj.Field).Select(s => s.Value).FirstOrDefault());
                        }
                        listDic.Add(dic);
                    }
                    fileName = data.Title + ".xlsx";
                    path     = EPPlusHelper.ExportGeneralExcel(listDic, fileName);
                }
                catch (Exception ex)
                {
                    Logger.Error($"解析表单出错:{data.Title},表单配置:{data.FormConfig},{ex.Message}");
                    return(webResponse.Error("获取表单出错"));
                }
                webResponse.Code = "-1";
                return(webResponse.OK(null, path.EncryptDES(AppSetting.Secret.ExportFile)));
            };
            return(base.Export(pageData));
        }