示例#1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtFullName.Text == "" || txtEmailId.Text == "" || txtMobile.Text == "")
     {
         MessageBox.Show("Fill The Required Fields ");
     }
     else if (!this.txtEmailId.Text.Contains('@') || !this.txtEmailId.Text.Contains('.'))
     {
         MessageBox.Show("Enter Wright Email Address");
     }
     else
     {
         ReloadForm();
         model.fullName = txtFullName.Text.Trim();
         model.mobile   = txtMobile.Text.Trim();
         model.emailId  = txtEmailId.Text.Trim();
         model.DOB      = dateTimePickerDOB.Value;
         model.city     = txtCity.Text.Trim();
         //model.createdAt = DateTime.Now;
         using (MonthlyContributionEntities MC = new MonthlyContributionEntities())
         {
             if (model.id == 0) //for Insert
             {
                 MC.Members.Add(model);
             }
             else
             {
                 MC.Entry(model).State = EntityState.Modified;//for Update
             }
             try
             {
                 MC.SaveChanges();
             }
             catch (DbEntityValidationException c)
             {
                 foreach (var eve in c.EntityValidationErrors)
                 {
                     Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                     foreach (var ve in eve.ValidationErrors)
                     {
                         Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                           ve.PropertyName, ve.ErrorMessage);
                     }
                 }
             }
         }
         clear();
         MessageBox.Show("Submitted Successfully.");
         dvg();
     }
 }
        // delet buttons
        private void btnDeleteFirst_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are You Sure to Delete this Record ?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                using (MonthlyContributionEntities MC = new MonthlyContributionEntities())
                {
                    var entry = MC.Entry(m1);
                    if (entry.State == EntityState.Detached)
                    {
                        MC.First_mR.Attach(m1);
                        MC.First_mR.Remove(m1);
                        MC.SaveChanges();

                        MessageBox.Show("Deleted Successfully");
                    }
                }
            }
            dgvFirstR.DataSource = mc.First_mR.ToList();
        }
示例#3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Record ?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (MonthlyContributionEntities MC = new MonthlyContributionEntities())
         {
             var entry = MC.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 MC.Members.Attach(model);
                 MC.Members.Remove(model);
                 MC.SaveChanges();
                 clear();
                 MessageBox.Show("Deleted Successfully");
                 dvg();
             }
         }
     }
 }
示例#4
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure to Delete this Details ?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (MonthlyContributionEntities MC = new MonthlyContributionEntities())
         {
             var entry = MC.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 MC.Bcs.Attach(model);
                 MC.Bcs.Remove(model);
                 MC.SaveChanges();
                 clear();
                 MessageBox.Show("Deleted Successfully");
                 dgvBeesi.DataSource = mc.Bcs.ToList();
             }
         }
     }
     btnDelete.Enabled = false;
     txtCreate.Enabled = true;
 }
示例#5
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     mc.Entry(model).State = EntityState.Modified;
     btnDelete.Enabled     = false;
 }