Esempio n. 1
0
 /// <summary>
 /// Modify method.
 /// </summary>
 /// <remarks>
 /// The main method of that class that initialize the components in the form.
 /// </remarks>
 /// <param name="iVehicle">The selected vehicle from the previos form</param>
 /// <param name="modList">List with all stock vehicles</param>
 /// <param name="sName">The name of the user (buyer)</param>
 /// <param name="cBudget">The budget of the user</param>
 public Modify(int iVehicle, ModifiableList modList, string sName, Budget cBudget)
 {
     InitializeComponent();
     this.FormClosing += ThisForm_FormClosing; //check if the red "X" is pressed
     Debug.WriteLine("ListSize() in Modify: " + modList.ListSize()); // the size of the list in this form
     imb = modList.GetObjectFromList(iVehicle);
     this.sName = sName;
     this.cBudget = cBudget;
     Modify_Load();
 }
Esempio n. 2
0
        /// <summary>
        /// btnSubmit_Click method
        /// </summary>
        /// <remarks>
        /// Check if all the fields are filled with the appropriate input. Then proceed to the next form.
        /// </remarks>
        /// <param name="sender">A reference to the control/object that raised the event.</param>
        /// <param name="e">The event data</param>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            Debug.WriteLine("Selected object is: " + iSelectedObject);
            try
            {
                //is empty
                if (string.IsNullOrWhiteSpace(txtName.Text) || string.IsNullOrWhiteSpace(txtBudget.Text) || string.IsNullOrWhiteSpace(cmbVehicleType.Text) || string.IsNullOrWhiteSpace(cmbVehicleModel.Text))
                {
                    MessageBox.Show("Please fill all fields.");
                }
                // does the name contain numbers
                else if (txtName.Text.Any(char.IsDigit))
                {
                    MessageBox.Show("Please enter valid data.");
                    txtName.BackColor = System.Drawing.Color.Red;
                }
                //OK
                else
                {
                    Budget budget = new Budget();
                    budget.Balance = Convert.ToDouble(txtBudget.Text) - imb.Price;
                    Modify secondForm = new Modify(iSelectedObject, modlist, txtName.Text, budget);
                    secondForm.Show();
                    this.Hide();
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Please enter valid data.");
                txtBudget.BackColor = System.Drawing.Color.Red;

            }
            catch (LowBalanceExeption money)
            {
                int errorLenght = Convert.ToString(money).IndexOf("!") - Convert.ToString(money).IndexOf(":");
                MessageBox.Show(Convert.ToString(money).Substring(Convert.ToString(money).IndexOf(":") + 2, errorLenght));
            }
        }