public BloodPosting GetBloodPosting(int id) { BloodPosting bp = new BloodPosting(); using (SqlConnection con = new SqlConnection(Queries.connection)) { con.Open(); SqlCommand command = new SqlCommand { Connection = con, CommandType = CommandType.Text, CommandText = Queries.getBloodPostingById }; command.Parameters.Add(Constants.id, SqlDbType.Int).Value = id; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { bp.Id = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.id))); bp.BloodGroup = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.bloodGroup))); bp.State = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.state))); bp.Area = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.area))); bp.Pincode = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.pincode))); bp.ContactNumber = Convert.ToInt64(reader.GetValue(reader.GetOrdinal(Constants.contactNumber))); } reader.Close(); } return(bp); }
public List <BloodPosting> AlertUserSpecificMatchBlood(int userId) { List <BloodPosting> bpList = new List <BloodPosting>(); using (SqlConnection con = new SqlConnection(Queries.connection)) { con.Open(); SqlCommand command = new SqlCommand { Connection = con, CommandType = CommandType.Text, CommandText = Queries.getBloodPostingByUserBloodMatch }; command.Parameters.Add(Constants.paramUserId, SqlDbType.Int).Value = userId; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { BloodPosting bp = new BloodPosting(); bp.Id = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.id))); bp.BloodGroup = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.bloodGroup))); bp.State = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.state))); bp.Area = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.area))); bp.Pincode = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.pincode))); bp.ContactNumber = Convert.ToInt64(reader.GetValue(reader.GetOrdinal(Constants.contactNumber))); bpList.Add(bp); } reader.Close(); } return(bpList); }
public List <BloodPosting> GetAllBloodPostings() { List <BloodPosting> bpList = new List <BloodPosting>(); using (SqlConnection con = new SqlConnection(Queries.connection)) { con.Open(); SqlCommand command = new SqlCommand { Connection = con, CommandType = CommandType.Text, CommandText = Queries.getAllBloodPostings }; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { BloodPosting bp = new BloodPosting(); bp.Id = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.id))); bp.BloodGroup = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.bloodGroup))); bp.State = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.state))); bp.Area = Convert.ToString(reader.GetValue(reader.GetOrdinal(Constants.area))); bp.Pincode = Convert.ToInt32(reader.GetValue(reader.GetOrdinal(Constants.pincode))); bp.ContactNumber = Convert.ToInt64(reader.GetValue(reader.GetOrdinal(Constants.contactNumber))); bpList.Add(bp); } reader.Close(); } return(bpList); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { if (Session[Constants.userId].ToString() != null || Session[Constants.userId].ToString() != "") { lblUserId.Text = Session[Constants.userId].ToString(); } lblUserId.Visible = false; Session[Constants.userId] = lblUserId.Text; string bloodPostingId = Request.QueryString[Constants.id].ToString(); Session["bloodPostingId"] = bloodPostingId; BloodBL bl = new BloodBL(); UserBL userBL = new UserBL(); if (int.Parse(bloodPostingId) != 0) { BloodPosting bp = bl.GetBloodPosting(int.Parse(bloodPostingId)); User userDetails = userBL.GetUser(Session[Constants.userEmail].ToString()); if (!bp.BloodGroup.Equals(userDetails.BloodGroup)) { Response.Write("<script>alert('Posted Blood not matched with your Blood. Please Choose other to Donate Blood');window.location.href='HomePage.aspx'</script>"); } } panelMyLocation.Visible = false; panelOtherLocation.Visible = false; /* * List<string> states = bl.GetAllStates(); * ddlStateOtherLocation.DataSource = states; * ddlStateOtherLocation.DataBind(); */ ddlStateOtherLocation.Items.Add("Andhra Pradesh"); ddlStateOtherLocation.Items.Insert(0, "Select State"); } catch (Exception ex) { Response.Write("<script>alert('Your session expired...Please login again');window.location.href='HomePageBeforeLogin.aspx'</script>"); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { BloodPosting blood = new BloodPosting(); blood.State = ddlState.SelectedValue.ToString(); blood.Area = ddlArea.SelectedValue.ToString(); blood.Pincode = int.Parse(txtPincode.Text.ToString()); blood.BloodGroup = ddlBloodGroup.SelectedValue.ToString(); blood.ContactNumber = long.Parse(txtPhnNumber.Text.ToString()); BloodBL bl = new BloodBL(); int result = bl.PostBlood(blood, int.Parse(lblUserId.Text)); if (result == 1) { Response.Write("<script>alert('Your blood details posted successfully');window.location.href='HomePage.aspx'</script>"); } } catch (Exception ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } }
public int PostBlood(BloodPosting bp, int userId) { int result = 0; using (SqlConnection con = new SqlConnection(Queries.connection)) { con.Open(); SqlCommand command = new SqlCommand { Connection = con, CommandType = CommandType.Text, CommandText = Queries.postBlood }; command.Parameters.Add(Constants.paramContactNumber, SqlDbType.BigInt).Value = bp.ContactNumber; command.Parameters.Add(Constants.paramState, SqlDbType.VarChar).Value = bp.State; command.Parameters.Add(Constants.paramArea, SqlDbType.VarChar).Value = bp.Area; command.Parameters.Add(Constants.paramPincode, SqlDbType.Int).Value = bp.Pincode; command.Parameters.Add(Constants.paramBloodGroup, SqlDbType.VarChar).Value = bp.BloodGroup; command.Parameters.Add(Constants.userId, SqlDbType.Int).Value = userId; result = command.ExecuteNonQuery(); } return(result); }