Ejemplo n.º 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            // Search for the wallet id.
            if (!string.IsNullOrEmpty(txtWallet.Text))
            {
                if ((serviceLayer.GetListenerById(int.Parse(txtWallet.Text)) != null))
                {
                    // Are we in delete mode?
                    if (theType == FindListenerFormType.DeleteForm)
                    {
                        deleteListenerLocal(int.Parse(txtWallet.Text));
                        this.Close();
                    }

                    // Are we in delete mode?
                    if (theType == FindListenerFormType.EditForm)
                    {
                        My.MyProject.Forms.formEdit.Show();
                        My.MyProject.Forms.formEdit.setupForm(serviceLayer.GetListenerById(int.Parse(txtWallet.Text)));
                        this.Close();
                    }

                    if (theType == FindListenerFormType.StopSending)
                    {
                        My.MyProject.Forms.formStopSending.Show();
                        My.MyProject.Forms.formStopSending.setupForm(serviceLayer.GetListenerById(int.Parse(txtWallet.Text)));
                        this.Close();
                    }

                    if (theType == FindListenerFormType.PrintLabels)
                    {
                        My.MyProject.Forms.formChoosePrintPoint.Show();
                        My.MyProject.Forms.formChoosePrintPoint.SetupForm(serviceLayer.GetListenerById(int.Parse(txtWallet.Text)));
                        this.Close();
                    }

                    if (theType == FindListenerFormType.AdjustStock)
                    {
                        FormAdjustStockLevels formAdjustStock = new FormAdjustStockLevels();
                        formAdjustStock.setListener(serviceLayer.GetListenerById(int.Parse(txtWallet.Text)));
                        formAdjustStock.Show();
                        this.Close();
                    }

                    if (theType == FindListenerFormType.PrintCollector)
                    {
                        DialogResult result  = MessageBox.Show("Are you printing this form for a deleted listener? (Select No if its a new one)", ModuleGeneric.getAppShortName(), MessageBoxButtons.YesNo);
                        bool         deleted = (result == DialogResult.Yes);

                        My.MyProject.Forms.formPrintCollectionForm.Show();
                        My.MyProject.Forms.formPrintCollectionForm.setupForm(serviceLayer.GetListenerById(int.Parse(txtWallet.Text)), deleted);
                        this.Close();
                    }
                }
                else
                {
                    Interaction.MsgBox("Could not find a listener with the following Wallet number: " + txtWallet.Text);
                }
            }

            // Search for the name / surname.
            if (!(string.IsNullOrEmpty(txtForename.Text) & string.IsNullOrEmpty(txtSurname.Text)))
            {
                List <Listener> theListeners = new List <Listener>();
                theListeners = serviceLayer.GetListenersByName(txtForename.Text, txtSurname.Text);

                if ((theListeners.Count > 0))
                {
                    // If there is just one duplicate.
                    if (theListeners.Count == 1)
                    {
                        // Look up data.
                        Listener theListener = theListeners[0];

                        // Delete form.
                        if (theType == FindListenerFormType.DeleteForm)
                        {
                            string dataString = null;
                            dataString = Listener.FormatListenerData(theListener);
                            deleteListenerLocal(theListener.Wallet);
                            this.Close();
                        }

                        // Edit form.
                        if (theType == FindListenerFormType.EditForm)
                        {
                            My.MyProject.Forms.formEdit.Show();
                            My.MyProject.Forms.formEdit.setupForm(theListener);
                            this.Close();
                        }
                        if (theType == FindListenerFormType.StopSending)
                        {
                            My.MyProject.Forms.formStopSending.Show();
                            My.MyProject.Forms.formStopSending.setupForm(theListener);
                            this.Close();
                        }
                        if (theType == FindListenerFormType.PrintLabels)
                        {
                            My.MyProject.Forms.formChoosePrintPoint.Show();
                            My.MyProject.Forms.formChoosePrintPoint.SetupForm(theListener);
                            this.Close();
                        }
                        if (theType == FindListenerFormType.AdjustStock)
                        {
                            FormAdjustStockLevels formAdjustStock = new FormAdjustStockLevels();
                            formAdjustStock.setListener(serviceLayer.GetListenerById(int.Parse(txtWallet.Text)));
                            formAdjustStock.Show();
                            this.Close();
                        }
                        if (theType == FindListenerFormType.PrintCollector)
                        {
                            DialogResult result  = MessageBox.Show("Are you printing this form for a deleted listener? (Select No if its a new one)", ModuleGeneric.getAppShortName(), MessageBoxButtons.YesNo);
                            bool         deleted = (result == DialogResult.Yes);

                            My.MyProject.Forms.formPrintCollectionForm.Show();
                            My.MyProject.Forms.formPrintCollectionForm.setupForm(theListener, deleted);
                            this.Close();
                        }
                    }
                    else
                    {
                        // If there are more than 1 duplicate.
                        My.MyProject.Forms.formDuplicates.Show();
                        if (theType == FindListenerFormType.DeleteForm)
                        {
                            My.MyProject.Forms.formDuplicates.setupForm(FormDuplicates.DuplicateFormType.DeleteForm);
                        }
                        if (theType == FindListenerFormType.EditForm)
                        {
                            My.MyProject.Forms.formDuplicates.setupForm(FormDuplicates.DuplicateFormType.EditForm);
                        }
                        if (theType == FindListenerFormType.StopSending)
                        {
                            My.MyProject.Forms.formDuplicates.setupForm(FormDuplicates.DuplicateFormType.StopSending);
                        }
                        if (theType == FindListenerFormType.PrintLabels)
                        {
                            My.MyProject.Forms.formDuplicates.setupForm(FormDuplicates.DuplicateFormType.PrintLabels);
                        }
                        if (theType == FindListenerFormType.PrintCollector)
                        {
                            My.MyProject.Forms.formDuplicates.setupForm(FormDuplicates.DuplicateFormType.PrintCollector);
                        }
                        if (theType == FindListenerFormType.AdjustStock)
                        {
                            My.MyProject.Forms.formDuplicates.setupForm(FormDuplicates.DuplicateFormType.AdjustStock);
                        }
                        foreach (Listener tListener in theListeners)
                        {
                            My.MyProject.Forms.formDuplicates.addDuplicate(tListener);
                        }
                        this.Close();
                    }
                }
                else
                {
                    Interaction.MsgBox("Could not find any listeners with the Forename and Surname provided.");
                }
            }
        }
Ejemplo n.º 2
0
        // Dynamic button depending on form setup.
        private void btnDynamic_Click(object sender, EventArgs e)
        {
            // Add Form
            if (theFormType == DuplicateFormType.AddForm)
            {
                My.MyProject.Forms.formAddFull.Show();

                // Use subitems 1, 2, and 3 as they are Title, Forename and Surname.
                My.MyProject.Forms.formAddFull.comboTitle.SelectedItem = lstDuplicates.Items[0].SubItems[1].Text;
                My.MyProject.Forms.formAddFull.txtSurname.Text         = lstDuplicates.Items[0].SubItems[2].Text;
                My.MyProject.Forms.formAddFull.txtForename.Text        = lstDuplicates.Items[0].SubItems[3].Text;
                this.Close();
            }

            // Delete Form
            if (theFormType == DuplicateFormType.DeleteForm)
            {
                // Do we have a selected item?
                if ((lstDuplicates.FocusedItem != null))
                {
                    int theIndex = 0;
                    theIndex = lstDuplicates.FocusedItem.Index;

                    // First sub item is wallet number.
                    int walletNumb = 0;
                    walletNumb = int.Parse(lstDuplicates.Items[theIndex].SubItems[0].Text);

                    string dataString = null;
                    dataString = Listener.FormatListenerData(serviceLayer.GetListenerById(walletNumb));

                    // Show prompt.
                    DialogResult result = MessageBox.Show("Are you sure you wish to delete the following listener?" + Environment.NewLine + Environment.NewLine + dataString + Environment.NewLine + "Press [Y] to confirm or [N] to cancel.", ModuleGeneric.getAppShortName(), MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        string myReason       = Interaction.InputBox("Please enter a reason for deletion", "S.B.T.N.A.", "");
                        bool   resultofdelete = false;

                        // Check if the delete was a success.
                        resultofdelete = serviceLayer.SoftDeleteListener(serviceLayer.GetListenerById(walletNumb), myReason);
                        if (resultofdelete)
                        {
                            Interaction.MsgBox("Listener deleted successfully.");
                            lstDuplicates.Items[theIndex].Remove();

                            MessageBox.Show("You should remove all wallets including the magazine wallet" + Environment.NewLine + "from stock for Wallet number " + walletNumb + ".", ModuleGeneric.getAppShortName(), MessageBoxButtons.OK);
                        }
                        else
                        {
                            Interaction.MsgBox("Error deleting listener.");
                        }
                        this.Close();
                    }
                }
            }

            // Edit Form
            if (theFormType == DuplicateFormType.EditForm)
            {
                // Do we have a selected item?
                if ((lstDuplicates.FocusedItem != null))
                {
                    int theIndex = 0;
                    theIndex = lstDuplicates.FocusedItem.Index;

                    // First sub item is wallet number.
                    int walletNumb = 0;
                    walletNumb = int.Parse(lstDuplicates.Items[theIndex].SubItems[0].Text);

                    My.MyProject.Forms.formEdit.Show();
                    My.MyProject.Forms.formEdit.setupForm(serviceLayer.GetListenerById(walletNumb));
                    this.Close();
                }
            }

            // StopSending form
            if (theFormType == DuplicateFormType.StopSending)
            {
                // Do we have a selected item?
                if ((lstDuplicates.FocusedItem != null))
                {
                    int theIndex = 0;
                    theIndex = lstDuplicates.FocusedItem.Index;

                    // First sub item is wallet number.
                    int walletNumb = 0;
                    walletNumb = int.Parse(lstDuplicates.Items[theIndex].SubItems[0].Text);

                    My.MyProject.Forms.formStopSending.Show();
                    My.MyProject.Forms.formStopSending.setupForm(serviceLayer.GetListenerById(walletNumb));
                    this.Close();
                }
            }

            // Print labels form.
            if (theFormType == DuplicateFormType.PrintLabels)
            {
                // Do we have a selected item?
                if ((lstDuplicates.FocusedItem != null))
                {
                    int theIndex = 0;
                    theIndex = lstDuplicates.FocusedItem.Index;

                    // First sub item is wallet number.
                    int walletNumb = 0;
                    walletNumb = int.Parse(lstDuplicates.Items[theIndex].SubItems[0].Text);

                    My.MyProject.Forms.formChoosePrintPoint.Show();
                    My.MyProject.Forms.formChoosePrintPoint.SetupForm(serviceLayer.GetListenerById(walletNumb));
                    this.Close();
                }
            }

            if (theFormType == DuplicateFormType.PrintCollector)
            {
                // Do we have a selected item?
                if ((lstDuplicates.FocusedItem != null))
                {
                    int theIndex = 0;
                    theIndex = lstDuplicates.FocusedItem.Index;

                    // First sub item is wallet number.
                    int walletNumb = 0;
                    walletNumb = int.Parse(lstDuplicates.Items[theIndex].SubItems[0].Text);

                    DialogResult result  = MessageBox.Show("Are you printing this form for a deleted listener? (Select No if its a new one)", ModuleGeneric.getAppShortName(), MessageBoxButtons.YesNo);
                    bool         deleted = (result == DialogResult.Yes);

                    My.MyProject.Forms.formPrintCollectionForm.Show();
                    My.MyProject.Forms.formPrintCollectionForm.setupForm(serviceLayer.GetListenerById(walletNumb), deleted);
                    this.Close();
                }
            }

            if (theFormType == DuplicateFormType.AdjustStock)
            {
                // Do we have a selected item?
                if ((lstDuplicates.FocusedItem != null))
                {
                    int theIndex = 0;
                    theIndex = lstDuplicates.FocusedItem.Index;

                    // First sub item is wallet number.
                    int walletNumb = 0;
                    walletNumb = int.Parse(lstDuplicates.Items[theIndex].SubItems[0].Text);

                    FormAdjustStockLevels formAdjustStock = new FormAdjustStockLevels();
                    formAdjustStock.setListener(serviceLayer.GetListenerById(walletNumb));
                    formAdjustStock.Show();
                    this.Close();
                }
            }
        }