コード例 #1
0
        /// <summary>
        /// 生成update查询语句
        /// </summary>
        /// <param name="dbname">库名</param>
        /// <param name="tablename">表名</param>
        /// <returns></returns>
        public string GetSQLDelete(string dbname, string tablename)
        {
            dbobj.DbConnectStr = _dbconnectStr;
            DataTable dt = dbobj.GetColumnList(dbname, tablename);

            this.DbName    = dbname;
            this.TableName = tablename;
            StringPlus strsql = new StringPlus();

            strsql.AppendLine("delete from " + tablename);
            strsql.Append(" where  <搜索条件>");
            return(strsql.Value);
        }
コード例 #2
0
        /// <summary>
        /// 生成update查询语句
        /// </summary>
        /// <param name="dbname">库名</param>
        /// <param name="tablename">表名</param>
        /// <returns></returns>
        public string GetSQLUpdate(string dbname, string tablename)
        {
            dbobj.DbConnectStr = _dbconnectStr;
            DataTable dt = dbobj.GetColumnList(dbname, tablename);

            this.DbName    = dbname;
            this.TableName = tablename;
            StringPlus strsql = new StringPlus();

            strsql.AppendLine("update " + tablename + " set ");
            if (dt != null)
            {
                foreach (DataRow row in dt.Rows)
                {
                    string columnName = row["ColumnName"].ToString();
                    strsql.AppendLine("[" + columnName + "] = <" + columnName + ">,");
                }
                strsql.DelLastComma();
            }
            strsql.Append(" where <搜索条件>");
            return(strsql.Value);
        }
コード例 #3
0
        public string CreatPROCGetMaxID()
        {
            StringPlus strclass = new StringPlus();

            strclass.AppendLine("------------------------------------");
            strclass.AppendLine("--用途:得到最大ID ");
            strclass.AppendLine("--项目名称:" + ProjectName);
            strclass.AppendLine("--说明:");
            strclass.AppendLine("--时间:" + DateTime.Now.ToString());
            strclass.AppendLine("------------------------------------");
            strclass.AppendLine("CREATE PROCEDURE " + ProcPrefix + "" + _tablename + "_GetMaxId");
            strclass.AppendLine("AS");
            strclass.AppendSpaceLine(1, "DECLARE @TempID int");
            strclass.AppendSpaceLine(1, "SELECT @TempID = max([" + ID + "])+1 FROM " + _tablename);
            strclass.AppendSpaceLine(1, "IF @TempID IS NULL");
            strclass.AppendSpaceLine(2, "RETURN 1");
            strclass.AppendSpaceLine(1, "ELSE");
            strclass.AppendSpaceLine(2, "RETURN @TempID");
            strclass.AppendLine("");
            strclass.AppendLine("GO");
            return(strclass.ToString());
        }
コード例 #4
0
        public string GetSQLUpdate(string dbname, string tablename)
        {
            this.dbobj.DbConnectStr = this._dbconnectStr;
            List <ColumnInfo> columnList = this.dbobj.GetColumnList(dbname, tablename);

            this.DbName    = dbname;
            this.TableName = tablename;
            StringPlus stringPlus = new StringPlus();

            stringPlus.AppendLine("update " + tablename + " set ");
            if (columnList != null && columnList.Count > 0)
            {
                foreach (ColumnInfo current in columnList)
                {
                    string columnName = current.ColumnName;
                    stringPlus.AppendLine(columnName + " = <" + columnName + ">,");
                }
                stringPlus.DelLastComma();
            }
            stringPlus.Append(" where <搜索条件>");
            return(stringPlus.Value);
        }
コード例 #5
0
        /// <summary>
        /// 生成update查询语句
        /// </summary>
        /// <param name="dbname">库名</param>
        /// <param name="tablename">表名</param>
        /// <returns></returns>
        public string GetSQLUpdate(string dbname, string tablename)
        {
            dbobj.DbConnectStr = _dbconnectStr;
            List <ColumnInfo> collist = dbobj.GetColumnList(dbname, tablename);

            this.DbName    = dbname;
            this.TableName = tablename;
            StringPlus strsql = new StringPlus();

            strsql.AppendLine("UPDATE [" + tablename + "] set ");
            if ((collist != null) && (collist.Count > 0))
            {
                foreach (ColumnInfo col in collist)
                {
                    string columnName = col.ColumnName;
                    strsql.AppendLine("[" + columnName + "] = <" + columnName + ">,");
                }
                strsql.DelLastComma();
            }
            strsql.AppendLine(" WHERE <搜索条件>");
            return(strsql.Value);
        }
コード例 #6
0
        /// <summary>
        /// 得到Update()的代码
        /// </summary>
        /// <param name="DbName"></param>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <param name="ModelName"></param>
        /// <returns></returns>
        public string CreatUpdate()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus strclass  = new StringPlus();
            StringPlus strclass1 = new StringPlus();
            StringPlus strclass2 = new StringPlus();

            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// 更新一条数据");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public void Update(" + ModelSpace + " model)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpaceLine(3, "strSql.Append(\"update " + _tablename + " set \");");
            //int n = 0;
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string Length     = field.Length;
                bool   IsIdentity = field.IsIdentity;
                bool   isPK       = field.IsPK;

                strclass1.AppendSpaceLine(3, "db.AddInParameter(dbCommand, \"" + columnName + "\", DbType." + CSToProcType(columnType) + ", model." + columnName + ");");

                if (field.IsIdentity || field.IsPK || (Keys.Contains(field)))
                {
                    continue;
                }
                strclass.AppendSpaceLine(3, "strSql.Append(\"" + columnName + "=" + preParameter + columnName + ",\");");
            }


            //去掉最后的逗号
            strclass.DelLastComma();
            strclass.AppendLine("\");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + GetWhereExpression(Keys) + "\");");


            strclass.AppendSpaceLine(3, "Database db = DatabaseFactory.CreateDatabase();");
            strclass.AppendSpaceLine(3, "DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());");


            strclass.Append(strclass1.Value);
            strclass.AppendSpaceLine(3, "db.ExecuteNonQuery(dbCommand);\r\n");
            strclass.AppendSpaceLine(2, "}");
            return(strclass.ToString());
        }
コード例 #7
0
        public string CreatPROCGetMaxID()
        {
            StringPlus stringPlus = new StringPlus();

            if (this._keys.Count > 0)
            {
                foreach (ColumnInfo current in this._keys)
                {
                    if (CodeCommon.DbTypeToCS(current.TypeName) == "int")
                    {
                        string columnName = current.ColumnName;
                        if (current.IsPrimaryKey)
                        {
                            stringPlus.AppendLine("------------------------------------");
                            stringPlus.AppendLine("--用途:得到主键字段最大值 ");
                            stringPlus.AppendLine("--项目名称:" + this.ProjectName);
                            stringPlus.AppendLine("--说明:");
                            stringPlus.AppendLine("--时间:" + DateTime.Now.ToString());
                            stringPlus.AppendLine("------------------------------------");
                            stringPlus.AppendLine("CREATE PROCEDURE " + this.ProcPrefix + this._tablename + "_GetMaxId");
                            stringPlus.AppendLine("AS");
                            stringPlus.AppendSpaceLine(1, "DECLARE @TempID int");
                            stringPlus.AppendSpaceLine(1, "SELECT @TempID = max([" + columnName + "])+1 FROM " + this._tablename);
                            stringPlus.AppendSpaceLine(1, "IF @TempID IS NULL");
                            stringPlus.AppendSpaceLine(2, "RETURN 1");
                            stringPlus.AppendSpaceLine(1, "ELSE");
                            stringPlus.AppendSpaceLine(2, "RETURN @TempID");
                            stringPlus.AppendLine("");
                            stringPlus.AppendLine("GO");
                            break;
                        }
                    }
                }
            }
            return(stringPlus.ToString());
        }
コード例 #8
0
        /// <summary>
        /// 生成INSERT查询语句
        /// </summary>
        /// <param name="dbname">库名</param>
        /// <param name="tablename">表名</param>
        /// <returns></returns>
        public string GetSQLInsert(string dbname, string tablename)
        {
            dbobj.DbConnectStr = _dbconnectStr;
            //DataTable dt = dbobj.GetColumnList(dbname, tablename);
            List <ColumnInfo> collist = dbobj.GetColumnList(dbname, tablename);

            this.DbName    = dbname;
            this.TableName = tablename;
            StringPlus strsql  = new StringPlus();
            StringPlus strsql2 = new StringPlus();

            strsql.AppendLine("INSERT INTO [" + tablename + "] ( ");

            if ((collist != null) && (collist.Count > 0))
            {
                foreach (ColumnInfo col in collist)
                {
                    string columnName = col.ColumnName;
                    string columnType = col.TypeName;

                    strsql.AppendLine("[" + columnName + "] ,");
                    if (LTP.CodeHelper.CodeCommon.IsAddMark(columnType))
                    {
                        strsql2.Append("'" + columnName + "',");
                    }
                    else
                    {
                        strsql2.Append(columnName + ",");
                    }
                }
                strsql.DelLastComma();
                strsql2.DelLastComma();
            }
            strsql.Append(") VALUES (" + strsql2.Value + ")");
            return(strsql.Value);
        }
コード例 #9
0
        public string GetShowAspx()
        {
            StringPlus stringPlus = new StringPlus();

            stringPlus.AppendLine();
            stringPlus.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">");
            foreach (ColumnInfo current in this.Fieldlist)
            {
                string columnName = current.ColumnName;
                string typeName   = current.TypeName;
                string text       = current.Description;
                text = CodeCommon.CutDescText(text, 15, columnName);
                stringPlus.AppendSpaceLine(1, "<tr>");
                stringPlus.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">");
                stringPlus.AppendSpaceLine(2, text);
                stringPlus.AppendSpaceLine(1, ":</td>");
                stringPlus.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">");
                typeName.Trim().ToLower();
                stringPlus.AppendSpaceLine(2, "<asp:Label id=\"lbl" + columnName + "\" runat=\"server\"></asp:Label>");
                stringPlus.AppendSpaceLine(1, "</td></tr>");
            }
            stringPlus.AppendLine("</table>");
            return(stringPlus.ToString());
        }
コード例 #10
0
        public string CreateDBTabScript(string dbname)
        {
            this.dbobj.DbConnectStr = this.DbConnectStr;
            StringPlus    stringPlus = new StringPlus();
            List <string> tables     = this.dbobj.GetTables(dbname);

            if (tables.Count > 0)
            {
                foreach (string current in tables)
                {
                    stringPlus.AppendLine(this.CreateTabScript(dbname, current));
                }
            }
            return(stringPlus.Value);
        }
コード例 #11
0
        /// <summary>
        /// 得到一个库下所有表的存储过程
        /// </summary>
        /// <param name="DbName"></param>
        /// <returns></returns>
        public string GetPROCCode(string dbname)
        {
            dbobj.DbConnectStr = this.DbConnectStr;
            StringPlus    strclass = new StringPlus();
            List <string> tabNames = dbobj.GetTables(dbname);

            if (tabNames.Count > 0)
            {
                foreach (string tabname in tabNames)
                {
                    strclass.AppendLine(GetPROCCode(dbname, tabname));
                }
            }
            return(strclass.Value);
        }
コード例 #12
0
        /// <summary>
        /// 生成修改方法代码
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="columnList"></param>
        /// <param name="keyColumnList"></param>
        /// <returns></returns>
        public string BuildCode_Update(string tableName, List <Column> columnList, List <Column> keyColumnList)
        {
            StringPlus sp = new StringPlus();

            //注释
            sp.AppendSpaceLine(1, "/// <summary>");
            sp.AppendSpaceLine(1, "/// " + "修改");
            sp.AppendSpaceLine(1, "/// </summary>");

            //方法头
            string strretu = "int";
            string strFun  = "\t" + "public " + strretu + " Update(" + tableName + " model)";

            sp.AppendLine(strFun);

            //方法体
            sp.AppendSpaceLine(1, "{");
            sp.AppendSpaceLine(2, "StringBuilder strSql = new StringBuilder();");
            sp.AppendSpaceLine(2, "strSql.Append(\"update " + tableName + " set \");");
            string columnsString = BuildHelper.BuildSetString(columnList);

            sp.AppendSpaceLine(2, "strSql.Append(\" " + columnsString + " \");");
            sp.AppendSpaceLine(2, "strSql.Append(\" where " + BuildHelper.BuildWhereStringInP(keyColumnList) + "\");");
            sp.AppendSpaceLine(2, "SqlParameter[] parameters = new SqlParameter[" + (columnList.Count + keyColumnList.Count) + "];");
            int i = 0;

            for (i = 0; i < columnList.Count; i++)
            {
                sp.AppendSpaceLine(2, "parameters[" + i + "] = new SqlParameter(\"@" + columnList[i].Name + "\", SqlDbType." + columnList[i].Type.ToSqlDbTypeString() + ");");
            }
            for (int k = 0; k < keyColumnList.Count; k++, i++)
            {
                sp.AppendSpaceLine(2, "parameters[" + i + "] = new SqlParameter(\"@" + keyColumnList[k].Name + "\", SqlDbType." + keyColumnList[k].Type.ToSqlDbTypeString() + ");");
            }
            int j = 0;

            for (j = 0; j < columnList.Count; j++)
            {
                sp.AppendSpaceLine(2, "parameters[" + j + "].Value = model." + columnList[j].Name + ";");
            }
            for (int k = 0; k < keyColumnList.Count; k++, j++)
            {
                sp.AppendSpaceLine(2, "parameters[" + j + "].Value = model." + keyColumnList[k].Name + ";");
            }
            sp.AppendSpaceLine(2, "return SQLHelper.ExecuteSql(strSql.ToString(), parameters);");
            sp.AppendSpaceLine(1, "}");
            return(sp.ToString());
        }
コード例 #13
0
ファイル: BuilderModelT.cs プロジェクト: yichao0803/Builder
 /// <summary>
 /// ��������Model��
 /// </summary>		
 public string CreatModelMethodT()
 {
     StringPlus strclass = new StringPlus();
     strclass.AppendLine(CreatModelMethod());
     strclass.AppendSpaceLine(2, "private List<" + ModelNameSon + "> _" + ModelNameSon.ToLower() + "s;");//˽�б���
     strclass.AppendSpaceLine(2, "/// <summary>");
     strclass.AppendSpaceLine(2, "/// ���� ");
     strclass.AppendSpaceLine(2, "/// </summary>");
     //strclass.AppendSpaceLine(2, "[Serializable]");
     strclass.AppendSpaceLine(2, "public List<" + ModelNameSon + "> " + ModelNameSon + "s");//����
     strclass.AppendSpaceLine(2, "{");
     strclass.AppendSpaceLine(3, "set{" + " _" + ModelNameSon.ToLower() + "s=value;}");
     strclass.AppendSpaceLine(3, "get{return " + "_" + ModelNameSon.ToLower() + "s;}");
     strclass.AppendSpaceLine(2, "}");
     return strclass.ToString();
 }
コード例 #14
0
        public string GetIDALCode(bool Maxid, bool Exists, bool Add, bool Update, bool Delete, bool GetModel, bool List)
        {
            StringPlus stringPlus = new StringPlus();

            stringPlus.AppendLine("using System;");
            stringPlus.AppendLine("using System.Data;");
            stringPlus.AppendLine("namespace " + this.IDALpath);
            stringPlus.AppendLine("{");
            stringPlus.AppendSpaceLine(1, "/// <summary>");
            stringPlus.AppendSpaceLine(1, "/// 接口层" + this.TableDescription);
            stringPlus.AppendSpaceLine(1, "/// </summary>");
            stringPlus.AppendSpaceLine(1, "public interface " + this.IClass);
            stringPlus.AppendSpaceLine(1, "{");
            stringPlus.AppendSpaceLine(2, "#region  成员方法");
            if (Maxid)
            {
                stringPlus.Append(this.CreatGetMaxID());
            }
            if (Exists)
            {
                stringPlus.Append(this.CreatExists());
            }
            if (Add)
            {
                stringPlus.Append(this.CreatAdd());
            }
            if (Update)
            {
                stringPlus.Append(this.CreatUpdate());
            }
            if (Delete)
            {
                stringPlus.Append(this.CreatDelete());
            }
            if (GetModel)
            {
                stringPlus.Append(this.CreatGetModel());
            }
            if (List)
            {
                stringPlus.Append(this.CreatGetList());
            }
            stringPlus.AppendSpaceLine(2, "#endregion  成员方法");
            stringPlus.AppendSpaceLine(2, "#region  MethodEx");
            stringPlus.AppendLine("");
            stringPlus.AppendSpaceLine(2, "#endregion  MethodEx");
            stringPlus.AppendLine("\t} ");
            stringPlus.AppendLine("}");
            return(stringPlus.ToString());
        }
コード例 #15
0
        /// <summary>
        /// 得到一个库下所有表的存储过程
        /// </summary>
        /// <param name="DbName"></param>
        /// <returns></returns>
        public string GetPROCCode(string dbname)
        {
            dbobj.DbConnectStr = _dbconnectStr;
            DataTable  dt       = dbobj.GetTabViews(dbname);
            StringPlus strclass = new StringPlus();

            if (dt != null)
            {
                foreach (DataRow row in dt.Rows)
                {
                    string tabname = row["name"].ToString();
                    strclass.AppendLine(GetPROCCode(dbname, tabname));
                }
            }
            return(strclass.Value);
        }
コード例 #16
0
        public string GetPROCCode(string dbname)
        {
            this.dbobj.DbConnectStr = this._dbconnectStr;
            DataTable  tabViews   = this.dbobj.GetTabViews(dbname);
            StringPlus stringPlus = new StringPlus();

            if (tabViews != null)
            {
                foreach (DataRow dataRow in tabViews.Rows)
                {
                    string tablename = dataRow["name"].ToString();
                    stringPlus.AppendLine(this.GetPROCCode(dbname, tablename));
                }
            }
            return(stringPlus.Value);
        }
コード例 #17
0
ファイル: BuilderDAL.cs プロジェクト: starseaing/mycodematic
        /// <summary>
        /// 得到Update()的代码
        /// </summary>
        /// <param name="DbName"></param>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <param name="ModelName"></param>
        /// <returns></returns>
        public string CreatUpdate()
        {
            //if (ModelSpace == "")
            //{
            //    ModelSpace = "ModelClassName"; ;
            //}
            StringPlus strclass = new StringPlus();

            strclass.AppendLine("");
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// 更新一条数据");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public void Update(" + ModelSpace + " model)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "Database db = DatabaseFactory.CreateDatabase();");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpaceLine(3, "strSql.Append(\"update " + _tablename + " set \");");
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string Length     = field.Length;
                bool   IsIdentity = field.IsIdentity;
                bool   isPK       = field.IsPK;

                if (field.IsIdentity || field.IsPK || (Keys.Contains(field)))
                {
                    continue;
                }
                if (CodeCommon.IsAddMark(columnType.Trim()))
                {
                    strclass.AppendSpaceLine(3, "strSql.Append(\"" + columnName + "='\"+model." + columnName + "+\"',\");");
                }
                else
                {
                    strclass.AppendSpaceLine(3, "strSql.Append(\"" + columnName + "=\"+model." + columnName + "+\",\");");
                }
            }

            //去掉最后的逗号
            strclass.Remove(strclass.Value.Length - 6, 1);
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + LTP.CodeHelper.CodeCommon.GetModelWhereExpression(Keys) + "\");");
            strclass.AppendSpaceLine(3, "DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());");
            strclass.AppendSpaceLine(3, "db.ExecuteNonQuery(dbCommand);");
            strclass.AppendSpace(2, "}");
            return(strclass.ToString());
        }
コード例 #18
0
        /// <summary>
        /// 生成数据库所有表的创建脚本
        /// </summary>
        /// <returns></returns>
        public string CreateDBTabScript(string dbname)
        {
            dbobj.DbConnectStr = this.DbConnectStr;
            DataTable  dt       = dbobj.GetTables(dbname);
            StringPlus strclass = new StringPlus();

            if (dt != null)
            {
                foreach (DataRow row in dt.Rows)
                {
                    string tabname = row["name"].ToString();

                    strclass.AppendLine(CreateTabScript(dbname, tabname));
                }
            }
            return(strclass.Value);
        }
コード例 #19
0
        /// <summary>
        /// 生成完整Model类
        /// </summary>
        public string CreatModelMethodT()
        {
            StringPlus strclass = new StringPlus();

            strclass.AppendLine(CreatModelMethod());
            strclass.AppendSpaceLine(2, "private List<" + ModelNameSon + "> _" + ModelNameSon.ToLower() + "s;");//私有变量
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// 子类 ");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "[Serializable]");
            strclass.AppendSpaceLine(2, "public List<" + ModelNameSon + "> " + ModelNameSon + "s");//属性
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "set{" + " _" + ModelNameSon.ToLower() + "s=value;}");
            strclass.AppendSpaceLine(3, "get{return " + "_" + ModelNameSon.ToLower() + "s;}");
            strclass.AppendSpaceLine(2, "}");
            return(strclass.ToString());
        }
コード例 #20
0
        public string GetListAspx()
        {
            StringPlus stringPlus = new StringPlus();

            stringPlus.AppendLine();
            foreach (ColumnInfo current in this.Fieldlist)
            {
                string columnName = current.ColumnName;
                string typeName   = current.TypeName;
                string text       = current.Description;
                bool   arg_43_0   = current.IsPrimaryKey;
                bool   isIdentity = current.IsIdentity;
                text = CodeCommon.CutDescText(text, 15, columnName);
                if (!isIdentity && !this.isFilterColume(columnName))
                {
                    string a;
                    if ((a = typeName.Trim().ToLower()) != null && (a == "bit" || a == "dateTime"))
                    {
                        stringPlus.AppendSpaceLine(2, string.Concat(new string[]
                        {
                            "<asp:BoundField DataField=\"",
                            columnName,
                            "\" HeaderText=\"",
                            text,
                            "\" SortExpression=\"",
                            columnName,
                            "\" ItemStyle-HorizontalAlign=\"Center\"  /> "
                        }));
                    }
                    else
                    {
                        stringPlus.AppendSpaceLine(2, string.Concat(new string[]
                        {
                            "<asp:BoundField DataField=\"",
                            columnName,
                            "\" HeaderText=\"",
                            text,
                            "\" SortExpression=\"",
                            columnName,
                            "\" ItemStyle-HorizontalAlign=\"Center\"  /> "
                        }));
                    }
                }
            }
            return(stringPlus.ToString());
        }
コード例 #21
0
        /// <summary>
        /// 得到方法输入参数的列表 (例如:用于Exists  Delete  GetModel 的参数传入)
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public string GetInParameter(List <ColumnInfo> fieldlist, bool output)
        {
            StringPlus strclass = new StringPlus();

            foreach (ColumnInfo field in fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                bool   IsIdentity = field.IsIdentity;
                bool   IsPK       = field.IsPK;
                string Length     = field.Length;
                string Preci      = field.Preci;
                string Scale      = field.Scale;
                string isout      = " ";
                if ((IsIdentity) && (output))
                {
                    isout = " out ";
                }
                switch (columnType.ToLower())
                {
                case "decimal":
                case "numeric":
                    strclass.Append("" + columnName + "_in" + isout + columnType + "(" + Preci + "," + Scale + ")");
                    break;

                case "varchar":
                case "nvarchar":
                case "char":
                case "nchar":
                    strclass.Append("" + columnName + "_in" + isout + columnType + "(" + Length + ")");
                    break;

                default:
                    strclass.Append("" + columnName + "_in" + isout + columnType);
                    break;
                }
                if ((IsIdentity) && (output))
                {
                    continue;
                }
                strclass.AppendLine(",");
            }
            strclass.DelLastComma();
            return(strclass.Value);
        }
コード例 #22
0
        /// <summary>
        /// 增加窗体的html代码
        /// </summary>
        public string GetAddDesigner()
        {
            StringPlus strclass = new StringPlus();

            strclass.AppendLine();
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText     = field.Description;
                bool   ispk       = field.IsPrimaryKey;
                bool   IsIdentity = field.IsIdentity;
                if (IsIdentity)
                {
                    continue;
                }
                if (isFilterColume(columnName))
                {
                    continue;
                }
                if ("uniqueidentifier" == columnType.ToLower())
                {
                    continue;
                }
                switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower())
                {
                case "datetime":
                case "smalldatetime":
                    strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";");
                    break;

                case "bool":
                    strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.CheckBox chk" + columnName + ";");
                    break;

                default:
                    strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";");
                    break;
                }
            }
            //按钮
            strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnSave;");
            strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnCancel;");
            return(strclass.ToString());
        }
コード例 #23
0
ファイル: BuilderDAL.cs プロジェクト: starseaing/mycodematic
        /// <summary>
        /// 得到Delete的代码
        /// </summary>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <returns></returns>
        public string CreatDelete()
        {
            StringPlus strclass = new StringPlus();

            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// 删除一条数据");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public void Delete(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ")");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "int rowsAffected;");

            strclass.AppendLine(GetPreParameter(Keys));

            strclass.AppendSpaceLine(3, "" + DbHelperName + ".RunProcedure(\"" + ProcPrefix + _tablename + "_Delete" + "\",parameters,out rowsAffected);");

            strclass.AppendSpaceLine(2, "}");
            return(strclass.Value);
        }
コード例 #24
0
ファイル: BuilderDAL.cs プロジェクト: starseaing/mycodematic
        /// <summary>
        /// 得到Delete的代码
        /// </summary>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <returns></returns>
        public string CreatDelete()
        {
            StringPlus strclass = new StringPlus();

            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// 删除一条数据");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public void Delete(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ")");
            strclass.AppendSpaceLine(2, "{");

            strclass.AppendSpaceLine(3, "Database db = DatabaseFactory.CreateDatabase();");
            strclass.AppendSpaceLine(3, "DbCommand dbCommand = db.GetStoredProcCommand(\"" + ProcPrefix + _tablename + "_Delete\");");

            strclass.AppendLine(GetPreParameter(Keys));
            strclass.AppendSpaceLine(3, "db.ExecuteNonQuery(dbCommand);");
            strclass.AppendSpaceLine(2, "}");
            return(strclass.Value);
        }
コード例 #25
0
        public string GetWebCode(bool ExistsKey, bool AddForm, bool UpdateForm, bool ShowForm, bool SearchForm)
        {
            StringPlus stringPlus = new StringPlus();

            if (AddForm)
            {
                stringPlus.AppendLine("  /******************************增加窗体代码********************************/");
                stringPlus.AppendLine(this.GetAddAspxCs());
            }
            if (UpdateForm)
            {
                stringPlus.AppendLine("  /******************************修改窗体代码********************************/");
                stringPlus.AppendLine("  /*修改代码-显示 */");
                stringPlus.AppendLine(this.GetUpdateShowAspxCs());
                stringPlus.AppendLine("  /*修改代码-提交更新 */");
                stringPlus.AppendLine(this.GetUpdateAspxCs());
            }
            if (ShowForm)
            {
                stringPlus.AppendLine("  /******************************显示窗体代码********************************/");
                stringPlus.AppendLine(this.GetShowAspxCs());
            }
            return(stringPlus.Value);
        }
コード例 #26
0
        /// <summary>
        /// 生成sql语句中的参数列表(例如:用于Add  Exists  Update Delete  GetModel 的参数传入)
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public string GetPreParameter(List <ColumnInfo> keys)
        {
            StringPlus strclass  = new StringPlus();
            StringPlus strclass2 = new StringPlus();

            strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {");
            int n = 0;

            foreach (ColumnInfo key in keys)
            {
                strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),");
                strclass2.AppendSpaceLine(3, "parameters[" + n.ToString() + "].Value = " + key.ColumnName + ";");
                n++;
            }
            strclass.DelLastComma();
            strclass.AppendLine("};");
            strclass.Append(strclass2.Value);
            return(strclass.Value);
        }
コード例 #27
0
        /// <summary>
        /// 得到GetModel()的代码
        /// </summary>
        /// <param name="DbName"></param>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <param name="ModelName"></param>
        /// <returns></returns>
        public string CreatGetModel()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus strclass = new StringPlus();

            strclass.AppendLine();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// 得到一个对象实体");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public " + ModelSpace + " GetModel(object Id)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, ModelSpace + " model = ExecuteQueryForObject<" + ModelSpace + ">(\"SelectById\", Id);");
            strclass.AppendSpaceLine(3, "return model;");
            strclass.AppendSpaceLine(2, "}");
            return(strclass.ToString());
        }
コード例 #28
0
ファイル: BuilderDAL.cs プロジェクト: zhangxsheng/Codematic
        public string CreatGetModel()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus stringPlus = new StringPlus();

            stringPlus.AppendSpaceLine(2, "/// <summary>");
            stringPlus.AppendSpaceLine(2, "/// " + this.Languagelist["summaryGetModel"].ToString());
            stringPlus.AppendSpaceLine(2, "/// </summary>");
            stringPlus.AppendSpaceLine(2, string.Concat(new string[]
            {
                "public ",
                this.ModelSpace,
                " GetModel(",
                CodeCommon.GetInParameter(this.Keys, true),
                ")"
            }));
            stringPlus.AppendSpaceLine(2, "{");
            stringPlus.AppendLine(CodeCommon.GetPreParameter(this.Keys, true, this.dbobj.DbType));
            stringPlus.AppendSpaceLine(3, this.ModelSpace + " model=new " + this.ModelSpace + "();");
            stringPlus.AppendSpaceLine(3, string.Concat(new string[]
            {
                "DataSet ds= ",
                this.DbHelperName,
                ".RunProcedure(\"",
                this.ProcPrefix,
                this._tablename,
                "_GetModel\",parameters,\"ds\");"
            }));
            stringPlus.AppendSpaceLine(3, "if(ds.Tables[0].Rows.Count>0)");
            stringPlus.AppendSpaceLine(3, "{");
            stringPlus.AppendSpaceLine(4, "return DataRowToModel(ds.Tables[0].Rows[0]);");
            stringPlus.AppendSpaceLine(3, "}");
            stringPlus.AppendSpaceLine(3, "else");
            stringPlus.AppendSpaceLine(3, "{");
            stringPlus.AppendSpaceLine(4, "return null;");
            stringPlus.AppendSpaceLine(3, "}");
            stringPlus.AppendSpaceLine(2, "}");
            return(stringPlus.Value);
        }
コード例 #29
0
        /// <summary>
        /// 得到Exists方法的代码
        /// </summary>
        /// <param name="_tablename"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string CreatExists()
        {
            StringPlus strclass = new StringPlus();

            if (_keys.Count > 0)
            {
                strclass.AppendLine("");
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// 是否存在该记录");
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public bool Exists(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ")");
                strclass.AppendSpaceLine(2, "{");
                strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql.Append(\"select count(1) from " + _tablename + "\");");
                strclass.AppendSpaceLine(3, "strSql.Append(\" where " + LTP.CodeHelper.CodeCommon.GetWhereExpression(Keys) + "\");");
                strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Exists(strSql.ToString());");
                strclass.AppendSpace(2, "}");
            }
            return(strclass.ToString());
        }
コード例 #30
0
        public string CreatGetMaxID()
        {
            StringPlus stringPlus = new StringPlus();

            if (this.Keys.Count > 0)
            {
                foreach (ColumnInfo current in this.Keys)
                {
                    if (CodeCommon.DbTypeToCS(current.TypeName) == "int" && current.IsPrimaryKey)
                    {
                        stringPlus.AppendSpaceLine(2, "/// <summary>");
                        stringPlus.AppendSpaceLine(2, "/// 得到最大ID");
                        stringPlus.AppendSpaceLine(2, "/// </summary>");
                        stringPlus.AppendLine("\t\tint GetMaxId();");
                        break;
                    }
                }
            }
            return(stringPlus.ToString());
        }
コード例 #31
0
        /// <summary>
        /// 得到Exists方法的代码
        /// </summary>
        /// <param name="_tablename"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string CreatExists()
        {
            StringPlus strclass = new StringPlus();

            if (_keys.Count > 0)
            {
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// 是否存在该记录");
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public bool Exists(" + LTP.CodeHelper.CodeCommon.GetInParameter(Keys) + ")");
                strclass.AppendSpaceLine(2, "{");

                strclass.AppendSpaceLine(3, "Database db = DatabaseFactory.CreateDatabase();");
                strclass.AppendSpaceLine(3, "StringBuilder strSql = new StringBuilder();");
                strclass.AppendSpace(3, "strSql.Append(\"select count(1) from " + _tablename);
                strclass.AppendLine(" where " + GetWhereExpression(Keys) + "\");");
                strclass.AppendSpaceLine(3, "DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());");
                strclass.Append(GetPreParameter(Keys));
                strclass.AppendSpaceLine(3, "int cmdresult;");
                strclass.AppendSpaceLine(3, "object obj = db.ExecuteScalar(dbCommand);");

                strclass.AppendSpaceLine(3, "if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "cmdresult = 0;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "else");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "cmdresult = int.Parse(obj.ToString());");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "if (cmdresult == 0)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return false;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "else");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return true;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(2, "}");
            }
            return(strclass.Value);
        }
コード例 #32
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ���б�����html����
        /// </summary>     
        public string GetListAspx()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();

            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;
                deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName);

                if (IsIdentity)
                {
                    continue;
                }

                if (isFilterColume(columnName))
                {
                    continue;
                }

                switch (columnType.Trim().ToLower())
                {
                    case "bit":
                    case "dateTime":
                        strclass.AppendSpaceLine(2, "<asp:BoundField DataField=\"" + columnName + "\" HeaderText=\"" + deText + "\" SortExpression=\"" + columnName + "\" ItemStyle-HorizontalAlign=\"Center\"  /> ");
                        break;
                    default:
                        strclass.AppendSpaceLine(2, "<asp:BoundField DataField=\"" + columnName + "\" HeaderText=\"" + deText + "\" SortExpression=\"" + columnName + "\" ItemStyle-HorizontalAlign=\"Center\"  /> ");
                        break;
                }
            }
            return strclass.ToString();
        }
コード例 #33
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�Update�����Ĵ���
        /// </summary>
        /// <param name="DbName"></param>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <param name="ModelName"></param>
        /// <returns></returns>
        public string CreatUpdate()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus strclass = new StringPlus();
            strclass.AppendLine("");
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryUpdate"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public bool Update(" + ModelSpace + " model)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpaceLine(3, "strSql.Append(\"update " + _tablename + " set \");");
            if (Fieldlist.Count == 0)
            {
                Fieldlist = Keys;
            }
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string Length = field.Length;
                bool IsIdentity = field.IsIdentity;
                bool isPK = field.IsPrimaryKey;
                bool nullable = field.Nullable;

                if (field.IsIdentity || field.IsPrimaryKey || (Keys.Contains(field)))
                {
                    continue;
                }
                if (columnType.ToLower() == "timestamp")
                {
                    continue;
                }
                strclass.AppendSpaceLine(3, "if (model." + columnName + " != null)");
                strclass.AppendSpaceLine(3, "{");

                if ((dbobj.DbType == "Oracle") && (columnType.ToLower() == "date" || columnType.ToLower() == "datetime"))
                {
                    strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "=to_date('\" + model." + columnName + ".ToString() + \"','YYYY-MM-DD HH24:MI:SS'),\");");
                }
                else
                    if (columnType.ToLower() == "bit")
                    {
                        strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "=\"+ (model." + columnName + "? 1 : 0) +\",\");");
                    }
                    else
                        if (CodeCommon.IsAddMark(columnType.Trim()))
                        {
                            strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "='\"+model." + columnName + "+\"',\");");
                        }
                        else
                        {
                            strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "=\"+model." + columnName + "+\",\");");
                        }
                strclass.AppendSpaceLine(3, "}");
                if (nullable)
                {
                    strclass.AppendSpaceLine(3, "else");//��null�����
                    strclass.AppendSpaceLine(3, "{");
                    strclass.AppendSpaceLine(4, "strSql.Append(\"" + columnName + "= null ,\");");
                    strclass.AppendSpaceLine(3, "}");
                }

            }

            //ȥ�����Ķ���

            strclass.AppendSpaceLine(3, "int n = strSql.ToString().LastIndexOf(\",\");");
            strclass.AppendSpaceLine(3, "strSql.Remove(n, 1);");
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetModelWhereExpression(Keys, true) + "\");");
            strclass.AppendSpaceLine(3, "int rowsAffected=" + DbHelperName + ".ExecuteSql(strSql.ToString());");

            strclass.AppendSpaceLine(3, "if (rowsAffected > 0)");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return true;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "else");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return false;");
            strclass.AppendSpaceLine(3, "}");

            strclass.AppendSpace(2, "}");
            return strclass.ToString();
        }
コード例 #34
0
        private string BuilderMethod()
        {
            StringPlus plus = new StringPlus();


            plus.AppendSpaceLine(2, "#region Method");


            //只读
            if (IsView)
            {
                plus.AppendSpaceLine(2, "/// <summary>");
                plus.AppendSpaceLine(2, "/// 是否只读");
                plus.AppendSpaceLine(2, "/// </summary>");
                plus.AppendSpaceLine(2, "public override bool IsReadOnly()");
                plus.AppendSpaceLine(2, "{");
                plus.AppendSpaceLine(3, "return true;");
                plus.AppendSpaceLine(2, "}");
            }

            Model.ColumnInfo identityColumn = Columns.Find(delegate(Model.ColumnInfo col) { return col.IsIdentity; });
            if (null != identityColumn)
            {
                plus.AppendSpaceLine(2, "/// <summary>");
                plus.AppendSpaceLine(2, "/// 获取实体中的标识列");
                plus.AppendSpaceLine(2, "/// </summary>");
                plus.AppendSpaceLine(2, "public override Field GetIdentityField()");
                plus.AppendSpaceLine(2, "{");
                plus.AppendSpaceLine(3, "return _." + identityColumn.ColumnName + ";");
                plus.AppendSpaceLine(2, "}");
            }

            List<Model.ColumnInfo> primarykeyColumns = Columns.FindAll(delegate(Model.ColumnInfo col) { return col.IsPK; });
            if (null != primarykeyColumns && primarykeyColumns.Count > 0)
            {
                plus.AppendSpaceLine(2, "/// <summary>");
                plus.AppendSpaceLine(2, "/// 获取实体中的主键列");
                plus.AppendSpaceLine(2, "/// </summary>");
                plus.AppendSpaceLine(2, "public override Field[] GetPrimaryKeyFields()");
                plus.AppendSpaceLine(2, "{");
                plus.AppendSpaceLine(3, "return new Field[] {");
                StringPlus plus2 = new StringPlus();
                foreach (Model.ColumnInfo col in primarykeyColumns)
                {
                    plus2.AppendSpaceLine(4, "_." + col.ColumnName + ",");
                }
                plus.Append(plus2.ToString().TrimEnd().Substring(0, plus2.ToString().TrimEnd().Length - 1));
                plus.AppendLine("};");
                plus.AppendSpaceLine(2, "}");
            }



            plus.AppendSpaceLine(2, "/// <summary>");
            plus.AppendSpaceLine(2, "/// 获取列信息");
            plus.AppendSpaceLine(2, "/// </summary>");
            plus.AppendSpaceLine(2, "public override Field[] GetFields()");
            plus.AppendSpaceLine(2, "{");
            plus.AppendSpaceLine(3, "return new Field[] {");
            StringPlus plus3 = new StringPlus();
            foreach (ColumnInfo col in Columns)
            {
                plus3.AppendSpaceLine(4, "_." + col.ColumnName + ",");
            }
            plus.Append(plus3.ToString().TrimEnd().Substring(0, plus3.ToString().TrimEnd().Length - 1));
            plus.AppendLine("};");
            plus.AppendSpaceLine(2, "}");


            plus.AppendSpaceLine(2, "/// <summary>");
            plus.AppendSpaceLine(2, "/// 获取值信息");
            plus.AppendSpaceLine(2, "/// </summary>");
            plus.AppendSpaceLine(2, "public override object[] GetValues()");
            plus.AppendSpaceLine(2, "{");
            plus.AppendSpaceLine(3, "return new object[] {");
            StringPlus plus4 = new StringPlus();
            foreach (ColumnInfo col in Columns)
            {
                plus4.AppendSpaceLine(4, "this._" + col.ColumnName + ",");
            }
            plus.Append(plus4.ToString().TrimEnd().Substring(0, plus4.ToString().TrimEnd().Length - 1));
            plus.AppendLine("};");
            plus.AppendSpaceLine(2, "}");

            //2015-08-10注释
            //plus.AppendSpaceLine(2, "/// <summary>");
            //plus.AppendSpaceLine(2, "/// 给当前实体赋值");
            //plus.AppendSpaceLine(2, "/// </summary>");
            //plus.AppendSpaceLine(2, "public override void SetPropertyValues(IDataReader reader)");
            //plus.AppendSpaceLine(2, "{");
            //foreach (ColumnInfo col in Columns)
            //{
            //    plus.AppendSpaceLine(3, "this._" + col.ColumnName + " = DataUtils.ConvertValue<" + col.TypeName + ">(reader[\"" + col.ColumnNameRealName + "\"]);");
            //}
            //plus.AppendSpaceLine(2, "}");


            //2015-08-10注释
            //plus.AppendSpaceLine(2, "/// <summary>");
            //plus.AppendSpaceLine(2, "/// 给当前实体赋值");
            //plus.AppendSpaceLine(2, "/// </summary>");
            //plus.AppendSpaceLine(2, "public override void SetPropertyValues(DataRow row)");
            //plus.AppendSpaceLine(2, "{");
            //foreach (ColumnInfo col in Columns)
            //{
            //    plus.AppendSpaceLine(3, "this._" + col.ColumnName + " = DataUtils.ConvertValue<" + col.TypeName + ">(row[\"" + col.ColumnNameRealName + "\"]);");
            //}
            //plus.AppendSpaceLine(2, "}");


            plus.AppendSpaceLine(2, "#endregion");
            plus.AppendLine();



            plus.AppendSpaceLine(2, "#region _Field");
            plus.AppendSpaceLine(2, "/// <summary>");
            plus.AppendSpaceLine(2, "/// 字段信息");
            plus.AppendSpaceLine(2, "/// </summary>");
            plus.AppendSpaceLine(2, "public class _");
            plus.AppendSpaceLine(2, "{");
            plus.AppendSpaceLine(3, "/// <summary>");
            plus.AppendSpaceLine(3, "/// * ");
            plus.AppendSpaceLine(3, "/// </summary>");
            plus.AppendSpaceLine(3, "public readonly static Field All = new Field(\"*\",\"" + TableName + "\");");
            foreach (ColumnInfo col in Columns)
            {
                plus.AppendSpaceLine(3, "/// <summary>");
                plus.AppendSpaceLine(3, "/// " + col.DeText);
                plus.AppendSpaceLine(3, "/// </summary>");
                plus.AppendSpaceLine(3, "public readonly static Field " + col.ColumnName + " = new Field(\"" + col.ColumnNameRealName + "\",\"" + TableName + "\",\"" + (string.IsNullOrEmpty(col.DeText) ? col.ColumnNameRealName : col.DeText) + "\");");
            }
            plus.AppendSpaceLine(2, "}");
            plus.AppendSpaceLine(2, "#endregion");
            plus.AppendLine();

            return plus.ToString();


        }
コード例 #35
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�GetList()�Ĵ���
        /// </summary>
        public string CreatGetList()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public DataSet GetList(string strWhere)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpace(3, "strSql.Append(\"select ");
            strclass.AppendLine(Fieldstrlist + " \");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableNameParent + " \");");
            strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());");
            strclass.AppendSpaceLine(2, "}");

            if ((dbobj.DbType == "SQL2000") ||
               (dbobj.DbType == "SQL2005") ||
               (dbobj.DbType == "SQL2008") ||
               (dbobj.DbType == "SQL2012"))
            {
                strclass.AppendLine();
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList2"].ToString());
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public DataSet GetList(int Top,string strWhere,string filedOrder)");
                strclass.AppendSpaceLine(2, "{");
                strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql.Append(\"select \");");
                strclass.AppendSpaceLine(3, "if(Top>0)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "strSql.Append(\" top \"+Top.ToString());");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");");
                strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableNameParent + " \");");
                strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "strSql.Append(\" order by \" + filedOrder);");
                strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());");
                strclass.AppendSpaceLine(2, "}");
            }

            return strclass.Value;
        }
コード例 #36
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ��޸Ĵ���Ĵ���
        /// </summary>      
        public string GetUpdateAspxCs()
        {
            StringPlus strclass = new StringPlus();
            StringPlus strclass0 = new StringPlus();
            StringPlus strclass1 = new StringPlus();
            StringPlus strclass2 = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpaceLine(3, "string strErr=\"\";");
            //bool ishasuser = false;
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;

                //���Զ���-�����ֶδ���
                //if (
                //    (columnName.IndexOf("_iCreator") > 0) ||  //ҳ�治��Ҫ��2��
                //    (columnName.IndexOf("_dateCreate") > 0) ||
                //    (columnName.IndexOf("_bValid") > 0) ||
                //    (columnName.IndexOf("_dateValid") > 0) ||
                //    (columnName.IndexOf("_dateExpire") > 0)
                //    )
                //{
                //    continue;
                //}
                //if ((!ishasuser) && (columnName.IndexOf("_iMaintainer") > 0))
                //{
                //    strclass0.AppendSpaceLine(4, "User currentUser;");
                //    strclass0.AppendSpaceLine(3, "if (Session[\"UserInfo\"] != null)");
                //    strclass0.AppendSpaceLine(3, "{");
                //    strclass0.AppendSpaceLine(4, "currentUser = (User)Session[\"UserInfo\"];");
                //    strclass0.AppendSpaceLine(3, "}else{");
                //    strclass0.AppendSpaceLine(4, "return;");
                //    strclass0.AppendSpaceLine(3, "}");
                //    ishasuser = true;
                //}

                deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName);

                //���Զ���-�����ֶδ���
                //if ((columnName.IndexOf("_cLang") > 0) && (columnType.Trim().ToLower() == "varchar"))//���Դ���
                //{
                //    strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistLanguage1.LanguageCode;");
                //    continue;
                //}
                //if (columnName.IndexOf("_iAuthority") > 0)//Ȩ�޽�ɫ����
                //{
                //    strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistPermission1.PermissionID;");
                //    continue;
                //}
                //if (columnName.IndexOf("_cCurrency") > 0)//���Ҵ���
                //{
                //    strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistCurrency1.CurrencyCode;");
                //    continue;
                //}
                //if (columnName.IndexOf("_cCurrencyUnit") > 0)//���Ҵ���
                //{
                //    strclass2.AppendSpaceLine(3, "model." + columnName + "= UCDroplistCurrencyUnit1.CurrencyUnitID;");
                //    continue;
                //}

                switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower())
                {
                    case "int":
                    case "smallint":
                        if ((ispk) || (IsIdentity))
                        {
                            strclass0.AppendSpaceLine(3, "int " + columnName + "=int.Parse(this.lbl" + columnName + ".Text);");
                        }
                        else
                        {
                            strclass0.AppendSpaceLine(3, "int " + columnName + "=int.Parse(this.txt" + columnName + ".Text);");
                            strclass1.AppendSpaceLine(3, "if(!PageValidate.IsNumber(txt" + columnName + ".Text))");
                            strclass1.AppendSpaceLine(3, "{");
                            strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                            strclass1.AppendSpaceLine(3, "}");
                        }
                        break;
                    case "long":
                        if ((ispk) || (IsIdentity))
                        {
                            strclass0.AppendSpaceLine(3, "long " + columnName + "=long.Parse(this.lbl" + columnName + ".Text);");
                        }
                        else
                        {
                            strclass0.AppendSpaceLine(3, "long " + columnName + "=long.Parse(this.txt" + columnName + ".Text);");
                            strclass1.AppendSpaceLine(3, "if(!PageValidate.IsNumber(txt" + columnName + ".Text))");
                            strclass1.AppendSpaceLine(3, "{");
                            strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                            strclass1.AppendSpaceLine(3, "}");
                        }
                        break;
                    case "float":
                    case "numeric":
                    case "decimal":
                        if ((ispk) || (IsIdentity))
                        {
                            strclass0.AppendSpaceLine(3, "decimal " + columnName + "=decimal.Parse(this.lbl" + columnName + ".Text);");
                        }
                        else
                        {
                            strclass0.AppendSpaceLine(3, "decimal " + columnName + "=decimal.Parse(this.txt" + columnName + ".Text);");
                            strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDecimal(txt" + columnName + ".Text))");
                            strclass1.AppendSpaceLine(3, "{");
                            strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                            strclass1.AppendSpaceLine(3, "}");
                        }
                        break;
                    case "datetime":
                    case "smalldatetime":
                        strclass0.AppendSpaceLine(3, "DateTime " + columnName + "=DateTime.Parse(this.txt" + columnName + ".Text);");
                        strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDateTime(txt" + columnName + ".Text))");
                        strclass1.AppendSpaceLine(3, "{");
                        strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                        strclass1.AppendSpaceLine(3, "}");

                        break;
                    case "bool":
                        strclass0.AppendSpaceLine(3, "bool " + columnName + "=this.chk" + columnName + ".Checked;");
                        break;
                    case "byte[]":
                        strclass0.AppendSpaceLine(3, "byte[] " + columnName + "= new UnicodeEncoding().GetBytes(this.txt" + columnName + ".Text);");
                        break;
                    case "guid":
                    case "uniqueidentifier":
                        strclass0.AppendSpaceLine(3, "Guid " + columnName + "= new Guid(this.lbl" + columnName + ".Text);");
                        break;
                    default:
                        if ((ispk) || (IsIdentity))
                        {
                            strclass0.AppendSpaceLine(3, "string " + columnName + "=this.lbl" + columnName + ".Text;");
                        }
                        else
                        {
                            strclass0.AppendSpaceLine(3, "string " + columnName + "=this.txt" + columnName + ".Text;");
                            strclass1.AppendSpaceLine(3, "if(this.txt" + columnName + ".Text.Trim().Length==0)");
                            strclass1.AppendSpaceLine(3, "{");
                            strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "����Ϊ�գ�\\\\n\";	");
                            strclass1.AppendSpaceLine(3, "}");
                        }
                        break;
                }
                strclass2.AppendSpaceLine(3, "model." + columnName + "=" + columnName + ";");

            }
            strclass.AppendLine(strclass1.ToString());
            strclass.AppendSpaceLine(3, "if(strErr!=\"\")");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "MessageBox.Show(this,strErr);");
            strclass.AppendSpaceLine(4, "return;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendLine(strclass0.ToString());
            strclass.AppendLine();
            strclass.AppendSpaceLine(3, ModelSpace + " model=new " + ModelSpace + "();");
            strclass.AppendLine(strclass2.ToString());
            strclass.AppendSpaceLine(3, BLLSpace + " bll=new " + BLLSpace + "();");
            strclass.AppendSpaceLine(3, "bll.Update(model);");
            strclass.AppendSpaceLine(3, "Maticsoft.Common.MessageBox.ShowAndRedirect(this,\"����ɹ���\",\"list.aspx\");");
            return strclass.ToString();
        }
コード例 #37
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ����ʾ����Ĵ���
        /// </summary>       
        public string GetShowAspxCs()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            string key = Key;
            strclass.AppendSpaceLine(1, "private void ShowInfo(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")");
            strclass.AppendSpaceLine(1, "{");
            strclass.AppendSpaceLine(2, BLLSpace + " bll=new " + BLLSpace + "();");
            strclass.AppendSpaceLine(2, ModelSpace + " model=bll.GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetFieldstrlist(Keys, true) + ");");
            //bool ishasuser = false;
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;
                //if ((ispk) || (IsIdentity))
                //{
                //    continue;
                //}

                #region �����ֶδ���
                //���Զ���-�����ֶδ���
                //if (columnName.IndexOf("_iAuthority") > 0)
                //{
                //    continue;
                //}
                //if ((columnName.IndexOf("_cLang") > 0) && (columnType.Trim().ToLower() == "varchar"))//���Դ���
                //{
                //    strclass.AppendSpaceLine(2, "BLL.SysManage.MultiLanguage bllML = new BLL.SysManage.MultiLanguage();");
                //    strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text= bllML.GetLanguageNameByCache(model." + columnName + ");");
                //    continue;
                //}
                //if ((!ishasuser) && ((columnName.IndexOf("_iCreator") > 0) || (columnName.IndexOf("_iMaintainer") > 0)))
                //{
                //    strclass.AppendSpaceLine(2, "Maticsoft.Accounts.Bus.User user = new Maticsoft.Accounts.Bus.User();");
                //    ishasuser = true;
                //}
                //if ((columnName.IndexOf("_iCreator") > 0) || (columnName.IndexOf("_iMaintainer") > 0))
                //{
                //    strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text= user.GetTrueNameByCache(model." + columnName + ");");
                //    ishasuser = true;
                //    continue;
                //}
                #endregion

                switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower())
                {
                    case "int":
                    case "long":
                    case "smallint":
                    case "float":
                    case "numeric":
                    case "decimal":
                    case "datetime":
                    case "smalldatetime":
                        strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();");
                        break;
                    case "bool":
                        strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + "?\"��\":\"��\";");
                        break;
                    case "byte[]":
                        strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();");
                        break;
                    case "guid":
                    case "uniqueidentifier":
                        strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();");
                        break;
                    default:
                        strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ";");
                        break;
                }
            }
            strclass.AppendLine();
            strclass.AppendSpaceLine(1, "}");
            return strclass.ToString();
        }
コード例 #38
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�GetModel()�Ĵ���
        /// </summary>
        public string CreatGetModel()
        {
            //if (ModelSpaceParent == "")
            //{
            //    ModelSpaceParent = "ModelClassName"; ;
            //}
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public " + ModelSpaceParent + " GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(KeysParent, true) + ")");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpaceLine(3, "strSql.Append(\"select " + Fieldstrlist + " from " + _tablenameparent + " \");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + CodeCommon.GetWhereParameterExpression(KeysParent, true, dbobj.DbType) + "\");");

            strclass.AppendLine(CodeCommon.GetPreParameter(KeysParent, true, dbobj.DbType));

            strclass.AppendSpaceLine(3, "" + ModelSpaceParent + " model=new " + ModelSpaceParent + "();");
            strclass.AppendSpaceLine(3, "DataSet ds=" + DbHelperName + ".Query(strSql.ToString(),parameters);");
            strclass.AppendSpaceLine(3, "if(ds.Tables[0].Rows.Count>0)");
            strclass.AppendSpaceLine(3, "{");

            //��������
            strclass.AppendSpaceLine(4, "#region  ������Ϣ");
            foreach (ColumnInfo field in FieldlistParent)
            {

                string columnName = field.ColumnName;
                string columnType = field.TypeName;

                strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null && ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                strclass.AppendSpaceLine(4, "{");
                #region �ֶ�����
                switch (CodeCommon.DbTypeToCS(columnType))
                {
                    case "int":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "long":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "decimal":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "float":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "DateTime":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "string":
                        {
                            strclass.AppendSpaceLine(5, "model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();");
                        }
                        break;
                    case "bool":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "if((ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()==\"1\")||(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString().ToLower()==\"true\"))");
                            strclass.AppendSpaceLine(5, "{");
                            strclass.AppendSpaceLine(6, "model." + columnName + "=true;");
                            strclass.AppendSpaceLine(5, "}");
                            strclass.AppendSpaceLine(5, "else");
                            strclass.AppendSpaceLine(5, "{");
                            strclass.AppendSpaceLine(6, "model." + columnName + "=false;");
                            strclass.AppendSpaceLine(5, "}");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "byte[]":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])ds.Tables[0].Rows[0][\"" + columnName + "\"];");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "Guid":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=new Guid(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    default:
                        strclass.AppendSpaceLine(5, "//model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();");
                        break;
                }
                #endregion
                strclass.AppendSpaceLine(4, "}");
            }
            strclass.AppendSpaceLine(4, "#endregion  ������Ϣend");
            strclass.AppendLine();

            #region �ӱ�����

            strclass.AppendSpaceLine(4, "#region  �ӱ���Ϣ");
            strclass.AppendSpaceLine(4, "StringBuilder strSql2=new StringBuilder();");
            strclass.AppendSpaceLine(4, "strSql2.Append(\"select " + FieldstrlistSon + " from " + _tablenameson + " \");");
            strclass.AppendSpaceLine(4, "strSql2.Append(\" where " +  CodeCommon.GetWhereParameterExpression(KeysSon, true, dbobj.DbType)+ "\");");
            strclass.AppendLine(GetPreParameter(KeysParent, "2"));
            strclass.AppendSpaceLine(4, "DataSet ds2=" + DbHelperName + ".Query(strSql2.ToString(),parameters2);");
            strclass.AppendSpaceLine(4, "if(ds2.Tables[0].Rows.Count>0)");
            strclass.AppendSpaceLine(4, "{");

            strclass.AppendSpaceLine(5, "#region  �ӱ��ֶ���Ϣ");
            strclass.AppendSpaceLine(5, "int i = ds2.Tables[0].Rows.Count;");
            strclass.AppendSpaceLine(5, "List<" + ModelSpaceSon + "> models = new List<" + ModelSpaceSon + ">();");
            strclass.AppendSpaceLine(5, ModelSpaceSon + " modelt;");
            strclass.AppendSpaceLine(5, "for (int n = 0; n < i; n++)");
            strclass.AppendSpaceLine(5, "{");
            strclass.AppendSpaceLine(6, "modelt = new " + ModelSpaceSon + "();");
            foreach (ColumnInfo field in FieldlistSon)
            {

                string columnName = field.ColumnName;
                string columnType = field.TypeName;

                strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"]!=null && ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                strclass.AppendSpaceLine(6, "{");
                #region �ֶ�����
                switch (CodeCommon.DbTypeToCS(columnType))
                {
                    case "int":
                        {
                            //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(6, "{");
                            strclass.AppendSpaceLine(7, "modelt." + columnName + "=int.Parse(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(6, "}");
                        }
                        break;
                    case "decimal":
                        {
                            //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(6, "{");
                            strclass.AppendSpaceLine(7, "modelt." + columnName + "=decimal.Parse(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(6, "}");
                        }
                        break;
                    case "DateTime":
                        {
                            //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(6, "{");
                            strclass.AppendSpaceLine(7, "modelt." + columnName + "=DateTime.Parse(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(6, "}");
                        }
                        break;
                    case "string":
                        {
                            strclass.AppendSpaceLine(7, "modelt." + columnName + "=ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString();");
                        }
                        break;
                    case "bool":
                        {
                            //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(6, "{");
                            strclass.AppendSpaceLine(7, "if((ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()==\"1\")||(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString().ToLower()==\"true\"))");
                            strclass.AppendSpaceLine(7, "{");
                            strclass.AppendSpaceLine(8, "modelt." + columnName + "=true;");
                            strclass.AppendSpaceLine(7, "}");
                            strclass.AppendSpaceLine(7, "else");
                            strclass.AppendSpaceLine(7, "{");
                            strclass.AppendSpaceLine(8, "modelt." + columnName + "=false;");
                            strclass.AppendSpaceLine(7, "}");
                            //strclass.AppendSpaceLine(6, "}");
                        }
                        break;
                    case "byte[]":
                        {
                            //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(6, "{");
                            strclass.AppendSpaceLine(7, "modelt." + columnName + "=(byte[])ds2.Tables[0].Rows[n][\"" + columnName + "\"];");
                            //strclass.AppendSpaceLine(6, "}");
                        }
                        break;
                    case "Guid":
                        {
                            //strclass.AppendSpaceLine(6, "if(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(6, "{");
                            strclass.AppendSpaceLine(7, "modelt." + columnName + "=new Guid(ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(6, "}");
                        }
                        break;
                    default:
                        strclass.AppendSpaceLine(7, "modelt." + columnName + "=ds2.Tables[0].Rows[n][\"" + columnName + "\"].ToString();");
                        break;
                }
                #endregion

                strclass.AppendSpaceLine(6, "}");
            }
            strclass.AppendSpaceLine(6, "models.Add(modelt);");
            strclass.AppendSpaceLine(5, "}");
            strclass.AppendSpaceLine(5, "model." + ModelNameSon + "s = models;");
            strclass.AppendSpaceLine(5, "#endregion  �ӱ��ֶ���Ϣend");

            strclass.AppendSpaceLine(4, "}");

            strclass.AppendSpaceLine(4, "#endregion  �ӱ���Ϣend");
            #endregion

            strclass.AppendLine();
            strclass.AppendSpaceLine(4, "return model;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "else");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return null;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(2, "}");
            return strclass.ToString();
        }
コード例 #39
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
 /// <summary>
 /// �õ�ij�ֶ����ֵ�ķ�������(ֻ��������int�͵����������)
 /// </summary>
 /// <param name="TabName"></param>
 /// <param name="ID"></param>
 /// <returns></returns>
 public string CreatGetMaxID()
 {
     StringPlus strclass = new StringPlus();
     if (_keys.Count > 0)
     {
         string keyname = "";
         foreach (ColumnInfo obj in _keys)
         {
             if (CodeCommon.DbTypeToCS(obj.TypeName) == "int")
             {
                 keyname = obj.ColumnName;
                 if (obj.IsPrimaryKey)
                 {
                     strclass.AppendLine("");
                     strclass.AppendSpaceLine(2, "/// <summary>");
                     strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetMaxId"].ToString());
                     strclass.AppendSpaceLine(2, "/// </summary>");
                     strclass.AppendSpaceLine(2, "public int GetMaxId()");
                     strclass.AppendSpaceLine(2, "{");
                     strclass.AppendSpaceLine(2, "return " + DbHelperName + ".GetMaxID(\"" + keyname + "\", \"" + _tablename + "\"); ");
                     strclass.AppendSpaceLine(2, "}");
                     break;
                 }
             }
         }
     }
     return strclass.ToString();
 }
コード例 #40
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�GetList()�Ĵ���
        /// </summary>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <returns></returns>
        public string CreatGetList()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public DataSet GetList(string strWhere)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpace(3, "strSql.Append(\"select ");
            strclass.AppendLine(Fieldstrlist + " \");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableName + " \");");
            strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());");
            strclass.AppendSpaceLine(2, "}");

            if ((dbobj.DbType == "SQL2000") ||
                (dbobj.DbType == "SQL2005") ||
                (dbobj.DbType == "SQL2008") ||
                (dbobj.DbType == "SQL2012"))
            {
                strclass.AppendLine();
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList2"].ToString());
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public DataSet GetList(int Top,string strWhere,string filedOrder)");
                strclass.AppendSpaceLine(2, "{");
                strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql.Append(\"select \");");
                strclass.AppendSpaceLine(3, "if(Top>0)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "strSql.Append(\" top \"+Top.ToString());");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");");
                strclass.AppendSpaceLine(3, "strSql.Append(\" FROM " + TableName + " \");");
                strclass.AppendSpaceLine(3, "if(strWhere.Trim()!=\"\")");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "strSql.Append(\" where \"+strWhere);");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "strSql.Append(\" order by \" + filedOrder);");
                strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Query(strSql.ToString());");
                strclass.AppendSpaceLine(2, "}");
            }

            //����List<>
            strclass.AppendLine(); // ���峬 2015-10-13
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public List<" + ModelSpace + "> GetModelList(string strWhere)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "DataSet ds = GetList(strWhere);");
            strclass.AppendSpaceLine(3, "return DataTableToList(ds.Tables[0]);");
            strclass.AppendSpaceLine(2, "}");

            //����List<>
            strclass.AppendLine();// ���峬 2015-10-13
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetList"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public List<" + ModelSpace + "> DataTableToList(DataTable dt)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "List<" + ModelSpace + "> modelList = new List<" + ModelSpace + ">();");
            strclass.AppendSpaceLine(3, "int rowsCount = dt.Rows.Count;");
            strclass.AppendSpaceLine(3, "if (rowsCount > 0)");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, ModelSpace + " model;");
            strclass.AppendSpaceLine(4, "for (int n = 0; n < rowsCount; n++)");
            strclass.AppendSpaceLine(4, "{");
            strclass.AppendSpaceLine(5, "model = DataRowToModel(dt.Rows[n]);");
            strclass.AppendSpaceLine(5, "if (model != null)");
            strclass.AppendSpaceLine(5, "{");
            strclass.AppendSpaceLine(6, "modelList.Add(model);");
            strclass.AppendSpaceLine(5, "}");
            strclass.AppendSpaceLine(4, "}");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "return modelList;");
            strclass.AppendSpaceLine(2, "}");

            return strclass.Value;
        }
コード例 #41
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
 /// <summary>
 /// �õ�Exists�����Ĵ���
 /// </summary>
 /// <param name="_tablename"></param>
 /// <param name="ID"></param>
 /// <returns></returns>
 public string CreatExists()
 {
     StringPlus strclass = new StringPlus();
     if (_keys.Count > 0)
     {
         string strInparam = Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, false);
         if (!string.IsNullOrEmpty(strInparam))
         {
             strclass.AppendLine("");
             strclass.AppendSpaceLine(2, "/// <summary>");
             strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryExists"].ToString());
             strclass.AppendSpaceLine(2, "/// </summary>");
             strclass.AppendSpaceLine(2, "public bool Exists(" + strInparam + ")");
             strclass.AppendSpaceLine(2, "{");
             strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
             strclass.AppendSpaceLine(3, "strSql.Append(\"select count(1) from " + _tablename + "\");");
             strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetWhereExpression(Keys, false) + "\");");
             strclass.AppendSpaceLine(3, "return " + DbHelperName + ".Exists(strSql.ToString());");
             strclass.AppendSpace(2, "}");
         }
     }
     return strclass.ToString();
 }
コード例 #42
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�Delete�Ĵ���
        /// </summary>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <returns></returns>
        public string CreatDelete()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine("");
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public bool Delete(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            //if (dbobj.DbType != "OleDb")
            //{
            //    strclass.AppendSpaceLine(3, "strSql.Append(\"delete " + _tablename + " \");" );
            //}
            //else
            //{
            strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");");
            //}
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetWhereExpression(Keys, true) + "\" );");

            strclass.AppendSpaceLine(3, "int rowsAffected=" + DbHelperName + ".ExecuteSql(strSql.ToString());");

            strclass.AppendSpaceLine(3, "if (rowsAffected > 0)");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return true;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "else");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return false;");
            strclass.AppendSpaceLine(3, "}");

            strclass.AppendSpace(2, "}");

            #region �����������ȵ�ɾ��(���б�ʶ�ֶΣ����зDZ�ʶ�����ֶ�)

            if ((Maticsoft.CodeHelper.CodeCommon.HasNoIdentityKey(Keys)) && (Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(Keys) != null))
            {
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString());
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public bool Delete(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, false) + ")");
                strclass.AppendSpaceLine(2, "{");
                strclass.AppendSpaceLine(3, KeysNullTip);
                strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");");
                strclass.AppendSpaceLine(3, "strSql.Append(\" where " + GetWhereExpression(Keys, false) + "\");");
                strclass.AppendLine(GetPreParameter(Keys, false));

                strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString(),parameters);");
                strclass.AppendSpaceLine(3, "if (rows > 0)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return true;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "else");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return false;");
                strclass.AppendSpaceLine(3, "}");

                strclass.AppendSpaceLine(2, "}");
            }

            #endregion

            #region ����ɾ������

            string keyField = "";
            if (Keys.Count == 1)
            {
                keyField = Keys[0].ColumnName;
            }
            else
            {
                foreach (ColumnInfo field in Keys)
                {
                    if (field.IsIdentity)
                    {
                        keyField = field.ColumnName;
                        break;
                    }
                }
            }
            if (keyField.Trim().Length > 0)
            {
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDeletelist"].ToString());
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public bool DeleteList(string " + keyField + "list )");
                strclass.AppendSpaceLine(2, "{");
                strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablename + " \");");
                strclass.AppendSpaceLine(3, "strSql.Append(\" where " + keyField + " in (\"+" + keyField + "list + \")  \");");
                strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString());");
                strclass.AppendSpaceLine(3, "if (rows > 0)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return true;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "else");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return false;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(2, "}");
            }
            #endregion

            return strclass.ToString();
        }
コード例 #43
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// DataRowToModel�Ĵ���
        /// </summary>      
        public string CreatDataRowToModel()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public " + ModelSpace + " DataRowToModel(DataRow row)");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "" + ModelSpace + " model=new " + ModelSpace + "();");

            strclass.AppendSpaceLine(3, "if (row != null)");
            strclass.AppendSpaceLine(3, "{");

            #region �ֶθ�ֵ
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;

                //strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                //strclass.AppendSpaceLine(4, "{");
                #region
                switch (CodeCommon.DbTypeToCS(columnType))
                {
                    case "int":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(row[\"" + columnName + "\"].ToString());");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "long":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(row[\"" + columnName + "\"].ToString());");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "decimal":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(row[\"" + columnName + "\"].ToString());");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "float":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(row[\"" + columnName + "\"].ToString());");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "DateTime":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(row[\"" + columnName + "\"].ToString());");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "string":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null)");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=row[\"" + columnName + "\"].ToString();");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "bool":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "if((row[\"" + columnName + "\"].ToString()==\"1\")||(row[\"" + columnName + "\"].ToString().ToLower()==\"true\"))");
                            strclass.AppendSpaceLine(5, "{");
                            strclass.AppendSpaceLine(6, "model." + columnName + "=true;");
                            strclass.AppendSpaceLine(5, "}");
                            strclass.AppendSpaceLine(5, "else");
                            strclass.AppendSpaceLine(5, "{");
                            strclass.AppendSpaceLine(6, "model." + columnName + "=false;");
                            strclass.AppendSpaceLine(5, "}");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "byte[]":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])row[\"" + columnName + "\"];");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "uniqueidentifier":
                    case "Guid":
                        {
                            strclass.AppendSpaceLine(4, "if(row[\"" + columnName + "\"]!=null && row[\"" + columnName + "\"].ToString()!=\"\")");
                            strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "= new Guid(row[\"" + columnName + "\"].ToString());");
                            strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    default:
                        strclass.AppendSpaceLine(5, "//model." + columnName + "=row[\"" + columnName + "\"].ToString();");
                        break;
                }
                #endregion
                //strclass.AppendSpaceLine(4, "}");
            }
            #endregion

            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "return model;");
            strclass.AppendSpaceLine(2, "}");
            return strclass.ToString();
        }
コード例 #44
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ���б����Ĵ���
        /// </summary>       
        public string GetListAspxCs()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpace(2, BLLSpace + " bll = new " + BLLSpace + "();");

            return strclass.ToString();
        }
コード例 #45
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ����ʾ�����html����
        /// </summary>     
        public string GetShowAspx()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">");
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName);

                strclass.AppendSpaceLine(1, "<tr>");
                strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">");
                strclass.AppendSpaceLine(2, deText);
                strclass.AppendSpaceLine(1, "��</td>");
                strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">");
                switch (columnType.Trim().ToLower())
                {
                    //case "bit":
                    //    strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />" );
                    //    break;
                    default:
                        strclass.AppendSpaceLine(2, "<asp:Label id=\"lbl" + columnName + "\" runat=\"server\"></asp:Label>");
                        break;
                }
                strclass.AppendSpaceLine(1, "</td></tr>");
            }
            strclass.AppendLine("</table>");
            return strclass.ToString();
        }
コード例 #46
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
 /// <summary>
 /// ���ɱ�ʾ��ҳ���CS����
 /// </summary>
 /// <param name="ExistsKey"></param>
 /// <param name="AddForm">�Ƿ��������Ӵ���Ĵ���</param>
 /// <param name="UpdateForm">�Ƿ������޸Ĵ���Ĵ���</param>
 /// <param name="ShowForm">�Ƿ�������ʾ����Ĵ���</param>
 /// <param name="SearchForm">�Ƿ����ɲ�ѯ����Ĵ���</param>
 /// <returns></returns>
 public string GetWebCode(bool ExistsKey, bool AddForm, bool UpdateForm, bool ShowForm, bool SearchForm)
 {
     StringPlus strclass = new StringPlus();
     if (AddForm)
     {
         strclass.AppendLine("  /******************************���Ӵ������********************************/");
         strclass.AppendLine(GetAddAspxCs());
     }
     if (UpdateForm)
     {
         strclass.AppendLine("  /******************************�޸Ĵ������********************************/");
         strclass.AppendLine("  /*�޸Ĵ���-��ʾ */");
         strclass.AppendLine(GetUpdateShowAspxCs());
         strclass.AppendLine("  /*�޸Ĵ���-�ύ���� */");
         strclass.AppendLine(GetUpdateAspxCs());
     }
     if (ShowForm)
     {
         strclass.AppendLine("  /******************************��ʾ�������********************************/");
         strclass.AppendLine(GetShowAspxCs());
     }
     //if (DelForm)
     //{
     //    strclass.Append("  /******************************ɾ���������********************************/");
     //    strclass.Append("");
     //    strclass.Append(CreatDeleteForm());
     //}
     return strclass.Value;
 }
コード例 #47
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ�����Ӵ����html����
        /// </summary>      
        public string GetUpdateAspx()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine("");
            strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">");
            bool hasDate = false;
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;
                deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName);
                if (isFilterColume(columnName))
                {
                    continue;
                }

                if ((ispk) || (IsIdentity) || (columnType.Trim().ToLower() == "uniqueidentifier"))
                {
                    strclass.AppendSpaceLine(1, "<tr>");
                    strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">");
                    strclass.AppendSpaceLine(2, deText);
                    strclass.AppendSpaceLine(1, "��</td>");
                    strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">");
                    strclass.AppendSpaceLine(2, "<asp:label id=\"lbl" + columnName + "\" runat=\"server\"></asp:label>");
                    strclass.AppendSpaceLine(1, "</td></tr>");
                }
                else
                {
                    //
                    strclass.AppendSpaceLine(1, "<tr>");
                    strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">");
                    strclass.AppendSpaceLine(2, deText);
                    strclass.AppendSpaceLine(1, "��</td>");
                    strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">");

                    switch (columnType.Trim().ToLower())
                    {
                        case "datetime":
                        case "smalldatetime":
                            //strclass.AppendSpaceLine(2, "<INPUT onselectstart=\"return false;\" onkeypress=\"return false\" id=\"txt" + columnName + "\" onfocus=\"setday(this)\"");
                            //strclass.AppendSpaceLine(2, " readOnly type=\"text\" size=\"10\" name=\"Text1\" runat=\"server\">");
                            strclass.AppendSpaceLine(2, "<asp:TextBox ID=\"txt" + columnName + "\" runat=\"server\" Width=\"70px\"  onfocus=\"setday(this)\"></asp:TextBox>");
                            hasDate = true;
                            break;
                        case "bit":
                            strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />");
                            break;
                        default:
                            strclass.AppendSpaceLine(2, "<asp:TextBox id=\"txt" + columnName + "\" runat=\"server\" Width=\"200px\"></asp:TextBox>");
                            break;
                    }
                    strclass.AppendSpaceLine(1, "</td></tr>");
                }
            }

            ////��ť
            //strclass.AppendSpaceLine(1, "<tr>");
            //strclass.AppendSpaceLine(1, "<td height=\"25\" colspan=\"2\"><div align=\"center\">");
            //strclass.AppendSpaceLine(2, "<asp:Button ID=\"btnSave\" runat=\"server\" Text=\"�� ���� ��\" OnClick=\"btnSave_Click\" ></asp:Button>");
            ////strclass.AppendSpaceLine(2, "<asp:Button ID=\"btnCancel\" runat=\"server\" Text=\"�� ȡ�� ��\" OnClick=\"btnCancel_Click\" ></asp:Button>");
            //strclass.AppendSpaceLine(1, "</div></td></tr>");
            strclass.AppendLine("</table>");
            if (hasDate)
            {
                strclass.AppendLine("<script src=\"/js/calendar1.js\" type=\"text/javascript\"></script>");
            }
            return strclass.Value;
        }
コード例 #48
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�Delete�Ĵ���
        /// </summary>
        public string CreatDelete()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// ɾ��һ�����ݣ����ӱ������������");
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public bool Delete(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(KeysParent, true) + ")");
            strclass.AppendSpaceLine(2, "{");

            strclass.AppendSpaceLine(3, "List<CommandInfo> sqllist = new List<CommandInfo>();");

            //��
            strclass.AppendSpaceLine(3, "StringBuilder strSql2=new StringBuilder();");
            if (dbobj.DbType != "OleDb")
            {
                strclass.AppendSpaceLine(3, "strSql2.Append(\"delete " + _tablenameson + " \");");
            }
            else
            {
                strclass.AppendSpaceLine(3, "strSql2.Append(\"delete from " + _tablenameson + " \");");
            }
            strclass.AppendSpaceLine(3, "strSql2.Append(\" where " + CodeCommon.GetWhereParameterExpression(KeysSon, true, dbobj.DbType) + "\");");
            strclass.AppendLine(GetPreParameter(KeysSon, "2"));
            strclass.AppendSpaceLine(3, "CommandInfo cmd = new CommandInfo(strSql2.ToString(), parameters2);");
            strclass.AppendSpaceLine(3, "sqllist.Add(cmd);");

            //��
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            if (dbobj.DbType != "OleDb")
            {
                strclass.AppendSpaceLine(3, "strSql.Append(\"delete " + _tablenameparent + " \");");
            }
            else
            {
                strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablenameparent + " \");");
            }
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + CodeCommon.GetWhereParameterExpression(KeysParent, true, dbobj.DbType) + "\");");

            strclass.AppendLine(CodeCommon.GetPreParameter(KeysParent, true, dbobj.DbType));
            strclass.AppendSpaceLine(3, "cmd = new CommandInfo(strSql.ToString(), parameters);");
            strclass.AppendSpaceLine(3, "sqllist.Add(cmd);");

            strclass.AppendSpaceLine(3, "int rowsAffected=" + DbHelperName + ".ExecuteSqlTran(sqllist);");

            strclass.AppendSpaceLine(3, "if (rowsAffected > 0)");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return true;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "else");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return false;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(2, "}");

            #region ����ɾ������

            string keyField = "";
            if (KeysParent.Count == 1)
            {
                keyField = KeysParent[0].ColumnName;
            }
            else
            {
                foreach (ColumnInfo field in KeysParent)
                {
                    if (field.IsIdentity)
                    {
                        keyField = field.ColumnName;
                        break;
                    }
                }
            }
            if (keyField.Trim().Length > 0)
            {
                strclass.AppendSpaceLine(2, "/// <summary>");
                strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryDelete"].ToString());
                strclass.AppendSpaceLine(2, "/// </summary>");
                strclass.AppendSpaceLine(2, "public bool DeleteList(string " + keyField + "list )");
                strclass.AppendSpaceLine(2, "{");
                strclass.AppendSpaceLine(3, "List<string> sqllist = new List<string>();");

                strclass.AppendSpaceLine(3, "StringBuilder strSql2=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql2.Append(\"delete from " + _tablenameson + " \");");
                strclass.AppendSpaceLine(3, "strSql2.Append(\" where " + KeysSon[0].ColumnName + " in (\"+" + keyField + "list + \")  \");");
                strclass.AppendSpaceLine(3, "sqllist.Add(strSql2.ToString());");

                strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
                strclass.AppendSpaceLine(3, "strSql.Append(\"delete from " + _tablenameparent + " \");");
                strclass.AppendSpaceLine(3, "strSql.Append(\" where " + keyField + " in (\"+" + keyField + "list + \")  \");");
                strclass.AppendSpaceLine(3, "sqllist.Add(strSql.ToString());");

                strclass.AppendSpaceLine(3, "int rowsAffected=" + DbHelperName + ".ExecuteSqlTran(sqllist);");
                strclass.AppendSpaceLine(3, "if (rowsAffected > 0)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return true;");
                strclass.AppendSpaceLine(3, "}");
                strclass.AppendSpaceLine(3, "else");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "return false;");
                strclass.AppendSpaceLine(3, "}");

                strclass.AppendSpaceLine(2, "}");
            }
            #endregion

            return strclass.Value;
        }
コード例 #49
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ��޸Ĵ���Ĵ���
        /// </summary>       
        public string GetUpdateShowAspxCs()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            string key = Key;
            strclass.AppendSpaceLine(1, "private void ShowInfo(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")");
            strclass.AppendSpaceLine(1, "{");
            strclass.AppendSpaceLine(2, BLLSpace + " bll=new " + BLLSpace + "();");
            strclass.AppendSpaceLine(2, ModelSpace + " model=bll.GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetFieldstrlist(Keys, true) + ");");
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;

                if (isFilterColume(columnName))
                {
                    continue;
                }

                //���Զ���-�����ֶδ���
                //if ((columnName.IndexOf("_cLang") > 0) && (columnType.Trim().ToLower() == "varchar"))
                //{
                //    strclass.AppendSpaceLine(2, "UCDroplistLanguage1.LanguageCode =model." + columnName + ";");
                //    continue;
                //}
                //if (columnName.IndexOf("_iAuthority") > 0)
                //{
                //    strclass.AppendSpaceLine(2, "UCDroplistPermission1.PermissionID =model." + columnName + ";");
                //    continue;
                //}
                //if (columnName.IndexOf("_cCurrency") > 0)//���Ҵ���
                //{
                //    strclass.AppendSpaceLine(2, "UCDroplistCurrency1.CurrencyCode =model." + columnName + ";");
                //    continue;
                //}
                //if (columnName.IndexOf("_cCurrencyUnit") > 0)//���Ҵ���
                //{
                //    strclass.AppendSpaceLine(2, "UCDroplistCurrencyUnit1.CurrencyUnitID =model." + columnName + ";");
                //    continue;
                //}

                switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower())
                {
                    case "int":
                    case "long":
                    case "smallint":
                    case "float":
                    case "numeric":
                    case "decimal":
                    case "datetime":
                    case "smalldatetime":
                        if ((ispk) || (IsIdentity))
                        {
                            strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();");
                        }
                        else
                        {
                            strclass.AppendSpaceLine(2, "this.txt" + columnName + ".Text=model." + columnName + ".ToString();");
                        }
                        break;
                    case "bool":
                        strclass.AppendSpaceLine(2, "this.chk" + columnName + ".Checked=model." + columnName + ";");
                        break;
                    case "byte[]":
                        strclass.AppendSpaceLine(2, "this.txt" + columnName + ".Text=model." + columnName + ".ToString();");
                        break;
                    case "guid":
                    case "uniqueidentifier":
                        strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ".ToString();");
                        break;
                    default:
                        if ((ispk) || (IsIdentity))
                        {
                            strclass.AppendSpaceLine(2, "this.lbl" + columnName + ".Text=model." + columnName + ";");
                        }
                        else
                        {
                            strclass.AppendSpaceLine(2, "this.txt" + columnName + ".Text=model." + columnName + ";");
                        }
                        break;
                }
            }
            strclass.AppendLine();
            strclass.AppendSpaceLine(1, "}");
            return strclass.Value;
        }
コード例 #50
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
 ///// <summary>
 ///// �õ�Where������� - Parameter��ʽ (���磺����Exists  Delete  GetModel ��where)
 ///// </summary>
 ///// <param name="keys"></param>
 ///// <returns></returns>
 //public string GetWhereExpression(List<ColumnInfo> keys)
 //{
 //    StringPlus strclass = new StringPlus();
 //    foreach (ColumnInfo key in keys)
 //    {
 //        strclass.Append(key.ColumnName + "=" + preParameter + key.ColumnName + " and ");
 //    }
 //    strclass.DelLastChar("and");
 //    return strclass.Value;
 //}
 ///// <summary>
 ///// ����sql����еIJ����б�(���磺����Add  Exists  Update Delete  GetModel �IJ�������)
 ///// </summary>
 ///// <param name="keys"></param>
 ///// <returns></returns>
 //public string GetPreParameter(List<ColumnInfo> keys)
 //{
 //    StringPlus strclass = new StringPlus();
 //    StringPlus strclass2 = new StringPlus();
 //    strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {");
 //    int n = 0;
 //    foreach (ColumnInfo key in keys)
 //    {
 //        strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),");
 //        strclass2.AppendSpaceLine(3, "parameters[" + n.ToString() + "].Value = " + key.ColumnName + ";");
 //        n++;
 //    }
 //    strclass.DelLastComma();
 //    strclass.AppendLine("};");
 //    strclass.Append(strclass2.Value);
 //    return strclass.Value;
 //}
 /// <summary>
 /// ����sql����еIJ����б�(���磺����Add  Exists  Update Delete  GetModel �IJ�������)
 /// </summary>
 /// <param name="keys"></param>
 /// <returns></returns>
 public string GetPreParameter(List<ColumnInfo> keys, string numPara)
 {
     StringPlus strclass = new StringPlus();
     StringPlus strclass2 = new StringPlus();
     strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters" + numPara + " = {");
     int n = 0;
     foreach (ColumnInfo key in keys)
     {
         strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),");
         strclass2.AppendSpaceLine(3, "parameters" + numPara + "[" + n.ToString() + "].Value = " + key.ColumnName + ";");
         n++;
     }
     strclass.DelLastComma();
     strclass.AppendLine("};");
     strclass.Append(strclass2.Value);
     return strclass.Value;
 }
コード例 #51
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
 /// <summary>
 /// ��ɾ��3��ҳ�����
 /// </summary>      
 public string GetWebHtmlCode(bool ExistsKey, bool AddForm, bool UpdateForm, bool ShowForm, bool SearchForm)
 {
     StringPlus strclass = new StringPlus();
     if (AddForm)
     {
         strclass.AppendLine(" <!--******************************����ҳ�����********************************-->");
         strclass.AppendLine(GetAddAspx());
     }
     if (UpdateForm)
     {
         strclass.AppendLine(" <!--******************************�޸�ҳ�����********************************-->");
         strclass.AppendLine(GetUpdateAspx());
     }
     if (ShowForm)
     {
         strclass.AppendLine("  <!--******************************��ʾҳ�����********************************-->");
         strclass.AppendLine(GetShowAspx());
     }
     if (SearchForm)
     {
         strclass.AppendLine("  <!--******************************�б�ҳ�����********************************-->");
         strclass.AppendLine(GetListAspx());
     }
     return strclass.ToString();
 }
コード例 #52
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        public string GetDALCode(bool Maxid, bool Exists, bool Add, bool Update, bool Delete, bool GetModel, bool List)
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine("using System;");
            strclass.AppendLine("using System.Data;");
            strclass.AppendLine("using System.Text;");
            strclass.AppendLine("using System.Collections.Generic;");

            switch (dbobj.DbType)
            {
                case "SQL2005":
                case "SQL2008":
                case "SQL2012":
                    strclass.AppendLine("using System.Data.SqlClient;");
                    break;
                case "SQL2000":
                    strclass.AppendLine("using System.Data.SqlClient;");
                    break;
                case "Oracle":
                    strclass.AppendLine("using System.Data.OracleClient;");
                    break;
                case "MySQL":
                    strclass.AppendLine("using MySql.Data.MySqlClient;");
                    break;
                case "OleDb":
                    strclass.AppendLine("using System.Data.OleDb;");
                    break;
                case "SQLite":
                    strclass.AppendLine("using System.Data.SQLite;");
                    break;
            }
            if (IDALpath != "")
            {
                strclass.AppendLine("using " + IDALpath + ";");
            }
            //  strclass.AppendLine("using Maticsoft.DBUtility;//Please add references");
            // ���峬 2014-10-21 �޸�Ϊ����Ŀ���ݿ⹫����
            strclass.AppendLine("using " + NameSpace + ".DBUtility;");
            strclass.AppendLine("namespace " + DALpath);
            strclass.AppendLine("{");
            strclass.AppendSpaceLine(1, "/// <summary>");
            strclass.AppendSpaceLine(1, "/// " + Languagelist["summary"].ToString() + ":" + DALName);
            strclass.AppendSpaceLine(1, "/// </summary>");
            strclass.AppendSpace(1, "public partial class " + DALName);
            if (IClass != "")
            {
                strclass.Append(":" + IClass);
            }
            strclass.AppendLine("");
            strclass.AppendSpaceLine(1, "{");
            strclass.AppendSpaceLine(2, "public " + DALName + "()");
            strclass.AppendSpaceLine(2, "{}");
            strclass.AppendSpaceLine(2, "#region  Method");

            #region  ��������
            if (Maxid)
            {
                strclass.AppendLine(CreatGetMaxID());
            }
            if (Exists)
            {
                strclass.AppendLine(CreatExists());
            }
            if (Add)
            {
                strclass.AppendLine(CreatAdd());
            }
            if (Update)
            {
                strclass.AppendLine(CreatUpdate());
            }
            if (Delete)
            {
                strclass.AppendLine(CreatDelete());
            }
            if (GetModel)
            {
                strclass.AppendLine(CreatGetModel());
                strclass.AppendLine(CreatDataRowToModel());
            }
            if (List)
            {
                strclass.AppendLine(CreatGetList());
                strclass.AppendLine(CreatGetListByPage());
                strclass.AppendLine(CreatGetListByPageProc());
            }
            #endregion

            strclass.AppendSpaceLine(2, "#endregion  Method");

            //strclass.AppendSpaceLine(2, "#region  MethodEx");
            //strclass.AppendLine("");
            //strclass.AppendSpaceLine(2, "#endregion  MethodEx");

            strclass.AppendSpaceLine(1, "}");
            strclass.AppendLine("}");
            strclass.AppendLine("");

            return strclass.ToString();
        }
コード例 #53
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�Add()�Ĵ���
        /// </summary>        
        public string CreatAdd()
        {
            StringPlus strclass = new StringPlus();
            StringPlus strclass1 = new StringPlus();
            StringPlus strclass2 = new StringPlus();
            StringPlus strclass3 = new StringPlus();
            StringPlus strclass4 = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// ����һ������,�����ӱ�����");
            strclass.AppendSpaceLine(2, "/// </summary>");
            string strretu = "void";
            if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity))
            {
                strretu = "int";
            }
            //��������ͷ
            string strFun = CodeCommon.Space(2) + "public " + strretu + " Add(" + ModelSpaceParent + " model)";
            strclass.AppendLine(strFun);
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpaceLine(3, "strSql.Append(\"insert into " + _tablenameparent + "(\");");
            strclass1.AppendSpace(3, "strSql.Append(\"");
            int n = 0;
            int nkey = 0;
            foreach (ColumnInfo field in FieldlistParent)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                bool IsIdentity = field.IsIdentity;
                string Length = field.Length;
                if (field.IsIdentity)
                {
                    //nkey = n;
                    continue;
                }
                strclass3.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + columnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, columnType, Length) + "),");
                strclass1.Append(columnName + ",");
                strclass2.Append(preParameter + columnName + ",");
                strclass4.AppendSpaceLine(3, "parameters[" + n + "].Value = model." + columnName + ";");
                n++;
            }
            if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005"
                || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity))
            {
                nkey = n;
                strclass3.AppendSpaceLine(5, "new SqlParameter(\"@ReturnValue\",SqlDbType.Int),");
                strclass4.AppendSpaceLine(3, "parameters[" + nkey.ToString() + "].Direction = ParameterDirection.Output;");
            }

            //ȥ�����Ķ���
            strclass1.DelLastComma();
            strclass2.DelLastComma();
            strclass3.DelLastComma();
            strclass1.AppendLine(")\");");
            strclass.Append(strclass1.ToString());
            strclass.AppendSpaceLine(3, "strSql.Append(\" values (\");");
            strclass.AppendSpaceLine(3, "strSql.Append(\"" + strclass2.ToString() + ")\");");
            if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity))
            {
                strclass.AppendSpaceLine(3, "strSql.Append(\";set @ReturnValue= @@IDENTITY\");");
            }
            strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {");
            strclass.Append(strclass3.Value);
            strclass.AppendLine("};");
            strclass.AppendLine(strclass4.Value);

            #region tran
            strclass.AppendSpaceLine(3, "List<CommandInfo> sqllist = new List<CommandInfo>();");
            strclass.AppendSpaceLine(3, "CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);");
            strclass.AppendSpaceLine(3, "sqllist.Add(cmd);");

            strclass.AppendSpaceLine(3, "StringBuilder strSql2;");
            strclass.AppendSpaceLine(3, "foreach (" + ModelSpaceSon + " models in model." + ModelNameSon + "s)");
            strclass.AppendSpaceLine(3, "{");

            StringPlus strclass11 = new StringPlus();
            StringPlus strclass21 = new StringPlus();
            StringPlus strclass31 = new StringPlus();
            StringPlus strclass41 = new StringPlus();
            //�µ�����
            strclass.AppendSpaceLine(4, "strSql2=new StringBuilder();");
            strclass.AppendSpaceLine(4, "strSql2.Append(\"insert into " + _tablenameson + "(\");");
            strclass11.AppendSpace(4, "strSql2.Append(\"");
            int ns = 0;
            foreach (ColumnInfo field in FieldlistSon)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                bool IsIdentity = field.IsIdentity;
                string Length = field.Length;
                if (field.IsIdentity)
                {
                    continue;
                }
                strclass31.AppendSpaceLine(6, "new " + DbParaHead + "Parameter(\"" + preParameter + columnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, columnType, Length) + "),");
                strclass11.Append(columnName + ",");
                strclass21.Append(preParameter + columnName + ",");
                strclass41.AppendSpaceLine(4, "parameters2[" + ns + "].Value = models." + columnName + ";");
                ns++;
            }
            strclass11.DelLastComma();
            strclass21.DelLastComma();
            strclass31.DelLastComma();
            strclass11.AppendLine(")\");");
            strclass.Append(strclass11.ToString());
            strclass.AppendSpaceLine(4, "strSql2.Append(\" values (\");");
            strclass.AppendSpaceLine(4, "strSql2.Append(\"" + strclass21.ToString() + ")\");");
            //if (IsHasIdentity)
            //{
            //    strclass.AppendSpaceLine(4, "strSql2.Append(\";select @@IDENTITY\");");
            //}
            strclass.AppendSpaceLine(4, "" + DbParaHead + "Parameter[] parameters2 = {");
            strclass.Append(strclass31.Value);
            strclass.AppendLine("};");
            strclass.AppendLine(strclass41.Value);
            //end�µ�����

            strclass.AppendSpaceLine(4, "cmd = new CommandInfo(strSql2.ToString(), parameters2);");
            strclass.AppendSpaceLine(4, "sqllist.Add(cmd);");
            strclass.AppendSpaceLine(3, "}");
            #endregion

            //���¶��巽��ͷ
            if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005"
                || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity))
            {
                strclass.AppendSpaceLine(3, DbHelperName + ".ExecuteSqlTranWithIndentity(sqllist);");
                strclass.AppendSpaceLine(3, "return (" + _keyType + ")parameters[" + nkey + "].Value;");
            }
            else
            {
                strclass.AppendSpaceLine(3, "" + DbHelperName + ".ExecuteSqlTran(sqllist);");
            }
            strclass.AppendSpace(2, "}");
            return strclass.ToString();
        }
コード例 #54
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ�����Ӵ����html����
        /// </summary>      
        public string GetAddAspx()
        {
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            strclass.AppendLine("<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">");
            bool hasDate = false;
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;
                if (IsIdentity)
                {
                    continue;
                }

                if (isFilterColume(columnName))
                {
                    continue;
                }
                if (columnType.Trim().ToLower() == "uniqueidentifier")
                {
                    continue;
                }

                deText = CodeHelper.CodeCommon.CutDescText(deText, 15, columnName);

                strclass.AppendSpaceLine(1, "<tr>");
                strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"30%\" align=\"right\">");
                strclass.AppendSpaceLine(2, deText);
                strclass.AppendSpaceLine(1, "��</td>");
                strclass.AppendSpaceLine(1, "<td height=\"25\" width=\"*\" align=\"left\">");

                switch (columnType.Trim().ToLower())
                {
                    case "datetime":
                    case "smalldatetime":
                        strclass.AppendSpaceLine(2, "<asp:TextBox ID=\"txt" + columnName + "\" runat=\"server\" Width=\"70px\"  onfocus=\"setday(this)\"></asp:TextBox>");
                        hasDate = true;
                        break;
                    case "bit":
                        strclass.AppendSpaceLine(2, "<asp:CheckBox ID=\"chk" + columnName + "\" Text=\"" + deText + "\" runat=\"server\" Checked=\"False\" />");
                        break;
                    case "uniqueidentifier":
                        break;
                    default:
                        strclass.AppendSpaceLine(2, "<asp:TextBox id=\"txt" + columnName + "\" runat=\"server\" Width=\"200px\"></asp:TextBox>");
                        break;
                }
                strclass.AppendSpaceLine(1, "</td></tr>");
            }
            strclass.AppendLine("</table>");
            if (hasDate)
            {
                strclass.AppendLine("<script src=\"/js/calendar1.js\" type=\"text/javascript\"></script>");
            }
            return strclass.ToString();
        }
コード例 #55
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ���ʾ�����Ӵ���Ĵ���
        /// </summary>      
        public string GetAddAspxCs()
        {
            StringPlus strclass = new StringPlus();
            StringPlus strclass0 = new StringPlus();
            StringPlus strclass1 = new StringPlus();
            StringPlus strclass2 = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpaceLine(3, "string strErr=\"\";");
            //bool ishasuser = false;
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                string deText = field.Description;
                bool ispk = field.IsPrimaryKey;
                bool IsIdentity = field.IsIdentity;
                if ((IsIdentity))
                {
                    continue;
                }
                if ("uniqueidentifier" == columnType.ToLower())
                {
                    continue;
                }
                //���Զ���-�����ֶδ���
                //if ((!ishasuser) && ((columnName.IndexOf("_iCreator") > 0) || (columnName.IndexOf("_iMaintainer") > 0)))
                //{
                //    strclass0.AppendSpaceLine(3, "User currentUser;");
                //    strclass0.AppendSpaceLine(3, "if (Session[\"UserInfo\"] != null)");
                //    strclass0.AppendSpaceLine(3, "{");
                //    strclass0.AppendSpaceLine(4, "currentUser = (User)Session[\"UserInfo\"];");
                //    strclass0.AppendSpaceLine(3, "}else{");
                //    strclass0.AppendSpaceLine(4, "return;");
                //    strclass0.AppendSpaceLine(3, "}");
                //    ishasuser = true;
                //}

                deText = Maticsoft.CodeHelper.CodeCommon.CutDescText(deText, 15, columnName);

                switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower())
                {
                    case "int":
                    case "smallint":
                       strclass0.AppendSpaceLine(3, "int " + columnName + "=int.Parse(this.txt" + columnName + ".Text);");
                            strclass1.AppendSpaceLine(3, "if(!PageValidate.IsNumber(txt" + columnName + ".Text))");
                            strclass1.AppendSpaceLine(3, "{");
                            strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                            strclass1.AppendSpaceLine(3, "}");
                        break;
                    case "float":
                    case "numeric":
                    case "decimal":
                        strclass0.AppendSpaceLine(3, "decimal " + columnName + "=decimal.Parse(this.txt" + columnName + ".Text);");
                        strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDecimal(txt" + columnName + ".Text))");
                        strclass1.AppendSpaceLine(3, "{");
                        strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                        strclass1.AppendSpaceLine(3, "}");
                        break;
                    case "datetime":
                    case "smalldatetime":
                        strclass0.AppendSpaceLine(3, "DateTime " + columnName + "=DateTime.Parse(this.txt" + columnName + ".Text);");
                        strclass1.AppendSpaceLine(3, "if(!PageValidate.IsDateTime(txt" + columnName + ".Text))");
                        strclass1.AppendSpaceLine(3, "{");
                        strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "��ʽ����\\\\n\";	");
                        strclass1.AppendSpaceLine(3, "}");

                        break;
                    case "bool":
                        strclass0.AppendSpaceLine(3, "bool " + columnName + "=this.chk" + columnName + ".Checked;");
                        break;
                    case "byte[]":
                        strclass0.AppendSpaceLine(3, "byte[] " + columnName + "= new UnicodeEncoding().GetBytes(this.txt" + columnName + ".Text);");
                        break;
                    case "guid":
                    case "uniqueidentifier":
                        break;
                    default:
                        strclass0.AppendSpaceLine(3, "string " + columnName + "=this.txt" + columnName + ".Text;");
                        strclass1.AppendSpaceLine(3, "if(this.txt" + columnName + ".Text.Trim().Length==0)");
                        strclass1.AppendSpaceLine(3, "{");
                        strclass1.AppendSpaceLine(4, "strErr+=\"" + deText + "����Ϊ�գ�\\\\n\";	");
                        strclass1.AppendSpaceLine(3, "}");
                        break;
                }
                strclass2.AppendSpaceLine(3, "model." + columnName + "=" + columnName + ";");
            }
            strclass.AppendLine(strclass1.ToString());
            strclass.AppendSpaceLine(3, "if(strErr!=\"\")");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "MessageBox.Show(this,strErr);");
            strclass.AppendSpaceLine(4, "return;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendLine(strclass0.ToString());
            strclass.AppendSpaceLine(3, ModelSpace + " model=new " + ModelSpace + "();");
            strclass.AppendLine(strclass2.ToString());
            strclass.AppendSpaceLine(3, BLLSpace + " bll=new " + BLLSpace + "();");
            strclass.AppendSpaceLine(3, "bll.Add(model);");
            strclass.AppendSpaceLine(3, NameSpace + ".Common.MessageBox.ShowAndRedirect(this,\"����ɹ���\",\"add.aspx\");");
            return strclass.Value;
        }
コード例 #56
0
ファイル: BuilderWeb.cs プロジェクト: yichao0803/Builder
 /// <summary>
 /// ���Ӵ����html����
 /// </summary>      
 public string GetAddDesigner()
 {
     StringPlus strclass = new StringPlus();
     strclass.AppendLine();
     foreach (ColumnInfo field in Fieldlist)
     {
         string columnName = field.ColumnName;
         string columnType = field.TypeName;
         string deText = field.Description;
         bool ispk = field.IsPrimaryKey;
         bool IsIdentity = field.IsIdentity;
         if (IsIdentity)
         {
             continue;
         }
         if (isFilterColume(columnName))
         {
             continue;
         }
         if ("uniqueidentifier" == columnType.ToLower())
         {
             continue;
         }
         switch (CodeCommon.DbTypeToCS(columnType.Trim().ToLower()).ToLower())
         {
             case "datetime":
             case "smalldatetime":
                 strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";");
                 break;
             case "bool":
                 strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.CheckBox chk" + columnName + ";");
                 break;
             default:
                 strclass.AppendSpaceLine(2, "protected global::System.Web.UI.WebControls.TextBox txt" + columnName + ";");
                 break;
         }
     }
     //��ť
     strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnSave;");
     strclass.AppendSpaceLine(1, "protected global::System.Web.UI.WebControls.Button btnCancel;");
     return strclass.ToString();
 }
コード例 #57
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// ����sql����еIJ����б�(���磺���� Exists  Delete  GetModel ��where������ֵ)
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public string GetPreParameter(List<ColumnInfo> keys, bool IdentityisPrior)
        {
            StringPlus strclass = new StringPlus();
            StringPlus strclass2 = new StringPlus();
            strclass.AppendSpaceLine(3, "" + DbParaHead + "Parameter[] parameters = {");

            ColumnInfo field = Maticsoft.CodeHelper.CodeCommon.GetIdentityKey(keys);
            if ((IdentityisPrior) && (field != null)) //�б�ʶ�ֶ�
            {
                strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + field.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, field.TypeName, "") + ")");
                strclass2.AppendSpaceLine(3, "parameters[0].Value = " + field.ColumnName + ";");
            }
            else
            {
                int n = 0;
                foreach (ColumnInfo key in keys)
                {
                    if (key.IsPrimaryKey)
                    {
                        strclass.AppendSpaceLine(5, "new " + DbParaHead + "Parameter(\"" + preParameter + "" + key.ColumnName + "\", " + DbParaDbType + "." + CodeCommon.DbTypeLength(dbobj.DbType, key.TypeName, "") + "),");
                        strclass2.AppendSpaceLine(3, "parameters[" + n.ToString() + "].Value = " + key.ColumnName + ";");
                        n++;
                    }
                }
                strclass.DelLastComma();
            }
            strclass.AppendLine("};");
            strclass.Append(strclass2.Value);
            return strclass.Value;
        }
コード例 #58
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�GetModel()�Ĵ���
        /// </summary>
        /// <param name="DbName"></param>
        /// <param name="_tablename"></param>
        /// <param name="_key"></param>
        /// <param name="ModelName"></param>
        /// <returns></returns>
        public string CreatGetModel()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus strclass = new StringPlus();
            strclass.AppendLine();
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryGetModel"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            strclass.AppendSpaceLine(2, "public " + ModelSpace + " GetModel(" + Maticsoft.CodeHelper.CodeCommon.GetInParameter(Keys, true) + ")");
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpace(3, "strSql.Append(\"select ");
            if (dbobj.DbType == "SQL2005" || dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012")
            {
                strclass.Append(" top 1 ");
            }
            strclass.AppendLine(" \");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" " + Fieldstrlist + " \");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" from " + _tablename + " \");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" where " + Maticsoft.CodeHelper.CodeCommon.GetWhereExpression(Keys, true) + "\" );");
            strclass.AppendSpaceLine(3, ModelSpace + " model=new " + ModelSpace + "();");
            strclass.AppendSpaceLine(3, "DataSet ds=" + DbHelperName + ".Query(strSql.ToString());");
            strclass.AppendSpaceLine(3, "if(ds.Tables[0].Rows.Count>0)");
            strclass.AppendSpaceLine(3, "{");

            #region
            /*
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;

                strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null && ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                strclass.AppendSpaceLine(4, "{");
                #region
                switch (CodeCommon.DbTypeToCS(columnType))
                {
                    case "int":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=int.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "long":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=long.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "decimal":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=decimal.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "float":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=float.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "DateTime":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=DateTime.Parse(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "string":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"]!=null)");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "bool":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "if((ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()==\"1\")||(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString().ToLower()==\"true\"))");
                            strclass.AppendSpaceLine(5, "{");
                            strclass.AppendSpaceLine(6, "model." + columnName + "=true;");
                            strclass.AppendSpaceLine(5, "}");
                            strclass.AppendSpaceLine(5, "else");
                            strclass.AppendSpaceLine(5, "{");
                            strclass.AppendSpaceLine(6, "model." + columnName + "=false;");
                            strclass.AppendSpaceLine(5, "}");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "byte[]":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=(byte[])ds.Tables[0].Rows[0][\"" + columnName + "\"];");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    case "uniqueidentifier":
                    case "Guid":
                        {
                            //strclass.AppendSpaceLine(4, "if(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString()!=\"\")");
                            //strclass.AppendSpaceLine(4, "{");
                            strclass.AppendSpaceLine(5, "model." + columnName + "=new Guid(ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString());");
                            //strclass.AppendSpaceLine(4, "}");
                        }
                        break;
                    default:
                        strclass.AppendSpaceLine(5, "//model." + columnName + "=ds.Tables[0].Rows[0][\"" + columnName + "\"].ToString();");
                        break;
                }
                #endregion
                strclass.AppendSpaceLine(4, "}");

            }
            */
            #endregion

            strclass.AppendSpaceLine(4, "return DataRowToModel(ds.Tables[0].Rows[0]);");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpaceLine(3, "else");
            strclass.AppendSpaceLine(3, "{");
            strclass.AppendSpaceLine(4, "return null;");
            strclass.AppendSpaceLine(3, "}");
            strclass.AppendSpace(2, "}");
            return strclass.ToString();
        }
コード例 #59
0
        public string Builder()
        {
            Columns = DbToCS.DbtoCSColumns(Columns);

            StringPlus plus = new StringPlus();
            plus.AppendLine("//------------------------------------------------------------------------------");
            plus.AppendLine("// <auto-generated>");
            plus.AppendLine("//     此代码由工具生成。");
            plus.AppendLine("//     运行时版本:" + Environment.Version.ToString());
            plus.AppendLine("//     Support: http://www.cnblogs.com/huxj");
            plus.AppendLine("//     Website: http://ITdos.com/Dos/ORM/Index.html");
            plus.AppendLine("//     对此文件的更改可能会导致不正确的行为,并且如果");
            plus.AppendLine("//     重新生成代码,这些更改将会丢失。");
            plus.AppendLine("// </auto-generated>");
            plus.AppendLine("//------------------------------------------------------------------------------");
            plus.AppendLine();
            plus.AppendLine();
            plus.AppendLine("using System;");
            plus.AppendLine("using System.Data;");
            plus.AppendLine("using System.Data.Common;");
            plus.AppendLine("using Dos.ORM;");
            plus.AppendLine("using Dos.ORM.Common;");
            plus.AppendLine();
            plus.AppendLine("namespace " + NameSpace);
            plus.AppendLine("{");
            plus.AppendLine();
            plus.AppendSpaceLine(1, "/// <summary>");
            plus.AppendSpaceLine(1, "/// 实体类" + ClassName + " 。(属性说明自动提取数据库字段的描述信息)");
            plus.AppendSpaceLine(1, "/// </summary>");
            plus.AppendSpaceLine(1, "[Serializable]");
            plus.AppendSpaceLine(1, "public partial class " + ClassName + " : Entity ");
            plus.AppendSpaceLine(1, "{");
            plus.AppendSpaceLine(2, "public " + ClassName + "():base(\"" + TableName + "\") {}");
            plus.AppendLine();
            plus.AppendLine(BuilderModel());
            plus.AppendLine(BuilderMethod());
            plus.AppendSpaceLine(1, "}");
            plus.AppendLine("}");
            plus.AppendLine("");
            return plus.ToString();
        }
コード例 #60
0
ファイル: BuilderDAL.cs プロジェクト: yichao0803/Builder
        /// <summary>
        /// �õ�Add()�Ĵ���
        /// </summary>        
        public string CreatAdd()
        {
            if (ModelSpace == "")
            {
                //ModelSpace = "ModelClassName"; ;
            }
            StringPlus strclass = new StringPlus();
            strclass.AppendLine("");
            strclass.AppendSpaceLine(2, "/// <summary>");
            strclass.AppendSpaceLine(2, "/// " + Languagelist["summaryadd"].ToString());
            strclass.AppendSpaceLine(2, "/// </summary>");
            string strretu = "bool";
            if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005" ||
                dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012" || dbobj.DbType == "SQLite") && (IsHasIdentity))
            {
                strretu = "int";
                if (_IdentityKeyType != "int")
                {
                    strretu = _IdentityKeyType;
                }
            }
            //if (dbobj.DbType == "OleDb" && IsHasIdentity)
            //{
            //    strretu = "bool";
            //}

            //��������ͷ
            string strFun = CodeCommon.Space(2) + "public " + strretu + " Add(" + ModelSpace + " model)";
            strclass.AppendLine(strFun);
            strclass.AppendSpaceLine(2, "{");
            strclass.AppendSpaceLine(3, "StringBuilder strSql=new StringBuilder();");
            strclass.AppendSpaceLine(3, "StringBuilder strSql1=new StringBuilder();");
            strclass.AppendSpaceLine(3, "StringBuilder strSql2=new StringBuilder();");
            foreach (ColumnInfo field in Fieldlist)
            {
                string columnName = field.ColumnName;
                string columnType = field.TypeName;
                bool IsIdentity = field.IsIdentity;

                if (IsIdentity)
                {
                    continue;
                }
                strclass.AppendSpaceLine(3, "if (model." + columnName + " != null)");
                strclass.AppendSpaceLine(3, "{");
                strclass.AppendSpaceLine(4, "strSql1.Append(\"" + columnName + ",\");");
                if ((dbobj.DbType == "Oracle") && (columnType.ToLower() == "date" || columnType.ToLower() == "datetime"))
                {
                    strclass.AppendSpaceLine(4, "strSql2.Append(\"to_date('\" + model." + columnName + ".ToString() + \"','YYYY-MM-DD HH24:MI:SS'),\");");
                }
                else
                    if (columnType.ToLower() == "bit")
                    {
                        strclass.AppendSpaceLine(4, "strSql2.Append(\"\"+(model." + columnName + "? 1 : 0) +\",\");");
                    }
                    else
                        if ("uniqueidentifier" == columnType.ToLower())
                        {
                            strclass.AppendSpaceLine(4, "strSql2.Append(\"'\"+ Guid.NewGuid().ToString() +\"',\");");
                        }
                        else
                            if (CodeCommon.IsAddMark(columnType.Trim()))
                            {
                                strclass.AppendSpaceLine(4, "strSql2.Append(\"'\"+model." + columnName + "+\"',\");");
                            }
                            else
                            {
                                strclass.AppendSpaceLine(4, "strSql2.Append(\"\"+model." + columnName + "+\",\");");
                            }

                strclass.AppendSpaceLine(3, "}");
            }
            strclass.AppendSpaceLine(3, "strSql.Append(\"insert into " + TableName + "(\");");
            strclass.AppendSpaceLine(3, "strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));");
            strclass.AppendSpaceLine(3, "strSql.Append(\")\");");
            strclass.AppendSpaceLine(3, "strSql.Append(\" values (\");");
            strclass.AppendSpaceLine(3, "strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));");
            strclass.AppendSpaceLine(3, "strSql.Append(\")\");");

            if (strretu == "void")
            {
                strclass.AppendSpaceLine(3, "" + DbHelperName + ".ExecuteSql(strSql.ToString());");
            }
            else
                if (strretu == "bool")
                {
                    strclass.AppendSpaceLine(3, "int rows=" + DbHelperName + ".ExecuteSql(strSql.ToString());");
                    strclass.AppendSpaceLine(3, "if (rows > 0)");
                    strclass.AppendSpaceLine(3, "{");
                    strclass.AppendSpaceLine(4, "return true;");
                    strclass.AppendSpaceLine(3, "}");
                    strclass.AppendSpaceLine(3, "else");
                    strclass.AppendSpaceLine(3, "{");
                    strclass.AppendSpaceLine(4, "return false;");
                    strclass.AppendSpaceLine(3, "}");
                }
                else//�����Զ�������ֵ
                {
                    if ((dbobj.DbType == "SQL2000" || dbobj.DbType == "SQL2005"
                        || dbobj.DbType == "SQL2008" || dbobj.DbType == "SQL2012") && (IsHasIdentity))
                    {
                        strclass.AppendSpaceLine(3, "strSql.Append(\";select @@IDENTITY\");");
                    }
                    if ((dbobj.DbType == "SQLite") && (IsHasIdentity))
                    {
                        strclass.AppendSpaceLine(3, "strSql.Append(\";select LAST_INSERT_ROWID()\");");
                    }
                    strclass.AppendSpaceLine(3, "object obj = " + DbHelperName + ".GetSingle(strSql.ToString());");
                    strclass.AppendSpaceLine(3, "if (obj == null)");
                    strclass.AppendSpaceLine(3, "{");
                    strclass.AppendSpaceLine(4, "return 0;");
                    strclass.AppendSpaceLine(3, "}");
                    strclass.AppendSpaceLine(3, "else");
                    strclass.AppendSpaceLine(3, "{");
                    switch (strretu)
                    {
                        case "int":
                            strclass.AppendSpaceLine(4, "return Convert.ToInt32(obj);");
                            break;
                        case "long":
                            strclass.AppendSpaceLine(4, "return Convert.ToInt64(obj);");
                            break;
                        case "decimal":
                            strclass.AppendSpaceLine(4, "return Convert.ToDecimal(obj);");
                            break;
                    }
                    strclass.AppendSpaceLine(3, "}");
                }
            strclass.AppendSpace(2, "}");
            return strclass.ToString();
        }