Saturday, November 11, 2006

SQL

This week I was told about a book titled, "Gurus Guide to Transact SQL". So being told about the book I headed to the local Borders with my daughter to check the book out. This book first and for most is better purchased online it is a lot cheaper.

This book is the ultimate guide to SQL Server Transact-SQL. T-SQL is a must for any developer utlizing SQL Server as their backend DBMS (Data Base Management System).

Sunday, October 15, 2006

Back on the blog

Moojjoo here and I am would like to apologize for not writting more. Having a 7 month old is a lot of work and not to mention the full plate I have at work lately.

I am very excited that my current company R.J. Reynolds Tobacco Company is finally moving forward to ASP.NET 2.0 and Visual Studio 2005.

As for coding I have really been researching the ability to use tiers in development so I can use as much resuse as possible.

Til Later

Friday, June 16, 2006

Using .NET Outlook to send formatted email

Imports Microsoft.Office
Imports Microsoft.Office.Core
Imports System.Runtime.InteropServices
Imports Outlook = Microsoft.Office.Interop.Outlook


Public Class TestOutlookMail
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
Private Sub InitializeComponent()

End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Private app As Outlook.ApplicationClass

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
app = New Outlook.ApplicationClass
End Sub

'Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' CreateEmailMessage()
'End Sub 'button1_Click


'Private Sub CreateEmailMessage()
' 'Initialize the envelope values.
' Dim strTo As String = "yourname@yourdomain.com"
' Dim strBCC As String = "yourname@yourdomain.com"
' Dim strCC As String = "yourname@yourdomain.com"
' Dim strSubject As String = "Outlook Automation"
' Dim strBody As String = "Hello World"

' 'Automate the Outlook mail item.
' app = New Outlook.ApplicationClass
' Dim mItem As Outlook.MailItemClass = CType(app.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItemClass)
' 'Dim As Outlook.MailItemClass = CType(doc.MailEnvelope.Item, Outlook.MailItemClass)
' 'Outlook.MailItemClass mi = (Outlook.MailItemClass)app.CreateItem
' mItem.To = strTo
' mItem.BCC = strBCC
' mItem.CC = strCC
' mItem.Subject = strSubject
' mItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
' mItem.HTMLBody = strBody
' 'mItem.ItemEvents_Event_Close += New Outlook.ItemEvents_CloseEventHandler(Me.wApp_Close)

' 'wApp.Visible = True

' ' Loop until there are no more references to release.
' While Marshal.ReleaseComObject(mItem) > 0
' End While
' mItem = Nothing

' ' Invoke the .NET garbage collector.
' GC.Collect()
' GC.WaitForPendingFinalizers()
'End Sub 'CreateEmailMessage

Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Subject As String = "This is my Subject"
Dim Body As String = "This is my Body"


Dim mi As Outlook.MailItemClass = CType(app.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItemClass)
mi.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
mi.HTMLBody = Body
mi.Subject = Subject
mi.Display(New Object)

Dim ni As Outlook.NoteItemClass = CType(app.CreateItem(Outlook.OlItemType.olNoteItem), Outlook.NoteItemClass)
ni.Body = "This is my Body again"
ni.Display(New Object)

Dim pi As Outlook.PostItemClass = CType(app.CreateItem(Outlook.OlItemType.olPostItem), Outlook.PostItemClass)
pi.Subject = Subject
pi.BodyFormat = Outlook.OlBodyFormat.olFormatHTML
pi.Body = Body

pi.Display(New [Object])
End Sub 'button1_Click


End Class

Thursday, June 15, 2006

DropDown in DataGrid, How to Select

This is a two parter. First we will discuss on to add a "Select Value" to the Drop Down List after we populate the DropDown with Data from the Database then I will discuss how to Select that value using the OnItemDataBound from the DataGrid.

Inside the DataGrid you must use a Template like so

Thursday, June 08, 2006

SQL Time Converter

Private Sub BuildSQLTime(ByVal strProdDate, ByVal strProdTime)
Dim SQLDateTime As DateTime
Dim strDate As String = strProdDate
Dim strTime As String = strProdTime

Dim DateArray(2) As String
DateArray(0) = strDate.Substring(0, 2)
DateArray(1) = strDate.Substring(2, 2)
DateArray(2) = strDate.Substring(4, 2)

Dim tempDateTime As String
Dim newDateTime As DateTime

tempDateTime = DateArray(1) & "/" & DateArray(2) & "/" & DateArray(0)
newDateTime = Convert.ToDateTime(tempDateTime & " " & strTime)
'newDateTime = DateTime.Now

lblResults.Text = newDateTime
End Sub

Tuesday, May 30, 2006

Update to Access Folders without reboot

Need to access a folder you were just given access to? No need to reboot. Simply go to Start > Run > Type CMD At the dos prompt type gpupdate

Friday, May 19, 2006

SQL Server Leading Zeros for CHAR Type

declare @DirectiveNumber char(6)
declare @DirLength int



SET @DirectiveNumber = (SELECT DirectiveNumber FROM dbo.tblPlants WHERE PlantId = '1201')

--UPDATE dbo.tblPlants SET DirectiveNumber =
SET @DirectiveNumber = @DirectiveNumber + 1

Select @DirLength = LEN(@DirectiveNumber)

IF (@DirLength = 1)
SET @DirectiveNumber = '00000' + @DirectiveNumber
IF (@DirLength = 2)
SET @DirectiveNumber = '0000' + @DirectiveNumber
IF (@DirLength = 3)
SET @DirectiveNumber = '000' + @DirectiveNumber
IF (@DirLength = 4)
SET @DirectiveNumber = '00' + @DirectiveNumber
IF (@DirLength = 5)
SET @DirectiveNumber = '0' + @DirectiveNumber

UPDATE dbo.tblPlants SET DirectiveNumber = @DirectiveNumber WHERE PlantId = '1201'

SELECT @DirectiveNumber

Tuesday, May 16, 2006

ASP.NET 2.0

WOW,

Well I just deployed my first ASP.NET 2.0. What a difference from 1.x.

I learned that you can deploy by using a publish and precompiled mode that will not cause a slow load the first time a user accesses the site, but the issue with using that is that when you make change you have to redeploy all the .aspx and .dll files again. That kinda sucks.

However, after a little research I found a tool that add-ons from microsoft: http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/

This feature more reflects the ASP.NET 1.x way of creating dlls

Friday, May 12, 2006

How do I hide a column in my Datagrid if AutoGenerateColumns is set to True?

Question: How do I hide a column in my Datagrid if AutoGenerateColumns is set to True?

Answer: AutoGenerated columns do not appear in the Datagrid's Columns() collection, and so the usual method of hiding a Datagrid column will fail:

'Will NOT work for AutoGenerated columns:
Datagrid1.Columns(1).Visible = False

So the place to handle this is in the ItemDataBound event of the Datagrid:

<asp:DataGrid id="Datagrid1" runat="server" AutoGenerateColumns="True" OnItemDataBound="Datagrid1_OnItemDataBound"/>

Codebehind
Private Sub Datagrid1_OnItemDataBound(s As Object, e As DatagridItemEventArgs)
e.Item.Cells(1).Visible = False
End Sub

Tuesday, May 09, 2006

AUTOEVENTWIREUP .NET

WARNING...

Auto Event Wireup will fire your ASP.NET pages twice be warned.

Monday, May 08, 2006

Parse Error When adding new Web pages to application

I am banging my head on this one... All of my other Web forms work fine but now...

I am getting the following error when adding new Web forms to my application:

I just added simple Web form with Hello World typed on the page.

Server Error in '/XXX.QuipSap.WebUi' Application.



Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'XXX.QuipSap.WebUi.TestForm'.

Source Error:

Line 1: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="XXX.QuipSap.WebUi.TestForm"%>
Line 2:
Line 3:

Source File: c:\inetpub\wwwroot\XXX.QuipSap.WebUi\TestForm.aspx Line: 1


SOLUTION:
OK as crazy as a solution that this sounds, but I am not to happy with the solution but it works.

When I create add a new Web form I just remove the inherits part from the first line of the aspx page. If I add labels or buttons and double click on them VS.NET 2003 adds back the inherits and magically (HMM I say magically because if I knew what was fixing it I would not be writting this) fixes the issue.

Parse Error When adding new Web pages to application

I am banging my head on this one... All of my other Web forms work fine but now...

I am getting the following error when adding new Web forms to my application:

I just added simple Web form with Hello World typed on the page.

Server Error in '/XXX.QuipSap.WebUi' Application.



Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'XXX.QuipSap.WebUi.TestForm'.

Source Error:

Line 1: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="XXX.QuipSap.WebUi.TestForm"%>
Line 2:
Line 3:

Source File: c:\inetpub\wwwroot\XXX.QuipSap.WebUi\TestForm.aspx Line: 1


SOLUTION:
OK as crazy as a solution that this sounds, but I am not to happy with the solution but it works.

When I create add a new Web form I just remove the inherits part from the first line of the aspx page. If I add labels or buttons and double click on them VS.NET 2003 adds back the inherits and magically (HMM I say magically because if I knew what was fixing it I would not be writting this) fixes the issue.

Parse Error When adding new Web pages to application

I am banging my head on this one... All of my other Web forms work fine but now...

I am getting the following error when adding new Web forms to my application:

I just added simple Web form with Hello World typed on the page.

Server Error in '/XXX.QuipSap.WebUi' Application.



Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'XXX.QuipSap.WebUi.TestForm'.

Source Error:

Line 1: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="XXX.QuipSap.WebUi.TestForm"%>
Line 2:
Line 3:

Source File: c:\inetpub\wwwroot\XXX.QuipSap.WebUi\TestForm.aspx Line: 1


SOLUTION:
OK as crazy as a solution that this sounds, but I am not to happy with the solution but it works.

When I create add a new Web form I just remove the inherits part from the first line of the aspx page. If I add labels or buttons and double click on them VS.NET 2003 adds back the inherits and magically (HMM I say magically because if I knew what was fixing it I would not be writting this) fixes the issue.

Parse Error When adding new Web pages to application

I am banging my head on this one... All of my other Web forms work fine but now...

I am getting the following error when adding new Web forms to my application:

I just added simple Web form with Hello World typed on the page.

Server Error in '/XXX.QuipSap.WebUi' Application.



Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'XXX.QuipSap.WebUi.TestForm'.

Source Error:

Line 1: <%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestForm.aspx.vb" Inherits="XXX.QuipSap.WebUi.TestForm"%>
Line 2:
Line 3:

Source File: c:\inetpub\wwwroot\XXX.QuipSap.WebUi\TestForm.aspx Line: 1


SOLUTION:
OK as crazy as a solution that this sounds, but I am not to happy with the solution but it works.

When I create add a new Web form I just remove the inherits part from the first line of the aspx page. If I add labels or buttons and double click on them VS.NET 2003 adds back the inherits and magically (HMM I say magically because if I knew what was fixing it I would not be writting this) fixes the issue.

Sunday, January 29, 2006

Right click command prompt

Here's a handy tip that I got from a co-worker, who found it in the book Microsoft Visual C# .NET Step by Step. It creates a shortcut in the right click context menu of Windows Explorer to open a command prompt in the current directory. When I need to run scripts in a very long directory name, this is very handy.

So here's how you set it up:

Open up windows explorer
Tools -> Folder Options.
File Types Tab
Select the Folder file type
Click Advanced
Click New
For the Action type what ever you want the context menu to display, I used Command Prompt.
For the Application used to perform the action use c:\windows\system32\cmd.exe (note on win2k you will want to specify the winnt directory instead of the windows directory)

You can also use this feature to attach context actions to file types. Or if you want to create a right click open with option for any file type (for instance I like to be able to open any file with notepad, see: my blog entry here.

Friday, January 20, 2006

Arrays

Well I guess it is time to start being a true programmer and master arrays. So what did I learn day one about using arrays.

If you are going to use C# and want a dynamic array you better use the following code... (HINT USE AN ARRAY LIST)

int i = 0;
ArrayList al = new ArrayList();
while (myReader.Read())
{
al.Add(myReader.GetInt32(0));
i = i + 1;
}

Friday, January 13, 2006

Directory .NET Functions

NET Framework Class Library

Directory Members

Moojjoo Blog

SharePoint Stats

Getting Usage Statistics on Sharepoint Portal 2003 Areas
This comes from this microsoft blog



"There are pages available in Windows SharePoint Services that will allow you to obtain usage statistics for WSS Sites. However, this is not the case for Areas in SharePoint Portal Server 2003. There are no built-in hyperlinks in the Admin pages for viewing usage statistics for a give Area.

Does this mean that usage statistics are not available for Areas in SPS 2003? No, it just means that you have to know a backdoor URL to get to the pages that display the stats. Here is the format of the URL:

http://{your portal name}/_layouts/1033/usageDetails.aspx

This URL will take you to a usage statistics page for the Home Area of your portal. (Note: the 1003 is the designator for you language, so it will be different if not using U.S. English).

If you want to look at usage statistics for a Subarea, for instance, News, you would modify the URL to look as follows:

http://{your portal name}/News/_layouts/1033/usageDetails.aspx"


Moojjoo Blog

Wednesday, January 11, 2006

Validating Edits in Grids

When using the Grid Web Controld a lot of times I find myself needing to customize the edit functionality to use validation. The following are the procedures that I use to customize the Data Grid Web Controld.

In order to implement a customization in a datagrid you need to implement a template

<asp:TemplateColumn HeaderText="Gift Amount">
<itemtemplate>
<asp:label id="lblAward_Amount" text='<%# DataBinder.Eval(Container.DataItem, "Gift_Amount", "{0:c}") %>' Runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox ID="txtGift_Amount2" text='<%# DataBinder.Eval(Container.DataItem, "Gift_Amount", "{0:c}") %>' runat="server" />
<asp:regularexpressionvalidator id="Regularexpressionvalidator1" runat="server" ControlToValidate="txtGift_Amount2"
ErrorMessage="Money Values only example 20.00 no commas!" ValidationExpression="\d*.\d{2}"></asp:regularexpressionvalidator></asp:boundcolumn>
</edititemtemplate>
</asp:TemplateColumn>

To access this in the code behind you must using the following:

// This will access the control inside the data grid.
tempGiftAmount = (((TextBox)e.Item.FindControl("txtGift_Amount2")).Text);