コード例 #1
0
ファイル: CodeCommon.cs プロジェクト: xiaopohou/CodeGenerator
        public static string GetPreParameter(List <ColumnInfo> keys, bool IdentityisPrior, string DbType)
        {
            StringPlus stringPlus1 = new StringPlus();
            StringPlus stringPlus2 = new StringPlus();

            stringPlus1.AppendSpaceLine(3, CodeCommon.DbParaHead(DbType) + "Parameter[] parameters = {");
            ColumnInfo identityKey = CodeCommon.GetIdentityKey(keys);
            bool       flag        = CodeCommon.HasNoIdentityKey(keys);

            if (IdentityisPrior && identityKey != null || !flag && identityKey != null)
            {
                stringPlus1.AppendSpaceLine(5, "new " + CodeCommon.DbParaHead(DbType) + "Parameter(\"" + CodeCommon.preParameter(DbType) + identityKey.ColumnName + "\", " + CodeCommon.DbParaDbType(DbType) + "." + CodeCommon.DbTypeLength(DbType, identityKey.TypeName, "") + ")");
                stringPlus2.AppendSpaceLine(3, "parameters[0].Value = " + identityKey.ColumnName + ";");
            }
            else
            {
                int num = 0;
                foreach (ColumnInfo columnInfo in keys)
                {
                    if (columnInfo.IsPrimaryKey || !columnInfo.IsIdentity)
                    {
                        stringPlus1.AppendSpaceLine(5, "new " + CodeCommon.DbParaHead(DbType) + "Parameter(\"" + CodeCommon.preParameter(DbType) + columnInfo.ColumnName + "\", " + CodeCommon.DbParaDbType(DbType) + "." + CodeCommon.DbTypeLength(DbType, columnInfo.TypeName, columnInfo.Length) + "),");
                        stringPlus2.AppendSpaceLine(3, "parameters[" + num.ToString() + "].Value = " + columnInfo.ColumnName + ";");
                        ++num;
                    }
                }
                stringPlus1.DelLastComma();
            }
            stringPlus1.AppendSpaceLine(3, "};");
            stringPlus1.Append(stringPlus2.Value);
            return(stringPlus1.Value);
        }
コード例 #2
0
ファイル: CodeCommon.cs プロジェクト: xiaopohou/CodeGenerator
        public static string GetWhereParameterExpression(List <ColumnInfo> keys, bool IdentityisPrior, string DbType)
        {
            StringPlus stringPlus  = new StringPlus();
            ColumnInfo identityKey = CodeCommon.GetIdentityKey(keys);
            bool       flag        = CodeCommon.HasNoIdentityKey(keys);

            if (IdentityisPrior && identityKey != null || !flag && identityKey != null)
            {
                stringPlus.Append(identityKey.ColumnName + "=" + CodeCommon.preParameter(DbType) + identityKey.ColumnName);
            }
            else
            {
                foreach (ColumnInfo columnInfo in keys)
                {
                    if (columnInfo.IsPrimaryKey || !columnInfo.IsIdentity)
                    {
                        stringPlus.Append(columnInfo.ColumnName + "=" + CodeCommon.preParameter(DbType) + columnInfo.ColumnName + " and ");
                    }
                }
                stringPlus.DelLastChar("and");
            }
            return(stringPlus.Value);
        }