public static List <EstabUserTransaction> getAllTransactions()
    {
        List <EstabUserTransaction> transactions = new List <EstabUserTransaction>();

        try
        {
            SqlCommand command = new SqlCommand("Select * from BplTransactionEstabToUser");
            command.Connection = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                EstabUserTransaction t = new EstabUserTransaction();
                t.ID     = reader["bplEstabTrasactionID"].ToString();
                t.Match  = EstabUserMatchDB.getUserMatchByID(reader["bpMatchEstabUserID"].ToString());
                t.Units  = Convert.ToInt32(reader["unitsPossible"]);
                t.Status = reader["status"].ToString();
                transactions.Add(t);
            }
            reader.Close();
        }
        finally
        {
            connection.Close();
        }
        return(transactions);
    }
Пример #2
0
    protected void gvUserMatches_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        EstablishmentBPRequest      selectedRequest     = pendingRequests[gvRequests.PageSize * gvRequests.PageIndex + gvRequests.SelectedIndex];
        List <EstabUserTransaction> allUserTransactions = EstabUserTransactionDB.getAllTransactions();

        foreach (EstabUserTransaction m in allUserTransactions)
        {
            if (m.Match.Request.ID == selectedRequest.ID && m.Status == "accepted")
            {
                userTransactions.Add(m);
            }
        }
        EstabUserTransaction selectedTransaction = userTransactions[e.RowIndex];

        selectedTransaction.Status = "cancelled";
        EstabUserTransactionDB.updateTransaction(selectedTransaction);


        selectedTransaction.Match.Status = "declined";
        EstabUserMatchDB.updateMatch(selectedTransaction.Match);

        selectedRequest.MatchedUnits = selectedRequest.MatchedUnits - selectedTransaction.Units;
        EstablishmentBPRequestDB.updateEstablishmentRequest(selectedRequest);
        Server.Transfer("PendingRequests.aspx");
    }
Пример #3
0
    protected void gvUserMatches_SelectedIndexChanged(object sender, EventArgs e)
    {
        EstablishmentBPRequest      selectedRequest     = pendingRequests[gvRequests.PageSize * gvRequests.PageIndex + gvRequests.SelectedIndex];
        List <EstabUserTransaction> allUserTransactions = EstabUserTransactionDB.getAllTransactions();

        foreach (EstabUserTransaction m in allUserTransactions)
        {
            if (m.Match.Request.ID == selectedRequest.ID && m.Status == "accepted")
            {
                userTransactions.Add(m);
            }
        }
        EstabUserTransaction selectedTransaction = userTransactions[gvUserMatches.SelectedIndex];

        selectedTransaction.Status = "complete";
        EstabUserTransactionDB.updateTransaction(selectedTransaction);


        EstabUserMatch currentMatch = selectedTransaction.Match;

        currentMatch.Status = "complete";
        EstabUserMatchDB.updateMatch(currentMatch);

        Users currentUser = currentMatch.Match;
        List <LastDonationDate> allLastDates = LastDonationDateDB.getAllLastDonations();

        foreach (LastDonationDate ld in allLastDates)
        {
            if (ld.User.UserId == currentUser.UserId)
            {
                ld.LastDonation = DateTime.Today;
                ld.Type         = currentMatch.Request.Type;
                ld.Status       = "Not in transaction";
                LastDonationDateDB.updateLastDonation(ld);
            }
        }



        if (selectedRequest.MatchedUnits == selectedRequest.Units)
        {
            selectedRequest.Status = "complete";
            EstablishmentBPRequestDB.updateEstablishmentRequest(selectedRequest);
            foreach (EstabUserTransaction ut in allUserTransactions)
            {
                if (ut.Match.Request.ID == selectedRequest.ID)
                {
                    ut.Status = "complete";
                    EstabUserTransactionDB.updateTransaction(ut);
                    ut.Match.Status = "complete";
                    EstabUserMatchDB.updateMatch(ut.Match);
                }
            }
        }

        Server.Transfer("PendingRequests.aspx");
    }
Пример #4
0
    protected void gvRequests_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        EstablishmentBPRequest selectedRequest = pendingRequests[gvRequests.PageSize * gvRequests.PageIndex + e.RowIndex];
        int noTransactions = 0;
        List <EstabEstabTransaction> allEstabTransactions = EstabEstabTransactionDB.getAllTransactions();
        List <EstabUserTransaction>  allUserTransactions  = EstabUserTransactionDB.getAllTransactions();

        foreach (EstabEstabTransaction m in allEstabTransactions)
        {
            if (m.Match.Request.ID == selectedRequest.ID && m.Status == "complete")
            {
                noTransactions = 1;
            }
        }
        foreach (EstabUserTransaction m in allUserTransactions)
        {
            if (m.Match.Request.ID == selectedRequest.ID && m.Status == "complete")
            {
                noTransactions = 2;
            }
        }
        if (noTransactions == 1 || noTransactions == 2)
        {
            lblOutput.Text = "Sorry this request cannot be cancelled!";
        }
        else
        {
            foreach (EstabEstabTransaction m in allEstabTransactions)
            {
                if (m.Match.Request.ID == selectedRequest.ID)
                {
                    m.Status = "cancelled";
                    EstabEstabTransactionDB.updateTransaction(m);
                    m.Match.Status = "declined";
                    EstabEstabMatchDB.updateMatch(m.Match);
                }
            }
            foreach (EstabUserTransaction m in allUserTransactions)
            {
                if (m.Match.Request.ID == selectedRequest.ID)
                {
                    m.Status = "cancelled";
                    EstabUserTransactionDB.updateTransaction(m);
                    m.Match.Status = "declined";
                    EstabUserMatchDB.updateMatch(m.Match);
                }
            }

            selectedRequest.Status = "cancelled";
            EstablishmentBPRequestDB.updateEstablishmentRequest(selectedRequest);
            Server.Transfer("PendingRequests.aspx");
        }
    }
Пример #5
0
    //protected void gvUserMatches_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    gvUserMatches.PageIndex = e.NewPageIndex;
    //    gvUserMatches.DataSource = userTransactions;
    //    gvUserMatches.DataBind();
    //}

    //protected void gvEstabMatches_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    gvEstabMatches.PageIndex = e.NewPageIndex;
    //    gvEstabMatches.DataSource = estabTransactions;
    //    gvEstabMatches.DataBind();
    //}



    protected void lbtnReport_Click(object sender, EventArgs e)
    {
        LinkButton             lbtn            = (LinkButton)sender;
        GridViewRow            gvr             = (GridViewRow)lbtn.NamingContainer;
        int                    i               = Convert.ToInt32(gvr.RowIndex);
        EstablishmentBPRequest selectedRequest = pendingRequests[gvRequests.PageSize * gvRequests.PageIndex + gvRequests.SelectedIndex];

        List <EstabUserTransaction> allUserTransactions = EstabUserTransactionDB.getAllTransactions();

        foreach (EstabUserTransaction m in allUserTransactions)
        {
            if (m.Match.Request.ID == selectedRequest.ID && m.Status == "accepted")
            {
                userTransactions.Add(m);
            }
        }

        EstabUserTransaction selectedTransaction = userTransactions[i];
        Users reportedUser = selectedTransaction.Match.Match;

        reportedUser.MedicalStatus         = "cannot donate";
        reportedUser.MedicalStatusUpdateBy = ((Establishment)Session["establishment"]).ID;
        UsersDB.updateUser(reportedUser);
        List <LastDonationDate> allLastDates = LastDonationDateDB.getAllLastDonations();

        foreach (LastDonationDate ld in allLastDates)
        {
            if (ld.User.UserId == reportedUser.userId)
            {
                ld.LastDonation = DateTime.Today;
                ld.Type         = selectedRequest.Type;
                ld.Status       = "Not in transaction";
                LastDonationDateDB.updateLastDonation(ld);
            }
        }

        selectedTransaction.Status = "cancelled";
        EstabUserTransactionDB.updateTransaction(selectedTransaction);

        selectedTransaction.Match.Status = "declined";
        EstabUserMatchDB.updateMatch(selectedTransaction.Match);

        selectedRequest.MatchedUnits = selectedRequest.MatchedUnits - selectedTransaction.Units;
        EstablishmentBPRequestDB.updateEstablishmentRequest(selectedRequest);
        Server.Transfer("PendingRequests.aspx");
    }
Пример #6
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //sending request if the amount is greater than 1
        if (Convert.ToInt32(tbxAmount.Text) > 0)
        {
            Establishment          currentEstab     = (Establishment)Session["establishment"];
            EstablishmentBPRequest currentRequestBP = new EstablishmentBPRequest();
            currentRequestBP.BloodGroup    = ddlBloodType.SelectedValue;
            currentRequestBP.Units         = Convert.ToInt32(tbxAmount.Text);
            currentRequestBP.MatchedUnits  = 0;
            currentRequestBP.Type          = ddlRequestType.SelectedValue;
            currentRequestBP.Establishment = currentEstab;
            currentRequestBP.Status        = "pending";
            currentRequestBP.RequestDate   = DateTime.Today;
            int num = EstablishmentBPRequestDB.insertEstablishmentRequest(currentRequestBP);
            if (num != 1)
            {
                lblOutput.Text = "Cannot";
            }
            else
            {
                List <EstablishmentBPRequest> establishmentBPRequest = EstablishmentBPRequestDB.getAllEstablishmentRequests();
                //get inserted request
                string x      = establishmentBPRequest[0].ID;
                int    tempId = Convert.ToInt32(x.Substring(4, x.Length - 4));
                foreach (EstablishmentBPRequest tempReq in establishmentBPRequest)
                {
                    int t = Convert.ToInt32(tempReq.ID.Substring(4, tempReq.ID.Length - 4));

                    if (tempId <= t && tempReq.Establishment.ID == currentEstab.ID)
                    {
                        tempId = Convert.ToInt32(tempReq.ID.Substring(4, tempReq.ID.Length - 4));
                    }
                }
                EstablishmentBPRequest request = EstablishmentBPRequestDB.getRequestByID("bper" + Convert.ToString(tempId));
                lblOutput.Text = "Your request ID is bper" + tempId;
                List <Establishment> establishments = EstablishmentDB.getAllEstablishments();
                foreach (Establishment est in establishments)
                {
                    EstabEstabMatch newMatch = new EstabEstabMatch();
                    if ((est.Type == "Hospital" || est.Type == "Blood Bank") && currentEstab.ID != est.ID)
                    {
                        int d = getDistance(est.Address, currentEstab.Address);
                        if (d < 3600)
                        {
                            newMatch.Request  = request;
                            newMatch.Match    = est;
                            newMatch.Distance = d;
                            newMatch.Status   = "pending";
                            EstabEstabMatchDB.insertMatch(newMatch);
                        }
                    }
                }
                List <Users>            users    = UsersDB.getallUsers();
                List <LastDonationDate> allDates = LastDonationDateDB.getAllLastDonations();

                foreach (Users tusr in users)
                {
                    EstabUserMatch newMatch     = new EstabUserMatch();
                    string         userGroup    = tusr.BloodType;
                    string         requestGroup = request.BloodGroup;
                    bool           f            = false;
                    //check blood to match with other user
                    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 match found check his medical status and status
                    if (f == true && tusr.medicalStatus.ToLower() == "can donate" && tusr.Status == "Allow")
                    {
                        foreach (LastDonationDate d in allDates)
                        {
                            if (d.User.userId == tusr.userId)
                            {
                                if ((d.LastDonation < System.DateTime.Now.AddDays(-90) && d.Type == "blood") || (d.LastDonation < System.DateTime.Now.AddDays(-14) && d.Type == "platelet") && d.Status == "Not in transaction")
                                {
                                    int d1 = getDistance(Convert.ToString(tusr.latitude) + "," + Convert.ToString(tusr.longtitude), currentEstab.Address);
                                    if (d1 < 3600)
                                    {
                                        newMatch.Match    = tusr;
                                        newMatch.Request  = request;
                                        newMatch.Status   = "pending";
                                        newMatch.Distance = d1;
                                        EstabUserMatchDB.insertMatch(newMatch);
                                    }
                                }
                            }
                        }
                    }
                }

                tbxAmount.Text               = "";
                ddlBloodType.SelectedIndex   = 0;
                ddlRequestType.SelectedIndex = 0;
                string MyAccountUrl = "RequestBlood.aspx";
                Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=4;url={0}> ", MyAccountUrl)));
            }
        }
        else
        {
            lblOutput.Text = "Blood amount cannot be 0 or less than that";
            return;
        }
    }