ningshuxia
2025-03-21 7af1565cf5af77397453a3ea6ad516ac9be371f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace PBS.WinFrmUI.Hydro
{
    public partial class SetMapBaseMapDlg : DevExpress.XtraEditors.XtraForm
    {
        public SetMapBaseMapDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.layoutControl1.SetupLayoutControl();
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
        }
 
        /// <summary>
        /// 重载数据
        /// </summary>
        public event Action<string, double, double> ReloadDataEvent;
 
        private string _filePath = null;
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
 
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(string filePath, double width, double height)
        { 
            if (File.Exists(filePath))
            {
                using var stream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
                using var image = Image.FromStream(stream);
                this.pictureEditBaseMap.Image = new Bitmap(image);
            }
 
            _filePath = filePath;
            this.txtBaseMapWidth.EditValue = width;
            this.txtBaseMapHeight.EditValue = height;
 
        }
 
        private void pictureEditBaseMap_Click(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.png;*.gif)|*.bmp;*.jpg;*.jpeg;*.png;*.gif";
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            if (openFileDialog.ShowDialog() != DialogResult.OK)
                return;
 
            _filePath = openFileDialog.FileName;
            using var stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.ReadWrite);
            using var image = Image.FromStream(stream);
            this.pictureEditBaseMap.Image =new Bitmap(image);
 
        }
 
 
        //数据验证
        private bool Verify()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(_filePath))
            {
                this.dxErrorProvider1.SetError(this.pictureEditBaseMap, "必选项");
                return false;
            }
 
            if (this.pictureEditBaseMap.Image == null)
            {
                this.dxErrorProvider1.SetError(this.pictureEditBaseMap, "必选项");
                return false;
            }
            return true;
        }
 
        //确定
        private void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (!Verify())
            {
                return;
            }
            var filePath = _filePath;
            var width = Convert.ToDouble(this.txtBaseMapWidth.EditValue);
            var height = Convert.ToDouble(this.txtBaseMapHeight.EditValue);
 
 
            this.ReloadDataEvent?.Invoke(filePath,width,height);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
    
      
    }
}