Esempio n. 1
0
 /// <summary>
 /// Creates a new User
 /// </summary>
 /// <param name="firstName">First Name</param>
 /// <param name="lastName">Last Name</param>
 /// <param name="eMailAdress">E-Mail Adress</param>
 /// <param name="username">Username</param>
 /// <param name="customerNumber">Usernumber</param>
 public User(string firstName, string lastName, string eMailAdress, string username, int customerNumber)
 {
     _username       = username;
     _customerNumber = customerNumber;
     _dateOfCreate   = DateTime.Now;
     _eMail          = new EMailAddress(eMailAdress);
     _firstName      = firstName;
     _lastName       = lastName;
 }
Esempio n. 2
0
 /// <summary>
 /// Updates the E-Mail Address
 /// </summary>
 /// <param name="lastname"></param>
 /// <param name="e_MailAddress"></param>
 public void UpdateNameAddressEmail(string lastname, EMailAddress e_MailAddress, Address address)
 {
     if (address != null)
     {
         _adress = address;
     }
     _lastName = lastname;
     _eMail    = e_MailAddress;
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a new Customer
 /// </summary>
 /// <param name="firstName">First Name</param>
 /// <param name="lastName">Last Name</param>
 /// <param name="eMailAddress">E-Mail Address</param>
 /// <param name="customerNumber">Usernumber</param>
 /// <param name="moneyBalance">Money Balance</param>
 /// <param name="DateOfChange">Date of change</param>
 public Customer(string firstName, string lastName, string eMailAddress, int customerNumber, float moneyBalance, DateTime DateOfChange)
 {
     _MoneyBalance   = moneyBalance;
     _customerNumber = customerNumber;
     _dateOfCreate   = DateTime.Now;
     _DateOfChange   = DateOfChange;
     _eMail          = new EMailAddress(eMailAddress);
     _firstName      = firstName;
     _lastName       = lastName;
 }
Esempio n. 4
0
        private bool CheckEMailforUnique(EMailAddress eMailAddress)
        {
            for (int i = 0; i < CustomerList.Count; i++)
            {
                if (eMailAddress.getEmailAddress() == CustomerList[i]._eMail.getEmailAddress())
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Change the Name and/or E-Mail of the customer
        /// </summary>
        /// <param name="customertoChange"></param>
        /// <param name="newlastName"></param>
        /// <param name="newEMailAddress"></param>
        public Customer EditCustomeritems(Customer customer, string newlastName, EMailAddress newEMailAddress, Address newAddress)
        {
            if (CustomerList == null || customer == null)
            {
                return(customer);
            }

            for (int i = 0; i < CustomerList.Count; i++)
            {
                if (customer._customerNumber == CustomerList[i]._customerNumber)
                {
                    CustomerList[i].UpdateNameAddressEmail(newlastName, newEMailAddress, newAddress);
                    customer = CustomerList[i];
                    _mainView.UpdateDataGridViewOverview(CustomerList);
                    _mainView.UpdateDatagridViewFullList(CustomerList);
                    return(customer);
                }
            }

            return(customer);
        }
Esempio n. 6
0
        /// <summary>
        /// add a new customer to list
        /// </summary>
        /// <param name="customer"></param>
        public void AddCustomer(string firstName, string lastName, EMailAddress eMailAddress, float moneyBalance, Address address)
        {
            if (CustomerList == null)
            {
                CustomerList = new List <Customer>();
            }

            int customerNumber = CheckCustomerNumberorFindOne(CustomerList.Count + 1);


            if (eMailAddress.getEmailAddress() == String.Empty || CheckEMailforUnique(eMailAddress) == false)
            {
                MessageBox.Show("Wrong input of the E-Mail address or the E-Mail address already exit");
                return;
            }
            else
            {
                Customer customer = new Customer(firstName, lastName, eMailAddress, customerNumber, moneyBalance, DateTime.Now, address);
                CustomerList.Add(customer);
                _mainView.UpdateDataGridViewOverview(CustomerList);
                _mainView.UpdateDatagridViewFullList(CustomerList);
            }
        }
Esempio n. 7
0
        //finished
        private void ButtonClickedMainTab(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(Button))
            {
                Button btn = (Button)sender;

                if (btn == ButtonCancelSearch)
                {
                    TextBoxSearchbyLastName.Clear();
                }
                else if (btn == ButtonAddNewCustomertoList)
                {
                    Address address = new Address(TextBoxAddStreet.Text, int.Parse(TextBoxAddStreetNumber.Text),
                                                  int.Parse(TextBoxAddPostcode.Text), TextBoxAddCity.Text, TextBoxAddCountry.Text);
                    EMailAddress mailAdress = new EMailAddress(TextBoxAddE_Mail.Text);
                    _controller.AddCustomer(TextBoxAddFirstName.Text, TextBoxAddLastName.Text, mailAdress, float.Parse(TextBoxAddNewAmount.Text), address);
                    ClearTextBoxesAddNewCustomer();
                }
                else if (btn == ButtonCancelNewCustomer)
                {
                    ClearTextBoxesAddNewCustomer();
                }
            }
        }
Esempio n. 8
0
        // finished
        private void TextBoxChangedTabControllEditItems(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(TextBox))
            {
                TextBox txBox = (TextBox)sender;

                //Check Input Balance
                if (txBox == TextBoxNewAmount)
                {
                    decimal moneyBalance;
                    if (decimal.TryParse(TextBoxNewAmount.Text, out moneyBalance))
                    {
                        TextBoxNewAmount.BackColor = Color.Green;
                        if (_currentEditCustomer != null)
                        {
                            ButtonSaveNewBalance.Enabled = true;
                        }
                    }
                    else
                    {
                        TextBoxNewAmount.BackColor   = Color.Red;
                        ButtonSaveNewBalance.Enabled = false;
                    }
                }

                //Check Input Edit Items
                else if (txBox == TextBoxLastNameEditItems)
                {
                    if (CheckforLettersonly(TextBoxLastNameEditItems.Text) && TextBoxLastNameEditItems.Text.Length > 2)
                    {
                        TextBoxLastNameEditItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxLastNameEditItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled        = false;
                    }
                }
                else if (txBox == TextBoxStreetEditItems)
                {
                    if (CheckforLettersonly(TextBoxStreetEditItems.Text) && TextBoxStreetEditItems.Text.Length > 2)
                    {
                        TextBoxStreetEditItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxStreetEditItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled      = false;
                    }
                }
                else if (txBox == TextBoxEditStreetNumberItems)
                {
                    decimal moneyBalance;
                    if (decimal.TryParse(TextBoxEditStreetNumberItems.Text, out moneyBalance))
                    {
                        TextBoxEditStreetNumberItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxEditStreetNumberItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled            = false;
                    }
                }
                else if (txBox == TextBoxPostcodeEditItems)
                {
                    decimal moneyBalance;
                    if (decimal.TryParse(TextBoxPostcodeEditItems.Text, out moneyBalance))
                    {
                        TextBoxPostcodeEditItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxPostcodeEditItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled        = false;
                    }
                }
                else if (txBox == TextBoxCityEditItems)
                {
                    if (CheckforLettersonly(TextBoxCityEditItems.Text) && TextBoxCityEditItems.Text.Length > 2)
                    {
                        TextBoxCityEditItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxCityEditItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled    = false;
                    }
                }
                else if (txBox == TextBoxCountryEditItems)
                {
                    if (CheckforLettersonly(TextBoxCountryEditItems.Text) && TextBoxCountryEditItems.Text.Length > 2)
                    {
                        TextBoxCountryEditItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxCountryEditItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled       = false;
                    }
                }
                else if (txBox == TextBoxEMailEditItems)
                {
                    EMailAddress eMailAdress = new EMailAddress(TextBoxEMailEditItems.Text);
                    if (eMailAdress.Address != string.Empty && eMailAdress.Address != string.Empty)
                    {
                        TextBoxEMailEditItems.BackColor = Color.Green;
                        CheckEditBoxes();
                    }
                    else
                    {
                        TextBoxEMailEditItems.BackColor = Color.Red;
                        ButtonSaveEditItems.Enabled     = false;
                    }
                }
            }
        }
Esempio n. 9
0
        //finished
        private void TextBoxChangedMainTabControl(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(TextBox))
            {
                TextBox txBox = (TextBox)sender;

                if (txBox == TextBoxAddFirstName)
                {
                    bool textOk = CheckforLettersonly(TextBoxAddFirstName.Text);

                    if (textOk && TextBoxAddFirstName.Text.Length > 2)
                    {
                        TextBoxAddFirstName.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddFirstName.BackColor      = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddLastName)
                {
                    bool textOk = CheckforLettersonly(TextBoxAddLastName.Text);

                    if (textOk && TextBoxAddLastName.Text.Length > 2)
                    {
                        TextBoxAddLastName.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddLastName.BackColor       = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddE_Mail)
                {
                    EMailAddress eMailAdress = new EMailAddress(TextBoxAddE_Mail.Text);
                    if (eMailAdress.Address != string.Empty && eMailAdress.Address != string.Empty)
                    {
                        TextBoxAddE_Mail.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddE_Mail.BackColor         = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddNewAmount)
                {
                    decimal moneyBalance;
                    if (decimal.TryParse(TextBoxAddNewAmount.Text, out moneyBalance))
                    {
                        TextBoxAddNewAmount.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddNewAmount.BackColor      = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddStreet)
                {
                    bool textOk = CheckforLettersonly(TextBoxAddStreet.Text);

                    if (textOk && TextBoxAddStreet.Text.Length > 2)
                    {
                        TextBoxAddStreet.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddStreet.BackColor         = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddStreetNumber)
                {
                    decimal moneyBalance;
                    if (decimal.TryParse(TextBoxAddStreetNumber.Text, out moneyBalance))
                    {
                        TextBoxAddStreetNumber.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddStreetNumber.BackColor   = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddPostcode)
                {
                    decimal moneyBalance;
                    if (decimal.TryParse(TextBoxAddPostcode.Text, out moneyBalance))
                    {
                        TextBoxAddPostcode.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddPostcode.BackColor       = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddCity)
                {
                    bool textOk = CheckforLettersonly(TextBoxAddCity.Text);

                    if (textOk && TextBoxAddCity.Text.Length > 2)
                    {
                        TextBoxAddCity.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddCity.BackColor           = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }
                else if (txBox == TextBoxAddCountry)
                {
                    bool textOk = CheckforLettersonly(TextBoxAddCountry.Text);

                    if (textOk && TextBoxAddCountry.Text.Length > 2)
                    {
                        TextBoxAddCountry.BackColor = Color.Green;
                        CheckAddBoxes();
                    }
                    else
                    {
                        TextBoxAddCountry.BackColor        = Color.Red;
                        ButtonAddNewCustomertoList.Enabled = false;
                    }
                }

                else if (txBox == TextBoxSearchbyLastName)
                {
                    _controller.SearchforCustomer(TextBoxSearchbyLastName.Text, _currentCustomersList);
                }
            }
        }
Esempio n. 10
0
        // finished
        private void ButtonClickedEditItemsTab(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(Button))
            {
                Button btn = (Button)sender;

                if (btn == ButtonSaveNewBalance)
                {
                    if (_currentEditCustomer != null)
                    {
                        float newBalance;
                        if (float.TryParse(LabelNewBalanceShow.Text, out newBalance))
                        {
                            _currentEditCustomer = _controller.ChangeBalanceofCustomer(_currentEditCustomer, newBalance);
                            UpdateBalanceTab(_currentEditCustomer);
                            UpdateEditItemsTab(_currentEditCustomer);
                        }
                    }
                }
                else if (btn == ButtonCancelNewBalance)
                {
                    _currentEditCustomer = null;
                    ClearTextBoxesEditBalanceItems();
                }

                else if (btn == ButtonAddNewAmount)
                {
                    if (_currentEditCustomer != null && ButtonSaveNewBalance.Enabled == true)
                    {
                        float newAmount = _currentEditCustomer._MoneyBalance + float.Parse(TextBoxNewAmount.Text);
                        _currentEditCustomer._MoneyBalance = newAmount;
                        LabelNewBalanceShow.Text           = _currentEditCustomer._MoneyBalance.ToString();
                    }
                }
                else if (btn == ButtonSubNewAmount)
                {
                    if (_currentEditCustomer != null)
                    {
                        if (_currentEditCustomer != null && ButtonSaveNewBalance.Enabled == true)
                        {
                            float newAmount = _currentEditCustomer._MoneyBalance - float.Parse(TextBoxNewAmount.Text);;
                            _currentEditCustomer._MoneyBalance = newAmount;
                            LabelNewBalanceShow.Text           = _currentEditCustomer._MoneyBalance.ToString();
                        }
                    }
                }
                else if (btn == ButtonSaveEditItems)
                {
                    if (_currentEditCustomer != null)
                    {
                        EMailAddress eMailAddress = new EMailAddress(TextBoxEMailEditItems.Text);
                        Address      address      = new Address(TextBoxStreetEditItems.Text, int.Parse(TextBoxEditStreetNumberItems.Text),
                                                                int.Parse(TextBoxPostcodeEditItems.Text), TextBoxCityEditItems.Text, TextBoxCountryEditItems.Text);

                        if (address != null && eMailAddress.Address != string.Empty && CheckforLettersonly(TextBoxLastNameEditItems.Text))
                        {
                            _currentEditCustomer = _controller.EditCustomeritems(_currentEditCustomer,
                                                                                 TextBoxLastNameEditItems.Text, eMailAddress, address);
                            UpdateBalanceTab(_currentEditCustomer);
                            UpdateEditItemsTab(_currentEditCustomer);
                        }
                    }
                }
                else if (btn == ButtonCancelEditItems)
                {
                    _currentEditCustomer = null;
                    ClearTextBoxesEditBalanceItems();
                }
                else if (btn == ButtonDeleteCustomer)
                {
                    if (_currentEditCustomer._MoneyBalance == 0)
                    {
                        _controller.DeleteCustomer(_currentEditCustomer);
                    }
                    else
                    {
                        MessageBox.Show("The MoneyBalance of the customer needs to be 0 EURO");
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Returns the Customer-Data. Format: CustomerNumber;FirstName;LastName;EMail;DateOfChange;MoneyBalance;Address
        /// </summary>
        /// <param name="path">File-path</param>
        /// <returns></returns>
        public List <Customer> readCSV(string path)
        {
            StreamReader myReader = StreamReader.Null;

            try
            {
                myReader = new StreamReader(path, Encoding.Unicode);
                string          textLine = string.Empty;
                string[]        splitLine;
                List <string[]> customerDataAsString = new List <string[]>();
                List <Customer> customerData         = new List <Customer>();

                if (File.Exists(path))
                {
                    while (!myReader.EndOfStream)
                    {
                        textLine = myReader.ReadLine();
                        if (textLine != "")
                        {
                            splitLine = textLine.Split(';');
                            customerDataAsString.Add(splitLine);
                        }
                    }
                }

                // Start at 1 - Line1 = Header
                for (int i = 1; i < customerDataAsString.Count; i++)
                {
                    string[] data = customerDataAsString[i];

                    int          customerNumber       = Convert.ToInt16(data[0]);
                    string       firstName            = data[1];
                    string       lastName             = data[2];
                    string       eMailAddressString   = data[3].ToString();
                    EMailAddress eMailAddress         = new EMailAddress(eMailAddressString);
                    DateTime     DateOfChange         = Convert.ToDateTime(data[4]);
                    string       moneyBalanceAsString = data[5];
                    float        moneyBalance;
                    float.TryParse(moneyBalanceAsString, out moneyBalance);


                    Address address = Address.ConvertStringToAddress(data[6]);


                    Customer myCustomer = new Customer(firstName, lastName, eMailAddress, customerNumber, moneyBalance, DateOfChange, address);

                    customerData.Add(myCustomer);
                }

                return(customerData);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The process cannot access the file"))
                {
                    MessageBox.Show("The file you are importing is open.", "Import Account", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }

                return(null);
            }
            finally
            {
                myReader.Close();
            }
        }