基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
using DevExpress.Xpo;
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
namespace AFKAbutment
|
||||
{
|
||||
public static class DatabaseFormatJudgment
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断输入的字符串是否可以转换成数值类型
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsNumberic(string str)
|
||||
{
|
||||
double vsNum;
|
||||
bool isNum;
|
||||
isNum = double.TryParse(str, System.Globalization.NumberStyles.Float,
|
||||
System.Globalization.NumberFormatInfo.InvariantInfo, out vsNum);
|
||||
if (string.IsNullOrWhiteSpace(str)) isNum = false;
|
||||
return isNum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:SQLQuery验证</para>
|
||||
/// <para>创建人:</para>
|
||||
/// <para>创建日期: </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// <param name="TableProperties">数据库的表格属性表</param>
|
||||
/// <param name="fieldKey">列名</param>
|
||||
/// <param name="fieldValue">值</param>
|
||||
/// </summary>
|
||||
public static string SQLQueryVerification(DataTable TableProperties, string fieldKey, string fieldValue,string Comment = null)
|
||||
{
|
||||
|
||||
if (TableProperties.Rows.Count == 0) return "";
|
||||
DataRow[] ListOfAttributes = TableProperties.Select("COLUMN_NAME='" + fieldKey + "'");//指定列的数据库属性
|
||||
if (ListOfAttributes == null || ListOfAttributes.Length == 0) return "";
|
||||
string saveErrorMessage = string.Empty;
|
||||
int MaxInputLength = 0;//最大长度
|
||||
|
||||
//判断长度是否超出
|
||||
//if (ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("varchar"))
|
||||
//{
|
||||
// if (int.Parse(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"].ToString()) == -1)
|
||||
// {
|
||||
// ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] = 8000;
|
||||
// }
|
||||
// MaxInputLength = System.Text.Encoding.Default.GetBytes(fieldValue).Length;
|
||||
//}
|
||||
//else if (ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("nvarchar"))
|
||||
//{
|
||||
// if (int.Parse(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"].ToString()) == -1)
|
||||
// {
|
||||
// ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] = 4000;
|
||||
// }
|
||||
// MaxInputLength = fieldValue.Length;
|
||||
//}
|
||||
//if (!string.IsNullOrWhiteSpace(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] + "") && IsNumberic(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] + "") && int.Parse(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"].ToString()) < MaxInputLength)
|
||||
//{
|
||||
// saveErrorMessage = saveErrorMessage + fieldKey + ": 输入内容长度超出限制;\r\n";
|
||||
//}
|
||||
|
||||
//判断属性是否正确
|
||||
//if ((ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("int") || ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("decimal")) && !IsNumberic((row[col.ColumnName] + "").Replace("'", "''")) && !string.IsNullOrWhiteSpace((row[col.ColumnName] + "")))
|
||||
//{
|
||||
// saveErrorMessage = saveErrorMessage + hasContainRow["username"].ToString() + "~" + col.ColumnName + ": 数据格式错误,请输入数值;\r\n";
|
||||
//}
|
||||
|
||||
//判断非空
|
||||
if ((ListOfAttributes[0]["IS_NULLABLE"].ToString().Equals("NO") && string.IsNullOrWhiteSpace(fieldValue)))
|
||||
{
|
||||
saveErrorMessage = saveErrorMessage + (string.IsNullOrWhiteSpace(Comment) ? fieldKey : Comment + "不能为空#");
|
||||
}
|
||||
|
||||
return saveErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:MYSQL验证</para>
|
||||
/// <para>创建人:</para>
|
||||
/// <para>创建日期: </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// <param name="TableProperties">数据库的表格属性表</param>
|
||||
/// <param name="fieldKey">列名</param>
|
||||
/// <param name="fieldValue">值</param>
|
||||
/// </summary>
|
||||
public static string MYSqlVerification(DataTable TableProperties, string fieldKey, string fieldValue, string Comment = null)
|
||||
{
|
||||
|
||||
if (TableProperties.Rows.Count == 0) return "";
|
||||
DataRow[] ListOfAttributes = TableProperties.Select("Field='" + fieldKey + "'");//指定列的数据库属性
|
||||
if (ListOfAttributes == null || ListOfAttributes.Length == 0) return "";
|
||||
string saveErrorMessage = string.Empty;
|
||||
int MaxInputLength = 0;//最大长度
|
||||
|
||||
//判断长度是否超出
|
||||
//if (ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("varchar"))
|
||||
//{
|
||||
// if (int.Parse(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"].ToString()) == -1)
|
||||
// {
|
||||
// ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] = 8000;
|
||||
// }
|
||||
// MaxInputLength = System.Text.Encoding.Default.GetBytes(fieldValue).Length;
|
||||
//}
|
||||
//else if (ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("nvarchar"))
|
||||
//{
|
||||
// if (int.Parse(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"].ToString()) == -1)
|
||||
// {
|
||||
// ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] = 4000;
|
||||
// }
|
||||
// MaxInputLength = fieldValue.Length;
|
||||
//}
|
||||
//if (!string.IsNullOrWhiteSpace(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] + "") && IsNumberic(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"] + "") && int.Parse(ListOfAttributes[0]["CHARACTER_MAXIMUM_LENGTH"].ToString()) < MaxInputLength)
|
||||
//{
|
||||
// saveErrorMessage = saveErrorMessage + fieldKey + ": 输入内容长度超出限制;\r\n";
|
||||
//}
|
||||
|
||||
//判断属性是否正确
|
||||
//if ((ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("int") || ListOfAttributes[0]["DATA_TYPE"].ToString().Equals("decimal")) && !IsNumberic((row[col.ColumnName] + "").Replace("'", "''")) && !string.IsNullOrWhiteSpace((row[col.ColumnName] + "")))
|
||||
//{
|
||||
// saveErrorMessage = saveErrorMessage + hasContainRow["username"].ToString() + "~" + col.ColumnName + ": 数据格式错误,请输入数值;\r\n";
|
||||
//}
|
||||
|
||||
//判断非空
|
||||
if ((ListOfAttributes[0]["Null"].ToString().Equals("NO") && string.IsNullOrWhiteSpace(fieldValue)))
|
||||
{
|
||||
saveErrorMessage = saveErrorMessage + (string.IsNullOrWhiteSpace(Comment) ? fieldKey : Comment + "不能为空#");
|
||||
}
|
||||
|
||||
return saveErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user