Пример #1
0
        protected void ShowTemplateView_OnClick(object sender, EventArgs e)
        {
            string query = string.Empty; var templateID = TemplateList.SelectedValue;

            if (String.IsNullOrEmpty(templateID) || templateID == "-1")
            {
                return;
            }

            template = Storage.Select <Template>(templateID);


            var userID = Convert.ToInt32(Session["SystemUser.objID"]);

            UserTemlatePermission.SetFieldsTaboo(userID, template);

            if (template.TreeTypeEnum == TreeType.Undefined || template.TreeTypeEnum == TreeType.General)
            {
                query = CreateObjectDynamicQuery(string.Format(@"declare @sql varchar(max)= '' 
                                    EXEC [report].[getBObjectData]  null, {0}, @cyr = 1, @select=@sql out
                                    select @sql", template.ID));

                dynamicQueryForGeneral = new DynamicQueryForHeardTemplate(query, template,
                                                                          Session["SortTemplate" + template.ID] == null
                            ? new Hashtable()
                            : (Hashtable)Session["SortTemplate" + template.ID]);

                StartBuildTreeView();
            }
            else if (template.TreeTypeEnum == TreeType.Children) //template.Entity.IsHierarchic &&
            {
                string systemName = template.Entity.IsHierarchic ? template.Entity.SystemName : GetHierarchicEntityName(template);

                query = CreateObjectDynamicQuery(string.Format(@"declare @sql varchar(max)= '' 
                                    EXEC [report].[getBObjectData]  null, {0}, @cyr = 1, @condition ='{1}.parentID is null', @select=@sql out
                                    select @sql", template.ID, systemName));

                dynamicQueryForChildren = new Dynamic_Query_For_Heard_Template_Type_Children(query, template,
                                                                                             Session["SortTemplate" + template.ID] == null ? new Hashtable() : (Hashtable)Session["SortTemplate" + template.ID]);

                StartBuildTreeView_Children();
            }
            else if (template.Entity.IsHierarchic && template.TreeTypeEnum == TreeType.Branch)
            {
            }
        }
Пример #2
0
        protected void toExcelButton_Click(object sender, EventArgs e)
        {
            var templateID = TemplateList.SelectedValue;

            if (string.IsNullOrEmpty(templateID))
            {
                return;
            }
            //throw new InvalidOperationException("Не выбран шаблон! Невозможно произвести экспорт в Excel.");

            Template template = Storage.Select <Template>(templateID);
            string   fileName = template.FileName;


            using (var stream = new MemoryStream())
            {
                var builder = new HardReportExcelBuilder();


                //ToDo: Доделать
                if (template.TreeTypeEnum == Reporting.Reporting.Template.EnumTreeType.Undefined || template.TreeTypeEnum == Reporting.Reporting.Template.EnumTreeType.General)
                {
                    var query = string.Format(@"declare @sql varchar(max)= '' 
                                    EXEC [report].[getBObjectData]  null, {0}, @cyr = 1, @select=@sql out
                                    select @sql", template.ID);

                    query = CreateObjectDynamicQuery(query);
                    dynamicQueryForGeneral = new DynamicQueryForHeardTemplate(query, template,
                                                                              Session["SortTemplate" + template.ID] == null ? new Hashtable() : (Hashtable)Session["SortTemplate" + template.ID]);

                    builder.dynamicQuery = dynamicQueryForGeneral;
                }
                else if (template.Entity.IsHierarchic && template.TreeTypeEnum == Reporting.Reporting.Template.EnumTreeType.Children)
                {
                    string systemName = "";
                    if (template.Entity.IsHierarchic)
                    {
                        systemName = template.Entity.SystemName;
                    }
                    else
                    {
                        systemName = GetHierarchicEntityName(template);
                    }

                    var query = string.Format(@"declare @sql varchar(max)= '' 
                                    EXEC [report].[getBObjectData]  null, {0}, @cyr = 1, @condition ='{1}.parentID is null', @select=@sql out
                                    select @sql", template.ID, systemName);

                    query = CreateObjectDynamicQuery(query);

                    dynamicQueryForChildren = new Dynamic_Query_For_Heard_Template_Type_Children(query, template,
                                                                                                 Session["SortTemplate" + template.ID] == null ? new Hashtable() : (Hashtable)Session["SortTemplate" + template.ID]);

                    #region extract 'where jnt0.parentID is null'
                    // var whereParentID = query.Substring(query.LastIndexOf("where"), query.Count() - query.LastIndexOf("where"));
                    // query = query.Remove(query.LastIndexOf("where"), query.Count() - query.LastIndexOf("where"));
                    // dynamicQueryForChildren.whereParentID = whereParentID.Remove(whereParentID.LastIndexOf("is"), whereParentID.Count() - whereParentID.LastIndexOf("is"));
                    #endregion

                    builder.dynamicQueryChildren = dynamicQueryForChildren;
                }
                else if (template.Entity.IsHierarchic && template.TreeTypeEnum == Reporting.Reporting.Template.EnumTreeType.Branch)
                {
                }


                builder.template = template;

                builder.Create(stream, template);

                Response.Clear();
                Response.ContentType = "text/html";
                Response.AddHeader("content-disposition", string.Format("attachment;fileName={0}.xlsx", fileName));
                Response.ContentEncoding = Encoding.UTF8;
                Response.BinaryWrite(stream.ToArray());
                Response.Flush();
                Response.End();
            }
        }