コード例 #1
0
        private void btnSaveSalePerson_Click(object sender, EventArgs e)
        {
            if (cmbEmployeeName.Items.Count == 0)
            {
                btnSaveSalePerson.Enabled = false;
            }
            else
            {
                btnSaveSalePerson.Enabled = true;
            }
            if (cmbEmployeeName.SelectedIndex == 0)
            {
                MessageBox.Show("Pleae select an employee", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            SalesPerson sp = new SalesPerson();

            try
            {
                if (cmbEmployeeName.Items.Count > 0 && cmbEmployeeName.SelectedValue != null)
                {
                    sp.SalesPersonID = Int32.Parse(cmbEmployeeName.SelectedValue.ToString());
                }
                int index = cmbEmployeeName.SelectedIndex;

                if (txtSalesQuota.Text.Trim() != String.Empty)
                {
                    sp.SalesQuota = decimal.Parse(txtSalesQuota.Text);
                }
                if (txtCommissionPct.Text.Trim() != String.Empty)
                {
                    sp.CommissionPct = decimal.Parse(txtCommissionPct.Text);
                }
                if (txtBounus.Text.Trim() != string.Empty)
                {
                    sp.Bonus = decimal.Parse(txtBounus.Text);
                }
                sp.AddSalesPerson(sp);
                MessageBox.Show("Record Saved Successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                RefreshForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "MICS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                sp = null;
            }
        }