コード例 #1
0
 /**
   * This method defines what happens on form load
   */
 private void EditSalesman_Load(object sender, EventArgs e)
 {
     try
     {
         changedSales = GlobalVariables.currentSalesmanDetails.sales;
         changedRegion = GlobalVariables.currentSalesmanDetails.region;
         firstCountry = GlobalVariables.currentSalesmanDetails.country;
         StreamReader obgStrReader = new StreamReader("CountryComboList.txt");//available in assignment2/bin/debug
         string line = obgStrReader.ReadLine();
         while (line != null)
         {
             countryCombobox.Items.Add(line);
             line = obgStrReader.ReadLine();//adding items to como box
         }
         populateform();//populating form
         editedSalesman = GlobalVariables.currentSalesmanDetails;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:" + ex.Message);
     }
 }
コード例 #2
0
        /**
         * This method defines what happens when the add salesman button is pressed
         */
        private void btnAddSalesman_Click(object sender, EventArgs e)
        {
            try
            {
                var val = new SearchAndValidation();
                if (string.IsNullOrEmpty(txtTotalSales.Text))
                {
                    txtTotalSales.Text = "0";
                }
                if (val.isSalesMan(salesmanList, Convert.ToInt32(txtEmpID.Text)))
                {
                    errorProvider1.SetError(txtEmpID, "Employee ID already exists");
                    txtEmpID.Focus();
                    passedValidation = false;
                }

                if (passedValidation)
                {
                    var currentDetail = new TeamDetails();
                    currentDetail.employeeID = Convert.ToInt32(txtEmpID.Text);
                    currentDetail.firstName = this.txtFirstName.Text;
                    currentDetail.surname = this.txtSurname.Text;
                    currentDetail.dateOfBirth = this.dateTimePicker1.Value.ToShortDateString();
                    currentDetail.email = this.txtEmail.Text;
                    currentDetail.mobilePhoneNumber = this.txtMobileNum.Text;
                    currentDetail.officeNumber = this.txtOfficeNum.Text;
                    currentDetail.sales = Convert.ToInt32(this.txtTotalSales.Text);
                    currentDetail.streetNameAndNumber = this.txtStreetName1.Text;
                    currentDetail.streetNameAndNumber2 = this.txtStreetName2.Text;
                    currentDetail.city = this.txtCity.Text;
                    currentDetail.country = countryCombobox.SelectedItem.ToString();
                    currentDetail.teamName = string.Empty;
                    currentDetail.teamLeader = string.Empty;
                    currentDetail.teamSales = 0;
                    currentDetail.region = this.txtRegion.Text;
                    GlobalVariables.allSalesmenList.Add(currentDetail);
                }
                else
                {
                    throw new Exception("Input must be valid");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }