Click here to Skip to main content
15,896,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all, for hrm project i'm working on web based timesheet. I'm able to create daily basis timesheet(
SQL
employeeid, projectid, hours, totaltime(entry date + hours ), weeknumber
), and also able to show weekly timesheet(filtered by select week) with features: editable row wise, grouping.

Now my client requirement is to fill timesheet on week bases(not daily). Same as the exel timesheets. add new row for diffeernt project just like(pivot table)
C#
Project Name | Monday | Tuesday |... | Sunday 
Sample1          6         2
Sample2          2         8
...             ...       ...

Hours are bounded to textbox.

Thanks in advance

P.S. sorry for grammer mistakes.
Posted

Hey i m working on same...i also implemented it .i m giving u my code accrding u change ur query n also code..
C#
 public void calculateWeek()
    {
        try
        {
            DateTime date = Convert.ToDateTime(txtenddate2.Text);
            DateTime startDate = date;
            DateTime lastdate = DateTime.Now;
            DateTime endDate = startDate.AddMonths(1).AddDays(-1);
            int i = 0;
            for (DateTime result = startDate; result <= endDate; result = lastdate.AddDays(1))
            {
                if (result.Day != 31)
                {
                    weeks[i, 0] = result.ToString();
                    if (result.AddDays(14) >= endDate)
                    {
                        weeks[i, 1] = endDate.ToString();
                        lastdate = result.AddDays(14);
                    }
                    else
                    {
                        weeks[i, 1] = result.AddDays(14).ToString();
                        lastdate = result.AddDays(14);
                    }
                }
                else
                {
                    weeks[i - 1, 1] = result.ToString();
                    lastdate = result.AddDays(14);
                }
                i++;

            }

            if (weeks.Length > 0)
            {
                Session["frt_1"] = Convert.ToDateTime(weeks[0, 0].ToString());
                Session["frt_2"] = Convert.ToDateTime(weeks[0, 1].ToString());
                Session["frt_3"] = Convert.ToDateTime(weeks[1, 0].ToString());
                Session["frt_4"] = Convert.ToDateTime(weeks[1, 1].ToString());
            }

        }
        catch (Exception ex)
        {

        }
    }
//Response.Redirect("~/report1.aspx?dt=" + date + "&job=" + DropJob.SelectedValue + "&comp=" + ViewState["compid"].ToString() + "&pagename=WeekwiseJob");
                string str = "select s.StaffName,isnull(t.HourlyCharges,0) as HourlyCharges,isnull(sum(convert(float,TotalTime)),0)as TotalTime, " +
                " isnull((isnull(sum(convert(float,TotalTime)),0)* t.HourlyCharges),0)as Charges,isnull(sum(OpeAmt),0)as OpeAmt,dbo.TotalTime(isnull(sum(convert(float,TotalTime)),0)) as mints,convert(varchar(50),dbo.TotalTime(isnull(sum(convert(float,TotalTime)),0))/60) + '.' + convert(varchar(50),dbo.TotalTime(isnull(sum(convert(float,TotalTime)),0))%60) as timet " +
                " from   dbo.Staff_Master as s right join dbo.Job_Staff_Table as j on s.StaffCode=j.StaffCode " +
                " left join  dbo.TimeSheet_Table as t on  t.JobId=j.JobId and t.StaffCode=j.StaffCode  and  t.Date>='" + Convert.ToDateTime(weeks[0, 0].ToString()) + "' " +
                " and t.Date <='" + Convert.ToDateTime(weeks[1, 1].ToString()) + "' where  j.JobId='" + DropJob.SelectedValue + "' and t.CLTId='" + DropClient.SelectedValue + "' group by s.StaffName,t.HourlyCharges";
                DataTable dt = db.GetDataTable(str);
 
Share this answer
 
Comments
Sandeip Yadav 5-Oct-12 8:41am    
if you are working on same kind of project.. then can we share code via team viewer..
thanks for reply...
Calculating week isn't a problem... I'm able to fetch data according to week by parameter
SQL
@WeekStartDate and @WeekEndDate or @Weeknumber
..
SQL
select * from (select e.AccountProjectId, dbo.GetWeekDayNameOfDate(e.totaltime) as weekd, e.Hours from AccountEmployeeTimeEntry e where CONVERT(date, StartTime)= @start and CONVERT(date, EndTime)=@end and AccountEmployeeId =@AccountEmployeeId) P pivot (
dbo.sumFunction(hours) for weekd in([Monday], [Tuesday], [Wednesday], [thursday], [Friday], [Saturday], [Sunday] ) ) as pvt 


i want to insert and update in weekly format(not in daily format) ... please provide info regarding insert n update in week format
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900