コード例 #1
0
ファイル: MyHttpRequest.cs プロジェクト: xiaoshanyang/ISRA
        public Dictionary <string, object> GetDefectImage(GetDefectImageByPfIDRequestData reqData)
        {
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            //数据库中获取当前pfId对应的defectId
            DataOpt   dbopt = new DataOpt();
            DataTable dt    = dbopt.getDefectImageNameBypfId(reqData.pfId); //53532_171115_D.bmp

            if (dt == null || dt.Rows.Count == 0)
            {
                dictionary.Add("state", 2);
                dictionary.Add("errmessage", "获取纸病图片失败");
            }
            else
            {
                dictionary.Add("state", 1);
                // 组合图片路径
                //IMAGE\18012\18012002\30573_051613.bmp
                string basicPath   = "IMAGE\\" + dt.Rows[0]["Event_Num"].ToString().Substring(0, 5) + "\\" + dt.Rows[0]["Event_Id"].ToString() + "\\";
                string moudleImage = dt.Rows[0]["defectImageName"].ToString().Replace("_D", "");
                dictionary.Add("sourceImg", basicPath + moudleImage);
                dictionary.Add("defectImg", basicPath + dt.Rows[0]["defectImageName"].ToString());
                dictionary.Add("dLength", dt.Rows[0]["dLength"].ToString());
                dictionary.Add("dWidth", dt.Rows[0]["dWidth"].ToString());
                dictionary.Add("dArea", dt.Rows[0]["dArea"].ToString());
            }

            return(dictionary);
        }
コード例 #2
0
ファイル: MyHttpRequest.cs プロジェクト: xiaoshanyang/ISRA
        public string GetDefectHtml(GetDefectImageAllWebNumRequestData reqData)
        {
            DataOpt   dbopt = new DataOpt();
            DataTable dt    = dbopt.getDefectImageNameBypfId(reqData.pfId); //53532_171115_D.bmp
            // 默认页面,没有找到对应html文件时,显示
            string htmlPath  = "D:\\ISRA\\HTML" + reqData.rollNum.Substring(0, 5) + "\\" + reqData.rollNum + "\\";
            string imageName = dt.Rows[0]["defectImageName"].ToString();

            if (imageName.IndexOf("_D.bmp") > 0)
            {
                htmlPath = "D:\\ISRA\\HTML" + reqData.rollNum.Substring(0, 5) + "\\" + reqData.rollNum + "\\" + imageName.Substring(0, imageName.IndexOf("_D.bmp") + 1) + ".html";
            }
            string content = string.Empty;

            //文件读取
            if (File.Exists(htmlPath))
            {
                FileStream   fs   = new FileStream(htmlPath, FileMode.Open);
                StreamReader sr   = new StreamReader(fs);
                string       line = string.Empty;//直接读取一行
                while ((line = sr.ReadLine()) != null)
                {
                    //不为空,继续读取
                    content += line;
                }

                sr.Close();
                fs.Close();
            }
            else
            {
            }

            //html转译
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(content);
            HtmlNodeCollection tableList = doc.DocumentNode.SelectNodes("//table");

            // 图片名改名
            tableList[1].SelectNodes("tr")[0].SelectNodes("td")[0].SelectNodes("img")[0].SetAttributeValue("src", imageName);
            tableList[1].SelectNodes("tr")[0].SelectNodes("td")[1].SelectNodes("img")[0].SetAttributeValue("src", imageName.Substring(0, imageName.IndexOf("_D.bmp") + 1) + ".bmp");
            // 模板图片改名
            HtmlNodeCollection liList = tableList[2].SelectNodes("tr")[0].SelectNodes("td")[0].SelectNodes("div")[0].SelectNodes("ul")[0].SelectNodes("li");

            liList[0].SelectNodes("img")[0].SetAttributeValue("src", "IMAGE\\Template\\" + reqData.rollNum.Substring(0, 5) + "\\Camera1.jpeg");
            liList[1].SelectNodes("img")[0].SetAttributeValue("src", "IMAGE\\Template\\" + reqData.rollNum.Substring(0, 5) + "\\Camera2.jpeg");
            liList[2].SelectNodes("img")[0].SetAttributeValue("src", "IMAGE\\Template\\" + reqData.rollNum.Substring(0, 5) + "\\Camera3.jpeg");

            return(doc.ToString());
        }