Beispiel #1
0
        public void UploadPic(List <T_TX> txList, T_JCXX jcxx, string fileId)
        {
            var targetServerDir = $"{DateTime.Now.ToString("yyyy")}\\{DateTime.Now.ToString("MM")}\\{DateTime.Now.ToString("dd")}\\{fileId}";
            var pisServerDir    = jcxx.F_TXML;
            var localdir        = $"Pics\\" + targetServerDir;

            for (int i = 0; i < txList.Count; i++)
            {
                var upFilePath         = targetServerDir + "\\";
                var serverFileFullName = pisServerDir + "\\" + txList[i].F_TXM.Trim();
                var localFileFullName  = localdir + "\\" + txList[i].F_TXM.Trim();

                //下载图片
                string ftpstatus = "";
                if (!Directory.Exists(localdir))
                {
                    Directory.CreateDirectory(localdir);
                }
                try
                {
                    ftpPis.Download(localdir, serverFileFullName, txList[i].F_TXM.Trim(), out ftpstatus);
                    if (ftpstatus == "Error")
                    {
                        throw new Exception("下载图片失败");
                    }
                }
                catch (Exception e)
                {
                    log.WriteMyLog("下载ftp图片失败,病理号:" + jcxx.F_BLH +
                                   "\r\n失败原因:" + e);
                    continue;
                }


                //上传到目标ftp
                string ftpstatusUP = "";
                try
                {
                    ftpUp.Makedir("BL", out ftpstatusUP);
                    ftpUp.Makedir("BL\\" + upFilePath, out ftpstatusUP);
                    ftpUp.Upload(localFileFullName, targetServerDir, out ftpstatusUP);
                    if (ftpstatusUP == "Error")
                    {
                        throw new Exception("Error");
                    }
                }
                catch (Exception e)
                {
                    log.WriteMyLog("上传ftp图片失败,病理号:" + jcxx.F_BLH +
                                   "\r\n失败原因:" + e);
                    continue;
                }

                //上传完成后删除本地图片
                try
                {
                    File.Delete(localFileFullName);
                }
                catch
                {
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 病理图片上传到外部系统ftp,并获取病理图片xml字符串
        /// </summary>
        /// <param name="jcxx">检查信息表</param>
        /// <returns></returns>
        public string GetImageFile(T_JCXX jcxx)
        {
            var sqlWhere = $" F_BLH='{jcxx.F_BLH}' and F_SFDY='1' ";
            var txList   = new T_TX_DAL().GetList(sqlWhere);

            string imageFileString = "";

            #region ftp变量声明

            IniFiles f             = new IniFiles("sz.ini");
            string   ftpserver     = f.ReadString("ftp", "ftpip", "").Replace("\0", "");
            string   ftpuser       = f.ReadString("ftp", "user", "ftpuser").Replace("\0", "");
            string   ftppwd        = f.ReadString("ftp", "pwd", "ftp").Replace("\0", "");
            string   ftplocal      = f.ReadString("ftp", "ftplocal", "c:\\temp").Replace("\0", "");
            string   ftpremotepath = f.ReadString("ftp", "ftpremotepath", "pathimages").Replace("\0", "");
            string   ftps          = f.ReadString("ftp", "ftp", "").Replace("\0", "");
            string   txpath        = f.ReadString("txpath", "txpath", "").Replace("\0", "");
            FtpWeb   fw            = new FtpWeb(ftpserver, ftpremotepath, ftpuser, ftppwd);

            string ftpserver2     = f.ReadString("ftpup", "ftpip", "").Replace("\0", "");
            string ftpuser2       = f.ReadString("ftpup", "user", "ftpuser").Replace("\0", "");
            string ftppwd2        = f.ReadString("ftpup", "pwd", "ftp").Replace("\0", "");
            string ftplocal2      = f.ReadString("ftpup", "ftplocal", "c:\\temp").Replace("\0", "");
            string ftpremotepath2 = f.ReadString("ftpup", "ftpremotepath", "").Replace("\0", "");
            string ftps2          = f.ReadString("ftp", "ftp", "").Replace("\0", "");
            FtpWeb fwup           = new FtpWeb(ftpserver2, ftpremotepath2, ftpuser2, ftppwd2);

            string ftpPath  = $@"ftp:\\{ftpserver}\";  //这里要替换为本地配置文件的ftp路径
            string ftpPath2 = $@"ftp:\\{ftpserver2}\"; //这里要替换为本地配置文件的ftp路径

            #endregion

            for (int i = 0; i < txList.Count; i++)
            {
                var upFilePath = jcxx.F_TXML + "\\";
                var upFileName = upFilePath + txList[i].F_TXM.Trim();

                //下载图片
                string ftpstatus = "";
                if (!Directory.Exists(ftplocal + "\\" + upFilePath))
                {
                    Directory.CreateDirectory(ftplocal + "\\" + upFilePath);
                }
                try
                {
                    fw.Download(ftplocal + "\\" + upFilePath, upFileName, txList[i].F_TXM.Trim(), out ftpstatus);
                    if (ftpstatus == "Error")
                    {
                        throw new Exception("Error");
                    }
                }
                catch (Exception e)
                {
                    log.WriteMyLog("下载ftp图片失败,病理号:" + jcxx.F_BLH +
                                   "\r\n失败原因:" + e.Message);
                    continue;
                }


                //上传到目标ftp
                string ftpstatusUP = "";
                try
                {
                    fwup.Makedir("BL", out ftpstatusUP);
                    fwup.Makedir("BL\\" + upFilePath, out ftpstatusUP);
                    fwup.Upload(ftplocal + "\\" + upFileName, "BL\\" + upFilePath, out ftpstatusUP);
                    if (ftpstatusUP == "Error")
                    {
                        throw new Exception("Error");
                    }
                }
                catch (Exception e)
                {
                    log.WriteMyLog("上传ftp图片失败,病理号:" + jcxx.F_BLH +
                                   "\r\n失败原因:" + e.Message);
                    continue;
                }

                imageFileString +=
                    $@"<Path{i + 1}> {ftpPath2 + "BL\\" + upFileName} | 1 </Path{i + 1}>                                    ";
            }

            return(imageFileString);
        }