using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using SuperMap.Data; using Sunny.UI; using WWPipeLine.MapBasic; using WeifenLuo.WinFormsUI.Docking; using SuperMap.UI; using SuperMap.Mapping; using System.IO; using System.Net; using WWPipeLine.Commons; namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu { public partial class BJdmt : ConditionPanel { string imgNoPath = Paths.ApplicationResourcesDir + "\\no.png"; public BJdmt() { this.ConditionPanelName = "节点图片信息管理"; InitializeComponent(); this.SetSize(800, 600); this.IsShowPanelFooter = false; } protected override void OnLoad(EventArgs e) { foreach (Layer lyr in ComsStatic.MapLayers) { if (lyr.Dataset.Type != DatasetType.Point) continue; uicbx.Items.Add(new DoListItem(lyr.Dataset.Name, lyr.Caption)); } uicbx.SelectedIndex = 0; } private void uiButton1_Click(object sender, EventArgs e) { DatasetVector dv = ComsStatic.Datasource.Datasets[(uicbx.SelectedItem as DoListItem).Key] as DatasetVector; string sql = ""; if (!string.IsNullOrEmpty(uitbkey.Text)) //sql = string.Format(" dmt like '%{0}%' ", uitbkey.Text); sql = string.Format("tz like '%{0}%' OR fsw like '%{0}%' OR xh like '%{0}%' OR dzms like '%{0}%'", uitbkey.Text); Recordset rd = dv.Query(sql, CursorType.Static); rd.MoveFirst(); uilb.Items.Clear(); while (!rd.IsEOF) { string mpValue = string.Format("{0} {1} {2} {3}", rd.GetFieldValue("smid"), rd.GetFieldValue("fsw"), rd.GetFieldValue("xh"), rd.GetFieldValue("dzms")); uilb.Items.Add(new DoListItem(rd.GetFieldValue("bsm").ToString(), mpValue)); rd.MoveNext(); } ComsStatic.RecordsetDispose(rd); } private void uilb_SelectedIndexChanged(object sender, EventArgs e) { string imgUrl = ComsStatic.webTool + "uploadImg/" + (uilb.SelectedItem as DoListItem).Key; showImg(picbox1, "-01.jpg"); showImg(picbox2, "-02.jpg"); showImg(picbox3, "-03.jpg"); showImg(picbox4, "-04.jpg"); void showImg(PictureBox pb, string urlPb) { string imgUrlPB = imgUrl + urlPb; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(imgUrlPB); webRequest.Timeout = 5000; webRequest.Method = "HEAD"; webRequest.CookieContainer = new CookieContainer(); HttpWebResponse httpWebResponse = null; try { httpWebResponse = (HttpWebResponse)webRequest.GetResponse(); if (httpWebResponse.StatusCode == HttpStatusCode.OK) { pb.Load(imgUrlPB); } else { pb.Load(imgNoPath); } } catch { pb.Load(imgNoPath); } finally { if (httpWebResponse != null) { httpWebResponse.Close(); httpWebResponse.Dispose(); } } } #region 读取到当前客户端所在的机器 //string imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-01.jpg"; //if (!File.Exists(imgPath)) // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png"; //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read)) //{ // picbox1.Image = Image.FromStream(lStream); // picbox1.ImageLocation = imgPath; //} //imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-02.jpg"; //if (!File.Exists(imgPath)) // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png"; //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read)) //{ // picbox2.Image = Image.FromStream(lStream); // picbox2.ImageLocation = imgPath; //} //imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-03.jpg"; //if (!File.Exists(imgPath)) // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png"; //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read)) //{ // picbox3.Image = Image.FromStream(lStream); // picbox3.ImageLocation = imgPath; //} //imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-04.jpg"; //if (!File.Exists(imgPath)) // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png"; //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read)) //{ // picbox4.Image = Image.FromStream(lStream); // picbox4.ImageLocation = imgPath; //} #endregion } private void pictureBox_DoubleClick(object sender, EventArgs e) { try { PictureBox pb = sender as PictureBox; if (pb.ImageLocation.Contains("no.png")) return;//File.Exists(pb.ImageLocation) && System.Diagnostics.Process.Start(pb.ImageLocation); } catch { } } private void PicUpload_Click(object sender, EventArgs e) { if (uilb.SelectedItem == null) { UIMessageTip.ShowError("请选择图片对应的管点信息"); return; } OpenFileDialog ofd = new OpenFileDialog { Filter = "Jpeg 图片|*.jpeg|Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png", RestoreDirectory = true, Title = "请选择需要上传的图片" }; if (ofd.ShowDialog() != DialogResult.OK) return; string imgFileName = ofd.FileName; if (new FileInfo(imgFileName).Length > 1000000) { UIMessageTip.ShowError("请将图片缩放至1MB以内"); return; } PictureBox pb = uicms.SourceControl as PictureBox; string uploadName = (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg"; byte[] sb = new WebClient().UploadFile(ComsStatic.webTool + "Tools/PictureUpload.ashx?action=UpLoadFile&name=" + uploadName, "POST", imgFileName); string uploadResult = Encoding.GetEncoding("gb2312").GetString(sb); if (string.IsNullOrEmpty(uploadResult)) { ComsStatic.ShowErrorLog("图片上传失败"); return; } ComsStatic.ShowOKLog("图片上传成功", ComsStatic.webTool + uploadResult); pb.Load(ComsStatic.webTool + uploadResult); //WebRequest webRequest = System.Net.WebRequest.Create(ComsStatic.webUrl + uploadResult); //webRequest.Timeout = 5000; //webRequest.Method = "HEAD"; //HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse(); //if (httpWebResponse.StatusCode == HttpStatusCode.OK) //{ //} #region 上传到当前客户端所在的机器 //string uploadImg = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg"; //try //{ // File.Copy(imgFileName, uploadImg, true); //} //catch (Exception ex) //{ // ComsStatic.ShowErrorLog("图片上传失败", ex.Message); return; //} //ComsStatic.ShowOKLog("图片上传成功", pb.ImageLocation); //using (FileStream lStream = new FileStream(uploadImg, FileMode.Open, FileAccess.Read)) //{ // pb.Image = Image.FromStream(lStream); // pb.ImageLocation = uploadImg; //} #endregion #region 上传到服务端所在的机器 会暴露服务端的文件夹 不安全 //string serverPath = @"\\192.168.17.44\测试\" + (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg"; //WebClient myWebClient = new WebClient(); //myWebClient.Credentials = CredentialCache.DefaultCredentials; //using (FileStream fs = new FileStream(imgFileName, FileMode.Open, FileAccess.Read)) //{ // BinaryReader r = new BinaryReader(fs); // byte[] postArray = r.ReadBytes((int)fs.Length); // Stream postStream = myWebClient.OpenWrite(serverPath, "PUT"); // if (postStream.CanWrite) // { // postStream.Write(postArray, 0, postArray.Length); // postStream.Close(); // fs.Dispose(); // } //} #endregion } private void PicDelete_Click(object sender, EventArgs e) { //if (!UIMessageDialog.ShowAskDialog(this.ParentForm, "提示", "确定删除该图片吗")) return; PictureBox pb = uicms.SourceControl as PictureBox; string uploadName = (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg"; byte[] sb = new WebClient().UploadFile(ComsStatic.webTool + "Tools/PictureUpload.ashx?action=UpLoadFile&name=" + uploadName, "POST", imgNoPath); string uploadResult = Encoding.GetEncoding("gb2312").GetString(sb); if (string.IsNullOrEmpty(uploadResult)) { ComsStatic.ShowErrorLog("图片删除失败"); return; } ComsStatic.ShowOKLog("图片删除成功", ComsStatic.webTool + uploadResult); pb.Load(imgNoPath); #region 删除服务端的图片 删除失败 //string imgUrlPB = pb.ImageLocation; //string imgNo = Paths.ApplicationResourcesDir + "\\no.png"; //HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(imgUrlPB); //webRequest.Timeout = 5000; //webRequest.Method = "DELETE"; //webRequest.CookieContainer = new CookieContainer(); //HttpWebResponse httpWebResponse = null; //try //{ // httpWebResponse = (HttpWebResponse)webRequest.GetResponse(); // if (httpWebResponse.StatusCode == HttpStatusCode.OK) // { // pb.Load(imgNo); // } //} //catch (WebException ex) //{ // LogHelper.Error(ex); //} //finally //{ // if (httpWebResponse != null) // { // httpWebResponse.Close(); // httpWebResponse.Dispose(); // } //} #endregion #region 删除当前客户端所在的机器 //try //{ // if (File.Exists(pb.ImageLocation) && !pb.ImageLocation.Contains("no.png")) // new FileInfo(pb.ImageLocation).Delete(); //} //catch (Exception ex) //{ // ComsStatic.ShowErrorLog("图片删除失败", ex.Message); return; //} //ComsStatic.ShowOKLog("图片删除成功", pb.ImageLocation); //pb.Image = null; //pb.ImageLocation = ""; #endregion } } }