protected void gvProjects_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "btnView") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvProjects.Rows[row]; Session["projID"] = Convert.ToInt32(selectedRow.Cells[0].Text); Response.Redirect("~/PM/ManageProject.aspx"); } if (e.CommandName == "btnDeactivate") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvProjects.Rows[row]; Project proj = ff.Projects.Where(p => p.projId == Convert.ToInt32(selectedRow.Cells[0].Text)).First(); proj.isActive = 0; ff.SubmitChanges(); //Response.Redirect("~/PM/ProjectList.aspx"); populateProjectList(); } } catch (Exception exception) { //lblException.Text = exception.StackTrace; } }
protected void gvWorkPackages_RowCommand(object sender, GridViewCommandEventArgs e) { // try //{ string fullname2 = ""; string fullname3 = ""; try { string[] fullname = lblProjectManager2.Text.Split(' '); fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower(); fullname3 = fullname[0] + "_" + fullname[1]; } catch (Exception exception) { fullname2 = ""; fullname3 = ""; } if (e.CommandName == "btnView") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvWorkPackages.Rows[row]; Session["wpID"] = selectedRow.Cells[0].Text; Response.Redirect("~/RE/ManageWorkPackage.aspx"); } if (e.CommandName == "btnDeactivate") { FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext(); if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3) { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvWorkPackages.Rows[row]; WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First(); workpackage.isActive = 0; var wps = from wp in ff.WorkPackages where (wp.wpId.ToString().Contains(workpackage.wpId)) select wp; foreach (var wp in wps) { wp.isActive = 0; string s2 = wp.wpId; gg.SubmitChanges(); } gg.SubmitChanges(); populateManageProject(); } else { MessageBox.Show("You are not the project manager."); } } // } //catch (Exception exception) //{ //lblException.Text = exception.StackTrace; //} }
//Adds selected users to a project protected void buttonAssignUser_Click(object sender, EventArgs e) { AssignLabel.Text = ""; foreach (ListItem l in lbUnassignedUsers.Items) { if (l.Selected) { EmployeeProject ep = new EmployeeProject() { empId = Convert.ToInt32(l.Value), projId = Convert.ToInt32(ddlAllProjects.SelectedValue) }; try { ff.EmployeeProjects.InsertOnSubmit(ep); ff.SubmitChanges(); } catch (Exception ex) { AssignLabel.Text = "An error has occured: " + ex.Message; AssignLabel.ForeColor = System.Drawing.Color.Red; } } } populateListBoxes(); }
protected void btnSaveAlloc_Click(object sender, EventArgs e) { try { FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext(); if (tbUnalloc.Text == "") { tbUnalloc.Text = "0.0"; } Project proj = gg.Projects.Where(p => p.projId == Convert.ToInt32(Session["projID"].ToString())).First(); proj.unallocated_dollars = Convert.ToDecimal(tbUnalloc.Text); gg.SubmitChanges(); lblUnalloc2.Text = proj.unallocated_dollars.ToString(); //divOriginalAlloc.Visible = true; lblUnalloc2.Visible = true; btnSaveAlloc.Visible = false; btnCancelAlloc.Visible = false; btnChangeAlloc.Visible = true; tbUnalloc.Visible = false; } catch (Exception exception) { // lblException.Text = exception.StackTrace; } }
protected void btnCreateProject_Click(object sender, EventArgs e) { try { Project proj = new Project(); if (ff.Projects.Where(te => te.projId == Convert.ToInt32(tbProjectID.Text)).ToArray().Length > 0) { lblError.Text = "Project ID already exists."; } else { proj.projId = Convert.ToInt32(tbProjectID.Text); proj.projName = tbProjectName.Text; proj.manager = Convert.ToInt32(ddlProjectManager.SelectedValue); proj.allocated_dollars = 0; proj.unallocated_dollars = Convert.ToDecimal(tbUnalloc.Text); proj.isActive = 1; ff.Projects.InsertOnSubmit(proj); ff.SubmitChanges(); Session["projID"] = proj.projId; divCreateSuccess.Visible = true; divCreateProject.Visible = false; try { Roles.AddUserToRole( ff.Employees.Where(a => a.empId == Convert.ToInt32(ddlProjectManager.SelectedValue)) .Select(a => a.firstName).Single().ToString() + "_" + ff.Employees.Where(a => a.empId == Convert.ToInt32(ddlProjectManager.SelectedValue)) .Select(a => a.lastName).Single().ToString(), "ProjectManager"); } catch (Exception alreadyPM) { } } } catch (Exception exception) { //lblException.Text = exception.StackTrace; } }
protected void btnCreateWorkPackage_Click(object sender, EventArgs e) { try { WorkPackage wp = new WorkPackage(); if (ff.WorkPackages.Where(te => te.wpId == Convert.ToInt32(Session["projID"]) + "." + tbwpID.Text).ToArray().Length > 0 && Session["wpID"] == null) { lblError.Text = "Work Package already exists"; } else { if (Session["wpID"] == null) { wp.wpId = Convert.ToInt32(Session["projID"]) + "." + tbwpID.Text; } else { wp.wpId = Session["wpID"].ToString() + "." + tbwpID.Text; if (ff.WorkPackages.Where(te => te.wpId == Session["wpID"].ToString() + "." + tbwpID.Text).ToArray().Length > 0) { lblError.Text = "Work Package already exists"; return; } } wp.name = tbwpName.Text; wp.description = tbDescription.Text; wp.projId = Convert.ToInt32(Session["projID"]); wp.isActive = 1; Session["wpID"] = wp.wpId; ff.WorkPackages.InsertOnSubmit(wp); ff.SubmitChanges(); divCreateWorkPackage.Visible = false; divCreateSuccess.Visible = true; lblSuccessMsg.Text = "Work Package(" + wp.wpId + ") is created successfully."; } } catch (Exception exception) { //lblException.Text = exception.StackTrace; } }
protected void btnSaveAlloc_Click(object sender, EventArgs e) { try { FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext(); if (tbUnalloc.Text == "") tbUnalloc.Text = "0.0"; Project proj = gg.Projects.Where(p => p.projId == Convert.ToInt32(Session["projID"].ToString())).First(); proj.unallocated_dollars = Convert.ToDecimal(tbUnalloc.Text); gg.SubmitChanges(); lblUnalloc2.Text = proj.unallocated_dollars.ToString(); //divOriginalAlloc.Visible = true; lblUnalloc2.Visible = true; btnSaveAlloc.Visible = false; btnCancelAlloc.Visible = false; btnChangeAlloc.Visible = true; tbUnalloc.Visible = false; } catch (Exception exception) { // lblException.Text = exception.StackTrace; } }
//Saves new P-Level to the Database protected void buttonPlevel_Click(object sender, EventArgs e) { using (FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext()) { PersonLevel pl = new PersonLevel() { rate = Convert.ToDecimal(tbRate.Text), pLevel = tbPLevelID.Text, fiscalYear = Convert.ToInt32(lblFiscalYear.Text) }; ff.PersonLevels.InsertOnSubmit(pl); try { ff.SubmitChanges(); } catch (Exception ex) { ex.ToString(); lblError.Text = "PLevel ID already exists."; lblError.ForeColor = System.Drawing.Color.Red; return; } lblError.Text = "P-Level added. Refresh page to see changes."; lblError.ForeColor = System.Drawing.Color.Green; } }
protected void btnSubmit_Click(object sender, EventArgs e) { ViewState["empId"] = GridView1.SelectedRow.Cells[1].Text; ViewState["date"] = GridView1.SelectedRow.Cells[2].Text; ViewState["proj"] = GridView1.SelectedRow.Cells[3].Text; ViewState["wp"] = GridView1.SelectedRow.Cells[4].Text; var selectedStatus = (from th in ff.TimesheetHeaders join tse in ff.TimesheetEntries on new { th.tsDate, th.empId } equals new { tse.tsDate, tse.empId } where th.empId == Convert.ToInt32(ViewState["empId"]) && th.tsDate == Convert.ToDateTime(ViewState["date"]) && tse.wpId == Convert.ToString(ViewState["wp"]) && tse.projId == Convert.ToInt32(ViewState["proj"]) select th).Single(); if (DropDownList1.SelectedValue == "Approve") { selectedStatus.status = "APPROVED"; } else { selectedStatus.status = "REJECTED"; selectedStatus.comments = tbComments.Text; } ff.SubmitChanges(); field.Visible = false; DropDownList1.Visible = false; btnSubmit.Visible = false; GridView2.Visible = false; GridView1.Visible = true; populateGridView(); }
protected void gvWorkPackages_RowCommand(object sender, GridViewCommandEventArgs e) { // try //{ string fullname2 = ""; string fullname3 = ""; try { string[] fullname = lblProjectManager2.Text.Split(' '); fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower(); fullname3 = fullname[0] + "_" + fullname[1]; } catch (Exception exception) { fullname2 = ""; fullname3 = ""; } if (e.CommandName == "btnView") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvWorkPackages.Rows[row]; Session["wpID"] = selectedRow.Cells[0].Text; Response.Redirect("~/RE/ManageWorkPackage.aspx"); } if (e.CommandName == "btnDeactivate") { FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext(); if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3) { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvWorkPackages.Rows[row]; WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First(); workpackage.isActive = 0; var wps = from wp in ff.WorkPackages where (wp.wpId.ToString().Contains(workpackage.wpId)) select wp; foreach (var wp in wps) { wp.isActive = 0; string s2 = wp.wpId; gg.SubmitChanges(); } gg.SubmitChanges(); populateManageProject(); } else MessageBox.Show("You are not the project manager."); } // } //catch (Exception exception) //{ //lblException.Text = exception.StackTrace; //} }
protected void gvUnactiveWP_RowCommand(object sender, GridViewCommandEventArgs e) { //try //{ string fullname2 = ""; string fullname3 = ""; try { string[] fullname = lblProjectManager2.Text.Split(' '); fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower(); fullname3 = fullname[0] + "_" + fullname[1]; } catch (Exception exception) { fullname2 = ""; fullname3 = ""; } if (e.CommandName == "btnView") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnactiveWP.Rows[row]; Session["wpID"] = selectedRow.Cells[0].Text; Response.Redirect("~/RE/ManageWorkPackage.aspx"); } if (e.CommandName == "btnActivate") { if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3) { FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext(); int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnactiveWP.Rows[row]; WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First(); workpackage.isActive = 1; string[] wpArray = workpackage.wpId.Split('.'); string s = ""; for (int j = wpArray.Length - 1; j > 1; j--) { for (int i = 0; i < j; i++) { if (i == j - 1) s += wpArray[i]; else s += wpArray[i] + "."; } var subwp = (from wp in gg.WorkPackages where (wp.wpId == s) select wp); string s2 = subwp.First().wpId; subwp.First().isActive = 1; gg.SubmitChanges(); s = ""; } gg.SubmitChanges(); populateManageProject(); } else MessageBox.Show("You are not the project manager."); } //} //catch (Exception exception) // { //lblException.Text = exception.StackTrace; //} }
//Adds the newly created user to the Employee table and links them together in EmployeeMembership protected void cuwCreateUser_CreatedUser(object sender, EventArgs e) { string tmpFirstName = ((TextBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("FirstName")).Text; string tmpLastName = ((TextBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("LastName")).Text; string tmpSupervisor = ((ListBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("SupervisorList")).SelectedValue; string tmpApprover = ((ListBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("ApproverList")).SelectedValue; string tmpEmpID = ((TextBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("EmployeeID")).Text; CheckBoxList tempCheck = (CheckBoxList)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("RoleList"); for (int i = 0; i < tempCheck.Items.Count; i++) { if (tempCheck.Items[i].Selected) { Roles.AddUserToRole(((TextBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("UserName")).Text , tempCheck.Items[i].Text); } } Employee emp = new Employee() { firstName = tmpFirstName, lastName = tmpLastName, empId = Convert.ToInt32(tmpEmpID), supervisor = Convert.ToInt32(tmpSupervisor), approver = Convert.ToInt32(tmpApprover), minHoursPerWeek = 0, vacationLeave = 0, sickDays = 0, flexHours = 0, isActive = 1 }; //Employee table updated ff.Employees.InsertOnSubmit(emp); //EmployeeMembership updated (link created here) ff.EmployeeMemberships.InsertOnSubmit(new EmployeeMembership { empId = Convert.ToInt32(tmpEmpID), userId = ff.aspnet_Users .Where(u => u.UserName == ((TextBox)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("UserName")).Text) .ToArray()[0].UserId }); //PLevel Entry Created and submitted EmployeePersonLevel epl = new EmployeePersonLevel() { dateUpdated = DateTime.Now.Date, empId = Convert.ToInt32(tmpEmpID), //Fiscal Year is not DateTime.Now.Year but for lack of time it will be fiscalYear = DateTime.Now.Year, pLevel = ((DropDownList)wsEmployeeAccountInfo.ContentTemplateContainer.FindControl("ddlPLevel")).SelectedValue, }; ff.EmployeePersonLevels.InsertOnSubmit(epl); ff.SubmitChanges(); //Adds selected Approver to the TSApprover Role if they are not in it already string approverUsername = ff.vw_EmployeeInRolewFirstLastNameEmpIDUserIDs.Where(em => em.empId == Convert.ToInt32(tmpApprover)).Select(u => u.UserName).First(); if (!Roles.IsUserInRole(approverUsername, "TimesheetApprover")) { Roles.AddUserToRole(approverUsername, "TimesheetApprover"); } }
//Fills changed information into object and submits changes to DB protected void buttonDetailsSubmit_Click(object sender, EventArgs e) { Employee ManagedEmployee = ff.Employees.Where(em => em.empId == Convert.ToInt32(lblEmpId.Text)).First(); ManagedEmployee.firstName = tbFirstName.Text; ManagedEmployee.lastName = tbLastName.Text; ManagedEmployee.supervisor = Convert.ToInt32(lbSupervisors.SelectedValue); ManagedEmployee.approver = Convert.ToInt32(lbApprovers.SelectedValue); ManagedEmployee.minHoursPerWeek = Convert.ToDecimal(tbMinHours.Text); ManagedEmployee.vacationLeave = Convert.ToInt32(tbVacation.Text); ManagedEmployee.sickDays = Convert.ToInt32(tbSickDays.Text); ManagedEmployee.flexHours = Convert.ToDecimal(tbFlexHours.Text); if (cbActiveUser.Checked) { ManagedEmployee.isActive = 1; } else { ManagedEmployee.isActive = 0; } #region Add/Remove Roles List <string> rolesToAdd = new List <string>(); List <string> rolesToRemove = new List <string>(); foreach (ListItem r in cblUserRoles.Items) { if (r.Selected) { rolesToAdd.Add(r.Text); } else { rolesToRemove.Add(r.Text); } } foreach (string r in rolesToAdd) { try { Roles.AddUserToRole(lblUsername.Text, r); } catch (Exception ex) { Trace.Write(ex.Message); } } foreach (string r in rolesToRemove) { try { Roles.RemoveUserFromRole(lblUsername.Text, r); } catch (Exception ex) { Trace.Write(ex.Message); } } #endregion string approverUsername = ff.vw_EmployeeInRolewFirstLastNameEmpIDUserIDs .Where(em => em.empId == Convert.ToInt32(lbApprovers.SelectedValue)) .Select(u => u.UserName).First(); if (!Roles.IsUserInRole(approverUsername, "TimesheetApprover")) { Roles.AddUserToRole(approverUsername, "TimesheetApprover"); } //P-Level update //if exists on dateupdated, update if (ff.EmployeePersonLevels .Where(ep => (ep.empId == Convert.ToInt32(lblEmpId.Text)) && ep.dateUpdated == DateTime.Now.Date) .Count() > 0) { EmployeePersonLevel epl = ff.EmployeePersonLevels .Where(ep => (ep.empId == Convert.ToInt32(lblEmpId.Text)) && ep.fiscalYear == DateTime.Now.Year) .OrderByDescending(ep => ep.dateUpdated) .First(); epl.pLevel = ddlPLevel.SelectedValue; epl.dateUpdated = DateTime.Now.Date; } //if does not exist on dateupdated, create new else { EmployeePersonLevel epl = new EmployeePersonLevel() { empId = Convert.ToInt32(lblEmpId.Text), fiscalYear = DateTime.Now.Year, pLevel = ddlPLevel.SelectedValue, dateUpdated = DateTime.Now.Date }; ff.EmployeePersonLevels.InsertOnSubmit(epl); } //DB SubmitChanges try { ff.SubmitChanges(); } catch (Exception ex) { lblUserEditError.Text = ex.Message; lblUserEditError.ForeColor = System.Drawing.Color.Red; return; } lblUserEditError.Text = "User Has been updated. Show all users to see changes."; lblUserEditError.ForeColor = System.Drawing.Color.ForestGreen; }
protected void gvEmployees_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "btnDelete") { ff.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEmployees.Rows[row]; EmployeeWorkPackage empwp = ff.EmployeeWorkPackages.Where(emp => emp.empId == (Convert.ToInt32(selectedRow.Cells[0].Text)) && emp.wpId == lblWPID2.Text).First(); ff.EmployeeWorkPackages.DeleteOnSubmit(empwp); ff.SubmitChanges(); populateManageWorkPackage(); } }
protected void populateManageProject() { try { ff.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); if (Session["projID"] == null) { Response.Redirect("~/PM/ProjectList.aspx"); } if (Session["wpID"] != null) { Session["wpID"] = null; } if (divChangeAlloc.Visible == false) { divOriginalAlloc.Visible = true; } divChangeAlloc.Visible = false; lblProjID2.Text = Session["projID"].ToString(); //Get project name var proj = from p in ff.Projects where p.projId == Convert.ToInt32(Session["projID"]) select p; lblProjName2.Text = proj.First().projName; try { lblProjectManager2.Text = ff.Employees .Where(a => a.empId == proj.First().manager).First().firstName + " " + ff.Employees .Where(a => a.empId == proj.First().manager).First().lastName; } catch (Exception e) { lblProjectManager2.Text = ""; } if (proj.First().allocated_dollars == null) { lblAlloc2.Text = "UNDEFINED"; } else { lblAlloc2.Text = proj.First().allocated_dollars.ToString(); } if (proj.First().unallocated_dollars == null) { lblUnalloc2.Text = "UNDEFINED"; } else { lblUnalloc2.Text = proj.First().unallocated_dollars.ToString(); } getAllActiveWP(); getAllUnactiveWP(); identifyRole(); string[] name = lblProjectManager2.Text.Split(' '); var query = (from emp in ff.Employees where emp.firstName == name[0] && emp.lastName == name[1] select new { emp.empId }).First(); try { Roles.AddUserToRole(name[0].ToLower() + "_" + name[1].ToLower(), "ProjectManager"); } catch (Exception exception) { } try { EmployeeProject ep = new EmployeeProject(); ep.projId = Convert.ToInt32(lblProjID2.Text); ep.empId = query.empId; ff.EmployeeProjects.InsertOnSubmit(ep); ff.SubmitChanges(); } catch (Exception exception) { } } catch (Exception exception) { //lblException.Text = exception.StackTrace; } }
protected void gvUnactiveWP_RowCommand(object sender, GridViewCommandEventArgs e) { //try //{ string fullname2 = ""; string fullname3 = ""; try { string[] fullname = lblProjectManager2.Text.Split(' '); fullname2 = fullname[0].ToLower() + "_" + fullname[1].ToLower(); fullname3 = fullname[0] + "_" + fullname[1]; } catch (Exception exception) { fullname2 = ""; fullname3 = ""; } if (e.CommandName == "btnView") { int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnactiveWP.Rows[row]; Session["wpID"] = selectedRow.Cells[0].Text; Response.Redirect("~/RE/ManageWorkPackage.aspx"); } if (e.CommandName == "btnActivate") { if (User.Identity.Name == fullname2 || User.Identity.Name == fullname3) { FlyingFishClassesDataContext gg = new FlyingFishClassesDataContext(); int row = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvUnactiveWP.Rows[row]; WorkPackage workpackage = gg.WorkPackages.Where(wp => wp.wpId == selectedRow.Cells[0].Text).First(); workpackage.isActive = 1; string[] wpArray = workpackage.wpId.Split('.'); string s = ""; for (int j = wpArray.Length - 1; j > 1; j--) { for (int i = 0; i < j; i++) { if (i == j - 1) { s += wpArray[i]; } else { s += wpArray[i] + "."; } } var subwp = (from wp in gg.WorkPackages where (wp.wpId == s) select wp); string s2 = subwp.First().wpId; subwp.First().isActive = 1; gg.SubmitChanges(); s = ""; } gg.SubmitChanges(); populateManageProject(); } else { MessageBox.Show("You are not the project manager."); } } //} //catch (Exception exception) // { //lblException.Text = exception.StackTrace; //} }
//------------------------------------------------------------------------- protected void btnCreateNewRecord_Click(object sender, EventArgs e) { FlyingFishClassesDataContext ff = new FlyingFishClassesDataContext(); try { var qry = (from emp in ff.Employees where emp.empId == Convert.ToInt32(Session["CurEmpId"]) select emp.approver).FirstOrDefault(); TimesheetHeader tmp = new TimesheetHeader() { tsDate = Convert.ToDateTime(Session["CurrentDate"]), empId = Convert.ToInt32(Session["CurEmpId"]), status = "SAVED", approvedBy = qry, comments = "Comments" }; var qry2 = (from th in ff.TimesheetHeaders where th.empId == tmp.empId && th.tsDate == tmp.tsDate select th).ToList(); if (qry2.Count == 0) { ff.TimesheetHeaders.InsertOnSubmit(tmp); ff.SubmitChanges(); } TimesheetEntry tmp2 = new TimesheetEntry() { tsDate = Convert.ToDateTime(Session["CurrentDate"]), empId = Convert.ToInt32(Session["CurEmpId"]), projId = Convert.ToInt32(ddlProjectId.SelectedValue), wpId = (ddlWpId.SelectedValue).ToString(), sun = Convert.ToInt32(tbSun.Text), sat = Convert.ToInt32(tbSat.Text), fri = Convert.ToInt32(tbFri.Text), thu = Convert.ToInt32(tbThu.Text), wed = Convert.ToInt32(tbWed.Text), tue = Convert.ToInt32(tbTue.Text), mon = Convert.ToInt32(tbMon.Text), notes = tbNote.Text }; ff.TimesheetEntries.InsertOnSubmit(tmp2); ff.SubmitChanges(); lblteSubmitSuccess.Text = "Submit has been saved."; divNewRecord.Visible = false; btnNewRecord.Visible = true; divtotal.Visible = true; tbFri.Text = String.Empty; tbMon.Text = String.Empty; tbNote.Text = String.Empty; //tbProjectID.Text = String.Empty; tbSat.Text = String.Empty; tbSun.Text = String.Empty; tbThu.Text = String.Empty; tbTue.Text = String.Empty; tbWed.Text = String.Empty; //tbWpID.Text = String.Empty; } catch (Exception myException) { lblteSubmitSuccess.Text = "ENTRY ALREADY EXISTS"; // Label1.Text = "You have sumbitted the record before, Cannot insert duplicate record into the database!!!"; } }
protected void gvStatus_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Get the row that's changing. GridViewRow row = gvStatus.Rows[e.RowIndex]; GridViewRow empRow = gvStatus.Rows[e.RowIndex - 1]; int empId = extractEmpId(((Label)empRow.Cells[0].Controls[1]).Text); String strEtc = UnknownValue; String strEac = UnknownValue; String strAcwp = ((Label)row.Cells[1].Controls[1]).Text; decimal acwp = 0; decimal etc = 0; decimal eac = 0; String format = "{0:0.0}"; String result = ""; // Get the new values. if (e.NewValues["ETC"] != null) { if (!(e.NewValues["ETC"].Equals(String.Empty))) { strEtc = e.NewValues["ETC"].ToString(); } } if (e.NewValues["EAC"] != null) { if (!(e.NewValues["EAC"].Equals(String.Empty))) { strEac = e.NewValues["EAC"].ToString(); } } if (!Regex.IsMatch(strEac, "^(^[U]{1}[n]{1}[k]{1}[n]{1}[o]{1}[w]{1}[n]{1}$)|(^[0-9]*([.]+[0-9]*)*)$")) { SetResults("* EAC can only contain a dollar sign, comma, period, positive numbers, or 'Unknown'.", false, FailColour); return; } if (!Regex.IsMatch(strEtc, "^(^[U]{1}[n]{1}[k]{1}[n]{1}[o]{1}[w]{1}[n]{1}$)|(^[0-9]*([.]+[0-9]*)*)$")) { SetResults("* ETC can only contain a dollar sign, comma, period, positive numbers, or 'Unknown'.", false, FailColour); return; } if (!(strEac.Equals(UnknownValue) && strEtc.Equals(UnknownValue))) { SetResults("* At least one value must be 'Unknown' or blank. Please change one value to 'Unknown' or blank.", false, FailColour); return; } // Check for existing empWPEtc for the cut off date. EmployeeWorkPackageETC empWpEtc = (from ewetc in ffdb.EmployeeWorkPackageETCs where ewetc.empId == empId && ewetc.dateUpdated.Equals(Convert.ToDateTime(ViewState["cutOffDate"])) select ewetc).FirstOrDefault(); if (!((result = calculateEac(strAcwp, strEtc, format)).Equals(UnknownValue))) { eac = Convert.ToDecimal(result); strAcwp = this.stripFormatting(strAcwp); acwp = Convert.ToDecimal(strAcwp); etc = eac - acwp; } else if (!((result = calculateEtc(strAcwp, strEac, format)).Equals(UnknownValue))) { etc = Convert.ToDecimal(result); strAcwp = this.stripFormatting(strAcwp); acwp = Convert.ToDecimal(strAcwp); eac = etc + acwp; if (eac < acwp) { SetResults("* The EAC '" + strEac + "' is less than the ACWP. Please use a higher EAC or click cancel.", false, FailColour); return; } if (eac == 0) { SetResults("* The EAC must be greater than 0. Please use a different EAC or click cancel.", false, FailColour); return; } } else { if (empWpEtc != null) { SetResults("* Cannot set both existing estimates to 'Unknown' or blank values. Please give at least 1 value.", false, FailColour); return; } // Error, exit method and redraw grid view normally gvStatus.EditIndex = -1; e.Cancel = true; GetWorkPackageStatusReport(); SetResults("* An error has occured, we've exited edit mode.", false, FailColour); return; } // If ETC exists, update it if (empWpEtc != null) { empWpEtc.ETC_days = etc; } else { // If ETC doesn't exist, create one empWpEtc = new EmployeeWorkPackageETC(); empWpEtc.ETC_days = etc; empWpEtc.empId = empId; empWpEtc.projId = Convert.ToInt32(ViewState["projId"]); empWpEtc.wpId = (String)ViewState["wpId"]; // If the current date is earlier than the cut off date, use the current date // Otherwise, use the cut-off date if (DateTime.Now <= Convert.ToDateTime(ViewState["cutOffDate"])) { empWpEtc.dateUpdated = DateTime.Now; } else { empWpEtc.dateUpdated = Convert.ToDateTime(ViewState["cutOffDate"]); } ffdb.EmployeeWorkPackageETCs.InsertOnSubmit(empWpEtc); } // Persist the changes, exit edit mode, redraw the grid ffdb.SubmitChanges(); gvStatus.EditIndex = -1; e.Cancel = true; GetWorkPackageStatusReport(); SetResults("The report updated successfully.", false, SuccessColour); }