Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using Telerik.WinControls.UI;
- using HallmarkSolutions.PAMS.Interop.EntityFramework;
- using HallmarkSolutions.PAMS.Interop.DataObjects;
- using HallmarkSolutions.PAMS.Interop.DataObjects.Employee;
- using UtilityLibrary;
- using Telerik.WinControls;
- using TelerikReports;
- using System.Collections.ObjectModel;
- namespace HallmarkSolutions.PAMS.Interop.Forms
- {
- public partial class EmployeeAppraisalForm : Telerik.WinControls.UI.RadForm
- {
- #region Fields
- private string employeeName;
- private int userid;
- private PamsContext pamsContext = new PamsContext();
- // private List<AppraisalList> apprList;
- BindingList<AppraisalList> apprList;
- int recordid;
- int empNo;
- DateTime apprisal_date;
- bool dataChanged;
- private bool viewRights;
- #endregion
- public EmployeeAppraisalForm(int id, string username, bool viewRights, bool addRights, bool editRights, bool deleteRights)
- {
- InitializeComponent();
- empNo = id;
- employeeName = username;
- this.Text += " "+employeeName.ToString();
- this.viewRights = viewRights;
- if (!addRights)
- cmdnew.Enabled = false;
- if (!deleteRights)
- cmddelete.Enabled = false;
- if (!editRights)
- {
- rdaprisal.ReadOnly = true;
- rdnotes.ReadOnly = true;
- cbotalent.Enabled = false;
- grvappraisal.ReadOnly = true;
- btnsave.Enabled = true;
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- }
- private void DataValueChanged(object sender, EventArgs e)
- {
- try
- {
- dataChanged = true;
- if (!btnsave.Enabled)
- btnsave.Enabled = true;
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the DataValueChanged event.", ex);
- }
- }
- private void EmployeeAppraisalForm_Load(object sender, EventArgs e)
- {
- // try
- // {
- rdtalentrating.DataSource = pamsContext.GetTalentRating();
- rdtalentrating.DisplayMember = "value";
- rdtalentrating.ValueMember = "key";
- rdreadiness.DataSource = pamsContext.GetAppraisalReadiness();
- rdreadiness.DisplayMember = "value";
- rdreadiness.ValueMember = "key";
- BindAppraisalList(false);
- rdnotes.TextChanged += DataValueChanged;
- rdnextappraisaldate.TextChanged += DataValueChanged;
- rdaprisal.ValueChanged += DataValueChanged;
- rdreadiness.TextChanged += DataValueChanged;
- performancescore.TextChanged += DataValueChanged;
- rdtalentrating.TextChanged += DataValueChanged;
- this.rdnextappraisaldate.DateTimePickerElement.NullDate = new DateTime(1900, 01, 01);
- this.rdnextappraisaldate.NullText = "";
- // }
- // catch (Exception ex)
- /// {
- // ExceptionBox.Show("An error occurred in the Form load event.", ex);
- // }
- }
- private void BindAppraisalList(bool postUpdate)
- {
- try
- {
- BindingSource bs = new BindingSource();
- bs.DataSource = pamsContext.GetAppraisals(empNo);
- grvappraisal.DataSource = bs;
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the Bind Appraisal event.", ex);
- }
- }
- private void cmdnew_Click(object sender, EventArgs e)
- {
- int contractId = 0;
- List<ContractSelectionList> contracts = pamsContext.GetEmployeeContracts(empNo);
- if (contracts.Count == 0)
- {
- MessageBox.Show(string.Format("{0} ({1}) does not have any contracts!", "", empNo), "Create Appriasal Records", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- else
- {
- if (contracts.Count > 1)
- {
- EmployeeContractSelectionForm form = new EmployeeContractSelectionForm("", contracts);
- form.ShowDialog(this);
- contractId = form.ContractId;
- }
- else
- { contractId = contracts[0].ContractId;
- }
- EmployeeTransactionDateForm form2 = new EmployeeTransactionDateForm();
- form2.ShowDialog(this);
- contractId = contractId;
- DateTime? dateSample;
- dateSample = null;
- apprList.Add(new AppraisalList(empNo, contractId, contractId, Convert.ToDateTime("15/08/2013"), "david", Convert.ToDateTime("15/08/2013"), 90, "test", Convert.ToDateTime("15/08/2013"), 1, 2, 3));
- rebindgrid(apprList);
- }
- // BindAppraisalList(false);
- }
- private void rebindgrid(BindingList<AppraisalList> bd)
- {
- BindingSource bs = new BindingSource();
- bs.DataSource = bd;
- grvappraisal.DataSource = bs;
- }
- private void btnsave_click(object sender, EventArgs e)
- {
- try
- {
- if (dataChanged)
- {
- if ( pamsContext.SaveChanges())
- Close();
- }
- else
- Close();
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the Save button Click event.", ex);
- }
- }
- private void grvappraisal_Click(object sender, EventArgs e)
- {
- recordid = Convert.ToInt32(grvappraisal.SelectedRows[0].Cells[0].Value);//grvappraisal.SelectedRows.
- }
- private void grvappraisal_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
- {
- try
- {
- if (grvappraisal.SelectedRows.Count > 0)
- {
- //appraisal appraisal = grvappraisal.SelectedRows[0].DataBoundItem as appraisal;
- AppraisalList appraisal = grvappraisal.SelectedRows[0].DataBoundItem as AppraisalList;
- appraisal.Next_Date = rdnextappraisaldate.Value;
- //appraisal.Readiness = Convert.ToInt32(rdreadiness.SelectedValue);
- //appraisal.rating = Convert.ToInt32(rdtalentrating.SelectedValue);
- //appraisal.submitted = rdaprisal.Value;
- // appraisal.notes = rdnotes.Text;
- }
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the CurrentRowChanged event.", ex);
- }
- }
- private void grvappraisal_RowsChanged(object sender, GridViewCollectionChangedEventArgs e)
- {
- }
- private void grvappraisal_SelectionChanged(object sender, EventArgs e)
- {
- try
- {
- if (grvappraisal.SelectedRows.Count > 0)
- {
- AppraisalList appraisal = grvappraisal.SelectedRows[0].DataBoundItem as AppraisalList;
- rdnextappraisaldate.Value= appraisal.Next_Date ;
- //appraisal appraisal = grvappraisal.SelectedRows[0].DataBoundItem as appraisal;
- //rdnextappraisaldate.Value = appraisal.next_date;
- //rdreadiness.SelectedValue = appraisal.Readiness;
- //rdtalentrating.SelectedValue = appraisal.rating;
- //appraisal.submitted = rdaprisal.Value;
- //rdnotes.Text = appraisal.notes;
- }
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the grvappraisal_SelectionChanged event.", ex);
- }
- }
- private void cmdcancel_Click(object sender, EventArgs e)
- {
- try
- {
- if (dataChanged)
- {
- DialogResult result = CheckForChanges();
- if (result == DialogResult.Cancel)
- return;
- else
- Close();
- }
- else
- Close();
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the Close button click event.", ex);
- }
- }
- private DialogResult CheckForChanges()
- {
- DialogResult result = DialogResult.Cancel;
- try
- {
- result = MessageBox.Show("The appraisal form record details have changed. Do you want to keep the changes?", "Keep Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3);
- switch (result)
- {
- case DialogResult.Yes:
- if (!pamsContext.SaveChanges())
- return DialogResult.Cancel;
- break;
- case DialogResult.No:
- dataChanged = false;
- break;
- }
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the CheckForChanges method.", ex);
- }
- return result;
- }
- private void rdnotes_TextChanged(object sender, EventArgs e)
- {
- dataChanged = true;
- }
- private void grvappraisal_RowsChanging(object sender, GridViewCollectionChangingEventArgs e)
- {
- }
- private void grvappraisal_CellDoubleClick(object sender, GridViewCellEventArgs e)
- {
- }
- private void rdaprisal_ValueChanged(object sender, EventArgs e)
- {
- dataChanged = true;
- }
- private void rdtalentrating_VisibleChanged(object sender, EventArgs e)
- {
- dataChanged = true;
- }
- private void rdreadiness_SelectedValueChanged(object sender, EventArgs e)
- {
- dataChanged = true;
- }
- private void rdnextappraisaldate_ValueChanged(object sender, EventArgs e)
- {
- dataChanged = true;
- }
- private void performancescore_TextChanged(object sender, EventArgs e)
- {
- dataChanged = true;
- }
- private void btnsave_Click_1(object sender, EventArgs e)
- {
- }
- private void btnsave_Click_2(object sender, EventArgs e)
- {
- try
- {
- if (dataChanged)
- {
- DialogResult result = CheckForChanges();
- if (result == DialogResult.Cancel)
- return;
- else
- {
- }
- // Close();
- }
- else
- Close();
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the Close button click event.", ex);
- }
- }
- private void cmdprint_Click(object sender, EventArgs e)
- {
- try
- {
- EmployeeTransactionDateForm form2 = new EmployeeTransactionDateForm();
- form2.ShowDialog(this);
- form2.Text = "Date Selection";
- AppraisalReportGeneratingForm form = new AppraisalReportGeneratingForm();
- form.CancelGeneration += OnCancelGeneration;
- form.Show(this);
- backgroundWorker.RunWorkerAsync();
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the btnPrint_Click event.", ex);
- }
- }
- private void OnCancelGeneration()
- {
- try
- {
- backgroundWorker.CancelAsync();
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the OnCancelGeneration event.", ex);
- }
- }
- private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
- {
- try
- {
- Form[] forms = this.OwnedForms;
- foreach (Form f in forms)
- {
- if (f is AppraisalReportGeneratingForm)
- f.Close();
- }
- ReportViewer viewer = new ReportViewer();
- Telerik.Reporting.Report rpt = null;
- AppraisalListReport reportfilter;
- rpt = new AppraisalReport();
- ((AppraisalReport)rpt).DataSource = pamsContext.GetAppraisalReport(empNo,DateTime.MinValue,DateTime.MinValue);
- ((AppraisalReport)rpt).ReportTitle = "Appraisal Report";
- viewer.ReportTitle = "Appraisal Report";
- viewer.Report = rpt;
- viewer.Refresh();
- viewer.ShowDialog(this);
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the backgroundWorker_RunWorkerCompleted event.", ex);
- }
- }
- private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
- {
- try
- {
- e.Result = pamsContext.GetAppraisalReport(empNo, DateTime.MinValue, DateTime.MinValue);
- }
- catch (System.IO.IOException ioex)
- {
- backgroundWorker.ReportProgress(0, "I/O Error.");
- e.Result = ioex;
- }
- catch (Exception ex)
- {
- backgroundWorker.ReportProgress(0, "An exception occurred.");
- e.Result = ex;
- }
- }
- private void cmddelete_Click(object sender, EventArgs e)
- {
- try
- {
- AppraisalList apprisal = grvappraisal.SelectedRows[0].DataBoundItem as AppraisalList;
- if (grvappraisal.SelectedRows.Count == 0)
- return;
- grvappraisal.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.FullRowSelect;
- DialogResult result = MessageBox.Show(string.Format("Are you sure you want to delete the following Appraisal record: ", ""), "Delete Apprisal Record", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- if (result == DialogResult.Yes)
- {
- if (pamsContext.SaveChanges())
- {
- BindAppraisalList(false);
- }
- else
- MessageBox.Show("The Appraisal record could not be deleted!", "Delete Appraisal Record", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- }
- catch (Exception ex)
- {
- ExceptionBox.Show("An error occurred in the delete Appraisal record button Click event.", ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement