From a8873848498c3bf071b951957e0aaaa3d0c9aa77 Mon Sep 17 00:00:00 2001 From: ​ Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: payment --- payment/Payment/frmCustomer.cs | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 payment/Payment/frmCustomer.cs (limited to 'payment/Payment/frmCustomer.cs') diff --git a/payment/Payment/frmCustomer.cs b/payment/Payment/frmCustomer.cs new file mode 100644 index 0000000..eb57959 --- /dev/null +++ b/payment/Payment/frmCustomer.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Payment +{ + public partial class frmCustomer : Form + { + public frmCustomer() + { + InitializeComponent(); + } + + bool isDataSaved = true; + + private void frmCustomer_Load(object sender, EventArgs e) + { + cboNames.Items.Add("Mike Smith"); + cboNames.Items.Add("Nancy Jones"); + } + + private void frmCustomer_FormClosing(object sender, FormClosingEventArgs e) + { + if (isDataSaved == false) { + string msg = "This form contains unsaved data" + + "\n\nDo you want to save it?"; + + DialogResult button = + MessageBox.Show(msg, "Customer", + MessageBoxButtons.YesNoCancel, + MessageBoxIcon.Warning); + + if (button == DialogResult.Yes) + if (IsValidData()) + this.SaveData(); + else + e.Cancel = true; + if (button == DialogResult.Cancel) + e.Cancel = true; + } + } + + private void btnSelectPayment_Click(object sender, EventArgs e) + { + Form payment = new frmPayment(); + DialogResult selectedButton = payment.ShowDialog(); + if (selectedButton == DialogResult.OK) + lblPayment.Text = (string)payment.Tag; + } + + private void btnSave_Click(object sender, EventArgs e) + { + if (IsValidData()) + SaveData(); + } + + private void btnExit_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void lblPayment_TextChanged(object sender, EventArgs e) + { + isDataSaved = false; + } + + private void cboNames_SelectedIndexChanged(object sender, EventArgs e) + { + isDataSaved = false; + lblPayment.Text = ""; + } + + private void SaveData() + { + cboNames.SelectedIndex = -1; + lblPayment.Text = ""; + isDataSaved = true; + cboNames.Focus(); + } + + private bool IsValidData() + { + if (cboNames.SelectedIndex == -1) { + MessageBox.Show("You must select a customer", + "Entry Error"); + return false; + } + if (lblPayment.Text == "") { + MessageBox.Show("You must enter a payment", + "Entry Error"); + return false; + } + return true; + } + } +} -- cgit 1.4.1