You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
2.9 KiB
108 lines
2.9 KiB
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Text; |
|
|
|
namespace KGIS.Plugin.DataChanging |
|
{ |
|
public static class ExtendMethd |
|
{ |
|
public static string ToTrim(this object value) |
|
{ |
|
if (value == null || value == DBNull.Value) |
|
return string.Empty; |
|
return value.ToString().Trim(); |
|
} |
|
public static double ToDouble(this object value) |
|
{ |
|
if (value == null) |
|
return 0; |
|
double result; |
|
double.TryParse(value.ToString(), out result); |
|
return result; |
|
} |
|
|
|
public static int GetIntByObject(object obj) |
|
{ |
|
int iTemp = 0; |
|
try |
|
{ |
|
iTemp = JudgeIsCouldConversionInt(obj) == true ? Convert.ToInt32(obj) : 0; |
|
return iTemp; |
|
} |
|
catch (Exception ex) |
|
{ |
|
return 0; |
|
} |
|
} |
|
|
|
private static bool JudgeIsCouldConversionInt(object sTheValue) |
|
{ |
|
try |
|
{ |
|
if (sTheValue == null) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
if (string.IsNullOrWhiteSpace(sTheValue.ToString()) == true) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
int iTemp = 0; |
|
if (int.TryParse(sTheValue.ToString(), out iTemp) == false) |
|
{ |
|
return false; |
|
} |
|
else |
|
{ |
|
return true; |
|
} |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
public static double ToDouble(this object value, int w) |
|
{ |
|
if (value == null) |
|
return 0; |
|
double result; |
|
double.TryParse(value.ToString(), out result); |
|
if (result > 0) |
|
{ |
|
result = Math.Round(result, w, MidpointRounding.AwayFromZero); |
|
} |
|
return result; |
|
} |
|
|
|
public static decimal ToDecimal(this object value) |
|
{ |
|
if (value == null) |
|
return 0; |
|
decimal result; |
|
decimal.TryParse(value.ToString(), out result); |
|
return result; |
|
} |
|
|
|
public static decimal ToDecimal(this object value, int w) |
|
{ |
|
if (value == null) |
|
return 0; |
|
decimal result; |
|
decimal.TryParse(value.ToString(), out result); |
|
if (result > 0) |
|
{ |
|
result = Math.Round(result, w, MidpointRounding.AwayFromZero); |
|
} |
|
return result; |
|
} |
|
} |
|
}
|
|
|