public static BplTransactionUserToEstab getbpTransactionUserToEstabyID(string bplUserToEstabTrasactionID)
    {
        BplTransactionUserToEstab m = new BplTransactionUserToEstab();

        try
        {
            SqlCommand command = new SqlCommand("Select * from BplTransactionUserToEstab where bplUserToEstabTrasactionID=@bplUserToEstabTrasactionID");
            command.Connection = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                m.bplUserToEstabTrasactionID = reader["bplUserToEstabTrasactionID"].ToString();
                BPMatchUserToEstab es = BPMatchUserToEstabDB.getBloodRequestsMatchbyID(reader["bpMatchUsrEstID"].ToString());
                m.bpMatchUsrEstID = es;
                m.unit            = Convert.ToInt32(reader["unitsPossible"]);
                m.status          = reader["status"].ToString();
            }
            reader.Close();
        }
        finally
        {
            connection.Close();
        }
        return(m);
    }
Beispiel #2
0
    protected void gvAcceptedEstabRequests_SelectedIndexChanged(object sender, EventArgs e)
    {
        BloodPlateletRequestUser         selectedRequest      = userRequests[gvRequestInfo.PageSize * gvRequestInfo.PageIndex + gvRequestInfo.SelectedIndex];
        List <BplTransactionUserToEstab> allEstabTransactions = BplTransactionUserToEstabDB.getAllbpTransactionUserToEsta();

        foreach (BplTransactionUserToEstab m in allEstabTransactions)
        {
            if (m.bpMatchUsrEstID.bpRequestID.bplUserRequestID == selectedRequest.bplUserRequestID && m.status == "accepted")
            {
                estabsAccepted.Add(m);
            }
        }

        BplTransactionUserToEstab selectedTransaction = estabsAccepted[gvAcceptedEstabRequests.PageSize * gvAcceptedEstabRequests.PageIndex + gvAcceptedEstabRequests.SelectedIndex];

        selectedTransaction.status = "complete";
        BplTransactionUserToEstabDB.updateBPTranscationUserToEstab(selectedTransaction);
        gvAcceptedEstabRequests.DataBind();

        BPMatchUserToEstab currentMatch = selectedTransaction.bpMatchUsrEstID;

        currentMatch.status = "declined";
        BPMatchUserToEstabDB.updateBPMatchUserToEstab(currentMatch);

        if (selectedRequest.Units == selectedRequest.unitMatched)
        {
            selectedRequest.Status = "complete";
            BloodPlateletRequestUserDB.updateBloodPlateles(selectedRequest);
            gvRequestInfo.DataBind();
        }
    }
    public static List <BplTransactionUserToEstab> getAllbpTransactionUserToEstabyTime(DateTime from, DateTime to)
    {
        List <BplTransactionUserToEstab> matches = new List <BplTransactionUserToEstab>();

        try
        {
            SqlCommand command = new SqlCommand("Select * from BplTransactionUserToEstab WHERE requestDate BETWEEN @fromdate AND @todate");
            command.Connection = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                BplTransactionUserToEstab m = new BplTransactionUserToEstab();
                m.bplUserToEstabTrasactionID = reader["bplUserToEstabTrasactionID"].ToString();
                BPMatchUserToEstab es = BPMatchUserToEstabDB.getBloodRequestsMatchbyID(reader["bpMatchUsrEstID"].ToString());
                m.bpMatchUsrEstID = es;
                m.unit            = Convert.ToInt32(reader["unitsPossible"]);
                m.status          = reader["status"].ToString();
                matches.Add(m);
            }
            reader.Close();
        }
        finally
        {
            connection.Close();
        }
        return(matches);
    }
Beispiel #4
0
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        BloodPlateletRequestUser bpru = BloodPlateletRequestUserDB.getUserBloodRequestsbyID(lblRID.Text);

        bpru.Status = "cancelled";
        int num = BloodPlateletRequestUserDB.updateBloodPlateles(bpru);

        if (num != 1)
        {
            lblOutput.Text = "Cannot Cancel Request Right Now!";
            return;
        }
        else
        {
            lblOutput.Text = "Cancel Successful! u can check history in the following table";
            //if donation cancel change the status of matching also
            List <BPMatchUserToUser> bpmuulist = BPMatchUserToUserDB.getAllUserBloodRequestsbyUserID(bpru.bplUserRequestID);
            foreach (BPMatchUserToUser b in bpmuulist)
            {
                b.status = "declined";
                BPMatchUserToUserDB.updateMatchUserToUser(b);
            }
            List <BPMatchUserToEstab> bpmuelist = BPMatchUserToEstabDB.getAllBloodRequestsMatchbyUserID(bpru.bplUserRequestID);
            foreach (BPMatchUserToEstab be in bpmuelist)
            {
                be.status = "declined";
                BPMatchUserToEstabDB.updateBPMatchUserToEstab(be);
            }
        }
    }
    protected void lbtnContact1_Click(object sender, EventArgs e)
    {
        Establishment             currentEstab    = (Establishment)Session["establishment"];
        LinkButton                lbtn            = (LinkButton)sender;
        GridViewRow               gvr             = (GridViewRow)lbtn.NamingContainer;
        int                       i               = Convert.ToInt32(gvr.RowIndex);
        List <BPMatchUserToEstab> allUserRequests = BPMatchUserToEstabDB.getAllbpMatchUserToEsta();
        List <BPMatchUserToEstab> userRequests    = new List <BPMatchUserToEstab>();

        foreach (BPMatchUserToEstab m in allUserRequests)
        {
            if (m.matchID.ID == currentEstab.ID && m.status == "pending" && m.bpRequestID.unitMatched < m.bpRequestID.Units)
            {
                userRequests.Add(m);
            }
        }
        BPMatchUserToEstab currentMatch = userRequests[i];
        Users contactUser = currentMatch.bpRequestID.requestorID;

        Session["ldID"]  = contactUser.UserId;
        Session["rwEst"] = null;
        Session["echat"] = null;
        Server.Transfer("IndividualChatE.aspx");
        //store session for individual chat in next page
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["establishment"] == null)
        {
            Server.Transfer("Login.aspx");
        }
        else
        {
            Establishment          currentEstab     = (Establishment)Session["establishment"];
            List <EstabEstabMatch> allEstabRequests = EstabEstabMatchDB.getAllMatches();
            List <EstabEstabMatch> estabRequests    = new List <EstabEstabMatch>();
            foreach (EstabEstabMatch m in allEstabRequests)
            {
                if (m.Match.ID == currentEstab.ID && m.Status == "pending" && m.Request.MatchedUnits < m.Request.Units)
                {
                    estabRequests.Add(m);
                }
            }
            if (estabRequests.Count == 0)
            {
                lblOutput.Text           = "There are currently no requests from establishments";
                pnlEstabRequests.Visible = false;
            }
            else
            {
                gvEstabRequests.DataSource = estabRequests;
                gvEstabRequests.DataBind();
            }

            List <BPMatchUserToEstab> allUserRequests = BPMatchUserToEstabDB.getAllbpMatchUserToEsta();
            List <BPMatchUserToEstab> userRequests    = new List <BPMatchUserToEstab>();
            foreach (BPMatchUserToEstab m in allUserRequests)
            {
                if (m.matchID.ID == currentEstab.ID && m.status == "pending" && m.bpRequestID.unitMatched < m.bpRequestID.Units)
                {
                    userRequests.Add(m);
                }
            }
            if (userRequests.Count == 0)
            {
                lblOutput.Text          = "There are currently no requests from users";
                pnlUserRequests.Visible = false;
            }
            else
            {
                gvUserRequests.DataSource = userRequests;
                gvUserRequests.DataBind();
            }
        }
    }
    protected void gvUserRequests_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Establishment             currentEstab    = (Establishment)Session["establishment"];
        List <BPMatchUserToEstab> allUserRequests = BPMatchUserToEstabDB.getAllbpMatchUserToEsta();
        List <BPMatchUserToEstab> userRequests    = new List <BPMatchUserToEstab>();

        foreach (BPMatchUserToEstab m in allUserRequests)
        {
            if (m.matchID.ID == currentEstab.ID && m.status == "pending" && m.bpRequestID.unitMatched < m.bpRequestID.Units)
            {
                userRequests.Add(m);
            }
        }
        gvUserRequests.PageIndex  = e.NewPageIndex;
        gvUserRequests.DataSource = userRequests;
        gvUserRequests.DataBind();
    }
    protected void gvUserRequests_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Establishment             currentEstab    = (Establishment)Session["establishment"];
        List <BPMatchUserToEstab> allUserRequests = BPMatchUserToEstabDB.getAllbpMatchUserToEsta();
        List <BPMatchUserToEstab> userRequests    = new List <BPMatchUserToEstab>();

        foreach (BPMatchUserToEstab m in allUserRequests)
        {
            if (m.matchID.ID == currentEstab.ID && m.status == "pending" && m.bpRequestID.unitMatched < m.bpRequestID.Units)
            {
                userRequests.Add(m);
            }
        }
        BPMatchUserToEstab currentMatch = userRequests[gvUserRequests.PageSize * gvUserRequests.PageIndex + e.RowIndex];

        currentMatch.status = "declined";
        BPMatchUserToEstabDB.updateBPMatchUserToEstab(currentMatch);
        Server.Transfer("IncomingRequests.aspx");
    }
    protected void btnUserSubmit_Click(object sender, EventArgs e)
    {
        Establishment             currentEstab    = (Establishment)Session["establishment"];
        List <BPMatchUserToEstab> allUserRequests = BPMatchUserToEstabDB.getAllbpMatchUserToEsta();
        List <BPMatchUserToEstab> userRequests    = new List <BPMatchUserToEstab>();

        foreach (BPMatchUserToEstab m in allUserRequests)
        {
            if (m.matchID.ID == currentEstab.ID && m.status == "pending" && m.bpRequestID.unitMatched < m.bpRequestID.Units)
            {
                userRequests.Add(m);
            }
        }
        BPMatchUserToEstab        currentMatch   = userRequests[gvUserRequests.PageSize * gvUserRequests.PageIndex + gvUserRequests.SelectedIndex];
        BloodPlateletRequestUser  r              = currentMatch.bpRequestID;
        BplTransactionUserToEstab newTransaction = new BplTransactionUserToEstab();
        int donateUnits = Convert.ToInt32(tbxUserUnits.Text);

        if (donateUnits > (currentMatch.bpRequestID.Units - currentMatch.bpRequestID.unitMatched))
        {
            lblUserOutput.Text = "Please enter a valid amount";
        }
        else
        {
            currentMatch.status = "accepted";
            BPMatchUserToEstabDB.updateBPMatchUserToEstab(currentMatch);
            newTransaction.bpMatchUsrEstID = currentMatch;
            newTransaction.unit            = donateUnits;
            newTransaction.status          = "accepted";
            BplTransactionUserToEstabDB.insertbptrans(newTransaction);
            r.unitMatched = r.unitMatched + donateUnits;
            BloodPlateletRequestUserDB.updateBloodPlateles(r);
            lblOutput.Text        = "Donation successfully accepted!";
            pnlAcceptUser.Visible = false;
            tbxUserUnits.Text     = "";
            Server.Transfer("IncomingRequests.aspx");
        }
    }
Beispiel #10
0
    protected void btnRequest_Click(object sender, EventArgs e)
    {
        string groups, estname, type;
        int    unit;

        if (RadioBlood.Checked)
        {
            groups = "blood";
        }
        else
        {
            groups = "platelet";
        }
        if (tbxAmount.Text == "")
        {
            lblAmount.Visible = true;
            return;
        }
        else
        {
            lblAmount.Visible = false;
            unit = Convert.ToInt32(tbxAmount.Text);
        }
        estname = ddlEstablish.SelectedItem.Text;
        Establishment es = EstablishmentDB.getEstablishmentByName(estname);
        Users         u  = UsersDB.getUserbyEmail(Session["email"].ToString());

        type = ddlBloodType.SelectedValue;
        BloodPlateletRequestUser b = new BloodPlateletRequestUser(unit, 0, es, u, type, "pending", groups, DateTime.Now);
        int num = BloodPlateletRequestUserDB.insertBloodRequestByUser(b);

        if (num != 1)
        {
            lblOutput.Text = "Cannot Request Blood!";
            return;
        }
        else
        {
            lblOutput.Text = "Request Successful!";


            List <BloodPlateletRequestUser> bloodPlateletRequestUser = BloodPlateletRequestUserDB.getAllUserBloodRequests();

            string x      = bloodPlateletRequestUser[0].bplUserRequestID;
            int    tempID = Convert.ToInt32(x.Substring(4, x.Length - 4));
            foreach (BloodPlateletRequestUser bpr in bloodPlateletRequestUser)
            {
                if (tempID < Convert.ToInt32(bpr.bplUserRequestID.Substring(4, bpr.bplUserRequestID.Length - 4)) && bpr.requestorID.UserId == u.UserId)
                {
                    tempID = Convert.ToInt32(bpr.bplUserRequestID.Substring(4, bpr.bplUserRequestID.Length - 4));
                }
            }

            BloodPlateletRequestUser request        = BloodPlateletRequestUserDB.getUserBloodRequestsbyID("bpur" + Convert.ToString(tempID));
            List <Establishment>     establishments = EstablishmentDB.getAllEstablishments();
            foreach (Establishment est in establishments)
            {
                BPMatchUserToEstab newMatch = new BPMatchUserToEstab();
                if ((est.Type == "Hospital" || est.Type == "Blood Bank") && request.Establishment.ID != est.ID)
                {
                    int d = getDistance(est.Address, request.Establishment.Address);
                    if (d < 3600 && d > 0)
                    {
                        newMatch.bpRequestID = request;
                        newMatch.matchID     = est;
                        newMatch.distance    = d;
                        newMatch.status      = "pending";
                        int nums = BPMatchUserToEstabDB.insertbp(newMatch);
                        if (nums != 1)
                        {
                            lblOutput.Text = "Cannot Request Blood!";
                            return;
                        }
                        else
                        {
                            lblOutput.Text = "Request Successful!";
                        }
                    }
                }
            }
            List <Users>            users    = UsersDB.getallUsers();
            List <LastDonationDate> lastDate = LastDonationDateDB.getAllLastDonations();
            foreach (Users usr in users)
            {
                BPMatchUserToUser newMatchU = new BPMatchUserToUser();

                string userGroup    = usr.BloodType;
                string requestGroup = request.Type;
                bool   f            = false;
                if (requestGroup == "AB+")
                {
                    f = true;
                }
                else if (requestGroup == "AB-" && (userGroup == "O-" || userGroup == "B-" || userGroup == "A-" || userGroup == "AB-"))
                {
                    f = true;
                }
                else if (requestGroup == "A+" && (userGroup == "O-" || userGroup == "O+" || userGroup == "A-" || userGroup == "A+"))
                {
                    f = true;
                }
                else if (requestGroup == "A-" && (userGroup == "O-" || userGroup == "A-"))
                {
                    f = true;
                }
                else if (requestGroup == "B+" && (userGroup == "O-" || userGroup == "O+" || userGroup == "B-" || userGroup == "B+"))
                {
                    f = true;
                }
                else if (requestGroup == "B-" && (userGroup == "O-" || userGroup == "B-"))
                {
                    f = true;
                }
                else if (requestGroup == "O+" && (userGroup == "O-" || userGroup == "O+"))
                {
                    f = true;
                }
                else if (requestGroup == "O-" && (userGroup == "O-"))
                {
                    f = true;
                }
                if ((request.requestorID.UserId != usr.UserId) && (f == true) && (usr.MedicalStatus.ToLower() == "can donate") && (usr.status == "Allow"))
                {
                    foreach (LastDonationDate lddate in lastDate)
                    {
                        if ((lddate.User.UserId == usr.UserId))
                        {
                            if ((lddate.LastDonation < System.DateTime.Now.AddDays(-90) && lddate.Type == "blood") || (lddate.LastDonation < System.DateTime.Now.AddDays(-14) && lddate.Type == "platelet") && lddate.Status == "Not in transaction")
                            {
                                string origin = usr.Latitude + "," + usr.Longtitude;
                                int    d      = getDistance(origin, request.Establishment.Address);
                                if (d < 3600)
                                {
                                    newMatchU.bplUsrRequestID = request;
                                    newMatchU.matchID         = usr;
                                    newMatchU.distance        = d;
                                    newMatchU.status          = "pending";
                                    BPMatchUserToUserDB.insertbpusertoUser(newMatchU);
                                }
                            }
                        }
                    }
                }
            }
            string DRUrl = "DonateAndRequest.aspx";
            Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=3;url={0}> ", DRUrl)));
        }
        //}
    }