Exemple #1
0
        protected override void RenderContents(HtmlTextWriter output)
        {
            string strError = "";
            int    nRet     = 0;

#if NO
            if (this.XmlFilename == "")
            {
                strError = "<span class='comment'>"
                           + this.GetString("尚未指定日期参数") // "(尚未指定日期参数)"
                           + "</span>";
                goto ERROR1;
            }
#endif
            if (String.IsNullOrEmpty(this.Xml) == true)
            {
                /*
                 * strError = "<span class='comment'>"
                 + this.GetString("尚未指定日期参数")  // "(尚未指定日期参数)"
                 + "</span>";
                 + goto ERROR1;
                 * */
                strError = "<span class='comment'>"
                           + this.DateRange + " " + this.GetString("没有统计信息")
                           + "</span>";
                goto ERROR1;
            }


            OpacApplication app         = (OpacApplication)this.Page.Application["app"];
            SessionInfo     sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            string strTemplateFilename = app.CfgDir + "\\statis_template.xml";

            if (File.Exists(strTemplateFilename) == true)
            {
                string strTargetXml = "";

                LoginState loginstate = Global.GetLoginState(this.Page);

                // 利用模板文件过滤统计事项,并将事项按照模板顺序排序
                nRet = StatisViewControl.FilterXmlFile(
                    loginstate.ToString().ToLower(), // notlogin public reader librarian
                    this.Xml,
                    strTemplateFilename,
                    false,
                    out strTargetXml,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                this.Xml = strTargetXml;
            }



            string strDate = "";

            strDate = this.DateRange;

            try
            {
                dom = new XmlDocument();
                dom.LoadXml(this.Xml);
            }
            catch (Exception ex)
            {
                strError = "XML字符串装入DOM时出错:" + ex.Message;
                goto ERROR1;
            }

#if NO
            if (nRet == 0)
            {
                strError = "<span class='comment'>" + strDate
                           + this.GetString("没有统计信息")
                           + "</span>";
                goto ERROR1;
            }
#endif

            output.Write("<table class='statis' >");// border='1'

            // 标题行
            output.Write("<tr class='tabletitle'><td colspan='2'>" + strDate + " "
                         + this.GetString("实时统计信息")
                         + "</td></tr>");

            // 注释行
            if (this.RangeStatisInfo != null)
            {
                string strComment = GetCommentString(this.RangeStatisInfo);
                output.Write("<tr class='comment'><td colspan='2'>" + strComment + "</td></tr>");
            }


            XmlNodeList categorys = this.dom.DocumentElement.SelectNodes("category");
            for (int i = 0; i < categorys.Count; i++)
            {
                XmlNode category = categorys[i];

                string strCategory = DomUtil.GetAttr(category, "name");

                // 2009/7/31
                string strCategoryCaption = this.GetStringEx(strCategory);
                if (String.IsNullOrEmpty(strCategoryCaption) == true)
                {
                    strCategoryCaption = strCategory;
                }

                output.Write("<tr class='category'><td colspan='2'>");
                output.Write(strCategoryCaption);
                output.Write("</td></tr>");

                XmlNodeList items = category.SelectNodes("item");

                for (int j = 0; j < items.Count; j++)
                {
                    XmlNode item = items[j];

                    string strItemName  = DomUtil.GetAttr(item, "name");
                    string strItemValue = DomUtil.GetAttr(item, "value");

                    // 2009/7/31
                    string strItemNameCaption = this.GetStringEx(strItemName);
                    if (String.IsNullOrEmpty(strItemNameCaption) == true)
                    {
                        strItemNameCaption = strItemName;
                    }


                    output.Write("<tr class='content'><td class='name'>");
                    output.Write(strItemNameCaption);
                    output.Write("</td><td class='value'>");
                    output.Write(strItemValue);
                    output.Write("</td></tr>");
                }
            }
            output.Write("</table>");

            return;

ERROR1:
            output.Write(strError);
        }
Exemple #2
0
        protected override void Render(HtmlTextWriter writer)
        {
            string strError = "";
            int    nRet     = 0;

            LiteralControl table = (LiteralControl)this.FindControl("table");

#if NO
            DropDownList list = (DropDownList)this.FindControl("librarycode");
#endif

            if (String.IsNullOrEmpty(this.Xml) == true)
            {
                /*
                 * strError = "<span class='comment'>"
                 + this.GetString("尚未指定日期参数")  // "(尚未指定日期参数)"
                 + "</span>";
                 + goto ERROR1;
                 * */
                strError = this.DateRange + " " + this.GetString("没有统计信息");
                goto ERROR1;
            }

            OpacApplication app         = (OpacApplication)this.Page.Application["app"];
            SessionInfo     sessioninfo = (SessionInfo)this.Page.Session["sessioninfo"];

            string strTemplateFilename = app.CfgDir + "\\statis_template.xml";
#if NO
            string strLibraryCode = list.Text;
            if (strLibraryCode == "<所有分馆>")
            {
                strLibraryCode = "";
            }
#endif
            string strLibraryCode = (string)this.Page.Session["librarycode"];

            List <string> codes = app.GetAllLibraryCodes();
            bool          bExistsTemplateFile = false;
            if (File.Exists(strTemplateFilename) == true)
            {
                bExistsTemplateFile = true;

                string     strTargetXml = "";
                LoginState loginstate   = GlobalUtil.GetLoginState(this.Page);

                // 利用模板文件过滤统计事项,并将事项按照模板顺序排序
                nRet = StatisViewControl.FilterXmlFile(
                    strLibraryCode,
                    loginstate.ToString().ToLower(), // notlogin public reader librarian
                    this.Xml,
                    strTemplateFilename,
                    false,
                    out strTargetXml,
                    // out exist_codes,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                this.Xml = strTargetXml;
            }

            string strDate = "";
            strDate = this.DateRange;

            try
            {
                dom = new XmlDocument();
                dom.LoadXml(this.Xml);
            }
            catch (Exception ex)
            {
                strError = "XML字符串装入DOM时出错:" + ex.Message;
                goto ERROR1;
            }

#if NO
            // 如果没有过滤,则需要在这里获得馆代码
            if (File.Exists(strTemplateFilename) == false)
            {
                XmlNodeList nodes = dom.DocumentElement.SelectNodes("library");
                foreach (XmlNode node in nodes)
                {
                    string strCode = DomUtil.GetAttr(node, "code");
                    exist_codes.Add(strCode);
                }
            }
#endif
            // 如果没有过滤,则需要在这里把特定馆代码的片段提升到根下
            if (bExistsTemplateFile == false &&
                string.IsNullOrEmpty(strLibraryCode) == false)
            {
                XmlNode node = dom.DocumentElement.SelectSingleNode("library[@code='" + strLibraryCode + "']");
                if (node != null)
                {
                    dom.DocumentElement.InnerXml = node.InnerXml;
                }
                else
                {
                    dom.DocumentElement.InnerXml = "";
                }
            }

            StringBuilder text = new StringBuilder(4096);

            text.Append("<div class='statisframe'><table class='statis' >");// border='1'

            string strLibraryCodeText = "";
            if (String.IsNullOrEmpty(strLibraryCode) == true)
            {
                if (codes.Count == 0)
                {
                    strLibraryCodeText = "";
                }
                else
                {
                    strLibraryCodeText = this.GetString("全部分馆") + " ";
                }
            }
            else
            {
                strLibraryCodeText = strLibraryCode + " ";
            }
            List <string> column_titles = new List <string>();

            DateTime start_date = DateTimeUtil.Long8ToDateTime(this.RangeStatisInfo.StartDate);
            DateTime end_date   = DateTimeUtil.Long8ToDateTime(this.RangeStatisInfo.EndDate);
            DateTime now        = DateTime.Now;
            if (this.IsRange == true)
            {
                DateTime current_date = start_date;
                while (current_date <= end_date &&
                       current_date <= now)
                {
                    column_titles.Add(GetDateString(current_date, current_date == start_date));
                    current_date = current_date.AddDays(1);
                }
            }


            string strColspan = "";
            strColspan = " colspan='" + (column_titles.Count + 2).ToString() + "' ";

            // 标题行
            text.Append("<tr class='tabletitle'><td " + strColspan + ">" + strLibraryCodeText + strDate + " "
                        + this.GetString("实时统计信息")
                        + "</td></tr>");

            // 注释行
            if (this.RangeStatisInfo != null)
            {
                string strComment = GetCommentString(this.RangeStatisInfo);
                text.Append("<tr class='comment'><td " + strColspan + ">" + strComment + "</td></tr>");
            }

            // 栏目标题行
            string strColumnLine = "";
            if (this.IsRange == true)
            {
                StringBuilder line = new StringBuilder(4096);
                foreach (string s in column_titles)
                {
                    line.Append("<td class='day'>" + s + "</td>");
                }
                strColumnLine = "<tr class='column'><td class='rowtitle'>统计指标</td><td class='rowtitle'>合计</td>"
                                + line.ToString()
                                + "</tr>";
            }
            else
            {
                strColumnLine = "<tr class='column'><td class='rowtitle'>统计指标</td><td class='rowtitle'>合计</td>"
                                + "</tr>";
            }
            text.Append(strColumnLine);

            XmlNodeList categorys = this.dom.DocumentElement.SelectNodes("category");
            for (int i = 0; i < categorys.Count; i++)
            {
                XmlNode category = categorys[i];

                string strCategory = DomUtil.GetAttr(category, "name");

                // 2009/7/31
                string strCategoryCaption = this.GetStringEx(strCategory);
                if (String.IsNullOrEmpty(strCategoryCaption) == true)
                {
                    strCategoryCaption = strCategory;
                }

                text.Append("<tr class='category'><td " + strColspan + ">");
                text.Append(strCategoryCaption);
                text.Append("</td></tr>");

                XmlNodeList items = category.SelectNodes("item");

                for (int j = 0; j < items.Count; j++)
                {
                    XmlNode item = items[j];

                    string strItemName  = DomUtil.GetAttr(item, "name");
                    string strItemValue = DomUtil.GetAttr(item, "value");

                    // 2009/7/31
                    string strItemNameCaption = this.GetStringEx(strItemName);
                    if (String.IsNullOrEmpty(strItemNameCaption) == true)
                    {
                        strItemNameCaption = strItemName;
                    }

                    if (this.IsRange == false)
                    {
                        text.Append("<tr class='content'><td class='name'>");
                        text.Append(strItemNameCaption);
                        text.Append("</td><td class='value'>");
                        text.Append(strItemValue);
                        text.Append("</td></tr>");
                    }
                    else
                    {
                        string[] values = strItemValue.Split(new char[] { ',' });
                        text.Append("<tr class='content'><td class='name'>");
                        text.Append(strItemNameCaption);
                        text.Append("</td>");

                        int      k            = 0;
                        DateTime current_date = start_date;
                        foreach (string v in values)
                        {
                            if (current_date <= end_date &&
                                current_date <= now)
                            {
                            }
                            else
                            {
                                break;  // 比今天还要靠后的就不显示了
                            }
                            string strClass = "day";
                            if (k == 0)
                            {
                                strClass = "value";
                            }

                            text.Append("<td class='" + strClass + "'>");
                            text.Append(string.IsNullOrEmpty(v) == false ? v : "&nbsp;");
                            text.Append("</td>");

                            if (k != 0) // 第一次出现是合计值, 不是普通日子的值
                            {
                                current_date = current_date.AddDays(1);
                            }

                            k++;
                        }

                        while (current_date <= end_date &&
                               current_date <= now)
                        {
                            text.Append("<td class='day'>&nbsp;</td>");
                            current_date = current_date.AddDays(1);
                        }
                        text.Append("</tr>");
                    }
                }
            }

            if (this.IsRange == true && column_titles.Count > 3)
            {
                // 底部再来一次栏目标题行
                text.Append(strColumnLine);
            }

            text.Append("</table></div>");

            table.Text = text.ToString();
            base.Render(writer);
            return;

ERROR1:
            table.Text = "<span class='comment'>"
                         + HttpUtility.HtmlEncode(strError)
                         + "</span>";
            base.Render(writer);
        }