Ejemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            tblLogFault fault = new tblLogFault();

            if (dgvViewLog.CurrentRow.Index != -1)
            {
                model.LogID = Convert.ToInt32(dgvViewLog.CurrentRow.Cells["LogID"].Value);
                using (MacrocommEntities db = new MacrocommEntities())
                {
                    model = db.tblViewLogs.Where(x => x.LogID == model.LogID).FirstOrDefault();

                    if (MessageBox.Show("Are you sure to delete this record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        var entry = db.Entry(model);
                        if (entry.State == EntityState.Detached)
                        {
                            db.tblViewLogs.Attach(model);
                        }
                        db.tblViewLogs.Remove(model);
                        db.SaveChanges();
                        MessageBox.Show("Deleted Successfully");
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to delete this record ?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (MacrocommEntities db = new MacrocommEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.tblRegistrations.Attach(model);
             }
             db.tblRegistrations.Remove(model);
             db.SaveChanges();
             MessageBox.Show("Deleted Successfully");
             this.Close();
         }
     }
 }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //txtFirstName.Visible = false;
            //txtEmail.Visible = false;
            //txtMobile.Visible = false;
            //txtSurname.Visible = false;
            //tblroles.Visible = false;

            //btnUpload.Visible = false;
            //btnSave.Visible = false;
            //btnEditProfile.Visible = true;


            //lblFirstName.Visible = true;
            //lblEmail.Visible = true;
            //lblMobile.Visible = true;
            //lblrole.Visible = true;
            //lblSurname.Visible = true;


            if (txtFirstName.Text == "" || txtSurname.Text == "" || txtMobile.Text == "" || txtEmail.Text == "" || imgProfile.Image == null)
            {
                MessageBox.Show("Please enter all fields");

                txtFirstName.Visible = true;
                txtSurname.Visible   = true;
                txtEmail.Visible     = true;
                txtMobile.Visible    = true;
                tblroles.Visible     = true;
                cmbUserRole.Visible  = true;

                btnUpload.Visible      = true;
                btnSave.Visible        = true;
                btnEditProfile.Visible = false;
                btnCancel.Visible      = false;
                btnDelete.Visible      = false;
                btnCancel2.Visible     = true;

                lblFirstName.Visible = false;
                lblSurname.Visible   = false;
                lblrole.Visible      = false;
                lblEmail.Visible     = false;
                lblMobile.Visible    = false;
            }
            else
            {
                try
                {
                    //MacrocommEntities context = new MacrocommEntities();


                    model.FirstName = txtFirstName.Text;
                    model.Surname   = txtSurname.Text;
                    model.Email     = txtEmail.Text;
                    model.UserRole  = cmbUserRole.Text;
                    model.Mobile    = txtMobile.Text;
                    //model.images = ConvertFiltoByte(this.imgProfile.ImageLocation);

                    using (MacrocommEntities context = new MacrocommEntities())
                    {
                        context.Entry(model).State = EntityState.Modified;
                        context.SaveChanges();
                    }

                    MessageBox.Show("Record Modified", "Confirmation");
                    txtFirstName.Visible = false;
                    txtEmail.Visible     = false;
                    txtMobile.Visible    = false;
                    txtSurname.Visible   = false;
                    tblroles.Visible     = false;
                    cmbUserRole.Visible  = false;

                    btnUpload.Visible      = false;
                    btnSave.Visible        = false;
                    btnEditProfile.Visible = true;
                    btnCancel2.Visible     = true;
                    btnDelete.Visible      = false;


                    lblFirstName.Visible = true;
                    lblEmail.Visible     = true;
                    lblMobile.Visible    = true;
                    lblrole.Visible      = true;
                    lblSurname.Visible   = true;
                }
                catch
                {
                    txtFirstName.Visible = true;
                    txtSurname.Visible   = true;
                    txtEmail.Visible     = true;
                    txtMobile.Visible    = true;
                    tblroles.Visible     = true;

                    btnUpload.Visible      = true;
                    btnSave.Visible        = true;
                    btnEditProfile.Visible = false;
                    btnCancel.Visible      = false;
                    btnDelete.Visible      = false;
                    btnCancel2.Visible     = true;

                    lblFirstName.Visible = false;
                    lblSurname.Visible   = false;
                    lblrole.Visible      = false;
                    lblEmail.Visible     = false;
                    lblMobile.Visible    = false;
                    MessageBox.Show("User not Updated", "Confirmation");
                }
            }
        }