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;
}
///
/// 重载数据
///
public event Action ReloadDataEvent;
private string _filePath = null;
///
/// 绑定数据
///
public void SetBindingData()
{
}
///
/// 绑定数据
///
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();
}
}
}