예제 #1
0
        ///////////////////////以下生成 Model
        #region 多表时,生成实例类文件
        /// <summary>
        /// 多表时,生成实例类文件
        /// </summary>
        /// <param name="ds"></param>
        public string ToModels(bool confirmWrite, List <string> tablesName)
        {
            StringBuilder ret = new StringBuilder();
            ProcTable     pt  = new ProcTable();
            ProcString    ps  = new ProcString();

            ps.SetTabs(strNameSpace);
            DataSet dsColumnsDescription = pt.GetTablesColumnDecription(tablesName);

            foreach (string tableName in tablesName)
            {
                //if (tableName == " JHPIX_PAT_MASTER_INDEX")
                //    MessageBox.Show("JHPIX_PAT_MASTER_INDEX类的GetUpdateSQL方法特殊!不可自动生成");
                string    strClass     = "";
                TableInfo tableInfo    = new TableInfo(strNameSpace, strPrefix, tableName);
                DataSet   dsTableInfo  = tableInfo.dsTableInfo;
                DataTable dtColumnType = dsTableInfo.Tables[1];
                //DataColumnCollection dtcols = dtColumnType.Columns;
                DataTable dtColumnsDescription = null;
                string    tableDecription      = pt.GetTableDesciption(tableName);

                for (int i = 0; i < dsColumnsDescription.Tables.Count; i++)
                {
                    dtColumnsDescription = dsColumnsDescription.Tables[i].Copy();

                    if (dtColumnsDescription.TableName == tableName)
                    {
                        dsColumnsDescription.Tables.RemoveAt(i);
                        break;
                    }
                }
                //缺少主键校验
                strClass = pt.GetTable(dtColumnType, dtColumnsDescription
                                       , tableDecription
                                       , strPrefix, strNameSpace);
                ret.AppendLine(strClass);
                #region 写文件
                if (confirmWrite)
                {
                    string tem = path + "/Model/";
                    if (!Directory.Exists(tem))
                    {
                        Directory.CreateDirectory(tem);
                    }
                    string className = ps.GetClassNameByTableName(tableName, strPrefix.Trim()); //类名大写
                    //className = ps.GetClassName(className);//lsj
                    string fullPath = tem + className + ".cs";                                  //2021-2-2-lsj-首字母大写

                    Write(fullPath, strClass);
                }
                #endregion
            }
            return(ret.ToString());
        }
예제 #2
0
        ///////////////////////以上生成 Model

        ////////////////////////////以下生成 数据访问层
        #region 生成单表数据访问层
        /// <summary>
        /// 生成单表数据访问层
        /// </summary>
        /// <param name="confirmWrite">是否生成文件</param>
        /// <returns></returns>
        public string ToDataAccess(bool confirmWrite, List <string> tablesName)
        {
            StringBuilder ret = new StringBuilder();
            ProcTable     pt  = new ProcTable();
            ProcString    ps  = new ProcString();

            ps.SetTabs(strNameSpace);
            ps.strImportNameSpace = @"using System;
using System.Data;
using System.Collections.Generic;
";
            foreach (string tableName in tablesName)
            {
                string strMember    = @"IDBOperator idb =  DBOperator.GetInstance();";
                string strClassBody = ps.GetDataAccessClassBody(tableName, strPrefix, strNameSpace);
                string str          = ps.GetCLassByModel(strNameSpace, strPrefix, tableName, strADO, strMember, strClassBody);
                ret.Append(str);

                #region 写文件
                if (confirmWrite)
                {
                    string tem          = path + "/ADO/";
                    string strClassName = ps.GetClassNameByTableName(tableName, strPrefix);
                    if (!Directory.Exists(tem))
                    {
                        Directory.CreateDirectory(tem);
                    }

                    string fullpath = tem + strADO + strClassName + ".cs";

                    Write(fullpath, ret.ToString());
                }
                #endregion
            }
            return(ret.ToString());
        }
예제 #3
0
        /// <summary>
        /// 单表时,生成实例类文件
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <returns></returns>
        public string ToModel(bool confirmWrite, string tableName)
        {
            StringBuilder ret = new StringBuilder();
            ProcTable     pt  = new ProcTable();
            ProcString    ps  = new ProcString();

            ps.SetTabs(strNameSpace);
            DataTable dtColumnDescription = pt.GetTableColumnDecription(tableName);

            string strTableDescription = pt.GetTableDesciption(tableName);

            DataTable dtColumnType = pt.GetTableInfo(tableName).Tables[1];

            string strClassName = ps.GetClassNameByTableName(tableName, strPrefix);

            StringBuilder sbBody    = new StringBuilder();
            TableInfo     tableInfo = new TableInfo(strNameSpace, strPrefix, tableName);

            foreach (DataRow drType in dtColumnDescription.Rows)
            {
                string columnName           = drType["ColumnName"].ToString();        //列名
                string columnType           = drType["ColumnDescription"].ToString(); //列数据类型
                string firstLowerColumnName = "";                                     //首字母小写,用于字段
                string firstUpperColumnName = "";                                     //首字母大写,用于属性

                #region 以下为字段
                foreach (DataRow drDescription in dtColumnDescription.Rows)
                {
                    if (drDescription["ColumnName"].ToString() == columnName)
                    {
                        string strColumnDescription = drDescription["ColumnDescription"].ToString();
                        sbBody.AppendLine(ps.tabMember + "/// <summary>");
                        sbBody.AppendLine(ps.tabMember + "/// " + strColumnDescription);
                        sbBody.AppendLine(ps.tabMember + "/// <summary>");
                    }
                }
                firstLowerColumnName = ps.ConvertStringToUpperOrLower(columnName, false);
                //if (!string.IsNullOrEmpty(columnDefault))
                //{
                //    if (columnName.ToUpper() != "HOSPITAL_NO")
                //    {
                //        sbBody.AppendLine(ps.tabMember + "private " + ps.ConvertType(columnType, columnName, tableInfo) + " " + firstLowerColumnName + "=\"" + columnDefault + "\";");
                //    }
                //}
                //else
                //{
                sbBody.AppendLine(ps.tabMember + "private " + ps.ConvertType(columnType, columnName, tableInfo) + " " + firstLowerColumnName + ";");
                //}
                #endregion

                #region 以下为属性
                foreach (DataRow drDescription in dtColumnDescription.Rows)
                {
                    if (drDescription["ColumnName"].ToString() == columnName)
                    {
                        string strColumnDescription = drDescription["ColumnDescription"].ToString();
                        sbBody.AppendLine(ps.tabMember + "/// <summary>");
                        sbBody.AppendLine(ps.tabMember + "/// " + strColumnDescription);
                        sbBody.AppendLine(ps.tabMember + "/// <summary>");
                    }
                }
                firstUpperColumnName = ps.ConvertStringToUpperOrLower(columnName, true);
                sbBody.AppendLine(ps.tabMember + "public " + ps.ConvertType(columnType, columnName, tableInfo) + " " + firstUpperColumnName);
                sbBody.AppendLine(ps.tabMember + "{");
                sbBody.AppendLine(ps.tabLocalVar + "get{ return " + firstLowerColumnName + "; }");
                sbBody.AppendLine(ps.tabLocalVar + "set{ " + firstLowerColumnName + " = value; }");
                sbBody.AppendLine(ps.tabMember + "}");
                #endregion
                sbBody.AppendLine();
            }
            string strClass = ps.GetCLassByModel(strNameSpace, strPrefix, tableName, sbBody.ToString());
            ret.Append(strClass);

            #region 写文件
            if (confirmWrite)
            {
                string tem = path + "/Model/";
                if (!Directory.Exists(tem))
                {
                    Directory.CreateDirectory(tem);
                }
                string fullpath = tem + strClassName + ".cs";

                Write(fullpath, ret.ToString());
            }
            #endregion

            return(ret.ToString());
        }