Пример #1
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            using (var db = new EmbassyEntitiesFramework())
            {
                db.Database.Connection.ConnectionString = connectionString;

                Visa v = db.Visa.Where(visa => visa.Id == ID).FirstOrDefault <Visa>();

                db.Entry(v).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }
            deleteButton.Visible = false;
            addButton.Visible    = false;
        }
Пример #2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (addButton.Text == "Add")
            {
                if (!String.IsNullOrWhiteSpace(typeComboBox.Text) || !String.IsNullOrWhiteSpace(receiverBox.Text) ||
                    !String.IsNullOrWhiteSpace(providerBox.Text))
                {
                    using (var db = new EmbassyEntitiesFramework())
                    {
                        db.Database.Connection.ConnectionString = connectionString;
                        Visa v = new Visa();
                        v.Type        = typeComboBox.Text;
                        v.Received_by = receiverBox.Text;
                        v.Expiration  = monthCalendar.SelectionRange.Start;
                        v.Granted_by  = Int32.Parse(providerBox.Text);

                        //db.Visa.Add(v);
                        db.Entry(v).State = System.Data.Entity.EntityState.Added;
                        db.SaveChanges();
                    }
                    addButton.Visible = false;
                }
                else
                {
                    MessageBox.Show("Fill all fields, please!");
                }
            }
            else if (addButton.Text == "Update")
            {
                using (var db = new EmbassyEntitiesFramework())
                {
                    db.Database.Connection.ConnectionString = connectionString;

                    Visa v = db.Visa.Where(visa => visa.Id == ID).FirstOrDefault <Visa>();
                    v.Type        = typeComboBox.Text;
                    v.Received_by = receiverBox.Text;
                    v.Expiration  = monthCalendar.SelectionRange.Start;
                    v.Granted_by  = Int32.Parse(providerBox.Text);

                    db.Entry(v).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                addButton.Visible = false;
            }
        }