示例#1
0
        /// <summary>
        /// edit record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEdit_Click(object sender, EventArgs e)
        {
            //if the record is selected
            if (IsSelected())
            {
                //create an instance of contactform
                RecordForm frmContact = new RecordForm();
                //provided the record is selected from the listbox
                if (manager.GetAt(lstRecords.SelectedIndex) != null)
                {
                    //get selected record's ino and display it on contact form
                    frmContact.CustomerData = manager.GetAt(lstRecords.SelectedIndex);
                    //save id
                    int id = frmContact.CustomerData.CustomerId;

                    //when user chooses to update corrected info and click ok button
                    if (frmContact.ShowDialog() == DialogResult.OK)
                    {
                        frmContact.CustomerData.CustomerId = id;
                        //save updated info
                        manager.ChangeAt(frmContact.CustomerData, lstRecords.SelectedIndex);

                        //update data in the listbox
                        UpdateList();
                    }
                }
            }
        }
示例#2
0
        /*******************Add, Edit and deletecustomer records******************/
        /// <summary>
        /// add new record
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            RecordForm recForm = new RecordForm();

            //when user enters all data in contact form and click ok
            if (recForm.ShowDialog() == DialogResult.OK)
            {
                Customer customer = new Customer(recForm.CustomerData.FirstName, recForm.CustomerData.Surname, recForm.CustomerData.AddressData, recForm.CustomerData.Email, recForm.CustomerData.ProductData, manager.GetNewId);

                //add new record to customers list
                manager.Add(customer);
                //display updated info in the listbox
                UpdateList();
            }
        }