示例#1
0
        /// <summary>
        /// Adds an Non-Unicode variable character parameter to the procedure.
        /// Strings longer than SqlUtility.MAX_VARCHAR_LENGTH and the length argument are truncated to fit.
        /// </summary>
        /// <param name="name">The name of the parameter to add.</param>
        /// <param name="value">The value of the parameter to add.</param>
        /// <param name="length">The length of the variable character parameter.</param>
        /// <param name="direction">The direction of the parameter. Use one of the class parameter constants. Defaults to IN.</param>
        /// <returns>True if the parameter is added, false otherwise.</returns>
        public override bool AddVarCharParameter(string name, string value, int length, ParameterType direction)
        {
            // Truncate the string value if necessary.
            if (!string.IsNullOrWhiteSpace(value) && length != MAX_VARCHAR_SIZE)
            {
                MSSqlUtility utility = new MSSqlUtility();
                if (value.Length > utility.MAX_VARCHAR_LENGTH)
                {
                    value = value.Substring(0, utility.MAX_VARCHAR_LENGTH);
                }
            }

            // Check whether to return a MAX sized parameter.
            if (length != MAX_VARCHAR_SIZE)
            {
                // The parameter fits the requirements for a normal nvarchar parameter.
                // Set the size of the parameter to the length of the string because each
                // ANSI character is 1 byte long.
                return(AddParameter(name, value, DbType.String, typeof(SqlParameter), direction, length));
            }
            else
            {
                // The parameter is too large for a normal nvarchar parameter.
                // Create a MAX sized parameter and set the size to the special value associated with max sized parameters.
                return(AddParameter(name, value, DbType.String, typeof(SqlParameter), direction, MAX_VARCHAR_SIZE));
            }
        }
示例#2
0
        /// <summary>
        /// Adds an Unicode fixed length character parameter to the procedure.
        /// Strings longer than SqlUtility.MAX_NCHAR_LENGTH and the length argument are truncated to fit.
        /// </summary>
        /// <param name="name">The name of the parameter to add.</param>
        /// <param name="value">The value of the parameter to add.</param>
        /// <param name="length">The length of the fixed length character parameter.</param>
        /// <param name="direction">The direction of the parameter. Use one of the class parameter constants. Defaults to IN.</param>
        /// <returns>True if the parameter is added, false otherwise.</returns>
        public override bool AddNCharParameter(string name, string value, int length, ParameterType direction)
        {
            // Truncate the string value if necessary.
            if (!string.IsNullOrWhiteSpace(value))
            {
                MSSqlUtility utility = new MSSqlUtility();
                if (value.Length > utility.MAX_NCHAR_LENGTH)
                {
                    value = value.Substring(0, utility.MAX_NCHAR_LENGTH);
                }
            }

            // Set the size of the parameter to twice the length of the string because each
            // Unicode character is 2 bytes long.
            return(AddParameter(name, value, DbType.String, typeof(SqlParameter), direction, length * 2));
        }
示例#3
0
        void DatabaseRead()
        {
            // Create a utility to handle the SQL calls for this action.
            MSSqlUtility sqlUtil = new MSSqlUtility();

            //Create an empty row list to be used as the all cards holder
            List<SqlRow> allCardsRows = new List<SqlRow>();

            //Create an empty row list to be used as the all factions holder
            List<SqlRow> allFactionsRows = new List<SqlRow>();

            //Create an empty row list to be used as the all leaders holder
            List<SqlRow> allLeadersRows = new List<SqlRow>();
            try
            {

                allCardsRows = sqlUtil.ExecuteQuery(gAppOptions.SelectAllPlayerCards, connectionString, null);

                //READ LEADERS AND FACTIONS
                allFactionsRows = sqlUtil.ExecuteQuery(gAppOptions.SelectAllFactions, connectionString, null);
                allLeadersRows = sqlUtil.ExecuteQuery(gAppOptions.SelectAllLeaders, connectionString, null);
                //Build the Factions and build the list
                if (allFactionsRows != null)
                {
                    foreach (SqlRow row in allFactionsRows)
                    {
                        //Assign the returned database values into the object
                        FactionInfo faction = new FactionInfo();
                        faction.FactionName = ((string)row["factionName"]).Trim();
                        faction.FactionAbbr = ((string)row["factionAbbreviation"]).Trim();
                        faction.FactionPerk = ((string)row["factionPerk"]).Trim();
                        gAllFactions.Add(faction);
                    }
                }
                //Build the Leaders and build the list
                if (allLeadersRows != null)
                {
                    foreach (SqlRow row in allLeadersRows)
                    {
                        //Assign the returned database values into the object
                        LeaderInfo leader = new LeaderInfo();
                        leader.LeaderName = ((string)row["leaderName"]).Trim();
                        leader.LeaderAbility = ((string)row["leaderAbility"]).Trim();
                        leader.LeaderFaction = ((string)row["leaderFaction"]).Trim();
                        leader.LeaderFactionAbbr = ((string)row["leaderFactionAbbreviation"]);
                        gAllLeaders.Add(leader);
                    }
                }
                //Build the motherlode deck by assigning the attributes from the database into the object attributes.
                //The TRY/CATCH is there to handle potential null values because C# null is not the same as DBNULL
                if (allCardsRows != null)
                {
                    foreach (SqlRow row in allCardsRows)
                    {
                        Card card = new Card();
                        try
                        {
                            card.Name = ((string)row["cardName"]).Trim();
                        }
                        catch
                        { }
                        try
                        {
                            card.Power = (int)row["cardPower"];
                        }
                        catch { }
                        try
                        {
                            card.Faction = ((string)row["cardFaction"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Quote = ((string)row["cardQuote"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Hero = (bool)(row["cardHero"]);
                        }
                        catch { }
                        try
                        {
                            card.Range = ((string)row["cardRange"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Ability = ((string)row["cardAbilities"]).Trim();
                        }
                        catch { }
                        try
                        {
                            card.Quote = ((string)row["cardQuote"]).Trim();
                        }
                        catch { }
                        //New logic to read image file from DB and build path. ImageFilePath
                        try
                        {
                            string cardImageFileName = (string)row["cardImageFileName"];
                            card.ImageFilePath = "~/Content/Images/" + (cardImageFileName.Trim().Replace(" ", "%20"));

                        }
                        catch { }
                        gAllCards.Add(card);
                    }
                }

            } // end of Try-No Touchy
            catch
            {
                //Do we need to perform an action on catch?
            }
        }
        /// <summary>
        /// Adds an Non-Unicode variable character parameter to the procedure.
        /// Strings longer than SqlUtility.MAX_VARCHAR_LENGTH and the length argument are truncated to fit.
        /// </summary>
        /// <param name="name">The name of the parameter to add.</param>
        /// <param name="value">The value of the parameter to add.</param>
        /// <param name="length">The length of the variable character parameter.</param>
        /// <param name="direction">The direction of the parameter. Use one of the class parameter constants. Defaults to IN.</param>
        /// <returns>True if the parameter is added, false otherwise.</returns>
        public override bool AddVarCharParameter(string name, string value, int length, ParameterType direction)
        {
            // Truncate the string value if necessary.
            if (!string.IsNullOrWhiteSpace(value) && length != MAX_VARCHAR_SIZE)
            {
                MSSqlUtility utility = new MSSqlUtility();
                if (value.Length > utility.MAX_VARCHAR_LENGTH)
                {
                    value = value.Substring(0, utility.MAX_VARCHAR_LENGTH);
                }
            }

            // Check whether to return a MAX sized parameter.
            if (length != MAX_VARCHAR_SIZE)
            {
                // The parameter fits the requirements for a normal nvarchar parameter.
                // Set the size of the parameter to the length of the string because each
                // ANSI character is 1 byte long.
                return AddParameter(name, value, DbType.String, typeof(SqlParameter), direction, length);
            }
            else
            {
                // The parameter is too large for a normal nvarchar parameter.
                // Create a MAX sized parameter and set the size to the special value associated with max sized parameters.
                return AddParameter(name, value, DbType.String, typeof(SqlParameter), direction, MAX_VARCHAR_SIZE);
            }
        }
        /// <summary>
        /// Adds an Unicode fixed length character parameter to the procedure.
        /// Strings longer than SqlUtility.MAX_NCHAR_LENGTH and the length argument are truncated to fit.
        /// </summary>
        /// <param name="name">The name of the parameter to add.</param>
        /// <param name="value">The value of the parameter to add.</param>
        /// <param name="length">The length of the fixed length character parameter.</param>
        /// <param name="direction">The direction of the parameter. Use one of the class parameter constants. Defaults to IN.</param>
        /// <returns>True if the parameter is added, false otherwise.</returns>
        public override bool AddNCharParameter(string name, string value, int length, ParameterType direction)
        {
            // Truncate the string value if necessary.
            if (!string.IsNullOrWhiteSpace(value))
            {
                MSSqlUtility utility = new MSSqlUtility();
                if (value.Length > utility.MAX_NCHAR_LENGTH)
                {
                    value = value.Substring(0, utility.MAX_NCHAR_LENGTH);
                }
            }

            // Set the size of the parameter to twice the length of the string because each
            // Unicode character is 2 bytes long.
            return AddParameter(name, value, DbType.String, typeof(SqlParameter), direction, length * 2);
        }