Exemplo n.º 1
0
        public void Execute(IMenuCommand command)
        {
            IDiagram diagram = this.DiagramContext.CurrentDiagram;
            IModelStore modelStore = diagram.ModelStore;

            const string newPath = @"C:\PLDB";
            System.IO.Directory.CreateDirectory(newPath);
            string SqlFile = Path.Combine(newPath, @"PLDBmysql.sql");
            string PythonFile = Path.Combine(newPath, @"PLDB.py");

            using (StreamWriter fsSql = new StreamWriter(SqlFile))
            {
                using (StreamWriter fsPy = new StreamWriter(PythonFile))
                {
                    SQLWriter mySql = new SQLWriter(SQLGenerateRun.INNODB);
                    //DjangoWriter py = new DjangoWriter();
                    PythonClassWriter py = new PythonClassWriter();
                    SQLGenerator sqlGen = new SQLGenerator(fsSql, mySql, fsPy, py, modelStore);
                    sqlGen.GenerateMySQL();

                }
            }

            // TODO debug this code: seems like I'm missing an assembly reference!
            //var outWindow = Package.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
            //Guid generalPaneGuid = VSConstants.GUID_OutWindowGeneralPane;
            //IVsOutputWindowPane generalPane;
            //outWindow.GetPane(ref generalPaneGuid, out generalPane);
            //generalPane.OutputString("============= SQL Generation Successful =================");
            //generalPane.Activate(); // Brings this pane into view
        }
        public void TestSequentialNumberFormatterCase1()
        {
            //
            //Arrange
            //
            var testRow = 4;
            var format  = @"insert into TableA \(\[ColumnA\]\) values"
                          + @"\s+\('abc 010 def'\),"
                          + @"\s+\('abc 011 def'\),"
                          + @"\s+\('abc 012 def'\),"
                          + @"\s+\('abc 010 def'\)"
                          + @";"
                          + @"\s+GO"
            ;
            var config = new GenerateConfig[] {
                new GenerateConfig {
                    TableName           = "TableA",
                    ColumnName          = "ColumnA",
                    DataType            = "varchar",
                    GenerateFormat      = @"abc {seq|start:10,end:12,padding:'\{0:000\}'} def",
                    GenerateRecordCount = testRow
                }
            };

            //
            //Act
            //
            var result = SQLGenerator.GenerateInsertStatement(new MSSQLBuilder(), config).ToString();

            //
            //Assert
            //
            Assert.IsTrue(
                Regex.Match(result, format).Success,
                "Format: \"{0}\", Actuals: \"{1}\"", format, result);
        }
Exemplo n.º 3
0
 public String GenerateSQLOutput()
 {
     return(SQLGenerator.GenerateSAISQL(Type, entryorguid, events) + "\n\n\n" + SQLGenerator.GenerateConditionsSQL(Type, entryorguid, events));
 }
        public void TestReferenceColumnFormatterCase1()
        {
            //
            //Arrange
            //
            var testRow = 2;
            var format  = @"insert into Staff \(\[Id\]\) values"
                          + @"\s*\('E001'\),*"
                          + @"\s*\('E002'\),*"
                          + @";"
                          + @"\s+GO"
                          + @"\s*insert into LeaveType \(\[Id\]\) values"
                          + @"\s*\('L001'\),*"
                          + @"\s*\('L002'\),*"
                          + @";"
                          + @"\s+GO"
                          + @"\s*insert into StaffLeave \(\[Id\], \[StaffId\], \[LeaveId\]\) values"
                          + @"\s*\('1', 'E00(1|2)', 'L00(1|2)'\),*"
                          + @"\s*\('2', 'E00(1|2)', 'L00(1|2)'\),*"
                          + @";"
                          + @"\s+GO"
            ;
            var config = new GenerateConfig[] {
                new GenerateConfig {
                    TableName           = "Staff",
                    ColumnName          = "Id",
                    DataType            = "varchar",
                    GenerateFormat      = @"E{seq|start:1,padding:'\{0:000\}'}",
                    GenerateRecordCount = testRow
                },
                new GenerateConfig {
                    TableName           = "StaffLeave",
                    ColumnName          = "Id",
                    DataType            = "varchar",
                    GenerateFormat      = @"{seq|start:1}",
                    GenerateRecordCount = testRow
                },
                new GenerateConfig {
                    TableName           = "StaffLeave",
                    ColumnName          = "StaffId",
                    DataType            = "varchar",
                    GenerateFormat      = @"{ref|table:'Staff',column:'Id'}",
                    GenerateRecordCount = testRow
                },
                new GenerateConfig {
                    TableName           = "StaffLeave",
                    ColumnName          = "LeaveId",
                    DataType            = "varchar",
                    GenerateFormat      = @"{ref|table:'LeaveType',column:'Id'}",
                    GenerateRecordCount = testRow
                },
                new GenerateConfig {
                    TableName           = "LeaveType",
                    ColumnName          = "Id",
                    DataType            = "varchar",
                    GenerateFormat      = @"L{seq|start:1,padding:'\{0:000\}'}",
                    GenerateRecordCount = testRow
                },
            };

            //
            //Act
            //
            var result = SQLGenerator.GenerateInsertStatement(new MSSQLBuilder(), config).ToString();

            //
            //Assert
            //
            Assert.IsTrue(
                Regex.Match(result, format.ToString()).Success,
                "Format: \"{0}\", Actuals: \"{1}\"", format, result);
        }
Exemplo n.º 5
0
        protected void OnGenerateCode(object parameter)
        {
            switch (CurrentTool.Language)
            {
            case "javascript":
                //Check for source files
                string fileStatus = DocumentCreator.AddFile(@"D:\Zkit\SourceFiles", @"Output\Scripts", "CommonObjects.js");

                //Create CSS
                CSSGenerator css       = new CSSGenerator(CurrentTool);
                string       cssStatus = DocumentCreator.CreateDocument(@"Output\Styles", (CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project") + "Styles", "css", css.GenerateDoc(), true);

                PHPGenerator php = new PHPGenerator(CurrentTool);
                //set php info here
                php.DB     = "zkit";
                php.Pass   = "******";
                php.Server = "localhost";
                php.User   = "******";

                //Create PHP Scripts
                string phpStatus = DocumentCreator.CreateDocument(@"Output\PHP", "connect", "php", php.GenerateConnectDoc(), true);
                if (!String.IsNullOrWhiteSpace(phpStatus))
                {
                    MessageBox.Show(phpStatus);
                }
                phpStatus = DocumentCreator.CreateDocument(@"Output\PHP", "save_" + (CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project"), "php", php.GenerateSaveDoc(), true);
                if (!String.IsNullOrWhiteSpace(phpStatus))
                {
                    MessageBox.Show(phpStatus);
                }
                phpStatus = DocumentCreator.CreateDocument(@"Output\PHP", "load_" + (CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project"), "php", php.GenerateLoadDoc(), true);
                if (!String.IsNullOrWhiteSpace(phpStatus))
                {
                    MessageBox.Show(phpStatus);
                }

                //Create Javascript files
                JavascriptGenerator js = new JavascriptGenerator(CurrentTool);
                js.ProjectName = CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project";    //Needs to be the name of the objecst
                string jsStatus = DocumentCreator.CreateDocument(@"Output\Scripts", js.ProjectName, "js", js.GenerateDoc(), true);
                if (!String.IsNullOrWhiteSpace(jsStatus))
                {
                    MessageBox.Show(jsStatus);
                }
                jsStatus = DocumentCreator.CreateDocument(@"Output\Scripts", js.ProjectName + "_functions", "js", js.GenerateFunctionsDoc(), true);
                if (!String.IsNullOrWhiteSpace(jsStatus))
                {
                    MessageBox.Show(jsStatus);
                }

                HTMLGenerator g = CurrentTool.HTML;
                g.ProjectName = CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project";
                g.ToolRef     = CurrentTool;
                g.ScriptIncludes.Add("CommonObjects.js");
                g.ScriptIncludes.Add(js.ProjectName + ".js");
                g.ScriptIncludes.Add("https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js");
                g.ScriptIncludes.Add(g.ProjectName + "_functions.js");
                g.GenerateDoc();    //Creates begining point of doc

                //Load js objects
                var htmlTag = g.Tags.Where(x => x.TagName == "html").FirstOrDefault();
                if (htmlTag != null && htmlTag.GetType() == typeof(HTMLTagBase))
                {
                    var headTag = ((HTMLTagBase)htmlTag).Children.Where(x => x.TagName == "head").FirstOrDefault();
                    if (headTag != null)
                    {
                        var         scriptTag = ((HTMLTagBase)headTag).Children.Where(x => x.TagName == "script").FirstOrDefault();
                        HTMLTagBase script    = null;
                        if (scriptTag != null)
                        {
                            script = (HTMLTagBase)scriptTag;
                        }
                        else    //create a script tag
                        {
                            script         = new HTMLTagBase();
                            script.TagName = "script";
                            headTag.Children.Add(script);
                        }
                        List <string> names = new List <string>();
                        foreach (var o in CurrentTool.Objects)
                        {
                            names.Add(o.Name);
                        }
                        script.InnerHTML = JavascriptGenerator.GenerateInitFunction(names);
                    }

                    var bodyTag = ((HTMLTagBase)htmlTag).Children.Where(x => x.TagName == "body").FirstOrDefault();
                    if (bodyTag != null)
                    {
                        bodyTag.Elements.Add("onload", "initObjs();");
                    }
                }
                else    //no html tag found.  Something is wrong.
                {
                }

                string htmlDoc = g.ReOutputDoc();

                string status = DocumentCreator.CreateDocument("Output", CurrentTool.Parent != null ? ((Project)CurrentTool.Parent).Name : "Project", "html", htmlDoc, true);
                if (!String.IsNullOrWhiteSpace(status))
                {
                    MessageBox.Show(status);
                }

                //TODO: Finish adding all report elements - tags in reports.html, additional scripts
                //***** Create Report Document
                HTMLTagBase reportDoc     = g.CreateReportPage();
                var         reportHeadTag = ((HTMLTagBase)reportDoc).Children.Where(x => x.TagName == "head").FirstOrDefault();
                if (reportHeadTag != null)
                {
                    var         scriptTag = ((HTMLTagBase)reportHeadTag).Children.Where(x => x.TagName == "script").FirstOrDefault();
                    HTMLTagBase script    = null;
                    if (scriptTag != null)
                    {
                        script = (HTMLTagBase)scriptTag;
                    }
                    else    //create a script tag
                    {
                        script         = new HTMLTagBase();
                        script.TagName = "script";
                        reportHeadTag.Children.Add(script);
                    }
                    List <string> names = new List <string>();
                    foreach (var o in CurrentTool.Objects)
                    {
                        names.Add(o.Name);
                    }
                    script.InnerHTML = JavascriptGenerator.GenerateReportInitFunction(names, CurrentTool.Objects.ElementAt(0));
                }

                var reportBodyTag = ((HTMLTagBase)reportDoc).Children.Where(x => x.TagName == "body").FirstOrDefault();
                if (reportBodyTag != null)
                {
                    reportBodyTag.Elements["onload"] += "initObjs();";
                }

                status = DocumentCreator.CreateDocument("Output", "Reports", "html", reportDoc.GenerateTag(), true);
                if (!String.IsNullOrWhiteSpace(status))
                {
                    MessageBox.Show(status);
                }

                //***** Create SQL Scripts
                SQLGenerator sql       = new SQLGenerator(CurrentTool);
                string       sqlStatus = DocumentCreator.CreateDocument("Output", "CREATE_TABLES", "sql", sql.GenerateDoc(), true);

                MessageBox.Show("Files Created!");
                break;
            }
        }
 /// <summary>
 /// 本表join的时候使用right方式
 /// </summary>
 public LinqDLR2Sql <TSource> RightJoin()
 {
     SQLGenerator.DoRightJoin(this);
     return(this);
 }
 /// <summary>
 /// 本表join的时候使用left方式
 /// </summary>
 public LinqDLR2Sql <TSource> LeftJoin()
 {
     SQLGenerator.DoLeftJoin(this);
     return(this);
 }
 /// <summary>
 /// 转为sql语句
 /// </summary>
 /// <returns></returns>
 public string ToSql()
 {
     return(SQLGenerator.ToSql());
 }