Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_tab">要转化的数据表</param>
        /// <param name="strtemplatefile">使用的模板文件</param>
        /// <param name="savepath">保存文件夹</param>
        private void FoarmatClassByTable(SOTable _tab, string strtemplatefile, string savepath)
        {
            ////模板路径
            //C:\Users\marke\Desktop\Kalman.Studio\Kalman.Studio\src\Kalman.Studio\bin\Debug\T4Template\Asp.Net\Ebboy\Entity\Model.tt
            TableHost host = new TableHost();

            host.Table = _tab;
            //模板路径
            host.TemplateFile = strtemplatefile;
            //要显示的属性列表
            host.ColumnList = _tab.ColumnList;

            Engine engine  = new Engine();
            var    sw      = new Stopwatch();
            var    content = File.ReadAllText(host.TemplateFile);
            //读取模板内容并替换表相关字段、名称内容
            string outputContent = engine.ProcessTemplate(content, host);

            StringBuilder sb = new StringBuilder();

            if (host.ErrorCollection.HasErrors)
            {
                foreach (CompilerError err in host.ErrorCollection)
                {
                    sb.AppendLine(err.ToString());
                }
                outputContent = outputContent + Environment.NewLine + sb.ToString();
            }

            string strsavepath = Path.Combine(savepath, (_tab.Name + CodeTypeHelper.GetExtention(_CodeType)));

            textEditorControl2.Text = outputContent;
            textEditorControl2.SaveFile(strsavepath);
        }
Esempio n. 2
0
        /// <summary>
        /// 新建文档
        /// </summary>
        /// <param name="caption">文档所在窗体的标题,如“Class1.cs”</param>
        /// <param name="codeType">代码类型</param>
        /// <param name="content">文档文本内容</param>
        public void NewDockDocument(string caption, string codeType, string content)
        {
            DockDocument doc = new DockDocument();

            int    count = 1;
            string ext   = CodeTypeHelper.GetExtention(codeType);
            string text  = string.Format("{0}{1}{2}", caption, count.ToString(), ext);

            while (FindDockDocument(text) != null)
            {
                count++;
                if (count > 1)
                {
                    text = string.Format("{0}{1}{2}", caption, count.ToString(), ext);
                }
                else
                {
                    text = string.Format("{0}{1}", caption, ext);
                }
            }
            doc.Text = text;
            doc.LoadTextContent(content, codeType);

            if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                doc.MdiParent = this;
                doc.Show();
            }
            else
            {
                doc.Show(dockPanel);
            }
        }
Esempio n. 3
0
        private void btn_Ok_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count < 1)
            {
                return;
            }

            string selstr = this.listView1.SelectedItems[0].Text;

            Config.MainForm.NewDockDocument("New", CodeTypeHelper.GetCodeType(selstr), Config.MainForm.GetCodeTemplateText(selstr), selstr);
            Close();
        }
Esempio n. 4
0
        //打开文档
        void OpenDockDocument()
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.InitialDirectory = Application.ExecutablePath;
            openFile.Filter           = "所有文件 (*.*)|*.*";
            openFile.FilterIndex      = 1;
            openFile.RestoreDirectory = true;

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                string fileName = openFile.FileName;
                OpenDockDocument(fileName, CodeTypeHelper.GetCodeType(Path.GetExtension(fileName)));
            }
        }
Esempio n. 5
0
 private void menuItemSave_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedTab == tabPage1)
     {
         textEditorControl1.SaveFile(gbTemplateFile.Text);
     }
     else
     {
         SaveFileDialog dialog = new SaveFileDialog();
         dialog.Filter   = "所有文件 (*.*)|*.*";
         dialog.FileName = Table.Name + CodeTypeHelper.GetExtention(_CodeType);
         if (dialog.ShowDialog() == DialogResult.OK)
         {
             textEditorControl2.SaveFile(dialog.FileName);
         }
     }
 }