Esempio n. 1
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();
            }
        }
    }
Esempio n. 2
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.";
                            }
                        }
                    }
                }
            }
        }
    }
    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"; }
    }