Beispiel #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();
        }
Beispiel #2
0
        /// <summary>
        /// BindDtl
        /// </summary>
        /// <param name="ens"></param>
        public void BindDtl(Entities ens)
        {
            string clas = ens.GetType().Name;

            if (!this.ContainsClass(clas))
            {
                return;
            }
            DocParams pars = this.GetDocParams(clas);

            if (pars.Count > 0 && this.ContainsDT(clas))
            {
                this.ListDT[clas] = ens.Count;
                foreach (DocParam par in pars)
                {
                    for (int ie = 0; ie < ens.Count; ie++)
                    {
                        DocParam addpar = new DocParam();
                        addpar.Key   = par.Key + (ie + 1).ToString().PadLeft(3, '0');
                        addpar.Field = par.Field.Insert(par.Field.IndexOf('.'), (ie + 1).ToString());
                        addpar.Value = "";
                        this.DocParamTable.Add(addpar);
                    }
                    if (ens.Count > 0)
                    {
                        this.DocParamTable.Remove(par);
                    }
                }
            }
            this.BindEns(ens);
        }
Beispiel #3
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);
        }
Beispiel #4
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);

                this.RepairLine(ref 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)
                        {                           //0   start   50  end  100
                            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, "");
                            //if(rowCount==0)
                            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();
        }