コード例 #1
0
        public JsonResult ExportExcel()
        {
            string code = QueryString("UICode");

            code.CheckNotNullOrEmpty("UICode");
            var listConfig = UnitOfWork.GetSingle <ListConfig>(a => a.UICode == code);

            listConfig.CheckNotNull("listConfig");
            var colList = listConfig.GetColumnList();//列设置

            #region 数据库数据
            string sql = listConfig.SQL;
            if (!string.IsNullOrEmpty(listConfig.OrderBy))
            {
                if (!listConfig.OrderBy.ToLower().Contains("order") && !listConfig.OrderBy.ToLower().Contains("by"))
                {
                    sql += (" order by " + listConfig.OrderBy);
                }
                else
                {
                    sql += (" " + listConfig.OrderBy);
                }
            }
            var res = UnitOfWork.DynamicListFromSql(listConfig.DBName, sql);
            #endregion
            //fieldName替换为标题
            var dt = DictionaryExtend.ConvertDicToTable(res.ToList());
            foreach (DataColumn dataCol in dt.Columns)
            {
                var colItem = colList.FirstOrDefault(a => a.GetValue("field") == dataCol.ColumnName);
                if (colItem != null)
                {
                    dataCol.ColumnName = colItem.GetValue("title");
                }
            }
            NPOIExcelHelper.ExportByWeb(dt, listConfig.Name, listConfig.Name);
            return(Json(""));
        }
コード例 #2
0
        public ActionResult Export(long id = 0)
        {
            if (id > 0)
            {
                var model = ActivityJoinBLL.Instance.GetJoinList(id);

                if (model.PartyInfo.UserID == UserID || UserBaseBLL.Instance.IsRoot)
                {
                    var partyInfo = model.PartyInfo;
                    if (partyInfo != null)
                    {
                        var joinQuestions = model.JoinQuestions;
                        var joinAnswers   = model.JoinAnswers;

                        DataTable dt = new DataTable();
                        dt.Columns.Add(new DataColumn("活动名称"));
                        dt.Columns.Add(new DataColumn("昵称"));
                        dt.Columns.Add(new DataColumn("姓名"));
                        dt.Columns.Add(new DataColumn("手机"));
                        dt.Columns.Add(new DataColumn("票种"));
                        dt.Columns.Add(new DataColumn("数量"));
                        dt.Columns.Add(new DataColumn("付费类型"));
                        dt.Columns.Add(new DataColumn("单价"));
                        dt.Columns.Add(new DataColumn("实付金额"));
                        dt.Columns.Add(new DataColumn("付费状态"));
                        dt.Columns.Add(new DataColumn("报名时间"));
                        joinQuestions.ForEach(a =>
                        {
                            dt.Columns.Add(new DataColumn(a.ItemName));
                        });

                        var    lsit = model.JoinList;
                        string none = "-";
                        lsit.ForEach(join =>
                        {
                            DataRow dr = dt.NewRow();
                            dr["活动名称"] = partyInfo.Title;
                            dr["昵称"]   = join.JoinUserName;
                            dr["姓名"]   = join.LinkMan ?? join.JoinUserName;
                            dr["手机"]   = join.LinkTel ?? none;
                            dr["票种"]   = join.FeeName;
                            dr["数量"]   = join.JoinCount;
                            dr["付费类型"] = join.FeeType == 0 ? "免费" : join.FeeType == 10 ? "积分付费" : join.FeeType == 20 ? "VIP分付费" : "RMB付费";
                            dr["单价"]   = join.ItemSourceFee;
                            dr["实付金额"] = join.RealPayFee;
                            dr["付费状态"] = join.IsFeed == 1 ? "已付费" : "未付费";
                            dr["报名时间"] = join.JoinTime;
                            joinQuestions.ForEach(a =>
                            {
                                var answer     = joinAnswers.FirstOrDefault(joinanswer => { return(joinanswer.JoinItemQuestionExtId == a.JoinItemQuestionExtId && joinanswer.BuyerID == join.JoinUserID); });
                                dr[a.ItemName] = answer == null ? none : answer.ItemAnswer;
                            });
                            dt.Rows.Add(dr);
                        });
                        NPOIExcelHelper.ExportByWeb(dt, "活动报名信息", "活动报名信息.xls");
                    }
                    return(Redirect(Request.Url.AbsoluteUri));
                }
                else
                {
                    return(RedirectToAction("Index", "Party"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Party"));
            }
        }
コード例 #3
0
        public ActionResult Export(int gtype, long id = 0)
        {
            if (id > 0)
            {
                var model = UserGiftBLL.Instance.GetBuyerList(id, gtype == 1 ? JoinItemTypeEnum.Gift : gtype == 2 ? JoinItemTypeEnum.DataAnalysis : JoinItemTypeEnum.KeCheng);

                if (model.GiftInfo.GiftCreateUserID == UserID || UserBaseBLL.Instance.IsRoot)
                {
                    string desc      = gtype == 1 ? "礼品" : gtype == 2 ? "数据" : "百晓堂课程";
                    var    partyInfo = model.GiftInfo;
                    if (partyInfo != null)
                    {
                        var    joinQuestions = model.JoinQuestions;
                        var    joinAnswers   = model.JoinAnswers;
                        string mainName      = "{0}名称".FormatWith(desc);

                        DataTable dt = new DataTable();
                        dt.Columns.Add(new DataColumn(mainName));
                        dt.Columns.Add(new DataColumn("昵称"));
                        dt.Columns.Add(new DataColumn("姓名"));
                        dt.Columns.Add(new DataColumn("手机"));
                        dt.Columns.Add(new DataColumn("票种"));
                        dt.Columns.Add(new DataColumn("数量"));
                        dt.Columns.Add(new DataColumn("付费类型"));
                        dt.Columns.Add(new DataColumn("单价"));
                        dt.Columns.Add(new DataColumn("实付金额"));
                        dt.Columns.Add(new DataColumn("付费状态"));
                        dt.Columns.Add(new DataColumn("购买时间"));
                        joinQuestions.ForEach(a =>
                        {
                            dt.Columns.Add(new DataColumn(a.ItemName));
                        });

                        var    lsit = model.BuyList;
                        string none = "-";
                        lsit.ForEach(join =>
                        {
                            DataRow dr   = dt.NewRow();
                            dr[mainName] = partyInfo.GiftName;
                            dr["昵称"]     = join.BuyerName;
                            dr["姓名"]     = join.LinkMan ?? join.BuyerName;
                            dr["手机"]     = join.LinkTel ?? none;
                            dr["票种"]     = join.FeeName;
                            dr["数量"]     = join.BuyCount;
                            dr["付费类型"]   = join.FeeType == 0 ? "免费" : join.FeeType == 10 ? "积分付费" : join.FeeType == 20 ? "VIP分付费" : "RMB付费";
                            dr["单价"]     = join.ItemSourceFee;
                            dr["实付金额"]   = join.Fee;
                            dr["付费状态"]   = join.IsPay == 1 ? "已付费" : "未付费";
                            dr["购买时间"]   = join.BuyTime;
                            joinQuestions.ForEach(a =>
                            {
                                var answer     = joinAnswers.FirstOrDefault(joinanswer => { return(joinanswer.JoinItemQuestionExtId == a.JoinItemQuestionExtId && joinanswer.BuyerID == join.BuyUserID); });
                                dr[a.ItemName] = answer == null ? none : answer.ItemAnswer;
                            });
                            dt.Rows.Add(dr);
                        });
                        string excelname = "{0}购买信息".FormatWith(desc);
                        NPOIExcelHelper.ExportByWeb(dt, excelname, "{0}.xls".FormatWith(excelname));
                    }
                    return(Redirect(Request.Url.AbsoluteUri));
                }
                else
                {
                    return(RedirectToAction("Index", "Gift"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Gift"));
            }
        }