protected void btnMyPets_Click(object sender, EventArgs e) { DatabaseEntities db = new DatabaseEntities(); VETS loginVet = (VETS)Session["Vet"]; var query = (from p in db.PETS join v in db.VETS on p.vetID equals v.vetID where v.vetID == loginVet.vetID && p.approvalSituation == true && p.isActive == true select new DataBindingProjection { ID = p.petID, photo = p.photoURL, name = p.name, type = p.type, petClass = p.petClass, age = p.age, gender = p.gender, address = p.address, city = p.city, vetName = v.name, vetSurname = v.surname }).ToList(); grdPets.DataSource = query; grdPets.DataBind(); grdPets.Visible = true; grdAnnouncements.Visible = false; lblPetsHeader.Visible = true; lblAnnouncementsHeader.Visible = false; }
protected void grdVet_RowDeleting(object sender, GridViewDeleteEventArgs e) { GridViewRow row = (GridViewRow)grdVet.Rows[e.RowIndex]; Label lbldeleteid = (Label)row.FindControl("lblVetID"); DatabaseEntities db = new DatabaseEntities(); int id = Convert.ToInt32(lbldeleteid.Text); VETS v = (from x in db.VETS where x.approvalSituation == true && x.vetID == id && x.isActive == true select x).SingleOrDefault(); v.isActive = false; db.SaveChanges(); VETS[] v1 = (from x in db.VETS where x.approvalSituation == true && x.isActive == true select x).ToArray(); grdVet.DataSource = v1; grdVet.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { VETS loginVet = (VETS)Session["Vet"]; lblHeaderName.Text = loginVet.name + " " + loginVet.surname; imgVet.ImageUrl = loginVet.photoURL; DateTime todayDate = DateTime.Today; DatabaseEntities db = new DatabaseEntities(); ANNOUNCEMENTS[] listOfPastAnnouncements = (from x in db.ANNOUNCEMENTS where x.date < todayDate && x.isActive == true select x).ToArray(); for (int i = 0; i < listOfPastAnnouncements.Length; i++) { listOfPastAnnouncements[i].isActive = false; } db.SaveChanges(); }
protected void btnMyAnnouncements_Click(object sender, EventArgs e) { DatabaseEntities db = new DatabaseEntities(); VETS loginVet = (VETS)Session["Vet"]; var query = (from a in db.ANNOUNCEMENTS join v in db.VETS on a.vetID equals v.vetID join p in db.PETS on a.petID equals p.petID where v.vetID == loginVet.vetID && a.approvalSituation == true && a.isActive == true select new DataBindingProjection { ID = a.announcementID, date = a.date, photo = p.photoURL, name = p.name, type = p.type, petClass = p.petClass, age = p.age, gender = p.gender, situation = a.situation, fee = a.fee, text = a.text, vetName = v.name, vetSurname = v.surname, vetAddress = v.address, vetMail = v.emailAddress, vetPhone = v.phoneNumber }).ToList(); grdAnnouncements.DataSource = query; grdAnnouncements.DataBind(); grdAnnouncements.Visible = true; grdPets.Visible = false; lblAnnouncementsHeader.Visible = true; lblPetsHeader.Visible = false; }
protected void grdVet_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label id = (Label)grdVet.Rows[e.RowIndex].FindControl("lblVetID"); TextBox name = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtVetName"); TextBox surname = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtVetSurname"); TextBox eMailAddress = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtEmail"); TextBox password = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtPassword"); TextBox phoneNumber = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtPhone"); TextBox age = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtAge"); TextBox gender = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtGender"); TextBox photo = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtPhoto"); TextBox address = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtAddress"); TextBox city = (TextBox)grdVet.Rows[e.RowIndex].FindControl("txtCity"); CheckBox approval = (CheckBox)grdVet.Rows[e.RowIndex].FindControl("checkApproval"); DatabaseEntities db = new DatabaseEntities(); int id1 = Convert.ToInt32(id.Text); VETS v = (from x in db.VETS where x.approvalSituation == true && x.vetID == id1 && x.isActive == true select x).SingleOrDefault(); v.name = name.Text; v.surname = surname.Text; v.emailAddress = eMailAddress.Text; v.password = password.Text; v.phoneNumber = phoneNumber.Text; v.age = Convert.ToInt32(age.Text); v.gender = gender.Text; v.photoURL = photo.Text; v.address = address.Text; v.city = city.Text; v.approvalSituation = approval.Checked; db.SaveChanges(); VETS[] v1 = (from x in db.VETS where x.approvalSituation == true && x.isActive == true select x).ToArray(); grdVet.DataSource = v1; grdVet.DataBind(); }
protected void btnLogin_Click(object sender, EventArgs e) { string email = txtEmail.Text; string password = txtPassword.Text; DatabaseEntities db = new DatabaseEntities(); USERS u = (from x in db.USERS where x.emailAddress == email && x.password == password && x.approvalSituation == true && x.isActive == true select x).SingleOrDefault(); if (u == null) { ADMINISTRATORS a = (from x in db.ADMINISTRATORS where x.companyEmail == email && x.password == password && x.isActive == true select x).SingleOrDefault(); if (a == null) { VETS v = (from x in db.VETS where x.emailAddress == email && x.password == password && x.isActive == true select x).SingleOrDefault(); if (v == null) { lblMessage.Visible = true; lblMessage.Text = "Please check your information !"; } else { if (cbRememberMe.Checked) { Response.Cookies["Email"].Value = txtEmail.Text; Response.Cookies["Email"].Expires = DateTime.Now.AddHours(8); Response.Cookies["Password"].Value = txtPassword.Text; Response.Cookies["Password"].Expires = DateTime.Now.AddHours(8); } else { if (Request.Cookies["Email"] != null && Request.Cookies["Password"] != null) { Response.Cookies["Email"].Expires = DateTime.Now.AddHours(-1); Response.Cookies["Password"].Expires = DateTime.Now.AddHours(-1); } } Session["Vet"] = v; Application.Lock(); Application["Counter"] = Convert.ToInt32(Application["Counter"]) + 1; Application.UnLock(); Response.Redirect("VetHomePage.aspx"); } } else { if (cbRememberMe.Checked) { Response.Cookies["Email"].Value = txtEmail.Text; Response.Cookies["Email"].Expires = DateTime.Now.AddHours(8); Response.Cookies["Password"].Value = txtPassword.Text; Response.Cookies["Password"].Expires = DateTime.Now.AddHours(8); } else { if (Request.Cookies["Email"] != null && Request.Cookies["Password"] != null) { Response.Cookies["Email"].Expires = DateTime.Now.AddHours(-1); Response.Cookies["Password"].Expires = DateTime.Now.AddHours(-1); } } Session["Admin"] = a; Application.Lock(); Application["Counter"] = Convert.ToInt32(Application["Counter"]) + 1; Application.UnLock(); Response.Redirect("AdminHomePage.aspx"); } } else { if (cbRememberMe.Checked) { Response.Cookies["Email"].Value = txtEmail.Text; Response.Cookies["Email"].Expires = DateTime.Now.AddHours(8); Response.Cookies["Password"].Value = txtPassword.Text; Response.Cookies["Password"].Expires = DateTime.Now.AddHours(8); } else { if (Request.Cookies["Email"] != null && Request.Cookies["Password"] != null) { Response.Cookies["Email"].Expires = DateTime.Now.AddHours(-1); Response.Cookies["Password"].Expires = DateTime.Now.AddHours(-1); } } Session["User"] = u; Application.Lock(); Application["Counter"] = Convert.ToInt32(Application["Counter"]) + 1; Application.UnLock(); Response.Redirect("UserHomePage.aspx"); } }
protected void btnRegister_Click(object sender, EventArgs e) { DatabaseEntities db = new DatabaseEntities(); USERS u = (from x in db.USERS where x.emailAddress == txtEmail.Text select x).SingleOrDefault(); if (u == null) { VETS v = (from x in db.VETS where x.emailAddress == txtEmail.Text select x).SingleOrDefault(); if (v == null) { if (ddlUserTypes.SelectedValue == "User") { USERS newUser = new USERS(); newUser.name = txtName.Text; newUser.surname = txtSurname.Text; newUser.emailAddress = txtEmail.Text; newUser.password = txtPassword.Text; newUser.phoneNumber = txtPhoneNumber.Text; newUser.age = Convert.ToInt32(txtAge.Text); newUser.gender = ddlGender.SelectedValue; newUser.address = txtAddress.Text; newUser.city = txtCity.Text; fuImage.SaveAs(Server.MapPath("~/Photos/" + fuImage.FileName)); newUser.photoURL = "~/Photos/" + fuImage.FileName; newUser.isActive = true; newUser.approvalSituation = false; db.USERS.Add(newUser); db.SaveChanges(); } else if (ddlUserTypes.SelectedValue == "Veterinary") { VETS newVet = new VETS(); newVet.name = txtName.Text; newVet.surname = txtSurname.Text; newVet.emailAddress = txtEmail.Text; newVet.password = txtPassword.Text; newVet.phoneNumber = txtPhoneNumber.Text; newVet.age = Convert.ToInt32(txtAge.Text); newVet.gender = ddlGender.SelectedValue; newVet.address = txtAddress.Text; newVet.city = txtCity.Text; fuImage.SaveAs(Server.MapPath("~/Photos/" + fuImage.FileName)); newVet.photoURL = "~/Photos/" + fuImage.FileName; newVet.isActive = true; newVet.approvalSituation = false; db.VETS.Add(newVet); db.SaveChanges(); } lblMessage.Visible = true; lblMessage.Text = "Your information has been successfully saved."; clear(); } else { lblMessage.Visible = true; lblMessage.Text = "Your e-mail registered already !"; } } else { lblMessage.Visible = true; lblMessage.Text = "Your e-mail registered already !"; } }