CheckData() public method

实现数据约束
public CheckData ( ) : string
return string
Exemplo n.º 1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     //ProductData 限定了 BarCode不能为空
     //这里设为空,提交时会抛出异常
     var item = new Code.ProductData() { InterFaceUser = "******", ProductName = "product2", BarCode = "" };
     var msg = item.CheckData();
     if (!string.IsNullOrEmpty(msg))//手动判断对象数据是否合法
     {
         Response.Write(msg);
     }
     try
     {
         Code.ProductDataManage.Instance.Add(item);
     }
     catch(Exception ero)//捕获异常
     {
         Response.Write(ero.Message);
     }
 }
Exemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //ProductData 限定了 BarCode不能为空
            //这里设为空,提交时会抛出异常
            var item = new Code.ProductData()
            {
                InterFaceUser = "******", ProductName = "product2", BarCode = ""
            };
            var msg = item.CheckData();

            if (!string.IsNullOrEmpty(msg))//手动判断对象数据是否合法
            {
                Response.Write(msg);
            }
            try
            {
                Code.ProductDataManage.Instance.Add(item);
            }
            catch (Exception ero)//捕获异常
            {
                Response.Write(ero.Message);
            }
        }