TimeSheet webpart solution in SharePoint
I had different design approach to make this things happens. However the simple way was to use the inbuilt feature in SharePoint and then added the out of the box feature. It needs to have one GUI where employee could able to put time sheet data, one list item as repository of data, and a workflow to activate the flow.
Front end GUI can be implementing through time sheet webpart. So the first task is to build one time sheet webpart. Create on SharePoint webpart project using VS.NET 2008 and name this webpart as TimeSheet.
Add reference the namespaces Microsoft.SharePoint, Microsoft.SharePoint.WebControls and System.Web.UI.WebControls.
Inherit the control below in the TimeSheet class (make sure you inherit System.Web.UI.WebControls.WebParts.WebPart in TimeSheet class).
Actual code need to be pluin uneder CreateChildControls() method.
public class TimeSheet : System.Web.UI.WebControls.WebParts.WebPar
{
DropDownList WeekCalendar;
DropDownList MemberTitle;
TextBox txtEmpName;
TextBox txtManagerName;
TextBox txtEmailAddress;
TextBox txtPhone;
int _ColsSpan = 9;
TextBox MonStartTime;
TextBox MonLunchOut;
TextBox MonLunchIn;
TextBox MonFinishTime;
TextBox MonTotalHours;
TextBox MonChrgblHrs;
TextBox MonTotal;
TextBox MonNote;
TextBox TueStartTime;
TextBox TueLunchOut;
TextBox TueLunchIn;
TextBox TueFinishTime;
TextBox TueTotalHours;
TextBox TueChrgblHrs;
TextBox TueTotal;
TextBox TueNote;
TextBox WedStartTime;
TextBox WedLunchOut;
TextBox WedLunchIn;
TextBox WedFinishTime;
TextBox WedTotalHours;
TextBox WedChrgblHrs;
TextBox WedTotal;
TextBox WedNote;
TextBox ThruStartTime;
TextBox ThruLunchOut;
TextBox ThruLunchIn;
TextBox ThruFinishTime;
TextBox ThruTotalHours;
TextBox ThruChrgblHrs;
TextBox ThruTotal;
TextBox ThruNote;
TextBox FriStartTime;
TextBox FriLunchOut;
TextBox FriLunchIn;
TextBox FriFinishTime;
TextBox FriTotalHours;
TextBox FriChrgblHrs;
TextBox FriTotal;
TextBox FriNote;
TextBox SatStartTime;
TextBox SatLunchOut;
TextBox SatLunchIn;
TextBox SatFinishTime;
TextBox SatTotalHours;
TextBox SatChrgblHrs;
TextBox SatTotal;
TextBox SatNote;
TextBox SunStartTime;
TextBox SunLunchOut;
TextBox SunLunchIn;
TextBox SunFinishTime;
TextBox SunTotalHours;
TextBox SunChrgblHrs;
TextBox SunTotal;
TextBox SunNote;
Button btnSendMessage;
public TimeSheet()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls();
SPWeb _SPWeb = SPContext.Current.Web;
SPUser _SPUser = _SPWeb.CurrentUser;
Table _TableHeader;
TableRow tr;
TableCell tc;
// A table that is used to layout the controls
_TableHeader = new Table();
// Label TimeSheet Heading
tr = new TableRow();
tc = new TableCell();
tr.BackColor = System.Drawing.Color.AliceBlue;
tc.ColumnSpan = _ColsSpan;
tc.HorizontalAlign = HorizontalAlign.Right;
tc.VerticalAlign = VerticalAlign.Top;
Label lblInstructions = new Label();
lblInstructions.Font.Size = (FontUnit)FontUnit.Medium;
lblInstructions.Text = “Time Sheet”;
tc.Controls.Add(lblInstructions);
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
// Label Company Infomation
tr = new TableRow();
tc = new TableCell();
tc.ColumnSpan = _ColsSpan;
tc.HorizontalAlign = HorizontalAlign.Left;
tc.VerticalAlign = VerticalAlign.Top;
tc.ForeColor = System.Drawing.Color.Crimson;
Label lblCompanyInfo = new Label();
lblCompanyInfo.Text = “Product2You.<br>10 Bank St, Suite 605,<br>Stamford, CT 06901<br>USA”;
tc.Controls.Add(lblCompanyInfo);
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
//Blue color
tr = new TableRow();
tr.BackColor = System.Drawing.Color.Blue;
tc = new TableCell();
tc.ColumnSpan = _ColsSpan;
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
// WorkWeek label
tr = new TableRow();
tc = new TableCell();
tc.ColumnSpan = _ColsSpan;
tc.Style["padding-top"] = “4px”;
tc.VerticalAlign = VerticalAlign.Top;
tc.HorizontalAlign = HorizontalAlign.Right;
Label lblWorkWeek = new Label();
lblWorkWeek.Text = “Work Week: ”;
tc.Controls.Add(lblWorkWeek);
tr.Controls.Add(tc);
WeekCalendar = new DropDownList();
WeekCalendar.SelectedIndexChanged += new EventHandler(WeekCalendar_SelectedIndexChanged);
WeekCalendar.ID = “WeekCalendar”;
WeekCalendar.Width = Unit.Pixel(200);
PopulateWeekends(WeekCalendar);
tc.Controls.Add(WeekCalendar);
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
// Emplyee label
tr = new TableRow();
tc = new TableCell();
tc.ColumnSpan = 5;
tc.Style["padding-top"] = “4px”;
tc.VerticalAlign = VerticalAlign.Top;
tc.HorizontalAlign = HorizontalAlign.Left;
Label lblEmployee = new Label();
lblEmployee.Text = “Employee: ”;
tc.Controls.Add(lblEmployee);
tr.Controls.Add(tc);
MemberTitle = new DropDownList();
MemberTitle.ID = “MemberTitle”;
MemberTitle.Width = Unit.Pixel(50);
MemberTitle.Items.Add(“Mr.”);
MemberTitle.Items.Add(“Ms.”);
tc.Controls.Add(MemberTitle);
tr.Controls.Add(tc);
txtEmpName = new TextBox();
txtEmpName.ID = “txtEmpName”;
txtEmpName.Width = Unit.Pixel(180);
txtEmpName.Text = _SPUser.Name;
tc.Controls.Add(txtEmpName);
tr.Controls.Add(tc);
//————————————-
tc = new TableCell();
tc.ColumnSpan = 4;
tc.VerticalAlign = VerticalAlign.Top;
tc.HorizontalAlign = HorizontalAlign.Left;
Label lblEmpPhone = new Label();
lblEmpPhone.Text = “ Emp phone: ”;
tc.Controls.Add(lblEmpPhone);
tr.Controls.Add(tc);
txtPhone = new TextBox();
txtPhone.ID = “txtPhone”;
txtPhone.Width = Unit.Pixel(140);
tc.Controls.Add(txtPhone);
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
// Manager label
tr = new TableRow();
tc = new TableCell();
tc.ColumnSpan = 5;
tc.Style["padding-top"] = “4px”;
tc.VerticalAlign = VerticalAlign.Top;
tc.HorizontalAlign = HorizontalAlign.Left;
Label lblManager = new Label();
lblManager.Text = “Emp Manager:    ”;
tc.Controls.Add(lblManager);
tr.Controls.Add(tc);
txtManagerName = new TextBox();
txtManagerName.ID = “txtManagerName”;
txtManagerName.Width = Unit.Pixel(150);
tc.Controls.Add(txtManagerName);
tr.Controls.Add(tc);
//————————————-
tc = new TableCell();
tc.ColumnSpan = 4;
tc.VerticalAlign = VerticalAlign.Top;
tc.HorizontalAlign = HorizontalAlign.Left;
Label lblEmpEmail = new Label();
lblEmpEmail.Text = “ Emp email:  ”;
tc.Controls.Add(lblEmpEmail);
tr.Controls.Add(tc);
txtEmailAddress = new TextBox();
txtEmailAddress.ID = “txtEmailAddress”;
txtEmailAddress.Width = Unit.Pixel(100);
tc.Controls.Add(txtEmailAddress);
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
//Blue color
tr = new TableRow();
tr.BackColor = System.Drawing.Color.Blue;
tc = new TableCell();
tc.ColumnSpan = _ColsSpan;
tr.Controls.Add(tc);
_TableHeader.Controls.Add(tr);
this.Controls.Add(_TableHeader);
//End Header Table
//Start DataTable
Table _TableContent;
TableRow _TRContent;
TableCell _TCContent;
_TableContent = new Table();
// Header Column
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
//Day
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblDay = new Label();
lblDay.Text = “Day”;
_TCContent.Controls.Add(lblDay);
_TRContent.Controls.Add(_TCContent);
//Start Time
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblStartTime = new Label();
lblStartTime.Text = “Start Time”;
_TCContent.Controls.Add(lblStartTime);
_TRContent.Controls.Add(_TCContent);
//Lunch Out
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblLunchOut = new Label();
lblLunchOut.Text = “Lunch Out”;
_TCContent.Controls.Add(lblLunchOut);
_TRContent.Controls.Add(_TCContent);
//Lunch In
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblLunchIn = new Label();
lblLunchIn.Text = “Lunch In”;
_TCContent.Controls.Add(lblLunchIn);
_TRContent.Controls.Add(_TCContent);
//Finish Time
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblFinishTime = new Label();
lblFinishTime.Text = “Finish Time”;
_TCContent.Controls.Add(lblFinishTime);
_TRContent.Controls.Add(_TCContent);
//Total Hours
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblTotalHours = new Label();
lblTotalHours.Text = “Total Hours”;
_TCContent.Controls.Add(lblTotalHours);
_TRContent.Controls.Add(_TCContent);
//Chargable Hrs
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblChargableHrs = new Label();
lblChargableHrs.Text = “Chargable Hrs”;
_TCContent.Controls.Add(lblChargableHrs);
_TRContent.Controls.Add(_TCContent);
//Total
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblTotal = new Label();
lblTotal.Text = “Total”;
_TCContent.Controls.Add(lblTotal);
_TRContent.Controls.Add(_TCContent);
//Note / comment
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblNote = new Label();
lblNote.Text = “Note / comment”;
_TCContent.Controls.Add(lblNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//End columns
// Data Fields – Monday
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
//MonDay
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblMonDay = new Label();
lblMonDay.Text = “Monday”;
_TCContent.Controls.Add(lblMonDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonStartTime = new TextBox();
MonStartTime.ID = “MonStartTime”;
MonStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonLunchOut = new TextBox();
MonLunchOut.ID = “MonLunchOut”;
MonLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonLunchIn = new TextBox();
MonLunchIn.ID = “MonLunchIn”;
MonLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonFinishTime = new TextBox();
MonFinishTime.ID = “MonFinishTime”;
MonFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonTotalHours = new TextBox();
MonTotalHours.ID = “MonTotalHours”;
MonTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonChrgblHrs = new TextBox();
MonChrgblHrs.ID = “MonChrgblHrs”;
MonChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonTotal = new TextBox();
MonTotal.ID = “MonTotal”;
MonTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
MonNote = new TextBox();
MonNote.ID = “MonNote”;
MonNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(MonNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//TueDay
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblTueDay = new Label();
lblTueDay.Text = “Tuesday”;
_TCContent.Controls.Add(lblTueDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueStartTime = new TextBox();
TueStartTime.ID = “TueStartTime”;
TueStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueLunchOut = new TextBox();
TueLunchOut.ID = “TueLunchOut”;
TueLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueLunchIn = new TextBox();
TueLunchIn.ID = “TueLunchIn”;
TueLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueFinishTime = new TextBox();
TueFinishTime.ID = “TueFinishTime”;
TueFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueTotalHours = new TextBox();
TueTotalHours.ID = “TueTotalHours”;
TueTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueChrgblHrs = new TextBox();
TueChrgblHrs.ID = “TuehrgblHrs”;
TueChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueTotal = new TextBox();
TueTotal.ID = “TueTotal”;
TueTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
TueNote = new TextBox();
TueNote.ID = “TueNote”;
TueNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(TueNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//WedDay
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblWedDay = new Label();
lblWedDay.Text = “Wednesday”;
_TCContent.Controls.Add(lblWedDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedStartTime = new TextBox();
WedStartTime.ID = “WedStartTime”;
WedStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedLunchOut = new TextBox();
WedLunchOut.ID = “WedLunchOut”;
WedLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedLunchIn = new TextBox();
WedLunchIn.ID = “WedLunchIn”;
WedLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedFinishTime = new TextBox();
WedFinishTime.ID = “WedFinishTime”;
WedFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedTotalHours = new TextBox();
WedTotalHours.ID = “WedTotalHours”;
WedTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedChrgblHrs = new TextBox();
WedChrgblHrs.ID = “WedhrgblHrs”;
WedChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedTotal = new TextBox();
WedTotal.ID = “WedTotal”;
WedTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
WedNote = new TextBox();
WedNote.ID = “WedNote”;
WedNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(WedNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//ThruDay
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblThruDay = new Label();
lblThruDay.Text = “Thrushday”;
_TCContent.Controls.Add(lblThruDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruStartTime = new TextBox();
ThruStartTime.ID = “ThruStartTime”;
ThruStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruLunchOut = new TextBox();
ThruLunchOut.ID = “ThruLunchOut”;
ThruLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruLunchIn = new TextBox();
ThruLunchIn.ID = “ThruLunchIn”;
ThruLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruFinishTime = new TextBox();
ThruFinishTime.ID = “ThruFinishTime”;
ThruFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruTotalHours = new TextBox();
ThruTotalHours.ID = “ThruTotalHours”;
ThruTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruChrgblHrs = new TextBox();
ThruChrgblHrs.ID = “ThruChrgblHrs”;
ThruChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruTotal = new TextBox();
ThruTotal.ID = “ThruTotal”;
ThruTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
ThruNote = new TextBox();
ThruNote.ID = “ThruNote”;
ThruNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(ThruNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//FriDay
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblFriDay = new Label();
lblFriDay.Text = “Friday”;
_TCContent.Controls.Add(lblFriDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriStartTime = new TextBox();
FriStartTime.ID = “FriStartTime”;
FriStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriLunchOut = new TextBox();
FriLunchOut.ID = “FriLunchOut”;
FriLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriLunchIn = new TextBox();
FriLunchIn.ID = “FriLunchIn”;
FriLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriFinishTime = new TextBox();
FriFinishTime.ID = “FriFinishTime”;
FriFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriTotalHours = new TextBox();
FriTotalHours.ID = “FriTotalHours”;
FriTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriChrgblHrs = new TextBox();
FriChrgblHrs.ID = “FriChrgblHrs”;
FriChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriTotal = new TextBox();
FriTotal.ID = “FriTotal”;
FriTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
FriNote = new TextBox();
FriNote.ID = “FriNote”;
FriNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(FriNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//SatDay
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblSatDay = new Label();
lblSatDay.Text = “Saturday”;
_TCContent.Controls.Add(lblSatDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatStartTime = new TextBox();
SatStartTime.ID = “SatStartTime”;
SatStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatLunchOut = new TextBox();
SatLunchOut.ID = “SatLunchOut”;
SatLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatLunchIn = new TextBox();
SatLunchIn.ID = “SatLunchIn”;
SatLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatFinishTime = new TextBox();
SatFinishTime.ID = “SatFinishTime”;
SatFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatTotalHours = new TextBox();
SatTotalHours.ID = “SatTotalHours”;
SatTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatChrgblHrs = new TextBox();
SatChrgblHrs.ID = “SatChrgblHrs”;
SatChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatTotal = new TextBox();
SatTotal.ID = “SatTotal”;
SatTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SatNote = new TextBox();
SatNote.ID = “SatNote”;
SatNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SatNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
//SunDay
_TRContent = new TableRow();
_TRContent.BackColor = System.Drawing.Color.Gray;
_TRContent.ForeColor = System.Drawing.Color.AliceBlue;
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
Label lblSunDay = new Label();
lblSunDay.Text = “Sunday”;
_TCContent.Controls.Add(lblSunDay);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunStartTime = new TextBox();
SunStartTime.ID = “SunStartTime”;
SunStartTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunStartTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunLunchOut = new TextBox();
SunLunchOut.ID = “SunLunchOut”;
SunLunchOut.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunLunchOut);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunLunchIn = new TextBox();
SunLunchIn.ID = “SunLunchIn”;
SunLunchIn.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunLunchIn);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunFinishTime = new TextBox();
SunFinishTime.ID = “SunFinishTime”;
SunFinishTime.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunFinishTime);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunTotalHours = new TextBox();
SunTotalHours.ID = “SunTotalHours”;
SunTotalHours.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunTotalHours);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunChrgblHrs = new TextBox();
SunChrgblHrs.ID = “SunChrgblHrs”;
SunChrgblHrs.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunChrgblHrs);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunTotal = new TextBox();
SunTotal.ID = “SunTotal”;
SunTotal.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunTotal);
_TRContent.Controls.Add(_TCContent);
_TCContent = new TableCell();
_TCContent.VerticalAlign = VerticalAlign.Middle;
_TCContent.HorizontalAlign = HorizontalAlign.Center;
SunNote = new TextBox();
SunNote.ID = “SunNote”;
SunNote.Width = Unit.Pixel(70);
_TCContent.Controls.Add(SunNote);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
// Empty table cell
_TRContent = new TableRow();
_TCContent = new TableCell();
_TCContent.ColumnSpan = 9;
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
// Send Message button
_TRContent = new TableRow();
_TCContent = new TableCell();
btnSendMessage = new Button();
btnSendMessage.Text = “Submit TimeSheet”;
btnSendMessage.Click += new EventHandler(btnSendMessage_Click);
_TCContent.Controls.Add(btnSendMessage);
_TRContent.Controls.Add(_TCContent);
_TableContent.Controls.Add(_TRContent);
this.Controls.Add(_TableContent);
//Dispose object
_SPUser = null;
_SPWeb.Dispose();
}
To generate weekend date (i.e. Friday for this project) in the combo control WeekCalendar, I used the method PopulateWeekends(). Used here DayOfWeek enumeration to select the date one. You gues can select any day in the date combo.
private void PopulateWeekends(DropDownList _DropDownControl)
{
DateTime _DateStart = new DateTime(2009, 1, 1);
DateTime _DateEnd = new DateTime(2010, 12, 31);
TimeSpan _TimeSpan = new TimeSpan();
_TimeSpan = (_DateEnd – _DateStart);
for (long iLoop = 1; iLoop <= (long)_TimeSpan.TotalDays; iLoop++)
{
switch (_DateStart.AddDays(iLoop).DayOfWeek)
{
case DayOfWeek.Monday:
break;
case DayOfWeek.Tuesday:
//FirstDayOfWeek = FirstDayOfWeek.AddDays(-1);
break;
case DayOfWeek.Wednesday:
//FirstDayOfWeek = FirstDayOfWeek.AddDays(-2);
break;
case DayOfWeek.Thursday:
//FirstDayOfWeek = FirstDayOfWeek.AddDays(-3);
break;
case DayOfWeek.Friday:
//FirstDayOfWeek = FirstDayOfWeek.AddDays(-4);
_DropDownControl.Items.Add(_DateStart.AddDays(iLoop).ToString().Substring(0, _DateStart.AddDays(iLoop).ToString().IndexOf(” “)));
//if (iLoop == 1)
//PopulateDate(_DateStart.AddDays(iLoop));
break;
case DayOfWeek.Saturday:
//FirstDayOfWeek = FirstDayOfWeek.AddDays(-5);
break;
case DayOfWeek.Sunday:
//FirstDayOfWeek = FirstDayOfWeek.AddDays(-6);
break;
}
}
}
Now the final touch, just after click on submit button, the data need first taking place in the SharePoint list TimeSheet.
protected void btnSendMessage_Click(object sender, EventArgs e)
{
SPWeb _SPWeb = SPContext.Current.Web;
SPList _SPList = _SPWeb.Lists["TimeSheet"];
try
{
DateTime _WeekDate = System.DateTime.Now;
SPListItem _NewItem = _SPList.Items.Add();
_NewItem["Title"] = MemberTitle.SelectedItem.Value;
_NewItem[_NewItem.Fields["Title"].InternalName] = MemberTitle.SelectedItem.Value.ToString();
_NewItem["EmpName"] = txtEmpName.Text.Trim();
_NewItem["EmpManager"] = txtManagerName.Text.Trim();
_NewItem["EmpPhone"] = txtPhone.Text.Trim();
_NewItem["email"] = txtEmailAddress.Text.Trim();
//Monday
_NewItem["MonStartTime"] = MonStartTime.Text.Trim();
_NewItem["MonLunchOut"] = MonLunchIn.Text.Trim();
_NewItem["MonLunchIn"] = MonLunchIn.Text.Trim();
_NewItem["MonFinishTime"] = MonFinishTime.Text.Trim();
_NewItem["MonTotalHr"] = MonTotalHours.Text.Trim();
_NewItem["MonChrgHr"] = MonChrgblHrs.Text.Trim();
_NewItem["MonNote"] = MonNote.Text.Trim();
//Tuesday
_NewItem["TueStartTime"] = TueStartTime.Text.Trim();
_NewItem["TueLunchOut"] = TueLunchOut.Text.Trim();
_NewItem["TueLunchIn"] = TueLunchIn.Text.Trim();
_NewItem["TueFinishTime"] = TueFinishTime.Text.Trim();
_NewItem["TueTotalHr"] = TueTotalHours.Text.Trim();
_NewItem["TueChrgHr"] = TueChrgblHrs.Text.Trim();
_NewItem["TueNote"] = TueNote.Text.Trim();
//Wednesday
_NewItem["WedStartTime"] = WedStartTime.Text.Trim();
_NewItem["WedLunchOut"] = WedLunchOut.Text.Trim();
_NewItem["WedLunchIn"] = WedLunchIn.Text.Trim();
_NewItem["WedFinishTime"] = WedFinishTime.Text.Trim();
_NewItem["WedTotalHr"] = WedTotalHours.Text.Trim();
_NewItem["WedChrgHr"] = WedChrgblHrs.Text.Trim();
_NewItem["WedNote"] = WedNote.Text.Trim()
//Thrushday
_NewItem["ThruStartTime"] = ThruStartTime.Text.Trim();
_NewItem["ThruLunchOut"] = ThruLunchOut.Text.Trim();
_NewItem["ThruLunchIn"] = ThruLunchIn.Text.Trim();
_NewItem["ThruFinishTime"] = ThruFinishTime.Text.Trim();
_NewItem["ThruTotalHr"] = ThruTotalHours.Text.Trim();
_NewItem["ThruChrgHr"] = ThruChrgblHrs.Text.Trim();
_NewItem["ThruNote"] = ThruNote.Text.Trim();
//Friday
_NewItem["FriStartTime"] = FriStartTime.Text.Trim();
_NewItem["FriLunchOut"] = FriLunchOut.Text.Trim();
_NewItem["FriLunchIn"] = FriLunchIn.Text.Trim();
_NewItem["FriFinishTime"] = FriFinishTime.Text.Trim();
_NewItem["FriTotalHr"] = FriTotalHours.Text.Trim();
_NewItem["FriChrgHr"] = FriChrgblHrs.Text.Trim();
_NewItem["FriNote"] = FriNote.Text.Trim();
//Saturday
_NewItem["SatStartTime"] = SatStartTime.Text.Trim();
_NewItem["SatLunchOut"] = SatLunchOut.Text.Trim();
_NewItem["SatLunchIn"] = SatLunchIn.Text.Trim();
_NewItem["SatFinishTime"] = SatFinishTime.Text.Trim();
_NewItem["SatTotalHr"] = SatTotalHours.Text.Trim();
_NewItem["SatChrgHr"] = SatChrgblHrs.Text.Trim();
_NewItem["SatNote"] = SatNote.Text.Trim();
//Sunday
_NewItem["SunStartTime"] = SunStartTime.Text.Trim();
_NewItem["SunLunchOut"] = SunLunchOut.Text.Trim();
_NewItem["SunLunchIn"] = SunLunchIn.Text.Trim();
_NewItem["SunFinishTime"] = SunFinishTime.Text.Trim();
_NewItem["SunTotalHr"] = SunStartTime.Text.Trim();
_NewItem["SunChrgHr"] = SunStartTime.Text.Trim();
_NewItem["SunNote"] = SunStartTime.Text.Trim();
//_NewItem["Created By"] = _SPUser.Name.ToString();
_NewItem["status"] = “InProcess”;
_NewItem.Update();
}
catch (Exception ex)
{
lblMessageSent.Text = ex.Message.ToString();
}
//// Let the user know the message was sent
lblMessageSent.Visible = true;
}
It is done. Now open WSP viewer, and rename the xml file as TimeSheet.xml file, and the following code will be there:
<?xml version=”1.0″ encoding=”utf-8″?>
<Elements Id=”ae77fa4d-0e0c-4793-8f5f-2f0bc0875e8e” xmlns=”http://schemas.microsoft.com/sharepoint/” >
<Module Name=”WebParts” List=”113″ Url=”_catalogs/wp”>
<File Path=”TimeSheet.webpart” Url=”TimeSheet.webpart” Type=”GhostableInLibrary” />
</Module>
</Elements>
Now, integrate SharePoint inbuilt ThreeState workflow with TimeSheet list. Go to theĀ TimeSheet list, click on Settings –> List Settings –> WorkFlow setting. You need to provide the workflow logic there.
Build the solution and deploy the solution into SharePoint. Open the SharePoint site, then go to edit page, and click on add webpart. There you will find the newly adde webpart. Add this webpart and start feeding data. Rest of the task will be executed automatically.
Enjoy SharePoint
