Browse Source

验证整理

bjmzak
wxd 2 years ago
parent
commit
6ab4c28d4d
  1. 4
      src/Shentun.Peis.Domain/CardBills/CardBillManager.cs
  2. 10
      src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs
  3. 4
      src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs
  4. 63
      src/Shentun.Peis.Domain/DataHelper.cs
  5. 6
      src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs
  6. 16
      src/Shentun.Peis.Domain/Items/ItemManager.cs

4
src/Shentun.Peis.Domain/CardBills/CardBillManager.cs

@ -34,9 +34,9 @@ namespace Shentun.Peis.CardBills
)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckGuidIsNull(entity.CardRegisterId, "卡登记编号");
DataHelper.CheckGuidIsDefaultValue(entity.CardRegisterId, "卡登记编号");
DataHelper.CheckStringIsNull(entity.PayModeId, "支付方式");
DataHelper.CheckDecimalIsNull(entity.BillMoney, "记账金额");
DataHelper.CheckDecimalIsGeaterThanZero(entity.BillMoney, "记账金额");
return new CardBill(GuidGenerator.Create())
{

10
src/Shentun.Peis.Domain/CardRegisters/CardRegisterManager.cs

@ -97,7 +97,7 @@ namespace Shentun.Peis.CardRegisters
public async Task UpdateActive(CardRegister entity, char isActive)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckCharIsNull(isActive, "使用标志", true);
DataHelper.CheckCharIsYOrN(isActive, "使用标志");
if (isActive == 'N')
{
@ -126,7 +126,6 @@ namespace Shentun.Peis.CardRegisters
public CardBill CreateCardBill(CardRegister entity, string payModeId, char billFlag, decimal amount)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckCharIsNull(billFlag, "记账标志");
if (amount == 0)
{
throw new ArgumentException("金额等于0");
@ -164,7 +163,6 @@ namespace Shentun.Peis.CardRegisters
public void AddCardBill(CardRegister entity, string payModeId, char billFlag, decimal amount)
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckCharIsNull(billFlag, "记账标志");
if (amount == 0)
{
throw new ArgumentException("金额等于0");
@ -198,9 +196,9 @@ namespace Shentun.Peis.CardRegisters
DataHelper.CheckStringIsNull(entity.CustomerName, "领用者");
DataHelper.CheckStringIsNull(entity.IdNo, "身份证号");
DataHelper.CheckStringIsNull(entity.IdNo, "手机号");
DataHelper.CheckGuidIsNull(entity.CardTypeId, "卡类型");
DataHelper.CheckGuidIsNull(entity.OrganizationUnitId, "体检中心");
DataHelper.CheckCharIsNull(entity.IsActive, "使用标志", true);
DataHelper.CheckGuidIsDefaultValue(entity.CardTypeId, "卡类型");
DataHelper.CheckGuidIsDefaultValue(entity.OrganizationUnitId, "体检中心");
DataHelper.CheckCharIsYOrN(entity.IsActive, "使用标志");
}
}
}

4
src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs

@ -95,8 +95,8 @@ namespace Shentun.Peis.CardTypes
private void Verify(CardType entity)
{
DataHelper.CheckStringIsNull(entity.DisplayName, "名称");
DataHelper.CheckIntIsNull(entity.Discount, "折扣率");
DataHelper.CheckIntIsNull(entity.ExpiryDay, "有效期");
DataHelper.CheckIntIsGeaterThanZero(entity.Discount, "折扣率");
DataHelper.CheckIntIsGeaterThanZero(entity.ExpiryDay, "有效期");
}

63
src/Shentun.Peis.Domain/DataHelper.cs

@ -392,25 +392,21 @@ namespace Shentun.Peis
}
}
#region 验证char类型参数
/// <summary>
/// 数据检查 字符
/// 验证char类型参数是否为null
/// </summary>
/// <param name="value">需要验证的值</param>
/// <param name="parameterName">字段名称</param>
/// <param name="IsBoolValue"> 默认false(true 验证为Y跟N false 不验证)</param>
/// <param name="ExceptionMessage">异常提示后缀</param>
/// <exception cref="ArgumentException"></exception>
public static void CheckCharIsNull(char? value, string parameterName, bool IsBoolValue = false, string ExceptionMessage = "不能为空")
public static void CheckCharIsNull(char? value, string parameterName, string ExceptionMessage = "不能为空")
{
if (value == null || value == '0')
if (value == null)
{
throw new ArgumentException($"{parameterName}{ExceptionMessage}");
}
if (IsBoolValue && value != 'Y' && value != 'N')
{
throw new ArgumentException($"{parameterName}参数为:{value},是无效值");
}
}
/// <summary>
@ -433,27 +429,26 @@ namespace Shentun.Peis
/// </summary>
/// <param name="value">需要验证的值</param>
/// <param name="parameterName">字段名称</param>
/// <param name="IsBoolValue"> 默认false(true 验证为Y跟N false 不验证)</param>
/// <param name="ExceptionMessage">异常提示后缀</param>
/// <exception cref="ArgumentException"></exception>
public static void CheckCharValidValue(char value, string parameterName, string ExceptionMessage = "是无效值,只能为Y跟N")
public static void CheckCharIsYOrN(char value, string parameterName)
{
if (value != 'Y' && value != 'N')
{
throw new ArgumentException($"{parameterName}参数为:{value},是无效值");
throw new ArgumentException($"{parameterName}参数为:{value},是无效值,只能为Y跟N");
}
}
#endregion
/// <summary>
/// 数据检查 整型
/// 验证Int类型数据是否>0
/// </summary>
/// <param name="value">需要验证的值</param>
/// <param name="parameterName">字段名称</param>
/// <param name="ExceptionMessage">异常提示后缀</param>
/// <exception cref="ArgumentException"></exception>
public static void CheckIntIsNull(int? value, string parameterName, string ExceptionMessage = "不能为空")
public static void CheckIntIsGeaterThanZero(int value, string parameterName, string ExceptionMessage = "只能为大于0的值")
{
if (value == null || value == 0)
if (value > 0)
{
throw new ArgumentException($"{parameterName}{ExceptionMessage}");
}
@ -461,7 +456,7 @@ namespace Shentun.Peis
/// <summary>
/// 数据检查 Guid
/// 验证Guid数据是否为null
/// </summary>
/// <param name="value">需要验证的值</param>
/// <param name="parameterName">字段名称</param>
@ -469,12 +464,44 @@ namespace Shentun.Peis
/// <exception cref="ArgumentException"></exception>
public static void CheckGuidIsNull(Guid? value, string parameterName, string ExceptionMessage = "不能为空")
{
if (value == null || value == Guid.Empty)
if (value == null)
{
throw new ArgumentException($"{parameterName}{ExceptionMessage}");
}
}
/// <summary>
/// 验证Guid数据是否为默认值00000000-0000-0000-0000-000000000000
/// </summary>
/// <param name="value">需要验证的值</param>
/// <param name="parameterName">字段名称</param>
/// <param name="ExceptionMessage">异常提示后缀</param>
/// <exception cref="ArgumentException"></exception>
public static void CheckGuidIsDefaultValue(Guid? value, string parameterName, string ExceptionMessage = "不能为默认值00000000-0000-0000-0000-000000000000")
{
if (value == Guid.Empty)
{
throw new ArgumentException($"{parameterName}{ExceptionMessage}");
}
}
/// <summary>
///验证decimal类型数据大于0
/// </summary>
/// <param name="value">需要验证的值</param>
/// <param name="parameterName">字段名称</param>
/// <param name="ExceptionMessage">异常提示后缀</param>
/// <exception cref="ArgumentException"></exception>
public static void CheckDecimalIsGeaterThanZero(decimal value, string parameterName, string ExceptionMessage = "值只能大于0")
{
if (value > 0)
{
throw new ArgumentException($"{parameterName}{ExceptionMessage}");
}
}
/// <summary>
/// 数据检查 decimal
/// </summary>
@ -484,7 +511,7 @@ namespace Shentun.Peis
/// <exception cref="ArgumentException"></exception>
public static void CheckDecimalIsNull(decimal? value, string parameterName, string ExceptionMessage = "不能为空")
{
if (value == null || value == 0)
if (value == null )
{
throw new ArgumentException($"{parameterName}{ExceptionMessage}");
}

6
src/Shentun.Peis.Domain/ItemTypes/ItemTypeManager.cs

@ -97,9 +97,9 @@ namespace Shentun.Peis.ItemTypes
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckStringIsNull(entity.DisplayName, "名称");
DataHelper.CheckGuidIsNull(entity.GuidTypeId, "指引类别");
DataHelper.CheckCharIsNull(entity.IsMergeAsbitem, "是否合并组合项目", true);
DataHelper.CheckGuidIsNull(entity.MedicalReportTypeId, "体检报告类别");
DataHelper.CheckGuidIsDefaultValue(entity.GuidTypeId, "指引类别");
DataHelper.CheckCharIsYOrN(entity.IsMergeAsbitem, "是否合并组合项目");
DataHelper.CheckGuidIsDefaultValue(entity.MedicalReportTypeId, "体检报告类别");
}

16
src/Shentun.Peis.Domain/Items/ItemManager.cs

@ -135,14 +135,14 @@ namespace Shentun.Peis.Items
{
DataHelper.CheckEntityIsNull(entity);
DataHelper.CheckStringIsNull(entity.DisplayName, "名称");
DataHelper.CheckGuidIsNull(entity.ItemTypeId, "项目类别");
DataHelper.CheckDecimalIsNull(entity.Price, "价格");
DataHelper.CheckCharIsNull(entity.IsProduceSummary, "是否生成小结", true);
DataHelper.CheckCharIsNull(entity.IsNameIntoSummary, "名称是否进入小结", true);
DataHelper.CheckCharIsNull(entity.IsDiagnosisFunction, "是否启用诊断函数", true);
DataHelper.CheckCharIsNull(entity.IsCalculationItem, "是否计算项目", true);
DataHelper.CheckCharIsNull(entity.IsContinueProcess, "是否继续处理", true);
DataHelper.CheckCharIsNull(entity.IsActive, "是否启用", true);
DataHelper.CheckGuidIsDefaultValue(entity.ItemTypeId, "项目类别");
DataHelper.CheckCharIsYOrN(entity.IsProduceSummary, "是否生成小结");
DataHelper.CheckCharIsYOrN(entity.IsNameIntoSummary, "名称是否进入小结");
DataHelper.CheckCharIsYOrN(entity.IsDiagnosisFunction, "是否启用诊断函数");
DataHelper.CheckCharIsYOrN(entity.IsCalculationItem, "是否计算项目");
DataHelper.CheckCharIsYOrN(entity.IsContinueProcess, "是否继续处理");
DataHelper.CheckCharIsYOrN(entity.IsActive, "是否启用");
}

Loading…
Cancel
Save