protected void cmdExport_Click(object sender, EventArgs e)
        {
            try
            {
                string   Checkbox_Value       = WebHelper.GetStringParam(Request, "Checkbox", "");
                string[] Checkbox_Value_Array = Checkbox_Value.Split(',');
                Int32    IDX = 0;

                List <DNNGo_PowerForms_Content> DataList = new List <DNNGo_PowerForms_Content>();
                for (int i = 0; i < Checkbox_Value_Array.Length; i++)
                {
                    if (Int32.TryParse(Checkbox_Value_Array[i], out IDX))
                    {
                        DNNGo_PowerForms_Content ContentItem = DNNGo_PowerForms_Content.FindByKeyForEdit(IDX);

                        if (ContentItem != null && ContentItem.ID > 0 && !String.IsNullOrEmpty(ContentItem.ContentValue))
                        {
                            //DataList.Add(  Common.Deserialize<List<DNNGo_PowerForms_ContentItem>>(ContentItem.ContentValue));
                            DataList.Add(ContentItem);
                        }
                    }
                }
                if (DataList.Count > 0)
                {
                    try
                    {
                        String FullName = String.Empty;
                        if (CsvHelper.SaveAsToFile(FieldList, DataList, out FullName, this))
                        {
                            FileSystemUtils.DownloadFile(FullName, Path.GetFileName(FullName));
                            //Response.Write(FullName);
                        }
                        else
                        {
                            mTips.LoadMessage("SaveExportRecordsError", EnumTips.Error, this, new String[] { FullName });
                        }
                    }
                    catch (Exception ex)
                    {
                        DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void cmdExportAll_Click(object sender, EventArgs e)
        {
            try
            {
                QueryParam qp = new QueryParam();
                qp.OrderType = 1;
                qp.Orderfld  = DNNGo_PowerForms_Content._.ID;
                qp.PageSize  = int.MaxValue;
                qp.Where     = BindSearch();
                Int32 RecordCount = 0;
                List <DNNGo_PowerForms_Content> DataList = DNNGo_PowerForms_Content.FindAll(qp, out RecordCount);


                if (DataList != null && DataList.Count > 0)
                {
                    try
                    {
                        String FullName = String.Empty;
                        if (CsvHelper.SaveAsToFile(FieldList, DataList, out FullName, this))
                        {
                            FileSystemUtils.DownloadFile(FullName, Path.GetFileName(FullName));

                            //Response.Write(FullName);
                        }
                        else
                        {
                            //导出记录失败
                            mTips.IsPostBack = true;
                            mTips.LoadMessage("SaveExportRecordsError", EnumTips.Error, this, new String[] { FullName });
                        }
                    }
                    catch (Exception ex)
                    {
                        DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 导出表格
        /// </summary>
        /// <param name="SchedulerItem"></param>
        /// <returns></returns>
        public String ExportExcel(DNNGo_PowerForms_Scheduler SchedulerItem, Int32 index)
        {
            String Attachment = String.Empty;
            List <DNNGo_PowerForms_Content> DataList  = DNNGo_PowerForms_Content.FindAllByModuleId(SchedulerItem.ModuleId);
            List <DNNGo_PowerForms_Field>   FieldList = DNNGo_PowerForms_Field.FindAllByModuleId(SchedulerItem.ModuleId);

            if (DataList != null && DataList.Count > 0)
            {
                if (FieldList != null && FieldList.Count > 0)
                {
                    String FileName = SchedulerItem.ExcelName;
                    FileName = Common.ReplaceNoCase(FileName, "{yyyy}", DateTime.Now.ToString("yyyy"));
                    FileName = Common.ReplaceNoCase(FileName, "{mm}", DateTime.Now.ToString("MM"));
                    FileName = Common.ReplaceNoCase(FileName, "{dd}", DateTime.Now.ToString("dd"));
                    FileName = Common.ReplaceNoCase(FileName, "{time}", DateTime.Now.ToString("HHmmss"));
                    FileName = Common.ReplaceNoCase(FileName, "{ModuleID}", SchedulerItem.ModuleId.ToString());

                    Attachment = String.Format("{0}temp\\PowerForms\\{1}.xls", HttpRuntime.AppDomainAppPath, FileName);

                    try
                    {
                        CsvHelper.SaveAsToFile(FieldList, DataList, Attachment, false);
                    }
                    catch (Exception exc)
                    {
                        this.ScheduleHistoryItem.AddLogNote(exc.Source);
                    }
                }
                else
                {
                    this.ScheduleHistoryItem.AddLogNote(String.Format("task {0},field list is empty,Has ignored. time:{1}<br />", index, DateTime.Now.ToString()));
                }
            }
            else
            {
                this.ScheduleHistoryItem.AddLogNote(String.Format("task {0},History records is empty,Has ignored. time:{1}<br />", index, DateTime.Now.ToString()));
            }
            return(Attachment);
        }