示例#1
0
 /// <summary>
 /// 全选事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void rbAll_CheckedChanged(object sender, EventArgs e)
 {
     try
     {
         if (rbAll.Checked)
         {
             for (var n = 0; n < clbDBNames.Items.Count; n++)
             {
                 clbDBNames.SetItemCheckState(n, CheckState.Checked);
             }
             tbIncludeTables.Text = AllTables;
             Clipboard.SetText(AllTables);
             regex = null;
         }
         else
         {
             for (var n = 0; n < clbDBNames.Items.Count; n++)
             {
                 clbDBNames.SetItemCheckState(n, CheckState.Unchecked);
             }
             tbIncludeTables.Text = NoTables;
             Clipboard.SetText(NoTables);
             regex = new Regex("^$");
         }
         btnOk.Enabled = rbAll.Checked;
     }
     catch (Exception ex)
     {
         MsgBoxHelp.ShowError("获取表信息失败", ex);
     }
 }
示例#2
0
 private void cmbReposi_DropDown(object sender, EventArgs e)
 {
     try
     {
         EnvDTE.DTE dte    = Model.SolutionCommon.Dte;
         bool       result = LoadProjectLogic.Load(dte);
         //加载所有表信息
         if (result)
         {
             _entitys                = LoadProjectLogic.GetEntitys();
             cmbReposi.DataSource    = _entitys;
             cmbReposi.DisplayMember = "Entity";
             cmbReposi.ValueMember   = "Data2Obj";
             cmbReturn.Enabled       = true;
         }
         else
         {
             MsgBoxHelp.ShowWorning("加载仓储列表出错!");
         }
     }
     catch (Exception ex)
     {
         MsgBoxHelp.ShowError(ex.Message, ex);
     }
 }
示例#3
0
 /// <summary>
 /// 通过关键字来添加项目引用
 /// </summary>
 /// <param name="project"></param>
 /// <param name="referId">项目ID,系统类库或者资源类库</param>
 public static void AddReferByKey(this Project project, string referId)
 {
     try
     {
         if (referId.Count() == 36)
         {
             Project referProject = TemplateContainer.Resove <Project>(referId);
             if (referProject != null)
             {
                 project.AddReferenceFromProject(referProject);
                 return;
             }
         }
         string[] files = Directory.GetFiles(CommonContainer.RootPath, "*.dll");
         if (files != null)
         {
             Array.ForEach(files, t =>
             {
                 if (t.Contains(referId))
                 {
                     project.AddReference(t);
                     return;
                 }
             });
         }
         project.AddReference(referId);
     }
     catch (Exception ex)
     {
         MsgBoxHelp.ShowError(string.Format(Properties.Resource.ReferError, referId), ex);
     }
 }
示例#4
0
        /// <summary>
        /// 执行上下文
        /// </summary>

        public void Commit()
        {
            while (_rEntityQueue.Count() > 0)
            {
                ReferenceEntity queue = _rEntityQueue.Dequeue();
                try
                {
                    Project       proj   = TemplateContainer.Resove <Project>(queue.ProjectId);
                    List <string> refers = queue.ReferenceCollection;
                    if (refers != null && refers.Count > 0)
                    {
                        refers.ForEach(t =>
                        {
                            proj.AddReferByKey(t);
                        });
                    }
                }
                catch (Exception ex)
                {
                    MsgBoxHelp.ShowError(string.Format(Properties.Resource.ReferError, PrjCmdId.FindProjectName(queue.ProjectId)), ex);
                }
                finally
                {
                    if (HandledOne != null)
                    {
                        HandledOne(this, new EventHandledArg(queue.ProjectId, Count));
                    }
                }
            }
        }
        public override void CreateCode()
        {
            StringBuilder result = new StringBuilder();

            result.AppendLine(CodeContent);
            try
            {
                if (null == ProjectContainer.DomainEntity)
                {
                    throw new Exception("Entity2Code DomainEntity Project Can not be Find");
                }
                string path = Path.Combine(ProjectContainer.DomainEntity.ToDirectory(), _entity.Entity + ".cs");
                if (File.Exists(path) == false)
                {
                    throw new Exception("Entity2Code DomainEntity Project Can not Find ProjectItem " + _entity.Entity + ".cs");
                }
                if (SolutionCommon.infrastryctType == InfrastructType.DbFirst)
                {
                    using (StreamReader reader = new StreamReader(path))
                    {
                        while (reader.Peek() != -1)
                        {
                            string line = reader.ReadLine();
                            if (line.IndexOf("get") != -1 && line.IndexOf("set") != -1 && line.IndexOf("virtual") == -1)
                            {
                                result.AppendLine("        [DataMember]");
                                result.AppendLine(line);
                            }
                        }
                    }
                }
                else
                {
                    Table tb = CodeFirstLogic.GetTables().GetTable(_entity.Entity, CodeFirstTools.SchemaName);
                    foreach (Column clm in tb.Columns)
                    {
                        result.AppendLine("        [DataMember]");
                        result.AppendLine(string.Format("        public {0}{1} {2} {3}", clm.PropertyType, CodeFirstTools.CheckNullable(clm), clm.PropertyName, "{get; set; }"));
                    }
                }
                result.AppendLine("   }");
                result.AppendLine("}");

                string targetPath = ModelPathConverter.GetCodePath(_consType, IsOverWrite, _entity);
                using (FileStream create = new FileStream(targetPath, FileMode.OpenOrCreate))
                {
                    byte[] buffer = Encoding.Default.GetBytes(result.ToString());
                    create.Write(buffer, 0, buffer.Length);
                }
                BuildResult = ProjectContainer.Data2Object.AddFromFile(targetPath);

                base.CreateCode();
            }
            catch (Exception ex)
            {
                MsgBoxHelp.ShowError("创建代码出现异常:", ex);
            }
        }
示例#6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public FormMain()
 {
     InitializeComponent();
     try
     {
         pic.Image         = Image.FromFile(StringConverter.ConvertPath("img.jpg"));
         pictureBox1.Image = Image.FromFile(StringConverter.ConvertPath("coment.jpg"));
         pictureBox2.Image = Image.FromFile(StringConverter.ConvertPath("first.jpg"));
     }
     catch (Exception ex)
     {
         MsgBoxHelp.ShowError("初始化窗口失败", ex);
     }
 }
 /// <summary>
 /// 开始执行上下文中所有的内容
 /// </summary>
 public void Commit()
 {
     while (_gEntityQueue.Count() > 0)
     {
         GenerateEntity queue = _gEntityQueue.Dequeue();
         try
         {
             queue.GenerateEngin.Generate(queue.GenerateId, queue.GenerateArgment, queue.GenerateContainer);
         }
         catch (Exception ex)
         {
             MsgBoxHelp.ShowError(string.Format(Properties.Resource.GenerateError, PrjCmdId.FindProjectName(queue.GenerateId)), ex);
         }
         finally
         {
             if (GeneratedOne != null)
             {
                 GeneratedOne(this, new EventGeneratedArg(queue.GenerateId, Count, KeywordContainer.Resove("$Entity$")));
             }
         }
     }
 }
示例#8
0
        /// <summary>
        /// 添加构架应用程序
        /// </summary>
        /// <param name="ProjectCommon"></param>
        private void AddSchameLib(bool overWrite = true)
        {
            try
            {
                if (SolutionCommon.infrastryctType == InfrastructType.CodeFirst)
                {
                    InfrastructureLogic.CreateCodeFirst(overWrite);
                    DomainEntityLogic.CreateCodeFirst(overWrite);
                }
                else
                {
                    InfrastructureLogic.Create(overWrite);
                    DomainEntityLogic.Create(overWrite);
                }
                RepositoryLogic.Create(overWrite);
                Data2ObjLogic.Create(overWrite);
                ApplicationLogic.Create(overWrite);
                if (SolutionCommon.IsAddService)
                {
                    ServiceLogic.CreateFrame(overWrite);
                    ServiceLogic.CreateCode(overWrite);
                }
                else
                {
                    ProjectContainer.Service = null;
                }

                //保存解决方案
                if (_dte.Solution.Saved == false)
                {
                    _dte.Solution.SaveAs(_dte.Solution.FullName);
                }
            }
            catch (Exception ex)
            {
                MsgBoxHelp.ShowError("Entity2Code Error:", ex);
            }
        }
示例#9
0
        public override void CreateCode()
        {
            try
            {
                if (null == BuildTaget)
                {
                    throw new Exception("Entity2Code Code Taget Lost");
                }
                StringCodeArgment fileObj = BuildTaget as StringCodeArgment;
                if (null == fileObj)
                {
                    throw new Exception("Entity2Code Code Taget Argment Error");
                }

                Project prj = fileObj.Target;
                BuildResult = string.IsNullOrEmpty(fileObj.Folder) ? prj.AddFromFileString(CodeContent.ToString(), fileObj.Name, fileObj.Encode) : BuildResult = prj.AddFromFileString(CodeContent.ToString(), fileObj.Folder, fileObj.Name);
                base.CreateCode();
            }
            catch (Exception ex)
            {
                MsgBoxHelp.ShowError("创建代码异常了", ex);
            }
        }
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex == 3)
         {
             OpenFileDialog dlg = new OpenFileDialog();
             dlg.Filter      = "应用程序集(.dll)|*.dll";
             dlg.Multiselect = false;
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 string sourcePath = dlg.FileName;
                 int    index      = e.RowIndex;
                 string name       = Path.GetFileNameWithoutExtension(sourcePath);
                 if (string.Compare(name, dataGridView1[0, index].Value.ToString(), true) == 0)
                 {
                     File.Copy(sourcePath, dataGridView1[4, index].Value.ToString(), true);
                     ReferManageArgment arg = ReferManageLogic.GetReferInfo(dataGridView1[4, index].Value.ToString());
                     dataGridView1[0, index].Value = arg.ReferName;
                     dataGridView1[1, index].Value = arg.currentVesion;
                     dataGridView1[2, index].Value = arg.ModifyTime;
                     dataGridView1[3, index].Value = "更新";
                     dataGridView1[4, index].Value = arg.Path;
                     dataGridView1.Refresh();
                 }
                 else
                 {
                     MsgBoxHelp.ShowWorning("引用程序集名称和源名称不一致,请选择正确的程序集");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MsgBoxHelp.ShowError("更新程序集错误", ex);
     }
 }
示例#11
0
        public override void CreateCode()
        {
            try
            {
                string path = string.Empty;
                if (null == _entity)
                {
                    path = ModelPathConverter.GetCodePath(_consType, IsOverWrite);
                }
                else
                {
                    path = ModelPathConverter.GetCodePath(_consType, IsOverWrite, _entity);
                }
                using (FileStream create = new FileStream(path, FileMode.OpenOrCreate))
                {
                    byte[] buffer = Encoding.Default.GetBytes(CodeContent.ToString());
                    create.Write(buffer, 0, buffer.Length);
                }

                if (null == BuildTaget)
                {
                    throw new Exception("Entity2Code Code Taget Lost");
                }
                Project prj = BuildTaget as Project;
                if (null == prj)
                {
                    throw new Exception("Entity2Code Code Taget Argment Error");
                }
                BuildResult = prj.AddFromFile(path);
                base.CreateCode();
            }
            catch (Exception ex)
            {
                MsgBoxHelp.ShowError("创建代码异常了", ex);
            }
        }