Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sources/CandidatesBrowser/CandidatesBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\DataSources\HumanResourcesLibrary.DataClasses.Candidate.datasource" />
<None Include="Properties\Settings.settings">
Expand Down
56 changes: 28 additions & 28 deletions sources/CandidatesBrowser/Forms/CandidateForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 61 additions & 29 deletions sources/CandidatesBrowser/Forms/CandidateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Resources;
using HumanResourcesLibrary.DataClasses; // for Candidate
using DevExpress.XtraGrid.Views.Grid;

Expand All @@ -20,6 +21,8 @@ public CandidateForm()
InitializeComponent();
englishLevelComboBox.Properties.Items.AddRange(typeof (HumanResourcesLibrary.DataClasses.EnglishLevel).GetEnumValues());
genderComboBox.Properties.Items.AddRange(typeof(HumanResourcesLibrary.DataClasses.Gender).GetEnumValues());

this.CancelButton = this.cancelButton; // pressing ESC is now equivalent to pressing Cancel
}

// TODO: you are free to change this name if you have a better one.
Expand Down Expand Up @@ -53,19 +56,28 @@ private void RenewPhoto()

private Candidate candidate, candidateCopy;

// Added to avoid double checking that candidate equals candidateCopy when Save and Close button is pressed.
private bool saved = false;

private void commentsGridView_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
{
var newContact = (ContactWithCandidate)((GridView)sender).GetRow(e.RowHandle);
newContact.Date = DateTime.Now;
newContact.Type = ContactTypes.Call;
newContact.Comment = "";
if (sender != null)
{
var newContact = (ContactWithCandidate)((GridView)sender).GetRow(e.RowHandle);
newContact.Date = DateTime.Now;
newContact.Type = ContactTypes.Call;
newContact.Comment = "";
}
}

private void RowsDeletion(object sender, KeyEventArgs e)
{
var gridView = (GridView)sender;
if (e.KeyCode == Keys.Delete)
gridView.DeleteSelectedRows();
if (sender != null)
{
var gridView = (GridView)sender;
if (e.KeyCode == Keys.Delete)
gridView.DeleteSelectedRows();
}
}

private void commentsGridView_KeyDown(object sender, KeyEventArgs e)
Expand All @@ -75,9 +87,12 @@ private void commentsGridView_KeyDown(object sender, KeyEventArgs e)

private void phonesGridView_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
{
var newPhone = (Phone)((GridView)sender).GetRow(e.RowHandle);
newPhone.Type = PhoneType.Mobile;
newPhone.PhoneNumber = "";
if (sender != null)
{
var newPhone = (Phone)((GridView)sender).GetRow(e.RowHandle);
newPhone.Type = PhoneType.Mobile;
newPhone.PhoneNumber = "";
}
}

private void phonesGridView_KeyDown(object sender, KeyEventArgs e)
Expand All @@ -87,19 +102,26 @@ private void phonesGridView_KeyDown(object sender, KeyEventArgs e)

private void socialNetworksGridView_InitNewRow(object sender, InitNewRowEventArgs e)
{
var newSocNetowrk = (SocialNetwork)((GridView)sender).GetRow(e.RowHandle);
newSocNetowrk.Type = SocialNetworkType.Facebook;
newSocNetowrk.Link = "";
if (sender != null)
{
var newSocNetowrk = (SocialNetwork)((GridView)sender).GetRow(e.RowHandle);
newSocNetowrk.Type = SocialNetworkType.Facebook;
newSocNetowrk.Link = "";
}
}

private void socialNetworksGridView_KeyDown(object sender, KeyEventArgs e)
{
RowsDeletion(sender, e);
}

private void saveButton_Click(object sender, EventArgs e)
private void saveAndCloseButton_Click(object sender, EventArgs e)
{
SaveCandidate();
if (!this.candidate.Equals(this.candidateCopy))
SaveCandidate();
saved = true;

Close();
}

private void cancelButton_Click(object sender, EventArgs e)
Expand All @@ -109,23 +131,33 @@ private void cancelButton_Click(object sender, EventArgs e)

private void CandidateForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (!this.candidate.Equals(this.candidateCopy))
// if Save and Close button was pressed, everything is already up to date and we don't need to check it.
if (saved)
{
var result = MessageBox.Show("Record has been changed but not saved.\nDo you want to save changes?",
"Warning", MessageBoxButtons.YesNoCancel);

switch (result)
saved = false;
}
else if (!this.candidate.Equals(this.candidateCopy))
{
using (var resources = new ResXResourceSet("..\\..\\Properties\\Resources.resx"))
{
case DialogResult.Yes:
SaveCandidate();
break;
var message = resources.GetString("CandidateFormClosingMessage");
var title = resources.GetString("CandidateFormClosingMBoxTitle");

var result = MessageBox.Show(message, title, MessageBoxButtons.YesNoCancel);

switch (result)
{
case DialogResult.Yes:
SaveCandidate();
break;

case DialogResult.No:
break;
case DialogResult.No:
break;

case DialogResult.Cancel:
e.Cancel = true;
break;
case DialogResult.Cancel:
e.Cancel = true;
break;
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions sources/CandidatesBrowser/Forms/CandidatesBrowserMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ private void addButton_Click(object sender, EventArgs e)

private void editButton_Click(object sender, EventArgs e)
{
if (mainGridView.SelectedRowsCount == 1)
if (mainGridView != null && mainGridView.SelectedRowsCount == 1)
this.mainGridView_DoubleClick(mainGridView, e);
}

private void mainGridView_DoubleClick(object sender, EventArgs e)
{
candidateForm.FormCandidate = (Candidate)((GridView)sender).GetRow(((GridView)sender).FocusedRowHandle);
candidateForm.ShowDialog();
if (sender != null)
{
candidateForm.FormCandidate = (Candidate)((GridView)sender).GetRow(((GridView)sender).FocusedRowHandle);
candidateForm.ShowDialog();
}
}
}
}
Loading