BJdmt.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using SuperMap.Data;
  12. using Sunny.UI;
  13. using WWPipeLine.MapBasic;
  14. using WeifenLuo.WinFormsUI.Docking;
  15. using SuperMap.UI;
  16. using SuperMap.Mapping;
  17. using System.IO;
  18. using System.Net;
  19. using WWPipeLine.Commons;
  20. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  21. {
  22. public partial class BJdmt : ConditionPanel
  23. {
  24. string imgNoPath = Paths.ApplicationResourcesDir + "\\no.png";
  25. public BJdmt()
  26. {
  27. this.ConditionPanelName = "节点图片信息管理";
  28. InitializeComponent();
  29. this.SetSize(800, 600);
  30. this.IsShowPanelFooter = false;
  31. }
  32. protected override void OnLoad(EventArgs e)
  33. {
  34. foreach (Layer lyr in ComsStatic.MapLayers)
  35. {
  36. if (lyr.Dataset.Type != DatasetType.Point) continue;
  37. uicbx.Items.Add(new DoListItem(lyr.Dataset.Name, lyr.Caption));
  38. }
  39. uicbx.SelectedIndex = 0;
  40. }
  41. private void uiButton1_Click(object sender, EventArgs e)
  42. {
  43. DatasetVector dv = ComsStatic.Datasource.Datasets[(uicbx.SelectedItem as DoListItem).Key] as DatasetVector;
  44. string sql = "";
  45. if (!string.IsNullOrEmpty(uitbkey.Text)) //sql = string.Format(" dmt like '%{0}%' ", uitbkey.Text);
  46. sql = string.Format("tz like '%{0}%' OR fsw like '%{0}%' OR xh like '%{0}%' OR dzms like '%{0}%'", uitbkey.Text);
  47. Recordset rd = dv.Query(sql, CursorType.Static);
  48. rd.MoveFirst();
  49. uilb.Items.Clear();
  50. while (!rd.IsEOF)
  51. {
  52. string mpValue = string.Format("{0} {1} {2} {3}", rd.GetFieldValue("smid"), rd.GetFieldValue("fsw"), rd.GetFieldValue("xh"), rd.GetFieldValue("dzms"));
  53. uilb.Items.Add(new DoListItem(rd.GetFieldValue("bsm").ToString(), mpValue));
  54. rd.MoveNext();
  55. }
  56. ComsStatic.RecordsetDispose(rd);
  57. }
  58. private void uilb_SelectedIndexChanged(object sender, EventArgs e)
  59. {
  60. string imgUrl = ComsStatic.webTool + "uploadImg/" + (uilb.SelectedItem as DoListItem).Key;
  61. showImg(picbox1, "-01.jpg");
  62. showImg(picbox2, "-02.jpg");
  63. showImg(picbox3, "-03.jpg");
  64. showImg(picbox4, "-04.jpg");
  65. void showImg(PictureBox pb, string urlPb)
  66. {
  67. string imgUrlPB = imgUrl + urlPb;
  68. HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(imgUrlPB);
  69. webRequest.Timeout = 5000;
  70. webRequest.Method = "HEAD";
  71. webRequest.CookieContainer = new CookieContainer();
  72. HttpWebResponse httpWebResponse = null;
  73. try
  74. {
  75. httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
  76. if (httpWebResponse.StatusCode == HttpStatusCode.OK)
  77. {
  78. pb.Load(imgUrlPB);
  79. }
  80. else
  81. {
  82. pb.Load(imgNoPath);
  83. }
  84. }
  85. catch
  86. {
  87. pb.Load(imgNoPath);
  88. }
  89. finally
  90. {
  91. if (httpWebResponse != null)
  92. {
  93. httpWebResponse.Close();
  94. httpWebResponse.Dispose();
  95. }
  96. }
  97. }
  98. #region 读取到当前客户端所在的机器
  99. //string imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-01.jpg";
  100. //if (!File.Exists(imgPath))
  101. // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png";
  102. //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
  103. //{
  104. // picbox1.Image = Image.FromStream(lStream);
  105. // picbox1.ImageLocation = imgPath;
  106. //}
  107. //imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-02.jpg";
  108. //if (!File.Exists(imgPath))
  109. // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png";
  110. //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
  111. //{
  112. // picbox2.Image = Image.FromStream(lStream);
  113. // picbox2.ImageLocation = imgPath;
  114. //}
  115. //imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-03.jpg";
  116. //if (!File.Exists(imgPath))
  117. // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png";
  118. //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
  119. //{
  120. // picbox3.Image = Image.FromStream(lStream);
  121. // picbox3.ImageLocation = imgPath;
  122. //}
  123. //imgPath = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-04.jpg";
  124. //if (!File.Exists(imgPath))
  125. // imgPath = Commons.Paths.ApplicationPictureDir + "\\no.png";
  126. //using (FileStream lStream = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
  127. //{
  128. // picbox4.Image = Image.FromStream(lStream);
  129. // picbox4.ImageLocation = imgPath;
  130. //}
  131. #endregion
  132. }
  133. private void pictureBox_DoubleClick(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. PictureBox pb = sender as PictureBox;
  138. if (pb.ImageLocation.Contains("no.png")) return;//File.Exists(pb.ImageLocation) &&
  139. System.Diagnostics.Process.Start(pb.ImageLocation);
  140. }
  141. catch { }
  142. }
  143. private void PicUpload_Click(object sender, EventArgs e)
  144. {
  145. if (uilb.SelectedItem == null) { UIMessageTip.ShowError("请选择图片对应的管点信息"); return; }
  146. OpenFileDialog ofd = new OpenFileDialog
  147. {
  148. Filter = "Jpeg 图片|*.jpeg|Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png",
  149. RestoreDirectory = true,
  150. Title = "请选择需要上传的图片"
  151. };
  152. if (ofd.ShowDialog() != DialogResult.OK) return;
  153. string imgFileName = ofd.FileName;
  154. if (new FileInfo(imgFileName).Length > 1000000)
  155. {
  156. UIMessageTip.ShowError("请将图片缩放至1MB以内"); return;
  157. }
  158. PictureBox pb = uicms.SourceControl as PictureBox;
  159. string uploadName = (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg";
  160. byte[] sb = new WebClient().UploadFile(ComsStatic.webTool + "Tools/PictureUpload.ashx?action=UpLoadFile&name=" + uploadName, "POST", imgFileName);
  161. string uploadResult = Encoding.GetEncoding("gb2312").GetString(sb);
  162. if (string.IsNullOrEmpty(uploadResult))
  163. {
  164. ComsStatic.ShowErrorLog("图片上传失败"); return;
  165. }
  166. ComsStatic.ShowOKLog("图片上传成功", ComsStatic.webTool + uploadResult);
  167. pb.Load(ComsStatic.webTool + uploadResult);
  168. //WebRequest webRequest = System.Net.WebRequest.Create(ComsStatic.webUrl + uploadResult);
  169. //webRequest.Timeout = 5000;
  170. //webRequest.Method = "HEAD";
  171. //HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
  172. //if (httpWebResponse.StatusCode == HttpStatusCode.OK)
  173. //{
  174. //}
  175. #region 上传到当前客户端所在的机器
  176. //string uploadImg = Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg";
  177. //try
  178. //{
  179. // File.Copy(imgFileName, uploadImg, true);
  180. //}
  181. //catch (Exception ex)
  182. //{
  183. // ComsStatic.ShowErrorLog("图片上传失败", ex.Message); return;
  184. //}
  185. //ComsStatic.ShowOKLog("图片上传成功", pb.ImageLocation);
  186. //using (FileStream lStream = new FileStream(uploadImg, FileMode.Open, FileAccess.Read))
  187. //{
  188. // pb.Image = Image.FromStream(lStream);
  189. // pb.ImageLocation = uploadImg;
  190. //}
  191. #endregion
  192. #region 上传到服务端所在的机器 会暴露服务端的文件夹 不安全
  193. //string serverPath = @"\\192.168.17.44\测试\" + (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg";
  194. //WebClient myWebClient = new WebClient();
  195. //myWebClient.Credentials = CredentialCache.DefaultCredentials;
  196. //using (FileStream fs = new FileStream(imgFileName, FileMode.Open, FileAccess.Read))
  197. //{
  198. // BinaryReader r = new BinaryReader(fs);
  199. // byte[] postArray = r.ReadBytes((int)fs.Length);
  200. // Stream postStream = myWebClient.OpenWrite(serverPath, "PUT");
  201. // if (postStream.CanWrite)
  202. // {
  203. // postStream.Write(postArray, 0, postArray.Length);
  204. // postStream.Close();
  205. // fs.Dispose();
  206. // }
  207. //}
  208. #endregion
  209. }
  210. private void PicDelete_Click(object sender, EventArgs e)
  211. {
  212. //if (!UIMessageDialog.ShowAskDialog(this.ParentForm, "提示", "确定删除该图片吗")) return;
  213. PictureBox pb = uicms.SourceControl as PictureBox;
  214. string uploadName = (uilb.SelectedItem as DoListItem).Key + "-" + pb.Tag.ToString() + ".jpg";
  215. byte[] sb = new WebClient().UploadFile(ComsStatic.webTool + "Tools/PictureUpload.ashx?action=UpLoadFile&name=" + uploadName, "POST", imgNoPath);
  216. string uploadResult = Encoding.GetEncoding("gb2312").GetString(sb);
  217. if (string.IsNullOrEmpty(uploadResult))
  218. {
  219. ComsStatic.ShowErrorLog("图片删除失败"); return;
  220. }
  221. ComsStatic.ShowOKLog("图片删除成功", ComsStatic.webTool + uploadResult);
  222. pb.Load(imgNoPath);
  223. #region 删除服务端的图片 删除失败
  224. //string imgUrlPB = pb.ImageLocation;
  225. //string imgNo = Paths.ApplicationResourcesDir + "\\no.png";
  226. //HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(imgUrlPB);
  227. //webRequest.Timeout = 5000;
  228. //webRequest.Method = "DELETE";
  229. //webRequest.CookieContainer = new CookieContainer();
  230. //HttpWebResponse httpWebResponse = null;
  231. //try
  232. //{
  233. // httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
  234. // if (httpWebResponse.StatusCode == HttpStatusCode.OK)
  235. // {
  236. // pb.Load(imgNo);
  237. // }
  238. //}
  239. //catch (WebException ex)
  240. //{
  241. // LogHelper.Error(ex);
  242. //}
  243. //finally
  244. //{
  245. // if (httpWebResponse != null)
  246. // {
  247. // httpWebResponse.Close();
  248. // httpWebResponse.Dispose();
  249. // }
  250. //}
  251. #endregion
  252. #region 删除当前客户端所在的机器
  253. //try
  254. //{
  255. // if (File.Exists(pb.ImageLocation) && !pb.ImageLocation.Contains("no.png"))
  256. // new FileInfo(pb.ImageLocation).Delete();
  257. //}
  258. //catch (Exception ex)
  259. //{
  260. // ComsStatic.ShowErrorLog("图片删除失败", ex.Message); return;
  261. //}
  262. //ComsStatic.ShowOKLog("图片删除成功", pb.ImageLocation);
  263. //pb.Image = null;
  264. //pb.ImageLocation = "";
  265. #endregion
  266. }
  267. }
  268. }