Friday, 30 October 2009

SQL: Try Catch

EG1:BEGIN TRY
-- Table does not exist; object name resolution
-- error not caught.
SELECT * FROM NonexistentTable;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH



EG2:CREATE PROCEDURE usp_ExampleProc
AS
SELECT * FROM NonexistentTable;
GO

BEGIN TRY
EXECUTE usp_ExampleProc;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH;

SQL: Reset column identity

--Check what currently is
DBCC CHECKIDENT (’tablename’, NORESEED)

--Reset
DBCC CHECKIDENT (’tablename’, RESEED, 1)

Thursday, 29 October 2009

ASP: Photoshop titles

http://abduzeedo.com/shiny-caligraphy-text-effect-photoshop#

Salary Calc

http://www.thesalarycalculator.co.uk/salary.php

ASP: Creating fading edges in images

Creating Faded Edges
There are several ways to create edges on an image which fade away into the background. One way is as follows:
1. Begin with a canvas which is larger than the image to be blurred, around all four edges. One way to do this is to use the Image->Canvas Size dialog.
2. Use the marquee tool to select an area which is a few pixels in from the edge of the image.



3. Use Select->Invert to select the border around the image.


4.

Use Select->Feather to blur the selected area by a few pixels. A value of 4 pixels was used here.

5.

Now, use Filter->Blur-> Gaussian Blur to produce the final effect. A value of 4.1 was used.



6.

Finally, crop any unneeded whitespace around the image and save it.


http://www.mtholyoke.edu/help/creating-pages/imaging/xfade.shtml

Tuesday, 27 October 2009

ADO .NET: Connect to SP

conn.Open();

SqlCommand cmd1 = new SqlCommand("[staging].[USP_ETL_INSERT_FILE_ETLQUEUE]");
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add(new SqlParameter("@CartesisID", cartesisID));
cmd1.Parameters.Add(new SqlParameter("@ReportingPeriod",reportingPeriod));
cmd1.Parameters.Add(new SqlParameter("@FilePath", fileNameFull));
cmd1.Parameters.Add(new SqlParameter("@UploadedBy", Request.ServerVariables["AUTH_USER"]));
cmd1.Connection = conn;
cmd1.ExecuteNonQuery();
conn.Close();

//Execute SSIS Package
string packagelocation = System.Configuration.ConfigurationSettings.AppSettings["SSISLocation"].ToString();
string packageConfiglocation = System.Configuration.ConfigurationSettings.AppSettings["SSISConfigLocation"].ToString();
packagelocation = packagelocation + "VerifyFile.dtsx";
Package verifyPackage = app.LoadPackage(packagelocation, null);
verifyPackage.ImportConfigurationFile(packageConfiglocation + "VerifyFileConfig.dtsConfig");
verifyPackage.Variables["FileName"].Value = fileNameFull;
DTSExecResult result = verifyPackage.Execute();

Thursday, 22 October 2009

EXCEL: Convert xls to txt, csv

Open the Excel file and paste this code into the Source code. Change file type, delimiter and location in the DoTheExport() funtion

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ExportToTextFile' This exports a sheet or range to a text file, using a' user-defined separator character.''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Sub DoTheExport() ExportToTextFile FName:="C:\HRDW\200908.txt", Sep:="~", _ SelectionOnly:=False, AppendData:=TrueEnd Sub
Public Sub ExportToTextFile(FName As String, _ Sep As String, SelectionOnly As Boolean, _ AppendData As Boolean)
Dim WholeLine As StringDim FNum As IntegerDim RowNdx As LongDim ColNdx As IntegerDim StartRow As LongDim EndRow As LongDim StartCol As IntegerDim EndCol As IntegerDim CellValue As String
Application.ScreenUpdating = FalseOn Error GoTo EndMacro:FNum = FreeFile
If SelectionOnly = True Then With Selection StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End WithElse With ActiveSheet.UsedRange StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End WithEnd If
If AppendData = True Then Open FName For Append Access Write As #FNumElse Open FName For Output Access Write As #FNumEnd If
For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If Cells(RowNdx, ColNdx).Value = "" Then CellValue = Chr(34) & Chr(34) Else CellValue = Cells(RowNdx, ColNdx).Text End If WholeLine = WholeLine & CellValue & Sep Next ColNdx WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep)) Print #FNum, WholeLineNext RowNdx
EndMacro:On Error GoTo 0Application.ScreenUpdating = TrueClose #FNum
End Sub''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' END ExportTextFile''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Wednesday, 21 October 2009

ASP: Increase Session State

Increase session state by simply changing the timeout property in the Web.config.
The default is 20mins.

<system.web>
<sessionState timeout ="20" mode ="InProc" />
</system.web>

Tuesday, 20 October 2009

ASP: Image mouse over

The main use of function is to prevent us from writing the same code again and again because we can call the same function with a different set of parameters.

In the image roll-over script of the previous session, the code for changing the image was placed inside the event handlers. This is fine if there are one or two images. In case of several images, it is advisable to pack the code in a function that can be called repeatedly by event handlers using different parameters.

There are two important things in an image roll-over code. One is the image name and the other is the image source. Thus, we have to construct a function that accepts these two arguments and changes the image source.

Step 1 (JavaScript):

function roll_over(img_name, img_src)
   {
   document[img_name].src = img_src;
   }

Step 2 (HTML):

<A HREF="some.html" onmouseover="roll_over('but1', 'icon2.gif')"
onmouseout="roll_over('but1', 'icon1.gif')">
<IMG SRC="icon1.gif" WIDTH="100" HEIGHT="50"
NAME="but1" BORDER="0">
</A>


Thursday, 1 October 2009

ASPNET: ReportViewer Control Example


<--form name="frmReportFrame" method="post" runat="server">
<--rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
ProcessingMode="Remote" ShowParameterPrompts="false" Width="100%" Height="100%"
ShowBackButton="false" ShowFindControls="false" ShowPageNavigationControls="true"
ShowToolBar="true" BackColor="#efefef" InternalBorderColor="#efefef">
<--ServerReport />
<--/rsweb:ReportViewer>
<--/form>
in frmReportFrame.aspx.cs:
if (Request.QueryString.Count > 0)
{
string ReportPath = "";
if (Request.QueryString["WS"] == "old")
{
ReportPath = ConfigurationSettings.AppSettings["KSTReportpath"].ToString();
}
else
{
ReportPath = ConfigurationSettings.AppSettings["KSTReportChartPath"].ToString();
}
string path = ConfigurationSettings.AppSettings["KSTReportURL"].ToString();
ReportViewer1.ServerReport.ReportServerUrl = new Uri(path);
ReportViewer1.ServerReport.ReportPath = ReportPath;
ReportParameter[] Rparms = new ReportParameter[5];
//WinUserName=wrkhyd05raghu&ViewID=-2&WorksheetID=4&WorkBookCode=kst&PermissionSetId=4&rc:Parameters=false";
Rparms[0] = new ReportParameter("WinUserName", Request.QueryString["WinUserName"].ToString());
Rparms[1] = new ReportParameter("ViewID", Request.QueryString["ViewID"].ToString());
Rparms[2] = new ReportParameter("WorksheetID", Request.QueryString["WorksheetID"].ToString());
Rparms[3] = new ReportParameter("WorkBookCode", Request.QueryString["WorkBookCode"].ToString());
Rparms[4] = new ReportParameter("PermissionSetId", Request.QueryString["PermissionSetId"].ToString());
ReportViewer1.ServerReport.SetParameters(Rparms);
ReportViewer1.ServerReport.Refresh();
}