Example #1
0
    public static LiveOrganMatching getMatchByID(string id)
    {
        LiveOrganMatching m = new LiveOrganMatching();

        try
        {
            SqlCommand command = new SqlCommand("Select * from organMatchingLive where liveOrganMatch = @id");
            command.Parameters.AddWithValue("@id", id);
            command.Connection = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                m.ID         = reader["liveOrganMatch"].ToString();
                m.LiveDonor  = LiveDonorDB.getLiveDonorbyID(reader["ldonorID"].ToString());
                m.Recipient  = OrganRecipientDB.getRecipientByID(reader["OrganWlID"].ToString());
                m.MatchScore = Convert.ToInt32(reader["matchScore"]);
                m.Comments   = reader["comments"].ToString();
                m.Status     = reader["status"].ToString();
                m.Distance   = Convert.ToInt32(reader["distance"]);
            }
            reader.Close();
        }
        finally
        {
            connection.Close();
        }
        return(m);
    }
Example #2
0
    public static List <LiveOrganMatching> getAllMatches()
    {
        List <LiveOrganMatching> matches = new List <LiveOrganMatching>();

        try
        {
            SqlCommand command = new SqlCommand("Select * from organMatchingLive");
            command.Connection = connection;
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                LiveOrganMatching m = new LiveOrganMatching();
                m.ID         = reader["liveOrganMatch"].ToString();
                m.LiveDonor  = LiveDonorDB.getLiveDonorbyID(reader["ldonorID"].ToString());
                m.Recipient  = OrganRecipientDB.getRecipientByID(reader["OrganWlID"].ToString());
                m.MatchScore = Convert.ToInt32(reader["matchScore"]);
                m.Comments   = reader["comments"].ToString();
                m.Status     = reader["status"].ToString();
                m.Distance   = Convert.ToInt32(reader["distance"]);
                matches.Add(m);
            }
            reader.Close();
        }
        finally
        {
            connection.Close();
        }
        return(matches);
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Users            u      = UsersDB.getUserbyEmail(Session["email"].ToString());
        List <LiveDonor> ldlist = LiveDonorDB.getLiveDonorbyuserID(u.userId);

        foreach (LiveDonor l in ldlist)
        {
            if (l.status == "not allotted")
            {
                id = l.ldonorID;
                break;
            }
        }
        if (id != null)
        {
            LiveDonor nowld = LiveDonorDB.getLiveDonorbyID(id);

            nowld.status = "cancelled";
            int num = LiveDonorDB.updateLiveDonor(nowld);
            if (num != 1)
            {
                lblDOutput.Text = "Sorry cancel Failed!";
            }
            else
            {
                lblDOutput.Text = "Your organ donation is now cancelled!";
                string DonateOrganUrl = "DonateOrgan.aspx";
                Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=2;url={0}> ", DonateOrganUrl)));
            }
        }
        else
        {
            lblDOutput.Text = "Sorry cancel Failed!";
        }
    }
Example #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Session["email"] == null)
         {
             Server.Transfer("CommonLogin.aspx");
         }
         else
         {
             Users            u          = UsersDB.getUserbyEmail(Session["email"].ToString());
             List <LiveDonor> ldLists    = LiveDonorDB.getLiveDonorbyuserID(u.userId);
             List <LiveDonor> cancellist = new List <LiveDonor>();
             foreach (LiveDonor l in ldLists)
             {
                 if (l.status == "cancelled" || l.status == "allotted")
                 {
                     cancellist.Add(l);
                 }
             }
             if (cancellist.Count == 0)
             {
                 Label1.Text = "Sorry! You don't have any transcation yet!";
                 return;
             }
             else
             {
                 Label1.Text = "We found " + cancellist.Count + " Donation History!";
                 cancellist.Reverse();
                 gvDHistory.DataSource = cancellist;
                 gvDHistory.DataBind();
             }
         }
     }
 }
Example #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["establishment"] == null)
        {
            Server.Transfer("Login.aspx");
        }

        else
        {
            List <LiveDonor> ldLists = LiveDonorDB.getallLiveDonor();
            foreach (LiveDonor ld in ldLists)
            {
                if (ld.Status == "complete" || ld.status == "allotted")
                {
                    ldpastLists.Add(ld);
                }
                else if (ld.status == "not allotted")
                {
                    ldcurrentLists.Add(ld);
                }
            }

            if (ldcurrentLists.Count == 0)
            {
                lblSorry.Visible = true;
                Panel1.Visible   = false;
            }
            else
            {
                lblSorry.Visible     = false;
                Panel1.Visible       = true;
                gvRequest.DataSource = ldcurrentLists;
                gvRequest.DataBind();
            }

            if (ldpastLists.Count == 0)
            {
                lblsorry2.Visible = true;
                Panel2.Visible    = false;
            }
            else
            {
                lblsorry2.Visible     = false;
                Panel2.Visible        = true;
                gvDHistory.DataSource = ldpastLists;
                gvDHistory.DataBind();
            }
        }
    }
Example #6
0
    protected void btnDSubmit_Click(object sender, EventArgs e)
    {
        if (Convert.ToInt32(tbxDPhone.Text) <= 0)
        {
            lblDOutput.Text = "Phone number is in incorrect format";
            return;
        }
        else
        {
            string ogtype;
            string Dname    = tbxDoctor.Text;
            int    Dphone   = Convert.ToInt32(tbxDPhone.Text);
            string Demail   = TbxDEmail.Text;
            string Daddress = tbxDAddress.Text;
            if (ddlOrgan.SelectedIndex == 0)
            {
                lblOrgan.Visible = true;
                return;
            }
            else
            {
                ogtype = ddlOrgan.SelectedValue;
            }
            if (tbxComment.Text == "")
            {
                comment = "-";
            }
            else
            {
                comment = tbxComment.Text;
            }
            Users u = UsersDB.getUserbyEmail(Session["email"].ToString());
            //add code for finding match here
            LiveDonor ld  = new LiveDonor(u, ogtype, comment, "not allotted", Dname, Dphone, Daddress, Demail);
            int       num = LiveDonorDB.insertLiveDonor(ld);
            if (num != -1)
            {
                LiveDonor        tLiveDonor;
                List <LiveDonor> tDonorList = LiveDonorDB.getLiveDonorbyuserID(u.userId);
                tLiveDonor = tDonorList[0];
                foreach (LiveDonor tld in tDonorList)
                {
                    if (tld.status == "not allotted")
                    {
                        tLiveDonor = tld;
                    }
                }

                List <OrganRecipient> allRecievers = OrganRecipientDB.getAllRecipients();
                bool f = false;
                foreach (OrganRecipient r in allRecievers)
                {
                    int    y   = 0;
                    String bt1 = u.bloodtype;
                    String bt2 = r.Bloodgroup;
                    if ((bt1 == "A+" || bt1 == "A-") && (bt2 == "A+" || bt2 == "A-" || bt2 == "AB+" || bt2 == "AB-"))
                    {
                        y = 1;
                    }
                    else if ((bt1 == "B+" || bt1 == "B-") && (bt2 == "B+" || bt2 == "B-" || bt2 == "AB+" || bt2 == "AB-"))
                    {
                        y = 1;
                    }
                    else if ((bt1 == "AB+" || bt1 == "AB-") && (bt2 == "AB+" || bt2 == "AB-"))
                    {
                        y = 1;
                    }
                    else if ((bt1 == "O+" || bt1 == "O-") && (bt2 == "A+" || bt2 == "A-" || bt2 == "AB+" || bt2 == "AB-" || bt2 == "B+" || bt2 == "B-" || bt2 == "O+" || bt2 == "O-"))
                    {
                        y = 1;
                    }

                    if (y == 1 && tLiveDonor.OrganType == r.Organrequired && r.Status == "waiting")
                    {
                        float d     = getDistance(u.address, r.Establishment.Address);
                        int   score = 0;
                        int   d1    = Convert.ToInt32(d);
                        d = d / 3600;
                        int wTimeScore = 0, distanceScore = 0;
                        if (d < 5)
                        {
                            distanceScore = 5;
                        }
                        else if (d < 15)
                        {
                            distanceScore = 4;
                        }
                        else if (d < 25)
                        {
                            distanceScore = 3;
                        }
                        else if (d < 35)
                        {
                            distanceScore = 2;
                        }
                        else if (d < 45)
                        {
                            distanceScore = 1;
                        }
                        else
                        {
                            distanceScore = 0;
                        }

                        double days = (DateTime.Today - r.Addedon).TotalDays;

                        if (days < 180)
                        {
                            wTimeScore = 1;
                        }
                        else if (days < 365)
                        {
                            wTimeScore = 2;
                        }
                        else if (days < 1095)
                        {
                            wTimeScore = 3;
                        }
                        else if (days < 1825)
                        {
                            wTimeScore = 4;
                        }
                        else
                        {
                            wTimeScore = 5;
                        }

                        score = r.Urgency * 3 + distanceScore + wTimeScore;

                        LiveOrganMatching match = new LiveOrganMatching();
                        match.LiveDonor  = tLiveDonor;
                        match.MatchScore = score;
                        match.Recipient  = r;
                        match.Status     = "pending";
                        match.Comments   = "NIL";
                        match.Distance   = d1;
                        LiveOrganMatchingDB.insertMatch(match);
                        f = true;
                    }
                }
                if (f == true)
                {
                    List <LiveOrganMatching> liveMatches     = LiveOrganMatchingDB.getAllMatches();
                    List <LiveOrganMatching> liveMatchesCurr = new List <LiveOrganMatching>();
                    foreach (LiveOrganMatching LOM1 in liveMatches)
                    {
                        if (LOM1.LiveDonor.LdonorID == tLiveDonor.LdonorID)
                        {
                            liveMatchesCurr.Add(LOM1);
                        }
                    }
                    LiveOrganMatching tempLOM = liveMatchesCurr[0];
                    foreach (LiveOrganMatching LOM in liveMatchesCurr)
                    {
                        if (LOM.MatchScore > tempLOM.MatchScore)
                        {
                            tempLOM = LOM;
                        }
                    }
                    tempLOM.Status = "current match";
                    LiveOrganMatchingDB.updateMatch(tempLOM);
                    tLiveDonor.status = "allotted";
                    LiveDonorDB.updateLiveDonor(tLiveDonor);
                    tempLOM.Recipient.Status = "allotted";
                    OrganRecipientDB.updateOrganRecipient(tempLOM.Recipient);
                }
                PanelRegisterDonor.Visible = false;
                Server.Transfer("HistoryOrgan.aspx");
            }
            else
            {
                PanelRegisterDonor.Visible = true;
                lblDOutput.Text            = "Registration Fail! Please Try Again.";
                return;
            }
        }
    }
Example #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["email"] == null)
            {
                Server.Transfer("CommonLogin.aspx");
            }
            else
            {
                string email = Session["email"].ToString();
                Users  nu    = UsersDB.getUserbyEmail(email);
                if (nu.weight == 0)
                {
                    PanelUpdate.Visible        = true;
                    PanelWeight.Visible        = true;
                    PanelRegisterDonor.Visible = false;
                    w = 0;
                }
                else
                {
                    w = 1;
                }

                if (nu.height == 0)
                {
                    PanelUpdate.Visible        = true;
                    PanelHeight.Visible        = true;
                    PanelRegisterDonor.Visible = false;
                    h = 0;
                }
                else
                {
                    h = 1;
                }

                if (nu.emergencyname == "null")
                {
                    PanelUpdate.Visible        = true;
                    PanelEmergency.Visible     = true;
                    PanelRegisterDonor.Visible = false;
                    ec = 0;
                }
                else
                {
                    ec = 1;
                }

                if (ec == 1 && h == 1 && w == 1)
                {
                    Users            u      = UsersDB.getUserbyEmail(Session["email"].ToString());
                    List <LiveDonor> ldlist = LiveDonorDB.getallLiveDonor();

                    foreach (LiveDonor ld in ldlist)
                    {
                        if (ld.userid.userId == u.userId && (ld.status == "not allotted" || ld.status == "allotted"))
                        {
                            lblHeading.Text            = "Donation History";
                            PanelRegisterDonor.Visible = false;
                            Label1.Visible             = true;
                            Label1.Text = "Well Done! You are already part of live organ donation. You doesn't need sign up again.";
                            break;
                        }
                        else
                        {
                            lblHeading.Text            = "Please fill this form to register as a organ donor.";
                            PanelRegisterDonor.Visible = true;
                            Label1.Visible             = false;
                            if ((u.Weight * 1000) / (u.height * u.height) > 30)
                            {
                                PanelRegisterDonor.Visible = false;
                                lblHeading.Text            = "Donate Organ";
                                Label1.Visible             = true;
                                Label1.Text = "Sorry! You're health condition doesn't allow you to donate organ.";
                            }
                        }
                    }
                }
            }
        }
    }
Example #8
0
    protected void btnDecline_Click(object sender, EventArgs e)
    {
        List <OrganRecipient> ourRecipients = new List <OrganRecipient>();
        List <OrganRecipient> allRecipients = OrganRecipientDB.getAllRecipients();
        Establishment         currentEstab  = (Establishment)Session["establishment"];

        foreach (OrganRecipient r in allRecipients)
        {
            if (r.Establishment.ID == currentEstab.ID && (r.Status == "waiting" || r.Status == "allotted"))
            {
                ourRecipients.Add(r);
            }
        }
        OrganRecipient        currentRecipient = ourRecipients[gvRecipients.PageSize * gvRecipients.PageIndex + gvRecipients.SelectedIndex];
        DeceasedOrganMatching deadOrgan        = new DeceasedOrganMatching();
        LiveOrganMatching     liveOrgan        = new LiveOrganMatching();
        int matchFound = 0;
        List <DeceasedOrganMatching> allDeadMatches     = DeceasedOrganMatchingDB.getAllMatches();
        List <LiveOrganMatching>     allLiveMatches     = LiveOrganMatchingDB.getAllMatches();
        List <DeceasedOrganMatching> allDeadMatchesCurr = new List <DeceasedOrganMatching>();
        List <LiveOrganMatching>     allLiveMatchesCurr = new List <LiveOrganMatching>();
        bool checkMatchD = false;
        bool checkMatchL = false;

        foreach (DeceasedOrganMatching d in allDeadMatches)
        {
            if (d.Recipient.ID == currentRecipient.ID && d.Status == "current match")
            {
                matchFound = 1;
                deadOrgan  = d;
            }
            else if (d.Recipient.ID == currentRecipient.ID && d.Status == "pending" && d.DeceasedDonor.Status == "not allotted")
            {
                allDeadMatchesCurr.Add(d);
                checkMatchD = true;
            }
        }
        foreach (LiveOrganMatching l in allLiveMatches)
        {
            if (l.Recipient.ID == currentRecipient.ID && l.Status == "current match")
            {
                matchFound = 2;
                liveOrgan  = l;
            }
            else if (l.Recipient.ID == currentRecipient.ID && l.Status == "pending" && l.LiveDonor.status == "not allotted")
            {
                allLiveMatchesCurr.Add(l);
                checkMatchL = true;
            }
        }
        if (matchFound == 0)
        {
            lblOutput.Text = "Sorry no matches yet!";
        }
        else if (matchFound == 2)
        {
            // tempCurrentMatch = deadOrgan.ID;
            liveOrgan.Status = "not possible";
            LiveOrganMatchingDB.updateMatch(liveOrgan);
        }
        else if (matchFound == 1)
        {
            // tempCurrentMatch = liveOrgan.ID;
            deadOrgan.Status = "not possible";
            DeceasedOrganMatchingDB.updateMatch(deadOrgan);
        }
        LiveOrganMatching tempLDM = new LiveOrganMatching();

        if (checkMatchL == true)
        {
            tempLDM = allLiveMatchesCurr[0];
            foreach (LiveOrganMatching ldm in allLiveMatchesCurr)
            {
                if (ldm.MatchScore > tempLDM.MatchScore)
                {
                    tempLDM = ldm;
                }
            }
        }
        DeceasedOrganMatching tempDOM = new DeceasedOrganMatching();

        if (checkMatchD == true)
        {
            tempDOM = allDeadMatchesCurr[0];
            foreach (DeceasedOrganMatching dom in allDeadMatchesCurr)
            {
                if (dom.MatchScore > tempDOM.MatchScore)
                {
                    tempDOM = dom;
                }
            }
        }
        if (checkMatchD == true && checkMatchL == true)
        {
            if (tempDOM.MatchScore < tempLDM.MatchScore)
            {
                tempLDM.Status = "current match";
                LiveOrganMatchingDB.updateMatch(tempLDM);
                LiveDonor tempItem = LiveDonorDB.getLiveDonorbyID(tempLDM.LiveDonor.LdonorID);
                tempItem.status = "allotted";
                LiveDonorDB.updateLiveDonor(tempItem);
            }
            else
            {
                tempDOM.Status = "current match";
                DeceasedOrganMatchingDB.updateMatch(tempDOM);
                DeceasedDonor tempItem = DeceasedDonorDB.getDonorByID(tempDOM.DeceasedDonor.ID);
                tempItem.Status = "allotted";
                DeceasedDonorDB.updateDeceasedDonor(tempItem);
            }
        }
        else if (checkMatchD == true && checkMatchL == false)
        {
            tempDOM.Status = "current match";
            DeceasedOrganMatchingDB.updateMatch(tempDOM);
            DeceasedDonor tempItem = DeceasedDonorDB.getDonorByID(tempDOM.DeceasedDonor.ID);
            tempItem.Status = "allotted";
            DeceasedDonorDB.updateDeceasedDonor(tempItem);
        }
        else if (checkMatchL == true && checkMatchD == false)
        {
            tempLDM.Status = "current match";
            LiveOrganMatchingDB.updateMatch(tempLDM);
            LiveDonor tempItem = LiveDonorDB.getLiveDonorbyID(tempLDM.LiveDonor.LdonorID);
            tempItem.status = "allotted";
            LiveDonorDB.updateLiveDonor(tempItem);
        }
        else
        {
            currentRecipient.Status = "waiting";
            OrganRecipientDB.updateOrganRecipient(currentRecipient);
        }
        Label1.Text = "Successfully completed";
        string MyAccountUrl = "RecipientWaitingList.aspx";

        Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=2;url={0}> ", MyAccountUrl)));
    }
Example #9
0
    protected void btnAccept_Click(object sender, EventArgs e)
    {
        List <OrganRecipient> ourRecipients = new List <OrganRecipient>();
        List <OrganRecipient> allRecipients = OrganRecipientDB.getAllRecipients();
        Establishment         currentEstab  = (Establishment)Session["establishment"];

        foreach (OrganRecipient r in allRecipients)
        {
            if (r.Establishment.ID == currentEstab.ID && (r.Status == "waiting" || r.Status == "allotted"))
            {
                ourRecipients.Add(r);
            }
        }
        OrganRecipient        currentRecipient = ourRecipients[gvRecipients.PageSize * gvRecipients.PageIndex + gvRecipients.SelectedIndex];
        DeceasedOrganMatching deadOrgan        = new DeceasedOrganMatching();
        LiveOrganMatching     liveOrgan        = new LiveOrganMatching();
        int matchFound = 0;
        List <DeceasedOrganMatching> allDeadMatches = DeceasedOrganMatchingDB.getAllMatches();
        List <LiveOrganMatching>     allLiveMatches = LiveOrganMatchingDB.getAllMatches();

        foreach (DeceasedOrganMatching d in allDeadMatches)
        {
            if (d.Recipient.ID == currentRecipient.ID && d.Status == "current match")
            {
                matchFound = 1;
                deadOrgan  = d;
            }
        }
        foreach (LiveOrganMatching l in allLiveMatches)
        {
            if (l.Recipient.ID == currentRecipient.ID && l.Status == "current match")
            {
                matchFound = 2;
                liveOrgan  = l;
            }
        }
        pnlMatch.Visible = true;
        if (matchFound == 0)
        {
            lblOutput.Text = "Sorry no matches yet!";
        }
        else if (matchFound == 1)
        {
            currentRecipient.Status = "complete";
            OrganRecipientDB.updateOrganRecipient(currentRecipient);
            deadOrgan.DeceasedDonor.Status = "complete";
            DeceasedDonorDB.updateDeceasedDonor(deadOrgan.DeceasedDonor);
            deadOrgan.Status = "complete";
            DeceasedOrganMatchingDB.updateMatch(deadOrgan);



            foreach (DeceasedOrganMatching d2 in allDeadMatches)
            {
                if (d2.DeceasedDonor.ID == deadOrgan.DeceasedDonor.ID && d2.Status != "complete")
                {
                    d2.Status = "not possible";
                    DeceasedOrganMatchingDB.updateMatch(d2);
                }
            }

            foreach (DeceasedOrganMatching dd in allDeadMatches)
            {
                if (dd.Recipient.ID == currentRecipient.ID && dd.Status != "complete")
                {
                    dd.Status = "not possible";
                    DeceasedOrganMatchingDB.updateMatch(dd);
                }
            }

            foreach (LiveOrganMatching ll in allLiveMatches)
            {
                if (ll.Recipient.ID == currentRecipient.ID && ll.Status != "complete")
                {
                    ll.Status = "not possible";
                    LiveOrganMatchingDB.updateMatch(ll);
                }
            }
            Label1.Text = "Successfully completed";
            string MyAccountUrl = "RecipientWaitingList.aspx";
            Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=2;url={0}> ", MyAccountUrl)));
        }
        else if (matchFound == 2)
        {
            currentRecipient.Status = "complete";
            OrganRecipientDB.updateOrganRecipient(currentRecipient);
            liveOrgan.LiveDonor.Status = "complete";
            LiveDonorDB.updateLiveDonor(liveOrgan.LiveDonor);
            liveOrgan.Status = "complete";
            LiveOrganMatchingDB.updateMatch(liveOrgan);



            foreach (LiveOrganMatching l2 in allLiveMatches)
            {
                if (l2.LiveDonor.LdonorID == liveOrgan.LiveDonor.LdonorID && l2.Status != "complete")
                {
                    l2.Status = "not possible";
                    LiveOrganMatchingDB.updateMatch(l2);
                }
            }

            foreach (DeceasedOrganMatching dd in allDeadMatches)
            {
                if (dd.Recipient.ID == currentRecipient.ID && dd.Status != "complete")
                {
                    dd.Status = "not possible";
                    DeceasedOrganMatchingDB.updateMatch(dd);
                }
            }
            foreach (LiveOrganMatching ll in allLiveMatches)
            {
                if (ll.Recipient.ID == currentRecipient.ID && ll.Status != "complete")
                {
                    ll.Status = "not possible";
                    LiveOrganMatchingDB.updateMatch(ll);
                }
            }
            Label1.Text = "Successfully completed";
            string MyAccountUrl = "RecipientWaitingList.aspx";
            Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=2;url={0}> ", MyAccountUrl)));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["email"] == null)
            {
                Server.Transfer("CommonLogin.aspx");
            }
            else
            {
                Users            u      = UsersDB.getUserbyEmail(Session["email"].ToString());
                List <LiveDonor> ldlist = LiveDonorDB.getLiveDonorbyuserID(u.userId);
                if (ldlist.Count == 0)
                {
                    Label1.Text = "Sorry! You doesn't have any current organ donation!";
                    PanelFinishRegister.Visible = false;
                }
                else
                {
                    foreach (LiveDonor l in ldlist)
                    {
                        if (l.status == "not allotted" || l.status == "allotted")
                        {
                            tempid = l.ldonorID;
                            PanelFinishRegister.Visible = true;
                            break;
                        }
                        else
                        {
                            tempid = "0";
                        }
                    }
                    if (tempid == "0")
                    {
                        Label1.Text = "Sorry! You doesn't have any current organ donation!";
                        PanelFinishRegister.Visible = false;
                    }
                    else
                    {
                        LiveDonor ld = LiveDonorDB.getLiveDonorbyID(tempid);

                        PanelFinishRegister.Visible = true;
                        lblComment.Text             = ld.comments;
                        lblDAddress.Text            = ld.doctorAddress;
                        lblDEmail.Text = ld.doctorEmail;
                        lblDoctor.Text = ld.doctorName;
                        lblDPhone.Text = Convert.ToString(ld.doctorNumber);
                        lblOrgan.Text  = ld.organType;
                        lblstatus.Text = ld.status;
                    }
                }

                List <LiveOrganMatching> lom     = LiveOrganMatchingDB.getAllMatches();
                List <LiveOrganMatching> lomshow = new List <LiveOrganMatching>();
                if (lom.Count == 0)
                {
                    lblmatchingF.Text = "Sorry! We haven't found any matching for you right now.";
                    gvMatch.Visible   = false;
                }
                else
                {
                    foreach (LiveOrganMatching l in lom)
                    {
                        if (l.LiveDonor.userid.UserId == u.UserId && l.Status == "current match")
                        {
                            l.Distance = l.Distance / 60;
                            lomshow.Add(l);
                        }
                    }

                    if (lomshow.Count == 0)
                    {
                        lblmatchingF.Text     = "Sorry! We haven't found any matching for you right now.";
                        panelmatching.Visible = false;
                    }
                    else
                    {
                        panelmatching.Visible = true;
                        gvMatch.DataSource    = lomshow;
                        gvMatch.DataBind();
                    }
                }
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            OrganRecipient or = new OrganRecipient();
            or.Establishment = (Establishment)Session["establishment"];
            or.Bloodgroup    = ddlBloodType.SelectedValue;
            or.DOB           = Convert.ToDateTime(tbxDate.Text);
            or.Height        = Convert.ToInt32(tbxHeight.Text);
            or.Weight        = Convert.ToInt32(tbxWeight.Text);
            or.Addedon       = DateTime.Today;
            or.Organrequired = rbtnlstOrganType.SelectedValue;
            or.Comments      = tbxComments.Text;
            or.Urgency       = Convert.ToInt32(ddlUrgency.SelectedValue);
            or.Refnumber     = tbxReference.Text;
            or.Status        = "waiting";
            OrganRecipientDB.insertOrganRecipient(or);


            Establishment currentEstab = (Establishment)Session["establishment"];
            string        address      = currentEstab.Address;

            List <LiveDonor> allLiveDonors = LiveDonorDB.getallLiveDonor();
            OrganRecipient   tReciepient;
            //donor id from database
            List <OrganRecipient> allReciepients = OrganRecipientDB.getAllRecipients();
            String x      = allReciepients[0].ID;
            int    tempId = Convert.ToInt32(x.Substring(4, x.Length - 4));
            foreach (OrganRecipient dd in allReciepients)
            {
                if (tempId < Convert.ToInt32(dd.ID.Substring(4, dd.ID.Length - 4)) && dd.Establishment.ID == currentEstab.ID)
                {
                    tempId = Convert.ToInt32(dd.ID.Substring(4, dd.ID.Length - 4));
                }
            }
            tReciepient = OrganRecipientDB.getRecipientByID("orwl" + Convert.ToString(tempId));
            //end of getting last one
            bool f = false;

            foreach (LiveDonor ldnr in allLiveDonors)
            {
                int    y   = 0;
                String bt2 = or.Bloodgroup;
                String bt1 = ldnr.Userid.BloodType;
                if ((bt1 == "A+" || bt1 == "A-") && (bt2 == "A+" || bt2 == "A-" || bt2 == "AB+" || bt2 == "AB-"))
                {
                    y = 1;
                }
                else if ((bt1 == "B+" || bt1 == "B-") && (bt2 == "B+" || bt2 == "B-" || bt2 == "AB+" || bt2 == "AB-"))
                {
                    y = 1;
                }
                else if ((bt1 == "AB+" || bt1 == "AB-") && (bt2 == "AB+" || bt2 == "AB-"))
                {
                    y = 1;
                }
                else if ((bt1 == "O+" || bt1 == "O-") && (bt2 == "A+" || bt2 == "A-" || bt2 == "AB+" || bt2 == "AB-" || bt2 == "B+" || bt2 == "B-" || bt2 == "O+" || bt2 == "O-"))
                {
                    y = 1;
                }

                if (ldnr.OrganType == or.Organrequired && y == 1 && ldnr.status == "not allotted")
                {
                    string matchAddress = ldnr.Userid.Address;
                    float  d            = getDistance(address, matchAddress);
                    int    score        = 0;
                    int    d1           = Convert.ToInt32(d);
                    d = d / 3600;

                    int wTimeScore = 0, distanceScore = 0;
                    if (d < 5)
                    {
                        distanceScore = 5;
                    }
                    else if (d < 15)
                    {
                        distanceScore = 4;
                    }
                    else if (d < 25)
                    {
                        distanceScore = 3;
                    }
                    else if (d < 35)
                    {
                        distanceScore = 2;
                    }
                    else if (d < 45)
                    {
                        distanceScore = 1;
                    }
                    else
                    {
                        distanceScore = 0;
                    }

                    wTimeScore = 1;

                    score = or.Urgency * 3 + distanceScore + wTimeScore;

                    LiveOrganMatching match = new LiveOrganMatching();
                    match.LiveDonor  = ldnr;
                    match.Recipient  = tReciepient;
                    match.MatchScore = score;
                    match.Comments   = "NIL";
                    match.Status     = "pending";
                    match.Distance   = d1;
                    LiveOrganMatchingDB.insertMatch(match);
                    f = true;
                }
            }
            if (f == true)
            {
                bool f1 = false;
                List <LiveOrganMatching> liveMatches   = LiveOrganMatchingDB.getAllMatches();
                List <LiveOrganMatching> liveMatchCurr = new List <LiveOrganMatching>();
                foreach (LiveOrganMatching LOM in liveMatches)
                {
                    if (LOM.Recipient == tReciepient)
                    {
                        liveMatchCurr.Add(LOM);
                        f1 = true;
                    }
                }
                if (f1 == true)
                {
                    bool f3 = false;
                    List <LiveOrganMatching> tempDOMList = new List <LiveOrganMatching>();
                    foreach (LiveOrganMatching LOM1 in liveMatchCurr)
                    {                       //also check for highest score
                        foreach (LiveOrganMatching LOM2 in liveMatches)
                        {
                            if (LOM1.LiveDonor == LOM2.LiveDonor && LOM2.Status == "current match")
                            {
                                f3 = true;
                            }
                        }
                        if (f3 == false)
                        {
                            tempDOMList.Add(LOM1);
                        }
                    }
                    LiveOrganMatching tempDOM = tempDOMList[0];

                    foreach (LiveOrganMatching t in tempDOMList)
                    {
                        if (t.MatchScore > tempDOM.MatchScore)
                        {
                            tempDOM = t;
                        }
                    }
                    tempDOM.Status = "current match";
                    LiveOrganMatchingDB.updateMatch(tempDOM);
                }
            }
            lblOutput.Text             = "Recipient successfully added!";
            tbxDate.Text               = "";
            tbxHeight.Text             = "";
            tbxWeight.Text             = "";
            tbxComments.Text           = "";
            tbxReference.Text          = "";
            ddlBloodType.SelectedIndex = 0;
            ddlUrgency.SelectedIndex   = 0;
            string MyAccountUrl = "RecipientWaitingList.aspx";
            Page.Header.Controls.Add(new LiteralControl(string.Format(@" <META http-equiv='REFRESH' content=2;url={0}> ", MyAccountUrl)));
        }
        catch { lblOutput.Text = "Please Check The Entered Values"; }
    }