Exemplo n.º 1
0
        /// <summary>
        /// 绑定表信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="isCompositeQueryDt"></param>
        /// <param name="sql"></param>
        public void BindTableInfo(DataTable dt, bool isCompositeQueryDt, string sql = "")
        {
            this.tabControlOpt.SelectedTab = this.tabPageTable;
            this.dgvTableInfo.DataSource = dt;

            if (isCompositeQueryDt)
            {
                this._codeBaseInfo = TableBll.GetCodeBaseInfoByDBTable(dt, true);
                this._codeBaseInfo.Sql = sql;

                this.txtClassName.Text = string.Empty;
            }
            else
            {
                this._codeBaseInfo = TableBll.GetCodeBaseInfoByDBTable(dt);

                this.txtClassName.Text = TableBll.GetClassName(dt.TableName);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 代码生成
 /// </summary>
 /// <param name="codeBaseInfo"></param>
 /// <param name="tempPath"></param>
 /// <returns></returns>
 public static string CodeGenerator(CodeBaseInfo codeBaseInfo, string tempPath)
 {
     return(CodeGenerator("dt", codeBaseInfo, tempPath, new string[] { typeof(CodeBaseInfo).Namespace }));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取代码生成所需的信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="isCompositeQuery"></param>
        /// <returns></returns>
        public static CodeBaseInfo GetCodeBaseInfoByDBTable(DataTable dt, bool isCompositeQuery = false)
        {
            if (dt == null || dt.Rows.Count == 0)
            {
                return(null);
            }

            var codeBase = new CodeBaseInfo()
            {
                TableName = dt.TableName
            };

            foreach (DataRow r in dt.Rows)
            {
                var filed = new FiledInfo()
                {
                    No           = 1,
                    Name         = string.Empty,
                    CSharpType   = string.Empty,
                    CommonType   = typeof(object),
                    Length       = 0,
                    DecimalPlace = 0,
                    IsIdentify   = false,
                    IsPk         = false,
                    IsAllowNull  = false,
                    Description  = string.Empty
                };

                if (dt.Columns.Contains("序号"))
                {
                    filed.No = int.Parse(r["序号"].ToString());
                }

                if (dt.Columns.Contains("列名"))
                {
                    filed.Name = r["列名"].ToString();
                }

                if (dt.Columns.Contains("数据类型"))
                {
                    if (isCompositeQuery)
                    {
                        filed.CSharpType = r["数据类型"].ToString();
                    }
                    else
                    {
                        filed.CSharpType = ConvertUnity.MapCsharpType(r["数据类型"].ToString());

                        filed.CommonType = ConvertUnity.MapCommonType(r["数据类型"].ToString());
                    }
                }

                if (dt.Columns.Contains("长度"))
                {
                    filed.Length = int.Parse(r["长度"].ToString());
                }

                if (dt.Columns.Contains("小数"))
                {
                    filed.DecimalPlace = int.Parse(r["小数"].ToString());
                }

                if (dt.Columns.Contains("标识"))
                {
                    filed.IsIdentify = bool.Parse(r["标识"].ToString());
                }

                if (dt.Columns.Contains("主键"))
                {
                    filed.IsPk = bool.Parse(r["主键"].ToString());
                }

                if (dt.Columns.Contains("允许空"))
                {
                    filed.IsAllowNull = bool.Parse(r["允许空"].ToString());
                }

                if (dt.Columns.Contains("说明"))
                {
                    filed.Description = r["说明"].ToString();
                }

                codeBase.FiledList.Add(filed);
            }

            return(codeBase);
        }