Timesheet using GridView(also logging using enterprise library)
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 50%;
margin-left: 0;
padding: 0;
}
.style3
{
width: 274px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td colspan="2">
Add New Project:
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Project Name:
</td>
<td>
<asp:TextBox ID="prjcttxt" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Manager Name:
</td>
<td>
<asp:TextBox ID="mgrtxt" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Start Date:
</td>
<td>
<asp:TextBox ID="strtdttxt" runat="server" Style="margin-bottom: 0px"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="strtdttxt_CalendarExtender" runat="server" Format="MMMM d, yyyy"
Enabled="true" TargetControlID="strtdttxt">
</ajaxToolkit:CalendarExtender>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
End Date:
</td>
<td>
<asp:TextBox ID="enddttxt" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="enddttxt_CalendarExtender" runat="server" Format="MMMM d, yyyy"
Enabled="True" TargetControlID="enddttxt">
</ajaxToolkit:CalendarExtender>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
<asp:Button ID="bttnaddproject" runat="server" OnClick="bttnaddproject_Click" Text="Add" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Time Sheet:
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style2" colspan="2" rowspan="5" valign="top">
<asp:GridView ID="GridViewtimesheet" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ShowFooter="True" DataKeyNames="Id"
OnRowCommand="GridViewtimesheet_RowCommand" ShowHeaderWhenEmpty="True" OnRowDataBound="GridViewtimesheet_RowDataBound"
Width="900px" OnRowDeleting="GridViewtimesheet_RowDeleting" ForeColor="Black"
GridLines="None">
<FooterStyle BackColor="Tan" />
<HeaderStyle CssClass="style2" BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:TemplateField HeaderText="Id">
<HeaderTemplate>
<asp:Label ID="lblId" Text="Id" runat="server" />
<asp:Label ID="lbltxt" Text="New->" runat="server" />
<asp:Label ID="lbltxt1" Width="50px" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Eval("Id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProjectName">
<HeaderTemplate>
<asp:Label ID="lblPro" Text="Project Name" runat="server" />
<asp:DropDownList ID="txtNewProjectName" runat="server" DataSourceID="SqlDataSource2"
DataTextField="ProjectName" DataValueField="ProjectName">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="value is must"
ControlToValidate="txtNewProjectName"></asp:RequiredFieldValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="txtProjectName" runat="server" DataSourceID="SqlDataSource2"
DataTextField="ProjectName" DataValueField="ProjectName" SelectedValue='<%# Bind("ProjectName") %>'>
</asp:DropDownList>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblProjectName" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task">
<HeaderTemplate>
<asp:Label ID="lblTa" Text="Task" runat="server" />
<asp:TextBox ID="txtNewTask" runat="Server" ValidationGroup="new" />
<asp:RequiredFieldValidator ID="RFVTask" ControlToValidate="txtNewTask" runat="server"
ErrorMessage="value is must" ValidationGroup="new" />
<ajaxToolkit:AutoCompleteExtender ID="txtNewTask_AutoCompleteExtender" runat="server"
EnableCaching="true" BehaviorID="AutoCompleteTask" TargetControlID="txtNewTask"
ServiceMethod="GetTask" MinimumPrefixLength="3" CompletionSetCount="10" FirstRowSelected="true">
</ajaxToolkit:AutoCompleteExtender>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtTask" runat="server" Text='<%# Eval("Task") %>' />
<ajaxToolkit:AutoCompleteExtender ID="txtTask_AutoCompleteExtender" runat="server"
EnableCaching="true" BehaviorID="AutoCompleteTask1" TargetControlID="txtTask"
ServiceMethod="GetTask" MinimumPrefixLength="3" CompletionSetCount="10" FirstRowSelected="true">
</ajaxToolkit:AutoCompleteExtender>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTask" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hours">
<HeaderTemplate>
<asp:Label ID="lblHo" Text="Hours" runat="server" />
<asp:TextBox ID="txtNewHours" Text="0" Width="50px" runat="Server" Enabled="false" />
<asp:RequiredFieldValidator ID="RequiredFieldValidatorHours" runat="server" ErrorMessage="invalid"
ControlToValidate="txtNewHours"></asp:RequiredFieldValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtHours" runat="server" Width="50px" Text='<%# Eval("Hours") %>'
Enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblHours" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mon">
<HeaderTemplate>
<asp:Label ID="lblMo" Text="Mon" runat="server" />
<asp:TextBox ID="txtNewMon" Width="50px" Text="0" runat="Server" />
<asp:RangeValidator ID="HoursValidationMon" runat="server" Display="static" ControlToValidate="txtNewMon"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtMon" runat="server" Width="50px" Text='<%# Eval("Mon") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblMon" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tue">
<HeaderTemplate>
<asp:Label ID="lblTu" Text="Tue" runat="server" />
<asp:TextBox ID="txtNewTue" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationTue" runat="server" Display="static" ControlToValidate="txtNewTue"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtTue" runat="server" Width="50px" Text='<%# Eval("Tue") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTue" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wed">
<HeaderTemplate>
<asp:Label ID="lblWe" Text="Wed" runat="server" />
<asp:TextBox ID="txtNewWed" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationWed" runat="server" Display="static" ControlToValidate="txtNewWed"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtWed" Width="50px" runat="server" Text='<%# Eval("Wed") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblWed" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Thr">
<HeaderTemplate>
<asp:Label ID="lblTh" Text="Thr" runat="server" />
<asp:TextBox ID="txtNewThr" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationThr" runat="server" Display="static" ControlToValidate="txtNewThr"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtThr" runat="server" Width="50px" Text='<%# Eval("Thr") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblThr" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fri">
<HeaderTemplate>
<asp:Label ID="lblFr" Text="Fri" runat="server" />
<asp:TextBox ID="txtNewFri" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationFri" runat="server" Display="static" ControlToValidate="txtNewFri"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtFri" runat="server" Width="50px" Text='<%# Eval("Fri") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblFri" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sat">
<HeaderTemplate>
<asp:Label ID="lblSa" Text="Sat" runat="server" />
<asp:TextBox ID="txtNewSat" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationSat" runat="server" Display="static" ControlToValidate="txtNewSat"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtSat" runat="server" Width="50px" Text='<%# Eval("Sat") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSat" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sun">
<HeaderTemplate>
<asp:Label ID="lblSu" Text="Sun" runat="server" />
<asp:TextBox ID="txtNewSun" Width="50px" Text="0" runat="Server" />
<asp:RangeValidator ID="HoursValidationSun" runat="server" Display="static" ControlToValidate="txtNewSun"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtSun" Width="50px" runat="server" Text='<%# Eval("Sun") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSun" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete?">
<HeaderTemplate>
<asp:Button ID="bttnInsert" runat="Server" Text="Insert" CommandName="Insert" UseSubmitBehavior="False" />
</HeaderTemplate>
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:Button ID="lnkB" runat="Server" Text="Delete" CommandName="Delete"></asp:Button>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
<br />
<asp:Button ID="bttnAdd" runat="server" Text="Add" OnClick="AddNewRecord" Visible="False" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [ProjectName] FROM [Project]"></asp:SqlDataSource>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [ProjectName] FROM [Project]"></asp:SqlDataSource>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<br />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Logging;
public partial class _Default : System.Web.UI.Page
{
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetTask(string prefixText)
{
return DalUsers.gettask(prefixText);
}
/// <summary>
/// Row Delete from grid view
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">Event Handler</param>
protected void GridViewtimesheet_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string autoid = GridViewtimesheet.DataKeys[e.RowIndex].Value.ToString();
DalUsers.deletetime(autoid);
this.Response.Redirect("#");
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert(' Data Deleted');", true);
}
catch (SqlException ee)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert(" + ee + ");", true);
}
}
/// <summary>
/// Update
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">event</param>
protected void Button2_Click(object sender, EventArgs e)
{
this.Ttl();
int id;
decimal monttl = 0, tuettl = 0, wedttl = 0, thrttl = 0, frittl = 0, satttl = 0, sunttl = 0;
for (int i = 0; i < int.Parse(this.ViewState["count"].ToString()); i++)
{
string a, b, c, d, f, g, h, j, k, l;
a = ((DropDownList)GridViewtimesheet.Rows[i].FindControl("txtProjectName")).SelectedValue.ToString();
b = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTask")).Text.ToString();
c = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtHours")).Text.ToString();
d = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtMon")).Text.ToString();
f = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTue")).Text.ToString();
g = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtWed")).Text.ToString();
h = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtThr")).Text.ToString();
j = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtFri")).Text.ToString();
k = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSat")).Text.ToString();
l = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSun")).Text.ToString();
monttl = Convert.ToDecimal(monttl) + Convert.ToDecimal(d);
tuettl = Convert.ToDecimal(tuettl) + Convert.ToDecimal(f);
wedttl = Convert.ToDecimal(wedttl) + Convert.ToDecimal(g);
thrttl = Convert.ToDecimal(thrttl) + Convert.ToDecimal(h);
frittl = Convert.ToDecimal(frittl) + Convert.ToDecimal(j);
satttl = Convert.ToDecimal(satttl) + Convert.ToDecimal(k);
sunttl = Convert.ToDecimal(sunttl) + Convert.ToDecimal(l);
}
if ((monttl <= 24) && (tuettl <= 24) && (wedttl <= 24) && (thrttl <= 24) && (frittl <= 24) && (satttl <= 24) && (sunttl <= 24))
{
for (int i = 0; i < int.Parse(this.ViewState["count"].ToString()); i++)
{
string a, b, c, d, f, g, h, j, k, l;
a = ((DropDownList)GridViewtimesheet.Rows[i].FindControl("txtProjectName")).SelectedValue.ToString();
b = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTask")).Text.ToString();
c = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtHours")).Text.ToString();
d = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtMon")).Text.ToString();
f = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTue")).Text.ToString();
g = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtWed")).Text.ToString();
h = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtThr")).Text.ToString();
j = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtFri")).Text.ToString();
k = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSat")).Text.ToString();
l = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSun")).Text.ToString();
decimal hours = Convert.ToDecimal(d) + Convert.ToDecimal(f)
+ Convert.ToDecimal(g) + Convert.ToDecimal(h)
+ Convert.ToDecimal(j) + Convert.ToDecimal(k)
+ Convert.ToDecimal(l);
id = int.Parse(((Label)GridViewtimesheet.Rows[i].FindControl("lblID")).Text);
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
var x = (from n in datacontext.Times
where n.Id == id
select n).FirstOrDefault();
x.ProjectName = a;
x.Task = b;
x.Hours = int.Parse(hours.ToString());
x.Mon = int.Parse(d);
x.Tue = int.Parse(f);
x.Wed = int.Parse(g);
x.Thr = int.Parse(h);
x.Fri = int.Parse(j);
x.Sat = int.Parse(k);
x.Sun = int.Parse(l);
datacontext.SubmitChanges();
}
StreamWriter sw = new StreamWriter("C:\\Users\\Himanshu\\Desktop\\test.txt", true);
sw.Write("Data Updated For TimeSheet " + DateTime.Now.ToString() + "\r\n");
sw.Close();
Logger.Write("Informational message", "EventLog", 2, 100);
}
this.Response.Redirect("#");
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Updation successfully');", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Invalid');", true);
}
}
/// <summary>
/// Row Command as Insert
/// </summary>
/// <param name="sender">Object</param>
/// <param name="e">Event</param>
protected void GridViewtimesheet_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Insert"))
{
string txtNewProjectName = (GridViewtimesheet.HeaderRow.FindControl("txtNewProjectName") as DropDownList).SelectedValue.ToString();
string txtNewTask = (GridViewtimesheet.HeaderRow.FindControl("txtNewTask") as TextBox).Text.ToString();
string txtNewHours = (GridViewtimesheet.HeaderRow.FindControl("txtNewHours") as TextBox).Text.ToString();
string txtNewMon = (GridViewtimesheet.HeaderRow.FindControl("txtNewMon") as TextBox).Text.ToString();
string txtNewTue = (GridViewtimesheet.HeaderRow.FindControl("txtNewTue") as TextBox).Text.ToString();
string txtNewWed = (GridViewtimesheet.HeaderRow.FindControl("txtNewWed") as TextBox).Text.ToString();
string txtNewThr = (GridViewtimesheet.HeaderRow.FindControl("txtNewThr") as TextBox).Text.ToString();
string txtNewFri = (GridViewtimesheet.HeaderRow.FindControl("txtNewFri") as TextBox).Text.ToString();
string txtNewSat = (GridViewtimesheet.HeaderRow.FindControl("txtNewSat") as TextBox).Text.ToString();
string txtNewSun = (GridViewtimesheet.HeaderRow.FindControl("txtNewSun") as TextBox).Text.ToString();
decimal hours = Convert.ToDecimal(txtNewMon) + Convert.ToDecimal(txtNewTue)
+ Convert.ToDecimal(txtNewWed) + Convert.ToDecimal(txtNewThr)
+ Convert.ToDecimal(txtNewFri) + Convert.ToDecimal(txtNewSat)
+ Convert.ToDecimal(txtNewSun);
this.InsertProduct(txtNewProjectName, txtNewTask, hours.ToString(), txtNewMon, txtNewTue, txtNewWed, txtNewThr, txtNewFri, txtNewSat, txtNewSun);
this.ViewState["Products"] = null;
this.BindData();
}
}
/// <summary>
/// Insert New Record
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">event</param>
protected void AddNewRecord(object sender, EventArgs e)
{
GridViewtimesheet.ShowHeader = true;
this.BindData();
}
/// <summary>
/// Page Load
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">event</param>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindData();
}
}
int total = 0, total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0, total6 = 0, total7 = 0;
/// <summary>
/// Databound GridView
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">GridViewRowEventArgs</param>
protected void GridViewtimesheet_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Hours"));
total1 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Mon"));
total2 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Tue"));
total3 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Wed"));
total4 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Thr"));
total5 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Fri"));
total6 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Sat"));
total7 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Sun"));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblHours0 = (Label)e.Row.FindControl("lblHours");
lblHours0.Text = total.ToString();
Label lblHours1 = (Label)e.Row.FindControl("lblMon");
lblHours1.Text = total1.ToString();
Label lblHours2 = (Label)e.Row.FindControl("lblTue");
lblHours2.Text = total2.ToString();
Label lblHours3 = (Label)e.Row.FindControl("lblWed");
lblHours3.Text = total3.ToString();
Label lblHours4 = (Label)e.Row.FindControl("lblThr");
lblHours4.Text = total4.ToString();
Label lblHours5 = (Label)e.Row.FindControl("lblFri");
lblHours5.Text = total5.ToString();
Label lblHours6 = (Label)e.Row.FindControl("lblSat");
lblHours6.Text = total6.ToString();
Label lblHours7 = (Label)e.Row.FindControl("lblSun");
lblHours7.Text = total7.ToString();
this.ViewState["mon"] = lblHours1.Text.ToString();
this.ViewState["tue"] = lblHours2.Text.ToString();
this.ViewState["wed"] = lblHours3.Text.ToString();
this.ViewState["thr"] = lblHours4.Text.ToString();
this.ViewState["fri"] = lblHours5.Text.ToString();
this.ViewState["sat"] = lblHours6.Text.ToString();
this.ViewState["sun"] = lblHours7.Text.ToString();
}
}
/// <summary>
/// This event will handle the click on bttnaddproject
/// </summary>
/// <param name="sender">Control</param>
/// <param name="e">Event Arg</param>
protected void bttnaddproject_Click(object sender, EventArgs e)
{
try
{
Project p = new Project();
p.ProjectName = prjcttxt.Text;
p.Manager = mgrtxt.Text;
p.StartDate = DateTime.Parse(strtdttxt.Text);
p.EndDate = DateTime.Parse(enddttxt.Text);
p.ModBy = "Himanshu";
p.MadDate = DateTime.Now;
DalUsers.insertPtoject(p);
Response.Redirect("#");
}
catch
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Invalid');", true);
}
}
/// <summary>
/// Bind Data in GridView
/// </summary>
private void BindData()
{
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
var x = from n in datacontext.Times select n;
GridViewtimesheet.DataSource = x;
GridViewtimesheet.DataBind();
}
}
/// <summary>
/// Insert New Data
/// </summary>
/// <param name="projectname">Project</param>
/// <param name="task">Task</param>
/// <param name="hours">Hours</param>
/// <param name="mon">Monday</param>
/// <param name="tue">Tuesday</param>
/// <param name="wed">Wednesday</param>
/// <param name="thr">Thursday</param>
/// <param name="fri">Friday</param>
/// <param name="sat">Saturday</param>
/// <param name="sun">Sunday</param>
private void InsertProduct(string projectname, string task, string hours, string mon, string tue, string wed, string thr, string fri, string sat, string sun)
{
decimal monttl = Convert.ToDecimal(mon) + Convert.ToDecimal((null != this.ViewState["mon"]) ? this.ViewState["mon"].ToString() : 0.ToString());
decimal tuettl = Convert.ToDecimal(tue) + Convert.ToDecimal((null != this.ViewState["tue"]) ? this.ViewState["tue"].ToString() : 0.ToString());
decimal wedttl = Convert.ToDecimal(wed) + Convert.ToDecimal((null != this.ViewState["wed"]) ? this.ViewState["wed"].ToString() : 0.ToString());
decimal thrttl = Convert.ToDecimal(thr) + Convert.ToDecimal((null != this.ViewState["thr"]) ? this.ViewState["thr"].ToString() : 0.ToString());
decimal frittl = Convert.ToDecimal(fri) + Convert.ToDecimal((null != this.ViewState["fri"]) ? this.ViewState["fri"].ToString() : 0.ToString());
decimal satttl = Convert.ToDecimal(sat) + Convert.ToDecimal((null != this.ViewState["sat"]) ? this.ViewState["sat"].ToString() : 0.ToString());
decimal sunttl = Convert.ToDecimal(sun) + Convert.ToDecimal((null != this.ViewState["sun"]) ? this.ViewState["sun"].ToString() : 0.ToString());
this.Page.Validate();
if ((monttl <= 24) && (tuettl <= 24) && (wedttl <= 24) && (thrttl <= 24) && (frittl <= 24) && (satttl <= 24) && (sunttl <= 24) && Page.IsValid == true)
{
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
Time t = new Time();
t.ProjectName = projectname;
t.Task = task;
t.Hours = int.Parse(hours);
t.Mon = int.Parse(mon);
t.Tue = int.Parse(tue);
t.Wed = int.Parse(wed);
t.Thr = int.Parse(thr);
t.Fri = int.Parse(fri);
t.Sat = int.Parse(sat);
t.Sun = int.Parse(sun);
t.ModBy = "Himanshu";
t.ModDate = DateTime.Now;
DalUsers.inserttime(t);
this.Response.Redirect("#");
}
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Insertion successfully.');", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Invalid');", true);
}
}
/// <summary>
/// Total Row In GridView
/// </summary>
private void Ttl()
{
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
var x = (from n in datacontext.Times
select n).Count();
this.ViewState["count"] = x;
}
}
}
Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
source="Enterprise Library Logging" formatter="Text Formatter"
log="" machineName="." traceOutputOptions="None" />
<add name="Event Log Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
source="Enterprise Library Logging" formatter="Text Formatter"
log="Himanshu's" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Event Log Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="testConnectionString" connectionString="uid=sa;password=123;database=test"/>
</connectionStrings>
</configuration>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 50%;
margin-left: 0;
padding: 0;
}
.style3
{
width: 274px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td colspan="2">
Add New Project:
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Project Name:
</td>
<td>
<asp:TextBox ID="prjcttxt" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Manager Name:
</td>
<td>
<asp:TextBox ID="mgrtxt" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Start Date:
</td>
<td>
<asp:TextBox ID="strtdttxt" runat="server" Style="margin-bottom: 0px"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="strtdttxt_CalendarExtender" runat="server" Format="MMMM d, yyyy"
Enabled="true" TargetControlID="strtdttxt">
</ajaxToolkit:CalendarExtender>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
End Date:
</td>
<td>
<asp:TextBox ID="enddttxt" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="enddttxt_CalendarExtender" runat="server" Format="MMMM d, yyyy"
Enabled="True" TargetControlID="enddttxt">
</ajaxToolkit:CalendarExtender>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
<asp:Button ID="bttnaddproject" runat="server" OnClick="bttnaddproject_Click" Text="Add" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
Time Sheet:
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style2" colspan="2" rowspan="5" valign="top">
<asp:GridView ID="GridViewtimesheet" runat="server" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow"
BorderColor="Tan" BorderWidth="1px" CellPadding="2" ShowFooter="True" DataKeyNames="Id"
OnRowCommand="GridViewtimesheet_RowCommand" ShowHeaderWhenEmpty="True" OnRowDataBound="GridViewtimesheet_RowDataBound"
Width="900px" OnRowDeleting="GridViewtimesheet_RowDeleting" ForeColor="Black"
GridLines="None">
<FooterStyle BackColor="Tan" />
<HeaderStyle CssClass="style2" BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<Columns>
<asp:TemplateField HeaderText="Id">
<HeaderTemplate>
<asp:Label ID="lblId" Text="Id" runat="server" />
<asp:Label ID="lbltxt" Text="New->" runat="server" />
<asp:Label ID="lbltxt1" Width="50px" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%#Eval("Id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ProjectName">
<HeaderTemplate>
<asp:Label ID="lblPro" Text="Project Name" runat="server" />
<asp:DropDownList ID="txtNewProjectName" runat="server" DataSourceID="SqlDataSource2"
DataTextField="ProjectName" DataValueField="ProjectName">
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="value is must"
ControlToValidate="txtNewProjectName"></asp:RequiredFieldValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:DropDownList ID="txtProjectName" runat="server" DataSourceID="SqlDataSource2"
DataTextField="ProjectName" DataValueField="ProjectName" SelectedValue='<%# Bind("ProjectName") %>'>
</asp:DropDownList>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblProjectName" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Task">
<HeaderTemplate>
<asp:Label ID="lblTa" Text="Task" runat="server" />
<asp:TextBox ID="txtNewTask" runat="Server" ValidationGroup="new" />
<asp:RequiredFieldValidator ID="RFVTask" ControlToValidate="txtNewTask" runat="server"
ErrorMessage="value is must" ValidationGroup="new" />
<ajaxToolkit:AutoCompleteExtender ID="txtNewTask_AutoCompleteExtender" runat="server"
EnableCaching="true" BehaviorID="AutoCompleteTask" TargetControlID="txtNewTask"
ServiceMethod="GetTask" MinimumPrefixLength="3" CompletionSetCount="10" FirstRowSelected="true">
</ajaxToolkit:AutoCompleteExtender>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtTask" runat="server" Text='<%# Eval("Task") %>' />
<ajaxToolkit:AutoCompleteExtender ID="txtTask_AutoCompleteExtender" runat="server"
EnableCaching="true" BehaviorID="AutoCompleteTask1" TargetControlID="txtTask"
ServiceMethod="GetTask" MinimumPrefixLength="3" CompletionSetCount="10" FirstRowSelected="true">
</ajaxToolkit:AutoCompleteExtender>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTask" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hours">
<HeaderTemplate>
<asp:Label ID="lblHo" Text="Hours" runat="server" />
<asp:TextBox ID="txtNewHours" Text="0" Width="50px" runat="Server" Enabled="false" />
<asp:RequiredFieldValidator ID="RequiredFieldValidatorHours" runat="server" ErrorMessage="invalid"
ControlToValidate="txtNewHours"></asp:RequiredFieldValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtHours" runat="server" Width="50px" Text='<%# Eval("Hours") %>'
Enabled="false" />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblHours" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mon">
<HeaderTemplate>
<asp:Label ID="lblMo" Text="Mon" runat="server" />
<asp:TextBox ID="txtNewMon" Width="50px" Text="0" runat="Server" />
<asp:RangeValidator ID="HoursValidationMon" runat="server" Display="static" ControlToValidate="txtNewMon"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtMon" runat="server" Width="50px" Text='<%# Eval("Mon") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblMon" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tue">
<HeaderTemplate>
<asp:Label ID="lblTu" Text="Tue" runat="server" />
<asp:TextBox ID="txtNewTue" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationTue" runat="server" Display="static" ControlToValidate="txtNewTue"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtTue" runat="server" Width="50px" Text='<%# Eval("Tue") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblTue" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Wed">
<HeaderTemplate>
<asp:Label ID="lblWe" Text="Wed" runat="server" />
<asp:TextBox ID="txtNewWed" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationWed" runat="server" Display="static" ControlToValidate="txtNewWed"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtWed" Width="50px" runat="server" Text='<%# Eval("Wed") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblWed" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Thr">
<HeaderTemplate>
<asp:Label ID="lblTh" Text="Thr" runat="server" />
<asp:TextBox ID="txtNewThr" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationThr" runat="server" Display="static" ControlToValidate="txtNewThr"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtThr" runat="server" Width="50px" Text='<%# Eval("Thr") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblThr" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Fri">
<HeaderTemplate>
<asp:Label ID="lblFr" Text="Fri" runat="server" />
<asp:TextBox ID="txtNewFri" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationFri" runat="server" Display="static" ControlToValidate="txtNewFri"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtFri" runat="server" Width="50px" Text='<%# Eval("Fri") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblFri" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sat">
<HeaderTemplate>
<asp:Label ID="lblSa" Text="Sat" runat="server" />
<asp:TextBox ID="txtNewSat" Text="0" Width="50px" runat="Server" />
<asp:RangeValidator ID="HoursValidationSat" runat="server" Display="static" ControlToValidate="txtNewSat"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtSat" runat="server" Width="50px" Text='<%# Eval("Sat") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSat" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sun">
<HeaderTemplate>
<asp:Label ID="lblSu" Text="Sun" runat="server" />
<asp:TextBox ID="txtNewSun" Width="50px" Text="0" runat="Server" />
<asp:RangeValidator ID="HoursValidationSun" runat="server" Display="static" ControlToValidate="txtNewSun"
ErrorMessage="not valid" Type="Integer" MinimumValue="0" MaximumValue="24">
</asp:RangeValidator>
</HeaderTemplate>
<ItemTemplate>
<asp:TextBox ID="txtSun" Width="50px" runat="server" Text='<%# Eval("Sun") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSun" Width="50px" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete?">
<HeaderTemplate>
<asp:Button ID="bttnInsert" runat="Server" Text="Insert" CommandName="Insert" UseSubmitBehavior="False" />
</HeaderTemplate>
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:Button ID="lnkB" runat="Server" Text="Delete" CommandName="Delete"></asp:Button>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
</asp:GridView>
<br />
<asp:Button ID="bttnAdd" runat="server" Text="Add" OnClick="AddNewRecord" Visible="False" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [ProjectName] FROM [Project]"></asp:SqlDataSource>
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [ProjectName] FROM [Project]"></asp:SqlDataSource>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<br />
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>
Default.aspx.cs:
using System;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Logging;
public partial class _Default : System.Web.UI.Page
{
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetTask(string prefixText)
{
return DalUsers.gettask(prefixText);
}
/// <summary>
/// Row Delete from grid view
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">Event Handler</param>
protected void GridViewtimesheet_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
string autoid = GridViewtimesheet.DataKeys[e.RowIndex].Value.ToString();
DalUsers.deletetime(autoid);
this.Response.Redirect("#");
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert(' Data Deleted');", true);
}
catch (SqlException ee)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert(" + ee + ");", true);
}
}
/// <summary>
/// Update
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">event</param>
protected void Button2_Click(object sender, EventArgs e)
{
this.Ttl();
int id;
decimal monttl = 0, tuettl = 0, wedttl = 0, thrttl = 0, frittl = 0, satttl = 0, sunttl = 0;
for (int i = 0; i < int.Parse(this.ViewState["count"].ToString()); i++)
{
string a, b, c, d, f, g, h, j, k, l;
a = ((DropDownList)GridViewtimesheet.Rows[i].FindControl("txtProjectName")).SelectedValue.ToString();
b = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTask")).Text.ToString();
c = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtHours")).Text.ToString();
d = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtMon")).Text.ToString();
f = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTue")).Text.ToString();
g = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtWed")).Text.ToString();
h = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtThr")).Text.ToString();
j = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtFri")).Text.ToString();
k = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSat")).Text.ToString();
l = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSun")).Text.ToString();
monttl = Convert.ToDecimal(monttl) + Convert.ToDecimal(d);
tuettl = Convert.ToDecimal(tuettl) + Convert.ToDecimal(f);
wedttl = Convert.ToDecimal(wedttl) + Convert.ToDecimal(g);
thrttl = Convert.ToDecimal(thrttl) + Convert.ToDecimal(h);
frittl = Convert.ToDecimal(frittl) + Convert.ToDecimal(j);
satttl = Convert.ToDecimal(satttl) + Convert.ToDecimal(k);
sunttl = Convert.ToDecimal(sunttl) + Convert.ToDecimal(l);
}
if ((monttl <= 24) && (tuettl <= 24) && (wedttl <= 24) && (thrttl <= 24) && (frittl <= 24) && (satttl <= 24) && (sunttl <= 24))
{
for (int i = 0; i < int.Parse(this.ViewState["count"].ToString()); i++)
{
string a, b, c, d, f, g, h, j, k, l;
a = ((DropDownList)GridViewtimesheet.Rows[i].FindControl("txtProjectName")).SelectedValue.ToString();
b = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTask")).Text.ToString();
c = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtHours")).Text.ToString();
d = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtMon")).Text.ToString();
f = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtTue")).Text.ToString();
g = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtWed")).Text.ToString();
h = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtThr")).Text.ToString();
j = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtFri")).Text.ToString();
k = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSat")).Text.ToString();
l = ((TextBox)GridViewtimesheet.Rows[i].FindControl("txtSun")).Text.ToString();
decimal hours = Convert.ToDecimal(d) + Convert.ToDecimal(f)
+ Convert.ToDecimal(g) + Convert.ToDecimal(h)
+ Convert.ToDecimal(j) + Convert.ToDecimal(k)
+ Convert.ToDecimal(l);
id = int.Parse(((Label)GridViewtimesheet.Rows[i].FindControl("lblID")).Text);
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
var x = (from n in datacontext.Times
where n.Id == id
select n).FirstOrDefault();
x.ProjectName = a;
x.Task = b;
x.Hours = int.Parse(hours.ToString());
x.Mon = int.Parse(d);
x.Tue = int.Parse(f);
x.Wed = int.Parse(g);
x.Thr = int.Parse(h);
x.Fri = int.Parse(j);
x.Sat = int.Parse(k);
x.Sun = int.Parse(l);
datacontext.SubmitChanges();
}
StreamWriter sw = new StreamWriter("C:\\Users\\Himanshu\\Desktop\\test.txt", true);
sw.Write("Data Updated For TimeSheet " + DateTime.Now.ToString() + "\r\n");
sw.Close();
Logger.Write("Informational message", "EventLog", 2, 100);
}
this.Response.Redirect("#");
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Updation successfully');", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Invalid');", true);
}
}
/// <summary>
/// Row Command as Insert
/// </summary>
/// <param name="sender">Object</param>
/// <param name="e">Event</param>
protected void GridViewtimesheet_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Insert"))
{
string txtNewProjectName = (GridViewtimesheet.HeaderRow.FindControl("txtNewProjectName") as DropDownList).SelectedValue.ToString();
string txtNewTask = (GridViewtimesheet.HeaderRow.FindControl("txtNewTask") as TextBox).Text.ToString();
string txtNewHours = (GridViewtimesheet.HeaderRow.FindControl("txtNewHours") as TextBox).Text.ToString();
string txtNewMon = (GridViewtimesheet.HeaderRow.FindControl("txtNewMon") as TextBox).Text.ToString();
string txtNewTue = (GridViewtimesheet.HeaderRow.FindControl("txtNewTue") as TextBox).Text.ToString();
string txtNewWed = (GridViewtimesheet.HeaderRow.FindControl("txtNewWed") as TextBox).Text.ToString();
string txtNewThr = (GridViewtimesheet.HeaderRow.FindControl("txtNewThr") as TextBox).Text.ToString();
string txtNewFri = (GridViewtimesheet.HeaderRow.FindControl("txtNewFri") as TextBox).Text.ToString();
string txtNewSat = (GridViewtimesheet.HeaderRow.FindControl("txtNewSat") as TextBox).Text.ToString();
string txtNewSun = (GridViewtimesheet.HeaderRow.FindControl("txtNewSun") as TextBox).Text.ToString();
decimal hours = Convert.ToDecimal(txtNewMon) + Convert.ToDecimal(txtNewTue)
+ Convert.ToDecimal(txtNewWed) + Convert.ToDecimal(txtNewThr)
+ Convert.ToDecimal(txtNewFri) + Convert.ToDecimal(txtNewSat)
+ Convert.ToDecimal(txtNewSun);
this.InsertProduct(txtNewProjectName, txtNewTask, hours.ToString(), txtNewMon, txtNewTue, txtNewWed, txtNewThr, txtNewFri, txtNewSat, txtNewSun);
this.ViewState["Products"] = null;
this.BindData();
}
}
/// <summary>
/// Insert New Record
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">event</param>
protected void AddNewRecord(object sender, EventArgs e)
{
GridViewtimesheet.ShowHeader = true;
this.BindData();
}
/// <summary>
/// Page Load
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">event</param>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindData();
}
}
int total = 0, total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0, total6 = 0, total7 = 0;
/// <summary>
/// Databound GridView
/// </summary>
/// <param name="sender">object</param>
/// <param name="e">GridViewRowEventArgs</param>
protected void GridViewtimesheet_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
total += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Hours"));
total1 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Mon"));
total2 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Tue"));
total3 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Wed"));
total4 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Thr"));
total5 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Fri"));
total6 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Sat"));
total7 += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Sun"));
}
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblHours0 = (Label)e.Row.FindControl("lblHours");
lblHours0.Text = total.ToString();
Label lblHours1 = (Label)e.Row.FindControl("lblMon");
lblHours1.Text = total1.ToString();
Label lblHours2 = (Label)e.Row.FindControl("lblTue");
lblHours2.Text = total2.ToString();
Label lblHours3 = (Label)e.Row.FindControl("lblWed");
lblHours3.Text = total3.ToString();
Label lblHours4 = (Label)e.Row.FindControl("lblThr");
lblHours4.Text = total4.ToString();
Label lblHours5 = (Label)e.Row.FindControl("lblFri");
lblHours5.Text = total5.ToString();
Label lblHours6 = (Label)e.Row.FindControl("lblSat");
lblHours6.Text = total6.ToString();
Label lblHours7 = (Label)e.Row.FindControl("lblSun");
lblHours7.Text = total7.ToString();
this.ViewState["mon"] = lblHours1.Text.ToString();
this.ViewState["tue"] = lblHours2.Text.ToString();
this.ViewState["wed"] = lblHours3.Text.ToString();
this.ViewState["thr"] = lblHours4.Text.ToString();
this.ViewState["fri"] = lblHours5.Text.ToString();
this.ViewState["sat"] = lblHours6.Text.ToString();
this.ViewState["sun"] = lblHours7.Text.ToString();
}
}
/// <summary>
/// This event will handle the click on bttnaddproject
/// </summary>
/// <param name="sender">Control</param>
/// <param name="e">Event Arg</param>
protected void bttnaddproject_Click(object sender, EventArgs e)
{
try
{
Project p = new Project();
p.ProjectName = prjcttxt.Text;
p.Manager = mgrtxt.Text;
p.StartDate = DateTime.Parse(strtdttxt.Text);
p.EndDate = DateTime.Parse(enddttxt.Text);
p.ModBy = "Himanshu";
p.MadDate = DateTime.Now;
DalUsers.insertPtoject(p);
Response.Redirect("#");
}
catch
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Invalid');", true);
}
}
/// <summary>
/// Bind Data in GridView
/// </summary>
private void BindData()
{
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
var x = from n in datacontext.Times select n;
GridViewtimesheet.DataSource = x;
GridViewtimesheet.DataBind();
}
}
/// <summary>
/// Insert New Data
/// </summary>
/// <param name="projectname">Project</param>
/// <param name="task">Task</param>
/// <param name="hours">Hours</param>
/// <param name="mon">Monday</param>
/// <param name="tue">Tuesday</param>
/// <param name="wed">Wednesday</param>
/// <param name="thr">Thursday</param>
/// <param name="fri">Friday</param>
/// <param name="sat">Saturday</param>
/// <param name="sun">Sunday</param>
private void InsertProduct(string projectname, string task, string hours, string mon, string tue, string wed, string thr, string fri, string sat, string sun)
{
decimal monttl = Convert.ToDecimal(mon) + Convert.ToDecimal((null != this.ViewState["mon"]) ? this.ViewState["mon"].ToString() : 0.ToString());
decimal tuettl = Convert.ToDecimal(tue) + Convert.ToDecimal((null != this.ViewState["tue"]) ? this.ViewState["tue"].ToString() : 0.ToString());
decimal wedttl = Convert.ToDecimal(wed) + Convert.ToDecimal((null != this.ViewState["wed"]) ? this.ViewState["wed"].ToString() : 0.ToString());
decimal thrttl = Convert.ToDecimal(thr) + Convert.ToDecimal((null != this.ViewState["thr"]) ? this.ViewState["thr"].ToString() : 0.ToString());
decimal frittl = Convert.ToDecimal(fri) + Convert.ToDecimal((null != this.ViewState["fri"]) ? this.ViewState["fri"].ToString() : 0.ToString());
decimal satttl = Convert.ToDecimal(sat) + Convert.ToDecimal((null != this.ViewState["sat"]) ? this.ViewState["sat"].ToString() : 0.ToString());
decimal sunttl = Convert.ToDecimal(sun) + Convert.ToDecimal((null != this.ViewState["sun"]) ? this.ViewState["sun"].ToString() : 0.ToString());
this.Page.Validate();
if ((monttl <= 24) && (tuettl <= 24) && (wedttl <= 24) && (thrttl <= 24) && (frittl <= 24) && (satttl <= 24) && (sunttl <= 24) && Page.IsValid == true)
{
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
Time t = new Time();
t.ProjectName = projectname;
t.Task = task;
t.Hours = int.Parse(hours);
t.Mon = int.Parse(mon);
t.Tue = int.Parse(tue);
t.Wed = int.Parse(wed);
t.Thr = int.Parse(thr);
t.Fri = int.Parse(fri);
t.Sat = int.Parse(sat);
t.Sun = int.Parse(sun);
t.ModBy = "Himanshu";
t.ModDate = DateTime.Now;
DalUsers.inserttime(t);
this.Response.Redirect("#");
}
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Insertion successfully.');", true);
}
else
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "msgbox", "alert('Data Invalid');", true);
}
}
/// <summary>
/// Total Row In GridView
/// </summary>
private void Ttl()
{
using (DataClassesDataContext datacontext = new DataClassesDataContext())
{
var x = (from n in datacontext.Times
select n).Count();
this.ViewState["count"] = x;
}
}
}
Web.config:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
source="Enterprise Library Logging" formatter="Text Formatter"
log="" machineName="." traceOutputOptions="None" />
<add name="Event Log Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
source="Enterprise Library Logging" formatter="Text Formatter"
log="Himanshu's" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=null"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
EventId: {eventid}{newline}
Severity: {severity}{newline}
Title:{title}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Event Log Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="testConnectionString" connectionString="uid=sa;password=123;database=test"/>
</connectionStrings>
</configuration>
Thanx...
ReplyDeleteIts Working as you said...!!
This comment has been removed by the author.
DeleteThis comment has been removed by the author.
Deletecan u please attach this code i need your help #Anil Saini
Deletecan u pls attach the source code
ReplyDeleteTired alot to find but as my system was crashed and no backup was there. But it was working fine. I have used this in my project as well.
Deletecan u please attach full source code......
ReplyDeleteTired alot to find but as my system was crashed and no backup was there. But it was working fine. I have used this in my project as well.
Delete