/// <summary>
 ///
 /// </summary>
 /// <param name="doc"></param>
 public void CreateDoc(ucBaseDocument doc)
 {
     doc.DocChanged = false;
     this.DocumentHost.Items.Add(doc);
     doc.Activate();
     doc.LoadProperties(this.lucDocumentProperties);
 }
 /// <summary>
 /// Select File Node
 /// </summary>
 /// <param name="pni"></param>
 void lucSolutionExplorer_SelectFileNode(PropertyNodeItem pni)
 {
     if (this.DocumentHost.Items.Count > 0)
     {
         foreach (Control c in this.DocumentHost.Items)
         {
             if (((ucBaseDocument)c).DocPath != null && ((ucBaseDocument)c).DocPath.ToLower() == pni.Value.ToLower())
             {
                 ((ucBaseDocument)c).Activate();
                 return;
             }
         }
     }
     if (File.Exists(pni.Value))
     {
         FileInfo       finfo = new FileInfo(pni.Value);
         ucBaseDocument doc   = new ucBaseDocument();
         doc.DocExt     = finfo.Extension;
         doc.DocPath    = pni.Value;
         doc.DocType    = DocumentType.CodeDocument;
         doc.DocChanged = false;
         doc.Title      = finfo.Name;
         TextEditor tb = new TextEditor();
         tb.IsReadOnly         = true;
         tb.SyntaxHighlighting = tb.SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(finfo.Extension);
         tb.Load(pni.Value);
         doc.Content = tb;
         doc.LoadProperties(this.lucDocumentProperties);
         this.DocumentHost.Items.Add(doc);
         doc.Activate();
     }
 }
        /// <summary>
        /// Select Template Node
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        void lucTemplatesExplorer_SelectTemplateNode(string filePath, string fileName)
        {
            if (this.DocumentHost.Items.Count > 0)
            {
                foreach (Control c in this.DocumentHost.Items)
                {
                    if (((ucBaseDocument)c).DocPath != null && ((ucBaseDocument)c).DocPath.ToLower() == filePath.ToLower())
                    {
                        ((ucBaseDocument)c).Activate();
                        return;
                    }
                }
            }

            if (filePath.IndexOf(".tt") > 0)
            {
                ucBaseDocument doc = new ucBaseDocument();
                doc.DocExt     = ".tt";
                doc.DocPath    = filePath;
                doc.DocType    = DocumentType.TemplateDocument;
                doc.DocChanged = false;
                doc.Title      = fileName;
                TextEditor tb = new TextEditor();
                tb.IsReadOnly = false;
                tb.Load(filePath);
                tb.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition(ToolHelper.GetHighlightingByExtension(GetOutputExtension(tb.Text).Replace(".", string.Empty)));
                doc.Content           = tb;
                doc.LoadProperties(this.lucDocumentProperties);
                this.DocumentHost.Items.Add(doc);
                doc.Activate();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerateCode_Click(object sender, RoutedEventArgs e)
        {
            if (!this.DocumentHost.ContainsActiveDocument)
            {
                MessageBox.Show("Please open a template document.");
                return;
            }
            ucBaseDocument doc = ((ucBaseDocument)this.DocumentHost.SelectedItem);

            if (doc.DocType == DocumentType.CodeDocument)
            {
                MessageBox.Show("Please select a template document.");
                return;
            }

            TextTemplatingEngineHost host = new TextTemplatingEngineHost();
            Engine engine = new Engine();

            host.Session           = new TextTemplatingSession();
            host.TemplateFileValue = doc.DocPath == null ? string.Empty : doc.DocPath.ToString();

            TextEditor tbox          = (TextEditor)doc.Content;
            string     inputTemplate = tbox == null ?string.Empty:tbox.Text;//.Replace("System.Windows.Controls.TextBox: ",string.Empty);

            List <CustomProperty> cpList = doc.GetParamters();

            foreach (CustomProperty cp in cpList)
            {
                Parameter par = new Parameter()
                {
                    Text = cp.Name.Trim(), Value = cp.Value.ToString()
                };
                host.Session.Add(cp.Name.Trim(), par);
            }

            string         strCodes = engine.ProcessTemplate(inputTemplate, host);
            string         docExt   = "." + GetOutputExtension(inputTemplate);
            CustomProperty tncp     = doc.GetProperty("TableName");
            string         tname    = tncp == null ? string.Empty : tncp.Value.ToString();
            string         dtitle   = doc.Title.Substring(4, doc.Title.Length - 7);
            ucBaseDocument codedoc  = new ucBaseDocument()
            {
                Title = tname + dtitle == string.Empty ? string.Format("Doc_{0}", DateTime.Now.ToString("yyyyMMdd")) : tname + dtitle + docExt,

                Content = new TextEditor()
                {
                    IsReadOnly         = false,
                    SyntaxHighlighting = HighlightingManager.Instance.GetDefinition(ToolHelper.GetHighlightingByExtension(GetOutputExtension(inputTemplate).Trim())),
                    Text = strCodes
                }
            };

            codedoc.DocType    = DocumentType.CodeDocument;
            codedoc.DocChanged = false;
            codedoc.DocExt     = docExt;
            this.DocumentHost.Items.Add(codedoc);
            codedoc.Activate();
            codedoc.LoadProperties(this.lucDocumentProperties);
        }
        /// <summary>
        /// SelectionChanged in Document Host
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DocumentHost_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ucBaseDocument doc = ((ucBaseDocument)DocumentHost.SelectedItem);

            if (doc != null && this.lucDocumentProperties != null)
            {
                doc.LoadProperties(this.lucDocumentProperties);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenDoc_Click(object sender, RoutedEventArgs e)
        {
            if (openFileDialog == null)
            {
                this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
            }

            this.openFileDialog.ShowDialog();
            if (this.DocumentHost.Items.Count > 0)
            {
                foreach (Control c in this.DocumentHost.Items)
                {
                    if (((ucBaseDocument)c).DocPath != null && ((ucBaseDocument)c).DocPath.ToLower() == openFileDialog.FileName.ToLower())
                    {
                        ((ucBaseDocument)c).Activate();
                        return;
                    }
                }
            }

            if (openFileDialog.CheckFileExists)
            {
                FileInfo       finfo = new FileInfo(openFileDialog.FileName);
                ucBaseDocument doc   = new ucBaseDocument()
                {
                    Title   = finfo.Name,
                    Content = new TextEditor()
                    {
                        Text = File.ReadAllText(openFileDialog.FileName),
                        SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(finfo.Extension),
                        Encoding           = System.Text.UnicodeEncoding.UTF8
                    }
                };
                doc.Title   = finfo.Name;
                doc.DocExt  = finfo.Extension;
                doc.DocPath = finfo.FullName;
                if (doc.DocExt == ".tt")
                {
                    doc.DocType = DocumentType.TemplateDocument;
                }
                else
                {
                    doc.DocType = DocumentType.CodeDocument;
                }
                doc.DocChanged = false;
                doc.LoadProperties(this.lucDocumentProperties);

                this.DocumentHost.Items.Add(doc);
                doc.Activate();
            }
        }
        private void btnGenerateSql_Click(object sender, RoutedEventArgs e)
        {
            if (null == tvSheets.SelectedItem)
            {
                MessageBox.Show("Please select a sheet first.", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var sheetName  = this.tvSheets.SelectedItem.ToString();
            var tableValue = spreadsheet.Tables[sheetName];
            var tableName  = txtTableName.Text;

            if (string.IsNullOrEmpty(tableName))
            {
                MessageBox.Show("Please specify table name first.", "", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (true == rbUpdate.IsChecked && 0 == listPrimaryKey.SelectedItems.Count)
            {
                MessageBox.Show("Please specify primary key first.", "", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var           workbookName   = Path.GetFileNameWithoutExtension(spreadsheet.WorkbookPath);
            var           fileNameSuffix = (true == rbUpdate.IsChecked ? "update" : "insert");
            StringBuilder writer         = new StringBuilder();

            if (rbInsert.IsChecked == true)
            {
                SqlGenerator.GenerateInsertStatements(tableName, tableValue, ref writer);
            }
            else if (rbUpdate.IsChecked == true)
            {
                var pks = listPrimaryKey.SelectedItems.Cast <string>().ToArray();
                SqlGenerator.GenerateUpdateStatements(tableName, pks, tableValue, ref writer);
            }
            ucBaseDocument doc = new ucBaseDocument()
            {
                Title   = string.Format("{0}_{1}", this.txtTableName.Text, fileNameSuffix),
                Content = new TextEditor()
                {
                    IsReadOnly         = false,
                    Text               = writer.ToString(),
                    SyntaxHighlighting = HighlightingManager.Instance.GetDefinitionByExtension(".sql")
                }
            };

            doc.DocExt  = "sql";
            doc.DocType = DocumentType.CodeDocument;
            winMainForm.CreateDoc(doc);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDocAddToProj_Click(object sender, RoutedEventArgs e)
        {
            if (this.DocumentHost.Items.Count == 0)
            {
                MessageBox.Show("Please new or open a code document add to current selected project.");
            }
            if (this.lucSolutionExplorer.CurProject == null)
            {
                MessageBox.Show("Please select target project or a file below target project.");
            }

            ucBaseDocument doc = this.DocumentHost.SelectedItem as ucBaseDocument;

            MessageBoxResult mbr = MessageBox.Show("Are you sure to add " + doc.Title + " to " + lucSolutionExplorer.CurProject.DisplayName + " ?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

            if (mbr == MessageBoxResult.No)
            {
                return;
            }

            TextEditor txtEditor = doc.Content as TextEditor;
            FileInfo   finfo     = new FileInfo(lucSolutionExplorer.CurProject.Value);

            string     newPaht = finfo.Directory.FullName + @"\" + doc.Title;
            FileStream fs;

            if (!File.Exists(newPaht))
            {
                fs = new FileStream(newPaht, FileMode.Create);
            }
            else
            {
                fs = new FileStream(newPaht, FileMode.Open);
            }
            StreamWriter sw = new StreamWriter(fs);

            sw.WriteLine(txtEditor.Text);

            sw.Close();
            fs.Close();
            FileInfo newinfo = new FileInfo(newPaht);

            doc.DocPath = newPaht;
            doc.DocExt  = finfo.Extension;
            doc.LoadProperties(this.lucDocumentProperties);

            UpdateProjectFile(doc, lucSolutionExplorer.CurProject.Value);

            this.lucSolutionExplorer.Refresh();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="projFilePath"></param>
        public void UpdateProjectFile(ucBaseDocument doc, string projFilePath)
        {
            DataSet ds = new DataSet();

            ds.ReadXml(projFilePath);

            DataTable dt = ds.Tables["Compile"];

            if (dt != null)
            {
                DataRow dr = dt.NewRow();
                dr["Include"]      = doc.Title;
                dr["ItemGroup_Id"] = 1;
                dt.Rows.Add(dr);
            }
            ds.WriteXml(projFilePath);
        }
        /// <summary>
        /// /
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDeleteDoc_Click(object sender, RoutedEventArgs e)
        {
            if (this.DocumentHost.ContainsActiveContent)
            {
                ucBaseDocument doc = ((ucBaseDocument)this.DocumentHost.SelectedItem);

                if (File.Exists(doc.DocPath))
                {
                    MessageBoxResult mbr = MessageBox.Show("Confirm to delect current active document?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
                    if (mbr == MessageBoxResult.Yes)
                    {
                        File.Delete(doc.DocPath);
                    }
                    doc.Close();
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewDoc_Click(object sender, RoutedEventArgs e)
        {
            ucBaseDocument doc = new ucBaseDocument()
            {
                Title   = string.Format("Doc_{0}", DateTime.Now.ToString("yyyyMMdd")),
                Content = new TextEditor()
                {
                    IsReadOnly         = false,
                    SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("txt")
                }
            };

            doc.DocType    = DocumentType.CodeDocument;
            doc.DocChanged = false;
            this.DocumentHost.Items.Add(doc);
            doc.Activate();
            doc.LoadProperties(this.lucDocumentProperties);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSaveDoc_Click(object sender, RoutedEventArgs e)
        {
            if (this.DocumentHost.ContainsActiveContent)
            {
                ucBaseDocument doc = ((ucBaseDocument)this.DocumentHost.SelectedItem);

                if (File.Exists(doc.DocPath))
                {
                    this.saveFileDialog.FileName = doc.DocPath;
                }
                if (!string.IsNullOrEmpty(doc.DocExt))
                {
                    this.saveFileDialog.Filter = doc.DocExt + "|*." + doc.DocExt;
                }
                else
                {
                    this.saveFileDialog.Filter = string.Empty;
                }
                this.saveFileDialog.ShowDialog();

                if (!string.IsNullOrEmpty(this.saveFileDialog.FileName))
                {
                    FileStream fs;
                    if (!File.Exists(this.saveFileDialog.FileName))
                    {
                        fs = new FileStream(this.saveFileDialog.FileName, FileMode.Create);
                    }
                    else
                    {
                        fs = new FileStream(this.saveFileDialog.FileName, FileMode.Open);
                    }
                    StreamWriter sw = new StreamWriter(fs);

                    sw.WriteLine(doc.Content.ToString());

                    sw.Close();
                    fs.Close();
                    FileInfo finfo = new FileInfo(this.saveFileDialog.FileName);
                    doc.DocPath = this.saveFileDialog.FileName;
                    doc.DocExt  = finfo.Extension;
                    doc.LoadProperties(this.lucDocumentProperties);
                }
            }
        }
예제 #13
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 67 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.btnNewDoc_Click);

            #line default
            #line hidden
                return;

            case 2:

            #line 68 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.btnOpenDoc_Click);

            #line default
            #line hidden
                return;

            case 3:

            #line 70 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.btnSaveDoc_Click);

            #line default
            #line hidden
                return;

            case 4:

            #line 73 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.btnProjOpen_Click);

            #line default
            #line hidden
                return;

            case 5:

            #line 75 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.btnDocAddToProj_Click);

            #line default
            #line hidden
                return;

            case 6:

            #line 76 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.btnDocRemoveFormProj_Click);

            #line default
            #line hidden
                return;

            case 7:

            #line 81 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.OnShowDockableContent);

            #line default
            #line hidden
                return;

            case 8:

            #line 91 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.OnShowDocumentContent);

            #line default
            #line hidden
                return;

            case 9:

            #line 98 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.MenuItemCloseAllDocs_Click);

            #line default
            #line hidden
                return;

            case 10:

            #line 107 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.ChangeStandardTheme);

            #line default
            #line hidden
                return;

            case 11:

            #line 108 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.ChangeStandardTheme);

            #line default
            #line hidden
                return;

            case 12:

            #line 111 "..\..\..\winMain.xaml"
                ((System.Windows.Controls.MenuItem)(target)).Click += new System.Windows.RoutedEventHandler(this.AboutMenu_Click);

            #line default
            #line hidden
                return;

            case 13:
                this.btnProjOpen = ((System.Windows.Controls.Button)(target));

            #line 115 "..\..\..\winMain.xaml"
                this.btnProjOpen.Click += new System.Windows.RoutedEventHandler(this.btnProjOpen_Click);

            #line default
            #line hidden
                return;

            case 14:
                this.btnProjNew = ((System.Windows.Controls.Button)(target));

            #line 120 "..\..\..\winMain.xaml"
                this.btnProjNew.Click += new System.Windows.RoutedEventHandler(this.btnProjNew_Click);

            #line default
            #line hidden
                return;

            case 15:
                this.btnOpenDoc = ((System.Windows.Controls.Button)(target));

            #line 125 "..\..\..\winMain.xaml"
                this.btnOpenDoc.Click += new System.Windows.RoutedEventHandler(this.btnOpenDoc_Click);

            #line default
            #line hidden
                return;

            case 16:
                this.btnNewDoc = ((System.Windows.Controls.Button)(target));

            #line 130 "..\..\..\winMain.xaml"
                this.btnNewDoc.Click += new System.Windows.RoutedEventHandler(this.btnNewDoc_Click);

            #line default
            #line hidden
                return;

            case 17:
                this.btnSaveDoc = ((System.Windows.Controls.Button)(target));

            #line 135 "..\..\..\winMain.xaml"
                this.btnSaveDoc.Click += new System.Windows.RoutedEventHandler(this.btnSaveDoc_Click);

            #line default
            #line hidden
                return;

            case 18:
                this.btnDeleteDoc = ((System.Windows.Controls.Button)(target));

            #line 140 "..\..\..\winMain.xaml"
                this.btnDeleteDoc.Click += new System.Windows.RoutedEventHandler(this.btnDeleteDoc_Click);

            #line default
            #line hidden
                return;

            case 19:
                this.btnGenerateCode = ((System.Windows.Controls.Button)(target));

            #line 162 "..\..\..\winMain.xaml"
                this.btnGenerateCode.Click += new System.Windows.RoutedEventHandler(this.btnGenerateCode_Click);

            #line default
            #line hidden
                return;

            case 20:
                this.imgSingle = ((System.Windows.Controls.Image)(target));
                return;

            case 21:
                this.btnBatchGenerateCode = ((System.Windows.Controls.Button)(target));

            #line 167 "..\..\..\winMain.xaml"
                this.btnBatchGenerateCode.Click += new System.Windows.RoutedEventHandler(this.btnBatchGenerateCode_Click);

            #line default
            #line hidden
                return;

            case 22:
                this.imgBatch = ((System.Windows.Controls.Image)(target));
                return;

            case 23:
                this.btnExceltoScript = ((System.Windows.Controls.Button)(target));

            #line 172 "..\..\..\winMain.xaml"
                this.btnExceltoScript.Click += new System.Windows.RoutedEventHandler(this.btnExceltoScript_Click);

            #line default
            #line hidden
                return;

            case 24:
                this.imgExceltoScript = ((System.Windows.Controls.Image)(target));
                return;

            case 25:
                this.btnDocAddToProj = ((System.Windows.Controls.Button)(target));

            #line 178 "..\..\..\winMain.xaml"
                this.btnDocAddToProj.Click += new System.Windows.RoutedEventHandler(this.btnDocAddToProj_Click);

            #line default
            #line hidden
                return;

            case 26:
                this.btnDocRemoveFromProj = ((System.Windows.Controls.Button)(target));

            #line 183 "..\..\..\winMain.xaml"
                this.btnDocRemoveFromProj.Click += new System.Windows.RoutedEventHandler(this.btnDocRemoveFormProj_Click);

            #line default
            #line hidden
                return;

            case 27:
                this.DockManager = ((AvalonDock.DockingManager)(target));
                return;

            case 28:
                this.lucTemplatesExplorer = ((SmartCodeGenerator.ucTemplatesExplorer)(target));
                return;

            case 29:
                this.lucServerExplorer = ((SmartCodeGenerator.ucServerExplorer)(target));
                return;

            case 30:
                this.DocumentHost = ((AvalonDock.DocumentPane)(target));

            #line 209 "..\..\..\winMain.xaml"
                this.DocumentHost.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.DocumentHost_SelectionChanged);

            #line default
            #line hidden
                return;

            case 31:
                this.InitNewDocument = ((SmartCodeGenerator.ucBaseDocument)(target));
                return;

            case 32:
                this.lucSolutionExplorer = ((SmartCodeGenerator.ucSolutionExplorer)(target));
                return;

            case 33:
                this.lucDocumentProperties = ((SmartCodeGenerator.ucParameterExplorer)(target));
                return;

            case 34:
                this.zoomSlider = ((System.Windows.Controls.Slider)(target));
                return;
            }
            this._contentLoaded = true;
        }