Ejemplo n.º 1
0
        private void UpdateBranchButton_Click(object sender, EventArgs e)
        {
            string tempName;

            try
            {
                if (currentBransch == null)
                {
                    lblresponse.Text = "No branch chosen";
                    return;
                }

                tempName = txtBranchName.Text;
                tempName = tempName.Trim();
                if (String.IsNullOrEmpty(tempName))
                {
                    lblresponse.Text = "Name field is empty";
                    return;
                }
                currentBransch.Name = txtBranchName.Text;

                BranschController.UpdateBransch(currentBransch);
                FillListWithAllBranches();
                lblresponse.Text = "Branch updated";
            }
            catch (Exception ex)
            {
                lblresponse.Text = ErrorHandlern.HandleExceptions(ex);
            }
        }
Ejemplo n.º 2
0
        private void updateCmbCompanyBranch()
        {
            DataTable branches = BranschController.ReadAll();

            for (int i = 0; i < branches.Rows.Count; i++)
            {
                cmbCompanyBranch.Items.Add(branches.Rows[i]["BranschId"]);
            }
        }
Ejemplo n.º 3
0
 private void dgvBranches_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         int branchId = Int32.Parse(dgvBranches.CurrentRow.Cells[0].Value.ToString());
         currentBransch                = BranschController.FindById(branchId);
         txtBranchId.Text              = currentBransch.BranschId.ToString();
         txtBranchName.Text            = currentBransch.Name;
         dgvBranchCompanies.DataSource = BranschController.ReadAllCompaniesForABransch(currentBransch);
     }
     catch (Exception ex)
     {
         lblresponse.Text = ErrorHandlern.HandleExceptions(ex);
     }
 }
Ejemplo n.º 4
0
        private void CreateBranchButton_Click(object sender, EventArgs e)
        {
            try
            {
                String tempId = txtBranchId.Text;
                tempId = tempId.Trim();
                if (String.IsNullOrEmpty(tempId))
                {
                    lblresponse.Text = "Id box is empty";
                    return;
                }

                Bransch bransch = new Bransch();
                bransch.BranschId = Int32.Parse(tempId);

                bransch.Name = txtBranchName.Text;
                bransch.Name = bransch.Name.Trim();
                if (bransch.BranschId < 0)
                {
                    lblresponse.Text = "Id is less than 0";
                    return;
                }
                if (String.IsNullOrEmpty(bransch.Name))
                {
                    lblresponse.Text = "You need to write a name";
                    return;
                }

                bool success = BranschController.CreateBransch(bransch);
                FillListWithAllBranches();

                if (success)
                {
                    lblresponse.Text = "Bransch Created";
                }
                else
                {
                    lblresponse.Text = "Failed to create Bransch";
                }
            }
            catch (Exception ex)
            {
                lblresponse.Text = ErrorHandlern.HandleExceptions(ex);
            }
            FillListWithAllEmployees();
        }
Ejemplo n.º 5
0
        private void DeleteBranchButton_Click(object sender, EventArgs e)
        {
            if (currentBransch == null)
            {
                lblresponse.Text = "No branch chosen";
                return;
            }
            bool deleted = BranschController.DeleteBransch(currentBransch.BranschId);

            if (deleted)
            {
                lblresponse.Text = "branch deleted";
            }
            else
            {
                lblresponse.Text = "branch not deleted";
            }
            FillListWithAllBranches();
        }
Ejemplo n.º 6
0
 private void FillListWithAllBranches()
 {
     dgvBranches.DataSource = BranschController.ReadAll();
 }