Esempio n. 1
0
        int BuildTextTableLine(PrintOption option,
            List<ListViewItem> items,
            int nIndex,
            StreamWriter sw,
            // ref ExcelDocument doc,
            IXLWorksheet sheet,
            bool bCutText)
        {
            string strError = "";
            int nRet = 0;

            if (nIndex >= items.Count)
            {
                strError = "error: nIndex(" + nIndex.ToString() + ") >= items.Count(" + items.Count.ToString() + ")";
                goto ERROR1;
            }

            ListViewItem item = items[nIndex];
            string strMARC = "";
            string strOutMarcSyntax = "";

            if (this.MarcFilter != null
                || option.HasEvalue() == true)
            {

                // TODO: 有错误要明显报出来,否则容易在打印出来后才发现,就晚了

                // 获得MARC格式书目记录
                string strBiblioRecPath = ListViewUtil.GetItemText(item, COLUMN_BIBLIORECPATH);
                nRet = GetMarc(strBiblioRecPath,
                    out strMARC,
                    out strOutMarcSyntax,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (this.MarcFilter != null)
                {
                    this.ColumnTable.Clear();   // 清除上一记录处理时残余的内容
                    this.MarcFilter.Host.UiItem = item; // 当前正在处理的 ListViewItem

                    // 触发filter中的Record相关动作
                    nRet = this.MarcFilter.DoRecord(
                        null,
                        strMARC,
                        strOutMarcSyntax,
                        nIndex,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }
            }

            // 栏目内容
            string strLineContent = "";

            // bool bBiblioSumLine = false;    // 是否为种的最后一行(汇总行)
            List<CellData> cells = new List<CellData>();
            int nColIndex = 0;

            for (int i = 0; i < option.Columns.Count; i++)
            {
                Column column = option.Columns[i];
                bool bNumber = false;

                // int nIndex = nPage * option.LinesPerPage + nLine;

                /*
                if (nIndex >= items.Count)
                    break;

                ListViewItem item = items[nIndex];
                 * */
                string strContent = "";
                if (string.IsNullOrEmpty(column.Evalue) == false)
                {
                    Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();
                    engine.EnableExposedClrTypes = true;
                    engine.SetGlobalValue("syntax", strOutMarcSyntax);
                    engine.SetGlobalValue("biblio", new MarcRecord(strMARC));
                    strContent = engine.Evaluate(column.Evalue).ToString();

                }
                else
                {
                    strContent = GetColumnContent(item,
                        column.Name);

                    if (strContent == "!!!#")
                    {
                        // strContent = ((nPage * option.LinesPerPage) + nLine + 1).ToString();
                        strContent = (nIndex + 1).ToString();
                        bNumber = true;
                    }

                    if (strContent == "!!!biblioPrice")
                    {
                        // 看看自己是不是处在切换边沿
                        string strCurLineBiblioRecPath = GetColumnContent(item, "biblioRecpath");

                        string strNextLineBiblioRecPath = "";

                        if (nIndex < items.Count - 1)
                        {
                            ListViewItem next_item = items[nIndex + 1];
                            strNextLineBiblioRecPath = GetColumnContent(next_item, "biblioRecpath");
                        }

                        if (strCurLineBiblioRecPath != strNextLineBiblioRecPath)
                        {
                            // 处在切换边沿

                            // 汇总前面的册价格
                            strContent = ComputeBiblioPrice(items, nIndex).ToString();
                            // bBiblioSumLine = true;
                        }
                        else
                        {
                            // 其他普通行
                            strContent = "";    //  "&nbsp;";
                        }

                    }
                }

                if (bCutText == true)
                {
                    // 截断字符串
                    if (column.MaxChars != -1)
                    {
                        if (strContent.Length > column.MaxChars)
                        {
                            strContent = strContent.Substring(0, column.MaxChars);
                            strContent += "...";
                        }
                    }
                }

                if (String.IsNullOrEmpty(strContent) == true)
                    strContent = "";    //  "&nbsp;";

                // string strClass = Global.GetLeft(column.Name);

                if (i != 0)
                    strLineContent += "\t";

                strLineContent += strContent;

                if (sheet != null)
                {
#if NO
                    CellData cell = new CellData(nColIndex++, strContent,
            !bNumber,
            5);
                    cells.Add(cell);
#endif
                    IXLCell cell = sheet.Cell(nIndex + _nTopIndex + 1, nColIndex + 1);
                    if (bNumber == true)
                        cell.Value = strContent;
                    else
                        cell.SetValue(strContent);
                    cell.Style.Alignment.WrapText = true;
                    cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;

                    nColIndex++;
                }
            }

            /*
            if (bBiblioSumLine == false)
            {
                StreamUtil.WriteText(strFileName,
        "<tr class='content'>");
            }
            else
            {
                StreamUtil.WriteText(strFileName,
        "<tr class='content_biblio_sum'>");
            }*/
            if (sw != null)
                sw.WriteLine(strLineContent);

#if NO
            if (doc != null)
                doc.WriteExcelLine(nIndex + _nTopIndex,
                    cells,
                    WriteExcelLineStyle.AutoString);  // WriteExcelLineStyle.None
#endif

            return 0;
        ERROR1:
            if (sw != null)
                sw.WriteLine(strError);
        if (sheet != null)
        {
#if NO
            List<CellData> temp_cells = new List<CellData>();
            temp_cells.Add(new CellData(0, strError));
            doc.WriteExcelLine(nIndex + _nTopIndex, temp_cells);
#endif
            IXLCell cell = sheet.Cell(nIndex + _nTopIndex + 1, 1);
            cell.Value = strError;

        }
            return -1;
        }
Esempio n. 2
0
        // 从 RML 文件中读入 <tr> 元素
        static int ReadLine(XmlTextReader reader,
            List<ColumnStyle> col_defs,
            out List<CellData> cells,
            out string strError)
        {
            strError = "";
            cells = new List<CellData>();
            int col_index = 0;

            int nColIndex = 0;
            while (true)
            {
                if (reader.Read() == false)
                    break;
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == "th" || reader.Name == "td")
                    {
                        string strText = reader.ReadElementContentAsString();

                        CellData new_cell = null;

                        string strType = "";

                        // 2014/8/16
                        if (col_defs != null
                            && col_index < col_defs.Count)
                            strType = col_defs[col_index].Type;

                        if (strType == "String")
                            new_cell = new CellData(nColIndex++, strText, true, 0);
                        else if (strType == "Number")
                        {
                            new_cell = new CellData(nColIndex++, strText, false, 0);
                        }
                        else // "Auto")
                        {
                            bool isString = !IsExcelNumber(strText);

                            new_cell = new CellData(nColIndex++, strText, isString, 0);
                        }

                        cells.Add(new_cell);

                        col_index++;
                    }
                }
                if (reader.NodeType == XmlNodeType.EndElement
    && reader.Name == "tr")
                    break;
            }

            return 0;
        }