コード例 #1
0
        /// <summary>
        /// 通过打印ID获取套打模板的路径
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="printId"></param>
        /// <param name="tmpDir"></param>
        /// <returns></returns>
        public string GetTemplateById(string PubConnectString, string printId, string tmpDir, string fileName = "")
        {
            DataTable dTb = new PrintDac(PubConnectString).GetTemplateById(printId);

            if (dTb.Rows.Count > 0)
            {
                byte[] bTemp = (byte[])dTb.Rows[0]["bfile"];
                string sStr  = Convert.ToBase64String(bTemp, 0, bTemp.Length);
                sStr  = sStr.Replace("*", "/");
                bTemp = Convert.FromBase64String(sStr);
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = dTb.Rows[0]["filename"].ToString();
                }
                string sPath = Path.Combine(tmpDir, fileName);
                if (!Directory.Exists(tmpDir))
                {
                    Directory.CreateDirectory(tmpDir);
                }
                FileStream fsw = new FileStream(sPath, FileMode.Create, FileAccess.Write);
                fsw.Write(bTemp, 0, bTemp.Length);
                fsw.Close();
                return(fileName);
            }
            return("");
        }
コード例 #2
0
        /// <summary>
        /// 通过打印ID获取套打模板
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="printId"></param>
        /// <param name="tmpDir"></param>
        /// <returns></returns>
        public DataTable GetModuleByID(string PubConnectString, string printId, string tmpDir)
        {
            DataTable dTb = new PrintDac(PubConnectString).GetTemplateById(printId);

            if (dTb.Rows.Count > 0)
            {
                byte[] bTemp = (byte[])dTb.Rows[0]["bfile"];
                string sStr  = Convert.ToBase64String(bTemp, 0, bTemp.Length);
                sStr  = sStr.Replace("*", "/");
                bTemp = Convert.FromBase64String(sStr);
                string fileName = "";
                if (dTb.Rows[0]["filename"] == DBNull.Value || string.IsNullOrEmpty(dTb.Rows[0]["filename"].ToString()))
                {
                    dTb.Rows[0]["filename"] = string.Format("{0}[{1}].xml", dTb.Rows[0]["billname"].ToString(), dTb.Rows[0]["typefile"].ToString());
                }
                fileName = dTb.Rows[0]["filename"].ToString();

                string sPath = Path.Combine(tmpDir, fileName);
                if (!Directory.Exists(tmpDir))
                {
                    Directory.CreateDirectory(tmpDir);
                }
                FileStream fsw = new FileStream(sPath, FileMode.Create, FileAccess.Write);
                fsw.Write(bTemp, 0, bTemp.Length);
                fsw.Close();
                dTb.Columns.Remove("bfile");
                return(dTb);
            }
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// 导入模板
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="sysPath"></param>
        /// <param name="allMoudleType"></param>
        /// <param name="mType"></param>
        /// <param name="errTxt"></param>
        /// <returns></returns>
        public int ImportModule(string PubConnectString, string sysPath, string allMoudleType, string mType, ref string errTxt)
        {
            string[] mArr = allMoudleType.Split(',');
            string   tmpPath = "", fileName = "";
            int      numCount = 0;
            PrintDac prt      = new PrintDac(PubConnectString);

            foreach (string s in mArr)
            {
                if (s.Length == 0)
                {
                    continue;
                }
                tmpPath = Path.Combine(sysPath, s);
                DirectoryInfo df = new DirectoryInfo(tmpPath);
                if (df.Exists)
                {
                    FileInfo[] fis = df.GetFiles("*.xml");
                    foreach (FileInfo f in fis)
                    {
                        fileName = f.Name;
                        if (!prt.CheckFtmTemplate(fileName, mType))
                        {
                            continue;
                        }
                        FileStream fStream = File.OpenRead(f.FullName);
                        byte[]     bTemp   = new byte[fStream.Length];
                        fStream.Read(bTemp, 0, bTemp.Length);
                        fStream.Flush();
                        fStream.Close();
                        if (mType == "sys")
                        {
                            numCount += prt.ImportSysTemplate(fileName, bTemp);
                        }
                        else
                        {
                            numCount += prt.ImportUserTemplate(fileName, bTemp);
                        }
                    }
                }
            }
            return(numCount);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="typefile"></param>
        /// <param name="tmpDir"></param>
        /// <returns></returns>
        public string GeteTemplatByTypeFile(string PubConnectString, string typefile, string def_int2, string tmpDir, string fileName = "")
        {
            DataTable dTb = new PrintDac(PubConnectString).GetePdfTemplatByTypeFile(typefile);

            if (dTb.Rows.Count > 0)
            {
                byte[]    bTemp;
                DataRow[] drs = dTb.Select("def_int2=" + def_int2);
                if (drs != null && drs.Length > 0)
                {
                    bTemp = (byte[])drs[0]["bfile"];
                    if (string.IsNullOrEmpty(fileName))
                    {
                        fileName = drs[0]["filename"].ToString();
                    }
                }
                else
                {
                    fileName = "";
                    return("");
                    //bTemp = (byte[])dTb.Rows[0]["bfile"];
                    //if (string.IsNullOrEmpty(fileName))
                    //{
                    //    fileName = dTb.Rows[0]["filename"].ToString();
                    //}
                }
                string sStr = Convert.ToBase64String(bTemp, 0, bTemp.Length);
                sStr  = sStr.Replace("*", "/");
                bTemp = Convert.FromBase64String(sStr);
                string sPath = Path.Combine(tmpDir, fileName);
                if (!Directory.Exists(tmpDir))
                {
                    Directory.CreateDirectory(tmpDir);
                }
                FileStream fsw = new FileStream(sPath, FileMode.Create, FileAccess.Write);
                fsw.Write(bTemp, 0, bTemp.Length);
                fsw.Close();
                return(fileName);
            }
            return("");
        }
コード例 #5
0
        /// <summary>
        /// 保存用户自定义模板
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="printId"></param>
        /// <param name="typeFile"></param>
        /// <param name="mTitle"></param>
        /// <param name="xmlDoc"></param>
        /// <param name="tmpDir"></param>
        /// <returns></returns>
        public string SaveUserDefTemplate(string PubConnectString, ref string printId, string typeFile, string mTitle, string xmlDoc, string tmpDir)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlDoc);

            string fName       = Guid.NewGuid().ToString() + ".xml"; //临时文件
            string XmlFileName = Path.Combine(tmpDir, fName);

            if (!Directory.Exists(tmpDir))
            {
                Directory.CreateDirectory(tmpDir);
            }
            doc.Save(XmlFileName);
            FileStream fStream = File.OpenRead(XmlFileName);

            byte[] bTemp = new byte[fStream.Length];
            fStream.Read(bTemp, 0, bTemp.Length);
            fStream.Flush();
            fStream.Close();

            string moduleno    = "";
            string newFileName = new PrintDac(PubConnectString).SaveUserDefTemplate(ref printId, typeFile, mTitle, bTemp, ref moduleno);

            if (!string.IsNullOrEmpty(newFileName))
            {
                fName = newFileName;
                string newXmlFileName = Path.Combine(tmpDir, moduleno, newFileName);
                if (File.Exists(newXmlFileName))
                {
                    File.Delete(newXmlFileName);
                }
                else if (!Directory.Exists(Path.Combine(tmpDir, moduleno)))
                {
                    Directory.CreateDirectory(Path.Combine(tmpDir, moduleno));
                }
                File.Move(XmlFileName, newXmlFileName);
            }
            return(moduleno + "/" + fName);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="otype"></param>
        /// <param name="printId"></param>
        /// <param name="moduleno"></param>
        /// <param name="tmpPath"></param>
        /// <param name="xmlDoc"></param>
        /// <param name="rowData"></param>
        /// <returns></returns>
        public string Update(string PubConnectString, string otype, string printId, string moduleno, string tmpPath, string xmlDoc, Dictionary <string, object> rowData)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlDoc);

            string fName       = Guid.NewGuid().ToString() + ".xml"; //临时文件
            string XmlFileName = Path.Combine(tmpPath, fName);

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }
            doc.Save(XmlFileName);
            FileStream fStream = File.OpenRead(XmlFileName);

            byte[] bTemp = new byte[fStream.Length];
            fStream.Read(bTemp, 0, bTemp.Length);
            fStream.Flush();
            fStream.Close();
            string oldXmlFileName = "";
            string fileName       = "";

            //if (bTemp != null && bTemp.Length > 0)
            //{
            //    string strDoc = Convert.ToBase64String(bTemp, 0, bTemp.Length);
            //    strDoc = strDoc.Replace("*", "/");
            //    bTemp = Convert.FromBase64String(strDoc);
            //}
            rowData.Add("bfile", bTemp);
            if (otype == "add")
            {
                //printId = Insert(PubConnectString,rowData, ref fileName);
                printId = new PrintDac(PubConnectString).Insert(rowData, ref fileName, false);
            }
            else
            {
                //printId = Update(PubConnectString,printId, rowData, ref oldXmlFileName, ref fileName);
                printId = new PrintDac(PubConnectString).Update(printId, rowData, ref oldXmlFileName, ref fileName);
            }
            #region 更新物理用户模板文件
            if (otype == "add" || otype == "edit")
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    tmpPath = Path.Combine(tmpPath, moduleno);
                    string newXmlFileName = Path.Combine(tmpPath, fileName);
                    if (!Directory.Exists(tmpPath))
                    {
                        Directory.CreateDirectory(tmpPath);
                    }
                    if (File.Exists(newXmlFileName))
                    {
                        File.Delete(newXmlFileName);
                    }
                    if (!string.IsNullOrEmpty(oldXmlFileName))
                    {
                        oldXmlFileName = Path.Combine(tmpPath, oldXmlFileName);
                        if (File.Exists(oldXmlFileName))
                        {
                            File.Delete(oldXmlFileName);
                        }
                    }
                    File.Move(XmlFileName, newXmlFileName);
                }
            }
            #endregion


            return(printId);
        }
コード例 #7
0
        public int UpdateModule(string PubConnectString, string sysPath, string allMoudleType, string mType, ref string errTxt)
        {
            string[] mArr = allMoudleType.Split(',');
            string   tmpPath = "", fileName = "";
            int      numCount = 0;
            PrintDac prt      = new PrintDac(PubConnectString);

            foreach (string moduleno in mArr)
            {
                if (moduleno.Length == 0)
                {
                    continue;
                }
                tmpPath = Path.Combine(sysPath, moduleno);
                DirectoryInfo df = new DirectoryInfo(tmpPath);
                if (df.Exists)
                {
                    FileInfo[] fis = df.GetFiles("*.xml");
                    foreach (FileInfo f in fis)
                    {
                        fileName = f.Name;
                        string def_int2 = "0";
                        switch (mType)
                        {
                        case "sys":
                            def_int2 = "1";
                            break;

                        case "sys_pdf":
                            def_int2 = "3";
                            break;

                        case "sys_pdf_0":    //不更新 有更新的系统PDF    isnew=1 系统PDF有更新
                            def_int2 = "3";
                            break;

                        default:
                            def_int2 = "0";
                            break;
                        }
                        int printid = prt.GetPrintId(fileName, def_int2, mType == "sys_pdf_0" ? "0" : "");
                        if (printid != -1)
                        {
                            FileStream fStream = File.OpenRead(f.FullName);
                            byte[]     bTemp   = new byte[fStream.Length];
                            fStream.Read(bTemp, 0, bTemp.Length);
                            fStream.Flush();
                            fStream.Close();
                            string filename       = "";
                            string oldXmlFileName = "";
                            string ret            = prt.Update(printid.ToString(), new Dictionary <string, object>()
                            {
                                { "bfile", bTemp },
                                { "isnew", (mType == "sys_pdf" || mType == "sys_pdf_0") ? "0" : "" }
                            }, ref oldXmlFileName, ref filename, true);
                            if (!string.IsNullOrEmpty(ret))
                            {
                                numCount++;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            return(numCount);
        }
コード例 #8
0
        /// <summary>
        /// 导入模板
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="sysPath"></param>
        /// <param name="allMoudleType"></param>
        /// <param name="mType"></param>
        /// <param name="errTxt"></param>
        /// <returns></returns>
        public int ImportModule(string PubConnectString, string sysPath, string allMoudleType, string mType, ref string errTxt)
        {
            string[] mArr = allMoudleType.Split(',');
            string   tmpPath = "", fileName = "";
            int      numCount = 0;
            PrintDac prt      = new PrintDac(PubConnectString);

            foreach (string moduleno in mArr)
            {
                if (moduleno.Length == 0)
                {
                    continue;
                }
                tmpPath = Path.Combine(sysPath, moduleno);
                DirectoryInfo df = new DirectoryInfo(tmpPath);
                if (df.Exists)
                {
                    FileInfo[] fis = df.GetFiles("*.xml");
                    foreach (FileInfo f in fis)
                    {
                        fileName = f.Name;
                        string def_int2 = "0";
                        switch (mType)
                        {
                        case "sys":
                            def_int2 = "1";
                            break;

                        case "sys_pdf":
                            def_int2 = "3";
                            break;

                        default:
                            def_int2 = "0";
                            break;
                        }
                        if (!prt.CheckFtmTemplate(fileName, def_int2))
                        {
                            continue;
                        }
                        FileStream fStream = File.OpenRead(f.FullName);
                        byte[]     bTemp   = new byte[fStream.Length];
                        fStream.Read(bTemp, 0, bTemp.Length);
                        fStream.Flush();
                        fStream.Close();
                        string billname = fileName.Substring(0, fileName.Length - 4);
                        int    b        = billname.LastIndexOf("[") + 1;
                        int    e        = billname.Length - 1;
                        string typeFile = billname.Substring(b, e - b);
                        billname = billname.Replace("[" + typeFile + "]", "");
                        if (def_int2 == "0")
                        {
                            string ret = prt.Insert(new Dictionary <string, object>()
                            {
                                { "typefile", typeFile },
                                { "moduleno", moduleno },
                                { "billname", billname },
                                { "filename", fileName },
                                { "def_int2", def_int2 },
                                { "def_str3", "supcan" },
                                { "remarks", "" },
                                { "bfile", bTemp },
                                { "iscompress", "0" },
                                { "ispub", "0" },
                                { "def_str1", NG3.AppInfoBase.UCode },
                                { "def_int1", "1" },
                                { "previeweditflg", "0" }
                            }, ref fileName, true);
                            if (!string.IsNullOrEmpty(ret))
                            {
                                numCount++;
                            }
                        }
                        else
                        {
                            string ret = prt.InsertTemplate(moduleno, typeFile, billname, ref fileName, bTemp, def_int2);
                            if (!string.IsNullOrEmpty(ret))
                            {
                                numCount++;
                            }
                        }
                    }
                }
            }
            return(numCount);
        }
コード例 #9
0
        /// <summary>
        /// 系统、用户模板更新(新增、修改)
        /// </summary>
        /// <param name="PubConnectString"></param>
        /// <param name="tmpPath"></param>
        /// <param name="oType"></param>
        /// <param name="printId"></param>
        /// <param name="moduleNo"></param>
        /// <param name="typeFile"></param>
        /// <param name="billName"></param>
        /// <param name="fileName"></param>
        /// <param name="remarks"></param>
        /// <param name="xmlDoc"></param>
        /// <returns></returns>
        public string UpdateLformTemplate(string PubConnectString, string tmpPath, string oType, string printId, string moduleNo, string typeFile, string billName, string fileName, string remarks, string xmlDoc)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xmlDoc);

            string fName       = Guid.NewGuid().ToString() + ".xml"; //临时文件
            string XmlFileName = Path.Combine(tmpPath, fName);

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }
            doc.Save(XmlFileName);
            FileStream fStream = File.OpenRead(XmlFileName);

            byte[] bTemp = new byte[fStream.Length];
            fStream.Read(bTemp, 0, bTemp.Length);
            fStream.Flush();
            fStream.Close();

            string oldXmlFileName = "";

            if (oType == "add")
            {
                printId = new PrintDac(PubConnectString).AddLformTemplate(moduleNo, typeFile, billName, ref fileName, remarks, bTemp);
            }
            else if (oType == "edit")
            {
                printId = new PrintDac(PubConnectString).EditLformTemplate(printId, billName, ref fileName, ref oldXmlFileName, remarks, bTemp);
            }
            else if (oType == "update")
            {
                printId = new PrintDac(PubConnectString).UpdateSysTemplate(printId, billName, ref fileName, ref oldXmlFileName, remarks, bTemp);
            }

            #region 更新物理用户模板文件
            if (oType == "add" || oType == "edit")
            {
                if (!string.IsNullOrEmpty(fileName))
                {
                    tmpPath = Path.Combine(tmpPath, moduleNo);
                    string newXmlFileName = Path.Combine(tmpPath, fileName);
                    oldXmlFileName = Path.Combine(tmpPath, oldXmlFileName);
                    if (!Directory.Exists(tmpPath))
                    {
                        Directory.CreateDirectory(tmpPath);
                    }
                    if (File.Exists(newXmlFileName))
                    {
                        File.Delete(newXmlFileName);
                    }
                    if (File.Exists(oldXmlFileName))
                    {
                        File.Delete(oldXmlFileName);
                    }
                    File.Move(XmlFileName, newXmlFileName);
                }
            }
            #endregion
            return(printId);
        }