Example #1
0
        // Edit Entry Button
        private void editBtn_Click(object sender, EventArgs e)
        {
            if (TableDisplay.SelectedItems.Count > 0)
            {
                // Parse data to customer class
                Customer selectedIBT = new Customer();
                ListViewItem rowSelected = TableDisplay.SelectedItems[0]; // for less typing
                selectedIBT.status = rowSelected.Text;
                selectedIBT.customerName = rowSelected.SubItems[1].Text;
                selectedIBT.phoneNumber = rowSelected.SubItems[2].Text;
                selectedIBT.dateStarted = rowSelected.SubItems[3].Text;
                selectedIBT.sku = rowSelected.SubItems[4].Text;
                selectedIBT.description = rowSelected.SubItems[5].Text;

                if (rowSelected.SubItems.Count > 6)
                {
                    selectedIBT.requestedFrom = rowSelected.SubItems[6].Text;
                    if (rowSelected.SubItems.Count > 7)
                    {
                        selectedIBT.ibtNumber = rowSelected.SubItems[7].Text;
                        if (rowSelected.SubItems.Count > 8)
                        {
                            selectedIBT.ibtChecked = rowSelected.SubItems[8].Text;
                            if (rowSelected.SubItems.Count > 9)
                            {
                                selectedIBT.customerCalled = rowSelected.SubItems[9].Text;
                                if (rowSelected.SubItems.Count > 10)
                                    selectedIBT.collected = rowSelected.SubItems[10].Text;
                            }
                        }
                    }
                }

                // Open new form
                using (EditForm newEditForm = new EditForm(selectedIBT))
                {
                    DialogResult dResult = newEditForm.ShowDialog();
                    if (dResult == DialogResult.OK)
                    {
                        rowSelected.Text = newEditForm.status;
                        rowSelected.SubItems[1].Text = newEditForm.name;
                        rowSelected.SubItems[2].Text = newEditForm.contactNum;
                        rowSelected.SubItems[3].Text = newEditForm.dateStarted;
                        rowSelected.SubItems[4].Text = newEditForm.refNum;
                        rowSelected.SubItems[5].Text = newEditForm.description;
                        rowSelected.SubItems[6].Text = newEditForm.requested;
                        rowSelected.SubItems[7].Text = newEditForm.ibtNum;
                        rowSelected.SubItems[9].Text = newEditForm.called;
                        rowSelected.SubItems[10].Text = newEditForm.collected;
                    }
                }

                XUpdate();
                refreshButtonStates();
                TableDisplay.Select();
            }
            else
            {
                MessageBox.Show("You first need to select an IBT to edit.", 
                    "Error", 
                    MessageBoxButtons.OK, 
                    MessageBoxIcon.Information);
            }
        }
Example #2
0
        public EditForm(Customer customer)
        {
            InitializeComponent();

            // Load in details
            statusTxtBox.Text = customer.status;
            nameTxtBox.Text = customer.customerName;
            contactNumTxtBox.Text = customer.phoneNumber;
            dateStartTxtBox.Text = customer.dateStarted;
            skuTxtBox.Text = customer.sku;
            descriptionTxtBox.Text = customer.description;

            if (customer.requestedFrom != null && customer.requestedFrom != String.Empty)
                requestedTxtBox.Text = customer.requestedFrom;
            if (customer.ibtNumber != null && customer.ibtNumber != String.Empty)
                ibtNumTxtBox.Text = customer.ibtNumber;

            if (customer.customerCalled != null && customer.customerCalled != String.Empty)
            {
                if (Regex.IsMatch(customer.customerCalled, "YES", RegexOptions.IgnoreCase))
                {
                    calledCheckBox.Checked = true;
                    if (Regex.Match(customer.customerCalled, @"\d{2}(/|-)\d{2}(/|-)(\d{4}|\d{2})").Success)
                    {
                        calledDateTxtBox.Text = Regex.Match(customer.customerCalled, @"\d{2}(/|-)\d{2}(/|-)(\d{4}|\d{2})").Value;
                        calledCheckBox.Checked = true;
                    }
                    else
                    {
                        MessageBox.Show("The call date field is not written in the correct form.\nExample of how it should be written: Yes - dd/mm/year",
                            "Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        calledDateTxtBox.Text = customer.customerCalled;
                    }
                }
                else
                {
                    MessageBox.Show("The call date field is not written in the correct form.\nExample of how it should be written: Yes - dd/mm/year",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    calledDateTxtBox.Text = customer.customerCalled;
                }
            }

            if (customer.collected != null && customer.collected != String.Empty)
            {
                if (Regex.IsMatch(customer.collected, "COLLECTED", RegexOptions.IgnoreCase))
                {
                    collectedCheckBox.Checked = true;
                    if (Regex.Match(customer.collected, @"\d{2}(/|-)\d{2}(/|-)(\d{4}|\d{2})").Success)
                    {
                        collectedDateTxtBox.Text = Regex.Match(customer.collected, @"\d{2}(/|-)\d{2}(/|-)(\d{4}|\d{2})").Value;
                    }
                    else
                    {
                        MessageBox.Show("The collected field is not written in the correct format.\nExample of how it should be written: Collected - dd/mm/year",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                        collectedDateTxtBox.Text = customer.collected;
                    }
                }
                else
                {
                    MessageBox.Show("The collected field is not written in the correct format.\nExample of how it should be written: Collected - dd/mm/year",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    collectedDateTxtBox.Text = customer.collected;
                }
            }
        }