Ejemplo n.º 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;
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 3
0
 private void comfirmationButton_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(passportNoBox.Text))
     {
         using (var db = new EmbassyEntitiesFramework())
         {
             db.Database.Connection.ConnectionString = connectionString;
             Visa v = db.Visa.Where(visa => visa.Received_by == passportNoBox.Text).FirstOrDefault <Visa>();
             if (v != null)
             {
                 AddForm a = new AddForm(passportNoBox.Text);
                 a.Show();
             }
             else
             {
                 MessageBox.Show("Such visa doesn't exist. Try adding it.");
             }
         }
     }
 }
Ejemplo n.º 4
0
 private void ShowContent(string passport)
 {
     using (var db = new EmbassyEntitiesFramework())
     {
         db.Database.Connection.ConnectionString = connectionString;
         Visa v = db.Visa.Where(visa => visa.Received_by == passport).FirstOrDefault <Visa>();
         if (v != null)
         {
             FillComboBox();
             providerBox.Text  = v.Granted_by.ToString();
             receiverBox.Text  = v.Received_by.ToString();
             typeComboBox.Text = v.Type.ToString();
             monthCalendar.SetDate(v.Expiration);
             ID = v.Id;
         }
         else
         {
             MessageBox.Show("Such visa doesn't exist. Try adding it.");
         }
     }
 }