Example #1
0
        void grdDepots_InsertCommand(object source, GridCommandEventArgs e)
        {
            // Ensure that all points are created.
            Page.Validate("PointSavedValidation");
            bool pointsValid = Page.IsValid;

            if (pointsValid)
            {
                //Find the Point control and Code textbox within the grid row
                Orchestrator.WebUI.Controls.Point ucPoint = (Orchestrator.WebUI.Controls.Point)e.Item.FindControl("ucPoint");
                TextBox     txtCode          = (TextBox)e.Item.FindControl("txtCode");
                TextBox     txtHubIdentifier = (TextBox)e.Item.FindControl("txtHubIdentifier");
                RadComboBox cboPrintOnLabel  = (RadComboBox)e.Item.FindControl("cboPrintOnLabel");
                Label       txtCodeProblem   = (Label)e.Item.FindControl("txtCodeProblem");
                int         identityId       = int.Parse(cboNetworks.SelectedValue);

                using (var uow = DIContainer.CreateUnitOfWork())
                {
                    var depotRepo = DIContainer.CreateRepository <Repositories.IDepotRepository>(uow);
                    var depot     = new Models.Depot();

                    // Check if any Depots already have this Depot Code for this Network
                    var depotCodeCount = depotRepo.GetAll().Count(d => d.NetworkIdentityID == identityId &&
                                                                  d.Code == txtCode.Text);

                    if (depotCodeCount > 0)
                    {
                        // Code already exists, inform the user.
                        txtCodeProblem.Visible = true;
                        e.Canceled             = true;
                    }
                    else
                    {
                        txtCodeProblem.Visible  = false;
                        depot.Code              = txtCode.Text;
                        depot.PointID           = ucPoint.PointID;
                        depot.HubIdentifier     = txtHubIdentifier.Text;
                        depot.PrintOnLabel      = cboPrintOnLabel.Text == "Yes";
                        depot.NetworkIdentityID = identityId;

                        depotRepo.Add(depot);
                        uow.SaveChanges();
                    }
                }
            }
            else
            {
                e.Canceled = true;
            }
        }
Example #2
0
        void grdDepots_UpdateCommand(object source, GridCommandEventArgs e)
        {
            // Ensure that all points are created.
            Page.Validate("PointSavedValidation");
            bool pointsValid = Page.IsValid;

            if (pointsValid)
            {
                // Get all the information out of the Grid Row
                Orchestrator.WebUI.Controls.Point ucPoint = (Orchestrator.WebUI.Controls.Point)e.Item.FindControl("ucPoint");
                TextBox     txtCode          = (TextBox)e.Item.FindControl("txtCode");
                TextBox     txtHubIdentifier = (TextBox)e.Item.FindControl("txtHubIdentifier");
                RadComboBox cboPrintOnLabel  = (RadComboBox)e.Item.FindControl("cboPrintOnLabel");
                Label       txtCodeProblem   = (Label)e.Item.FindControl("txtCodeProblem");
                int         identityId       = int.Parse(cboNetworks.SelectedValue);
                int         depotId          = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DepotId"];

                using (var uow = DIContainer.CreateUnitOfWork())
                {
                    var depotRepo = DIContainer.CreateRepository <Repositories.IDepotRepository>(uow);
                    var depot     = depotRepo.Find(depotId);

                    // Check if there is a Depot which already has this code for this Network (and which isn't THIS record!).
                    var depotCodeCount = depotRepo.GetAll().Count(d => d.NetworkIdentityID == identityId &&
                                                                  d.Code == txtCode.Text &&
                                                                  d.DepotID != depot.DepotID);

                    if (depotCodeCount > 0)
                    {
                        // Code already in use, show the error on-screen.
                        txtCodeProblem.Visible = true;
                        e.Canceled             = true;
                    }
                    else
                    {
                        txtCodeProblem.Visible = false;
                        depot.Code             = txtCode.Text;
                        depot.PointID          = ucPoint.PointID;
                        depot.HubIdentifier    = txtHubIdentifier.Text;
                        depot.PrintOnLabel     = cboPrintOnLabel.Text == "Yes";
                        uow.SaveChanges();
                    }
                }
            }
            else
            {
                e.Canceled = true;
            }
        }
Example #3
0
        protected void grdDepots_ItemDataBound(object sender, GridItemEventArgs e)
        {
            //If the Grid Item is the EditForm and it is being shown
            if (e.Item.ItemType == GridItemType.EditFormItem && e.Item.IsInEditMode)
            {
                //Get the Point and  Code controls from the EditForm
                Orchestrator.WebUI.Controls.Point ucPoint = (Orchestrator.WebUI.Controls.Point)e.Item.FindControl("ucPoint");
                TextBox     txtCode          = (TextBox)e.Item.FindControl("txtCode");
                TextBox     txtHubIdentifier = (TextBox)e.Item.FindControl("txtHubIdentifier");
                RadComboBox cboPrintOnLabel  = (RadComboBox)e.Item.FindControl("cboPrintOnLabel");

                //If the EditForm is being shown for a new Depot default the values
                if (e.Item.OwnerTableView.IsItemInserted)
                {
                    //Set the default values for a new Depot
                    txtCode.Text                  = string.Empty;
                    txtHubIdentifier.Text         = string.Empty;
                    cboPrintOnLabel.SelectedIndex = 1;
                    ucPoint.Reset();
                }
                else
                {
                    int depotId = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["DepotId"];

                    using (var uow = DIContainer.CreateUnitOfWork())
                    {
                        var depotRepo = DIContainer.CreateRepository <Repositories.IDepotRepository>(uow);
                        var depot     = depotRepo.Find(depotId);

                        Facade.Point   facPoint = new Orchestrator.Facade.Point();
                        Entities.Point point    = facPoint.GetPointForPointId(depot.PointID);
                        ucPoint.SelectedPoint = point;

                        txtCode.Text          = depot.Code;
                        txtHubIdentifier.Text = depot.HubIdentifier;

                        if (depot.PrintOnLabel == null || depot.PrintOnLabel == false)
                        {
                            cboPrintOnLabel.SelectedIndex = 1;
                        }
                        else
                        {
                            cboPrintOnLabel.SelectedIndex = 0;
                        }
                    }
                }
            }
        }