Friday, May 15, 2009

Sql mail (2005 )send using stored procedure

ALTER PROCEDURE [dbo].[uspGenerateMailTimeSheetDailyReminder]
AS
--Declaration area
DECLARE @firstName VARCHAR(50)
DECLARE @lastName VARCHAR(50)
DECLARE @email VARCHAR(255)
declare @body1 varchar(500)

------Send mail To Employees end of the day for timesheet tasks
DECLARE Mailing CURSOR FOR


SELECT Email, EmployeeFirstName,EmployeeSurname
FROM UserGroup INNER JOIN
tblEmployees ON UserGroup.UserName = tblEmployees.UserName

WHERE UserGroup.GroupName='Employee' AND IsActive='1' AND tblEmployees.EmployeeFirstName='sanjeewa'



OPEN Mailing
FETCH NEXT FROM Mailing INTO @email, @firstName,@lastName
WHILE 0 = @@FETCH_STATUS
BEGIN

set @body1 = 'Dear ' + CAST(@firstName AS VARCHAR) + ' ' + CAST(@lastName AS VARCHAR)+',< br/>' +'< br/ >'+ 'Please update your time sheets before you sign out. ' +'< br/>'+'< br/ >' + 'Regards' + '< br/ >'+ 'Admin.'
EXEC msdb.dbo.sp_send_dbmail @recipients=@email,
@subject = 'Please update your time sheets. ',
@body = @body1,
@body_format = 'HTML' ;

FETCH NEXT FROM Mailing INTO @email, @firstName,@lastName
END

CLOSE Mailing
DEALLOCATE Mailing

Tuesday, May 12, 2009

get summery total in datagrid C# - rowdatabound event

protected void gvWeeklySummeryReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
switch ((int)(e.Row.RowType))
{
case (int)ListItemType.Item:
case (int)ListItemType.AlternatingItem:
//Calculate total for the field of each row and alternating row.
myTotal += Convert.ToDouble(gvWeeklySummeryReport.DataKeys[e.Row.RowIndex].Values["SpentHours"]);
//Format the data, and then align the text of each cell to the right.
e.Row.Cells[3].Attributes.Add("align", "right");
break;
}
}
else if(e.Row.RowType == DataControlRowType.Footer)
{
gvWeeklySummeryReport.FooterStyle.Font.Bold = true;
//Use the footer to display the summary row.
e.Row.Cells[3].Text = "Total hours";
e.Row.Cells[4].Attributes.Add("align", "left");
e.Row.Cells[4].Attributes.Add("align", "center");
e.Row.Cells[4].Attributes.Add("style", "color:black;font-weight:bold");
e.Row.Cells[3].Attributes.Add("style", "color:black;font-weight:bold");
e.Row.Cells[4].Text = myTotal.ToString();
}
}

Monday, May 11, 2009

Get particular Date / Day C#

DateTime sundayDate = DateTime.Now.Subtract(new TimeSpan((int)DateTime.Now.DayOfWeek, 0, 0, 0));