protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["empid"] != null) { setdateofbirth(); setdepartment(); setEmployeeType(); int empid = int.Parse(Request.QueryString["empid"]); DBFunctions db = new DBFunctions(); Employee_tbl emp = db.getemployee(empid); EmpNametxt.Text = emp.Name; Qualificationtxt.Text = emp.Qualification; phonetxt.Text = emp.PhoneNumber; dropdownGender.SelectedValue = emp.Gender; DeptList.SelectedValue = emp.Deptid.ToString(); string[] dob = emp.DateOFBirth.Split('/'); dropdownDay.SelectedValue = dob[0]; dropdownMonth.SelectedValue = dob[1]; dropdownyears.SelectedValue = dob[2]; Emailtxt.Text = emp.Email; CNICtxt.Text = emp.CNIC; Addresstxt.Text = emp.Address; Citytxt.Text = emp.City; Accounttxt.Text = emp.BankAccountNumber; Banktxt.Text = emp.Bank; Designationtxt.Text = emp.Designation; DropDownEmpType.SelectedValue = emp.EmployeeType.ToString(); } } }
protected void btnupdateEmployee_Click(object sender, EventArgs e) { DBFunctions db = new DBFunctions(); DateTime dob = DateTime.Parse(dropdownyears.SelectedItem.Text + "-" + dropdownMonth.SelectedItem.Text + "-" + dropdownDay.SelectedItem.Text); Employee_tbl employee = new Employee_tbl {ID=int.Parse(Request.QueryString["empid"]), Name = EmpNametxt.Text, Qualification = Qualificationtxt.Text, PhoneNumber = phonetxt.Text, Gender = dropdownGender.SelectedValue, Deptid = int.Parse(DeptList.SelectedValue), DateOFBirth = dob.ToShortDateString(), Email = Emailtxt.Text, CNIC = CNICtxt.Text, Address = Addresstxt.Text, City = Citytxt.Text, BankAccountNumber = Accounttxt.Text, Bank = Banktxt.Text, Designation = Designationtxt.Text, EmployeeType = int.Parse(DropDownEmpType.SelectedValue) }; db.updateEmployee(employee); Response.Redirect("ManageEmployee.aspx"); }
public ActionResult Delete(int id) { using (DBModel db = new DBModel()) { Employee_tbl emp = db.Employee_tbl.Where(x => x.EmployeeID == id).FirstOrDefault <Employee_tbl>(); db.Employee_tbl.Remove(emp); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Succesfully" }, JsonRequestBehavior.AllowGet)); } }
protected void btnupdateEmployee_Click(object sender, EventArgs e) { DBFunctions db = new DBFunctions(); DateTime dob = DateTime.Parse(dropdownyears.SelectedItem.Text + "-" + dropdownMonth.SelectedItem.Text + "-" + dropdownDay.SelectedItem.Text); Employee_tbl employee = new Employee_tbl { ID = int.Parse(Request.QueryString["empid"]), Name = EmpNametxt.Text, Qualification = Qualificationtxt.Text, PhoneNumber = phonetxt.Text, Gender = dropdownGender.SelectedValue, Deptid = int.Parse(DeptList.SelectedValue), DateOFBirth = dob.ToShortDateString(), Email = Emailtxt.Text, CNIC = CNICtxt.Text, Address = Addresstxt.Text, City = Citytxt.Text, BankAccountNumber = Accounttxt.Text, Bank = Banktxt.Text, Designation = Designationtxt.Text, EmployeeType = int.Parse(DropDownEmpType.SelectedValue) }; db.updateEmployee(employee); Response.Redirect("ManageEmployee.aspx"); }
protected void btnaddEmployee_Click(object sender, EventArgs e) { DBFunctions db = new DBFunctions(); DateTime dob = DateTime.Parse(dropdownyears.SelectedItem.Text + "-" + dropdownMonth.SelectedItem.Text + "-" + dropdownDay.SelectedItem.Text); Employee_tbl employee = new Employee_tbl { Name = EmpNametxt.Text, Qualification = Qualificationtxt.Text, PhoneNumber = phonetxt.Text, Gender = dropdownGender.SelectedValue, Deptid = int.Parse(DeptList.SelectedValue), DateOFBirth = dob.ToShortDateString(), Email = Emailtxt.Text, CNIC = CNICtxt.Text, Address = Addresstxt.Text, City = Citytxt.Text, BankAccountNumber = Accounttxt.Text, Bank = Banktxt.Text, Designation = Designationtxt.Text, EmployeeType = int.Parse(DropDownEmpType.SelectedValue), Username = usernametxt.Text, Password = Passwordtxt.Text, IsFirstTime = 0 }; employee = db.addEmployee(employee); employee.Department_tbl = db.getalldepartments().Where(x => x.ID == int.Parse(DeptList.SelectedValue)).FirstOrDefault(); List <Employee_tbl> emp = new List <Employee_tbl>(); emp.Add(employee); renderemployees(emp); }
public ActionResult AddOrEdit(Employee_tbl emp) { using (DBModel db = new DBModel()) { if (emp.EmployeeID == 0) { db.Employee_tbl.Add(emp); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public JsonResult getEmployeeById(Employee_tbl emp) { using (PayRoll_Entities dataContext = new PayRoll_Entities()) { int no = emp.id; var employee = (from e in dataContext.Employee_tbl where e.id == no select new { e.id, Branch = e.Branch.ToString(), e.First_Name, e.Last_Name, DOB = e.DOB.ToString(), DOJ = e.DOJ.ToString(), Designation = e.Designation.ToString(), e.Employee_Code, Gender = e.Gender.ToString(), e.ProfileImage, e.Email, e.Mobile, e.Permanent_Address1, e.Present_Address1, e.Permanent_Address2, e.Present_Address2, e.Permanent_City, e.Present_City, e.Permanent_State, e.Present_State, e.Present_Pincode, e.Permanent_Pincode, e.Account_No, e.Bank_Name, e.IFSC_Code, e.Branch_Name, e.User_Id, Status = e.Status.ToString(), }).ToList(); return(Json(employee, JsonRequestBehavior.AllowGet)); } }
public string AddUpdateEmployee(Employee_tbl employee, HttpPostedFileBase file) { if (employee != null) { if (employee.id == 0) { using (PayRoll_Entities dataContext = new PayRoll_Entities()) { var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", "jpeg" }; //tbl.Id = fc["Id"].ToString(); //tbl.Image_url = file.ToString(); //getting complete url //tbl.Name = fc["Name"].ToString(); //var fileName = Path.GetFileName(file.FileName); //getting only file name(ex-ganesh.jpg) //var ext = Path.GetExtension(file.FileName); //getting the extension(ex-.jpg) //if (allowedExtensions.Contains(ext)) //check what type of extension //{ // string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension // string myfile = name + "_" + tbl.Id + ext; //appending the name with id // // store the file inside ~/project folder(Img) // var path = Path.Combine(Server.MapPath("~/Img"), myfile); // tbl.Image_url = path; // obj.tbl_details.Add(tbl); // obj.SaveChanges(); // file.SaveAs(path); //} employee.Create_by = 1; employee.Create_Date = DateTime.Now; dataContext.Employee_tbl.Add(employee); try { dataContext.SaveChanges(); err = "employee Added Successfully"; } catch (Exception ex) { HandleException(ex); } } } else { using (PayRoll_Entities dataContext = new PayRoll_Entities()) { int no = Convert.ToInt32(employee.id); var empList = dataContext.Employee_tbl.Where(x => x.id == no).FirstOrDefault(); empList.Employee_Code = employee.Employee_Code; empList.First_Name = employee.First_Name; empList.Last_Name = employee.Last_Name; empList.Gender = employee.Gender; empList.DOB = employee.DOB; empList.DOJ = employee.DOJ; empList.Email = employee.Email; empList.Mobile = employee.Mobile; empList.Designation = employee.Designation; empList.Branch = employee.Branch; empList.Present_Address1 = employee.Present_Address1; empList.Present_Address2 = employee.Present_Address2; empList.Present_City = employee.Present_City; empList.Present_State = employee.Present_State; empList.Present_Pincode = employee.Present_Pincode; empList.Permanent_Address1 = employee.Permanent_Address1; empList.Permanent_Address2 = employee.Permanent_Address2; empList.Permanent_City = employee.Permanent_City; empList.Permanent_State = employee.Permanent_State; empList.Permanent_Pincode = employee.Permanent_Pincode; empList.Bank_Name = employee.Bank_Name; empList.Account_No = employee.Account_No; empList.IFSC_Code = employee.IFSC_Code; empList.Branch_Name = employee.Branch_Name; empList.Status = employee.Status; empList.User_Id = employee.User_Id; empList.Update_by = 1; empList.Update_Date = DateTime.Now; empList.ProfileImage = employee.ProfileImage; try { dataContext.SaveChanges(); return("Employee Updated Successfully"); } catch (Exception ex) { HandleException(ex); } } } } else { err = "Invalid Item"; } return(err); }
public void updateEmployee(Employee_tbl employee) { db = new CollegeERPDBEntities(); db.Employee_tbl.Attach(employee); // var progrm = db.Program_tbl.Where(x => x.ID == id).FirstOrDefault(); db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); }
public Employee_tbl addEmployee(Employee_tbl Employee) { db = new CollegeERPDBEntities(); db.Employee_tbl.Add(Employee); db.SaveChanges(); return Employee; }
protected void btnaddEmployee_Click(object sender, EventArgs e) { DBFunctions db = new DBFunctions(); DateTime dob=DateTime.Parse(dropdownyears.SelectedItem.Text+"-"+dropdownMonth.SelectedItem.Text+"-"+dropdownDay.SelectedItem.Text); Employee_tbl employee = new Employee_tbl { Name = EmpNametxt.Text, Qualification = Qualificationtxt.Text, PhoneNumber = phonetxt.Text, Gender = dropdownGender.SelectedValue, Deptid = int.Parse(DeptList.SelectedValue), DateOFBirth = dob.ToShortDateString(), Email = Emailtxt.Text, CNIC = CNICtxt.Text, Address = Addresstxt.Text, City = Citytxt.Text, BankAccountNumber = Accounttxt.Text, Bank = Banktxt.Text,Designation=Designationtxt.Text,EmployeeType=int.Parse(DropDownEmpType.SelectedValue),Username=usernametxt.Text,Password=Passwordtxt.Text,IsFirstTime=0 }; employee = db.addEmployee(employee); employee.Department_tbl = db.getalldepartments().Where(x => x.ID == int.Parse(DeptList.SelectedValue)).FirstOrDefault(); List<Employee_tbl> emp = new List<Employee_tbl>(); emp.Add(employee); renderemployees(emp); }