Beispiel #1
0
 /// <summary>
 ///Full Constructor
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="Name">name</param>
 /// <param name="ElementType">type</param>
 /// <param name="AD_Tree_ID">tree</param>
 public MElement(MClient client, string name, string elementType, int AD_Tree_ID)
     : this(client.GetCtx(), 0, client.Get_TrxName())
 {
     SetClientOrg(client);
     SetName(name);
     SetElementType(elementType);        // A
     SetAD_Tree_ID(AD_Tree_ID);
     SetIsNaturalAccount(ELEMENTTYPE_Account.Equals(elementType));
 }
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true if it can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            if (GetAD_Org_ID() != 0)
            {
                SetAD_Org_ID(0);
            }
            String et = GetElementType();

            if (IsMandatory() &&
                (ELEMENTTYPE_UserList1.Equals(et) || ELEMENTTYPE_UserList2.Equals(et) ||
                 ELEMENTTYPE_UserElement1.Equals(et) || ELEMENTTYPE_UserElement2.Equals(et) ||
                 ELEMENTTYPE_UserElement3.Equals(et) || ELEMENTTYPE_UserElement4.Equals(et) ||
                 ELEMENTTYPE_UserElement5.Equals(et) || ELEMENTTYPE_UserElement6.Equals(et) ||
                 ELEMENTTYPE_UserElement7.Equals(et) || ELEMENTTYPE_UserElement8.Equals(et) ||
                 ELEMENTTYPE_UserElement9.Equals(et)))
            {
                SetIsMandatory(false);
            }
            else if (IsMandatory())
            {
                String errorField = null;
                if (ELEMENTTYPE_Account.Equals(et) && GetC_ElementValue_ID() == 0)
                {
                    errorField = "C_ElementValue_ID";
                }
                else if (ELEMENTTYPE_Activity.Equals(et) && GetC_Activity_ID() == 0)
                {
                    errorField = "C_Activity_ID";
                }
                else if (ELEMENTTYPE_BPartner.Equals(et) && GetC_BPartner_ID() == 0)
                {
                    errorField = "C_BPartner_ID";
                }
                else if (ELEMENTTYPE_Campaign.Equals(et) && GetC_Campaign_ID() == 0)
                {
                    errorField = "C_Campaign_ID";
                }
                else if (ELEMENTTYPE_LocationFrom.Equals(et) && GetC_Location_ID() == 0)
                {
                    errorField = "C_Location_ID";
                }
                else if (ELEMENTTYPE_LocationTo.Equals(et) && GetC_Location_ID() == 0)
                {
                    errorField = "C_Location_ID";
                }
                else if (ELEMENTTYPE_Organization.Equals(et) && GetOrg_ID() == 0)
                {
                    errorField = "Org_ID";
                }
                else if (ELEMENTTYPE_OrgTrx.Equals(et) && GetOrg_ID() == 0)
                {
                    errorField = "Org_ID";
                }
                else if (ELEMENTTYPE_Product.Equals(et) && GetM_Product_ID() == 0)
                {
                    errorField = "M_Product_ID";
                }
                else if (ELEMENTTYPE_Project.Equals(et) && GetC_Project_ID() == 0)
                {
                    errorField = "C_Project_ID";
                }
                else if (ELEMENTTYPE_SalesRegion.Equals(et) && GetC_SalesRegion_ID() == 0)
                {
                    errorField = "C_SalesRegion_ID";
                }
                if (errorField != null)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@IsMandatory@: @" + errorField + "@"));
                    return(false);
                }
            }
            //
            if (GetAD_Column_ID() == 0 &&
                (ELEMENTTYPE_UserElement1.Equals(et) || ELEMENTTYPE_UserElement2.Equals(et)))
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@IsMandatory@: @AD_Column_ID@"));
                return(false);
            }
            return(true);
        }