1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using DevExpress.XtraEditors;
- using DevExpress.XtraEditors.DXErrorProvider;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ExtensionsDev
- {
- public static class BaseEditExtension
- {
- public static void UseDoubleClickToSelectAll(this BaseEdit ctrl)
- {
- ctrl.DoubleClick += Ctrl_DoubleClick;
- }
- private static void Ctrl_DoubleClick(object sender, EventArgs e)
- {
- var ctrl = (BaseEdit)sender;
- ctrl.SelectAll();
- }
- public static bool CheckLonLat(this TextEdit @this, DXErrorProvider dxErrorProvider, string msg)
- {
- if (string.IsNullOrWhiteSpace(@this.Text.Trim()))
- {
- dxErrorProvider.SetError(@this, $"{msg}经纬度不能为空!");
- return false;
- }
- var context = @this.Text.Split(',');
- if (context.Length != 2)
- {
- dxErrorProvider.SetError(@this, $"{msg}经度纬度之间用英文逗号隔开!");
- return false;
- }
- double lon;
- bool isDoubleLon = Double.TryParse(context[0], out lon);
- if (!isDoubleLon || lon > 180 || lon < -180)
- {
- dxErrorProvider.SetError(@this, $"{msg}经度范围[180,-180]!");
- return false;
- }
- double lat;
- bool isDoubleLat = Double.TryParse(context[1], out lat);
- if (!isDoubleLat || lat > 90 || lat < -90)
- {
- dxErrorProvider.SetError(@this, $"{msg}纬度范围[90,-90]!");
- return false;
- }
- dxErrorProvider.SetError(@this, string.Empty);
- return true;
- }
- public static (bool, string) CheckLonLat(this TextEdit @this, string msg)
- {
- if (string.IsNullOrWhiteSpace(@this.Text.Trim()))
- {
- return (false, $"{msg}经纬度不能为空!");
- }
- var context = @this.Text.Split(',');
- if (context.Length != 2)
- {
- return (false, $"{msg}经度纬度之间用英文逗号隔开!");
- }
- double lon;
- bool isDoubleLon = Double.TryParse(context[0], out lon);
- if (!isDoubleLon || lon > 180 || lon < -180)
- {
- return (false, $"{msg}经度范围[180,-180]!");
- }
- double lat;
- bool isDoubleLat = Double.TryParse(context[1], out lat);
- if (!isDoubleLat || lat > 90 || lat < -90)
- {
- return (false, $"{msg}纬度范围[90,-90]!");
- }
- return (true, "");
- }
- public static double[] GetLonLat(this TextEdit @this)
- {
- var context = @this.Text.Replace(",", ",").Split(',');
- double lon = Convert.ToDouble(context[0]);
- double lat = Convert.ToDouble(context[1]);
- return new double[3] { lon, lat, 0 };
- }
- }
- }
|