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; namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu { public partial class BJdmt : ConditionPanel { public BJdmt() { this.ConditionPanelName = "节点图片信息管理"; InitializeComponent(); this.SetSize(800, 635); 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("tz"), rd.GetFieldValue("fsw"), rd.GetFieldValue("xh"), rd.GetFieldValue("dzms")); uilb.Items.Add(new DoListItem(rd.GetFieldValue("bsm").ToString(), mpValue)); rd.MoveNext(); } } private void uiButton3_Click(object sender, EventArgs e) { //if (uilb.SelectedItem == null) { UIMessageTip.ShowError("请选择图片对应的管点信息"); return; } //OpenFileDialog ofd = new OpenFileDialog //{ // Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png", // RestoreDirectory = true, // Title = "请选择需要上传的图片" //}; //if (ofd.ShowDialog() != DialogResult.OK) return; //string imgFileName = ofd.FileName; //if (new FileInfo(imgFileName).Length > (1024 * 1000)) //{ // UIMessageTip.ShowError("请将图片缩放至1MB以内"); return; //} //try //{ // File.Copy(imgFileName, Commons.Paths.ApplicationPictureDir + "\\" + (uilb.SelectedItem as DoListItem).Key + ".jpg", true); //} //catch (Exception ex) //{ // ComsStatic.ShowErrorLog("图片上传失败", ex.Message); return; //} //UIMessageTip.ShowOk("图片上传成功"); //using (FileStream lStream = new FileStream(imgFileName, FileMode.Open, FileAccess.Read)) // picbox1.Image = Image.FromStream(lStream); } private void uilb_SelectedIndexChanged(object sender, EventArgs e) { 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; } } private void pictureBox_DoubleClick(object sender, EventArgs e) { PictureBox pb = sender as PictureBox; if (File.Exists(pb.ImageLocation) && !pb.ImageLocation.Contains("no.png")) System.Diagnostics.Process.Start(pb.ImageLocation); } private void PicUpload_Click(object sender, EventArgs e) { if (uilb.SelectedItem == null) { UIMessageTip.ShowError("请选择图片对应的管点信息"); return; } OpenFileDialog ofd = new OpenFileDialog { Filter = "Jpg 图片|*.jpg|Bmp 图片|*.bmp|Png 图片|*.png", RestoreDirectory = true, Title = "请选择需要上传的图片" }; if (ofd.ShowDialog() != DialogResult.OK) return; string imgFileName = ofd.FileName; if (new FileInfo(imgFileName).Length > (1024 * 1000)) { UIMessageTip.ShowError("请将图片缩放至1MB以内"); return; } PictureBox pb = uicms.SourceControl as PictureBox; 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; } } private void PicDelete_Click(object sender, EventArgs e) { //if (!UIMessageDialog.ShowAskDialog(this.ParentForm, "提示", "确定删除该图片吗")) return; PictureBox pb = uicms.SourceControl as PictureBox; 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 = ""; } } }