public static string GetSnippet(Type typeClass, SnippetType snipType, bool isMobile)
        {
            //bool isMobile=CrudGenHelper.IsMobile(typeClass);
            string Sname = GetSname(typeClass.Name);

            FieldInfo[] fields  = typeClass.GetFields();         //We can't assume they are in the correct order.
            FieldInfo   priKey  = null;
            FieldInfo   priKey1 = null;
            FieldInfo   priKey2 = null;

            if (isMobile)
            {
                priKey1 = CrudGenHelper.GetPriKeyMobile1(fields, typeClass.Name);
                priKey2 = CrudGenHelper.GetPriKeyMobile2(fields, typeClass.Name);
            }
            else
            {
                priKey = CrudGenHelper.GetPriKey(fields, typeClass.Name);
            }
            string priKeyParam  = null;
            string priKeyParam1 = null;
            string priKeyParam2 = null;

            if (isMobile)
            {
                priKeyParam1 = priKey1.Name.Substring(0, 1).ToLower() + priKey1.Name.Substring(1);           //lowercase initial letter.  Example customerNum
                priKeyParam2 = priKey2.Name.Substring(0, 1).ToLower() + priKey2.Name.Substring(1);           //lowercase initial letter.  Example patNum
            }
            else
            {
                priKeyParam = priKey.Name.Substring(0, 1).ToLower() + priKey.Name.Substring(1);                        //lowercase initial letter.  Example patNum
            }
            string           obj             = typeClass.Name.Substring(0, 1).ToLower() + typeClass.Name.Substring(1); //lowercase initial letter.  Example feeSched
            string           tablename       = CrudGenHelper.GetTableName(typeClass);                                  //in lowercase now.  Example feesched
            List <FieldInfo> fieldsExceptPri = null;

            if (isMobile)
            {
                fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey2);             //for mobile, only excludes PK2
            }
            else
            {
                fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey);
            }
            switch (snipType)
            {
            default:
                return("snippet type not found.");

            case SnippetType.Insert:
                if (isMobile)
                {
                    return(GetInsert(typeClass.Name, obj, null, true));
                }
                else
                {
                    return(GetInsert(typeClass.Name, obj, priKey.Name, false));
                }

            case SnippetType.Update:
                return(GetUpdate(typeClass.Name, obj, isMobile));

            case SnippetType.EntireSclass:
                if (isMobile)
                {
                    return(GetEntireSclassMobile(typeClass.Name, obj, priKey1.Name, priKey2.Name, Sname, tablename, priKeyParam1, priKeyParam2));
                }
                else
                {
                    List <Permissions> listAuditTrailPerms = GroupPermissions.GetPermsFromCrudAuditPerm(CrudGenHelper.GetCrudAuditPermForClass(typeClass));
                    return(GetEntireSclass(typeClass.Name, obj, priKey.Name, Sname, tablename, priKeyParam, listAuditTrailPerms));
                }

            case SnippetType.CreateTable:
                return("Currently unavailable.");

                /*
                 * if(isMobile) {
                 *      return GetCreateTable(tablename,priKey1.Name,priKey2.Name,fieldsExceptPri);
                 * }
                 * else {
                 *      return GetCreateTable(tablename,priKey.Name,null,fieldsExceptPri);
                 * }*/
            }
        }
Example #2
0
        public static string GetSnippet(Type typeClass, SnippetType snipType, bool isMobile)
        {
            //bool isMobile=CrudGenHelper.IsMobile(typeClass);
            string Sname = GetSname(typeClass.Name);

            FieldInfo[] fields  = typeClass.GetFields();         //We can't assume they are in the correct order.
            FieldInfo   priKey  = null;
            FieldInfo   priKey1 = null;
            FieldInfo   priKey2 = null;

            if (isMobile)
            {
                priKey1 = CrudGenHelper.GetPriKeyMobile1(fields, typeClass.Name);
                priKey2 = CrudGenHelper.GetPriKeyMobile2(fields, typeClass.Name);
            }
            else
            {
                priKey = CrudGenHelper.GetPriKey(fields, typeClass.Name);
            }
            string priKeyParam  = null;
            string priKeyParam1 = null;
            string priKeyParam2 = null;

            if (isMobile)
            {
                priKeyParam1 = priKey1.Name.Substring(0, 1).ToLower() + priKey1.Name.Substring(1);           //lowercase initial letter.  Example customerNum
                priKeyParam2 = priKey2.Name.Substring(0, 1).ToLower() + priKey2.Name.Substring(1);           //lowercase initial letter.  Example patNum
            }
            else
            {
                priKeyParam = priKey.Name.Substring(0, 1).ToLower() + priKey.Name.Substring(1);                        //lowercase initial letter.  Example patNum
            }
            string           obj             = typeClass.Name.Substring(0, 1).ToLower() + typeClass.Name.Substring(1); //lowercase initial letter.  Example feeSched
            string           tablename       = CrudGenHelper.GetTableName(typeClass);                                  //in lowercase now.  Example feesched
            List <FieldInfo> fieldsExceptPri = null;

            if (isMobile)
            {
                fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey2);             //for mobile, only excludes PK2
            }
            else
            {
                fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey);
            }
            bool isTableHist        = CrudGenHelper.IsTableHist(typeClass);
            List <DbSchemaCol> cols = CrudQueries.GetListColumns(priKey.Name, null, fieldsExceptPri, false);

            switch (snipType)
            {
            default:
                return("snippet type not found.");

            case SnippetType.Insert:
                if (isMobile)
                {
                    return(GetInsert(typeClass.Name, obj, null, true));
                }
                else
                {
                    return(GetInsert(typeClass.Name, obj, priKey.Name, false));
                }

            case SnippetType.Update:
                return(GetUpdate(typeClass.Name, obj, isMobile, isTableHist));

            case SnippetType.EntireSclass:
                if (isMobile)
                {
                    return(GetEntireSclassMobile(typeClass.Name, obj, priKey1.Name, priKey2.Name, Sname, tablename, priKeyParam1, priKeyParam2, isTableHist));
                }
                else
                {
                    List <Permissions> listAuditTrailPerms = GroupPermissions.GetPermsFromCrudAuditPerm(CrudTableAttribute.GetCrudAuditPermForClass(typeClass));
                    return(GetEntireSclass(typeClass.Name, obj, priKey.Name, Sname, tablename, priKeyParam, listAuditTrailPerms, isTableHist));
                }

            case SnippetType.AddTable:
                return(CrudSchemaRaw.AddTable(tablename, cols, 0, false, false));

            case SnippetType.AddColumnEnd:
                return(string.Join("\r\n\r\n", cols.Select(x => CrudSchemaRaw.AddColumnEnd(tablename, x, 0, false, typeClass).Trim())));

            case SnippetType.AddIndex:
                return(string.Join("\r\n\r\n", cols.Select(x => CrudSchemaRaw.AddIndex(tablename, x.ColumnName, 0).Trim())));

            case SnippetType.DropColumn:
                return(string.Join("\r\n\r\n", cols.Select(x => CrudSchemaRaw.DropColumn(tablename, x.ColumnName, 0).Trim())));
            }
        }