Ejemplo n.º 1
0
        public override void Do()
        {
            string    msg = "";
            string    sql = "  SELECT * FROM WF_BillTemplate";
            DataTable dt  = DBAccess.RunSQLReturnTable(sql);

            foreach (DataRow dr in dt.Rows)
            {
                string file = SystemConfig.PathOfCyclostyleFile + dr["URL"].ToString() + ".rtf";
                msg += RepBill.RepairBill(file);
            }
            PubClass.ResponseWriteBlueMsg(msg);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 单据生成
        /// </summary>
        /// <param name="cfile">模板文件</param>
        /// <param name="path">生成路径</param>
        /// <param name="file">生成文件</param>
        /// <param name="isOpen">是否用IE打开?</param>
        public void MakeDoc(string cfile, string path, string file, string replaceVals, bool isOpen)
        {
            string str = Cash.GetBillStr(cfile, false).Substring(0);

            if (this.HisEns.Count == 0)
            {
                if (this.HisGEEntity == null)
                {
                    throw new Exception("@您没有为报表设置数据源...");
                }
            }

            this.ensStrs = "";
            if (this.HisEns.Count != 0)
            {
                foreach (Entity en in this.HisEns)
                {
                    ensStrs += en.ToString();
                }
            }
            else
            {
                ensStrs = this.HisGEEntity.ToString();
            }

            string error = "";

            string[] paras = null;
            if (this.HisGEEntity != null)
            {
                paras = Cash.GetBillParas(cfile, ensStrs, this.HisGEEntity);
            }
            else
            {
                paras = Cash.GetBillParas(cfile, ensStrs, this.HisEns);
            }

            this.TempFilePath = path + file;
            try
            {
                string key = "";
                string ss  = "";

                #region 替换主表标记
                foreach (string para in paras)
                {
                    if (para == null || para == "")
                    {
                        continue;
                    }
                    try
                    {
                        if (para.Contains("ImgAth"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueByKey(para));
                        }
                        else if (para.Contains("Siganture"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueByKey(para));
                        }
                        else if (para.Contains("Img@AppPath"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueImgStrs(para));
                        }
                        else if (para.Contains(".BPPaint"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueBPPaintStrs(para));
                        }
                        else if (para.Contains(".M2M"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueM2MStrs(para));
                        }
                        else if (para.Contains(".RMB"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueByKey(para));
                        }
                        else if (para.Contains(".RMBDX"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueByKey(para));
                        }
                        else if (para.Contains(".Boolen"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueByKey(para));
                        }
                        else if (para.Contains(".BoolenText"))
                        {
                            str = str.Replace("<" + para + ">", this.GetValueByKey(para));
                        }
                        else if (para.Contains(".NYR"))
                        {
                            str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
                        }
                        else if (para.Contains(".Yes") == true)
                        {
                            str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
                        }
                        else if (para.Contains(".") == true)
                        {
                            continue; /*有可能是明细表数据.*/
                        }
                        else
                        {
                            str = str.Replace("<" + para + ">", this.GetCode(this.GetValueByKey(para)));
                        }
                    }
                    catch (Exception ex)
                    {
                        error += "替换主表标记取参数[" + para + "]出现错误:有以下情况导致此错误;1你用Text取值时间,此属性不是外键。2,类无此属性。3,该字段是明细表字段但是丢失了明细表标记.<br>更详细的信息:<br>" + ex.Message;
                        if (SystemConfig.IsDebug)
                        {
                            throw new Exception(error);
                        }
                        Log.DebugWriteError(error);
                    }
                }
                #endregion 替换主表标记

                #region 从表
                string    shortName = "";
                ArrayList al        = this.EnsDataDtls;
                foreach (Entities dtls in al)
                {
                    Entity dtl       = dtls.GetNewEntity;
                    string dtlEnName = dtl.ToString();
                    shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1);

                    if (str.IndexOf(shortName) == -1)
                    {
                        continue;
                    }

                    int pos_rowKey = str.IndexOf(shortName);
                    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, "");

                        Map map = dtls.GetNewEntity.EnMap;
                        int i   = dtls.Count;
                        while (i > 0)
                        {
                            i--;
                            string rowData = row.Clone() as string;
                            dtl = dtls[i];
                            //替换序号
                            int rowIdx = i + 1;
                            rowData = rowData.Replace("<IDX>", rowIdx.ToString());

                            foreach (Attr attr in map.Attrs)
                            {
                                switch (attr.MyDataType)
                                {
                                case DataType.AppDouble:
                                case DataType.AppFloat:
                                case DataType.AppRate:
                                    rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStringByKey(attr.Key));
                                    break;

                                case DataType.AppMoney:
                                    rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValDecimalByKey(attr.Key).ToString("0.00"));
                                    break;

                                case DataType.AppInt:

                                    if (attr.MyDataType == DataType.AppBoolean)
                                    {
                                        rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key));
                                        int v = dtl.GetValIntByKey(attr.Key);
                                        if (v == 1)
                                        {
                                            rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "是");
                                        }
                                        else
                                        {
                                            rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", "否");
                                        }
                                    }
                                    else
                                    {
                                        if (attr.IsEnum)
                                        {
                                            rowData = rowData.Replace("<" + shortName + "." + attr.Key + "Text>", GetCode(dtl.GetValRefTextByKey(attr.Key)));
                                        }
                                        else
                                        {
                                            rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", dtl.GetValStrByKey(attr.Key));
                                        }
                                    }
                                    break;

                                default:
                                    rowData = rowData.Replace("<" + shortName + "." + attr.Key + ">", GetCode(dtl.GetValStrByKey(attr.Key)));
                                    break;
                                }
                            }

                            str = str.Insert(row_start, rowData);
                        }
                    }
                }
                #endregion 从表

                #region 明细 合计信息。
                al = this.EnsDataDtls;
                foreach (Entities dtls in al)
                {
                    Entity dtl       = dtls.GetNewEntity;
                    string dtlEnName = dtl.ToString();
                    shortName = dtlEnName.Substring(dtlEnName.LastIndexOf(".") + 1);
                    //shortName = dtls.ToString().Substring(dtls.ToString().LastIndexOf(".") + 1);
                    Map map = dtl.EnMap;
                    foreach (Attr attr in map.Attrs)
                    {
                        switch (attr.MyDataType)
                        {
                        case DataType.AppDouble:
                        case DataType.AppFloat:
                        case DataType.AppMoney:
                        case DataType.AppRate:
                            key = "<" + shortName + "." + attr.Key + ".SUM>";
                            if (str.IndexOf(key) != -1)
                            {
                                str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString());
                            }

                            key = "<" + shortName + "." + attr.Key + ".SUM.RMB>";
                            if (str.IndexOf(key) != -1)
                            {
                                str = str.Replace(key, dtls.GetSumFloatByKey(attr.Key).ToString("0.00"));
                            }

                            key = "<" + shortName + "." + attr.Key + ".SUM.RMBDX>";
                            if (str.IndexOf(key) != -1)
                            {
                                str = str.Replace(key,
                                                  GetCode(DA.DataType.ParseFloatToCash(dtls.GetSumFloatByKey(attr.Key))));
                            }
                            break;

                        case DataType.AppInt:
                            key = "<" + shortName + "." + attr.Key + ".SUM>";
                            if (str.IndexOf(key) != -1)
                            {
                                str = str.Replace(key, dtls.GetSumIntByKey(attr.Key).ToString());
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
                #endregion 从表合计

                #region 要替换的字段
                if (replaceVals != null && replaceVals.Contains("@"))
                {
                    string[] vals = replaceVals.Split('@');
                    foreach (string val in vals)
                    {
                        if (val == null || val == "")
                        {
                            continue;
                        }

                        if (val.Contains("=") == false)
                        {
                            continue;
                        }

                        string myRep = val.Clone() as string;

                        myRep = myRep.Trim();
                        myRep = myRep.Replace("null", "");
                        string[] myvals = myRep.Split('=');
                        str = str.Replace("<" + myvals[0] + ">", "<" + myvals[1] + ">");
                    }
                }
                #endregion

                StreamWriter wr = new StreamWriter(this.TempFilePath, false, Encoding.ASCII);
                str = str.Replace("<", "");
                str = str.Replace(">", "");
                wr.Write(str);
                wr.Close();
            }
            catch (Exception ex)
            {
                string msg = "";
                if (SystemConfig.IsDebug)
                {  // 异常可能与单据的配置有关系。
                    try
                    {
                        this.CyclostyleFilePath = SystemConfig.PathOfDataUser + "\\CyclostyleFile\\" + cfile;
                        str = Cash.GetBillStr(cfile, false);
                        string s = RepBill.RepairBill(this.CyclostyleFilePath);
                        msg = "@已经成功的执行修复线  RepairLineV2,您重新发送一次或者,退后重新在发送一次,是否可以解决此问题。@" + s;
                    }
                    catch (Exception ex1)
                    {
                        msg = "执行修复线失败.  RepairLineV2 " + ex1.Message;
                    }
                }
                throw new Exception("生成文档失败:单据名称[" + this.CyclostyleFilePath + "] 异常信息:" + ex.Message + " @自动修复单据信息:" + msg);
            }
            if (isOpen)
            {
                PubClass.Print(BP.Sys.Glo.Request.ApplicationPath + "Temp/" + file);
            }
        }