C2024-029 RO Editor - Referenced Object Definition Form - Add check if items changed before prompting to possibly save

This commit is contained in:
Matthew Schill 2024-10-15 08:40:12 -04:00
parent 28e4bdda29
commit a8294bb01a

View File

@ -1542,7 +1542,7 @@ namespace ROEditor
//only close if they say "Yes, they want to" //only close if they say "Yes, they want to"
protected override void OnFormClosing(FormClosingEventArgs e) protected override void OnFormClosing(FormClosingEventArgs e)
{ {
if (this.DialogResult != System.Windows.Forms.DialogResult.OK && !CloseCancel()) if (this.DialogResult != System.Windows.Forms.DialogResult.OK && IsPendingChange() && !CloseCancel())
{ {
e.Cancel = true; e.Cancel = true;
} }
@ -1558,6 +1558,49 @@ namespace ROEditor
return result == DialogResult.Yes; return result == DialogResult.Yes;
} }
//return true if a field has been modified
private bool IsPendingChange()
{
if (origRetVal != this.tbRetVal.Text)
return true;
if (origMenuItem != this.tbMenuVal.Text)
return true;
// check if in use records have changed
string inuserecs = null;
ROField rof;
for (int i = 0; i < InUseList.Count; i++)
{
rof = (ROField)InUseList[i];
if (rof.GetFieldname != null) //DO YET: why null?
{
inuserecs = inuserecs + rof.GetRecID;
if (i + 1 < InUseList.Count) inuserecs = inuserecs + " ";
}
}
if (inuserecs != origFieldsInUse)
return true;
//check if applicability fields have changed
string applicfieldrecs = null;
for (int i = 0; i < InUseApplcList.Count; i++)
{
rof = (ROField)InUseApplcList[i];
if (rof.GetFieldname != null)
{
applicfieldrecs = applicfieldrecs + rof.GetRecID;
if (i + 1 < InUseApplcList.Count) applicfieldrecs = applicfieldrecs + " ";
}
}
if (applicfieldrecs != origApplicFields)
return true;
//nothing has changed
return false;
}
#endregion #endregion
} }
} }