Exemplo n.º 1
0
        private void SetRibbonButtons(RibbonMode mode)
        {
            bool isApproved;

            if (supplyID > 0)
            {
                using (var repository = new SupplyRepository())
                {
                    isApproved = repository.GetSupply(supplyID).IsApproved;
                }
            }

            else
            {
                isApproved = false;
            }

            switch (mode)
            {
            case RibbonMode.Listing:
                FilterButton.Enabled        = true;
                NewButton.Enabled           = true;
                EditButton.Enabled          = false;
                SaveButton.Enabled          = false;
                CancelButton.Enabled        = false;
                ApproveButton.Enabled       = false;
                AddSupplyItemButton.Enabled = false;
                break;

            case RibbonMode.Detail:
                FilterButton.Enabled         = false;
                NewButton.Enabled            = false;
                EditButton.Enabled           = !isApproved;
                SaveButton.Enabled           = false;
                CancelButton.Enabled         = false;
                ApproveButton.Enabled        = !isApproved;
                AddSupplyItemButton.Enabled  = !isApproved;
                SaveSupplyItemButton.Enabled = IsSupplyItemChanged;
                break;

            case RibbonMode.Edit:
                FilterButton.Enabled           = false;
                NewButton.Enabled              = false;
                EditButton.Enabled             = false;
                SaveButton.Enabled             = true;
                CancelButton.Enabled           = true;
                ApproveButton.Enabled          = false;
                AddSupplyItemButton.Enabled    = false;
                RemoveSupplyItemButton.Enabled = false;
                SaveSupplyItemButton.Enabled   = false;
                break;
            }
        }
Exemplo n.º 2
0
        private void ViewSupplyDetailTab(int id, bool isSupplyItemIncluded)
        {
            using (var repository = new SupplyRepository())
            {
                if (id > 0)
                {
                    IsWork     = false;
                    RibbonMode = RibbonMode.Detail;

                    ChangeControlsEnabled(DetailTab.Controls, false, false);

                    var supply = repository.GetSupply(id);

                    IDTextBox.Text            = supply.ID.ToString();
                    DeliveredDatePicker.Value = supply.Delivered;
                    SupplierNameTextBox.Text  = supply.SupplierName;
                    DescriptionTextBox.Text   = supply.Description;

                    if (isSupplyItemIncluded)
                    {
                        SupplyItemGrid.DataSource = repository.GetSupplyItems(id);
                        IsSupplyItemChanged       = false;
                        SupplyItemGrid.Enabled    = !supply.IsApproved;
                    }

                    SupplyTabControl.SelectedTab = DetailTab;

                    SupplyItemGrid.ClearSelection();
                }
                else
                {
                    IsWork     = true;
                    RibbonMode = RibbonMode.Edit;

                    ChangeControlsEnabled(DetailTab.Controls, true, true);

                    IDTextBox.Enabled = false;
                    IDTextBox.Text    = repository.GetNextSupplyID().ToString();

                    SupplyTabControl.SelectedTab = DetailTab;
                }
            }
        }
Exemplo n.º 3
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (!Validation.IsAllValid(Detail.Controls))
            {
                return;
            }

            using (var repository = new SupplyRepository())
            {
                if (supplyID > 0)
                {
                    var supply = repository.GetSupply(supplyID);

                    supply.Delivered    = DeliveredDatePicker.Value.Date;
                    supply.SupplierName = SupplierNameTextBox.Text;
                    supply.Description  = DescriptionTextBox.Text;

                    repository.UpdateSupply(supply);
                    repository.Commit();

                    supplyID = supply.ID;
                }
                else
                {
                    var supply = new Supply
                    {
                        ID           = (int)IDTextBox.Text.AsInt(),
                        Delivered    = DeliveredDatePicker.Value.Date,
                        SupplierName = SupplierNameTextBox.Text,
                        Description  = DescriptionTextBox.Text
                    };

                    repository.InsertSupply(supply);
                    repository.Commit();

                    supplyID = supply.ID;
                }
            }

            ViewSupplyDetailTab(supplyID, false);
        }