예제 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            //ProductData 限定了 BarCode不能为空
            //这里设为空,提交时会抛出异常
            var item = new ProductData()
            {
                InterFaceUser = "******", ProductName = "product2", BarCode = ""
            };
            var msg = item.CheckData();

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