Ejemplo n.º 1
0
        /// <summary>
        /// 装载参数表
        /// </summary>
        private void ReadDocParamTable()
        {
            string  xlmpath = this.CyclostyleFilePath.ToUpper().Replace(".RTF", ".XML");
            DataSet ds      = new DataSet("ds");

            ds.ReadXml(xlmpath);
            DataTable tb = ds.Tables[0];

            this.DocParamTable = new DocParams(tb);    //根据datatable 生成参数集合。

            this.ListDT       = new Hashtable();       // 明细类名表
            this.ListEnsNames = new Hashtable();       // 类名列表
            foreach (DocParam par in this.DocParamTable)
            {
                int pos = par.Field.IndexOf('.');
                if (pos != -1)
                {
                    string clas = par.Field.Substring(0, pos);
                    if (ListEnsNames.ContainsKey(clas) == false)
                    {
                        ListEnsNames.Add(clas, clas);                          // 加入类名列表。
                    }
                    if (par.Key.TrimStart('<').Substring(0, 2) == "DT")
                    {
                        /*  dtl */
                        if (this.ContainsDT(clas) == false)                        // 加入明细类名表
                        {
                            this.ListDT.Add(clas, 0);
                        }
                    }
                }
            }
            ds.Dispose();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 取得参数
        /// </summary>
        /// <param name="enName">类名称</param>
        /// <returns>参数集合</returns>
        public DocParams GetDocParams(string enName)
        {
            DocParams pars = new DocParams();

            foreach (DocParam par in this.DocParamTable)
            {
                if (par.Field.IndexOf(enName) != -1)
                {
                    pars.Add(par);
                }
            }
            return(pars);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成文档。
        /// </summary>
        public void MakeDocument()
        {
            System.IO.File.Copy(this.CyclostyleFilePath, this.TempFilePath);                //复制一个样本到临时目录里面。

            StreamReader read = null;
            StreamWriter wr   = null;

            try
            {
                read = new StreamReader(this.TempFilePath, Encoding.ASCII); // 文件流
                string str = read.ReadToEnd();                              //读取完毕。
                read.Close();                                               // 关闭。
                wr = new StreamWriter(this.TempFilePath, false, Encoding.ASCII);

                str = this.RepairLine(str);                    // 修复线。

                #region 从表
                IDictionaryEnumerator dic = this.ListDT.GetEnumerator();


                while (dic.MoveNext())
                {
                    string    ensName  = dic.Key.ToString();                 //DT
                    DocParams pars     = this.GetDocParams(ensName);
                    int       rowCount = (int)dic.Value;
                    if (pars.Count > 0)
                    {
                        string rowKey = pars[0].Key.TrimStart('<').Substring(0, 4);                         //find dt row model
                        int    pos_rowKey = str.IndexOf(rowKey);
                        int    row_start = -1, row_end = -1;
                        if (pos_rowKey != -1)
                        {
                            row_start = str.Substring(0, pos_rowKey).LastIndexOf("\\row");
                            row_end   = str.Substring(pos_rowKey).IndexOf("\\row");
                        }
                        if (row_start != -1 && row_end != -1)
                        {
                            string row = str.Substring(row_start, (pos_rowKey - row_start) + row_end);
                            str = str.Replace(row, "");
                            for (int ir = rowCount; ir > 0; ir--)
                            {
                                string tmp = row;
                                pars = this.GetDocParams(ensName + ir);
                                foreach (DocParam par in pars)
                                {
                                    string key;
                                    if (par.Key[par.Key.Length - 1] == '>')
                                    {
                                        key = par.Key.Remove(par.Key.Length - 4, 3);
                                    }
                                    else
                                    {
                                        key = par.Key.Remove(par.Key.Length - 3, 3);
                                    }
                                    if (key.Length > 3)                                  //安全起见
                                    {
                                        tmp = tmp.Replace(key, par.Value);
                                    }
                                }
                                str = str.Insert(row_start, tmp);
                            }
                        }
                    }
                }
                #endregion 从表

                #region 主表
                foreach (DocParam par in this.DocParamTable)
                {
                    str = str.Replace(par.Key, par.Value);
                }
                #endregion

                wr.Write(str);
            }
            catch (Exception ex)
            {
                if (read != null)
                {
                    read.Close();
                }
                if (wr != null)
                {
                    wr.Close();
                }
                throw new Exception("生成文档失败:" + ex.Message);
            }
            read.Close();
            wr.Close();
        }