Ejemplo n.º 1
0
        /// <summary>
        /// Check mandatory field
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        public static string[][] CheckMandatoryFiled(object obj, params string[] field)
        {
            ObjectMandatoryField omf = new ObjectMandatoryField();

            if (field != null)
            {
                foreach (string f in field)
                {
                    MandatoryField mc = new MandatoryField();
                    mc.FieldName        = f;
                    mc.ControlName      = f;
                    mc.MandatoryMessage = f;
                    omf.AddProperty(mc);
                }
            }
            else if (obj != null && obj is object)
            {
                PropertyInfo[] props = obj.GetType().GetProperties();
                if (props != null)
                {
                    foreach (PropertyInfo prop in props)
                    {
                        MandatoryField mc = new MandatoryField();
                        mc.FieldName        = prop.Name;
                        mc.ControlName      = prop.Name;
                        mc.MandatoryMessage = prop.Name;
                        omf.AddProperty(mc);
                    }
                }
            }

            return(CheckMandatoryFiled(obj, omf));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Check all proprty in object is null or empty
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="paramIggnoreField"></param>
        /// <returns></returns>
        public static bool IsNullAllField(object obj, params string[] paramIggnoreField)
        {
            PropertyInfo[] props = obj.GetType().GetProperties();

            //Fix bug by Non A. 2/Mar/2012
            props = (from m in props where !paramIggnoreField.Contains <string>(m.Name) select m).ToArray <PropertyInfo>();

            ObjectMandatoryField f = new ObjectMandatoryField();

            for (int i = 0; i < props.Length; i++)
            {
                f.AddProperty(props[i].Name, props[i].Name);
            }

            string[][] strNullList = CheckMandatoryFiled(obj, f);

            if (strNullList != null)
            {
                if (strNullList.Length > 0)
                {
                    return(strNullList[0].Length == props.Length);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }