Ejemplo n.º 1
0
        protected override void BeforeChange(DataColumn dc, DataRow ddr)
        {
            string ObjectName = this.myAddressDT.TableName;

            atriumDB.AddressRow dr      = (atriumDB.AddressRow)ddr;
            WhereClause         whereCl = new WhereClause();

            switch (dc.ColumnName)
            {
            case  "City":
                if (!dr.IsNull("CountryCode") && dr.CountryCode == "CDN")
                {
                    if (dr.IsCityNull())
                    {
                        throw new RequiredException(Resources.AddressCity);
                    }

                    if (myA.AtMng.GetSetting(AppBoolSetting.ValidateCity))
                    {
                        if (!dr.IsProvinceCodeNull())
                        {
                            DataTable dt = myA.Codes("vCity");
                            whereCl.Add("ProvinceCode", "=", dr.ProvinceCode);

                            if (dt.Select(whereCl.Filter()).Length != 0)
                            {
                                whereCl.Add("City", "=", dr.City);
                                //dt = myA.AtMng.GetGeneralRec("City", whereCl);
                                if (dt.Select(whereCl.Filter()).Length == 0)
                                {
                                    throw new AtriumException(Resources.AddressCityNotInProv, Resources.AddressCity, Resources.AddressProvince);
                                }
                            }
                        }
                    }
                }
                break;

            case  "ProvinceCode":
                if (dr.IsProvinceCodeNull())
                {
                    if (!dr.IsNull("CountryCode"))
                    {
                        if (dr.CountryCode == "CDN" || dr.CountryCode == "USA")
                        {
                            throw new RequiredException(Resources.AddressProvinceCode);
                        }
                    }
                }
                else
                {
                    if (!dr.IsNull("CountryCode"))
                    {
                        if (dr.CountryCode == "CDN" || dr.CountryCode == "USA")
                        {
                            DataTable           dtP = myA.Codes("Province");
                            atLogic.WhereClause wc  = new atLogic.WhereClause();
                            wc.Add("CountryCode", "=", dr.CountryCode);

                            //if (!myA.Codes("Province").Rows.Contains(dr.ProvinceCode))
                            if (!dtP.Rows.Contains(dr.ProvinceCode))
                            {
                                throw new AtriumException(Resources.IsNotValid, Resources.AddressProvinceCode);
                            }
                        }
                    }
                }
                break;

            case  "CountryCode":
                if (dr.IsNull(dc))
                {
                    throw new RequiredException(Resources.AddressCountryCode);
                }

                else if (!myA.Codes("Country").Rows.Contains(dr.CountryCode))
                {
                    throw new AtriumException(Resources.IsNotValid, Resources.AddressCountryCode);
                }
                break;

            case  "AddressSourceCode":
                if (dr.IsAddressSourceCodeNull())
                {
                    throw new RequiredException(Resources.AddressAddressSourceCode);
                }
                else if (!myA.Codes("AddressSource").Rows.Contains(dr.AddressSourceCode))
                {
                    throw new AtriumException(Resources.IsNotValid, Resources.AddressAddressSourceCode);
                }
                break;

            case  "AddressType":
                if (dr.IsAddressTypeNull())
                {
                    throw new RequiredException(Resources.AddressAddressType);
                }
                else if (!myA.Codes("AddressType").Rows.Contains(dr.AddressType))
                {
                    throw new AtriumException(Resources.IsNotValid, Resources.AddressAddressType);
                }
                break;

            case "Address1":
                if (dr.IsNull(dc))
                {
                    throw new RequiredException(Resources.AddressAddress1);
                }
                break;

            case  "EffectiveTo":
                if (dr.IsEffectiveToNull())
                {
                    throw new RequiredException(Resources.AddressEffectiveTo);
                }
                myA.IsValidDate(Resources.AddressEffectiveTo, dr.EffectiveTo, false, DebtorBE.CSLBegin, DateTime.Today, Resources.ValidationCSLBegin, Resources.ValidationToday);
                break;

            default:
                break;
            }
        }