Thursday, July 31, 2008

Emailing from a Web Page

Imports System.Net.Mail

'Create an instance of the MailMessage class
Dim objMM As New MailMessage()
Dim Requestor_DropDownList As DropDownList
Dim IssueID_Label As Label

With Issue_FormView   Requestor_DropDownList = .FindControl("RequestedBy_DropDownList")
   IssueID_Label = .FindControl("JobID_Label")
End With

'Set the properties
objMM.To.Add(Requestor_DropDownList.SelectedValue + "@telecom.co.nz")
objMM.From = New MailAddress("est@telecom.co.nz")

'Send the email in html format
objMM.IsBodyHtml = True

'Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal

'Set the subject
objMM.Subject = "Feedback"

'Set the body
Dim sb As New StringBuildersb.AppendLine("Kiaora " + Requestor_DropDownList.SelectedItem.Text)
sb.AppendLine()
sb.AppendLine("Your EST Issue is about to be closed.")
sb.AppendLine("Please take 5 minutes to rate the service you have received the the Enterprise Service Team.")
sb.AppendLine("Click into this link: http://wstProdIIS/EST/register/Issue.aspx?ID=" + IssueID_Label.Text)
objMM.Body = sb.ToString

'Now, to send the message, use the Send method of the SmtpClient class
Dim objSC = New SmtpClient
objSC.Host = "WNEXBE01.telecom.tcnz.net"
objSC.Send(objMM)

Wednesday, July 30, 2008

Some extra Reporting Service Parameters

<rsweb:ReportViewer ID="rptLetter" runat="server" ExportContentDisposition="AlwaysAttachment" 
       Height="475px" ProcessingMode="Remote" PromptAreaCollapsed="true"
       ShowPromptAreaButton="false" SizeToReportContent="True" Width="100%" ShowFindControls="false"
       BackColor="#ededed">
        <ServerReport ReportPath="/Reports/Letter" ReportServerUrl="https://reportserver" />
        </rsweb:ReportViewer>

  Dim MyDate As New ReportParameter("date", PrintDate)
  Dim p() As ReportParameter = {MyDate}

  rptLetter.ServerReport.ReportPath = "/Reports/" & ReportName
  rptLetter.ServerReport.ReportServerCredentials = New ReportViewerCredentials(
       "username", "password", "domain")
  rptLetter.ServerReport.SetParameters(p)
  rptLetter.ServerReport.Refresh()
  rptLetter.Visible = True

Wednesday, June 18, 2008

Eliminate Double-Lines from Table Borders

<table border=1 bordercolor="black" style="border-collapse:collapse">
   <tr>
      <td>
         Something clever goes in here
      </td>
   </tr>
   <tr>
      <td>
         Something smart goes in here
      </td>
   </tr>
</table>

Something clever goes in here
Something smart goes in here

Wednesday, June 11, 2008

[dotnet] MCPD upgrade exams from MCSD

Kiaora Shane, The greatest piece of advice I received was: don’t do it!  Do the individual exams instead.  When I attempted the 70-551, I failed.  Ended up doing all 3 exams separately (70-536, 70-528, 70-547).  Greater coverage, greater understanding.  Unless you’re a genius.  For those of us of average intelligence, not a good choice.


From: dotnet@dot.net.nz [mailto:dotnet@dot.net.nz] On Behalf Of s ~
Sent: Tuesday, 10 June 2008 4:42 p.m.
To: dotnet@dot.net.nz
Subject: [dotnet] MCPD upgrade exams from MCSD

Fellas,

has anyone sat either of exams 70-553 or 70-554? If so, do you have any study material you can sell second hand, or can you point me towards some study material? There are guides and practice exams available for the other regular exams in the MCPD range, but there seems to be a scarcity of anything for the upgrade exams.

cheers

shane

Sunday, June 8, 2008

When 2 grids are linked

When you have:

  • a web page
  • 2 DataGridViews (parent/child relationship)
  • user wants to insert a new record into parent grid
  • parent grid has datasource set to Nothing so that EmptyDataTemplate shows
  • EmptyDataTemplate contains a DetailView
  • user fills in fields and clicks Insert
Then you get:
  • the parent record saves correctly; and
  • the page refreshes; but 
  • an error occurs because the child grid is linked to an empty Parent grid.
  • No amount of fiddling with the SelectedItem property of the Parent grid seems to work.

Resolution:

  • Hide the second grid until the user manually makes a selection on the Parent grid.

Thursday, May 22, 2008

[dotnet] Visual Studio Database Projects in 2005 or 2008

Ah!  You caught me out; yes, we primarily do single-developer projects.

  • Still, I find the Database Project useful not only as a source repository of migration scripts, but also:
  • The list of Database References helps keep the 3 environments handy when wanting to apply a script to any particular environment.
  • And, when you right-click a database object in the Server Explorer and click Generate Create Script to Project = very handy.

From: dotnet@dot.net.nz [mailto:dotnet@dot.net.nz] On Behalf Of Andrew Shearer
Sent: Thursday, 22 May 2008 4:03 p.m.
To: dotnet@dot.net.nz
Subject: [dotnet] RE: visual studio database projects in 2005 or 2008 -->

Do you have a whole team working on this migration script, or just you?

From: dotnet@dot.net.nz [mailto:dotnet@dot.net.nz] On Behalf Of James Hippolite
Sent: Thursday, 22 May 2008 3:51 p.m.
To: dotnet@dot.net.nz
Subject: [dotnet] RE: visual studio database projects in 2005 or 2008

-->

I use Database Projects; here’s how:

  • Each week I create a new migration script e.g. Update20080523.sql.
  • All database changes made to DEV, are scripted and saved to this file.
  • I test and re-test it in DEV.  Obviously this requires some smarts around whether to attempt to recreate objects or update data (IF EXISTS…).
  • I apply it to TEST, usually only once.
  • Finally, during Friday’s change window, I apply it to PROD; definitely only once.
  • It helps to place a comment at the top of the file referencing the changed objects.

From: dotnet@dot.net.nz [mailto:dotnet@dot.net.nz] On Behalf Of Andrew Shearer
Sent: Thursday, 22 May 2008 3:31 p.m.
To: dotnet@dot.net.nz
Subject: [dotnet] visual studio database projects in 2005 or 2008 -->

Who here actually uses these and finds them practical?? Sure, the source control aspect would be great but all i see is this hugely outweighed by trying to manage schema and data changes in a sequential fashion and the major problems that arise if that isn’t done correctly. We don’t roll out the entire database with each product release, but simply the iterative changes that have been made. Is that where we’re going wrong in terms of how a database project works? If you release just the incremental schema and data changes like we do, how are you maintaining this sequence in your database project ‘change scripts’?

thanks

Tuesday, May 20, 2008

Implementing Manual Sorting on GridView

Problem:

  • I have GridViews, powered by ObjectDataSources.
  • I wanted to implement sorting
  • Error: DataSource doesn't implement IEnumerable.
  • Went looking it up: too hard
Solution:
  • GetData() method accepts two input parameters: SortName and SortOrder
  • Page.Load method (snippet 1)
  • GridView.Sorting method (snippet 2)
  • ObjectDataSource.Selecting method (snippet 3)
Snippet 1:

  If IsPostBack Then
    Exit Sub
  End If

  ViewState("SortName") = "ColumnName"
  ViewState("SortOrder") = WebControls.SortDirection.Ascending

Snippet 2:
  e.Cancel = True 'Cancel the automatic sort, do it manually

  If ViewState("SortName") = e.SortExpression Then
     ViewState("SortOrder") = Not ViewState("SortOrder")
  Else
     ViewState("SortName") = e.SortExpression     
     ViewState("SortOrder") = e.SortDirection 
  End If

  GridView1.DataBind()
Snippet 3:

Dim iod As IOrderedDictionary = e.InputParameters 
iod("SortName") = ViewState("SortName")
iod("SortOrder") = ViewState("SortOrder")