using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using DevExpress.XtraEditors.DXErrorProvider; using DevExpress.XtraEditors; using DevExpress.Emf; using System.Text.RegularExpressions; using System.IO; namespace ExtensionsDev { public static class ParamCheckExtension { 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 CheckNumber(this ButtonEdit @this, DXErrorProvider dxErrorProvider, string msg) { if (string.IsNullOrWhiteSpace(@this.Text.Trim())) { dxErrorProvider.SetError(@this, $"{msg}不能为空!"); return false; } double number; bool isDoubleNum = Double.TryParse(@this.Text, out number); if (!isDoubleNum) { dxErrorProvider.SetError(@this, $"{msg}必须是数字!"); return false; } dxErrorProvider.SetError(@this, string.Empty); return true; } public static bool CheckDateEdit(this DateEdit @this, DXErrorProvider dxErrorProvider, string msg) { if (string.IsNullOrWhiteSpace(@this.Text.Trim())) { dxErrorProvider.SetError(@this, msg); return false; } else { dxErrorProvider.SetError(@this, string.Empty); return true; } } public static bool CheckFile(this ButtonEdit @this, DXErrorProvider dxErrorProvider, string msg) { if (string.IsNullOrWhiteSpace(@this.Text.Trim())) { dxErrorProvider.SetError(@this, $"{msg}不能为空!"); return false; } if (!File.Exists(@this.Text.Trim())) { dxErrorProvider.SetError(@this, $"{msg}不存在!"); return false; } dxErrorProvider.SetError(@this, string.Empty); return true; } } }