//Adds the customer to the database given the information private void CreateButton_Click(object sender, EventArgs e) { //The database needs a first and last name, so the function will not continue if (!first || !last) { MessageBox.Show("Please Enter a First and Last name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Create a customer object with a new transaction history Customer nCust = new Customer(); nCust.history = new List<Transaction>(); //Create a first time transaction Transaction initTrans = new Transaction(); //Sets the customer's name nCust.first = FirstText.Text; nCust.last = LastText.Text; //Adds optional information if (middle) nCust.middle = MiddleText.Text; if (DCI) nCust.DCINum = DCIText.Text; else nCust.DCINum = "N/A"; //Gets the starting credit and current time Decimal.TryParse(InitText.Text.Remove(0, 1), out nCust.credit); Decimal.TryParse(pText.Text.Remove(0, 1), out nCust.promo); initTrans.date = DateTime.Now; //Sets the reason for the intial transaction initTrans.reason = "Created Account - C: " + nCust.credit.ToString("C") + " P: " + nCust.promo.ToString("C"); initTrans.type = Transaction.Seperation.newCustomer; initTrans.amount = ""; //Adds the transaction to the customer's history nCust.history.Add(initTrans); //Loads the database List<Customer> custList = MainWin.load(); //Adds the customer to the database custList.Add(nCust); //Sorts the database to be alphabetical custList.Sort(delegate(Customer c1, Customer c2) { return c1.last.CompareTo(c2.last); }); //Saves the database MainWin.save(custList); //Process was okay DialogResult = DialogResult.OK; //Close the window this.Close(); }
//Adds the transaction to the customer's history and change's their store credit private void AmtButton_Click(object sender, EventArgs e) { //Create a transaction object Transaction trans = new Transaction(); trans.date = DateTime.Now; //Load the customer list List<Customer> custList = load(); //Find what customer the user currently has selected int custIndex = getSelectedCustomer(custList); //If there was no customer selected, then do nothing if (custIndex < 0) return; //Find what radio button is selected and make the transaction object represent that. //If one of these radio buttons are selected, then their store credit is increasing //When the customer is selling something to the user //This is the only option that adds trade-in credit if (CreditRadio.Checked) { trans.type = Transaction.Seperation.credit; trans.reason = "Traded in merchandise"; trans.amount = AmtTxt.Text; custList[custIndex].addCredit(AmtTxt.Text); } //The rest of the options add promotional credit //When the customer placed in a tournament else if (PlaceRadio.Checked) { trans.type = Transaction.Seperation.promo; trans.reason = "Came in " + PlacedNum.Value.ToString() + " place"; trans.amount = AmtTxt.Text; custList[custIndex].addPromo(AmtTxt.Text); } //When the customer split the first and second place prize else if (Top2Radio.Checked) { trans.type = Transaction.Seperation.promo; trans.reason = "Top 2"; trans.amount = AmtTxt.Text; custList[custIndex].addPromo(AmtTxt.Text); } //When the customer split the prize with the top 4 else if (Top4Radio.Checked) { trans.type = Transaction.Seperation.promo; trans.reason = "Top 4"; trans.amount = AmtTxt.Text; custList[custIndex].addPromo(AmtTxt.Text); } //When the customer split the prize with the top 8 else if (Top8Radio.Checked) { trans.type = Transaction.Seperation.promo; trans.reason = "Top 8"; trans.amount = AmtTxt.Text; custList[custIndex].addPromo(AmtTxt.Text); } //Custom reason else if (CustomRadio.Checked) { trans.type = Transaction.Seperation.promo; trans.reason = CustomText.Text; trans.amount = AmtTxt.Text; custList[custIndex].addPromo(AmtTxt.Text); } //If one of these radio buttons are selected, then their credit is decreasing //If the customer is buying something with their credit else if (PurchaseRadio.Checked) { trans.type = Transaction.Seperation.purchase; trans.reason = "Purchased merchandised"; trans.amount = "-" + AmtTxt.Text; custList[custIndex].subCredit(AmtTxt.Text); } //If the customer is using their credit for an entrance fee else if (EntryRadio.Checked) { trans.type = Transaction.Seperation.purchase; trans.reason = "Entry Fee"; trans.amount = "-" + AmtTxt.Text; custList[custIndex].subCredit(AmtTxt.Text); } //Custom reason for why they lose credit else if (CustomReRadio.Checked) { trans.type = Transaction.Seperation.purchase; trans.reason = CustomReText.Text; trans.amount = "-" + AmtTxt.Text; custList[custIndex].subCredit(AmtTxt.Text); } //Save the transaction to the customer's history custList[custIndex].history.Insert(0, trans); //Save the customer list save(custList); //Load the new list setUpList(); }