public static void GenerateDataAccess(string tableName)
        {
            var fieldList  = generateDal.GetFieldList(tableName);
            var tableModel = generateDal.GetTableList().Single(o => o.Name == tableName);

            ModelTemplate modelTemplate = new ModelTemplate(fieldList, tableModel);
            String        contentModel  = modelTemplate.TransformText();

            System.IO.File.WriteAllText(Utility.FileHelper.PathExists(Config.BusinessEntitiesPath, tableName, Enums.GenerateType.Model), contentModel, Encoding.UTF8);

            DataAccessTemplate dataAccessTemplate = new DataAccessTemplate(fieldList, tableModel);
            String             contentDataAccess  = dataAccessTemplate.TransformText();

            System.IO.File.WriteAllText(Utility.FileHelper.PathExists(Config.DataAccessPath, tableName, Enums.GenerateType.DataAccess), contentDataAccess, Encoding.UTF8);

            LogicTemplate logicTemplate = new LogicTemplate(fieldList, tableModel);
            String        contentLogic  = logicTemplate.TransformText();

            System.IO.File.WriteAllText(Utility.FileHelper.PathExists(Config.BusinessLogicPath, tableName, Enums.GenerateType.Logic), contentLogic, Encoding.UTF8);

            //业务逻辑层接口
            if (Utility.Config.IBusinessLogicEnable == true)
            {
                IDataAccessTemplate idataAccessTemplate = new IDataAccessTemplate(fieldList, tableModel);
                String icontentDataAccess = idataAccessTemplate.TransformText();
                System.IO.File.WriteAllText(Utility.FileHelper.PathExists(Config.IDataAccessPath, "I" + tableName, Enums.GenerateType.DataAccess), icontentDataAccess, Encoding.UTF8);
            }

            //数据访问层接口
            if (Utility.Config.IDataAccessEnable == true)
            {
                ILogicTemplate ilogicTemplate = new ILogicTemplate(fieldList, tableModel);
                String         icontentLogic  = ilogicTemplate.TransformText();
                System.IO.File.WriteAllText(Utility.FileHelper.PathExists(Config.IBusinessLogicPath, "I" + tableName, Enums.GenerateType.Logic), icontentLogic, Encoding.UTF8);
            }
        }
Exemplo n.º 2
0
 private void CreateDataAccessFile(DataAccessTemplate dataaccess)
 {
     outPutFile("DataAccess", dataaccess.AccessClassName + ".cs", dataaccess.TransformText());
 }
Exemplo n.º 3
0
        private void btCreate_Click(object sender, EventArgs e)
        {
            if (!CheckString())
            {
                return;
            }

            //if (string.IsNullOrEmpty(tbNameSpace.Text))
            //{
            //    MessageBox.Show("名称空间必须输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            if (clbTables.CheckedItems.Count <= 0)
            {
                MessageBox.Show(Resources.SelectTable, Resources.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            for (var i = 0; i < clbTables.CheckedItems.Count; i++)
            {
                var tableName         = string.Empty;
                var dtColunms         = Access.GetTableColunms(clbTables.CheckedItems[i].ToString(), _txtConn);
                var originalTableName = clbTables.CheckedItems[i].ToString();
                if (originalTableName.IndexOf('_') > 0)
                {
                    string[] arrayTableName = originalTableName.Split('_');
                    tableName = arrayTableName.Aggregate(tableName, (current, tName) => current + Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(tName.ToLower()));
                    //tableName = OriginalTableName.Substring(0, 1).ToUpper() + OriginalTableName.Substring(1, OriginalTableName.IndexOf("_")).ToLower()
                    //           + OriginalTableName.Substring(OriginalTableName.IndexOf("_") + 1, 1) + OriginalTableName.Substring(OriginalTableName.IndexOf("_") + 2).ToLower();
                }
                else
                {
                    tableName = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(originalTableName.ToLower());
                }
                var schema = new SchemaTemplate
                {
                    NameSpace         = tbNameSpace.Text,
                    DtColunms         = dtColunms,
                    TableName         = tableName,
                    OriginalTableName = originalTableName
                };
                CreateSchemaFile(schema);

                var entity = new EntityTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateEntityFile(entity);

                var dataaccess = new DataAccessTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateDataAccessFile(dataaccess);

                var business = new BusinessTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateBusinessFile(business);

                var model = new ModelTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateModelFile(model);
            }

            MessageBox.Show(Resources.OutPutSuccess);
        }