示例#1
0
        /// <summary>
        /// 获取CS文件
        /// </summary>
        /// <param name="parentName"></param>
        /// <param name="subName"></param>
        /// <param name="template"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private string GetCSFile(string parentName, string subName, string template, string entity = "Entity")
        {
            var csFile = string.Empty;

            try
            {
                List <DBStructure> infos = DBInfo.DBInfoList.Where(w => w.DBName == parentName).Select(s => s.TableStruList).FirstOrDefault();
                var info = infos.Where(w => w.TableName == subName).FirstOrDefault() ?? null;
                if (info == null)
                {
                    return(csFile);
                }
                Dictionary <string, object> dicInfo = new Dictionary <string, object>();
                dicInfo.Add("Entity", info);
                dicInfo.Add("ClassLibrary", ABContent.SelectedProject.ProjectName);
                dicInfo.Add("FolderName", cbx_Folder.Text);
                var result = NVelocityHelper.ProcessTemplate(template, dicInfo);
                //string result = Engine.Razor.RunCompile(template, "template6111", null, dbs); razor 略卡
                csFile = FilesHelper.Write(Path.Combine(ABContent.SelectedProject.ProjectDirectoryName, cbx_Folder.Text), subName + "Entity.cs", result);
            }
            catch (Exception ex)
            {
                OutputWindowHelper.OutPutMessage($"获取CS文件出现异常 \n 信息:{ex.Message} \n 堆栈:{ex.StackTrace}");
            }
            return(csFile);
        }
示例#2
0
        /// <summary>
        /// 确认提交事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SubmitEvent(object sender, RoutedEventArgs e)
        {
            var theSelectedProject = _autoBuildEntityContent.SelectedProject;

            try
            {
                //获取物理表名
                var addAndUpdateList = _hadAddCheckSelectList.Union(_noAddCheckSelectList).ToList();
                var removeFiles      = _noExistCheckSelectList.Select(a => a.ToCaseCamelName() + ".cs").ToList();

                //查询出表结构
                var dbTable  = new DbTable(_autoBuildEntityContent.EntityXml.ConnString);
                var dbtables = dbTable.GetTables(addAndUpdateList, _sqlType);

                //根据模版输出
                var templateModel =
                    dbtables.Select(
                        a =>
                        new TemplateModel(a.TableName, a.Columns,
                                          theSelectedProject.ProjectName)).ToList();

                var templateDic = templateModel.ToDictionary(a => a.ClassName,
                                                             item =>
                                                             NVelocityHelper.ProcessTemplate(_autoBuildEntityContent.EntityXml.EntityTemplate,
                                                                                             new Dictionary <string, object> {
                    { "entity", item }
                }));

                //保存文件
                foreach (var templateData in templateDic)
                {
                    var path = FilesHelper.WriteAndSave(theSelectedProject.ProjectDirectoryName,
                                                        templateData.Key, templateData.Value);

                    if (_noAddCheckSelectList.Select(a => a.ToCaseCamelName()).Contains(templateData.Key))
                    {
                        theSelectedProject.ProjectDte.ProjectItems.AddFromFile(path);
                    }
                }

                //添加项目项和排除项目项
                theSelectedProject.ProjectDte.RemoveFilesFromProject(removeFiles);

                Close();
            }
            catch (ArgumentException)
            {
                MessageBox.Show("您的选项在数据库里存在多个项目命名规范的表(视图)名");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
        /// <summary>
        /// 确认提交事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SubmitEvent(object sender, RoutedEventArgs e)
        {
            var theSelectedProject = _autoBuildEntityContent.SelectedProject;

            try
            {
                //获取物理表名
                var addAndUpdateList = _hadAddCheckSelectList.Union(_noAddCheckSelectList).ToList();
                var removeFiles      = _noExistCheckSelectList.Select(a => a + ".cs").ToList();

                //查询出表结构
                var dbTable  = new DbTable(_autoBuildEntityContent.EntityXml.ConnString);
                var dbtables = dbTable.GetTables(addAndUpdateList);

                //根据模版输出
                var templateModel =
                    dbtables.Select(
                        a =>
                        new TemplateModel(a.TableName, a.Columns,
                                          theSelectedProject.ProjectName)).ToList();

                var templateDic = templateModel.ToDictionary(a => a.TableName,
                                                             item =>
                                                             NVelocityHelper.ProcessTemplate(_autoBuildEntityContent.EntityXml.EntityTemplate,
                                                                                             new Dictionary <string, object> {
                    { "entity", item }
                }));

                //保存文件
                var addfiles =
                    templateDic.Select(
                        templateData =>
                        FilesHelper.Write(theSelectedProject.ProjectDirectoryName,
                                          templateData.Key, templateData.Value)).ToList();

                //添加项目项和排除项目项、
                theSelectedProject.ProjectDte.AddFilesToProject(addfiles);
                theSelectedProject.ProjectDte.RemoveFilesFromProject(removeFiles);

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 获取CS文件
        /// </summary>
        /// <param name="parentName"></param>
        /// <param name="subName"></param>
        /// <param name="template"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private string GetCSFile(string parentName, string subName, string template, List <DBStructure> dbStru = null, string sql = "", string entity = "Entity")
        {
            var csFile = string.Empty;

            try
            {
                List <DBStructure> strinfo = dbStru;
                if (dbStru == null || dbStru.Count == 0)
                {
                    List <DBStructure> infos = DBInfo.DBInfoList.Where(w => w.DBName == parentName).Select(s => s.TableStruList).FirstOrDefault();
                    strinfo = infos == null ? null : infos.Where(w => w.TableName == subName).ToList();
                    if (strinfo == null && strinfo.Count() > 0)
                    {
                        return(csFile);
                    }
                    strinfo.ForEach(f => f.ColDesc = Regex.Replace(f.ColDesc, @"[\r\n]+", ";"));
                }
                Dictionary <string, object> dicInfo = new Dictionary <string, object>();
                dicInfo.Add("Entity", strinfo);
                dicInfo.Add("NameSpace", BEContent.SelectedProject.ProjectName + (cbx_Folder.Text == "根文件" ? "" : $".{cbx_Folder.Text}"));
                dicInfo.Add("DBName", parentName);
                dicInfo.Add("TableName", subName);
                if (string.IsNullOrEmpty(sql) == false)
                {
                    dicInfo.Add("SQL", sql);
                }
                var result = NVelocityHelper.ProcessTemplate(BEContent.SelectedProject.ProjectDirectoryName, template, dicInfo);
                csFile = FilesHelper.Write(Path.Combine(BEContent.SelectedProject.ProjectDirectoryName, cbx_Folder.Text == "根文件" ? "" : cbx_Folder.Text), subName + "Entity", result);
            }
            catch (Exception ex)
            {
                OutputWindowHelper.OutPutMessage($"获取CS文件出现异常 \r\n 信息:{ex.Message} \r\n 堆栈:{ex.StackTrace}");
                OutPutMsg($"获取CS文件出现异常 \r\n 信息:{ex.Message}");
            }
            return(csFile);
        }