diff --git a/QueueSys/frmCustomerView.cs b/QueueSys/frmCustomerView.cs index ebcc1d3..f00fe8b 100644 --- a/QueueSys/frmCustomerView.cs +++ b/QueueSys/frmCustomerView.cs @@ -23,6 +23,12 @@ namespace QueueSys RefreshCustomerView(); } + // Triggered by Employee View form add buttom as a delegate. + public void MessageReceived(object sender, EventArgs e) + { + RefreshCustomerView(); + } + private void RefreshCustomerView() { SqliteDataAccess sdaCxView = new SqliteDataAccess(); diff --git a/QueueSys/frmEmployeeView.cs b/QueueSys/frmEmployeeView.cs index ae89905..ef54a30 100644 --- a/QueueSys/frmEmployeeView.cs +++ b/QueueSys/frmEmployeeView.cs @@ -8,6 +8,10 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +/* References */ +// Using a delegate to trigger method on the customer view form +// https://www.coderslexicon.com/passing-data-between-forms-using-delegates-and-events/ + namespace QueueSys { public partial class frmEmployeeView : Form @@ -17,18 +21,28 @@ namespace QueueSys InitializeComponent(); } + // Our delegate (which "points" at any method which takes an object and EventArgs) + // Look familiar? This is the signature of most control events on a form + public delegate void SendMessage(object obj, EventArgs e); + + // Here is the event we trigger to send messages out to listeners + public event SendMessage OnSendMessage; + /* Execute when program / main form loads. - * Pop up the customer view screen to drag onto second monitor */ + * Pop up the customer view screen to drag onto second monitor + * creates our second form, says "attach its MessageReceived function to the event" + */ private void frmEmployeeView_Load(object sender, EventArgs e) { - Form frm = new frmCustomerView(); + frmCustomerView frm = new frmCustomerView(); + OnSendMessage += frm.MessageReceived; frm.Show(); } /* Enable options menu. */ private void optionsToolStripMenuItem_Click(object sender, EventArgs e) { - Form frm = new frmOptions(); + frmOptions frm = new frmOptions(); frm.Show(); frm.Activate(); } @@ -52,7 +66,8 @@ namespace QueueSys sda.SaveCustomer(evNewCx); - //sda.LoadEmployeeView(); + //Invoke the delegate to update customer view. + OnSendMessage?.Invoke(this, e); tbCustomerName.Text = ""; cbNumBags.Text = ""; diff --git a/QueueSys/obj/Debug/QueueSys.csproj.FileListAbsolute.txt b/QueueSys/obj/Debug/QueueSys.csproj.FileListAbsolute.txt index 974bd49..7a3bbd5 100644 --- a/QueueSys/obj/Debug/QueueSys.csproj.FileListAbsolute.txt +++ b/QueueSys/obj/Debug/QueueSys.csproj.FileListAbsolute.txt @@ -26,3 +26,11 @@ C:\Users\kougyoku\Google Drive\TINFO 220_ HCI Group Project\QueueSys\QueueSys\bi C:\Users\kougyoku\Google Drive\TINFO 220_ HCI Group Project\QueueSys\QueueSys\bin\Debug\System.Data.SQLite.xml C:\Users\kougyoku\Google Drive\TINFO 220_ HCI Group Project\QueueSys\QueueSys\bin\Debug\System.Data.SQLite.dll.config C:\Users\kougyoku\Google Drive\TINFO 220_ HCI Group Project\QueueSys\QueueSys\obj\Debug\QueueSys.csproj.CopyComplete +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\bin\Debug\QueueSys.db +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\bin\Debug\Dapper.dll +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\bin\Debug\System.Data.SQLite.dll +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\bin\Debug\Dapper.xml +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\bin\Debug\System.Data.SQLite.xml +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\bin\Debug\System.Data.SQLite.dll.config +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\obj\Debug\QueueSys.frmOptions.resources +C:\Users\kougyoku\source\repos\QueueSys\QueueSys\obj\Debug\QueueSys.csproj.CopyComplete