protected void gvEmp_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { int id = Convert.ToInt32(gvEmp.Rows[e.RowIndex].Cells[5].Text); using (ClubDBEntities club = new ClubDBEntities()) { var emp = club.Employees.Where(a => a.EmpID == id).First(); club.Employees.DeleteObject(emp); if (!string.IsNullOrEmpty(emp.UserName)) { Membership.DeleteUser(emp.UserName, true); } club.SaveChanges(); gvEmp.DataSource = club.getEmployees(); gvEmp.DataBind(); string Message = " تم الحذف "; ScriptManager.RegisterStartupScript(Page, this.GetType(), "alert", string.Format("alert('{0}');", Message), true); } } catch { lblError.Text = "لايمكن حذف الموظف"; lblError.Visible = true; } }
protected void btnEAdd_Click(object sender, EventArgs e) { string name = tbEName.Text; long phone = Convert.ToInt64(tbPhone.Text); int dep = Convert.ToInt32(ddlType.SelectedValue); using (ClubDBEntities club = new ClubDBEntities()) { var emp = club.Employees.Where(a => a.EmpID == EditEmp).First(); emp.Name = name; emp.PhoneNum = phone; if (dep == 0) { emp.Type = "Manager"; } else { emp.Type = "Trainer"; var t = (from o in club.Departments where o.DepID == dep select o).First(); emp.Departments.Clear(); emp.Departments.Add(t); } club.SaveChanges(); resetEmp(); gvEmp.DataSource = club.getEmployees(); gvEmp.DataBind(); //chagesSaved(); } }
protected void btnAdd_Click(object sender, EventArgs e) { switch (rbAdd.SelectedIndex) { case 0: pnlEmp.Visible = true; pnlDep.Visible = false; pnlService.Visible = false; pnlWith.Visible = false; using (ClubDBEntities club = new ClubDBEntities()) { gvEmp.DataSource = club.getEmployees(); gvEmp.DataBind(); } break; case 1: pnlEmp.Visible = false; pnlDep.Visible = false; pnlService.Visible = true; pnlWith.Visible = false; using (ClubDBEntities club = new ClubDBEntities()) { var r = club.getServices(); gvSer.DataSource = r; gvSer.DataBind(); } break; case 2: pnlEmp.Visible = false; pnlDep.Visible = true; pnlService.Visible = false; pnlWith.Visible = false; using (ClubDBEntities club = new ClubDBEntities()) { var r = from i in club.Departments orderby i.DepID select i ; gvDep.DataSource = r; gvDep.DataBind(); } break; case 3: pnlEmp.Visible = false; pnlDep.Visible = false; pnlService.Visible = false; pnlWith.Visible = true; using (ClubDBEntities club = new ClubDBEntities()) { var result = club.getWithTypes(); gvWith.DataSource = result; gvWith.DataBind(); } break; } }