コード例 #1
0
        public void SaveContacts(TextBox[] contactsTextBox, RadioButtons[] radioButtons)
        {
            for (int i = 0; i < contactsTextBox.Length; i++)
            {
                var contact     = contactsTextBox[i].Text;
                var checkedType = radioButtons[i].Controls.OfType <RadioButton>()
                                  .FirstOrDefault(r => r.Checked);
                if (contact.Trim() == "" || checkedType == null)
                {
                    MessageBox.Show(@"Please fill all the fields for contact : " + (i + 1), @"Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                using (var dbEntities = new ExpenseTrackerDBEntities())
                {
                    dbEntities.Contacts.Add(new Contact()
                    {
                        contactType = checkedType.Text,
                        contactName = contact.Trim()
                    });
                    dbEntities.SaveChanges();
                }
            }
            MessageBox.Show(@"Contacts Are Successfully Added", @"Success", MessageBoxButtons.OK);
        }
コード例 #2
0
        public void Save(string transactionName, int value, string description, DateTime dateTime,
                         RadioButton checkedType, RadioButton checkedRecurringOption, Contact contact, int id)
        {
            using (var dbEntities = new ExpenseTrackerDBEntities())
            {
                Transaction transaction = new Transaction()
                {
                    UsersId         = MainView.user.Id,
                    transactionId   = id,
                    date            = dateTime,
                    transactionName = transactionName,
                    description     = description,
                    value           = value,
                    transactionType = checkedType.Text,
                    isRecurring     = checkedRecurringOption.Text,
                    ContactId       = contact.contactId
                };
                if (id == 0)
                {
                    dbEntities.Transactions.Add(transaction);
                }
                else
                {
                    dbEntities.Entry(transaction).State = EntityState.Modified;
                }

                dbEntities.SaveChanges();
            }
        }