protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int result = 0;

            // Enter data into the salesman model
            ModelSalesman salesman = new ModelSalesman
            {
                SalesmanId = Convert.ToInt32(txtID.Text),
                Name       = txtSalesmanName.Text,
                City       = txtCity.Text,
                Commision  = float.Parse(txtCommission.Text)
            };

            BusinessLayer bl = new BusinessLayer();

            result = bl.EnterNewSalesman(salesman);

            if (result > 0)
            {
                lblResult.Text       = "Record inserted successfully";
                txtCity.Text         = string.Empty;
                txtCommission.Text   = string.Empty;
                txtSalesmanName.Text = string.Empty;
                txtID.Text           = string.Empty;
            }
            else
            {
                lblResult.ForeColor = System.Drawing.Color.Red;
                lblResult.Text      = "ERROR: There is something going wrong";
            }

            FillDataToGridView();
        }
Esempio n. 2
0
        public int InsertSalesman(ModelSalesman salesman)
        {
            _connectionString = ConfigurationManager.ConnectionStrings["InventoryConnectionString"].ConnectionString;
            _connection       = new SqlConnection(_connectionString);

            try
            {
                string     query = $"Insert Into Salesman (salesman_id, name, city, commision) Values ({salesman.SalesmanId}, '{salesman.Name}', '{salesman.City}', {salesman.Commision});";
                SqlCommand cmd   = new SqlCommand(query, _connection);
                _connection.Open();
                int result = cmd.ExecuteNonQuery();
                _connection.Close();
                cmd.Dispose();
                return(result);
            }
            catch (SqlException e)
            {
                return(0);

                throw new Exception(e.Message);
            }
        }
        public int EnterNewSalesman(ModelSalesman salesman)
        {
            DBAccess addSalesman = new DBAccess();

            return(addSalesman.InsertSalesman(salesman));
        }