Exemple #1
0
        public static void Generate(DataGridView dgvTables, bool isPascal, EnumDbType dbType)
        {
            var          listSql = new List <string>();
            List <Table> list    = TableControl.GetCheckedTableName(dgvTables, isPascal);

            if (list.Count == 0)
            {
                MessageBox.Show(ConstantUtil.CheckedNoTable);
                return;
            }

            var ds = new DataSet();

            foreach (Table item in list)
            {
                DataTable dtColumns = ColumnControl.GetTableColumnsByTableName(item.TableName, dbType);
                dtColumns.TableName = item.TabPascalName + "$" + item.Comments;
                bool b = ColumnControl.GetColRelaPascalName(dtColumns);
                if (isPascal && !b)
                {
                    MessageBox.Show(ConstantUtil.NoRelaPascalCol);
                    return;
                }
                ds.Tables.Add(dtColumns);
            }

            CreateWordUtil.Create(ds, dbType);
        }
Exemple #2
0
        public static DataTable GetColumnAndPascalNameFromXml(string tableName, EnumDbType dbType)
        {
            DataTable dtColumns = ColumnControl.GetTableColumnsByTableName(tableName, dbType);

            XmlControl.CreateCorrespondingXmlWhenNotExist();

            var dic = XmlControl.ReadXml();

            for (int i = 0; i < dtColumns.Rows.Count; i++)
            {
                string name = dtColumns.Rows[i]["Column_Name"].ToString();
                if (dic.ContainsKey(name))
                {
                    dtColumns.Rows[i]["PascalName"] = dic[name];
                }
            }
            dtColumns.AcceptChanges();
            return(dtColumns);
        }
Exemple #3
0
        /// <summary>
        /// Generate Domain Class
        /// </summary>
        /// <param name="dbTableName">TableName in DataBase</param>
        /// <param name="tableName">TableName what'll generate</param>
        public StringBuilder Generate()
        {
            var sbTemp = new StringBuilder();

            DataTable dtColumns = ColumnControl.GetTableColumnsByTableName(dbTableName, dbType);

            string colName = string.Empty;

            #region Generate NameSpace And Class

            sbTemp.Append("using System;");
            sbTemp.Append("\r\n");
            sbTemp.Append("\r\n").Append("namespace ").Append(preNS);
            sbTemp.Append("\r\n").Append("{");
            sbTemp.Append("\r\n").Append("/// <summary>");
            sbTemp.Append("\r\n").Append("///").Append("Domain Class");
            sbTemp.Append("\r\n").Append("/// </summary>");
            sbTemp.Append("\r\n").Append("[Serializable]");

            sbTemp.Append("\r\n").Append("public class ").Append(preModel).Append(tableName);
            sbTemp.Append("\r\n").Append("{");

            #endregion

            #region Generate Constructors

            sbTemp.Append("\r\n").Append("/// <summary>");
            sbTemp.Append("\r\n").Append("///").Append("Constructor(initial properties null)");
            sbTemp.Append("\r\n").Append("/// </summary>");
            sbTemp.Append("\r\n").Append("public ").Append(preModel).Append(tableName).Append("()");
            sbTemp.Append("\r\n").Append("{");
            for (int i = 0; i < dtColumns.Rows.Count; i++)
            {
                string tempColumnName = dtColumns.Rows[i]["COLUMN_NAME"].ToString();
                if (isPascal)
                {
                    colName = dtColumns.Rows[i]["PascalName"].ToString();
                }
                else
                {
                    colName = tempColumnName;
                }
                string tempType = dtColumns.Rows[i]["DATA_TYPE"].ToString();


                sbTemp.Append("\r\n").Append("this.").Append(colName).Append(" = null").Append(";");
            }
            sbTemp.Append("\r\n}");

            #endregion

            #region Generate fields And properties

            for (int i = 0; i < dtColumns.Rows.Count; i++)
            {
                string tempColumnName = dtColumns.Rows[i]["COLUMN_NAME"].ToString();
                if (isPascal)
                {
                    colName = dtColumns.Rows[i]["PascalName"].ToString();
                }
                else
                {
                    colName = tempColumnName;
                }
                string tempType        = dtColumns.Rows[i]["DATA_TYPE"].ToString();
                string tempLength      = dtColumns.Rows[i]["DATA_LENGTH"].ToString();
                string tempDescription = dtColumns.Rows[i]["Comments"].ToString();
                string tempPrecision   = dtColumns.Rows[i]["DATA_PRECISION"].ToString();
                string tempScale       = dtColumns.Rows[i]["DATA_SCALE"].ToString();

                sbTemp.Append("\r\n");
                sbTemp.Append("\r\n/// <summary>");
                sbTemp.Append("\r\n///").Append(tempDescription);
                sbTemp.Append("\r\n/// </summary>");
                if (dbType == EnumDbType.Oracle)
                {
                    sbTemp.Append("\r\npublic ").Append(DataTypeConvertUtil.ConvertTypeOracle(tempType, tempPrecision,
                                                                                              tempScale)).Append(" ").Append(
                        colName).Append(
                        " { get; set; }");
                }
                else
                {
                    sbTemp.Append("\r\npublic ").Append(DataTypeConvertUtil.ConvertType2008SqlServer(tempType, tempPrecision,
                                                                                                     tempScale)).Append(" ").Append(
                        colName).Append(
                        " { get; set; }");
                }
            }
            sbTemp.Append("\r\n}");
            sbTemp.Append("\r\n}");

            #endregion

            return(sbTemp);
        }