示例#1
0
        private bool Validate()
        {
            try
            {
                ItemValidator valItem   = new ItemValidator();
                NZString      ItemCD    = new NZString(this, Text);
                ErrorItem     errorItem = null;

                string[] strItemTypes = null;
                //if (ItemType != null && ItemType.Length > 0)
                //{
                //    if (ItemType.Length == 1 && ItemType[0] == eItemType.All)
                //    {
                //        strItemTypes = new string[] { "01", "02", "03", "04" };
                //    }
                //    else
                //    {
                //        strItemTypes = new string[ItemType.Length];
                //        for (int i = 0; i < ItemType.Length; i++)
                //        {
                //            strItemTypes[i] = string.Format("{0:00}", (int)ItemType[i]);
                //        }
                //    }
                //}

                if (CheckEmpty)
                {
                    errorItem = valItem.CheckEmptyItemCode(ItemCD);
                }
                if (CheckExist)
                {
                    ValidateException.ThrowErrorItem(valItem.CheckExistWithItemType(ItemCD, SqlOperator, strItemTypes));
                }
                if (CheckNotExist)
                {
                    ValidateException.ThrowErrorItem(valItem.CheckNotExistWithItemType(ItemCD, SqlOperator, strItemTypes));
                    //BusinessException businessException = valItem.CheckItemNotExist(ItemCD);
                    //if (businessException != null)
                    //{
                    //    throw businessException;
                    //}
                }


                if (CustomerCode != null && !"".Equals(CustomerCode))
                {
                    ValidateException.ThrowErrorItem(valItem.CheckItemByCustomer(ItemCD, CustomerCode.ToNZString()));
                }

                if (null != errorItem)
                {
                    ValidateException.ThrowErrorItem(errorItem);
                }
            }
            catch (ValidateException err)
            {
                for (int i = 0; i < err.ErrorResults.Count; i++)
                {
                    MessageDialog.ShowBusiness(this.FindForm(), err.ErrorResults[i].Message);
                    err.ErrorResults[i].FocusOnControl();
                }
                return(false);
            }
            catch (BusinessException err)
            {
                MessageDialog.ShowBusiness(this.FindForm(), err.Error.Message);
                err.Error.FocusOnControl();
                return(false);
            }
            catch (Exception ex)
            {
                MessageDialog.ShowBusiness(this.FindForm(), ex.Message);
                return(false);
            }
            return(true);
        }