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; } } }
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"; } }