private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to delete ?", "EF CRUID Operation", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    using (CMSEntities db = new CMSEntities())
                    {
                        var entry = db.Entry(model);
                        if (entry.State == System.Data.Entity.EntityState.Detached)
                        {
                            db.WorkTables.Attach(model);
                            db.WorkTables.Remove(model);
                            db.SaveChanges();
                            populateDataGridView();

                            MessageBox.Show("Item Deleted");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
        private void FamilyView_Load(object sender, EventArgs e)
        {
            model.Username = Log.recby;

            using (CMSEntities db = new CMSEntities())
            {
                model             = db.FamilyDBs.Where(x => x.Username == model.Username).FirstOrDefault();
                txtName.Text      = model.Name;
                txtNID.Text       = model.NationalID;
                txtAddress.Text   = model.Address;
                txtEmail.Text     = model.Email;
                txtG.Text         = model.Gander;
                picbox.Image      = ConvertBytetoImage(model.NIDPic);
                btn_haire.Enabled = false;
                panelpro.Hide();
                txtName.Enabled    = false;
                txtNID.Enabled     = false;
                txtEmail.Enabled   = false;
                txtG.Enabled       = false;
                txtAddress.Enabled = false;
                picbox.Enabled     = false;
                txtG.Show();
                btn_save.Hide();
                redioFemale.Hide();
                redioMale.Hide();
            }
            populateDataGridView();
        }
 private void dgvrequest_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (dgvrequest.CurrentRow.Index != -1)
         {
             requF           = Convert.ToString(dgvrequest.CurrentRow.Cells["gdvreq"].Value);
             model4.Username = requF;
             using (CMSEntities db = new CMSEntities())
             {
                 model4      = db.FamilyDBs.Where(x => x.Username == model4.Username).FirstOrDefault();
                 txtnm.Text  = model4.Name;
                 txtid.Text  = model4.NationalID;
                 txtad.Text  = model4.Address;
                 txtema.Text = model4.Email;
                 txtga.Text  = model4.Gander;
                 pcbox.Image = ConvertBytetoImage(model4.NIDPic);
             }
         }
     }
     catch
     {
         MessageBox.Show("Invalid");
     }
 }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                model3.NUsername = Log.recby;
                using (CMSEntities db = new CMSEntities())
                {
                    model3 = db.AdmintoNannyReqs.Where(x => x.NUsername == model3.NUsername).FirstOrDefault();
                    dgvrequest.AutoGenerateColumns = false;

                    dgvrequest.DataSource = db.AdmintoNannyReqs.Where(x => x.NUsername == model3.NUsername).ToList <AdmintoNannyReq>();

                    row1     = dgvrequest.RowCount;
                    row.Text = Convert.ToString(row1);
                }


                preq.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
        void populateDataGridView()
        {
            using (CMSEntities db = new CMSEntities())
            {
                dgvNannies.AutoGenerateColumns = false;

                dgvNannies.DataSource = db.NannyDatas.ToList <NannyData>();
            }
        }
        void populateDataGridView()
        {
            using (CMSEntities db = new CMSEntities())
            {
                dgvnoti.AutoGenerateColumns = false;

                dgvnoti.DataSource = db.WorkTables.ToList <WorkTable>();

                row         = dgvnoti.RowCount;
                lblrow.Text = Convert.ToString(row);
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtuser.Text))
     {
         MessageBox.Show("Please Enter Username and Password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtuser.Focus();
         return;
     }
     try
     {
         using (CMSEntities db = new CMSEntities())
         {
             var query = from u in db.logins
                         where u.Username == txtuser.Text && u.Password == txtpass.Text && u.Type == comboBox1.Text
                         select u;
             if (query.SingleOrDefault() != null)
             {
                 recby = txtuser.Text;
                 MessageBox.Show("Welcome! ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 lg.Username = recby;
                 lg          = db.logins.Where(x => x.Username == lg.Username).FirstOrDefault();
                 if (lg.Type == "Family")
                 {
                     this.Hide();
                     FamilyView fv = new FamilyView();
                     fv.Show();
                 }
                 if (lg.Type == "Nanny")
                 {
                     this.Hide();
                     NannyView fv = new NannyView();
                     fv.Show();
                 }
                 if (lg.Type == "Admin")
                 {
                     this.Hide();
                     AdminView fv = new AdminView();
                     fv.Show();
                 }
             }
             else
             {
                 MessageBox.Show("Please enter correct username and password ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         throw;
     }
 }
 private void button4_Click(object sender, EventArgs e)
 {
     model3.FUsername = FamilyUser;
     model3.NUsername = NannyUser;
     using (CMSEntities db = new CMSEntities())
     {
         if (model3.UserID == 0)
         {
             db.AdmintoNannyReqs.Add(model3);
             MessageBox.Show("request accepted!");
         }
         db.SaveChanges();
     }
 }
        private void btn_haire_Click(object sender, EventArgs e)
        {
            using (CMSEntities db = new CMSEntities())
            {
                model4.FUsername  = fuser;
                model4.NUsername  = userName;
                model4.WorkStatus = "proccessing";
                if (model3.UserID == 0)
                {
                    db.WorkTables.Add(model4);

                    MessageBox.Show("Haire ruquest sent");
                }
                db.SaveChanges();
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            checkBox3.Enabled = false;
            checkBox4.Enabled = false;
            checkBox5.Enabled = false;
            checkBox6.Enabled = false;
            try
            {
                using (CMSEntities db = new CMSEntities())
                {
                    model.Name       = txtname.Text.Trim();
                    model.NationalID = txtNID.Text.Trim();
                    model.NIDPic     = ConvertFiltoByte(this.picbox.ImageLocation);

                    model.Email   = txtNID.Text.Trim();
                    model.Address = txtAddress.Text.Trim();


                    model.UserPic    = ConvertFiltoByte(this.userpic.ImageLocation);
                    model.Type       = type;
                    model.Experience = txtexperience.Text.Trim();
                    model.ExSalary   = txtexsal.Text.Trim();
                    model.Education  = txtedu.Text.Trim();
                    model.Mobile     = txtmobile.Text.Trim();
                    model.BirthDate  = datePicker.Value;
                    model.Status     = "Free";

                    model1.Username = Log.recby;


                    model1 = db.WorkCharts.Where(x => x.Username == model1.Username).FirstOrDefault();


                    db.Entry(model1).State = System.Data.Entity.EntityState.Modified;
                    db.Entry(model).State  = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    MessageBox.Show("your profile is successfully updated");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please change once more");
                throw;
            }
        }
 private void dgvnoti_Click(object sender, EventArgs e)
 {
     try {
         if (dgvnoti.CurrentRow.Index != -1)
         {
             FamilyUser      = Convert.ToString(dgvnoti.CurrentRow.Cells["dgvFuser"].Value);
             NannyUser       = Convert.ToString(dgvnoti.CurrentRow.Cells["dgvNanny"].Value);
             model.FUsername = Convert.ToString(dgvnoti.CurrentRow.Cells["dgvFuser"].Value);
             using (CMSEntities db = new CMSEntities())
             {
                 model = db.WorkTables.Where(x => x.FUsername == model.FUsername).FirstOrDefault(x => x.NUsername == NannyUser);
             }
         }
     }
     catch
     {
         MessageBox.Show("Invalid");
     }
 }
 private void button8_Click(object sender, EventArgs e)
 {
     try
     {
         model5.NUsername = Log.recby;
         using (CMSEntities db = new CMSEntities())
         {
             model5            = db.WorkTables.Where(x => x.NUsername == model5.NUsername).FirstOrDefault(x => x.FUsername == requF);
             model5.WorkStatus = "Booked";
             db.SaveChanges();
             MessageBox.Show("Congratulation ! you are haired!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
         throw;
     }
 }
        private void btn_fri_CheckedChanged(object sender, EventArgs e)
        {
            model1.Username = Log.recby;
            using (CMSEntities db = new CMSEntities())
            {
                model1 = db.WorkCharts.Where(x => x.Username == model1.Username).FirstOrDefault();
                if (btn_sun.Checked)
                {
                    model1.Friday = "Booked";
                }
                else
                {
                    model1.Friday = "Free";
                }

                db.Entry(model1).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
        private void button9_Click(object sender, EventArgs e)
        {
            model.Username = Log.recby;
            using (CMSEntities db = new CMSEntities())
            {
                model            = db.FamilyDBs.Where(x => x.Username == model.Username).FirstOrDefault();
                model.Name       = txtName.Text.Trim();
                model.NationalID = txtNID.Text.Trim();
                model.NIDPic     = ConvertFiltoByte(this.picbox.ImageLocation);
                model.Gander     = gen;
                model.Email      = txtEmail.Text.Trim();
                model.Address    = txtAddress.Text.Trim();

                db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                MessageBox.Show("Changes saved successfully");
            }
            redioFemale.Hide();
            redioMale.Hide();
            this.Hide();
            FamilyView fv = new FamilyView();

            fv.Show();
        }
 private void button1_Click(object sender, EventArgs e)
 {
     panelpro.Show();
     btn_haire.Enabled = true;
     btn_save.Show();
     try
     {
         if (dgvNannies.CurrentRow.Index != -1)
         {
             search = txtSearch1.Text;
             using (CMSEntities db = new CMSEntities())
             {
                 model1             = db.NannyDatas.Where(x => x.Username == search).FirstOrDefault();
                 model2             = db.WorkCharts.Where(x => x.Username == search).FirstOrDefault();
                 txt_n.Text         = model1.Name;
                 txtt.Text          = model1.Username;
                 txtBirth.Text      = Convert.ToString(model1.BirthDate);
                 txtedu.Text        = model1.Education;
                 txtem.Text         = model1.Email;
                 txtexperience.Text = model1.Experience;
                 txtexsal.Text      = model1.ExSalary;
                 NidPic.Image       = ConvertBytetoImage(model1.NIDPic);
                 userpic.Image      = ConvertBytetoImage(model1.UserPic);
                 txtmobile.Text     = model1.Mobile;
                 txtGen.Text        = model1.Gander;
                 if (model2.Saturday == "Free")
                 {
                     free = " Saturday";
                 }
                 if (model2.Sunday == "Free")
                 {
                     free = free + " Sunday";
                 }
                 if (model2.Monday == "Free")
                 {
                     free = free + " Monday";
                 }
                 if (model2.Tuesday == "Free")
                 {
                     free = free + " Tuesday";
                 }
                 if (model2.Wednesday == "Free")
                 {
                     free = free + " Wednesday";
                 }
                 if (model2.Thursday == "Free")
                 {
                     free = free + " Thursday";
                 }
                 if (model2.Friday == "Free")
                 {
                     free = free + " Friday";
                 }
                 txtFree.Text = free;
             }
         }
     }
     catch
     {
         MessageBox.Show("Something wrong happend");
     }
 }
        private void NannyView_Load(object sender, EventArgs e)
        {
            model.Username  = Log.recby;
            model1.Username = Log.recby;
            preq.Hide();
            using (CMSEntities db = new CMSEntities())
            {
                model                 = db.NannyDatas.Where(x => x.Username == model.Username).FirstOrDefault();
                model1                = db.WorkCharts.Where(x => x.Username == model1.Username).FirstOrDefault();
                txtname.Text          = model.Name;;
                txtNID.Text           = model.NationalID;
                txtAddress.Text       = model.Address;
                txtemail.Text         = model.Email;
                userpic.Image         = ConvertBytetoImage(model.UserPic);
                picbox.Image          = ConvertBytetoImage(model.NIDPic);
                txtexsal.Text         = model.ExSalary;
                txtexperience.Text    = model.Experience;
                txtedu.Text           = model.Education;
                txtLabel.Text         = model.Username;
                txtt.Text             = model.Type;
                txtmobile.Text        = model.Mobile;
                txtname.Enabled       = false;
                txtNID.Enabled        = false;
                txtAddress.Enabled    = false;
                txtemail.Enabled      = false;
                userpic.Enabled       = false;
                picbox.Enabled        = false;
                txtexsal.Enabled      = false;
                txtexperience.Enabled = false;
                txtedu.Enabled        = false;
                txtLabel.Enabled      = false;
                txtt.Enabled          = false;
                checkBox3.Enabled     = false;
                checkBox4.Enabled     = false;
                checkBox5.Enabled     = false;
                checkBox6.Enabled     = false;
                btn_sat.Enabled       = false;
                btn_sun.Enabled       = false;
                btn_mon.Enabled       = false;
                btn_tues.Enabled      = false;
                btn_wed.Enabled       = false;
                btn_thurs.Enabled     = false;
                btn_fri.Enabled       = false;
                if (model1.Saturday == "Free")
                {
                    free = " Saturday";
                }
                if (model1.Sunday == "Free")
                {
                    free = free + " Sunday";
                }
                if (model1.Monday == "Free")
                {
                    free = free + " Monday";
                }
                if (model1.Tuesday == "Free")
                {
                    free = free + " Tuesday";
                }
                if (model1.Wednesday == "Free")
                {
                    free = free + " Wednesday";
                }
                if (model1.Thursday == "Free")
                {
                    free = free + " Thursday";
                }
                if (model1.Friday == "Free")
                {
                    free = free + " Friday";
                }
                txtFree.Text = free;
            }

            row1     = dgvrequest.RowCount;
            row.Text = Convert.ToString(row1);
        }