Exemplo n.º 1
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (cboPoint.SelectedValue == String.Empty)
                {
                    int ownerID = 0;

                    if (cboOwner.SelectedValue == string.Empty)
                    {
                        // Create a new client customer for the point owner (this can be upgraded to client in the future).
                        Entities.Organisation organisation = new Entities.Organisation();
                        organisation.OrganisationName = cboOwner.Text;
                        organisation.OrganisationType = eOrganisationType.ClientCustomer;
                        Facade.IOrganisation  facOrganisation = new Facade.Organisation();
                        Entities.FacadeResult result          = facOrganisation.Create(organisation, ((Entities.CustomPrincipal)Page.User).UserName);
                        if (result.Success)
                        {
                            ownerID = result.ObjectId;
                        }
                        else
                        {
                            // Organisation has already been created by someone else between validation and this call (unlikely)
                            ownerID = facOrganisation.GetForName(cboOwner.Text).IdentityId;
                        }
                    }
                    else
                    {
                        ownerID = int.Parse(cboOwner.SelectedValue);
                    }

                    // Set the point type, organisation, town, and name for the new point
                    switch ((eInstructionType)m_instruction.InstructionTypeId)
                    {
                    case eInstructionType.Drop:
                        Session[wizard.C_POINT_TYPE] = ePointType.Deliver;
                        Session[wizard.C_POINT_FOR]  = m_instruction.ClientsCustomerIdentityID;
                        break;

                    case eInstructionType.Load:
                        Session[wizard.C_POINT_TYPE] = ePointType.Collect;
                        Session[wizard.C_POINT_FOR]  = ownerID;
                        break;
                    }

                    Session[wizard.C_INSTRUCTION_INDEX] = m_instructionIndex;
                    Session[wizard.C_POINT_NAME]        = cboPoint.Text;
                    Session[wizard.C_TOWN_ID]           = Convert.ToInt32(cboTown.SelectedValue);

                    // The point name must be unique for this client
                    bool          foundPointName = false;
                    Facade.IPoint facPoint       = new Facade.Point();
                    DataSet       pointNames     = facPoint.GetAllForOrganisation((int)Session[wizard.C_POINT_FOR], ePointType.Any, cboPoint.Text);
                    foreach (DataRow row in pointNames.Tables[0].Rows)
                    {
                        if (((string)row["Description"]) == cboPoint.Text)
                        {
                            foundPointName = true;
                        }
                    }

                    if (foundPointName)
                    {
                        pnlCreateNewPoint.Visible = true;
                    }
                    else
                    {
                        // Allow the user to create the new point
                        GoToStep("CNP");
                    }
                }
                else
                {
                    int pointId = Convert.ToInt32(cboPoint.SelectedValue);

                    if (m_isUpdate)
                    {
                        if (m_instruction.InstructionID == 0)
                        {
                            // Adding a new instruction

                            Facade.IPoint  facPoint      = new Facade.Point();
                            Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                            // Add the collect drop point information
                            m_instruction.Point         = selectedPoint;
                            m_instruction.PointID       = selectedPoint.PointId;
                            m_instruction.InstructionID = m_instruction.InstructionID;

                            Session[wizard.C_INSTRUCTION] = m_instruction;
                        }
                        else
                        {
                            if (pointId != m_instruction.PointID)
                            {
                                Facade.IPoint  facPoint      = new Facade.Point();
                                Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                                m_instruction.Point   = selectedPoint;
                                m_instruction.PointID = selectedPoint.PointId;
                            }

                            // Altering an existing instruction
                            // Cause the first collectdrop to be displayed.
                            if (m_instruction.CollectDrops.Count > 0)
                            {
                                Session[wizard.C_COLLECT_DROP]       = m_instruction.CollectDrops[0];
                                Session[wizard.C_COLLECT_DROP_INDEX] = 0;
                            }
                        }
                    }
                    else
                    {
                        if (m_isAmendment)
                        {
                            if (pointId != m_instruction.PointID)
                            {
                                Facade.IPoint  facPoint      = new Facade.Point();
                                Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                                m_instruction.Point   = selectedPoint;
                                m_instruction.PointID = selectedPoint.PointId;
                            }

                            // Cause the first point to be displayed.
                            if (m_instruction.CollectDrops.Count > 0)
                            {
                                Session[wizard.C_COLLECT_DROP]       = m_instruction.CollectDrops[0];
                                Session[wizard.C_COLLECT_DROP_INDEX] = 0;
                            }

                            Session[wizard.C_INSTRUCTION] = m_instruction;
                        }
                        else
                        {
                            Facade.IPoint  facPoint      = new Facade.Point();
                            Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                            // Add the collect drop point information
                            m_instruction.Point         = selectedPoint;
                            m_instruction.PointID       = selectedPoint.PointId;
                            m_instruction.InstructionID = m_instruction.InstructionID;

                            Session[wizard.C_INSTRUCTION] = m_instruction;
                        }
                    }

                    GoToStep("PD");
                }
            }
        }
Exemplo n.º 2
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (cboPoint.SelectedValue == String.Empty)
                {
                    // Set the point type, organisation, town, and name for the new point
                    switch ((eInstructionType)m_instruction.InstructionTypeId)
                    {
                    case eInstructionType.Drop:
                        Session[wizard.C_POINT_TYPE] = ePointType.Deliver;
                        Session[wizard.C_POINT_FOR]  = m_instruction.ClientsCustomerIdentityID;
                        break;

                    case eInstructionType.Load:
                        Session[wizard.C_POINT_TYPE] = ePointType.Collect;
                        Session[wizard.C_POINT_FOR]  = m_job.IdentityId;
                        break;
                    }

                    Session[wizard.C_POINT_NAME] = cboPoint.Text;
                    Session[wizard.C_TOWN_ID]    = Convert.ToInt32(cboTown.SelectedValue);

                    // The point name must be unique for this client
                    bool          foundPointName = false;
                    Facade.IPoint facPoint       = new Facade.Point();
                    DataSet       pointNames     = facPoint.GetAllForOrganisation((int)Session[wizard.C_POINT_FOR], ePointType.Any, cboPoint.Text);
                    foreach (DataRow row in pointNames.Tables[0].Rows)
                    {
                        if (((string)row["Description"]) == cboPoint.Text)
                        {
                            foundPointName = true;
                        }
                    }

                    if (foundPointName)
                    {
                        pnlCreateNewPoint.Visible = true;
                    }
                    else
                    {
                        // Allow the user to create the new point
                        GoToStep("CNP");
                    }
                }
                else
                {
                    int pointId = Convert.ToInt32(cboPoint.SelectedValue);

                    if (m_isUpdate)
                    {
                        if (m_instruction.InstructionID == 0)
                        {
                            // Adding a new instruction

                            Facade.IPoint  facPoint      = new Facade.Point();
                            Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                            // Add the collect drop point information
                            m_instruction.Point         = selectedPoint;
                            m_instruction.PointID       = selectedPoint.PointId;
                            m_instruction.InstructionID = m_instruction.InstructionID;

                            Session[wizard.C_INSTRUCTION] = m_instruction;
                        }
                        else
                        {
                            // Altering an existing instruction
                            // Cause the first collectdrop to be displayed.
                            if (m_instruction.CollectDrops.Count > 0)
                            {
                                Session[wizard.C_COLLECT_DROP]       = m_instruction.CollectDrops[0];
                                Session[wizard.C_COLLECT_DROP_INDEX] = 0;
                            }
                        }
                    }
                    else
                    {
                        if (m_isAmendment)
                        {
                            if (pointId != m_instruction.PointID)
                            {
                                Facade.IPoint  facPoint      = new Facade.Point();
                                Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                                m_instruction.Point   = selectedPoint;
                                m_instruction.PointID = selectedPoint.PointId;
                            }

                            // Cause the first point to be displayed.
                            if (m_instruction.CollectDrops.Count > 0)
                            {
                                Session[wizard.C_COLLECT_DROP]       = m_instruction.CollectDrops[0];
                                Session[wizard.C_COLLECT_DROP_INDEX] = 0;
                            }

                            Session[wizard.C_INSTRUCTION] = m_instruction;
                        }
                        else
                        {
                            Facade.IPoint  facPoint      = new Facade.Point();
                            Entities.Point selectedPoint = facPoint.GetPointForPointId(pointId);

                            // Add the collect drop point information
                            m_instruction.Point         = selectedPoint;
                            m_instruction.PointID       = selectedPoint.PointId;
                            m_instruction.InstructionID = m_instruction.InstructionID;

                            Session[wizard.C_INSTRUCTION] = m_instruction;
                        }
                    }

                    GoToStep("PD");
                }
            }
        }