Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using RRCAG.Business;
  10.  
  11. namespace VehicleSalesQuoteKyleSpecht
  12. {
  13. /// <summary>
  14. /// Represents a Vehicle Sales Quote Form
  15. /// </summary>
  16. public partial class VehicleSalesQuoteForm : Form
  17. {
  18. private SalesQuote salesQuote;
  19. private const decimal tax = .13m;
  20.  
  21. /// <summary>
  22. /// Initialzes a Vehicle Sales Quote Form
  23. /// </summary>
  24. public VehicleSalesQuoteForm()
  25. {
  26. InitializeComponent();
  27. salesQuote = null;
  28. lblSummarySalesTax.Text = string.Format("Sales Tax ({0}%):", Math.Round(tax * 100, 0));
  29. btnCalculate.Click += new EventHandler(btnCalculate_Click);
  30. txtTradeInValue.TextChanged += new EventHandler(VehicleSalePriceAndTradeIn_TextChanged);
  31. txtVehicleSalesPrice.TextChanged += new EventHandler(VehicleSalePriceAndTradeIn_TextChanged);
  32. nudAnnualInterestRate.ValueChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  33. nudNumOfYears.ValueChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  34. chkComputerNav.CheckedChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  35. chkLeatherInterior.CheckedChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  36. chkStereoSystem.CheckedChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  37. radCustom.CheckedChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  38. radPearlized.CheckedChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  39. radStandard.CheckedChanged += new EventHandler(ButtonCheckboxNumYearsAndInterestRate_Changed);
  40. btnReset.Click += new EventHandler(btnReset_Click);
  41.  
  42. }
  43.  
  44. /// <summary>
  45. /// Handled when the Reset button is clicked.
  46. /// </summary>
  47. void btnReset_Click(object sender, EventArgs e)
  48. {
  49. DialogResult result = MessageBox.Show("Do you want to reset the form?", "Reset Form", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
  50.  
  51. if (result == DialogResult.Yes)
  52. {
  53. ResetForm();
  54. }
  55. }
  56.  
  57. /// <summary>
  58. /// Handled when a Radio Button, Checkbox, Number of years or Interest Rate is changed.
  59. /// </summary>
  60. void ButtonCheckboxNumYearsAndInterestRate_Changed(object sender, EventArgs e)
  61. {
  62. if (salesQuote != null)
  63. {
  64. btnCalculate.PerformClick();
  65. }
  66. }
  67.  
  68. /// <summary>
  69. /// Handled when the Vehicle Sale Price or Trade In Value text is changed..
  70. /// </summary>
  71. void VehicleSalePriceAndTradeIn_TextChanged(object sender, EventArgs e)
  72. {
  73. TextChangedReset();
  74. }
  75.  
  76. /// <summary>
  77. /// Handled when the Calculate button is clicked.
  78. /// </summary>
  79. void btnCalculate_Click(object sender, EventArgs e)
  80. {
  81. decimal vehicleSalesPrice;
  82. decimal tradeInValue;
  83.  
  84. bool vehicleSalesPriceTextBool = decimal.TryParse(txtVehicleSalesPrice.Text, out vehicleSalesPrice);
  85. bool tradeInTextBool = decimal.TryParse(txtTradeInValue.Text, out tradeInValue);
  86.  
  87. if (!vehicleSalesPriceTextBool) //Cannot contain letters or special characters
  88. {
  89. errorProvider1.SetError(txtVehicleSalesPrice, "Vehicle price cannot contain letters or special characters.");
  90. errorProvider1.SetIconPadding(txtVehicleSalesPrice, 3);
  91. }
  92. else
  93. {
  94. if (vehicleSalesPrice <= 0) //Cannot be less than or equal to 0.
  95. {
  96. errorProvider1.SetError(txtVehicleSalesPrice, "Vehicle price cannot be less than or equal to 0.");
  97. errorProvider1.SetIconPadding(txtVehicleSalesPrice, 3);
  98. }
  99. }
  100.  
  101. if (!tradeInTextBool) // Cannot contain special characters or letters.
  102. {
  103. errorProvider1.SetError(txtTradeInValue, "Trade-in value cannot contain letters or special characters.");
  104. errorProvider1.SetIconPadding(txtTradeInValue, 3);
  105. }
  106. else
  107. {
  108. if (tradeInValue < 0) // Cannot be less than 0.
  109. {
  110. errorProvider1.SetError(txtTradeInValue, "Trade-in value cannot be less than 0.");
  111. errorProvider1.SetIconPadding(txtTradeInValue, 3);
  112. }
  113. }
  114.  
  115. if (vehicleSalesPriceTextBool && vehicleSalesPrice > 0) // Is a number AND greater than 0.
  116. {
  117. if (tradeInValue > vehicleSalesPrice) //Trade in value cannot be bigger than vehicle sales price
  118. {
  119. errorProvider1.SetError(txtTradeInValue, "Trade-in value cannot exceed the vehicle sale price.");
  120. errorProvider1.SetIconPadding(txtTradeInValue, 3);
  121. }
  122. else //Everything valides we calculate.
  123. {
  124. errorProvider1.SetError(txtTradeInValue, "");
  125. errorProvider1.SetError(txtVehicleSalesPrice, "");
  126.  
  127. //decimal tax = .14m;
  128.  
  129. salesQuote = new SalesQuote(decimal.Parse(txtVehicleSalesPrice.Text), decimal.Parse(txtTradeInValue.Text), tax, Accessories.None, ExteriorFinish.None);
  130.  
  131. AccessoriesCheck();
  132. FinishCheck();
  133.  
  134.  
  135. lblSummaryVehiclesSalePriceOutput.Text = string.Format("{0:C}", salesQuote.VehicleSalePrice);
  136. lblSummaryOptionsOutput.Text = string.Format("{0:N}", salesQuote.AccessoryCost + salesQuote.FinishCost);
  137. lblSummarySubtotalOutput.Text = string.Format("{0:C}", salesQuote.SubTotal);
  138. lblSummarySalesTaxOutput.Text = string.Format("{0:N}", salesQuote.SalesTax);
  139. lblSummaryTotalOutput.Text = string.Format("{0:C}", salesQuote.Total);
  140. lblSummaryTradeInOutput.Text = string.Format("{0:N}", salesQuote.TradeInAmount * -1);
  141. lblSummaryAmountDueOutput.Text = string.Format("{0:C}", salesQuote.AmountDue);
  142. lblFinanceMonthlyPaymentOutput.Text = string.Format("{0:C}", salesQuote.GetPayment(nudAnnualInterestRate.Value / 100, (int)nudNumOfYears.Value, salesQuote.AmountDue) / 12);
  143. }
  144. }
  145. }
  146.  
  147. /// <summary>
  148. /// Reset's the form to default input.
  149. /// </summary>
  150. public void ResetForm()
  151. {
  152. salesQuote = null;
  153. txtVehicleSalesPrice.Text = "";
  154. txtTradeInValue.Text = "0";
  155. lblSummaryAmountDueOutput.Text = "";
  156. lblSummaryOptionsOutput.Text = "";
  157. lblSummarySalesTaxOutput.Text = "";
  158. lblSummarySubtotalOutput.Text = "";
  159. lblSummaryTotalOutput.Text = "";
  160. lblSummaryTradeInOutput.Text = "";
  161. lblSummaryVehiclesSalePriceOutput.Text = "";
  162. lblFinanceMonthlyPaymentOutput.Text = "";
  163. chkComputerNav.Checked = false;
  164. chkLeatherInterior.Checked = false;
  165. chkStereoSystem.Checked = false;
  166. radCustom.Checked = false;
  167. radPearlized.Checked = false;
  168. radStandard.Checked = true;
  169. nudAnnualInterestRate.Value = 5m;
  170. nudNumOfYears.Value = 1m;
  171. errorProvider1.SetError(txtTradeInValue, "");
  172. errorProvider1.SetError(txtVehicleSalesPrice, "");
  173. txtVehicleSalesPrice.Focus();
  174. }
  175.  
  176. /// <summary>
  177. /// Adds the Accessories Chosen to the Vehicle Sales Quote.
  178. /// </summary>
  179. public void AccessoriesCheck()
  180. {
  181. if (chkComputerNav.Checked && chkLeatherInterior.Checked && chkStereoSystem.Checked)
  182. {
  183. salesQuote.AccessoriesChosen = Accessories.All;
  184. }
  185. else if (chkComputerNav.Checked && chkLeatherInterior.Checked)
  186. {
  187. salesQuote.AccessoriesChosen = Accessories.LeatherAndNavigation;
  188. }
  189. else if (chkStereoSystem.Checked && chkComputerNav.Checked)
  190. {
  191. salesQuote.AccessoriesChosen = Accessories.StereoAndNavigation;
  192. }
  193. else if (chkStereoSystem.Checked && chkLeatherInterior.Checked)
  194. {
  195. salesQuote.AccessoriesChosen = Accessories.StereoAndLeather;
  196. }
  197. else if (chkComputerNav.Checked)
  198. {
  199. salesQuote.AccessoriesChosen = Accessories.ComputerNavigation;
  200. }
  201. else if (chkLeatherInterior.Checked)
  202. {
  203. salesQuote.AccessoriesChosen = Accessories.LeatherInterior;
  204. }
  205. else if (chkStereoSystem.Checked)
  206. {
  207. salesQuote.AccessoriesChosen = Accessories.StereoSystem;
  208. }
  209. }
  210.  
  211. /// <summary>
  212. /// Adds the Exterior Finish chosen to the Vehicle Sales Quote.
  213. /// </summary>
  214. public void FinishCheck()
  215. {
  216. if (radCustom.Checked)
  217. {
  218. salesQuote.ExteriorFinishChosen = ExteriorFinish.Custom;
  219. }
  220.  
  221. else if (radPearlized.Checked)
  222. {
  223. salesQuote.ExteriorFinishChosen = ExteriorFinish.Pearlized;
  224. }
  225.  
  226. else if (radStandard.Checked)
  227. {
  228. salesQuote.ExteriorFinishChosen = ExteriorFinish.Standard;
  229. }
  230. }
  231.  
  232. /// <summary>
  233. /// Resets the Summary and Monthly Payment values on the form to initial state.
  234. /// </summary>
  235. public void TextChangedReset()
  236. {
  237. salesQuote = null;
  238. lblSummaryAmountDueOutput.Text = "";
  239. lblSummaryOptionsOutput.Text = "";
  240. lblSummarySalesTaxOutput.Text = "";
  241. lblSummarySubtotalOutput.Text = "";
  242. lblSummaryTotalOutput.Text = "";
  243. lblSummaryTradeInOutput.Text = "";
  244. lblSummaryVehiclesSalePriceOutput.Text = "";
  245. lblFinanceMonthlyPaymentOutput.Text = "";
  246. }
  247.  
  248.  
  249. }
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement