/// <summary> /// Handles the Click event of the btnUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnUpdate_Click(object sender, EventArgs e) { Rave.HR.BusinessLayer.Employee.ProfessionalDetails objProfessionalDetailsBAL; if (ValidateControls()) { int rowIndex = 0; int deleteRowIndex = -1; objProfessionalDetailsBAL = new Rave.HR.BusinessLayer.Employee.ProfessionalDetails(); BusinessEntities.ProfessionalDetails objProfessionalDetails = new BusinessEntities.ProfessionalDetails(); // 26864-Ambar-Start // Code to accept only one decimal point bool is_decimal_point = false; string str_current_char = null, strScore = txtScore.Text; if ((strScore != string.Empty) || (strScore != null) || (strScore != "")) { for (int i = 0; i < txtScore.Text.Length; i++) { str_current_char = strScore.Substring(i, 1); if ((str_current_char == ".")) { if (is_decimal_point) { lblMessage.Text = "<font color=RED>" + "Percentage can contain only one decimal point." + "</font>"; return; } else { is_decimal_point = true; } } } } // 26864-Ambar-End if (ViewState[DELETEROWINDEX] != null) { deleteRowIndex = Convert.ToInt32(ViewState[DELETEROWINDEX].ToString()); } //Update the grid view according the row, which is selected for editing. if (ViewState[ROWINDEX] != null) { rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString()); if (deleteRowIndex != -1 && deleteRowIndex < rowIndex) { rowIndex--; } Label ProfessionalId = (Label)gvProfessionalCourses.Rows[rowIndex].FindControl(PROFESSIONALID); Label Mode = (Label)gvProfessionalCourses.Rows[rowIndex].FindControl(MODE); gvProfessionalCourses.Rows[rowIndex].Cells[0].Text = txtCourseName.Text; gvProfessionalCourses.Rows[rowIndex].Cells[1].Text = txtInstituteName.Text; gvProfessionalCourses.Rows[rowIndex].Cells[2].Text = txtYearofPassing.Text; gvProfessionalCourses.Rows[rowIndex].Cells[3].Text = txtScore.Text; if (int.Parse(ProfessionalId.Text) == 0) { Mode.Text = "1"; } else { Mode.Text = "2"; } ImageButton btnImg = (ImageButton)gvProfessionalCourses.Rows[rowIndex].FindControl(IMGBTNDELETE); btnImg.Enabled = true; ViewState[ROWINDEX] = null; ViewState[DELETEROWINDEX] = null; } for (int i = 0; i < ProfessionalDetailsCollection.Count; i++) { objProfessionalDetails = (BusinessEntities.ProfessionalDetails)ProfessionalDetailsCollection.Item(i); Label ProfessionalId = (Label)gvProfessionalCourses.Rows[i].FindControl(PROFESSIONALID); Label Mode = (Label)gvProfessionalCourses.Rows[i].FindControl(MODE); objProfessionalDetails.ProfessionalId = int.Parse(ProfessionalId.Text); objProfessionalDetails.EMPId = int.Parse(EMPId.Value); objProfessionalDetails.CourseName = gvProfessionalCourses.Rows[i].Cells[0].Text; objProfessionalDetails.InstitutionName = gvProfessionalCourses.Rows[i].Cells[1].Text; objProfessionalDetails.PassingYear = gvProfessionalCourses.Rows[i].Cells[2].Text; objProfessionalDetails.Score = gvProfessionalCourses.Rows[i].Cells[3].Text; objProfessionalDetails.Mode = int.Parse(Mode.Text); } this.DoDataBind(); objProfessionalDetailsBAL.UpdateProfessionalDetails(objProfessionalDetails); //Clear all the fields after inserting row into gridview this.ClearControls(); btnAddRow.Visible = true; btnCancel.Visible = true; btnUpdateRow.Visible = false; btnCancelRow.Visible = false; //Enabling all the edit buttons. for (int i = 0; i < gvProfessionalCourses.Rows.Count; i++) { ImageButton btnImgEdit = (ImageButton)gvProfessionalCourses.Rows[i].FindControl(IMGBTNEDIT); btnImgEdit.Enabled = true; } lblMessage.Text = "Professional Courses updated successfully."; } }
/// <summary> /// Handles the Click event of the btnUpdate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnUpdate_Click(object sender, EventArgs e) { if (ValidateControls()) { int rowIndex = 0; int deleteRowIndex = -1; if (ViewState[DELETEROWINDEX] != null) { deleteRowIndex = Convert.ToInt32(ViewState[DELETEROWINDEX].ToString()); } //Update the grid view according the row, which is selected for editing. if (ViewState[ROWINDEX] != null) { rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString()); if (deleteRowIndex != -1 && deleteRowIndex < rowIndex) { rowIndex--; } Label ProfessionalId = (Label)gvProfessionalCourses.Rows[rowIndex].FindControl(PROFESSIONALID); Label Mode = (Label)gvProfessionalCourses.Rows[rowIndex].FindControl(MODE); gvProfessionalCourses.Rows[rowIndex].Cells[0].Text = txtCourseName.Text; gvProfessionalCourses.Rows[rowIndex].Cells[1].Text = txtInstituteName.Text; gvProfessionalCourses.Rows[rowIndex].Cells[2].Text = txtYearofPassing.Text; gvProfessionalCourses.Rows[rowIndex].Cells[3].Text = txtScore.Text; gvProfessionalCourses.Rows[rowIndex].Cells[4].Text = txtOutOf.Text; if (int.Parse(ProfessionalId.Text) == 0) { Mode.Text = "1"; } else { Mode.Text = "2"; } ImageButton btnImg = (ImageButton)gvProfessionalCourses.Rows[rowIndex].FindControl(IMGBTNDELETE); btnImg.Enabled = true; ViewState[ROWINDEX] = null; ViewState[DELETEROWINDEX] = null; } for (int i = 0; i < ProfessionalDetailsCollection.Count; i++) { BusinessEntities.ProfessionalDetails objProfessionalDetails = new BusinessEntities.ProfessionalDetails(); objProfessionalDetails = (BusinessEntities.ProfessionalDetails)ProfessionalDetailsCollection.Item(i); Label ProfessionalId = (Label)gvProfessionalCourses.Rows[i].FindControl(PROFESSIONALID); Label Mode = (Label)gvProfessionalCourses.Rows[rowIndex].FindControl(MODE); objProfessionalDetails.ProfessionalId = int.Parse(ProfessionalId.Text); objProfessionalDetails.EMPId = int.Parse(EMPId.Value); objProfessionalDetails.CourseName = gvProfessionalCourses.Rows[i].Cells[0].Text; objProfessionalDetails.InstitutionName = gvProfessionalCourses.Rows[i].Cells[1].Text; objProfessionalDetails.PassingYear = gvProfessionalCourses.Rows[i].Cells[2].Text; objProfessionalDetails.Score = gvProfessionalCourses.Rows[i].Cells[3].Text; objProfessionalDetails.Outof = gvProfessionalCourses.Rows[i].Cells[4].Text; objProfessionalDetails.Mode = int.Parse(Mode.Text); } //Clear all the fields after inserting row into gridview this.ClearControls(); btnAddRow.Visible = true; btnUpdateRow.Visible = false; btnCancelRow.Visible = false; //Enabling all the edit buttons. for (int i = 0; i < gvProfessionalCourses.Rows.Count; i++) { ImageButton btnImgEdit = (ImageButton)gvProfessionalCourses.Rows[i].FindControl(IMGBTNEDIT); btnImgEdit.Enabled = true; } } }
/// <summary> /// Handles the RowDeleting event of the gvProfessionalCourses control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param> protected void gvProfessionalCourses_RowDeleting(object sender, GridViewDeleteEventArgs e) { int deleteRowIndex = 0; int rowIndex = -1; Boolean Flag = false; Rave.HR.BusinessLayer.Employee.ProfessionalDetails objProfessionalDetailsBAL; BusinessEntities.ProfessionalDetails objProfessionalDetails = new BusinessEntities.ProfessionalDetails(); objProfessionalDetailsBAL = new Rave.HR.BusinessLayer.Employee.ProfessionalDetails(); deleteRowIndex = e.RowIndex; objProfessionalDetails = (BusinessEntities.ProfessionalDetails)ProfessionalDetailsCollection.Item(deleteRowIndex); if (objProfessionalDetails.Mode == 1) { Flag = true; } objProfessionalDetails.Mode = 3; if (ViewState[PROFESSIONALDETAILSDELETE] != null) { BusinessEntities.RaveHRCollection objDeleteProfessionalDetailsCollection = (BusinessEntities.RaveHRCollection)ViewState[PROFESSIONALDETAILSDELETE]; objDeleteProfessionalDetailsCollection.Add(objProfessionalDetails); ViewState[PROFESSIONALDETAILSDELETE] = objDeleteProfessionalDetailsCollection; } else { BusinessEntities.RaveHRCollection objDeleteProfessionalDetailsCollection1 = new BusinessEntities.RaveHRCollection(); objDeleteProfessionalDetailsCollection1.Add(objProfessionalDetails); ViewState[PROFESSIONALDETAILSDELETE] = objDeleteProfessionalDetailsCollection1; } ProfessionalDetailsCollection.RemoveAt(deleteRowIndex); ViewState[DELETEROWINDEX] = deleteRowIndex; DoDataBind(); objProfessionalDetailsBAL.DeleteProfessionalDetails(objProfessionalDetails); if (ViewState[ROWINDEX] != null) { rowIndex = Convert.ToInt32(ViewState[ROWINDEX].ToString()); //check edit index with deleted index if edit index is greater than or equal to delete index then rowindex decremented. if (rowIndex != -1 && deleteRowIndex <= rowIndex) { rowIndex--; //store the rowindex in viewstate. ViewState[ROWINDEX] = rowIndex; } ImageButton btnImg = (ImageButton)gvProfessionalCourses.Rows[rowIndex].FindControl(IMGBTNDELETE); btnImg.Enabled = false; //Disabling all the edit buttons. for (int i = 0; i < gvProfessionalCourses.Rows.Count; i++) { if (rowIndex != i) { ImageButton btnImgEdit = (ImageButton)gvProfessionalCourses.Rows[i].FindControl(IMGBTNEDIT); btnImgEdit.Enabled = false; } } } lblMessage.Text = "Professional Courses deleted successfully."; HfIsDataModified.Value = string.Empty; }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { Rave.HR.BusinessLayer.Employee.ProfessionalDetails objProfessionalDetailsBAL; BusinessEntities.ProfessionalDetails objProfessionalDetails; BusinessEntities.RaveHRCollection objSaveProfessionalDetailsCollection = new BusinessEntities.RaveHRCollection(); try { objProfessionalDetailsBAL = new Rave.HR.BusinessLayer.Employee.ProfessionalDetails(); if (gvProfessionalCourses.Rows[0].Cells[0].Text != NO_RECORDS_FOUND_MESSAGE) { for (int i = 0; i < gvProfessionalCourses.Rows.Count; i++) { objProfessionalDetails = new BusinessEntities.ProfessionalDetails(); Label ProfessionalId = (Label)gvProfessionalCourses.Rows[i].FindControl(PROFESSIONALID); Label Mode = (Label)gvProfessionalCourses.Rows[i].FindControl(MODE); objProfessionalDetails.ProfessionalId = int.Parse(ProfessionalId.Text); objProfessionalDetails.EMPId = int.Parse(EMPId.Value); objProfessionalDetails.CourseName = gvProfessionalCourses.Rows[i].Cells[0].Text; objProfessionalDetails.InstitutionName = gvProfessionalCourses.Rows[i].Cells[1].Text; objProfessionalDetails.PassingYear = gvProfessionalCourses.Rows[i].Cells[2].Text; objProfessionalDetails.Score = gvProfessionalCourses.Rows[i].Cells[3].Text; objProfessionalDetails.Outof = gvProfessionalCourses.Rows[i].Cells[4].Text; objProfessionalDetails.Mode = int.Parse(Mode.Text); objSaveProfessionalDetailsCollection.Add(objProfessionalDetails); } } BusinessEntities.RaveHRCollection objDeleteProfessionalDetailsCollection = (BusinessEntities.RaveHRCollection)ViewState[PROFESSIONALDETAILSDELETE]; if (objDeleteProfessionalDetailsCollection != null) { BusinessEntities.ProfessionalDetails obj = null; for (int i = 0; i < objDeleteProfessionalDetailsCollection.Count; i++) { objProfessionalDetails = new BusinessEntities.ProfessionalDetails(); obj = (BusinessEntities.ProfessionalDetails)objDeleteProfessionalDetailsCollection.Item(i); objProfessionalDetails.ProfessionalId = obj.ProfessionalId; objProfessionalDetails.EMPId = obj.EMPId; objProfessionalDetails.CourseName = obj.CourseName; objProfessionalDetails.InstitutionName = obj.InstitutionName; objProfessionalDetails.PassingYear = obj.PassingYear; objProfessionalDetails.Score = obj.Score; objProfessionalDetails.Outof = obj.Outof; objProfessionalDetails.Mode = obj.Mode; objSaveProfessionalDetailsCollection.Add(objProfessionalDetails); } } objProfessionalDetailsBAL.Manipulation(objSaveProfessionalDetailsCollection); if (ViewState.Count > 0) { ViewState.Clear(); } //Refresh the grip after saving //this.PopulateGrid(); if (EMPId.Value != string.Empty) { int empID = Convert.ToInt32(EMPId.Value); //Refresh the grip after saving this.PopulateGrid(empID); } if (gvProfessionalCourses.Rows.Count == 0) { btnSave.Visible = false; } lblMessage.Text = "Prosessional Courses saved successfully."; } catch (RaveHRException ex) { LogErrorMessage(ex); } catch (Exception ex) { RaveHRException objEx = new RaveHRException(ex.Message, ex, Sources.PresentationLayer, CLASS_NAME, "btnSave_Click", EventIDConstants.RAVE_HR_PROJECTS_PRESENTATION_LAYER); LogErrorMessage(objEx); } }