Beispiel #1
0
 /// <summary>
 /// 检测是否存在指定的部门名称
 /// </summary>
 /// <param name="txtLotId">当前待报数的lot卡序文本框</param>
 /// <param name="source">当前验证控件</param>
 /// <param name="args">验证控件提供的验证事件参数对象</param>
 /// <returns></returns>
 internal static bool IsSameOrderProductNum(
     TextBox txtLotId,
     object source,
     ServerValidateEventArgs args
 )
 {
     //当前对象
     var cv = ((CustomValidator)source);
     cv.ToolTip = "只允许版本号与订单生产编号不相同";
     //是否找到lot卡号文本框
     if (txtLotId == null)
     {
         return false;
     }
     //获取用户输入的lot卡号
     string lotId = txtLotId.Text;
     cv.ToolTip = "提供的lot卡号不正确";
     //检测lot卡号
     if (!lotId.Contains("-") || lotId.Length < 6)
     {
         return false;
     }
     //检测是否样板
     bool isSample = lotId.ToUpper().Contains("S");
     //非样板使用生产订单和lot卡中的数据
     if (!isSample && !ydOperateLotCard.IsLotCardId(ref lotId))
     {
         return false;
     }
     else if (isSample && !ydOperateSampleLotCard.IsSampleLotCardId(ref lotId))
     {
         return false;
     }
     //非样板订单在生产订单中查询
     if (!isSample)
     {
         //通过lot卡号获取订单中生产编号
         using (var da = new v_ppc_lot_card_join_orderTableAdapter())
         {
             //获取
             object obj = da.GetProductNumByLotId(lotId);
             if (obj == null)
             {
                 cv.ToolTip = "在订单中未找到生产编号";
                 return false;
             }
             else
             {
                 //取得的订单生产编号
                 string orderProductNum = obj.ToString();
                 //取得的输入的生产编号
                 string userProductNum = args.Value;
                 //小于两个字符不检测
                 if (orderProductNum.Length < 2)
                 {
                     return true;
                 }
                 else if (userProductNum.Length >= 2)
                 {
                     cv.ToolTip = string.Format("只允许版本号与订单生产编号\"{0}\"不相同", orderProductNum);
                     //检测是否存在部门
                     return orderProductNum.Remove(orderProductNum.Length - 2)
                         == userProductNum.Remove(userProductNum.Length - 2);
                 }
                 else
                 {
                     return false;
                 }
             }
         }
     }
     //样板在样板订单中查询
     else
     {
         //通过样板lot卡号获取样板订单中生产编号
         using (var da = new v_sample_lot_card_join_orderTableAdapter())
         {
             //获取
             object obj = da.GetProductNumByLotId(lotId);
             if (obj == null)
             {
                 cv.ToolTip = "在样板订单中未找到生产编号";
                 return false;
             }
             else
             {
                 //取得的样板订单生产编号
                 string orderProductNum = obj.ToString();
                 //取得的输入的样板生产编号
                 string userProductNum = args.Value;
                 //小于两个字符不检测
                 if (orderProductNum.Length < 2)
                 {
                     return true;
                 }
                 else if (userProductNum.Length >= 2)
                 {
                     cv.ToolTip = string.Format("只允许版本号与样板订单生产编号\"{0}\"不相同", orderProductNum);
                     //检测是否存在部门
                     return orderProductNum.Remove(orderProductNum.Length - 2)
                         == userProductNum.Remove(userProductNum.Length - 2);
                 }
                 else
                 {
                     return false;
                 }
             }
         }
     }
 }