/// <summary> /// Method to load the combobox with the service list /// </summary> private void InitializeForm() { cmboBox_Services.DataSource = Enum.GetNames(typeof(HomeClass.ServiceList)); //show the name and ID on the form txtBox_Name.Text = HomeClass.GetCustName(); txtBox_CustId.Text = HomeClass.GetCustId(); }
/// <summary> /// Method button to validate the selection was made /// and update the transaction list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_AddService_Click(object sender, EventArgs e) { bool goodTransaction = false; double amount = 0; if (cmboBox_Services.SelectedItem == null) { MessageBox.Show("Must select a service."); } else { if (paymentSelected) { if (txtBox_Amount.Text == "") { MessageBox.Show("Please Enter a Payment Amount"); } else { double.TryParse(txtBox_Amount.Text, out amount); amount *= -1; goodTransaction = true; } } else { double.TryParse(txtBox_Amount.Text, out amount); goodTransaction = true; } if (goodTransaction) { //update transaction list string transactionDate = DateTime.Now.ToString("MM/dd/yyyy"); string custID = HomeClass.GetCustId(); string selectedService = cmboBox_Services.SelectedItem.ToString(); string newTransaction = custID + "," + transactionDate + "," + selectedService + "," + amount.ToString(); HomeClass.CustomerServicesList.Add(newTransaction); Btn_AddService.Enabled = false; MessageBox.Show("Transaction Complete. Go Back or Add Another."); } } }
/// <summary> /// Method to populate the text box with selected cust info. /// </summary> private void InitializeAddServiceForm() { txtBox_CustId.Text = "Cust ID " + HomeClass.GetCustId(); string custID = HomeClass.GetCustId(); txtBox_CustName.Text = HomeClass.GetCustName(); double total = 0; double amount; //headers listView_ServiceList.View = View.Details; listView_ServiceList.Columns.Add("Date", 100); listView_ServiceList.Columns.Add("Service", 100); listView_ServiceList.Columns.Add("Cost", -2); //go through the customer service list, write info based on customerID selected foreach (string transaction in HomeClass.CustomerServicesList) { string[] transactionItems = transaction.Split(','); //match the custID from selected customer with ID from the list if (transactionItems[0] == custID) { string transactionDate = transactionItems[1].ToString(); string transactionType = transactionItems[2].ToString(); string cost = transactionItems[3].ToString(); //totaling the amount due double.TryParse(cost, out amount); total = total + amount; //adding the matching transactions to the listView (box) listView_ServiceList.Items.Add(new ListViewItem(new string[] { transactionDate, transactionType, cost })); } } //show the total due txtBox_AmountDue.Text = total.ToString(); }