コード例 #1
0
        internal void BtCreateClick(object sender, EventArgs e)
        {
            if (CheckAddContactButton() && CheckSsn(tbxSsn.Text))
            {
                _contactEdit = new Contact
                                   {
                                       FirstName = tbxName.Text,
                                       Surname = tbxSurname.Text,
                                       DateOfBirth = dtpDateOfBirth.Value.Date,
                                       Ssn = tbxSsn.Text,
                                       Email = tbxEmail.Text,
                                       HomeTelephone = tbxHomeNr.Text,
                                       MobileTelephone = tbxMobile.Text,
                                       ContactAddress = new Address
                                                            {
                                                                Street = tbxStreet.Text,
                                                                PostNumber = tbxPostnr.Text,
                                                                City = tbxCity.Text,
                                                                Country = tbxCountry.Text
                                                            }
                                   };
                Controller.AllContacts.Add(_contactEdit);
                Controller.AddBirthdayGreetings(new Birthday(_contactEdit)
                                                    {
                                                        DateTimeStart = dtpDateOfBirth.Value.Date
                                                    });

                FileManager.SaveContacts();

                dataGridViewContacts.DataSource = null;
                dataGridViewContacts.DataSource = Controller.AllContacts.ToList();
                HideColumnsInContactDataGridView(dataGridViewContacts);
                errorProvider.Clear();
                ClearContactInformation();
                btDeleteContact.Show();
                _contactEdit = null;
            }
            else if (CheckAddContactButton() == false)
                errorProvider.SetError(btCreate,
                                       "Fill in First Name, Surname, and" + Environment.NewLine +
                                       " Social Security number to create contact");

            else if (CheckSsn(tbxSsn.Text) == false)
                errorProvider.SetError(btCreate,
                                       "The social security number you entered" + Environment.NewLine +
                                       "already exists in your contact list");
        }
コード例 #2
0
        private void BtUploadClick(object sender, EventArgs e)
        {
            _contactEdit =
                Controller.AllContacts.Where(
                    contact => contact.Ssn == (string) dataGridViewContacts.SelectedRows[0].Cells["Ssn"].Value).
                    First();

            _logo = AddProfilePic(tbxSsn.Text);
            if (!string.IsNullOrEmpty(_logo))
            {
                var ms = new MemoryStream(File.ReadAllBytes(_logo));
                pbxImage.Image = Image.FromStream(ms);
                _contactEdit.Image = _logo;
            }

            else
                FileManager.SaveContacts();
            _logo = String.Empty;
        }
コード例 #3
0
        private void GetSelectedContactToEdit()
        {
            if (dataGridViewContacts.SelectedRows.Count > 0)
            {
                _contactEdit =
                    Controller.AllContacts.Where(
                        contact => contact.Ssn == (string) dataGridViewContacts.SelectedRows[0].Cells["Ssn"].Value).
                        First();

                tbxName.Text = _contactEdit.FirstName;
                tbxSurname.Text = _contactEdit.Surname;
                dtpRelDateOfBirth.Value = _contactEdit.DateOfBirth;
                tbxSsn.Text = _contactEdit.Ssn;
                tbxEmail.Text = _contactEdit.Email;
                tbxHomeNr.Text = _contactEdit.HomeTelephone;
                tbxMobile.Text = _contactEdit.MobileTelephone;
                tbxStreet.Text = _contactEdit.ContactAddress.Street;
                tbxPostnr.Text = _contactEdit.ContactAddress.PostNumber;
                tbxCity.Text = _contactEdit.ContactAddress.City;
                tbxCountry.Text = _contactEdit.ContactAddress.Country;
                if (!string.IsNullOrEmpty(_contactEdit.Image))
                {
                    var ms = new MemoryStream(File.ReadAllBytes(_contactEdit.Image));
                    pbxImage.Image = Image.FromStream(ms);
                    pbxImage.Show();
                }
            }
        }
コード例 #4
0
        //=========================================================================================================00
        internal static void ChangePicture(Contact contactToAddPicTo)
        {
            var openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = "c:\\",
                Filter = AvalibleImageFormats(),
                FilterIndex = 2,
                RestoreDirectory = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    File.Delete(contactToAddPicTo.Image);
                    var extension = Path.GetExtension(openFileDialog1.FileName);
                    var savePath = ImageDir("logo") + contactToAddPicTo.FirstName + extension;
                    File.Copy(openFileDialog1.FileName, savePath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }