예제 #1
0
        private void menuAddType_Click(object sender, EventArgs e)
        {
            Prompt p = new Prompt("模板分类")
            {
                Height = 100
            };
            string text = p.Show();

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            CodeBuilderService service = ServiceHelper.GetCodeBuilderService();
            TemplateEntity     entity  = new TemplateEntity()
            {
                ParentID     = TemplateRootID,
                Content      = "",
                FilePrefix   = "",
                TemplateName = text
            };

            if (service.AddTemplate(entity) > 0)
            {
                //创建模版目录
                //string path = Path.Combine(TemplateManager.TemplatePath, text);
                //FileHelper.CreateFolder(path);
                DataBind();
            }
            else
            {
                MsgBox.Alert("添加模板分类失败");
            }
        }
예제 #2
0
        public override bool SaveData()
        {
            string         templateName = this.txtTemplateName.Text.Trim();
            TemplateEntity entity       = new TemplateEntity()
            {
                FileExtensions = "." + this.cboCodeType.Text,
                FilePrefix     = this.txtPrefix.Text,
                FileName       = this.txtFileName.Text,
                TemplateName   = templateName,
                ParentID       = ParentID,
                Content        = this.txtCode.Text
            };
            bool result = false;

            using (CodeBuilderService service = ServiceHelper.GetCodeBuilderService())
            {
                if (string.IsNullOrEmpty(this.RecordID))
                {
                    result = service.AddTemplate(entity) > 0;
                }
                else
                {
                    entity.ID = Convert.ToInt32(RecordID);
                    result    = service.UpdateTemplate(entity);
                }
            }
            //if (result)
            //{
            //    try
            //    {
            //        string fileName=TemplateManager.GetTemplateFile(templateName, TypeName);
            //        FileHelper.WriteFile(fileName, this.txtCode.Text);
            //        if (!string.IsNullOrEmpty(OldFileName) && fileName!=OldFileName)
            //        {
            //            File.Delete(OldFileName);
            //        }
            //        result = true;
            //    }
            //    catch (Exception ex)
            //    {
            //        result = false;
            //        throw new Exception(ex.Message);
            //    }
            //}
            if (result)
            {
                //保存成功后,表示页面未发生改变
                IsChange   = false;
                OldContent = entity.Content;
            }
            return(result);
        }
예제 #3
0
 //导入模板
 private void menuImport_Click(object sender, EventArgs e)
 {
     string[] fileNames = Dialog.GetFileNames();
     if (fileNames != null && fileNames.Length > 0)
     {
         CodeBuilderService service     = ServiceHelper.GetCodeBuilderService();
         bool          isReloadTreeNode = false;
         StringBuilder sb       = new StringBuilder();
         string        parentid = GetSelectedID();
         foreach (string fileName in fileNames)
         {
             try
             {
                 TemplateEntity entity = ParseTemplateFileName(fileName);
                 entity.Content  = FileHelper.GetFileContent(fileName);
                 entity.ParentID = Convert.ToInt32(parentid);
                 int id = service.AddTemplate(entity);
                 if (id > 0)
                 {
                     isReloadTreeNode = true;
                 }
                 else
                 {
                     sb.AppendLine("文件:" + fileName + "导入失败!");
                 }
             }
             catch (Exception ex)
             {
                 sb.AppendLine("文件:" + fileName + "导入失败,错误信息:" + ex.Message);
             }
         }
         string errors = sb.ToString();
         if (string.IsNullOrEmpty(errors))
         {
             MsgBox.Alert("导入成功");
             if (isReloadTreeNode)
             {
                 TreeNode typeNode = GetSelectNode();
                 ReBindTemplateNodes(parentid, typeNode);
                 typeNode.ExpandAll();
             }
         }
         else
         {
             Utils.ShowErrorDialog(errors);
         }
     }
 }