Example #1
0
        static void Main(string[] args)
        {
            string database   = GetCommandLineValue("database=", args);
            string server     = GetCommandLineValue("server=", args);
            string user       = GetCommandLineValue("user="******"password="******"doupdatedb=", args).In("true", "1");

            if (string.IsNullOrEmpty(server))
            {
                server = "localhost";
            }
            if (string.IsNullOrEmpty(user))
            {
                user = "******";
            }
            if (doUpdateDb && !string.IsNullOrEmpty(database))
            {
                CrudGenHelper.UpdateDatabase(database, server, user, password);
                return;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Example #2
0
        ///<summary>priKeyName2=null for not mobile.</summary>
        public static List <DbSchemaCol> GetListColumns(string priKeyName1, string priKeyName2, List <FieldInfo> fieldsExceptPri, bool isMobile)
        {
            List <DbSchemaCol> retVal = new List <DbSchemaCol>();

            //DbSchemaCol col;
            retVal.Add(new DbSchemaCol(priKeyName1, OdDbType.Long));
            if (isMobile)
            {
                retVal.Add(new DbSchemaCol(priKeyName2, OdDbType.Long));
            }
            CrudSpecialColType specialType;

            for (int f = 0; f < fieldsExceptPri.Count; f++)
            {
                if (isMobile && fieldsExceptPri[f].Name == priKeyName1)               //2 already skipped
                {
                    continue;
                }
                specialType = CrudGenHelper.GetSpecialType(fieldsExceptPri[f]);
                TextSizeMySqlOracle textsize = TextSizeMySqlOracle.Small;
                if (specialType.HasFlag(CrudSpecialColType.TextIsClob))
                {
                    textsize = TextSizeMySqlOracle.Medium;
                }
                retVal.Add(new DbSchemaCol(fieldsExceptPri[f].Name, GetOdDbTypeFromColType(fieldsExceptPri[f].FieldType, specialType), textsize));
            }
            return(retVal);
        }
        ///<summary>Creates the Data Interface "s" classes for new tables, complete with typical stubs.  Asks user first.</summary>
        public static void Create(string convertDbFile, Type typeClass, string dbName, bool isMobile)
        {
            string Sname    = GetSname(typeClass.Name);
            string fileName = null;

            if (isMobile)
            {
                fileName = @"..\..\..\OpenDentBusiness\Mobile\Data Interface\" + Sname + ".cs";
            }
            else
            {
                fileName = @"..\..\..\OpenDentBusiness\Data Interface\" + Sname + ".cs";
            }
            if (File.Exists(fileName))
            {
                return;
            }
            if (CrudGenHelper.IsMissingInGeneral(typeClass))
            {
                return;
            }
            if (MessageBox.Show("Create stub for " + fileName + "?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
            string snippet = GetSnippet(typeClass, SnippetType.EntireSclass, isMobile);

            File.WriteAllText(fileName, snippet);
            CrudGenHelper.AddToSubversion(Path.Combine(Application.StartupPath, fileName));
            Form1.ListFilesToAddToODBiz.Add(Path.Combine("Data Interface", Path.GetFileName(fileName)));
            MessageBox.Show(fileName + " has been created.  It has been added to SVN and it will be added to the project on close.");
        }
Example #4
0
        ///<summary>Creates the Data Interface "s" classes for new tables, complete with typical stubs.  Asks user first.</summary>
        public static void Create(string convertDbFile, Type typeClass, string dbName, bool isMobile)
        {
            string Sname    = GetSname(typeClass.Name);
            string fileName = null;

            if (isMobile)
            {
                fileName = @"..\..\..\OpenDentBusiness\Mobile\Data Interface\" + Sname + ".cs";
            }
            else
            {
                fileName = @"..\..\..\OpenDentBusiness\Data Interface\" + Sname + ".cs";
            }
            if (File.Exists(fileName))
            {
                return;
            }
            if (CrudGenHelper.IsMissingInGeneral(typeClass))
            {
                return;
            }
            if (MessageBox.Show("Create stub for " + fileName + "?", "", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }
            string snippet = GetSnippet(typeClass, SnippetType.EntireSclass, isMobile);

            File.WriteAllText(fileName, snippet);
            //Process.Start(fileName);
            MessageBox.Show(fileName + " has been created.  Be sure to add it to the project and to SVN");
        }
        public static string Create()
        {
            StringBuilder strb = new StringBuilder();

            //This is a stub that is to be replaced with some good code generation:
            strb.Append(@"using System;
using System.Collections.Generic;
using System.Text;

namespace OpenDentBusiness {
	///<summary>Please ignore this class.  It's used only for testing.</summary>
	public class SchemaCrudTest {
		///<summary>Example only</summary>
		public static void AddTableTempcore() {
			string command="""";"            );
            Type typeClass = typeof(SchemaTable);

            FieldInfo[]        fields          = typeClass.GetFields();
            FieldInfo          priKey          = CrudGenHelper.GetPriKey(fields, typeClass.Name);
            List <FieldInfo>   fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey);
            List <DbSchemaCol> cols            = CrudQueries.GetListColumns(priKey.Name, null, fieldsExceptPri, false);

            strb.Append("\r\n" + CrudSchemaRaw.AddTable("tempcore", cols, 3, false, false));
            strb.Append(@"
		}

		///<summary>Example only</summary>
		public static void AddColumnEndClob() {
			string command="""";"            );
            DbSchemaCol col = new DbSchemaCol("ColEndClob", OdDbType.Text, TextSizeMySqlOracle.Medium);

            strb.Append("\r\n" + CrudSchemaRaw.AddColumnEnd("tempcore", col, 3, false, typeClass));
            strb.Append(@"
		}

		///<summary>Example only</summary>
		public static void AddColumnEndInt() {
			string command="""";"            );
            col = new DbSchemaCol("ColEndInt", OdDbType.Int);
            strb.Append("\r\n" + CrudSchemaRaw.AddColumnEnd("tempcore", col, 3, false, typeClass));
            strb.Append(@"
		}

		///<summary>Example only</summary>
		public static void AddColumnEndTimeStamp() {
			string command="""";"            );
            col = new DbSchemaCol("ColEndTimeStamp", OdDbType.DateTimeStamp);
            strb.Append("\r\n" + CrudSchemaRaw.AddColumnEnd("tempcore", col, 3, false, typeClass));
            strb.Append(@"
		}

		///<summary>Example only</summary>
		public static void AddIndex() {
			string command="""";"            );
            strb.Append("\r\n" + CrudSchemaRaw.AddIndex("tempcore", "ColEndInt", 3));
            strb.Append(@"
		}

		///<summary>Example only</summary>
		public static void DropColumn() {
			string command="""";"            );
            strb.Append("\r\n" + CrudSchemaRaw.DropColumn("tempcore", "TextLargeTest", 3));
            strb.Append(@"
		}

		//AddColumnAfter
		//DropColumnTimeStamp
		//DropIndex
		//etc.


	}
}");
            return(strb.ToString());
        }
Example #6
0
        ///<summary>Writes any necessary queries to the end of the ConvertDatabase file.  Usually zero or one.  The convertDbFile could also be the one in the Mobile folder.</summary>
        ///<param name="logFileName">If this is blank, will display the results in a MessageBox, otherwise writes the results to the file.</param>
        public static void Write(string convertDbFile, Type typeClass, string dbName, bool isMobile, bool doRunQueries, bool doAppendToConvertDbFile,
                                 string logFileName = "")
        {
            StringBuilder strb;

            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 tablename    = CrudGenHelper.GetTableName(typeClass);       //in lowercase now.
            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 or feeSchedm
            List <FieldInfo> fieldsExceptPri = null;

            if (isMobile)
            {
                fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey2);             //for mobile, only excludes PK2
            }
            else
            {
                fieldsExceptPri = CrudGenHelper.GetFieldsExceptPriKey(fields, priKey);
            }
            CrudSpecialColType specialType;
            string             command = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '" + dbName + "' AND table_name = '" + tablename + "'";

            if (DataCore.GetScalar(command) != "1")
            {
                if (!CrudGenHelper.IsMissingInGeneral(typeClass))
                {
                    strb = new StringBuilder();
                    strb.Append("This table was not found in the database:"
                                + rn + tablename);
                    if (doAppendToConvertDbFile)
                    {
                        strb.Append(rn + "Query will be found at the end of " + Path.GetFileName(convertDbFile));
                    }
                    if (doRunQueries)
                    {
                        strb.Append(rn + "Table will be added to database.");
                    }
                    if (string.IsNullOrEmpty(logFileName))
                    {
                        MessageBox.Show(strb.ToString());
                    }
                    else
                    {
                        File.AppendAllText(logFileName, strb.ToString() + "\r\n");
                    }
                    strb = new StringBuilder();
                    strb.Append(rn + rn + t4 + "/*");
                    List <DbSchemaCol> cols = null;
                    if (isMobile)
                    {
                        cols = CrudQueries.GetListColumns(priKey1.Name, priKey2.Name, fieldsExceptPri, true);
                    }
                    else
                    {
                        cols = CrudQueries.GetListColumns(priKey.Name, null, fieldsExceptPri, false);
                    }
                    strb.Append("\r\n" + CrudSchemaRaw.AddTable(tablename, cols, 4, isMobile, doRunQueries));
                    strb.Append(rn + t4 + "*/");
                    if (doAppendToConvertDbFile)
                    {
                        File.AppendAllText(convertDbFile, strb.ToString());
                    }
                }
            }
            List <FieldInfo> newColumns = CrudGenHelper.GetNewFields(fields, typeClass, dbName);

            if (newColumns.Count > 0)
            {
                strb = new StringBuilder();
                strb.Append("The following columns were not found in the database.");
                for (int f = 0; f < newColumns.Count; f++)
                {
                    strb.Append(rn + tablename + "." + newColumns[f].Name);
                }
                if (doAppendToConvertDbFile)
                {
                    strb.Append(rn + "Query will be found at the end of " + Path.GetFileName(convertDbFile));
                }
                if (doRunQueries)
                {
                    strb.Append(rn + "Column will be added to table.");
                }
                if (string.IsNullOrEmpty(logFileName))
                {
                    MessageBox.Show(strb.ToString());                    //one message for all new columns in a table.
                }
                else
                {
                    File.AppendAllText(logFileName, strb.ToString() + "\r\n");
                }
                strb = new StringBuilder();
                strb.Append(rn + rn + t4 + "/*");
                for (int f = 0; f < newColumns.Count; f++)
                {
                    specialType = CrudGenHelper.GetSpecialType(newColumns[f]);
                    OdDbType            odtype   = GetOdDbTypeFromColType(newColumns[f].FieldType, specialType);
                    TextSizeMySqlOracle textsize = TextSizeMySqlOracle.Small;
                    if (specialType.HasFlag(CrudSpecialColType.TextIsClob))
                    {
                        textsize = TextSizeMySqlOracle.Medium;
                    }
                    DbSchemaCol col = new DbSchemaCol(newColumns[f].Name, odtype, textsize);
                    strb.Append(CrudSchemaRaw.AddColumnEnd(tablename, col, 4, doRunQueries, typeClass));
                }
                strb.Append(rn + t4 + "*/");
                if (doAppendToConvertDbFile)
                {
                    File.AppendAllText(convertDbFile, strb.ToString());
                }
            }
        }
        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 #8
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())));
            }
        }