示例#1
0
        private void button_remove_Click(object sender, EventArgs e)
        {
            int             selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;
            DataGridViewRow selectedRow      = dataGridView1.Rows[selectedrowindex];
            var             id = Guid.Parse(selectedRow.Cells["Id"].Value.ToString());

            MongoRepositoryPeople.RemoveByAddressId(id);
            MongoRepositoryAddresses.Remove(id);
            dataGridView1.Rows.Remove(selectedRow);
        }
示例#2
0
        private void button_update_Click(object sender, EventArgs e)
        {
            int             selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;
            DataGridViewRow selectedRow      = dataGridView1.Rows[selectedrowindex];
            string          a          = selectedRow.Cells["Id"].Value.ToString();
            var             address    = MongoRepositoryAddresses.Get(Guid.Parse(a));
            var             peopleList = MongoRepositoryPeople.GetByAddressId(Guid.Parse(a));

            new AddressForm(address, peopleList).ShowDialog();
        }
示例#3
0
        private void button_ok_Click(object sender, EventArgs e)
        {
            var address = new Address
            {
                Id        = Address?.Id ?? Guid.NewGuid(),
                Street    = textBox_street.Text,
                Building  = textBox_biulding.Text,
                House     = textBox_house.Text,
                Apartment = textBox_apartment.Text,
                UserId    = ((ComboBoxItem)comboBox_users.SelectedItem).HiddenValue
            };

            MongoRepositoryAddresses.Upsert(address);

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                var id        = row.Cells[0].Value?.ToString();
                var lastName  = row.Cells[1].Value?.ToString();
                var firstName = row.Cells[2].Value?.ToString();
                var surName   = row.Cells[3].Value?.ToString();
                var phone     = row.Cells[4].Value?.ToString();

                if (!string.IsNullOrEmpty(id) && string.IsNullOrEmpty(firstName) &&
                    string.IsNullOrEmpty(lastName) && string.IsNullOrEmpty(surName) && string.IsNullOrEmpty(phone))
                {
                    MongoRepositoryPeople.Remove(Guid.Parse(id));
                }

                if (!string.IsNullOrEmpty(firstName) || !string.IsNullOrEmpty(lastName) ||
                    !string.IsNullOrEmpty(surName) || !string.IsNullOrEmpty(phone))
                {
                    var people = new People
                    {
                        Id = id == null?Guid.NewGuid() : Guid.Parse(id),
                                 FirstName = firstName,
                                 LastName  = lastName,
                                 SurName   = surName,
                                 Phone     = phone,
                                 AddressId = address.Id
                    };
                    MongoRepositoryPeople.Upsert(people);
                }
            }

            Close();
        }