/// <summary>
 /// 检查用的输入是否合法.合法返回true,否则返回false
 /// </summary>
 /// <returns></returns>
 private bool CheckUserInput()
 {
     //取得各文本框
     var txtSupplierCode = (TextBox)fvMaterialSupplierAdd.FindControl("txtSupplierCode");
     var txtSupplierName = (TextBox)fvMaterialSupplierAdd.FindControl("txtSupplierName");
     //检测文本框是空否为
     foreach (var tb in new TextBox[] { txtSupplierCode, txtSupplierName })
     {
         if (tb != null && tb.Text.Trim().Length <= 0)
         {
             throw new Exception("供应商代码和供应商名称都不能为空!");
         }
     }
     //供应商代码格式检测
     if (txtSupplierCode != null && !Regex.IsMatch(txtSupplierCode.Text, @"^[A-Z]\d{4}$"))
     {
         throw new Exception("必须为1位大写字母加4位数字!");
     }
     //非修改状态下
     if (fvMaterialSupplierAdd.CurrentMode != FormViewMode.Edit)
     {
         //供应商名称不能重复
         var supplierName = txtSupplierName.Text;
         using (var da = new t_material_supplierTableAdapter())
         {
             int? iCount = da.CountBySupplierName(supplierName);
             if (iCount.HasValue && iCount > 0)
             {
                 throw new Exception("供应商名称已经存在,不能重复输入!");
             }
         }
     }
     //可以提交
     return true;
 }
Exemple #2
0
 /// <summary>
 /// 检测是否存在指定的供应商名称
 /// </summary>
 /// <param name="source">当前验证控件</param>
 /// <param name="args">验证控件提供的验证事件参数对象</param>
 /// <returns></returns>
 internal static bool IsExistSupplierName(
     object source,
     ServerValidateEventArgs args
 )
 {
     //当前对象
     var cv = ((CustomValidator)source);
     //检测供应商名称是否存在
     using (var da = new t_material_supplierTableAdapter())
     {
         //执行获取
         int i = (int)da.CountBySupplierName(args.Value);
         if (i <= 0)
         {
             cv.ToolTip = "供应商名称不存在";
             return false;
         }
         else
         {
             return true;
         }
     }
 }