Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command"/> class.
        /// </summary>
        /// <param name="commandName">The command name used for retreiving command in Xaml.</param>
        public Command(string commandName)
        {
            if (CommandCache.ContainsKey(commandName))
            {
                throw new ArgumentException("A command with the same name '{0}' is already registered.", commandName);
            }

            Name = commandName;
            CommandCache.Add(commandName, this);
        }
        public override ICommand CreateUpdateByIdCommand(object data, Type type)
        {
            string uniqueId = "80065C07-24CD-40E8-9642-A46085892480";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName)))
            {
                Command sqlCommand = _CreateUpdateByIdCommand(data, type);
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]);
        }
        public override ICommand CreateUpdateByKeyCommand(object data, Type type)
        {
            string uniqueId = "34FD7357-8114-4f36-825E-77C3F819B39F";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName)))
            {
                Command sqlCommand = _CreateUpdateByKeyCommand(data, type);
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Command"/> class.
        /// </summary>
        /// <param name="commandName">The command name used for retreiving command in Xaml.</param>
        public Command(string commandName)
        {
            if (CommandCache.ContainsKey(commandName))
            {
                // Not throwing exception to prevent error in blend
                return;
                //throw new ArgumentException(Resource.CommandNameAlreadyRegistered, commandName);
            }

            Name = commandName;
            CommandCache.Add(commandName, this);
        }
        public override ICommand CreateCountCommand <T>()
        {
            Type   typeT    = typeof(T);
            string uniqueId = "1801F51F-A4EC-4A78-8AE8-BCB30402E4B5";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT);
                Command sqlCommand = (Command)CreateCountCommand(schemaTable.ViewSource);
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]);
        }
        public override ICommand CreateDeleteByKeyCommand(object data, Type type)
        {
            string uniqueId = "92C92A43-D467-4931-8C12-F26AA936E7D7";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(type);

                Command sqlCommand = _CreateDeletebyKeyCommand(data, schemaTable);
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]);
        }
        public override ICommand CreateDeleteByIdCommand(object data, Type type)
        {
            string uniqueId = "F58B3FAE-6E43-4B39-9850-8E2D4EC63419";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, type.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(type);

                Command sqlCommand = _CreateDeletebyIdCommand(data, schemaTable);
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, type.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, type.FullName)]);
        }
        public override ICommand CreateGetListCommand <T>(IFilterCriteria criteria)
        {
            Type   typeT    = typeof(T);
            string uniqueId = "232FDED0-6C97-40B4-930F-FC190124D181";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT);

                Command sqlCommand = new Command();

                sqlCommand.SqlCommand.CommandText = string.Format(
                    "{0} {1} {2} {3}",
                    SELECT, SelectColumnsStatement(typeT), FROM, schemaTable.ViewSource
                    );
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]);
        }
        public override ICommand CreateGetObjectByKeyCommand <T>()
        {
            Type   typeT    = typeof(T);
            string uniqueId = "4F9C6FBE-2971-46A8-A367-B28AB5F65895";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT);

                Command sqlCommand = new Command();

                var keyList = from column in schemaTable where column.IsPrimaryKey select column;

                if (keyList.Count() < 1)
                {
                    throw new TypeNoKeyException(typeof(T));
                }

                StringBuilder paramBuilder = new StringBuilder();
                foreach (Anito.Data.Schema.TypeColumn column in keyList)
                {
                    if (paramBuilder.Length > 0)
                    {
                        paramBuilder.Append(string.Format("{0}{1}{2}", SPACE, AND, SPACE));
                    }
                    paramBuilder.Append(string.Format("{0} = {1}{2}", column.Name, PARAM_IDENTIFIER, column.Name));
                    sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name));
                }

                sqlCommand.SqlCommand.CommandText =
                    string.Format("{0} {1} {2} {3} {4} {5}",
                                  SELECT, SelectColumnsStatement(typeT), FROM, schemaTable.ViewSource, WHERE, paramBuilder.ToString());
                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]);
        }
        public override ICommand CreateInsertCommand(object data)
        {
            Type   typeT    = data.GetType();
            string uniqueId = "26ABBE10-3D2A-40be-ABAC-F92EF9040608";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT);

                Command sqlCommand = new Command();

                StringBuilder commandTextBuilder = new StringBuilder();
                StringBuilder paramBuilder       = new StringBuilder();
                StringBuilder columnBuilder      = new StringBuilder();

                TypeColumn identityColumn = null;
                foreach (TypeColumn column in (from col in schemaTable where !col.ViewOnly select col))
                {
                    if (column.IsIdentity)
                    {
                        identityColumn = column;
                        continue;
                    }

                    if (sqlCommand.Parameters.ContainsKey(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name)))
                    {
                        continue;
                    }

                    if (columnBuilder.Length > 0 && paramBuilder.Length > 0)
                    {
                        columnBuilder.Append(COMMA);
                        paramBuilder.Append(COMMA);
                    }
                    columnBuilder.Append(column.Name);
                    paramBuilder.Append(PARAM_IDENTIFIER + column.Name);
                    if (!sqlCommand.Parameters.ContainsKey(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name)))
                    {
                        sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, column.Name));
                    }
                }
                commandTextBuilder.Append(string.Format("{0} {1} {2}",
                                                        INSERT, INTO, schemaTable.UpdateSource));
                commandTextBuilder.Append(OPEN_PARENTHESES);
                commandTextBuilder.Append(columnBuilder.ToString());
                commandTextBuilder.Append(CLOSE_PARENTHESES);
                commandTextBuilder.Append(SPACE);
                commandTextBuilder.Append(VALUES + OPEN_PARENTHESES);
                commandTextBuilder.Append(paramBuilder.ToString());
                commandTextBuilder.Append(CLOSE_PARENTHESES + SEMI_COLON);

                if (identityColumn != null)
                {
                    commandTextBuilder.Append(string.Format("SELECT {0} FROM {1} WHERE {2} = (SELECT IDENT_CURRENT('{3}'));"
                                                            , schemaTable.ColumnList
                                                            , schemaTable.ViewSource
                                                            , identityColumn.Name
                                                            , schemaTable.ViewSource));
                }

                sqlCommand.SqlCommand.CommandText = commandTextBuilder.ToString();

                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]);
        }
        public override ICommand CreateGetListByPageCommand <T>()
        {
            Type   typeT    = typeof(T);
            string uniqueId = "D89646AE-F93B-4D59-9A0C-7AF5A6B79F5D";

            if (!CommandCache.ContainsKey(string.Format(CACHE_KEY, uniqueId, typeT.FullName)))
            {
                Anito.Data.Schema.TypeTable schemaTable = Provider.GetSchema(typeT);

                Command sqlCommand = new Command();

                string tempTable = SHARP + "D89646AE" + schemaTable.ViewSource;

                StringBuilder columnBuilder     = new StringBuilder();
                StringBuilder keyBuilder        = new StringBuilder();
                StringBuilder keyCompareBuilder = new StringBuilder();

                foreach (Anito.Data.Schema.TypeColumn column in schemaTable)
                {
                    if (columnBuilder.Length > 0)
                    {
                        columnBuilder.Append(COMMA + SPACE);
                    }
                    columnBuilder.Append(schemaTable.ViewSource + DOT + column.Name);

                    if (column.IsPrimaryKey)
                    {
                        if (keyBuilder.Length > 0)
                        {
                            keyBuilder.Append(COMMA + SPACE);
                        }
                        keyBuilder.Append(column.Name);

                        if (keyCompareBuilder.Length > 0)
                        {
                            keyCompareBuilder.Append(SPACE + AND + SPACE);
                        }
                        keyCompareBuilder.Append(tempTable + DOT + column.Name);
                        keyCompareBuilder.Append(SPACE + EQUALS + SPACE);
                        keyCompareBuilder.Append(schemaTable.ViewSource + DOT + column.Name);
                    }
                }

                sqlCommand.SqlCommand.CommandText = string.Format(GET_TABLE_BY_PAGE,
                                                                  tempTable,
                                                                  tempTable,
                                                                  keyBuilder.ToString(),
                                                                  keyBuilder.ToString(),
                                                                  tempTable,
                                                                  schemaTable.ViewSource,
                                                                  SelectColumnsStatement(typeT),
                                                                  schemaTable.ViewSource,
                                                                  tempTable,
                                                                  keyCompareBuilder.ToString(),
                                                                  tempTable,
                                                                  tempTable);

                sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, PAGE));
                sqlCommand.AddParam(string.Format("{0}{1}", PARAM_IDENTIFIER, PAGE_SIZE));

                CommandCache.Add(string.Format(CACHE_KEY, uniqueId, typeT.FullName), sqlCommand);
            }
            return(CommandCache[string.Format(CACHE_KEY, uniqueId, typeT.FullName)]);
        }