Ejemplo n.º 1
0
        /// <summary>
        /// This method joins two forms. The current form represents the old form (which is probably being viewed by a user), and <paramref name="NewForm"/>
        /// represents the new updated form. The method makes sure values that are currently being edited (and which the server is unaware off) are kept, while
        /// all other changes are transferred to the current form.
        /// </summary>
        /// <param name="NewForm">New version of form.</param>
        public void Join(DataForm NewForm)
        {
            Field[] OldFields = this.fields;

            this.fieldsByVar  = NewForm.fieldsByVar;
            this.type         = NewForm.type;
            this.fields       = NewForm.fields;
            this.header       = NewForm.header;
            this.records      = NewForm.records;
            this.pages        = NewForm.pages;
            this.instructions = NewForm.instructions;
            this.title        = NewForm.title;

            foreach (Field OldField in OldFields)
            {
                if (!this.fieldsByVar.TryGetValue(OldField.Var, out Field NewField))
                {
                    continue;
                }

                if (!OldField.Edited)
                {
                    continue;
                }

                NewField.SetValue(OldField.ValueStrings);
            }

            DataFormEventHandler h = this.OnRemoteUpdate;

            if (h != null)
            {
                try
                {
                    h(this.client, this);
                }
                catch (Exception ex)
                {
                    this.client.Exception(ex);
                }
            }
        }
Ejemplo n.º 2
0
        public void NewFieldCheck()
        {
            var o = new NewField {
                X = "Foo", Y = "Bar"
            };
            BaseField b1 = o;

            b1.X = 123;
            var bin = MessagePackSerializer.Serialize(o, Resolvers.ContractlessStandardResolver.Options);

            this.logger.WriteLine(MessagePackSerializer.ConvertToJson(bin));
            var v = MessagePackSerializer.Deserialize <NewField>(bin, Resolvers.ContractlessStandardResolver.Options);

            v.IsStructuralEqual(o);

            // Verify that we still maintain compatibility with deserializing the base type.
            var b2 = MessagePackSerializer.Deserialize <BaseField>(bin, Resolvers.ContractlessStandardResolver.Options);

            Assert.Equal(b1.X, b2.X);
            Assert.Equal(b1.Y, b2.Y);
        }
Ejemplo n.º 3
0
        //TODO may have to re-think this as I am now using this in more than one spot
        private static void textChanged(object sender, TextChangedEventArgs e)
        {
            DependencyObject child  = e.OriginalSource as UIElement;
            DependencyObject parent = e.OriginalSource as UIElement;

            while (parent != null && !(parent is ListView))
            {
                parent = VisualTreeHelper.GetParent(parent);
            }

            if (parent != null)
            {
                var lv = (ListView)parent;

                if (lv.SelectedIndex == lv.Items.Count - 1)
                {
                    if (child is ClickableTextBox)
                    {
                        ((ClickableTextBox)child).FontStyle = FontStyles.Normal;
                        DependencyObject p = VisualTreeHelper.GetParent(child);
                        if (p is StackPanel)
                        {
                            foreach (var c in ((StackPanel)p).Children)
                            {
                                if (c is CheckBox)
                                {
                                    ((CheckBox)c).IsEnabled = true;
                                }
                            }
                        }
                    }

                    NewField nf = new NewField("Note Field Name");
                    ObservableCollection <NewField> source = lv.ItemsSource as ObservableCollection <NewField>;
                    source.Add(nf);
                }
            }
        }
 public ActionResult AddNewField(NewField newField)
 {
     _connectionString = TenantOperations.GetTenantConnectionString(User.Identity.Name);
     MainDataModel.AddNewField(newField.tablename, newField.fieldname, newField.fieldtypes, newField.fieldsize, newField.defaultvalue, newField.allownull, _connectionString);
     return(RedirectToAction("TableDescription", new { @tableName = newField.tablename }));
 }
Ejemplo n.º 5
0
        //建立编译文件
        public void CreateCompile(bool build)
        {
            string[] fileNames;
            //获取要生成的文件
            if (genConfig != null)
            {
                if (genConfig.controllerFiles.Count > 0)
                {
                    fileNames = new string[genConfig.controllerFiles.Count];
                    for (int i = 0; i < fileNames.Length; i++)
                    {
                        fileNames[i] = Frame.MapPath(genConfig.controllerFiles[i]);
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (!Directory.Exists(Frame.MapPath(config.Controller)))
                {
                    return;
                }
                //获取所有的controls文件
                fileNames = Directory.GetFiles(Frame.MapPath(config.Controller), "*.cs", SearchOption.AllDirectories);
                if (fileNames == null || fileNames.Length < 1)
                {
                    return;
                }
            }

            //生成的代码
            string compileCode = "";
            //类名称
            string ClassName = "";

            //前面的字符串部分添加或删除后,后面的代码的相对位置
            int relative_postion = 0;

            if (fileNames.Length > 0)
            {
                Compiler     com        = new Compiler();
                FileData     fileData   = null;
                ClassData    classData  = null;
                MethodData   methodData = null;
                StreamWriter sw         = null;
                VTemplate.Engine.TemplateDocument swDebug = null;
                //VTemplate.Engine.TemplateDocument swAspx = null;

                string compileFileName = "";
                string compileDir      = "";
                string debugFileName   = "";
                string methodContent   = "";
                for (int i = 0; i < fileNames.Length; i++)
                {
                    fileData = fileData = com.GetFileData(Frame.appRoot, this.config.APP, fileNames[i], System.Text.Encoding.UTF8);

                    ClassName = Path.GetFileNameWithoutExtension(fileNames[i]);
                    classData = fileData.GetClassData(ClassName);


                    if (classData.MethodDataList.Count > 0)
                    {
                        for (int j = 0; j < classData.MethodDataList.Count; j++)
                        {
                            //只有公开方法才能访问
                            if (classData.MethodDataList[j].isPublic)
                            {
                                relative_postion = 0;
                                compileCode      = fileData.csharpCode.ToString();
                                methodData       = classData.MethodDataList[j];
                                //相对
                                compileDir = config.ChangeControllerName(config.Web + config.defaultStyle, (fileData.nameSpace + '.' + ClassName).Replace('.', '/')) + "/";
                                //绝对
                                compileFileName = Frame.MapPath(compileDir + methodData.name + ".cs");
                                if (!Directory.Exists(Path.GetDirectoryName(compileFileName)))
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(compileFileName));
                                }
                                //调试文件
                                debugFileName = Frame.MapPath(compileDir + methodData.name + ".html");
                                //输出调试文件
                                if (!File.Exists(debugFileName))
                                {
                                    swDebug = new VTemplate.Engine.TemplateDocument(Frame.MapPath("/NFinal/Template/Debug.tpl"), System.Text.Encoding.UTF8);
                                    swDebug.SetValue("Url", config.ChangeControllerName(config.APP, (fileData.nameSpace + '.' + ClassName).Replace('.', '/')) + "/" + methodData.name + ".htm");
                                    swDebug.RenderTo(debugFileName, System.Text.Encoding.UTF8);
                                }
                                relative_postion += Replace(ref compileCode, relative_postion + fileData.start, fileData.length, "namespace " + (Frame.AssemblyTitle + compileDir.TrimEnd('/')).Replace('/', '.') + "\r\n{");
                                relative_postion += Replace(ref compileCode, relative_postion + classData.start, classData.length, "public class " +
                                                            methodData.name + "Action " + (string.IsNullOrEmpty(classData.baseName) ? "" : " : " + classData.baseName) + "\r\n\t{"
                                                            //添加初始化函数
                                                            + "\r\n\t\tpublic " + methodData.name + "Action(System.IO.TextWriter tw):base(tw){}"
                                                            + "\r\n\t\tpublic " + methodData.name + "Action(string fileName) : base(fileName) {}");
                                //循环内部所有方法
                                for (int k = 0; k < classData.MethodDataList.Count; k++)
                                {
                                    methodData = classData.MethodDataList[k];
                                    //如果两个相等,则进行替换
                                    if (j == k || (!classData.MethodDataList[k].isPublic))
                                    {
                                        #region "替换原有方法"
                                        //排除非公开和非基类的方法,替换原有方法体
                                        //if (methodData.isPublic)
                                        {
                                            methodContent = methodData.Content;
                                            SqlCompiler sqlCompiler = new NFinal.Compile.SqlCompiler();
                                            //从代码中分析出数据库相关函数
                                            List <DbFunctionData> dbFunctions = sqlCompiler.Compile(com.DeleteComment(methodContent));

                                            if (dbFunctions.Count > 0)
                                            {
                                                SqlAnalyse analyse = new SqlAnalyse();
                                                //与数据库相结合,从sql语句中分析出所有的表信息,列信息
                                                methodData.dbFunctions = analyse.FillFunctionDataList(NFinal.DB.Coding.DB.DbStore, dbFunctions);
                                            }
                                            //数据库函数替换
                                            int    content_relative_position = 0;
                                            string StructDatas = string.Empty;
                                            if (dbFunctions.Count > 0)
                                            {
                                                bool          hasSameVarName = false;
                                                List <string> varNames       = new List <string>();
                                                //添加struct类型
                                                for (int s = 0; s < dbFunctions.Count; s++)
                                                {
                                                    //去除重复项
                                                    if (varNames.Count > 0)
                                                    {
                                                        hasSameVarName = false;
                                                        for (int c = 0; c < varNames.Count; c++)
                                                        {
                                                            //如果发现重复项,则跳过循环
                                                            if (varNames[c] == dbFunctions[s].varName)
                                                            {
                                                                hasSameVarName = true;
                                                                break;
                                                            }
                                                        }
                                                        if (hasSameVarName)
                                                        {
                                                            continue;
                                                        }
                                                    }
                                                    varNames.Add(dbFunctions[s].varName);
                                                    //分析出sql返回的List<dynamic>和dynamic类型是否有用AddNewField(string fileName,Type t);添加相关的类型
                                                    NewField newFiled = new NewField(dbFunctions[s].varName);
                                                    List <NFinal.Compile.StructField> structFieldList = newFiled.GetFields(ref methodContent, methodData.name);
                                                    //添加struct字段
                                                    string StructData = sqlCompiler.SetMagicStruct(methodData.name, dbFunctions[s], structFieldList, Frame.appRoot);
                                                    StructDatas += StructData;
                                                    if (!string.IsNullOrEmpty(StructData))
                                                    {
                                                        compileCode       = compileCode.Insert(methodData.start + relative_postion, StructData);
                                                        relative_postion += StructData.Length;
                                                    }
                                                }
                                                //更换函数中的数据库操作
                                                content_relative_position += sqlCompiler.SetMagicFunction(methodData.name,
                                                                                                          ref methodContent,
                                                                                                          content_relative_position,
                                                                                                          methodData.dbFunctions,
                                                                                                          Frame.appRoot);
                                                //分析并更换其中的连接字符串
                                                content_relative_position += sqlCompiler.SetMagicConnection(methodData.name,
                                                                                                            ref methodContent,
                                                                                                            Frame.appRoot
                                                                                                            );
                                            }
                                            if (methodData.parameterTypeAndNames != string.Empty)
                                            {
                                                relative_postion += Replace(ref compileCode, relative_postion + methodData.parametersIndex, methodData.parametersLength, methodData.parameterTypeAndNames);
                                            }
                                            //从代码中分析出views函数
                                            NFinal.Compile.ViewCompiler viewCompiler = new NFinal.Compile.ViewCompiler();
                                            List <ViewData>             views        = viewCompiler.Compile(methodContent);
                                            //模版替换
                                            if (views.Count > 0)
                                            {
                                                content_relative_position = 0;
                                                content_relative_position = viewCompiler.SetMagicFunction(ref methodContent,
                                                                                                          content_relative_position,
                                                                                                          fileData.nameSpace,
                                                                                                          ClassName,
                                                                                                          methodData.name, views, config);
                                            }
                                            if (build)
                                            {
                                                relative_postion += Replace(ref compileCode, relative_postion + methodData.position, methodData.Content.Length, methodContent);
                                            }
                                            else
                                            {
                                                relative_postion += Replace(ref compileCode, relative_postion + methodData.position, methodData.Content.Length, string.Empty);
                                            }
                                            //生成自动提示类
                                            //views,Structs,DBFunctions
                                            AutoCompleteCompiler autoComplete = new AutoCompleteCompiler();
                                            autoComplete.Compile(classData.baseName, methodData, StructDatas, views, fileData.nameSpace, ClassName, config);
                                        }
                                        #endregion
                                    }
                                    //如果两个不相等
                                    else
                                    {
                                        compileCode = compileCode.Remove(relative_postion + classData.MethodDataList[k].start,
                                                                         classData.MethodDataList[k].length +
                                                                         classData.MethodDataList[k].Content.Length + 1);//去掉最后一个}
                                        relative_postion -= classData.MethodDataList[k].length +
                                                            classData.MethodDataList[k].Content.Length + 1;
                                    }
                                }
                                //写aspx页面的自动提示层

                                //写Web层.class文件
                                sw = new StreamWriter(compileFileName, false, System.Text.Encoding.UTF8);
                                sw.Write(compileCode);
                                sw.Close();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void CreateDAL(bool build)
        {
            string[] fileNames;
            //获取要生成的文件
            if (genConfig != null)
            {
                if (genConfig.bllFiles.Count > 0)
                {
                    fileNames = new string[genConfig.bllFiles.Count];
                    for (int i = 0; i < fileNames.Length; i++)
                    {
                        fileNames[i] = Frame.MapPath(genConfig.bllFiles[i]);
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (!Directory.Exists(Frame.MapPath(config.BLL)))
                {
                    return;
                }
                //获取所有的bll文件
                fileNames = Directory.GetFiles(Frame.MapPath(config.BLL), "*.cs", SearchOption.AllDirectories);
                if (fileNames == null || fileNames.Length < 1)
                {
                    return;
                }
            }

            //生成的代码
            string compileCode = "";
            //类名称
            string ClassName = "";

            int relative_position = 0;

            if (fileNames.Length > 0)
            {
                Compiler     com        = new Compiler();
                FileData     fileData   = null;
                ClassData    classData  = null;
                MethodData   methodData = null;
                StreamWriter sw         = null;

                string compileFileName = "";
                string compileDir      = "";
                string methodContent   = "";

                for (int i = 0; i < fileNames.Length; i++)
                {
                    relative_position = 0;
                    fileData          = com.GetFileData(Frame.appRoot, this.config.APP, fileNames[i], System.Text.Encoding.UTF8);

                    ClassName   = Path.GetFileNameWithoutExtension(fileNames[i]);
                    classData   = fileData.GetClassData(ClassName);
                    compileCode = fileData.csharpCode.ToString();
                    //相对
                    compileDir = config.ChangeBLLName(config.DAL.Trim('/'), fileData.nameSpace.Replace('.', '/'));
                    //绝对
                    compileFileName = Frame.MapPath(compileDir + "\\" + ClassName + ".cs");
                    //更改命名空间
                    relative_position += Replace(ref compileCode, relative_position + fileData.start, fileData.length, "namespace " + (Frame.AssemblyTitle + "/" + compileDir.TrimEnd('/')).Replace('/', '.') + "\r\n{");
                    if (classData.MethodDataList.Count > 0)
                    {
                        for (int j = 0; j < classData.MethodDataList.Count; j++)
                        {
                            methodData    = classData.MethodDataList[j];
                            methodContent = methodData.Content;
                            SqlCompiler sqlCompiler = new NFinal.Compile.SqlCompiler();

                            //从代码中分析出数据库相关函数
                            List <DbFunctionData> dbFunctions = sqlCompiler.Compile(com.DeleteComment(methodContent));

                            if (dbFunctions.Count > 0)
                            {
                                SqlAnalyse analyse = new SqlAnalyse();
                                //与数据库相结合,从sql语句中分析出所有的表信息,列信息
                                methodData.dbFunctions = analyse.FillFunctionDataList(NFinal.DB.Coding.DB.DbStore, dbFunctions);
                            }
                            //数据库函数替换
                            int content_relative_position = 0;
                            if (dbFunctions.Count > 0)
                            {
                                bool          hasSameVarName = false;
                                List <string> varNames       = new List <string>();
                                //添加struct类型
                                for (int s = 0; s < dbFunctions.Count; s++)
                                {
                                    //去除重复项
                                    if (varNames.Count > 0)
                                    {
                                        hasSameVarName = false;
                                        for (int c = 0; c < varNames.Count; c++)
                                        {
                                            //如果发现重复项,则跳过循环
                                            if (varNames[c] == dbFunctions[s].varName)
                                            {
                                                hasSameVarName = true;
                                                break;
                                            }
                                        }
                                        if (hasSameVarName)
                                        {
                                            continue;
                                        }
                                    }
                                    varNames.Add(dbFunctions[s].varName);
                                    //分析出sql返回的List<dynamic>和dynamic类型是否有用AddNewField(string fileName,Type t);添加相关的类型
                                    NewField newFiled = new NewField(dbFunctions[s].varName);
                                    List <NFinal.Compile.StructField> structFieldList = newFiled.GetFields(ref methodContent, methodData.name);
                                    //添加struct字段
                                    string StructData = sqlCompiler.SetMagicStruct(methodData.name, dbFunctions[s], structFieldList, Frame.appRoot);
                                    if (!string.IsNullOrEmpty(StructData))
                                    {
                                        compileCode        = compileCode.Insert(methodData.start + relative_position, StructData);
                                        relative_position += StructData.Length;
                                    }
                                }

                                //修正函数返回类型,提高执行效率
                                if (methodData.returnType.IndexOf("dynamic") > -1)
                                {
                                    string returnTypeString = "";
                                    if (new System.Text.RegularExpressions.Regex(@"List\s*<\s*dynamic\s*>").IsMatch(methodData.returnType))
                                    {
                                        returnTypeString = string.Format("NFinal.DB.NList<__{0}_{1}__>", methodData.name, methodData.returnVarName);
                                    }
                                    else
                                    {
                                        returnTypeString = string.Format("__{0}_{1}__", methodData.name, methodData.returnVarName);
                                    }
                                    relative_position += Replace(ref compileCode,
                                                                 methodData.returnTypeIndex + relative_position + classData.position,
                                                                 methodData.returnType.Length,
                                                                 returnTypeString);
                                }
                                //更换函数内的数据库操作函数
                                content_relative_position += sqlCompiler.SetMagicFunction(methodData.name,
                                                                                          ref methodContent,
                                                                                          content_relative_position,
                                                                                          methodData.dbFunctions,
                                                                                          Frame.appRoot);
                                //分析并更换其中的连接字符串
                                content_relative_position += sqlCompiler.SetMagicConnection(methodData.name,
                                                                                            ref methodContent,
                                                                                            Frame.appRoot
                                                                                            );
                            }
                            if (build)
                            {
                                relative_position += Replace(ref compileCode, relative_position + methodData.position, methodData.Content.Length, methodContent);
                            }
                            else
                            {
                                if (methodData.returnType == "void")
                                {
                                    relative_position += Replace(ref compileCode, relative_position + methodData.position, methodData.Content.Length, string.Empty);
                                }
                                else
                                {
                                    relative_position += Replace(ref compileCode, relative_position + methodData.position, methodData.Content.Length, "return null;");
                                }
                            }
                        }
                    }
                    //如果文件夹不存在则新建
                    if (!Directory.Exists(Frame.MapPath(compileDir)))
                    {
                        Directory.CreateDirectory(Frame.MapPath(compileDir));
                    }
                    //写DAL层.class文件
                    sw = new StreamWriter(compileFileName, false, System.Text.Encoding.UTF8);
                    sw.Write(compileCode);
                    sw.Close();
                }
            }
        }
Ejemplo n.º 7
0
    void OnGUI()
    {
        // The actual window code goes here



        Rect controlRect = new Rect(0, 0, 200, EditorGUIUtility.singleLineHeight);

        controlRect.y += controlRect.height;


        GUILayout.Label("Database", EditorStyles.boldLabel);

        string oldDb = DatabaseName;

        DatabaseName = EditorGUILayout.TextField("Database Name", DatabaseName);


        if (dbcon == null)
        {
            return;
        }
        else
        {
            if (!oldDb.Equals(DatabaseName))
            {
                string connection = "URI=file:" + Application.persistentDataPath + "/" + DatabaseName;
                dbcon.Close();
                dbcon = new SqliteConnection(connection);
                dbcon.Open();
            }
        }


        List <string> tables = new List <string>();

        IDataReader dbTables = getTables(dbcon);

        while (dbTables.Read())
        {
            tables.Add(dbTables[1].ToString());
        }


        tableIsEmpty = (tables.Count == 0);


        tableChanged   = false;
        actionChanged  = false;
        oldSelection   = this._selected;
        this._selected = EditorGUILayout.Popup("Select Table", _selected, tables.ToArray());



        if (oldSelection != this._selected)
        {
            tableChanged = true;
            action       = 0;
            NewData.Clear();
        }


        controlRect.y += controlRect.height;

        if (!tableIsEmpty)
        {
            currentTable = tables[_selected];


            IDbCommand  cmndRead = dbcon.CreateCommand();
            IDataReader reader;
            string      query = "SELECT * FROM " + tables[_selected];
            cmndRead.CommandText = query;
            reader = cmndRead.ExecuteReader();
            MultiColumnHeaderState.Column[] columns = new MultiColumnHeaderState.Column[reader.FieldCount];
            fields = getFields(dbcon, tables[_selected]);

            for (int i = 0; i < fields.Count; i++)
            {
                columns[i] = new MultiColumnHeaderState.Column();
                columns[i].headerContent = new GUIContent(fields[i]);
            }

            MultiColumnHeaderState headerstate = new MultiColumnHeaderState(columns);
            MultiColumnHeader      header      = new MultiColumnHeader(headerstate);

            if (m_SimpleTreeView == null || tableChanged)
            {
                m_SimpleTreeView = new SimpleTreeView(m_TreeViewState, header, reader, this);
            }
        }


        int oldAction = action;

        this.action = EditorGUILayout.Popup("Actions", this.action, actions);

        if (oldAction != this.action)
        {
            actionChanged = true;
        }



        if (action >= 0)
        {
            if (m_SimpleTreeView != null)
            {
                m_SimpleTreeView.SetAction(action);
            }

            if (action == viewing && actionChanged)
            {
                // tableChanged = true;
            }
            else if (action == Editing)
            {
            }
            else if (action == AddRow)
            {
                for (int i = 0; i < fields.Count; i++)
                {
                    controlRect.y += controlRect.height;
                    NewData.Add("");
                    NewData[i] = EditorGUILayout.TextField(fields[i], NewData[i]);
                }
                controlRect.y += controlRect.height + 50;

                if (GUI.Button(controlRect, "Add Data"))
                {
                    string nonNullFields = "";
                    for (int i = 0; i < NewData.Count; i++)
                    {
                        if (!String.IsNullOrEmpty(NewData[i]) && NewData[i].Trim().Length > 0)
                        {
                            nonNullFields = nonNullFields + fields[i];

                            if (i < (fields.Count - 1))
                            {
                                nonNullFields = nonNullFields + ", ";
                            }
                        }
                    }
                    string nonNullFieldValues = "";
                    for (int i = 0; i < NewData.Count; i++)
                    {
                        if (!String.IsNullOrEmpty(NewData[i]) && NewData[i].Trim().Length > 0)
                        {
                            nonNullFieldValues = nonNullFieldValues + "\"" + NewData[i] + "\"";

                            if (i < (fields.Count - 1))
                            {
                                nonNullFieldValues = nonNullFieldValues + ", ";
                            }
                        }
                    }



                    string command = "INSERT INTO " + tables[_selected] + " ( " + nonNullFields + " ) VALUES ( " + nonNullFieldValues + " )";



                    IDbCommand cmnd = dbcon.CreateCommand();
                    cmnd.CommandText = command;
                    cmnd.ExecuteNonQuery();


                    action = 0;
                    NewData.Clear();
                    tableChanged = true;
                }
                //controlRect.y += controlRect.height;
            }
            else if (action == NewTable)
            {
                EditorGUILayout.Space(20);
                controlRect.y += controlRect.height + 10;

                NewTableName   = EditorGUILayout.TextField("New Table Name:", NewTableName);
                controlRect.y += controlRect.height;

                NewField filed0 = new NewField();
                filed0.FieldName = "id";
                filed0.FieldType = 0; //integer
                filed0.FieldName = EditorGUILayout.TextField("Field 0 (auto incremented)", filed0.FieldName);
                if (actionChanged)
                {
                    newFileds = new List <NewField>();
                    newFileds.Add(filed0);
                }

                if (newFileds == null)
                {
                    action = 0;
                }
                else
                {
                    for (int i = 1; i < newFileds.Count; i++)
                    {
                        newFileds[i].FieldName = EditorGUILayout.TextField("Field " + i, newFileds[i].FieldName);
                        newFileds[i].FieldType =
                            EditorGUILayout.Popup("Field " + i + " Type", newFileds[i].FieldType, FieldType);

                        controlRect.y += controlRect.height + 20;
                    }
                }


                controlRect.y += controlRect.height + 60;
                if (GUI.Button(controlRect, "Add Field"))
                {
                    NewField filed = new NewField();
                    newFileds.Add(filed);
                }
                controlRect.y += controlRect.height;
                if (GUI.Button(controlRect, "Create Table"))
                {
                    CreateTable();
                }
            }
            else if (action == DropTable)
            {
                controlRect.y += controlRect.height;
                GUILayout.Label("Note: This will delete the table and all of its contents, are you sure ?", EditorStyles.boldLabel);

                controlRect.y += controlRect.height + 20;

                if (GUI.Button(controlRect, "Delete Table"))
                {
                    IDbCommand dbcmd         = dbcon.CreateCommand();
                    string     q_createTable =
                        "DROP TABLE IF EXISTS " + currentTable;


                    dbcmd.CommandText = q_createTable;
                    dbcmd.ExecuteReader();

                    oldSelection = -1;

                    action       = 0;
                    tableChanged = true;
                }
            }
            else if (action == EmptyTable)
            {
                controlRect.y += controlRect.height;
                GUILayout.Label("Note: This will clear all the data in this table, the table structure will remain unchanged. Are you sure you want to do this?", EditorStyles.boldLabel);

                controlRect.y += controlRect.height + 20;

                if (GUI.Button(controlRect, "Clear Table"))
                {
                    IDbCommand dbcmd         = dbcon.CreateCommand();
                    string     q_createTable =
                        "Delete FROM " + currentTable;

                    dbcmd.CommandText = q_createTable;
                    dbcmd.ExecuteReader();

                    oldSelection = -1;

                    action       = 0;
                    tableChanged = true;
                }
            }
            else if (action == NewDatabase)
            {
            }
            else if (action == DeleteDatabase)
            {
                controlRect.y += controlRect.height;
                GUILayout.Label("Note: This will delete the entire database and its contents, are you sure ?", EditorStyles.boldLabel);

                controlRect.y += controlRect.height + 20;

                if (GUI.Button(controlRect, "Delete Database"))
                {
                    File.Delete("URI=file:" + Application.persistentDataPath + "/" + DatabaseName);

                    oldSelection = -1;

                    action       = 0;
                    tableChanged = true;
                }
            }


            //action = 0;
        }



        controlRect.y += controlRect.height;

        float startY = controlRect.y + controlRect.height + 12;

        Rect r = new Rect(0, startY, position.width, position.height - startY);


        if (m_SimpleTreeView != null)
        {
            m_SimpleTreeView.OnGUI(r);
        }
    }