Archive for Novembre, 2007

DoEvents

CodeKeep C# Feed Novembre 30th, 2007

Description: Application DoEvents

Link: http://www.codekeep.net/snippets/81d331b6-75ca-4afa-b82f-d4f819372cec.aspx

   ExecuteLabelPrint(mTable.Rows[0], printLabelFile, port);
   mTable.Rows[0].Delete();
   this.dtgSpool.DataSource = mTable;
   Application.DoEvents();
   System.Threading.Thread.Sleep(500);

XML-Enabled Applications - Part 4

WebReference News Novembre 30th, 2007

When building XML-enabled PHP/Oracle applications, the database can be used as an efficient means of storing XML data and will operate on any kind of data that can be expressed in XML. PHP's XML extensions allow you to take advantage of Oracle XML DB. By Yuli Vasiliev. 1008

Call Oracle DBMS_DESCRIBE.DESCRIBE_PROCEDURE

CodeKeep C# Feed Novembre 30th, 2007

Description: Utility class for calling DBMS_DESCRIBE.DESCRIBE_PROCEDURE to get information about the arguments of an Oracle stored procedure.

Link: http://www.codekeep.net/snippets/7be0a2b8-4e0e-4262-a058-d77f89636150.aspx

    public static class Utility
    {
        private static Dictionary<string, ArgumentDescription[]> procedureArguments = new Dictionary<string, ArgumentDescription[]>();
        private static System.Data.DataTable allArgumentsCache = null;

        /// <summary>
        /// Contains the field values returned by the Oracle system procedure DBMS_DESCRIBE.DESCRIBE_PROCEDURE.
        /// </summary>
        public class ArgumentDescription
        {
            public int Overload;
            public int Position;
            public int Level;
            public string ArgumentName;
            public int DataType;
            public int DefaultValue;
            public int InOut;
            public int Length;
            public int Precision;
            public int Scale;
            public int Radix;
            public int Spare;
        }

        /// <summary>
        /// Calls the Oracle system procedure DBMS_DESCRIBE.DESCRIBE_PROCEDURE to return an argument of a stored procedure.
        /// </summary>
        /// <param name="ownerName">The package owner.</param>
        /// <param name="packageName">The package containing the procedure.</param>
        /// <param name="procedureName">The stored procedure name.</param>
        /// <param name="argumentName">The argument name.</param>
        /// <param name="connection">An <see cref="OracleConnection"/> to the Oracle database.</param>
        /// <returns>An <see cref="ArgumentDescription"/> representing the argument requested, or null of no matching argument is found.</returns>
        public static ArgumentDescription GetProcedureArgument(string ownerName, string packageName, string procedureName, string argumentName, OracleConnection connection)
        {
            argumentName = argumentName.Trim().ToUpper();
            foreach (ArgumentDescription argument in GetProcedureArguments(ownerName, packageName, procedureName, connection))
            {
                if (argument.ArgumentName.ToUpper() == argumentName)
                    return argument;
            }
            return null;
        }

        /// <summary>
        /// Calls the Oracle system procedure DBMS_DESCRIBE.DESCRIBE_PROCEDURE to return the arguments of a stored procedure.
        /// </summary>
        /// <param name="ownerName">The package owner.</param>
        /// <param name="packageName">The package containing the procedure.</param>
        /// <param name="procedureName">The stored procedure name.</param>
        /// <param name="connection">An <see cref="OracleConnection"/> to the Oracle database.</param>
        /// <returns>An array of <see cref="ArgumentDescription"/>.</returns>
        public static ArgumentDescription[] GetProcedureArguments(string ownerName, string packageName, string procedureName, OracleConnection connection)
        {
            ownerName = ownerName.Trim().ToUpper();
            packageName = packageName.Trim().ToUpper();
            procedureName = procedureName.Trim().ToUpper();

            string objectName = procedureName;
            if (!string.IsNullOrEmpty(packageName))
                objectName = packageName + "." + procedureName;
            OracleCommand cmd = null;
            string sql = null;

            // query ALL_ARGUMENTS table once and cache list of all arguments
            if (allArgumentsCache == null)
            {
                allArgumentsCache = new System.Data.DataTable();
                sql = "select owner, package_name, object_name, argument_name, position from sys.all_arguments WHERE owner='" + ownerName + "' ";
                cmd = new OracleCommand(sql, connection);
                OracleDataAdapter da = new OracleDataAdapter(cmd);
                da.Fill(allArgumentsCache);
            }
            
            // determine number of arguments in procedure
            sql = "owner='" + ownerName + "' and object_name='" + procedureName + "' ";
            if (!string.IsNullOrEmpty(packageName))
                sql += " and package_name='" + packageName + "' ";
            int argumentCount = Convert.ToInt32(allArgumentsCache.Compute("count(argument_name)", sql));
            int argumentCountPlusOne = argumentCount + 1; // in case procedure is actually a function that returns a value

            if (!procedureArguments.ContainsKey(objectName))
            {
                cmd = new OracleCommand("DBMS_DESCRIBE.DESCRIBE_PROCEDURE", connection);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add("OBJECT_NAME", OracleDbType.Varchar2).Value = objectName;
                cmd.Parameters.Add("RESERVED1", "");
                cmd.Parameters.Add("RESERVED2", "");

                int bindSize = 30;
                int[] arrayBindSize = new int[argumentCountPlusOne];
                for (int i = 0; i < argumentCountPlusOne; i++)
                    arrayBindSize[i] = bindSize;

                // setup the OUT associative arrays    
                string[] paramnames = new string[12] { "OVERLOAD", "POSITION", "LEVEL", "ARGUMENT_NAME", "DATATYPE", "DEFAULT_VALUE", "IN_OUT", "LENGTH", "PRECISION", "SCALE", "RADIX", "SPARE" };
                for (int i = 0; i < paramnames.Length; i++)
                {
                    OracleParameter p = null;
                    if (paramnames[i] != "ARGUMENT_NAME")
                        p = new OracleParameter(paramnames[i], OracleDbType.Int32, argumentCountPlusOne, null, System.Data.ParameterDirection.Output);
                    else
                    {
                        // need to set sizes on varchar2 params
                        p = new OracleParameter("ARGUMENT_NAME", OracleDbType.Varchar2, argumentCountPlusOne, null, System.Data.ParameterDirection.Output);
                        p.ArrayBindSize = arrayBindSize;
                    }
                    p.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
                    cmd.Parameters.Add(p);
                }

                cmd.ExecuteNonQuery();

                argumentCount = (cmd.Parameters[3].Value as Array).Length;
                ArgumentDescription[] argument = new ArgumentDescription[argumentCount];
                for (int i = 0; i < argumentCount; i++)
                {
                    int j = 3;
                    argument[i] = new ArgumentDescription();
                    argument[i].Overload = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Position = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Level = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].ArgumentName = Convert.ToString((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].DataType = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].DefaultValue = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].InOut = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Length = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Precision = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Scale = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Radix = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                    argument[i].Spare = Convert.ToInt32((cmd.Parameters[j++].Value as Array).GetValue(i));
                }

                procedureArguments.Add(objectName, argument);
            }

            return procedureArguments[objectName];
        }
    }

Check for Mobile Devices

CodeKeep C# Feed Novembre 29th, 2007

Description: Check for Mobile Devices

Link: http://www.codekeep.net/snippets/645b1297-ac91-4060-9ef9-c09369a8befc.aspx


<add key="MobileDevices" value="(nokia|sonyericsson|blackberry|samsung|sec-|windows ce|motorola|mot-|up.b)" />

Then I wrote a property called IsMobile which tries the Request.Browser.IsMobileDevice property first, and then tries the regular expression afterwards.

private static readonly Regex MOBILE_REGEX = new Regex(ConfigurationManager.AppSettings.Get("MobileDevices"), RegexOptions.IgnoreCase | RegexOptions.Compiled);

 

public static bool IsMobile

{

  get

  {

    HttpContext context = HttpContext.Current;

    if (context != null)

    {

      HttpRequest request = context.Request;

      if (request.Browser.IsMobileDevice)

        return true;

 

      if (!string.IsNullOrEmpty(request.UserAgent) && MOBILE_REGEX.IsMatch(request.UserAgent))

        return true;

    }

 

    return false;

  }

}

Path - Application.StartupPath (Windows Form)

CodeKeep C# Feed Novembre 29th, 2007

Description: Where the application starts

Link: http://www.codekeep.net/snippets/c1eb9568-de92-44f8-8496-fdbecf5cd7cd.aspx

string printLabel = Application.StartupPath + @"\Resources\";

Blogging: The Free Internet Marketing Method

WebReference News Novembre 28th, 2007

Blogging is one of the easiest ways to get your message noticed on the Web. While blogging has now become a hot method for teens to broadcast their thoughts, it’s also a great Internet marketing tool. By Rodney T. 1010

Validate A User’s Active Directory Credentials (pre-Windows XP)

CodeKeep C# Feed Novembre 28th, 2007

Description: How to validate a user's credentials in Windows 2000. For XP, use the code snippet "Validate A User's Active Directory Credentials".

Link: http://www.codekeep.net/snippets/2541ce83-624a-4f57-869a-f3475cd23384.aspx

        /// <summary>
        /// Validate a user's credentials against active directory.
        /// 
        /// Only use this method for PRE-XP operating systems.
        /// </summary>
        /// <param name="DomainName">string.  The user's domain name.  Example "AMERICAS"</param>
        /// <param name="UserName">string.  User name. Example "kevin_shuma"</param>
        /// <param name="Password">string.  The user's password.</param>
        /// <returns>bool.  True = authentication success, False = authentication failure.</returns>
        public static ValidateUserCredentialsReturnCodes
            ValidateUserCredentialsPreXP(string DomainName, string UserName, string Password)
        {
            try
            {
                DirectoryEntry User = new DirectoryEntry("LDAP://" + DomainName, UserName, Password, AuthenticationTypes.Secure);

                // the following assignment will raise an error if the login information is incorrect
                try
                {
                    UserName = User.Name;
                }
                catch (Exception AuthEx)
                {
                    // make sure we got an authentication error
                    if (AuthEx.Message.IndexOf("Logon failure") == -1) // not an authentication error
                        throw AuthEx; // rethrow the error to the general exception handler
                    else
                    {
                        // return an error indicating bad user name or password
                        return ValidateUserCredentialsReturnCodes.ERROR_BAD_USERNAME_OR_PASSWORD;
                    }
                }

                // everything passed okay, authentication was successful
                return ValidateUserCredentialsReturnCodes.SUCCESS;
            }
            catch (Exception ex)
            {
                //Logging.LogException(MethodBase.GetCurrentMethod(), ref ex);
                return ValidateUserCredentialsReturnCodes.UNKNOWN_ERROR;
            }
        }

Inside Camtasia Studio 5: Part 1

WebReference News Novembre 28th, 2007

In this article we’re going to look at the major new features of Camtasia Studio 5, including: the streamlined recorder, SmartFocus, ExpressShow, new editing features, features for bloggers, FTP and Screencast, transitions and the project settings. By Nathan Segal. 1024

How to Promote Your Product with Organic Search

WebReference News Novembre 28th, 2007

Pay-per-click marketing is often quite expensive and is one of the major complaints of small businesses. An alternative? Work at improving your organic search results. By Michael Fleischner. 1119.

DataTable - Creating and Using - Labels

CodeKeep C# Feed Novembre 28th, 2007

Description: DataTable - Creating and Using

Link: http://www.codekeep.net/snippets/1e0325ea-0b31-4db3-a9f8-1f9ff1dc4061.aspx

string Name = @"C:\Documents and Settings\kaa8823\My Documents\Visual Studio 2005\Projects\Classes\Solution\LabelPrinter\LabelMaker1\bin\Debug\Database\Data.dat";
            string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Name;

            string sSQL = "SELECT ITEMNUM, LOCATION, CATALOGCODE, ISSUEUNIT, DESCRIPTION from MATERIAL ORDER BY ITEMNUM";
            OleDbDataReader dr;
            OleDbConnection oCnn = new OleDbConnection(ConnectionString);
            OleDbCommand oCmd = oCnn.CreateCommand();

            DataTable mTable = new DataTable();
            DataRow mLine;
            mTable.Columns.Add(new DataColumn("ITEMNUM", typeof(string)));
            mTable.Columns.Add(new DataColumn("LOCATION", typeof(string)));
            mTable.Columns.Add(new DataColumn("CATALOGCODE", typeof(string)));
            mTable.Columns.Add(new DataColumn("ISSUEUNIT", typeof(string)));
            mTable.Columns.Add(new DataColumn("DESCRIPTION", typeof(string)));

            oCnn.Open();
            oCmd.CommandText = sSQL;
            dr = oCmd.ExecuteReader();
            while (dr.Read())
            {
                mLine = mTable.NewRow();
                mLine["ITEMNUM"] = dr["ITEMNUM"].ToString();
                mLine["LOCATION"] = dr["LOCATION"].ToString();
                mLine["CATALOGCODE"] = dr["CATALOGCODE"].ToString();
                mLine["ISSUEUNIT"] = dr["ISSUEUNIT"].ToString();
                mLine["DESCRIPTION"] = dr["DESCRIPTION"].ToString();
                
                mTable.Rows.Add(mLine);
            }
            dr.Close();
            oCnn.Close();

            this.dataGridView1.DataSource = mTable;

Next »