Example #1
0
        public ActionResult TimesheetDetailReport(string FromDate, string ToDate)
        {
            IEnumerable <Timesheet> timesheetList = null;

            try
            {
                TimesheetManager timesheetManager = new TimesheetManager();
                timesheetList = timesheetManager.TimesheetDetailReport(FromDate, ToDate);
                if (timesheetList.Count() > 0)
                {
                    var jsonResultS = this.Json(timesheetList, JsonRequestBehavior.AllowGet);
                    jsonResultS.MaxJsonLength = int.MaxValue;
                    return(jsonResultS);
                }
                else
                {
                    var result = new { Success = "True", Message = "No Data Found" };
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                string sMessage = ex.Message;
                var    result   = new { Success = "False", Message = "Exception: " + sMessage };
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        private void lstBoxEmployeesReport_SelectedIndexChanged(object sender, EventArgs e)
        {
            lstboxReport.Items.Clear();
            foreach (Employee obj in lst)
            {
                if (obj == lstBoxEmployeesReport.SelectedItem)
                {
                    int EmpId = obj.EmpId;
                    TimesheetManager           manager = new TimesheetManager();
                    Result <List <Timesheet> > result  = manager.DisplayReport(EmpId);
                    timelist = result.List;
                    switch (result.Status)
                    {
                    case ResultEnum.SUCCESS:
                        foreach (Timesheet tim in timelist)
                        {
                            lstboxReport.Items.Add(tim);
                        }
                        break;

                    case ResultEnum.FAIL:
                        MessageBox.Show("Error, Something went wrong");
                        break;
                    }
                }
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     TimesheetManager tm = new TimesheetManager();
     dbData = tm.getBranches();
     if (!IsPostBack) {
         datesDDL.DataSource = tm.getDates();
         datesDDL.DataBind();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     TimesheetManager tm = new TimesheetManager();
        using(var context = new PetoEntities())
     {
        string name = Membership.GetUser().UserName;
        User user = context.Users.FirstOrDefault(x => x.username == name);
        HiddenField1.Value = user.UserId.ToString();
     }
 }
Example #5
0
 public void CreateTimesheet(Timesheet timesheet)
 {
     try
     {
         TimesheetManager timesheetManager = new TimesheetManager();
         //timesheet.fkEmpId =// Convert.ToInt32(Session["UserID"]);
         timesheet.CreatedBy = Session["FullName"].ToString();
         var x = timesheetManager.CreateTimesheet(timesheet);
     }
     catch (Exception ex)
     {
         string sMessage = ex.Message;
     }
 }
Example #6
0
 public ActionResult Create(Timesheet timesheet)
 {
     try
     {
         TimesheetManager timesheetManager = new TimesheetManager();
         //timesheet.fkEmpId = Convert.ToInt32(Session["UserID"]);
         timesheet.CreatedBy = Session["FullName"].ToString();
         var x = timesheetManager.CreateTimesheet(timesheet);
         return(RedirectToAction("/Index"));
     }
     catch
     {
         return(View());
     }
 }
    protected void searchBtn_Click(object sender, EventArgs e)
    {
        if (searchTB.Text != string.Empty)
        {
            List<Document> searchResults = new List<Document>();

            //SqlConnection conn = new SqlConnection("data source=208.124.173.18;initial catalog=petomaccallum.ca;user id=sa;password=PMLsa1234;multipleactiveresultsets=True");
            SqlConnection conn = new SqlConnection("data source=User;initial catalog=petomaccallum.ca;user id=sa;password=PMLtest;multipleactiveresultsets=True");
            conn.Open();

            SqlCommand stmt = conn.CreateCommand();

            //get projnum, name, client
            if (searchTB.Text.Contains(' '))
            {
                stmt.CommandText = "SELECT DocumentId FROM Documents WHERE FREETEXT(fileContent,@searchText)";
            }
            else {
                stmt.CommandText = "SELECT DocumentId FROM Documents WHERE CONTAINS(fileContent,@searchText)";
            }

            stmt.Parameters.AddWithValue("@searchText", searchTB.Text);
            TimesheetManager tm = new TimesheetManager();

            SqlDataReader projectReader = stmt.ExecuteReader();
            using (var context = new PetoEntities())
            {
                if (projectReader.HasRows)
                {
                    while (projectReader.Read())
                    {
                        int id = projectReader.GetInt32(0);
                        searchResults.Add(context.Documents.FirstOrDefault(x => x.DocumentId == id));
                    }
                }
                GridView1.DataSource = searchResults;
                GridView1.DataBind();
            }
        }
        else {

             FileManager fm = new FileManager();

            GridView1.DataSource = fm.getDocuments("");
            GridView1.DataBind();
        }
    }
Example #8
0
        public JsonResult GetTimesheetEntries()
        {
            IEnumerable <Timesheet> timesheetList = null;

            try
            {
                TimesheetManager timesheetManager = new TimesheetManager();
                timesheetList = timesheetManager.GetTimesheetEntries(Convert.ToInt32(Session["AccountID"]));
            }
            catch (Exception ex)
            {
                string sMessage = ex.Message;
            }
            var jsonResult = this.Json(timesheetList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
Example #9
0
        private void btnAddTimesheet_Click(object sender, EventArgs e)
        {
            if (lst != null && lstboxEmployees.SelectedItem != null)
            {
                foreach (Employee obj in lst)
                {
                    if (obj == lstboxEmployees.SelectedItem)
                    {
                        try
                        {
                            int       empid      = obj.EmpId;
                            DateTime  dateWorked = dtpWorkedDate.Value;
                            double    hours      = double.Parse(txtHours.Text);
                            Timesheet tim        = new Timesheet();
                            tim.EmpId    = empid;
                            tim.WorkDate = dateWorked;
                            tim.Hours    = hours;

                            TimesheetManager manager = new TimesheetManager();
                            ResultEnum       result  = manager.AddTimesheet(tim);
                            switch (result)
                            {
                            case ResultEnum.SUCCESS:
                                MessageBox.Show("New TimeSheet Added");
                                break;

                            case ResultEnum.FAIL:
                                MessageBox.Show("Error, Something went wrong");
                                break;
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Please Enter Hours");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Select an employee!");
            }
        }
Example #10
0
        public JsonResult GetAccountTimeSheetSummaries()
        {
            IEnumerable <TimeSheetSummary> expenseSummaryList = null;

            try
            {
                ExpenseManager expenseManager = new ExpenseManager();

                expenseSummaryList = new TimesheetManager().TimesheetSummaryByAccount(Convert.ToInt32(Session["AccountID"]), DateTime.Now.Year, DateTime.Now.Month);
            }
            catch (Exception ex)
            {
                string sMessage = ex.Message;
            }
            var jsonResult = this.Json(expenseSummaryList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
Example #11
0
        public ActionResult Details(int id)
        {
            var projectManager   = new ProjectManager();
            var timesheetManager = new TimesheetManager();

            ClientDetails cDetails = new ClientDetails();

            cDetails.Client      = Mapper.Map <Models.Client.Client>(_clientManager.GetClient(id));
            cDetails.ProjectList = projectManager.GetProjects(id)
                                   .Select(i => Mapper.Map <Models.Project.Project>(i));

            cDetails.TotalHours = 0;
            foreach (var project in cDetails.ProjectList)
            {
                var timeEntries = timesheetManager.GetTimeEntries(project.ProjectId);
                cDetails.TotalHours += (float)timeEntries.Sum(i => i.sunday + i.monday + i.tuesday + i.wednesday + i.thursday + i.friday + i.saturday);
            }

            return(View(cDetails));
        }
Example #12
0
 private void btnTotalHours_Click(object sender, EventArgs e)
 {
     if (lst != null)
     {
         foreach (Employee obj in lst)
         {
             if (obj == lstBoxEmployeesReport.SelectedItem)
             {
                 int empId = obj.EmpId;
                 TimesheetManager manager = new TimesheetManager();
                 double           sum     = manager.SumOfHours(empId);
                 MessageBox.Show("Total hours worked " + sum + " hours");
             }
         }
     }
     else
     {
         MessageBox.Show("Error");
     }
 }
Example #13
0
        public JsonResult GetProjectTimebreakdown(int projectId)
        {
            var tsManager = new TimesheetManager();

            ProjectTimeBreakdown timeBreakdown = new ProjectTimeBreakdown();

            var groupedByWorkType = tsManager.GetTimeEntrySummaries(projectId)
                                    .GroupBy(i => i.worktypeid)
                                    .Select(i => new
            {
                Id            = i.Key,
                WorkType      = i.First().worktypename,
                WorkTypeTotal = i.Sum(s => s.entryHours.Value)
            })
                                    .OrderBy(i => i.Id);

            timeBreakdown.WorkTypes = groupedByWorkType.Select(i => i.WorkType).ToList();
            timeBreakdown.Hours     = groupedByWorkType.Select(i => i.WorkTypeTotal).ToList();

            return(Json(timeBreakdown, JsonRequestBehavior.AllowGet));
        }
        private ResultView ParseTimesheetFile(HttpPostedFile file)
        {
            var        streamReader = new StreamReader(file.InputStream);
            ResultView result       = new ResultView();
            List <TimesheetUploadItem> timesheetUploadList = new List <TimesheetUploadItem>();
            var index = 1;

            while (!streamReader.EndOfStream)
            {
                string line = streamReader.ReadLine();

                string[] columns = line.Split(',');
                if (columns[0] == "report id")
                {
                    int reportId = int.Parse(columns[1]);
                    //TODO: check if it is already in the DB
                    result = TimesheetManager.InsertRows(timesheetUploadList, reportId);
                }
                else if (columns[0] == "date")
                {
                }                                //skip the header
                else
                {
                    TimesheetUploadItem rowItem = new TimesheetUploadItem()
                    {
                        TimeEntry        = DateTime.ParseExact(columns[0], "d/M/yyyy", CultureInfo.InvariantCulture),
                        Hours            = double.Parse(columns[1]),
                        EmployeeId       = int.Parse(columns[2]),
                        JobGroup         = columns[3],
                        InFileLineNumber = index
                    };
                    timesheetUploadList.Add(rowItem);
                    index++;
                }
            }
            return(result);
        }
Example #15
0
        private Project GetProject(int id, DateTime?start = null, DateTime?end = null)
        {
            Project project = Mapper.Map <Project>(_projectManager.GetProject(id));

            project.JobYears = _projectManager.GetJobYears()
                               .Select(i => Mapper.Map <Models.Project.JobYear>(i))
                               .ToList();
            project.ProjectTypes = _projectManager.GetProjectTypes()
                                   .Select(i => Mapper.Map <Models.Project.ProjectType>(i))
                                   .ToList();

            var tsManager = new TimesheetManager();

            project.TimeEntrySummaries = tsManager.GetTimeEntrySummaries(id, start, end)
                                         .Select(i => Mapper.Map <Models.Timesheet.TimeEntrySummary>(i))
                                         .OrderByDescending(i => i.EndingDate)
                                         .ToList();

            if (project.TimeEntrySummaries != null)
            {
                project.InternalHours  = project.TimeEntrySummaries.Sum(j => j.EntryHours);
                project.InternalAmount = project.TimeEntrySummaries.Sum(j => j.InternalAmount);
                if (project.ContractedAmount.HasValue)
                {
                    project.InternalDifference      = project.ContractedAmount.Value - project.InternalAmount;
                    project.InternalDifferenceRatio = (float)(project.InternalAmount / project.ContractedAmount.Value);
                }
            }
            else
            {
                project.InternalHours  = 0;
                project.InternalAmount = 0;
            }

            return(project);
        }
Example #16
0
        public IHttpActionResult Posttimesheet(TimeSheetDTO input)
        {
            TextResult       httpResponse = new TextResult("There is already a timesheet present", message);
            TimesheetManager manager      = new TimesheetManager();

            var timesheetObject = manager.CreateTimeSheet(input.User_id, input.Start_date, input.Start_time.ToString(), input.Project_id, input.Activity_id);;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                db.timesheet.Add(timesheetObject);
                db.SaveChanges();
            }
            catch
            {
                httpResponse.ChangeHTTPMessage("Failed to create timesheet", message); // HTTP response if fails to savechanges to DB
                return(httpResponse);
            }

            return(Ok());
        }
    protected void projectNumTB_TextChanged(object sender, EventArgs e)
    {
        if (projectNumTB.Text != string.Empty)
        {
            string numFormat = "[0-9]{2}[TBHKPDY]{1}[MFXE]{1}[0-9]{3}[A-Z]*";
            // uppercase the letters if possible
            projectNumTB.Text = projectNumTB.Text.ToUpper();

            // check to see if the project number follows the correct format
            if (Regex.IsMatch(projectNumTB.Text, numFormat))
            {
                TimesheetManager tm = new TimesheetManager();
                Project p = tm.getProjectForID(projectNumTB.Text.Trim());
                classificationDDL.DataSource = tm.getClassificationForProject(projectNumTB.Text.Trim());
                classificationDDL.DataBind();
                classificationDDL.Items.Insert(0, "Select");
                classificationDDL.Focus();

                // if project is null get all classifications
                if (p != null)
                {
                    projectNameTB.Text = p.ProjectName;
                    clientNameTB.Text = p.ClientName;
                }
                else
                {
                    projectNameTB.Text = " ";
                    clientNameTB.Text = " ";
                    // get all classifications if project was not matched
                    classificationDDL.DataSource = tm.getClassifications();
                    classificationDDL.DataBind();
                    classificationDDL.Items.Insert(0, "Select");
                }
                chargeableBtn.Visible = true;
            }
            else
            {
                TimesheetManager tm = new TimesheetManager();
                // throw a dialog
                msg = "Project Number is not in Correct Format i.e: 11PM121(ABC)";
                dialogTitle = "Project Number Format";

                ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
                // get all classifications
                classificationDDL.DataSource = tm.getClassifications();
                classificationDDL.DataBind();
                classificationDDL.Items.Insert(0, "Select");
            }
            // re-populate the dates
            ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
        }
    }
Example #18
0
 public TimesheetUtil(IMapper mapper)
 {
     _tsManager = new TimesheetManager();
     _mapper    = mapper;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        dbData = new string[7] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
        // Fields to populate when user visits this page: Employee ID, Employee Name, and Branch
        TimesheetManager tm = new TimesheetManager();

        // re-highlight rows if possible
        HighLightDeletedRows();
        if (!IsPostBack)
        {

            verifyBtn.Enabled = true;
            // get and populate user information
            MembershipUser loggedInUser = Membership.GetUser();
            User employee = tm.getEmployeeForId(loggedInUser.UserName);
            empIdTB.Text = employee.empNo;
            nameTB.Text = employee.FirstName + " " + employee.MiddleName + " " + employee.LastName;
            departmentTB.Text = employee.branch;

            // populate generic non-chargeable drop down list elements
            specifyDDL.DataSource = tm.getWorkType();
            specifyDDL.DataBind();
            specifyDDL.Items.Insert(0, "Select");
            detailsDDL.DataSource = tm.getExpenses();
            detailsDDL.DataBind();
            detailsDDL.Items.Insert(0, "Select");

            // sub-menu's of non-chargeable section
            NonChargeExpensesPanel.Visible = false;
            NonChargeHoursPanel.Visible = false;
            detailsDDL.SelectedIndex = 0;
            specifyDDL.SelectedIndex = 0;

            // check query strings for form data to be populated
            if (Request.QueryString.Count > 0)
            {
                string timesheet = Request.QueryString["time"];
                string expense = Request.QueryString["expense"];
                string hours = Request.QueryString["hours"];
                string project = Request.QueryString["project"];
                string classification = Request.QueryString["class"];
                string activity = Request.QueryString["activity"];
                string delete = Request.QueryString["delete"];
                int chID = Convert.ToInt32(Request.QueryString["charge"]);
                int nonChID = Convert.ToInt32(Request.QueryString["nonCh"]);
                int lab = Convert.ToInt32(Request.QueryString["test"]);
                // reset weekending dates
                ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);

                int id = Convert.ToInt32(timesheet);
                timesheetID = id;
                HiddenField1.Value = id.ToString();

                // VIEW ONLY from a MANAGER's perspective.
                if (Request.QueryString["view"] == "view") {
                    verifyBtn.Enabled = false;
                    chargeableBtn.Enabled = false;
                    nonChargeBtn.Enabled = false;
                    labTestsBtn.Enabled = false;
                    // disable edit and delete columns
                    summaryGV.Columns[0].Visible = false;
                    summaryGV.Columns[1].Visible = false;
                    summaryGV.Columns[0].Visible = false;
                    summaryGV.Columns[1].Visible = false;
                    string username = Membership.GetUser().UserName;

                    TimeSheet ts = tm.getTimesheetForID(timesheetID);
                    User user = tm.getEmployeeForId(ts.EmployeeId);
                    departmentTB.Text = user.branch;
                    empIdTB.Text = user.empNo;
                    nameTB.Text = user.FirstName + " " + user.MiddleName + " " + user.LastName;
                }
                // display lab test hours
                if (lab > 0 && delete != "delete")
                {
                    List<EmpTest> tests = tm.getEmpTestsForTimeSheet(id);
                    updateLabTestsBtn.Visible = true;
                    labTestsBtn.Visible = false;
                    aID = 1;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    foreach (EmpTest item in tests)
                    {
                        if (item.Day == "Sunday")
                        {
                            sunLabTB.Text = item.LabTest.ToString();
                            sunNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Monday")
                        {
                            monLabTB.Text = item.LabTest.ToString();
                            monNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Tuesday")
                        {
                            tuesLabTB.Text = item.LabTest.ToString();
                            tuesNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Wednesday")
                        {
                            wedsLabTB.Text = item.LabTest.ToString();
                            wedsNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Thursday")
                        {
                            thursLabTB.Text = item.LabTest.ToString();
                            thursNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Friday")
                        {
                            friLabTB.Text = item.LabTest.ToString();
                            friNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Saturday")
                        {
                            satLabTB.Text = item.LabTest.ToString();
                            satNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                    }
                }

                // set static properties on the webpage
                weekEndingTB.Text = tm.getWeekendingForTimeSheet(id);

                // delete summary non-chargeable and chargeable
                if (delete == "delete")
                {
                    rowIDs.Add(summaryGV.SelectedIndex);
                    HighLightDeletedRows();
                    //tm.deleteSummary(nonChID, chID, id, lab, false);

                    summaryGV.Focus();
                }
                // if there is a query string, load the totals from the corresponding timesheet
                updateTimeSheetTotals();
                // this conditional structure determines what module to load based on query string values
                // Project Only
                if (Request.QueryString["projectOnly"] != null)
                {
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    projectNumTB.Text = p.ProjectNo;
                    projectNameTB.Text = p.ProjectName;
                    clientNameTB.Text = p.ClientName;
                    classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                    classificationDDL.DataBind();
                    classificationDDL.SelectedValue = classification;

                    projectNumTB.Enabled = true;
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                }
                // chargeable
                else if (project != null && project != "0")
                {
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);

                    // populate the project information fields
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    if (p != null)
                    {
                        projectNumTB.Text = p.ProjectNo;
                        projectNameTB.Text = p.ProjectName;
                        clientNameTB.Text = p.ClientName;
                        classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                        classificationDDL.DataBind();
                        classificationDDL.SelectedValue = classification;
                        activitiesDDL.DataSource = tm.getActivityForClassification(classification);
                        activitiesDDL.DataBind();
                        activitiesDDL.SelectedValue = activity;
                        projectNumTB.Enabled = true;

                        // populate the chargeable fields based on the classification and activity selected
                        List<ChargeableJob> cJobs = tm.getChargeableJobsForTimesheetID(timesheetID);

                        if (chID > 0)
                        {
                            cJobs.Add(tm.getChargeForID(chID));
                        }

                        if (cJobs != null)
                        {
                            chargeableBtn.Visible = false;
                            updateChargeableBtn.Visible = true;

                            foreach (var item in cJobs)
                            {
                                if (item.Day == "Sunday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        sunAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    sunCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    sunDistTB.Text = item.TravelDistance.ToString();
                                    sunTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        sunMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    sunCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Monday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        monAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    monCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    monDistTB.Text = item.TravelDistance.ToString();
                                    monTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        monMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    monCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Tuesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        tuesAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    tuesCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    tuesDistTB.Text = item.TravelDistance.ToString();
                                    tuesTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        tuesMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    tuesCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Wednesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        wedsAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    wedsCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    wedsDistTB.Text = item.TravelDistance.ToString();
                                    wedsTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        wedsMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    wedsCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Thursday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        thursAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    thursCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    thursDistTB.Text = item.TravelDistance.ToString();
                                    thursTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        thursMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    thursCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Friday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        friAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    friCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    friDistTB.Text = item.TravelDistance.ToString();
                                    friTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        friMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    friCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Saturday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        satAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    satCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    satDistTB.Text = item.TravelDistance.ToString();
                                    satTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        satMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    satCRemarksTB.Text = item.Remarks;
                                }
                            }
                        }
                    }
                }
                // Non-Chargeable
                else if (expense != "Select" || hours != "Select")
                {
                    aID = 2;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    // set the dropdownlists and display the different panels accordingly
                    if (hours != string.Empty)
                    {
                        specifyDDL.SelectedValue = hours;
                        NonChargeHoursPanel.Visible = true;
                    }
                    else
                    {
                        specifyDDL.SelectedIndex = 0;
                        NonChargeHoursPanel.Visible = false;
                    }

                    if (expense != string.Empty)
                    {
                        detailsDDL.SelectedValue = expense;
                        NonChargeExpensesPanel.Visible = true;
                    }
                    else
                    {
                        detailsDDL.SelectedIndex = 0;
                        NonChargeExpensesPanel.Visible = false;
                    }

                    List<NonChargeable> nCh = tm.getNonChargeableForTimesheetID(timesheet, expense, hours);
                    if (nCh != null)
                    {
                        // adjust buttons
                        nonChargeBtn.Visible = false;
                        updateNonChargeableBtn.Visible = true;
                        // populate the non chargeable text fields based on the expense and type of hours selected
                        foreach (var item in nCh)
                        {
                            if (item.Day == "Sunday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    sunNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                sunNCHoursTB.Text = item.Hours.ToString("0.0");
                                sunNCDistanceTB.Text = item.Distance.ToString();
                                sunTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    sunNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }

                                sunNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Monday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    monNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                monNCHoursTB.Text = item.Hours.ToString("0.0");
                                monNCDistanceTB.Text = item.Distance.ToString();
                                monTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    monNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }

                                monNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Tuesday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    tuesNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                tuesNCHoursTB.Text = item.Hours.ToString("0.0");
                                tuesNCDistanceTB.Text = item.Distance.ToString();
                                tuesTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    tuesNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }

                                tuesNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Wednesday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    wedsNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                wedsNCHoursTB.Text = item.Hours.ToString("0.0");
                                wedsNCDistanceTB.Text = item.Distance.ToString();
                                wedsTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    wedsNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                                wedsNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Thursday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    thursNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                thursNCHoursTB.Text = item.Hours.ToString("0.0");
                                thursNCDistanceTB.Text = item.Distance.ToString();
                                thursTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    thursNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                                thursNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Friday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    friNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                friNCHoursTB.Text = item.Hours.ToString("0.0");
                                friNCDistanceTB.Text = item.Distance.ToString();
                                friTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    friNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                                friNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Saturday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    satNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                satNCHoursTB.Text = item.Hours.ToString("0.0");
                                satNCDistanceTB.Text = item.Distance.ToString();
                                satTruckDistTB.Text = item.TruckDistance.ToString();
                                satNCRemarksTB.Text = item.Remarks;
                                if (item.Misc.HasValue)
                                {
                                    satNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                            }
                        }
                    }
                }
            }
        }
        // check to see if weekending is specified, if it is get timesheetID set it and update the gridviews
        if (weekEndingTB.Text != string.Empty)
        {
            // re-populate the dates
            ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
            // try and get the timesheet for the logged in user
            int id = tm.idForDate(weekEndingTB.Text, tm.idForUsername(Membership.GetUser().UserName));
            if (id != 0)
            {
                timesheetID = id;
                HiddenField1.Value = id.ToString();
                // update totals
                updateTimeSheetTotals();
                summaryGV.DataBind();
            }
        }
        // populate the predictive text arrays
        projectNoDB = tm.getProjectNumbers();
    }
    protected void updateChargeableTotals()
    {
        TimesheetManager tm = new TimesheetManager();

        decimal[] totals = tm.getChargeableTotalsForID(timesheetID);
        decimal finalTotal = 0;

        sunChargeLBL.Text = totals[0].ToString("0.0");
        sunTotalHoursLBL.Text = totals[0].ToString("0.0");
        finalTotal += totals[0];
        monChargeLBL.Text = totals[1].ToString("0.0");
        monTotalHoursLBL.Text = totals[1].ToString("0.0");
        finalTotal += totals[1];
        tuesChargeLBL.Text = totals[2].ToString("0.0");
        tuesTotalHoursLBL.Text = totals[2].ToString("0.0");
        finalTotal += totals[2];
        wedsChargeLBL.Text = totals[3].ToString("0.0");
        wedsTotalHoursLBL.Text = totals[3].ToString("0.0");
        finalTotal += totals[3];
        thursChargeLBL.Text = totals[4].ToString("0.0");
        thursTotalHoursLBL.Text = totals[4].ToString("0.0");
        finalTotal += totals[4];
        friChargeLBL.Text = totals[5].ToString("0.0");
        friTotalHoursLBL.Text = totals[5].ToString("0.0");
        finalTotal += totals[5];
        satChargeLBL.Text = totals[6].ToString("0.0");
        satTotalHoursLBL.Text = totals[6].ToString("0.0");
        finalTotal += totals[6];

        totalChargeLBL.Text = finalTotal.ToString("0.0");
        // if hours exceed 60 throw a dialog or 12 for any day
        if (totals[0] > OVERTIME_THRESHOLD || totals[1] > OVERTIME_THRESHOLD || totals[2] > OVERTIME_THRESHOLD || totals[3] > OVERTIME_THRESHOLD ||
           totals[4] > OVERTIME_THRESHOLD || totals[5] > OVERTIME_THRESHOLD || totals[6] > OVERTIME_THRESHOLD)
        {
            // throw a dialog
            dialogTitle = "Regular Hours Exceeded";
            msg = "A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
Example #21
0
 public TimesheetUtil(IMapper mapper, TimesheetManager tsManager)
 {
     _tsManager = tsManager;
     _mapper    = mapper;
 }
    // this method should be called after the updateChargeableTotal method to display the of sum the two values
    protected void updateNonChargeableTotals()
    {
        TimesheetManager tm = new TimesheetManager();
        decimal[] totals = tm.getEmpNonChargeableTotalsForID(timesheetID);
        decimal finalTotal = 0;
        sunNonChLBL.Text = totals[0].ToString("0.0");

        sunTotalHoursLBL.Text = (totals[0] + Convert.ToDecimal(sunTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[0];
        monNonChLBL.Text = totals[1].ToString("0.0");
        monTotalHoursLBL.Text = (totals[1] + Convert.ToDecimal(monTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[1];
        tuesNonChLBL.Text = totals[2].ToString("0.0");
        tuesTotalHoursLBL.Text = (totals[2] + Convert.ToDecimal(tuesTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[2];
        wedsNonChLBL.Text = totals[3].ToString("0.0");
        wedsTotalHoursLBL.Text = (totals[3] + Convert.ToDecimal(wedsTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[3];
        thursNonChLBL.Text = totals[4].ToString("0.0");
        thursTotalHoursLBL.Text = (totals[4] + Convert.ToDecimal(thursTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[4];
        friNonChLBL.Text = totals[5].ToString("0.0");
        friTotalHoursLBL.Text = (totals[5] + Convert.ToDecimal(friTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[5];
        satNonChLBL.Text = totals[6].ToString("0.0");
        satTotalHoursLBL.Text = (totals[6] + Convert.ToDecimal(satTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[6];
        totalNonChargeLBL.Text = finalTotal.ToString("0.0");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        dbData = new string[7] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
        weekEndingTB.Enabled = false;
        // Fields to populate when user visits this page: Employee ID, Employee Name, and Branch
        TimesheetManager tm = new TimesheetManager();
        projectNumTB.Enabled = true;
        if (!IsPostBack)
        {
            // populate generic non-chargeable drop down list elements
            specifyDDL.DataSource = tm.getWorkType();
            specifyDDL.DataBind();
            specifyDDL.Items.Insert(0, "Select");
            detailsDDL.DataSource = tm.getExpenses();
            detailsDDL.DataBind();
            detailsDDL.Items.Insert(0, "Select");

            // sub-menu's of non-chargeable section
            NonChargeExpensesPanel.Visible = false;
            NonChargeHoursPanel.Visible = false;

            // check query strings for form data to be populated
            if (Request.QueryString.Count > 0)
            {
                string timesheet = Request.QueryString["time"];
                string expense = Request.QueryString["expense"];
                string hours = Request.QueryString["hours"];
                string project = Request.QueryString["project"];
                string classification = Request.QueryString["class"];
                string activity = Request.QueryString["activity"];
                int chID = Convert.ToInt32(Request.QueryString["charge"]);
                int nonChID = Convert.ToInt32(Request.QueryString["nonCh"]);
                string delete = Request.QueryString["delete"];
                int lab = Convert.ToInt32(Request.QueryString["test"]);

                // reset weekending dates
                ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);

                int id = Convert.ToInt32(timesheet);
                timesheetID = id;
                HiddenField1.Value = id.ToString();

                // handle lab hours
                if (lab > 0 && delete != "delete")
                {
                    List<ManagerTest> tests = tm.getManagerTestsForTimeSheet(id);
                    updateLabTestsBtn.Visible = true;
                    labTestsBtn.Visible = false;
                    aID = 1;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    foreach (ManagerTest item in tests)
                    {
                        if (item.Day == "Sunday")
                        {
                            sunLabTB.Text = item.LabTest.ToString();
                            sunNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Monday")
                        {
                            monLabTB.Text = item.LabTest.ToString();
                            monNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Tuesday")
                        {
                            tuesLabTB.Text = item.LabTest.ToString();
                            tuesNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Wednesday")
                        {
                            wedsLabTB.Text = item.LabTest.ToString();
                            wedsNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Thursday")
                        {
                            thursLabTB.Text = item.LabTest.ToString();
                            thursNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Friday")
                        {
                            friLabTB.Text = item.LabTest.ToString();
                            friNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Saturday")
                        {
                            satLabTB.Text = item.LabTest.ToString();
                            satNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                    }
                }

                // set static properties on the webpage
                weekEndingTB.Text = tm.getWeekendingForTimeSheet(id);
                // if there is a query string, load the totals from the corresponding timesheet

                if (delete == "delete")
                {

                   tm.deleteSummary(nonChID, chID, id, lab, true);
                    summaryGV.Focus();
                }
                // update Timesheet Totals
                updateTimeSheetTotals();
                TimeSheet t = tm.getTimesheetForID(timesheetID);
                // get and populate user information
                User emp = tm.getEmployeeForId(t.EmployeeId);
                empIdTB.Text = emp.empNo;
                nameTB.Text = emp.FirstName + " " + emp.MiddleName + " " + emp.LastName;
                departmentTB.Text = emp.branch;
                if (Request.QueryString["projectOnly"] != null)
                {
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    projectNumTB.Text = p.ProjectNo;
                    projectNameTB.Text = p.ProjectName;
                    clientNameTB.Text = p.ClientName;
                    classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                    classificationDDL.DataBind();
                    classificationDDL.SelectedValue = classification;

                    projectNumTB.Enabled = true;
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                }
                // Chargeable
                else if (project != null && project != "0" && project != string.Empty)
                {
                    // adjust accordion panels
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    // populate the project information fields
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    if (p != null)
                    {
                        projectNumTB.Text = p.ProjectNo;
                        projectNameTB.Text = p.ProjectName;
                        clientNameTB.Text = p.ClientName;
                        classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                        classificationDDL.DataBind();
                        classificationDDL.SelectedValue = classification;

                        activitiesDDL.DataSource = tm.getActivityForClassification(classification);
                        activitiesDDL.DataBind();
                        activitiesDDL.SelectedValue = activity;

                        // adjust buttons
                        chargeableBtn.Visible = false;
                        updateChargeableBtn.Visible = true;

                        // populate the chargeable fields based on the classification and activity selected
                        List<ManagerChargeable> cJobs = tm.getManagerChargeableForID(timesheetID);

                        if (chID > 0)
                        {
                            cJobs.Add(tm.getManagerChargeForID(chID));
                        }

                        if (cJobs != null)
                        {
                            foreach (var item in cJobs)
                            {
                                if (item.Day == "Sunday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        sunBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        sunBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance
                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        sunBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }

                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        sunTruckDistTB.Text = item.TruckDistance.ToString();
                                    }

                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        sunBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }

                                    sunCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Monday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        monBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours

                                    if (item.BillingHours.HasValue)
                                    {
                                        monBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        monBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        monTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        monBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    monCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Tuesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        tuesBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours

                                    if (item.BillingHours.HasValue)
                                    {
                                        tuesBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        tuesBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        tuesTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        tuesBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    tuesCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Wednesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        wedsBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours

                                    if (item.BillingHours.HasValue)
                                    {
                                        wedsBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        wedsBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        wedsTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        wedsBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    wedsCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Thursday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        thursBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        thursBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        thursBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        thursTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        thursBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    thursCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Friday" && item.Classification == classification && item.Activity == activity)
                                {    // Accomodation
                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        friBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        friBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        friBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        friTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        friBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    friCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Saturday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation
                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        satBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        satBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance
                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        satBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        satTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc
                                    if (item.BillingMisc.HasValue)
                                    {
                                        satBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    satCRemarksTB.Text = item.Remarks;
                                }
                            }
                        }
                    }
                }
                // Non-Chargeable
                else if (expense != string.Empty && expense != null || hours != string.Empty && hours != null)
                {
                    // activate corresponding accordion panel
                    aID = 2;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);

                    // set the dropdownlists and display the different panels accordingly
                    if (hours != string.Empty)
                    {
                        specifyDDL.SelectedValue = hours;
                        NonChargeHoursPanel.Visible = true;
                    } if (expense != string.Empty)
                    {
                        detailsDDL.SelectedValue = expense;
                        NonChargeExpensesPanel.Visible = true;
                    }

                    // adjust buttons
                    nonChargeBtn.Visible = false;
                    updateNonChargeableBtn.Visible = true;

                    List<ManagerNonChargeable> nonCh = tm.getManagerNonChargeableForTimesheetID(timesheet, expense, hours);
                    if (nonCh != null)
                    {
                        // populate the non chargeable text fields based on the expense and type of hours selected
                        foreach (var item in nonCh)
                        {
                            if (item.Day == "Sunday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    sunNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                sunNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                sunNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    sunNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }

                                sunNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Monday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    monNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                monNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                monNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    monNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }

                                monNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Tuesday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    tuesNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                tuesNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                tuesNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    tuesNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }

                                tuesNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Wednesday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    wedsNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                wedsNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                wedsNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    wedsNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                                wedsNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Thursday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    thursNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                thursNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                thursNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    thursNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                                thursNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Friday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    friNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                friNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                friNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    friNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                                friNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Saturday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    satNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                satNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                satNCDistanceTB.Text = item.Distance.ToString();
                                satNCRemarksTB.Text = item.Remarks;
                                if (item.Misc.HasValue)
                                {
                                    satNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                            }
                        }
                    }
                }
            }
        }
        // check to see if weekending is specified update the gridviews
        if (weekEndingTB.Text != string.Empty)
        {
            // re-populate the dates
            ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
            // Get the timesheet id for the users whos timesheet we are managing
            string username = tm.getUsernameForEmpNo(empIdTB.Text);
            int id = tm.idForDate(weekEndingTB.Text, tm.idForUsername(username));

            if (id != 0)
            {
                timesheetID = id;
                HiddenField1.Value = id.ToString();
                // update totals
                updateTimeSheetTotals();
                summaryGV.DataBind();
            }
        }
        // populate the predictive text arrays
        projectNoDB = tm.getProjectNumbers();
    }
    protected void updateLabTestsBtn_Click(object sender, EventArgs e)
    {
        bool valid = true;
        TimesheetManager tm = new TimesheetManager();
        decimal tHours = Convert.ToDecimal(totalHoursLBL.Text);
        // try to update, if cannot update, then create new lab test
        if (sunLabTB.Text != string.Empty && sunLabTB.Text != "0")
        {
            if (!hoursValidator(sunLabTB.Text, "Sunday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, false, ref tHours);
            }
            sunLabTB.Text = string.Empty;
            sunNuclearDensityTestTB.Text = string.Empty;
        }

        if (monLabTB.Text != string.Empty && monLabTB.Text != "0")
        {
            if (!hoursValidator(monLabTB.Text, "Monday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Monday", monNuclearDensityTestTB.Text, monLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Monday", monNuclearDensityTestTB.Text, monLabTB.Text, timesheetID, false, ref tHours);
            }
            monLabTB.Text = string.Empty;
            monNuclearDensityTestTB.Text = string.Empty;
        }

        if (tuesLabTB.Text != string.Empty && tuesLabTB.Text != "0")
        {
            if (!hoursValidator(tuesLabTB.Text, "Tuesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Tuesday", tuesNuclearDensityTestTB.Text, tuesLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Tuesday", tuesNuclearDensityTestTB.Text, tuesLabTB.Text, timesheetID, false, ref tHours);
            }
            tuesLabTB.Text = string.Empty;
            tuesNuclearDensityTestTB.Text = string.Empty;
        }

        if (wedsLabTB.Text != string.Empty && wedsLabTB.Text != "0")
        {
            if (!hoursValidator(wedsLabTB.Text, "Wednesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, false, ref tHours);
            }
            wedsLabTB.Text = string.Empty;
            wedsNuclearDensityTestTB.Text = string.Empty;
        }

        if (thursLabTB.Text != string.Empty && thursLabTB.Text != "0")
        {
            if (!hoursValidator(thursLabTB.Text, "Thursday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, false, ref tHours);
            }
            thursLabTB.Text = string.Empty;
            thursNuclearDensityTestTB.Text = string.Empty;
        }

        if (friLabTB.Text != string.Empty && friLabTB.Text != "0")
        {
            if (!hoursValidator(friLabTB.Text, "Friday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, false, ref tHours);
            }
            friLabTB.Text = string.Empty;
            friNuclearDensityTestTB.Text = string.Empty;
        }

        if (satLabTB.Text != string.Empty && satLabTB.Text != "0")
        {
            if (!hoursValidator(satLabTB.Text, "Saturday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, false, ref tHours);
            }
            satLabTB.Text = string.Empty;
            satNuclearDensityTestTB.Text = string.Empty;
        }

        totalHoursLBL.Text = tHours.ToString("0.0");
        updateLabTotals();
        // update timesheet
        tm.updateTimeSheet(timesheetID, tHours, Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Updated", " ", " ");

        summaryGV.DataBind();
        updateLabTestsBtn.Visible = false;
        labTestsBtn.Visible = true;
    }
    protected void updateNonChargeableBtn_Click(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        bool result, valid = true;
        int count = 0, nCDist = Convert.ToInt32(totalDistanceLBL.Text), tDist = Convert.ToInt32(totalTruckLBL.Text);
        decimal nCHours = Convert.ToDecimal(totalHoursLBL.Text), nCExpense = Convert.ToDecimal(Convert.ToDecimal(totalExpensesLBL.Text));

        //sunday
        if (sunNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(sunNCHoursTB.Text, "Sunday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(sunNCHoursTB.Text, sunNCAccomTB.Text, sunNCDistanceTB.Text, sunNCMiscTB.Text, "Sunday",
                 detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, sunNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(sunNCHoursTB.Text, sunNCAccomTB.Text, sunNCDistanceTB.Text, sunNCMiscTB.Text, "Sunday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, sunNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // monday
        if (monNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(monNCHoursTB.Text, "Monday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(monNCHoursTB.Text, monNCAccomTB.Text, monNCDistanceTB.Text, monNCMiscTB.Text, "Monday",
                  detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, monNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(monNCHoursTB.Text, monNCAccomTB.Text, monNCDistanceTB.Text, monNCMiscTB.Text, "Monday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, monNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // tuesday
        if (tuesNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(tuesNCHoursTB.Text, "Tuesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(tuesNCHoursTB.Text, tuesNCAccomTB.Text, tuesNCDistanceTB.Text, tuesNCMiscTB.Text, "Tuesday",
                 detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(tuesNCHoursTB.Text, tuesNCAccomTB.Text, tuesNCDistanceTB.Text, tuesNCMiscTB.Text, "Tuesday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // wednessday
        if (wedsNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(wedsNCHoursTB.Text, "Wednesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(wedsNCHoursTB.Text, wedsNCAccomTB.Text, wedsNCDistanceTB.Text, wedsNCMiscTB.Text, "Wednesday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, wedsNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(wedsNCHoursTB.Text, wedsNCAccomTB.Text, wedsNCDistanceTB.Text, wedsNCMiscTB.Text, "Wednesday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, wedsNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // thursday
        if (thursNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(thursNCHoursTB.Text, "Thursday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(thursNCHoursTB.Text, thursNCAccomTB.Text, thursNCDistanceTB.Text, thursNCMiscTB.Text, "Thursday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, thursNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(thursNCHoursTB.Text, thursNCAccomTB.Text, thursNCDistanceTB.Text, thursNCMiscTB.Text, "Thursday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, thursNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // friday
        if (friNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(friNCHoursTB.Text, "Friday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(friNCHoursTB.Text, friNCAccomTB.Text, friNCDistanceTB.Text, friNCMiscTB.Text, "Friday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, friNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(friNCHoursTB.Text, friNCAccomTB.Text, friNCDistanceTB.Text, friNCMiscTB.Text, "Friday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, friNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // saturday
        if (satNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(satNCHoursTB.Text, "Saturday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(satNCHoursTB.Text, satNCAccomTB.Text, satNCDistanceTB.Text, satNCMiscTB.Text, "Saturday",
             detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, satNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(satNCHoursTB.Text, satNCAccomTB.Text, satNCDistanceTB.Text, satNCMiscTB.Text, "Saturday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, satNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // update the totalized labels
        totalHoursLBL.Text = nCHours.ToString("0.0");
        totalExpensesLBL.Text = nCExpense.ToString("0.00##");
        totalDistanceLBL.Text = nCDist.ToString();

        // if hours exceed 60 throw a dialog
        if (nCHours > MAX_WEEKLY_HOURS)
        {
            // throw a dialog
            dialogTitle = "Regular Weekly Hours Exceeded";
            msg = "You Worked more than 60 hours. A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }

        tm.updateTimeSheet(timesheetID, nCHours, nCDist, tDist, nCExpense, "Updated", " ", " ");
        // update gridview
        summaryGV.DataBind();
        // clear form fields
        clearNonChargeable();
        // update totals
        updateNonChargeableTotals();
        // reset drop down list to first index
        detailsDDL.SelectedIndex = 0;
        specifyDDL.SelectedIndex = 0;
        NonChargeHoursPanel.Visible = false;
        NonChargeExpensesPanel.Visible = false;

        updateNonChargeableBtn.Visible = false;
        nonChargeBtn.Visible = true;
    }
    protected void updateChargeableBtn_Click(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        bool result, valid = true;
        int count = 0, cDist = Convert.ToInt32(totalDistanceLBL.Text), tDist = Convert.ToInt32(totalTruckLBL.Text);
        decimal cHours = Convert.ToDecimal(totalHoursLBL.Text), cExpense = Convert.ToDecimal(Convert.ToDecimal(totalExpensesLBL.Text)); ;
        int id = tm.idForProjectNo(projectNumTB.Text);

        // sunday

        if (sunCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(sunCHoursTB.Text, "Sunday", true))
            {
                valid = false;
            }
        }

        if (valid)
        {
            result = tm.updateChargeable(sunCHoursTB.Text, sunAccomTB.Text, sunDistTB.Text, sunTruckDistTB.Text, sunMiscTB.Text, "Sunday", id, classificationDDL.SelectedValue,
        activitiesDDL.SelectedValue, timesheetID, sunCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(sunCHoursTB.Text, sunAccomTB.Text, sunDistTB.Text, sunTruckDistTB.Text, sunMiscTB.Text, "Sunday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, sunCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // monday

        if (monCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(monCHoursTB.Text, "Monday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(monCHoursTB.Text, monAccomTB.Text, monDistTB.Text, monTruckDistTB.Text, monMiscTB.Text, "Monday", id, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, monCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(monCHoursTB.Text, monAccomTB.Text, monDistTB.Text, monTruckDistTB.Text, monMiscTB.Text, "Monday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, monCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // tuesday
        if (tuesCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(tuesCHoursTB.Text, "Tuesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(tuesCHoursTB.Text, tuesAccomTB.Text, tuesDistTB.Text, tuesTruckDistTB.Text, tuesMiscTB.Text, "Tuesday", id, classificationDDL.SelectedValue,
              activitiesDDL.SelectedValue, timesheetID, tuesCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(tuesCHoursTB.Text, tuesAccomTB.Text, tuesDistTB.Text, tuesTruckDistTB.Text, tuesMiscTB.Text, "Tuesday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, tuesCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // Wednesday
        if (wedsCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(wedsCHoursTB.Text, "Wednesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(wedsCHoursTB.Text, wedsAccomTB.Text, wedsDistTB.Text, wedsTruckDistTB.Text, wedsMiscTB.Text, "Wednesday", id, classificationDDL.SelectedValue,
               activitiesDDL.SelectedValue, timesheetID, wedsCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(wedsCHoursTB.Text, wedsAccomTB.Text, wedsDistTB.Text, wedsTruckDistTB.Text, wedsMiscTB.Text, "Wednesday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, wedsCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // Thursday
        if (thursCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(thursCHoursTB.Text, "Thursday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(thursCHoursTB.Text, thursAccomTB.Text, thursDistTB.Text, thursTruckDistTB.Text, thursMiscTB.Text, "Thursday", id, classificationDDL.SelectedValue,
              activitiesDDL.SelectedValue, timesheetID, thursCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(thursCHoursTB.Text, thursAccomTB.Text, thursDistTB.Text, thursTruckDistTB.Text, thursMiscTB.Text, "Thursday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, thursCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // friday
        if (friCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(friCHoursTB.Text, "Friday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(friCHoursTB.Text, friAccomTB.Text, friDistTB.Text, friTruckDistTB.Text, friMiscTB.Text, "Friday", id, classificationDDL.SelectedValue,
          activitiesDDL.SelectedValue, timesheetID, friCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(friCHoursTB.Text, friAccomTB.Text, friDistTB.Text, friTruckDistTB.Text, friMiscTB.Text, "Friday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, friCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // Saturday
        if (satCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(satCHoursTB.Text, "Saturday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(satCHoursTB.Text, satAccomTB.Text, satDistTB.Text, satTruckDistTB.Text, satMiscTB.Text, "Saturday", id, classificationDDL.SelectedValue,
                 activitiesDDL.SelectedValue, timesheetID, satCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(satCHoursTB.Text, satAccomTB.Text, satDistTB.Text, satTruckDistTB.Text, satMiscTB.Text, "Saturday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, satCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // update the totalized labels
        totalHoursLBL.Text = cHours.ToString("0.0");
        totalExpensesLBL.Text = cExpense.ToString("0.00##");
        totalDistanceLBL.Text = cDist.ToString();
        totalTruckLBL.Text = tDist.ToString();
        // if hours exceed 60 throw a dialog
        if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
        {
            // throw a dialog
            dialogTitle = "Regular Hours Exceeded";
            msg = "A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
        // if hours exceed 60 throw a dialog
        if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
        {
            // throw a dialog
            dialogTitle = "Regular Hours Exceeded";
            msg = "A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "FillOTForm", "throwDialog();", true);
        }
        tm.updateTimeSheet(timesheetID, cHours, cDist, tDist, cExpense, "Updated", " ", " ");

        // update gridview
        summaryGV.DataBind();

        updateChargeableBtn.Visible = false;
        chargeableBtn.Visible = true;
        // update totals
        updateChargeableTotals();
        updateLabTotals();
        updateNonChargeableTotals();
        // clear form fields
        clearChargeable();

        // chargeable fields
        clientNameTB.Text = string.Empty;
        projectNameTB.Text = string.Empty;
        projectNumTB.Text = string.Empty;
        classificationDDL.Items.Clear();
        activitiesDDL.Items.Clear();
    }
Example #27
0
 public EmployeeController()
 {
     _tsManager      = new TimesheetManager();
     _accountManager = new AccountManager();
     _tsUtil         = new TimesheetUtil(Mapper, _tsManager);
 }
Example #28
0
 public TimesheetController()
 {
     _tsManager = new TimesheetManager();
     _tsUtil    = new TimesheetUtil(Mapper, _tsManager);
 }
    protected void completeBtn_Click(object sender, EventArgs e)
    {
        try
        {
            // if chargeable or non chargeable are being edited prompt user to save or update changes, else execute intended code
            if (activitiesDDL.Items.Count > 0 || specifyDDL.SelectedValue != "Select" || detailsDDL.SelectedValue != "Select")
            {
                // throw a dialog
                msg = "You have Un-Saved work on this Page, Please save,update or Clear the form";
                dialogTitle = "Warning: Un-saved Work";

                ScriptManager.RegisterStartupScript(this, this.GetType(), "unsavedwork", "throwDialog();", true);
            }
            else
            {
                TimesheetManager tm = new TimesheetManager();
                tm.updateTimeSheet(Convert.ToInt32(HiddenField1.Value), Convert.ToDecimal(totalHoursLBL.Text), Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Approved", empCommentsTB.Text, " ");
                //// update user status
                //AdminManager am = new AdminManager();
                //User user = tm.getEmployeeForId(timesheetID);
                //am.updateEmployee(Membership.GetUser().UserName, "Incomplete", user.branch, user.ManagedBy);
                dialogTitle = "Timesheet Approved";
                msg = "Timesheet has Been Approved.";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "timesheetSubmitted", "throwDialog();", true);
            }
        }
        catch (Exception)
        {
            // throw a dialog
            msg = "Your TimeSheet was not Approved.";
            dialogTitle = "TimeSheet not Approved";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "weekending", "throwDialog();", true);

        }
    }
        public List <TimesheetReportItemView> GetTimeSheetsReport()
        {
            var timesheets = TimesheetManager.GetTimesheetReportItems();

            return(timesheets);
        }
    // get totals for chargeable and final total hours
    protected void updateChargeableTotals()
    {
        TimesheetManager tm = new TimesheetManager();

        decimal[] totals = tm.getEmpChargeableTotalsForID(timesheetID);
        decimal finalTotal = 0;

        sunChargeLBL.Text = totals[0].ToString("0.0");
        sunTotalHoursLBL.Text = totals[0].ToString("0.0");
        finalTotal += totals[0];
        monChargeLBL.Text = totals[1].ToString("0.0");
        monTotalHoursLBL.Text = totals[1].ToString("0.0");
        finalTotal += totals[1];
        tuesChargeLBL.Text = totals[2].ToString("0.0");
        tuesTotalHoursLBL.Text = totals[2].ToString("0.0");
        finalTotal += totals[2];
        wedsChargeLBL.Text = totals[3].ToString("0.0");
        wedsTotalHoursLBL.Text = totals[3].ToString("0.0");
        finalTotal += totals[3];
        thursChargeLBL.Text = totals[4].ToString("0.0");
        thursTotalHoursLBL.Text = totals[4].ToString("0.0");
        finalTotal += totals[4];
        friChargeLBL.Text = totals[5].ToString("0.0");
        friTotalHoursLBL.Text = totals[5].ToString("0.0");
        finalTotal += totals[5];
        satChargeLBL.Text = totals[6].ToString("0.0");
        satTotalHoursLBL.Text = totals[6].ToString("0.0");
        finalTotal += totals[6];
        totalChargeLBL.Text = finalTotal.ToString("0.0");
    }
    protected void labTestsBtn_Click(object sender, EventArgs e)
    {
        decimal tHours = Convert.ToDecimal(totalHoursLBL.Text);
        bool valid = true;
        // begin to save tests if there is a timesheet id of non zero and weekending date exists
        if (weekEndingTB.Text != string.Empty && timesheetID != 0)
        {
            TimesheetManager tm = new TimesheetManager();
            // Sunday
            if (sunLabTB.Text != string.Empty && sunLabTB.Text != "0")
            {
                if (!hoursValidator(sunLabTB.Text, "Sunday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, false, ref tHours);
                sunLabTB.Text = string.Empty;
                sunNuclearDensityTestTB.Text = string.Empty;
            }

            // Monday
            if (monLabTB.Text != string.Empty && monLabTB.Text != "0")
            {
                if (!hoursValidator(monLabTB.Text, "Monnday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Monday", monNuclearDensityTestTB.Text, monLabTB.Text, timesheetID, false, ref tHours);
                monLabTB.Text = string.Empty;
                monNuclearDensityTestTB.Text = string.Empty;
            }

            // Tuesday
            if (tuesLabTB.Text != string.Empty && tuesLabTB.Text != "0")
            {
                if (!hoursValidator(tuesLabTB.Text, "Tuesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Tuesday", tuesNuclearDensityTestTB.Text, tuesLabTB.Text, timesheetID, false, ref tHours);
                tuesLabTB.Text = string.Empty;
                tuesNuclearDensityTestTB.Text = string.Empty;
            }

            // Wednesday
            if (wedsLabTB.Text != string.Empty && wedsLabTB.Text != "0")
            {
                if (!hoursValidator(wedsLabTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, false, ref tHours);
                wedsLabTB.Text = string.Empty;
                wedsNuclearDensityTestTB.Text = string.Empty;
            }

            // Thursday
            if (thursLabTB.Text != string.Empty && thursLabTB.Text != "0")
            {
                if (!hoursValidator(thursLabTB.Text, "Thursday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, false, ref tHours);
                thursLabTB.Text = string.Empty;
                thursNuclearDensityTestTB.Text = string.Empty;
            }

            // Friday
            if (friLabTB.Text != string.Empty && friLabTB.Text != "0")
            {
                if (!hoursValidator(friLabTB.Text, "Friday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, false, ref tHours);
                friLabTB.Text = string.Empty;
                friNuclearDensityTestTB.Text = string.Empty;
            }

            // Saturday
            if (satLabTB.Text != string.Empty && satLabTB.Text != "0")
            {
                if (!hoursValidator(satLabTB.Text, "Saturday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, false, ref tHours);
                satLabTB.Text = string.Empty;
                satNuclearDensityTestTB.Text = string.Empty;
            }
            updateLabTotals();
            totalHoursLBL.Text = tHours.ToString("0.0");

            // update timesheet
            tm.updateTimeSheet(timesheetID, tHours, Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Updated", " ", " ");
            // update gridview
            summaryGV.DataBind();
        }
        else
        {
            dialogTitle = "Missing Weekending Date";
            msg = "The timesheet needs a verified Weekending Date in order to proceed";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
    protected void updateLabTotals()
    {
        TimesheetManager tm = new TimesheetManager();
        decimal[] totals = tm.getLabTotalsForId(timesheetID, false);
        decimal finalTotal = 0;
        sunLabLBL.Text = totals[0].ToString("0.0");

        sunTotalHoursLBL.Text = (totals[0] + Convert.ToDecimal(sunTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[0];
        monLabLBL.Text = totals[1].ToString("0.0");
        monTotalHoursLBL.Text = (totals[1] + Convert.ToDecimal(monTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[1];
        tuesLabLBL.Text = totals[2].ToString("0.0");
        tuesTotalHoursLBL.Text = (totals[2] + Convert.ToDecimal(tuesTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[2];
        wedsLabLBL.Text = totals[3].ToString("0.0");
        wedsTotalHoursLBL.Text = (totals[3] + Convert.ToDecimal(wedsTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[3];
        thursLabLBL.Text = totals[4].ToString("0.0");
        thursTotalHoursLBL.Text = (totals[4] + Convert.ToDecimal(thursTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[4];
        friLabLBL.Text = totals[5].ToString("0.0");
        friTotalHoursLBL.Text = (totals[5] + Convert.ToDecimal(friTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[5];
        satLabLBL.Text = totals[6].ToString("0.0");
        satTotalHoursLBL.Text = (totals[6] + Convert.ToDecimal(satTotalHoursLBL.Text)).ToString("0.0");

        finalTotal += totals[6];
        totalLabLBL.Text = finalTotal.ToString("0.0");
    }
    protected void verifyBtn_Click(object sender, EventArgs e)
    {
        // if chargeable or non chargeable are being edited prompt user to save or update changes, else execute intended code for verify
        if (activitiesDDL.Items.Count > 0 || specifyDDL.SelectedValue != "Select" || detailsDDL.SelectedValue != "Select")
        {
            // throw a dialog
            msg = "You have Un-Saved work on this Page, Please save,update or Clear the form";
            dialogTitle = "Warning: Un-saved Work";

            ScriptManager.RegisterStartupScript(this, this.GetType(), "unsavedwork", "throwDialog();", true);
        }
        else
        {
            if (weekEndingTB.Text != string.Empty)
            {
                // disable the non chargeable hours and expense panels
                NonChargeHoursPanel.Visible = false;
                NonChargeExpensesPanel.Visible = false;
                specifyDDL.SelectedIndex = 0;
                detailsDDL.SelectedIndex = 0;

                TimesheetManager tm = new TimesheetManager();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
                int userID = tm.idForUsername(Membership.GetUser().UserName);
                timesheetID = tm.idForDate(weekEndingTB.Text, userID);
                projectNumTB.Enabled = true;

                // if a timesheet does not exist for the weekending date, create a new one
                if (timesheetID == 0)
                {
                    TimeSheet t = new TimeSheet();
                    t.WeekEnding = weekEndingTB.Text;
                    t.EmployeeId = userID;
                    t.DateCreated = DateTime.Now;
                    t.DateModified = DateTime.Now;
                    t.Status = "Started";
                    t.EmployeeName = nameTB.Text;
                    t.TotalHours = 0;
                    t.TotalExpenses = 0;
                    t.TotalDistance = 0;
                    t.Branch = departmentTB.Text;
                    totalDistanceLBL.Text = "0";
                    totalExpensesLBL.Text = "0";
                    totalHoursLBL.Text = "0";
                    totalTruckLBL.Text = "0";

                    // populate global variables
                    timesheetID = tm.createTimesheet(t);

                    HiddenField1.Value = t.TimeSheetId.ToString();
                    // enable controls
                    projectNumTB.Enabled = true;
                }
                else
                {
                    TimeSheet ts = tm.getTimesheetForID(timesheetID);
                    if (ts != null)
                    {
                        if (ts.Status == "Completed" || ts.Status == "Approved" || ts.Status == "Manager - Updated" || ts.Status == "Synchronized")
                        {
                            // throw a dialog
                            dialogTitle = "Completed TimeSheet";
                            msg = "The timesheet for this weekending date has already been Completed and Approved";
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);

                            // disable edit and delete columns
                            summaryGV.Columns[0].Visible = false;
                            summaryGV.Columns[1].Visible = false;
                            summaryGV.Columns[0].Visible = false;
                            summaryGV.Columns[1].Visible = false;
                            // disable the save buttons
                            chargeableBtn.Visible = false;
                            nonChargeBtn.Visible = false;
                            labTestsBtn.Visible = false;
                            updateChargeableBtn.Visible = false;
                            updateNonChargeableBtn.Visible = false;
                            updateLabTestsBtn.Visible = false;

                            // update totals
                            updateTimeSheetTotals();
                        }
                        else
                        {
                            // UPDATE TOTALS
                            updateTimeSheetTotals();
                            // for gridview
                            HiddenField1.Value = timesheetID.ToString();
                            // enable controls
                            projectNumTB.Enabled = true;

                            // re-ENABLE edit and delete columns
                            summaryGV.Columns[0].Visible = true;
                            summaryGV.Columns[1].Visible = true;
                            summaryGV.Columns[0].Visible = true;
                            summaryGV.Columns[1].Visible = true;
                            // re-enable the save buttons
                            chargeableBtn.Visible = true;
                            nonChargeBtn.Visible = true;
                            labTestsBtn.Visible = true;
                        }
                    }
                }
                // re-populate the dates
                ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
                summaryGV.DataBind();
            }
        }
    }
    protected void classificationDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        activitiesDDL.DataSource = tm.getActivityForClassification(classificationDDL.SelectedValue);
        activitiesDDL.DataBind();
        activitiesDDL.Focus();

        // re-populate the dates
        ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
        // activate corresponding accordion panel
        aID = 0;
        ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
    }
    // get project no for ID
    protected string getProjectNum(object idObj)
    {
        if (string.IsNullOrEmpty(idObj.ToString()))
            return null;

        int id = Convert.ToInt32(idObj.ToString());
        TimesheetManager tm = new TimesheetManager();
        return tm.getProjectNoForID(id);
    }
    protected void updateTimeSheetTotals()
    {
        TimesheetManager tm = new TimesheetManager();

        TimeSheet ts = tm.getTimesheetForID(timesheetID);

        if (ts != null)
        {
            // populate totals check for nulls and empty string
            if (ts.TotalDistance.ToString() == null || ts.TotalDistance.ToString() == string.Empty)
            {
                totalDistanceLBL.Text = "0";
            }
            else
            {
                totalDistanceLBL.Text = ts.TotalDistance.ToString();
            }

            // populate totals check for nulls and empty string
            if (ts.TotalTruck.ToString() == null || ts.TotalTruck.ToString() == string.Empty)
            {
                totalTruckLBL.Text = "0";
            }
            else
            {
                totalTruckLBL.Text = ts.TotalTruck.ToString();
            }

            if (ts.TotalExpenses.ToString() == null || ts.TotalExpenses.ToString() == string.Empty)
            {
                totalExpensesLBL.Text = "0";
            }
            else
            {
                totalExpensesLBL.Text = ts.TotalExpenses.Value.ToString("0.####");
            }

            if (ts.TotalHours.ToString() == null || ts.TotalHours.ToString() == string.Empty)
            {
                totalHoursLBL.Text = "0";
            }
            else
            {
                totalHoursLBL.Text = ts.TotalHours.Value.ToString("0.#");
            }
            // update totals
            updateChargeableTotals();
            updateLabTotals();
            updateNonChargeableTotals();
        }
    }
    protected void labTestsBtn_Click(object sender, EventArgs e)
    {
        bool valid = true;
        decimal tHours = Convert.ToDecimal(totalHoursLBL.Text);
        if (weekEndingTB.Text != string.Empty && timesheetID > 0)
        {
            TimesheetManager tm = new TimesheetManager();
            // Sunday
            if (sunLabTB.Text != string.Empty && sunLabTB.Text != "0")
            {
                if (!hoursValidator(sunLabTB.Text, "Sunday",false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, true, ref tHours);
                sunLabTB.Text = string.Empty;
                sunNuclearDensityTestTB.Text = string.Empty;
            }

            // Monday
            if (monLabTB.Text != string.Empty && monLabTB.Text != "0")
            {
                if (!hoursValidator(monLabTB.Text, "Monday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Monday", monNuclearDensityTestTB.Text, monLabTB.Text, timesheetID, true, ref tHours);
                monLabTB.Text = string.Empty;
                monNuclearDensityTestTB.Text = string.Empty;
            }

            // Tuesday
            if (tuesLabTB.Text != string.Empty && tuesLabTB.Text != "0")
            {
                if (!hoursValidator(tuesLabTB.Text, "Tuesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Tuesday", tuesNuclearDensityTestTB.Text, tuesLabTB.Text, timesheetID, true, ref tHours);
                tuesLabTB.Text = string.Empty;
                tuesNuclearDensityTestTB.Text = string.Empty;
            }

            // Wednesday
            if (wedsLabTB.Text != string.Empty && wedsLabTB.Text != "0")
            {
                if (!hoursValidator(wedsLabTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, true, ref tHours);
                wedsLabTB.Text = string.Empty;
                wedsNuclearDensityTestTB.Text = string.Empty;
            }
            // Thursday
            if (thursLabTB.Text != string.Empty && thursLabTB.Text != "0")
            {
                if (!hoursValidator(thursLabTB.Text, "Thursday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, true, ref tHours);
                thursLabTB.Text = string.Empty;
                thursNuclearDensityTestTB.Text = string.Empty;
            }
            // Friday
            if (friLabTB.Text != string.Empty && friLabTB.Text != "0")
            {
                if (!hoursValidator(friLabTB.Text, "Friday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, true, ref tHours);
                friLabTB.Text = string.Empty;
                friNuclearDensityTestTB.Text = string.Empty;
            }

            // SATURDAY
            if (satLabTB.Text != string.Empty && satLabTB.Text != "0")
            {
                if (!hoursValidator(satLabTB.Text, "Saturday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, true, ref tHours);
                satLabTB.Text = string.Empty;
                satNuclearDensityTestTB.Text = string.Empty;
            }

            totalHoursLBL.Text = tHours.ToString("0.0");
            updateLabTotals();
            // update timesheet
            tm.updateTimeSheet(timesheetID, tHours, Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Updated", " ", " ");
            // update gridview
            summaryGV.DataBind();
        }
        else
        {
            msg = "Select Weekending date and Verify before attempting to complete Timesheet";
            dialogTitle = "Error: Weekending Date";

            ScriptManager.RegisterStartupScript(this, this.GetType(), "InvalidEntry", "throwDialog();", true);
        }
    }
    protected void completeBtn_Click(object sender, EventArgs e)
    {
        try
        {
            // if chargeable or non chargeable are being edited prompt user to save or update changes, else execute intended code
            if (activitiesDDL.Items.Count > 0 || specifyDDL.SelectedValue != "Select" || detailsDDL.SelectedValue != "Select")
            {
                // throw a dialog
                msg = "You have Un-Saved work on this Page, Please save,update or Clear the form";
                dialogTitle = "Warning: Un-saved Work";

                ScriptManager.RegisterStartupScript(this, this.GetType(), "unsavedwork", "throwDialog();", true);
            }
            else
            {
                TimesheetManager tm = new TimesheetManager();
                TimeSheet t = tm.getTimesheetForID(timesheetID);
                // if the timesheet has been approved or completed, do not save the timesheet
                if (t.Status != "Approved" && t.Status != "Completed")
                {
                    tm.updateTimeSheet(timesheetID, Convert.ToDecimal(totalHoursLBL.Text), Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text),
                        Convert.ToDecimal(totalExpensesLBL.Text), "Completed", empCommentsTB.Text, " ");

                    // copy all of the timesheet's contents to managerial versions
                    tm.copyTimesheet(timesheetID);

                    dialogTitle = "Timesheet Complete";
                    msg = "Timesheet Completed and submitted to manager for Approval. You may view but not Re-submit this Timesheet";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "timesheetSubmitted", "throwDialog();", true);
                }
                else
                {
                    dialogTitle = "Timesheet Complete";
                    msg = "Timesheet has already been Completed or Approved. It cannot be re-submitted. Please Speak to Manager";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "timesheetSubmitted", "throwDialog();", true);
                }

                //  Server.Transfer("createTimeSheet.aspx");
            }
        }
        catch (Exception)
        {
            // throw a dialog
            msg = "Your TimeSheet was not Approved. Select a Weekending Date";
            dialogTitle = "TimeSheet not Approved";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "weekending", "throwDialog();", true);
        }
    }
    /// <summary>
    /// update manager chargeable expense record
    /// </summary>
    /// <param name="hours"></param>
    /// <param name="accom"></param>
    /// <param name="distance"></param>
    /// <param name="misc"></param>
    /// <param name="day"></param>
    /// <param name="projectNo"></param>
    /// <param name="classification"></param>
    /// <param name="activity"></param>
    /// <param name="timesheetID"></param>
    /// <returns></returns>
    public bool updateManagerChargeable(string bHours, string bAccom, string bDist, string truckDist, string bMisc,
        string day, int projectNo, string classification, string activity, int timesheetID, string remarks, ref decimal totalHours, ref int totalDist, ref int totalTruck, ref decimal totalExpense)
    {
        using (var context = new PetoEntities())
        {
            try
            {
                TimesheetManager tm = new TimesheetManager();
                ManagerChargeable cJob = context.ManagerChargeables.FirstOrDefault(x => x.ProjectId == projectNo && x.TimeSheetId == timesheetID && x.Day == day && x.Classification == classification && x.Activity == activity);

                // update fields
                if (cJob != null)
                {
                    // Hours
                    if (bHours != string.Empty)
                    {
                        if (cJob.BillingHours.HasValue)
                        {
                            totalHours -= cJob.BillingHours.Value;
                        }
                        cJob.BillingHours = Convert.ToDecimal(bHours.Trim());
                        // totalize hours
                        totalHours += cJob.BillingHours.Value;
                    }

                    // Misc
                    if (bMisc != string.Empty)
                    {
                        if (cJob.BillingMisc.HasValue)
                        {
                            totalExpense -= cJob.BillingMisc.Value;
                        }
                        cJob.BillingMisc = Convert.ToDecimal(bMisc.Trim());
                        totalExpense += cJob.BillingMisc.Value;
                    }
                    if (projectNo > 0)
                    {
                        cJob.ProjectId = projectNo;
                    }

                    if (remarks != string.Empty)
                    {
                        cJob.Remarks = remarks;
                    }
                    if (classification != "Select")
                    {
                        cJob.Classification = classification;
                    }
                    if (activity != "Select")
                    {
                        cJob.Activity = activity;
                    }
                    // Distance
                    if (bDist != string.Empty)
                    {
                        if (cJob.BillingTravelDistance.HasValue)
                        {
                            totalDist -= cJob.BillingTravelDistance.Value;
                        }
                        // assign inputted value
                        cJob.BillingTravelDistance = Convert.ToInt32(bDist.Trim());
                        // totalize distance
                        totalDist += cJob.BillingTravelDistance.Value;
                    }
                    // truck distance
                    if (truckDist != string.Empty)
                    {
                        // subtract the value if it already exists
                        if (cJob.TruckDistance.HasValue)
                        {
                            totalTruck -= cJob.TruckDistance.Value;
                        }
                        cJob.TruckDistance = Convert.ToInt32(truckDist);
                        totalTruck += cJob.TruckDistance.Value;
                    }
                    // Accom
                    if (bAccom != string.Empty)
                    {
                        if (cJob.BillingAccomodation.HasValue)
                        {
                            totalExpense -= cJob.BillingAccomodation.Value;
                        }
                        cJob.BillingAccomodation = Convert.ToDecimal(bAccom.Trim());
                        // totalize expense
                        totalExpense += cJob.BillingAccomodation.Value;
                    }
                    context.SaveChanges();

                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
    protected void chargeableBtn_Click(object sender, EventArgs e)
    {
        if (weekEndingTB.Text != string.Empty && timesheetID > 0)
        {
            bool valid = true;
            int cDist = Convert.ToInt32(totalDistanceLBL.Text), tDist = Convert.ToInt32(totalTruckLBL.Text);
            decimal cHours = Convert.ToDecimal(totalHoursLBL.Text), cExpense = Convert.ToDecimal(Convert.ToDecimal(totalExpensesLBL.Text));
            TimesheetManager tm = new TimesheetManager();

            // sunday
            if (sunCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(sunCHoursTB.Text, "Sunday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(sunCHoursTB.Text, sunAccomTB.Text, sunDistTB.Text, sunTruckDistTB.Text, sunMiscTB.Text, "Sunday", projectNumTB.Text, classificationDDL.SelectedValue,
                              activitiesDDL.SelectedValue, timesheetID, sunCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // monday

            if (monCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(monCHoursTB.Text, "Monday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(monCHoursTB.Text, monAccomTB.Text, monDistTB.Text, monTruckDistTB.Text, monMiscTB.Text, "Monday", projectNumTB.Text, classificationDDL.SelectedValue,
                         activitiesDDL.SelectedValue, timesheetID, monCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // tuesday
            if (tuesCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(tuesCHoursTB.Text, "Tuesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(tuesCHoursTB.Text, tuesAccomTB.Text, tuesDistTB.Text, tuesTruckDistTB.Text, tuesMiscTB.Text, "Tuesday", projectNumTB.Text, classificationDDL.SelectedValue,
               activitiesDDL.SelectedValue, timesheetID, tuesCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // wednesday
            if (wedsCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(wedsCHoursTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(wedsCHoursTB.Text, wedsAccomTB.Text, wedsDistTB.Text, wedsTruckDistTB.Text, wedsMiscTB.Text, "Wednesday", projectNumTB.Text, classificationDDL.SelectedValue,
                       activitiesDDL.SelectedValue, timesheetID, wedsCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // thursday

            if (thursCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(thursCHoursTB.Text, "Thursday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(thursCHoursTB.Text, thursAccomTB.Text, thursDistTB.Text, thursTruckDistTB.Text, thursMiscTB.Text, "Thursday", projectNumTB.Text, classificationDDL.SelectedValue,
                           activitiesDDL.SelectedValue, timesheetID, thursCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // friday
            if (friCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(friCHoursTB.Text, "Friday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(friCHoursTB.Text, friAccomTB.Text, friDistTB.Text, friTruckDistTB.Text, friMiscTB.Text, "Friday", projectNumTB.Text, classificationDDL.SelectedValue,
                     activitiesDDL.SelectedValue, timesheetID, friCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // saturday
            if (satCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(satCHoursTB.Text, "Saturday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(satCHoursTB.Text, satAccomTB.Text, satDistTB.Text, satTruckDistTB.Text, satMiscTB.Text, "Saturday", projectNumTB.Text, classificationDDL.SelectedValue,
                   activitiesDDL.SelectedValue, timesheetID, satCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // add to totalized value labels
            totalHoursLBL.Text = cHours.ToString("0.#");
            totalExpensesLBL.Text = cExpense.ToString("0.####");
            totalDistanceLBL.Text = cDist.ToString();
            totalTruckLBL.Text = tDist.ToString();

            // if TOTAL WEEKLY hours exceed 60 throw a dialog
            if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
            {
                // throw a dialog
                dialogTitle = "Regular Weekly Hours Exceeded";
                msg = "You Worked more than 60 hrs per Week. A separate Form must be filled out to accomodate overtime";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
            }

            // update timesheet
            tm.updateTimeSheet(timesheetID, cHours, cDist, tDist, cExpense, "Updated", " ", " ");

            projectNameTB.Enabled = false;
            clientNameTB.Enabled = false;

            // clear form fields
            clearChargeable();
            // update totals
            updateChargeableTotals();
            updateLabTotals();
            updateNonChargeableTotals();
            // chargeable fields
            clientNameTB.Text = string.Empty;
            projectNameTB.Text = string.Empty;
            projectNumTB.Text = string.Empty;
            classificationDDL.Items.Clear();
            activitiesDDL.Items.Clear();

            // update gridview
            summaryGV.DataBind();
        }
        else
        {
            dialogTitle = "Missing Weekending Date";
            msg = "The timesheet needs a verified Weekending Date in order to proceed";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
    protected void summaryGV_RowDeleted(object sender, System.Web.UI.WebControls.GridViewDeletedEventArgs e)
    {
        // update totals when a row is successfully deleted
        TimesheetManager tm = new TimesheetManager();

        TimeSheet t = tm.getTimesheetForID(timesheetID);
        if (t != null)
        {
            if (t.TotalHours >= 0)
            {
                totalHoursLBL.Text = t.TotalHours.Value.ToString("0.#");
            }
            if (t.TotalDistance >= 0)
            {
                totalDistanceLBL.Text = t.TotalDistance.ToString();
            }
            if (t.TotalTruck >= 0)
            {
                totalTruckLBL.Text = t.TotalTruck.ToString();
            }
            if (t.TotalExpenses >= 0)
            {
                totalExpensesLBL.Text = t.TotalExpenses.ToString();
            }
        }
    }
    protected void nonChargeBtn_Click(object sender, EventArgs e)
    {
        if (weekEndingTB.Text != string.Empty && timesheetID > 0)
        {
            bool valid = true;
            int nCDist = Convert.ToInt32(totalDistanceLBL.Text);
            decimal nCHours = Convert.ToDecimal(totalHoursLBL.Text), nCExpense = Convert.ToDecimal(totalExpensesLBL.Text);

            TimesheetManager tm = new TimesheetManager();

            // sunday
            if (sunNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(sunNCHoursTB.Text, "Sunday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(sunNCHoursTB.Text, sunNCAccomTB.Text, sunNCDistanceTB.Text, sunNCMiscTB.Text, "Sunday",
                         detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, sunNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }

            // monday

            if (monNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(monNCHoursTB.Text, "Monday", false))
                {
                    valid = false;
                }
            }
            if (valid)
                {
                    timesheetStatusLBL.Text = tm.createNonChargeable(monNCHoursTB.Text, monNCAccomTB.Text, monNCDistanceTB.Text, monNCMiscTB.Text, "Monday",
                       detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, monNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
                }

            // tuesday

            if (tuesNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(tuesNCHoursTB.Text, "Tuesday", false))
                {
                    valid = false;
                }
            }
                 if (valid)
                {
                    timesheetStatusLBL.Text = tm.createNonChargeable(tuesNCHoursTB.Text, tuesNCAccomTB.Text, tuesNCDistanceTB.Text, tuesNCMiscTB.Text, "Tuesday",
                    detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
                }

            // wednessday
            if (wedsNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(wedsNCHoursTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }

                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(wedsNCHoursTB.Text, wedsNCAccomTB.Text, wedsNCDistanceTB.Text, wedsNCMiscTB.Text, "Wednesday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // thursday
            if (thursNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(thursNCHoursTB.Text, "Thursday", false))
                {
                    valid = false;
                      }
            }
                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(thursNCHoursTB.Text, thursNCAccomTB.Text, thursNCDistanceTB.Text, thursNCMiscTB.Text, "Thursday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, thursNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // friday
            if (friNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(friNCHoursTB.Text, "Friday", false))
                {
                        }
            }
                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(friNCHoursTB.Text, friNCAccomTB.Text, friNCDistanceTB.Text, friNCMiscTB.Text, "Friday",
             detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, friNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // saturday
            if (satNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(satNCHoursTB.Text, "Saturday", false))
                {
                    valid = false;
                       }
            }
                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(satNCHoursTB.Text, satNCAccomTB.Text, satNCDistanceTB.Text, satNCMiscTB.Text, "Saturday",
               detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, satNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // add the totalized labels except truck which does not apply to non-chargeable
            totalHoursLBL.Text = nCHours.ToString("0.#");
            totalExpensesLBL.Text = nCExpense.ToString("0.####");
            totalDistanceLBL.Text = nCDist.ToString();
            // if hours exceed 60 throw a dialog
            if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
            {
                // throw a dialog
                dialogTitle = "Regular Hours Exceeded";
                msg = "A separate Form must be filled out to accomodate overtime";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
            }

            // update timesheet
            tm.updateTimeSheet(timesheetID, nCHours, nCDist, -1, nCExpense, "Updated", " ", " ");

            // update gridview
            summaryGV.DataBind();

            // populate generic non-chargeable drop down list elements
            specifyDDL.DataSource = tm.getWorkType();
            specifyDDL.DataBind();
            specifyDDL.Items.Insert(0, "Select");
            detailsDDL.DataSource = tm.getExpenses();
            detailsDDL.DataBind();
            detailsDDL.Items.Insert(0, "Select");

            // clear form fields
            clearNonChargeable();
            // update totals

            updateNonChargeableTotals();
            // reset drop down list to first index
            detailsDDL.SelectedIndex = 0;
            specifyDDL.SelectedIndex = 0;
            NonChargeHoursPanel.Visible = false;
            NonChargeExpensesPanel.Visible = false;
            updateNonChargeableBtn.Visible = false;
            nonChargeBtn.Visible = true;
        }
        else
        {
            dialogTitle = "Missing Weekending Date";
            msg = "The timesheet needs a verified Weekending Date in order to proceed";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        dbData = tm.getData();

        if (!IsPostBack)
        {
            statusDDL.DataSource = tm.getTimesheetStatus();
            statusDDL.DataBind();

            branchesDDL.DataSource = tm.getBranches();
            string username = Membership.GetUser().UserName;
            User user = tm.getEmployeeForId(username);
            //branchesDDL.SelectedValue = user.branch;
            branchesDDL.DataBind();
            datesDDL.DataSource = tm.getDates();
            datesDDL.DataBind();

            // check query strings for form data to be populated
            if (Request.QueryString.Count > 0)
            {
                if (Request.QueryString["reject"] == "reject")
                {
                    TimeSheet ts = tm.getTimesheetForID(Convert.ToInt32(Request.QueryString["time"]));
                    if (ts != null)
                    {
                        tm.updateTimeSheet(ts.TimeSheetId, ts.TotalHours.Value, ts.TotalDistance.Value, ts.TotalTruck.Value, ts.TotalExpenses.Value, "Rejected", ts.EmployeeComments, ts.ManagerComments);
                        statusDDL.SelectedValue = "Rejected";
                        statusDDL.DataBind();
                        GridView1.DataBind();
                    }
                }
                else if (Request.QueryString["sync"] == "sync")
                {
                    // create a connection to the database
                    SqlConnection conn = new SqlConnection("data source=USER;initial catalog=TIMESHEET_SYNC;user id=sa;password=PMLtest;multipleactiveresultsets=True");

                    int id = Convert.ToInt32(Request.QueryString["time"]);
                    petomaccallumModel.TimeSheet t = tm.getTimesheetForID(id);
                    if (t != null)
                    {
                        conn.Open();
                        SqlCommand tsStmt = conn.CreateCommand();
                        tsStmt.CommandText =
                        "INSERT INTO TimeSheet(TimeSheetId,TotalHours,TotalDistance, TotalExpenses, EmpNo, WeekEnding, ApprovedBy,EmployeeName, ManagerComments,EmployeeComments) VALUES(@TimeSheetId,@TotalHours, @TotalDistance, @TotalExpenses, @EmpNo, @WeekEnding, @ApprovedBy,@EmployeeName, @ManagerComments, @EmployeeComments)";

                        tsStmt.Parameters.AddWithValue("@TimeSheetId", t.TimeSheetId);
                        tsStmt.Parameters.AddWithValue("@TotalHours", t.TotalHours);
                        tsStmt.Parameters.AddWithValue("@TotalDistance", t.TotalDistance);
                        tsStmt.Parameters.AddWithValue("@TotalExpenses", t.TotalExpenses);
                        // get emp no
                        User emp = tm.getEmployeeForId(t.EmployeeId);

                        tsStmt.Parameters.AddWithValue("@EmpNo", emp.empNo);
                        tsStmt.Parameters.AddWithValue("@WeekEnding", t.WeekEnding);
                        tsStmt.Parameters.AddWithValue("@ApprovedBy", t.ApprovedBy);
                        tsStmt.Parameters.AddWithValue("@EmployeeName", t.EmployeeName);
                        tsStmt.Parameters.AddWithValue("@ManagerComments", t.ManagerComments);

                        tsStmt.Parameters.AddWithValue("@EmployeeComments", t.EmployeeComments);

                        tsStmt.ExecuteNonQuery();
                        tsStmt.Dispose();

                        // get manager chargeable data and map it
                        List<ManagerChargeable> mData = tm.getManagerChargeableForID(id);

                        if (mData != null)
                        {
                            // TODO: map the managerChargeable to the local db
                            try
                            {

                                // for each ManagerChargeable row for the timesheet, insert to temporary database
                                foreach (ManagerChargeable item in mData)
                                {
                                    SqlCommand stmt = conn.CreateCommand();
                                    //get projnum, name, client

                                    //get projnum, name, client
                                    stmt.CommandText =
                                    "INSERT INTO Chargeable(TimeSheetId,Day,PayRollHours,PayRollTravelDistance,PayRollAccomodation,PayRollMisc,BillingHours,BillingTravelDistance,BillingAccomodation,BillingMisc,ProjectNo,Classification,Activity,Remarks,BillingTruckDistance)" +
                                    "VALUES(@TimeSheetId,@Day,@PayRollHours,@PayRollTravelDistance, @PayRollAccomodation ,@PayRollMisc, @BillingHours, @BillingTravelDistance, @BillingAccomodation, @BillingMisc, @ProjectNo, @Classification, @Activity, @Remarks,@BillingTruckDistance)";
                                    stmt.Parameters.AddWithValue("@TimeSheetId", item.TimeSheetId);
                                    stmt.Parameters.AddWithValue("@Day", item.Day);
                                    // payroll
                                    if (item.PayRollHours.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollHours", item.PayRollHours.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollHours", 0);
                                    }
                                    if (item.PayRollTravelDistance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollTravelDistance", item.PayRollTravelDistance.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollTravelDistance", 0);
                                    }
                                    if (item.PayRollAccomodation.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollAccomodation", item.PayRollAccomodation.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollAccomodation", 0);
                                    }
                                    if (item.PayRollMisc.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollMisc", item.PayRollMisc.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollMisc", 0);
                                    }

                                    // billing
                                    if (item.BillingHours.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingHours", item.BillingHours.Value);
                                    }
                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTravelDistance", item.BillingTravelDistance.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTravelDistance", 0);
                                    }

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingAccomodation", item.BillingAccomodation.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingAccomodation", 0);
                                    }

                                    if (item.BillingMisc.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingMisc", item.BillingMisc.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingMisc", 0);
                                    }
                                    // get project number
                                    string no = tm.getProjectNoForID(item.ProjectId);
                                    stmt.Parameters.AddWithValue("@ProjectNo", no);
                                    stmt.Parameters.AddWithValue("@Classification", item.Classification);
                                    stmt.Parameters.AddWithValue("@Activity", item.Activity);
                                    if (item.Remarks != null)
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", item.Remarks);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", " ");
                                    }

                                    if (item.TruckDistance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTruckDistance", item.TruckDistance);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTruckDistance", 0);
                                    }

                                    stmt.ExecuteNonQuery();
                                    stmt.Dispose();
                                    stmt = null;
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        List<ManagerNonChargeable> nData = tm.getManagerNonChargeableForID(id);

                        if (nData != null)
                        {
                            try
                            {

                                // save each row of non chargeable data to the sync database
                                foreach (ManagerNonChargeable item in nData)
                                {

                                    SqlCommand stmt = conn.CreateCommand();

                                    stmt.CommandText =
                                   "INSERT INTO NonChargeable (TimeSheetId,Hours,Distance,Accomodations,Misc,TypeHours,TypeExpense,Day,Remarks)VALUES(@TimeSheetId,@Hours, @Distance, @Accomodations, @Misc, @TypeHours, @TypeExpense, @Day, @Remarks)";

                                    stmt.Parameters.AddWithValue("@TimeSheetId", t.TimeSheetId);

                                    if (item.Hours.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Hours", item.Hours.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Hours", 0);
                                    }

                                    if (item.Distance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Distance", item.Distance.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Distance", 0);
                                    }

                                    if (item.Accomodations.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Accomodations", item.Accomodations.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Accomodations", 0);
                                    }
                                    if (item.Misc.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Misc", item.Misc.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Misc", 0);
                                    }

                                    if (item.TypeHours != null)
                                    {
                                        stmt.Parameters.AddWithValue("@TypeHours", item.TypeHours);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@TypeHours", " ");
                                    }
                                    if (item.TypeExpense != null)
                                    {
                                        stmt.Parameters.AddWithValue("@TypeExpense", item.TypeExpense);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@TypeExpense", " ");

                                    }
                                    stmt.Parameters.AddWithValue("@Day", item.Day);

                                    if (item.Remarks != null)
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", item.Remarks);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", " ");
                                    }
                                    stmt.ExecuteNonQuery();
                                    stmt.Dispose();
                                    stmt = null;
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        // Synchronize the Lab and Density Tests
                        List<ManagerTest> tests = tm.getManagerTestsForTimeSheet(id);
                        if (tests != null)
                        {
                            try
                            {
                                foreach (ManagerTest item in tests)
                                {
                                    SqlCommand stmt = conn.CreateCommand();
                                    stmt.CommandText = "INSERT INTO ManagerTest(LabTest,DensityTest,TimeSheetId,Day) VALUES(@LabTest,@DensityTest,@TimeSheetId,@Day)";
                                    if (item.LabTest.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@LabTest", item.LabTest);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@LabTest", 0);
                                    }
                                    if (item.DensityTest.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@DensityTest", item.DensityTest);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@DensityTest", 0);
                                    }

                                    if (item.TimeSheetId > 0)
                                    {
                                        stmt.Parameters.AddWithValue("@TimeSheetId", item.TimeSheetId);
                                    }

                                    if (item.Day != string.Empty)
                                    {
                                        stmt.Parameters.AddWithValue("@Day", item.Day);
                                    }

                                    stmt.ExecuteNonQuery();
                                    stmt.Dispose();
                                    stmt = null;
                                }
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }

                        // update timesheet
                        tm.updateTimeSheet(t.TimeSheetId, t.TotalHours.Value, t.TotalDistance.Value, t.TotalTruck.Value, t.TotalExpenses.Value, "Synchronized", " ", " ");
                        conn.Close();
                    }
                }
            }
        }
    }