Joseph Michael Pesch
VP Programming

C# Convert Enum Array Into Typed Array Used in LINQ to SQL IN Query

by 30. March 2009 17:22

http://stackoverflow.com/questions/472384/convert-an-array-of-enum-to-an-array-of-int

http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql/

The example below take an enum array input variable, converts to an integer array variable for use in a LINQ to SQL IN clause type query:

    public enum FlagTypeCode
    {
      NotAssigned = 0,
      SendToServicerBlocked = 100,
      SelectedForQCReview = 200
    }
    public static IQueryable<ModFlagDate> LoadModFlagDate(FlagTypeCode[] FlagTypeCodeList, ref string ErrorMessage)
    {
      int[] FlagTypeList = Array.ConvertAll(FlagTypeCodeList, value => (int) value);
      ModCalcDataContext db = new ModCalcDataContext();
      var rows = (from row in db.ModFlagDates
                        where FlagTypeList.Contains(row.FlagTypeCode)
                        select row);
      return rows;
    }

Tags: ,

C# | LINQ to SQL

CSS Site Layout

by 30. March 2009 14:05

<html>
<head>
  <style type="text/css">
    body
    {
      font-family: calibri, tahoma, verdana, courier, times;
    }
    div#outer
    {
      width: 80%;
      background-color: #FFFFFF;
      margin-top: 50px;
      margin-bottom: 50px;
      margin-left: auto;
      margin-right: auto;
      padding: 0px;
      border: solid 1px #000000;
    }
    div#header
    {
      padding: 15px;
      margin: 0px;
      text-align: center;
      border-bottom: solid 1px #000000;
    }
    div#nav
    {
      width: 25%;
      padding: 10px;
      margin-top: 1px;
      float: left;
    }
    div#main
    {
      margin-left: 25%; /* Make at least as big as #nav width */
      min-height: 400px;
      margin-top: 1px;
      padding: 10px;
      border-left: solid 1px #000000;
    }
    div#footer
    {
      padding: 15px;
      margin: 0px;
      border-top: solid 1px #000000;
    }
  </style>
</head>
<body>
  <div id="outer">
    <div id="header">
      <h2>
        Home</h2>
    </div>
    <div id="nav">
      <h4>
        Navigation</h4>
      <ul>
        <li>Let me not to the marriage of true minds</li>
        <li>Admit impediments; love is not love</li>
        <li>Which alters when it alteration finds</li>
      </ul>
    </div>
    <div id="main">
      <p>
        Main Content -- Love's not time's fool...</p>
    </div>
    <div id="footer">
      <p>
        Footer text -- Admit impediments...</p>
    </div>
  </div>
</body>
</html>

Tags: ,

[None]

Zune Registry Hack for Vista - Allows Use as Mass Storage Device

by 30. March 2009 13:40
  • Make sure your Zune is not plugged in and your Zune software isn’t running
  • Open up Regedit by going to the start menu and selecting “run”. Type regedt32 and hit “OK”
  • Browse to HKEY_LOCAL_MACHINE\System\ControlSet002\Enum\USB\
  • Search for “PortableDeviceNameSpace”. This should be contained in the Vid_####&Pid_####\########_-_########_-_########_-_########\Device Parameters within the above …\USB\ The ##’s listed here will be numbers and letters specific to your Zune.
  • Change the following values:
    • EnableLegacySupport to 1
    • PortableDeviceNameSpaceExcludeFromShell to 0
    • ShowInShell to 1
  • Plug in your Zune, and make sure the Zune Software starts up.
  • Hopefully at this point you can open up “My Computer” and browse your device, though it does NOT show up as a drive letter.

Tags: ,

[None]

LinqSql DBML Connection String from Web.Config

by 26. March 2009 14:38

By default the DBML object sets the connection string information on the properties tab of the designer (available when you click on the white space in the the ORM designer).  IMPORTANT NOTE: Although you can select a web.config entry from the drop-down list in the designer, it will actually store the detailed connection string information in the DBML.cs file and not actually re-read the web.config at run time.  To use a true dynamic web.config default (vs. this hard coded default) make sure the designer connection is blank as shown in screen shot below.

Add partial class like this: 

namespace CRM {
publicpartialclassCRMDataContext : System.Data.Linq.DataContext

{
public CRMDataContext() : base(System.Configuration.ConfigurationManager.ConnectionStrings["CRM"].ConnectionString, mappingSource)
{
}
}
}


Tags: ,

LINQ to SQL

Copying .Net Assembly DLL from One Computer to Another

by 25. March 2009 23:33

1) cmd window to "C:\Windows\Assembly\GAC_MSIL" then use the "dir" command (use TAB key to get auto-complete help on directories) to navigate down into folder that contains target .DLL

2) Copy the .DLL to a folder (like "C:\Temp")

3) Copy the .DLL to a folder on the target machine.

4) On the target machine run "Assembly" (from the windows run).

5) Drag the .DLL onto the Assembly window.

Tags: ,

[None]

C# System.Drawing.Color from HTML Color String

by 23. March 2009 20:20

System.Drawing.Color OrangeColor = System.Drawing.ColorTranslator.FromHtml("#CE56CC");

You can also translate colors without the ColorTranslator class (which may be useful if you are using the Compact Framework).

System.Drawing.Color only supports creating custom colors using it's FromArgb method, which requires base-10 inputs. Therefore, two conversion functions are needed - a conversion from decimal to hexadecimal, and a conversion from a 6 character string to three numeric parts (one each for red, green, and blue).

Source CodeThe first function handles the safe conversion of a hexadecimal (base-16) number to decimal (base-10).

1protected int HexStringToBase10Int(string hex)
2...{
3    int base10value = 0;
4
5    try   ...{ base10value = System.Convert.ToInt32(hex, 16); }
6    catch ...{ base10value = 0; }
7
8    return base10value;
9}

The next function breaks the hexadecimal string into parts, removes a leading # (so you can pass it #FF00FF or FF00FF with the same result), and then converts the hexadecimal parts into decimal, and creates a color using the red, green, and blue value integers.

 1protected System.Drawing.Color HexStringToColor(string hex)
 2...{
 3    hex = hex.Replace("#", "");
 4
 5    if (hex.Length != 6)
 6        throw new Exception(hex +
 7            " is not a valid 6-place hexadecimal color code.");
 8
 9    string r, g, b;
10
11    r = hex.Substring(0, 2);
12    g = hex.Substring(2, 2);
13    b = hex.Substring(4, 2);
14
15    return System.Drawing.Color.FromArgb(HexStringToBase10Int(r),
16                                         HexStringToBase10Int(g),
17                                         HexStringToBase10Int(b));
18}

from: http://www.akxl.net/labs/articles/converting-a-hexadecimal-color-to-a-system.drawing.color-object/

Tags: ,

C#

SQL GoTo Statement

by 13. March 2009 18:06

declare @i int, @var int set @i = 1
while @i <= 10 begin
  printconvert(varchar(10), @i)+': while'

set @var = 1 goto Code1 ContinueWhile:


set @i = @i + 1
end
goto EndProcess Code1:

printconvert(varchar(10), @i)+': Code: '+convert(varchar(10), @var)
if @var < 5 begin
set @var = @var + 1 goto Code1 end


goto ContinueWhile EndProcess:

print'Done'

Tags: ,

SQL Server

Excel Formula to Convert Date Cell to Text Cell

by 13. March 2009 15:22

This formula will take the Date value from cell A1 and convert it to either the word null if no date is in the cell or a string representation of the date in small quotes (usefull for generating SQL insert/update strings):

=IF(A1="","null","'"&TEXT(MONTH(A1),"00") & "-" & TEXT(DAY(A1),"00") & "-" & TEXT(YEAR(A1), "0000")&"'")

Tags: ,

Excel

Oracle to_date() Function

by 12. March 2009 18:58

Date formatting in Oracle

select to_date('02/17/2009 12:22:01 PM', 'mm/dd/yyyy HH:MI:SS AM') from dual

 

Tags: ,

Oracle

Visual Studio XML Documentation Reference

by 8. March 2009 21:34

To add XML documentation:

1) Enable via Project Properties (on the Build tab).

2) Build project and you will receive warnings about all Public members that are not documented (you can double-click to add appropriate documentation in each section).

3) Install Sandcastle (http://www.codeplex.com/Sandcastle) and  Visual Studio 2008 SDK (http://www.microsoft.com/downloads/details.aspx?familyid=30402623-93ca-479a-867c-04dc45164f5b&displaylang=en)

4) Run Sandcastle program (in my case I ran it from C:\Program Files\Sandcastle\Examples\generic\SandcastleGui.exe)

5) Once you click on build the tool will generate HxS file under the sandcastle installation directory (named whatever you selected in the "Name" field). We will use this file to create a setup.exe which when installed integrates it with Visual Studio.

6) Open Visual Studio 2008 and click File -> New Project : In the new project dialog expand "Other Project Types" and select Extensibility. On the right hand side select "Help Integration Wizard" and enter a name for the project and click OK.  In the wizard that appears select "Setup project" and click Next.  In the next step select the HxS file we created in Step 5 above.  Visual Studio now creates 2 projects a Merge Module project and a setup project. Click on the setup project and modify its properties as needed.

7) Now compile the setup project to generate an MSI and a setup.exe file which when installed integrates the help with VS.NET.  You might have to close and re-open all instances VS.NET to see the change.  Now type in a class name in the code editor and press F1.  VS.NET should directly take you to the documentation associated with that class.

Below are the basic XML documetation tags you can apply to the source code for building the help file.

Documentation Sections

  • <summary>

    A short description of the item; describe the members of the type here.

    <summary>text</summary>
  • <remarks>

    The "Remarks" section of the documentation; specify overview information here.

    <remarks>text</remarks>
  • <example>

    The "Example" section of the documentation.

    <example>text</example>
  • <seealso>

    A link in the "See Also" section of the documentation.

    <seealso cref="member">text</seealso>

Member Documentation

  • <param>

    Describes a parameter to a method.

    <param name="name">text</param>
  • <returns>

    The return value of a method.

    <returns>text</returns>
  • <exception>

    The exceptions that can be thrown.

    <exception [cref="type"]>text</exception>
  • <value>

    Describes the value of a property.

    <value>text</value>
  • <permission>

    The permission applied to a member.

    <permission [cref="type"]>text</permission>

Text Formatting

  • <c>

    Format characters as code within other text.

    <c>code</c>
  • <code>

    Multiline section of code.

    <code>code</code>
  • <see cref>

    A link to a type, member or field in the current compilation environment.

    <see cref="member">text</see>
  • <see langword>

    Undocumented. A link to a keyword in the language of the current compilation environment, e.g. null.

    <see langword="keyword"/>
  • <paramref>

    A reference to a parameter within other text.

    <paramref name="name"/>
  • <list>

    A list of items.

    <list type="[bullet|number|table]">
        <listheader>
            <term>name</term>
            <description>text</description>
        </listheader>
        <item>
            <term>name</term>
            <description>text</description>
        </item>
    </list>
  • <para>

    A paragraph within other text.

    <para>text</para>
  • <include>

    Refer to comments in another file.

    <include file='filename' path='tagpath[@name="id"]' />

Tags: ,

Visual Studio

JQuery Reference

by 8. March 2009 21:08

MSDN Magazine article: Explore Rich Client Scripting With jQuery, Part 1 http://msdn.microsoft.com/en-us/magazine/dd453033.aspx#id0080053

Tags: ,

JQuery