private async void UpdateProcedureParticipants(ProcedureParticipantDetails procParticipant,UIButton btnField)
		{
			if(procParticipant.StartTime == string.Empty)
				procParticipant.StartTime  = "00:00";

			if(procParticipant.EndTime == string.Empty)
				procParticipant.EndTime = "00:00";
			
			if (btnField.CurrentTitle != "" && btnField.CurrentTitle != null) {
				    procParticipant.ProcID = procedureDetails.ID;
				ReceiveContext updContext = await AppDelegate.Current.pqrsMgr.AddUpdateProcedureParticipants(procParticipant);
     			if (updContext != null && updContext.status != null && updContext.status.ToUpper () == "OK") {
						Console.WriteLine ("Participant: " + btnField.TitleLabel.Text + " Updated Successfully");
						if (procParticipant.RoleID == 2 && selectedAnestheologistList.Count > 0) 
							selectedAnestheologistList.RemoveAt (selectedAnestheologistList.FindIndex (x => x.UserID == procParticipant.UserID));


						if (procParticipant.RoleID == 6 && selectedCRNAList.Count > 0)
							selectedCRNAList.RemoveAt (selectedCRNAList.FindIndex(x => x.UserID == procParticipant.UserID));

						
					UpdateProcedureStatus ();
						ProcedureParticipantDetails participant = (ProcedureParticipantDetails)JsonConvert.DeserializeObject (updContext.result.ToString (), typeof(ProcedureParticipantDetails));
					    ProcParticipantID=participant.ProcParticipantID;
						//if (btnField.Tag == 0)
						//	btnField.Tag = participant.ProcParticipantID;


					if (procParticipant.RoleID == 2) {
						selectedAnestheologistList.Remove(selectedAnestheologistList.Find(u=>u.ProcParticipantID==participant.ProcParticipantID));
						selectedAnestheologistList.Add (participant);
					}

					if (procParticipant.RoleID == 6) {
						selectedCRNAList.Remove(selectedCRNAList.Find(u=>u.ProcParticipantID==participant.ProcParticipantID));
						selectedCRNAList.Add (participant);
					}

					} else {
					    NavigationController.PopToRootViewController(true);
						Console.WriteLine ("Error Updating..UpdateProcedureParticipants(ProcedureParticipantDetails procParticipant,UIButton btnField)... ");							
					}
			} 
		}
		public void AddAnesView(ProcedureParticipantDetails participantDetails)
		{
			try
			{
				anesadded = true;
				UIView view = uvProviderView.ViewWithTag(AnesCount+100);
				if (view != null) {
					UIButton checkbtn=(UIButton)view.ViewWithTag(2);
					if (checkbtn != null && string.IsNullOrEmpty (checkbtn.TitleLabel.Text)) {
						new UIAlertView("Anes Info", "Please Update Anes"+AnesCount+" Record."
												, null, "ok", null).Show();
						return; 
					}
				}

				AnesCount = AnesCount + 1;
				UIView  uvblock=new UIView();
				uvblock.Tag = AnesCount+100;
				uvblock.Frame = new CoreGraphics.CGRect (0, Anesheight, 497, 100);
				Anesheight = Anesheight+100;
				UILabel lbltitle=new UILabel(new CoreGraphics.CGRect(5, 10,100,40));
				lbltitle.Text="Anes ("+AnesCount+"):";	

				UITextView hideid=new UITextView();
				hideid.Hidden=true;
				UIButton anesNameBtn = new UIButton(new CoreGraphics.CGRect(145, 5,350,30));
				anesNameBtn.Tag =  2;
				anesNameBtn.Layer.BorderWidth = 1;
				anesNameBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
				anesNameBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
				if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.Name)) {
						anesNameBtn.SetTitle (participantDetails.Name, UIControlState.Normal);
						anesNameBtn.Tag =  participantDetails.ProcParticipantID;
				} else {
					if (AnesCount == 1) {
						if(iProPQRSPortableLib.Consts.Role.Trim().ToLower() == "anesthesiologist")
							anesNameBtn.SetTitle (iProPQRSPortableLib.Consts.LoginUserFullName, UIControlState.Normal);
						
							if(participantDetails == null)
								participantDetails = new ProcedureParticipantDetails();
						
//							UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserLastName.ToLower() && x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserFirstName.ToLower());
							UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName == iProPQRSPortableLib.Consts.UserLastName && x.FirstName == iProPQRSPortableLib.Consts.UserFirstName);
							if(userDetails != null)
							{
								participantDetails.UserID = userDetails.ID;
								participantDetails.ProcParticipantID = 0;
								participantDetails.RoleID = 2;
								participantDetails.Name = anesNameBtn.CurrentTitle;
								if(anesNameBtn != null && anesNameBtn.CurrentTitle.Trim() != string.Empty){
									AddUpdateProcedureParticipants(participantDetails,anesNameBtn);
								}
							}
					}
				}
				anesNameBtn.Layer.CornerRadius = 5; 
				anesNameBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
				anesNameBtn.TouchUpInside += async delegate {
					try
					{
						if(listOfAnestheologists.Count > 0){
							if(participantDetails == null)
								participantDetails = new ProcedureParticipantDetails();

							participantDetails.RoleID = 2;
							BindParticipantsPopupover(listOfAnestheologists,anesNameBtn,(int)anesNameBtn.Frame.Y,participantDetails);
						}
					}
					catch{
						
					}
			};
			UILabel slblstar = new UILabel (new CoreGraphics.CGRect (214, 47, 10, 41));
			slblstar.Text = "*";
			slblstar.TextColor = UIColor.Red;

			UILabel lblstart= new UILabel(new CoreGraphics.CGRect(135, 50,80,30));
			lblstart.Text = "Start Time";

			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			UIButton startTimeBtn=new UIButton(new CoreGraphics.CGRect(230, 50,80,30));
			startTimeBtn.Tag=11;
			startTimeBtn.Layer.BorderWidth = 1;
			startTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			startTimeBtn.Layer.CornerRadius = 5; 
			startTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			startTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);			
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.StartTime)) {
				DateTime dt = DateTime.Parse(participantDetails.StartTime);
				if(dt.ToString("HH:mm") == "00:00")
					startTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
				else
					startTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);
			}
			if(participantDetails != null)
				{
				startTimeBtn.Tag = participantDetails.ProcParticipantID;
					ProcParticipantID=participantDetails.ProcParticipantID;
				}
				if(participantDetails == null && PrevHourTime !=0){
					if(PrevminTime != 60){						
						PrevminTime=+PrevminTime+1;
					}
					DateTime dt=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,PrevHourTime,PrevminTime,0);

				
					string strtime=PrevHourTime.ToString();
					strtime=dt.ToString("HH:mm");
					if(dt.ToString("HH:mm") == "00:00")
						strtime = string.Empty;;

					startTimeBtn.SetTitle(strtime,UIControlState.Normal);
				}
			startTimeBtn.TouchUpInside += async delegate {
					
					if(anesNameBtn.Tag==2)
					{
						new UIAlertView("Anes Info", "Please Select Anes Name"
							, null, "ok", null).Show();
						return;							
					}

				TimePicker  tp = new TimePicker();
				tp.PresentFromPopover(startTimeBtn,40,35);
				tp._ValueChanged += delegate {								
						participantDetails.StartTime = tp.SelectedTime;
						if(tp.SelectedTime == "00:00")
							tp.SelectedTime = string.Empty;
						
						startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);

						participantDetails.EndTime = endTimeBtn.CurrentTitle;
						participantDetails.ProcParticipantID=Convert.ToInt16(anesNameBtn.Tag);
						UpdateProcedureParticipants(participantDetails,anesNameBtn);

//						try
//						{
//					if (participantDetails == null)
//						participantDetails = new ProcedureParticipantDetails ();
//
//
//					startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
//					participantDetails.EndTime = endTimeBtn.CurrentTitle;
//					participantDetails.StartTime = startTimeBtn.CurrentTitle;
//
//					if(!string.IsNullOrEmpty(anesNameBtn.CurrentTitle)){
//						if(selectedAnestheologistList.Count > 0){
//							if(startTimeBtn.Tag != 0){
//										participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == ProcParticipantID).UserID;
//										participantDetails.ProcParticipantID = (int)ProcParticipantID;
//							}else{
//										participantDetails.UserID = selectedAnestheologistList.Find(x => x.Name !=null && x.Name.Trim().ToLower() == anesNameBtn.CurrentTitle.Trim().ToLower()).UserID;
//										participantDetails.ProcParticipantID=selectedAnestheologistList.Find(x => x.Name !=null &&  x.Name.Trim().ToLower() == anesNameBtn.CurrentTitle.Trim().ToLower()).ProcParticipantID;
//										//participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == ProcParticipantID).UserID;
//										//participantDetails.ProcParticipantID =ProcParticipantID;
//
//							}
//						}else{
//									UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName != null && x.LastName.Trim().ToLower() + ", " + x.LastName !=null && x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.LoginUserFullName.Trim().ToLower());
//							participantDetails.UserID = userDetails.ID;
//						}
//						participantDetails.RoleID = 2;
//						UpdateProcedureParticipants(participantDetails,anesNameBtn);
//					}
//						}
//						catch (Exception ex)
//						{
//							
//						}
				};
			};

			UILabel elblstar = new UILabel (new CoreGraphics.CGRect (403, 47, 10, 41));
			elblstar.Text = "*";
			elblstar.TextColor = UIColor.Red;

			UILabel lblendtime= new UILabel(new CoreGraphics.CGRect(330, 50,80,30));
			lblendtime.Text = "End Time";

//			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			
			endTimeBtn.Layer.BorderWidth = 1;
			endTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			endTimeBtn.Layer.CornerRadius = 5; 
			endTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			endTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.EndTime)) {
				DateTime dt = DateTime.Parse(participantDetails.EndTime);
					if(dt.ToString("HH:mm") == "00:00")
						endTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
					else
						endTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);
					
					if(dt.ToString("HH:mm") != "00:00"){
						PrevHourTime=dt.Hour;
						PrevminTime=dt.Minute;
					}
			}	
			if(participantDetails != null)
				endTimeBtn.Tag = participantDetails.ProcParticipantID;
			
			endTimeBtn.TouchUpInside += async delegate {

					if(anesNameBtn.Tag==2)
					{
						new UIAlertView("Anes Info", "Please Select Anes Name"
							, null, "ok", null).Show();
						return;							
					}

				TimePicker  tp=new TimePicker();
				tp.PresentFromPopover(endTimeBtn,50,35);
				tp._ValueChanged += delegate {	
						participantDetails.EndTime = tp.SelectedTime;
						if(tp.SelectedTime == "00:00")
							tp.SelectedTime = string.Empty;
						
						endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
						participantDetails.StartTime = startTimeBtn.CurrentTitle;

						participantDetails.ProcParticipantID=Convert.ToInt16(anesNameBtn.Tag);
						UpdateProcedureParticipants(participantDetails,anesNameBtn);

						if(tp.SelectedTime != string.Empty){
							DateTime dt=Convert.ToDateTime(tp.SelectedTime);
							PrevHourTime=dt.Hour;
							PrevminTime=dt.Minute;
						}
//						try
//						{
//					if (participantDetails == null)
//						participantDetails = new ProcedureParticipantDetails ();
//					endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
//					participantDetails.EndTime = endTimeBtn.CurrentTitle;
//					participantDetails.StartTime = startTimeBtn.CurrentTitle;
//
//					if(!string.IsNullOrEmpty(anesNameBtn.CurrentTitle)){
//						if(selectedAnestheologistList.Count > 0){
//							if(endTimeBtn.Tag != 0){
//								participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == endTimeBtn.Tag).UserID;
//								participantDetails.ProcParticipantID = (int)endTimeBtn.Tag;
//							}else{
//
//									//	if(selectedAnestheologistList.Count> 0 && selectedAnestheologistList[0].Name != null )
//										//{
//									//	participantDetails.UserID = selectedAnestheologistList.Find(x => x.Name !=null && x.Name == anesNameBtn.CurrentTitle).UserID;
//										//participantDetails.ProcParticipantID = selectedAnestheologistList.Find(x => x.Name !=null && x.Name == anesNameBtn.CurrentTitle).ProcParticipantID;
//										//}
//										participantDetails.UserID = selectedAnestheologistList.Find(x => x.ProcParticipantID == ProcParticipantID).UserID;
//										participantDetails.ProcParticipantID =ProcParticipantID;
//
//							}
//
//						}else{
//							UserDetails userDetails = listOfAnestheologists.Find (x => x.LastName.Trim().ToLower() + ", " + x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.LoginUserFullName.Trim().ToLower());
//							participantDetails.UserID = userDetails.ID;
//						}
//						participantDetails.RoleID = 2;
//						UpdateProcedureParticipants(participantDetails,anesNameBtn);
//					}
//						}
//						catch (Exception ex)
//						{
//							
//						}
				};
			};

			hideid.Tag=4;
				hideid.Text=anesNameBtn.Tag.ToString();
			uvblock.Add(lblstart);
			uvblock.Add(slblstar);
			uvblock.Add(anesNameBtn);
			uvblock.Add(lbltitle);
			uvblock.Add(startTimeBtn);
			uvblock.Add(lblendtime);
			uvblock.Add(elblstar);
			uvblock.Add(endTimeBtn);
			uvblock.Add(hideid);
			Anesstarttimebtn=startTimeBtn;
			Anesendtimebtn=endTimeBtn;
			UIView uvsp=new UIView(new CGRect(0,96,497,1));
			uvsp.BackgroundColor=UIColor.Black;
			UIView uvleftline=new UIView(new CGRect(497,0,1,100));
			uvleftline.BackgroundColor=UIColor.LightGray;
			uvblock.Add(uvleftline);
			uvblock.Add(uvsp);
			//uvProviderView
			uvProviderView.Add(uvblock);
			//svBillingInfo.Add(uvblock);
			if ((Anesheight - crnahheight) >= 100) {			    
				uvProviderView.Frame = new CGRect (0, 100, 1008, float.Parse (Anesheight.ToString ()) );

				uvBillingProcedureInfo.Frame = new CoreGraphics.CGRect (0, float.Parse (Anesheight.ToString ())+100 , 1008, 800);
				svBillingInfo.SizeToFit ();
				svBillingInfo.ContentSize = new SizeF (float.Parse (svBillingInfo.Frame.Width.ToString ()), float.Parse (svBillingInfo.Frame.Height.ToString ()) + Anesheight + 200);
			}
			}
			catch (Exception ex){
				string str = "";
			}
		}
		public async void AddUpdateProcedureParticipants(ProcedureParticipantDetails procParticipant,UIButton btnField)
		{
//			AppDelegate.pb.Start(this.View,"Updating Participants...");
			if(procParticipant.StartTime == string.Empty)
				procParticipant.StartTime = "00:00";

			if(procParticipant.EndTime == string.Empty)
				procParticipant.EndTime = "00:00";

			procParticipant.ProcID = procedureDetails.ID;

			ReceiveContext context=	await AppDelegate.Current.pqrsMgr.AddUpdateProcedureParticipants(procParticipant);
			if (context != null && context.status != null && context.status.ToUpper () == "OK") {

				ProcedureParticipantDetails participant = (ProcedureParticipantDetails)JsonConvert.DeserializeObject (context.result.ToString (), typeof(ProcedureParticipantDetails));
				//if(btnField.Tag == 0)
				btnField.Tag = participant.ProcParticipantID;

				procParticipant.ProcParticipantID = participant.ProcParticipantID;
				if (procParticipant.RoleID == 2) {
					selectedAnestheologistList.Remove (selectedAnestheologistList.Find (u => u.ProcParticipantID == participant.ProcParticipantID));
					selectedAnestheologistList.Add (participant);
				} else {
					selectedCRNAList.Remove(selectedCRNAList.Find(u=>u.ProcParticipantID==participant.ProcParticipantID));
					selectedCRNAList.Add (participant);
				}
				UpdateProcedureStatus ();
//				AppDelegate.pb.Stop ();
//				new UIAlertView ("Participants", "Successfully Saved", null, "ok", null).Show ();
			} else {
//				AppDelegate.pb.Stop ();
//				new UIAlertView ("Participants", context.message, null, "ok", null).Show ();
			}
		}
		public void AddCRNAView(ProcedureParticipantDetails participantDetails)
		{
			crnaadded = true;
			UIView view = uvProviderView.ViewWithTag(crnacount+200);
			if (view != null) {
				UIButton checkbtn = (UIButton)view.ViewWithTag(2);
				if (checkbtn != null && string.IsNullOrEmpty (checkbtn.TitleLabel.Text)) {
					new UIAlertView("CRNA Info", "Please Update CRNA"+crnacount+" Record."
						, null, "ok", null).Show();
					return; 
				}
			}


			crnacount = crnacount + 1;
			UIView  uvblock= new UIView();
			uvblock.Tag = crnacount+200;
			uvblock.Frame = new CoreGraphics.CGRect (498, crnahheight, 530, 100);
			crnahheight=crnahheight+100;
			UITextView hideid=new UITextView();
			hideid.Hidden=true;
			UILabel lbltitle= new UILabel(new CoreGraphics.CGRect(5, 10,100,40));
			lbltitle.Text="CRNA ("+crnacount+"):";			    		    
			UIButton crnaNameBtn=new UIButton(new CoreGraphics.CGRect(145, 5,350,30));
			crnaNameBtn.Tag =  2;
			crnaNameBtn.Layer.BorderWidth = 1;
			crnaNameBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			crnaNameBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.Name)) {
				crnaNameBtn.SetTitle (participantDetails.Name, UIControlState.Normal);
				crnaNameBtn.Tag = participantDetails.ProcParticipantID;
			} else {
//				if (crnacount ==1 && crnaNameBtn.Tag == 2 && !string.IsNullOrEmpty(crnaNameBtn.CurrentTitle)) {
				if (crnacount ==1 && crnaNameBtn.Tag == 2) {
					if(iProPQRSPortableLib.Consts.Role.Trim().ToLower() == "crna")
						crnaNameBtn.SetTitle (iProPQRSPortableLib.Consts.LoginUserFullName, UIControlState.Normal);
					
					if(participantDetails == null)
						participantDetails = new ProcedureParticipantDetails();

					UserDetails userDetails = null;
					try{
						userDetails = listOfCRNAs.Find (x => x.LastName == iProPQRSPortableLib.Consts.UserLastName && x.FirstName == iProPQRSPortableLib.Consts.UserFirstName);
//						 userDetails = listOfCRNAs.Find (x => x.LastName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserLastName.ToLower() && x.FirstName.Trim().ToLower() == iProPQRSPortableLib.Consts.UserFirstName.ToLower());
					}catch(Exception ex){
						Console.WriteLine ("AddCRNAView Ex: "+ex.Message);
					}

					if (userDetails != null) {
						participantDetails.UserID = userDetails.ID;
						participantDetails.ProcParticipantID = 0;
						participantDetails.RoleID = 6;
						participantDetails.Name = crnaNameBtn.CurrentTitle;//crnaNameBtn.CurrentTitle.Trim();
						if (crnaNameBtn != null && crnaNameBtn.CurrentTitle.Trim () != string.Empty) {
							AddUpdateProcedureParticipants (participantDetails, crnaNameBtn);
						}
					}
				}
			}


			crnaNameBtn.Layer.CornerRadius = 5; 
			crnaNameBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			crnaNameBtn.TouchUpInside += async delegate {
				if(listOfCRNAs.Count > 0){
					
					if(participantDetails == null)
						participantDetails = new ProcedureParticipantDetails();

					participantDetails.RoleID = 6;
					BindParticipantsPopupover(listOfCRNAs,crnaNameBtn,(int)crnaNameBtn.Frame.Y,participantDetails);
				}
			};
			UILabel slblstar = new UILabel (new CoreGraphics.CGRect (214, 47, 10, 41));
			slblstar.Text = "*";
			slblstar.TextColor = UIColor.Red;

			UILabel lblstart = new UILabel(new CoreGraphics.CGRect(135, 50,80,30));
			lblstart.Text = "Start Time";
			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			UIButton startTimeBtn= new UIButton(new CoreGraphics.CGRect(230, 50,80,30));
			startTimeBtn.Tag = 11;
			startTimeBtn.Layer.BorderWidth = 1;
			startTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			startTimeBtn.Layer.CornerRadius = 5; 
			startTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			startTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.StartTime)) {
				DateTime dt = DateTime.Parse(participantDetails.StartTime);
				//dt.ToString("HH:mm");
				if(dt.ToString("HH:mm") == "00:00")
					startTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
				else
					startTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);
			}

			if(participantDetails != null)
				startTimeBtn.Tag = participantDetails.ProcParticipantID;

			if(participantDetails == null && PrevcrnaHourTime !=0)
			{
				if(PrevcrnaminTime != 60)
				{						
					//PrevHourTime=PrevHourTime+1;
					PrevcrnaminTime=+PrevcrnaminTime+1;
				}
				DateTime dt=new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day,PrevcrnaHourTime,PrevcrnaminTime,0);


				string strtime=PrevHourTime.ToString();
				strtime=dt.ToShortTimeString();
				startTimeBtn.SetTitle(strtime,UIControlState.Normal);
			}

			startTimeBtn.TouchUpInside += (object sender, EventArgs e) => {
				if(crnaNameBtn.Tag==2)
				{
					new UIAlertView("Anes Info", "Please Select CRNA Name"
						, null, "ok", null).Show();
					return;							
				}
				TimePicker  tp= new TimePicker();
				tp.PresentFromPopover(startTimeBtn,40,35);
				tp._ValueChanged += delegate {
					try
					{
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();

					participantDetails.StartTime = tp.SelectedTime;
					if(tp.SelectedTime == "00:00")
						tp.SelectedTime = string.Empty;

					startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					
					participantDetails.EndTime = endTimeBtn.CurrentTitle;
					participantDetails.ProcParticipantID= Convert.ToInt16(crnaNameBtn.Tag);

					if(!string.IsNullOrEmpty(crnaNameBtn.CurrentTitle)){
						if(selectedCRNAList.Count > 0){
//							participantDetails.UserID = selectedCRNAList[(int)(startTimeBtn.Tag - 1)].UserID;
//							participantDetails.ProcParticipantID = selectedCRNAList[(int)(startTimeBtn.Tag - 1)].ProcParticipantID;
//
//							if(startTimeBtn.Tag != 0){
//								participantDetails.UserID = selectedCRNAList.Find(x => x.ProcParticipantID == startTimeBtn.Tag).UserID;
//								participantDetails.ProcParticipantID = (int)startTimeBtn.Tag;
//							}else{
//									participantDetails.UserID = selectedCRNAList.Find(x => x.Name!= null && x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).UserID;
//									participantDetails.ProcParticipantID = selectedCRNAList.Find(x => x.Name!= null && x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).ProcParticipantID;
//							}

							participantDetails.RoleID = 6;
							UpdateProcedureParticipants(participantDetails,crnaNameBtn);
						}
					}
					}
					catch
					{
						
					}
				};
			};

			UILabel elblstar = new UILabel (new CoreGraphics.CGRect (403, 47, 10, 41));
			elblstar.Text = "*";
			elblstar.TextColor = UIColor.Red;

			UILabel lblendtime= new UILabel(new CoreGraphics.CGRect(330, 50,80,30));
			lblendtime.Text = "End Time";
			endTimeBtn.Tag = 22;
			endTimeBtn.Layer.BorderWidth = 1;
			endTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			endTimeBtn.Layer.CornerRadius = 5; 
			endTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			endTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.EndTime)) {
				DateTime dt = DateTime.Parse(participantDetails.EndTime);
				//dt.ToString("HH:mm");
				if(dt.ToString("HH:mm") == "00:00")
					endTimeBtn.SetTitle (string.Empty, UIControlState.Normal);
				else
					endTimeBtn.SetTitle (dt.ToString("HH:mm"), UIControlState.Normal);

				if(dt.ToString("HH:mm") != "00:00"){
					PrevcrnaHourTime=dt.Hour;
					PrevcrnaminTime=dt.Minute;
				}
			}	

			if(participantDetails != null)
				endTimeBtn.Tag = participantDetails.ProcParticipantID;
			
			endTimeBtn.TouchUpInside += async delegate {
				if(crnaNameBtn.Tag==2)
				{
					new UIAlertView("Anes Info", "Please Select CRNA Name"
						, null, "ok", null).Show();
					return;							
				}


				TimePicker  tp=new TimePicker();
				tp.PresentFromPopover(endTimeBtn,50,35);
				tp._ValueChanged += delegate {		
					try
					{
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();

					participantDetails.EndTime = tp.SelectedTime;
					if(tp.SelectedTime == "00:00")
						tp.SelectedTime = string.Empty;

					endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					

					participantDetails.StartTime = startTimeBtn.CurrentTitle;
					participantDetails.ProcParticipantID= Convert.ToInt16(crnaNameBtn.Tag);

					if(tp.SelectedTime != string.Empty){
						DateTime dt=Convert.ToDateTime(tp.SelectedTime);
						PrevcrnaHourTime=dt.Hour;
						PrevcrnaminTime=dt.Minute;
					}

					if(!string.IsNullOrEmpty(crnaNameBtn.CurrentTitle)){
						if(selectedCRNAList.Count > 0){

//							if(endTimeBtn.Tag != 0){
//								participantDetails.UserID = selectedCRNAList.Find(x => x.ProcParticipantID == endTimeBtn.Tag).UserID;
//								participantDetails.ProcParticipantID = (int)startTimeBtn.Tag;
//							}else{
//									participantDetails.UserID = selectedCRNAList.Find(x => x.Name!= null &&  x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).UserID;
//									participantDetails.ProcParticipantID = selectedCRNAList.Find(x => x.Name!= null &&  x.Name.Trim().ToLower() == crnaNameBtn.CurrentTitle.Trim().ToLower()).ProcParticipantID;
//							}

							participantDetails.RoleID = 6;
							UpdateProcedureParticipants(participantDetails,crnaNameBtn);
						}
					}
					}
					catch
					{
						
					}

				};
			};
			hideid.Tag=4;
			hideid.Text=crnaNameBtn.Tag.ToString();
			uvblock.Add(lblstart);
			uvblock.Add (slblstar);
			uvblock.Add(crnaNameBtn);
			uvblock.Add(lbltitle);
			uvblock.Add(startTimeBtn);
			uvblock.Add(lblendtime);
			uvblock.Add(endTimeBtn);
			uvblock.Add (elblstar);
			uvblock.Add(hideid);
			crnaStarttime = startTimeBtn;
			crnaendtime = endTimeBtn;
			UIView uvsp = new UIView(new CGRect(0,96,520,1));
			uvsp.BackgroundColor = UIColor.Black;
			UIView uvleftline = new UIView(new CGRect(0,0,1,100));
			uvleftline.BackgroundColor = UIColor.LightGray;
			uvblock.Add(uvleftline);
			uvblock.Add(uvsp);
			//uvProviderView
			uvProviderView.Add(uvblock);
			//svBillingInfo.Add(uvblock);
			//Anesheight - crnahheight
			if (( crnahheight-Anesheight) >= 100) {
				uvProviderView.Frame = new CGRect (0,100, 1008, float.Parse (crnahheight.ToString ()) );

				uvBillingProcedureInfo.Frame = new CoreGraphics.CGRect (0, float.Parse (crnahheight.ToString ())+100 , 1008, 800);
				svBillingInfo.SizeToFit ();
				svBillingInfo.ContentSize = new SizeF (float.Parse (svBillingInfo.Frame.Width.ToString ()), float.Parse (svBillingInfo.Frame.Height.ToString ()) + crnahheight + 200);
			}


		}
		private async void RemovePreviousParticipant(UIButton btn,int roleID)
		{
			ProcedureParticipantDetails participantDetails = new ProcedureParticipantDetails();
			if(roleID == 2){
				participantDetails = selectedAnestheologistList.Find (x => x.Name.Trim() == btn.TitleLabel.Text.Trim());
			}
			if(roleID == 6){
				participantDetails = selectedCRNAList.Find (x => x.Name.Trim() == btn.TitleLabel.Text.Trim());
			}

			if (participantDetails != null) {
				if (participantDetails.ProcParticipantID != 0) {
					ReceiveContext deletecontext = await AppDelegate.Current.pqrsMgr.DeleteProcedureParticipant (participantDetails.ProcParticipantID);
					if (deletecontext != null && deletecontext.status != null && deletecontext.status.ToUpper () == "OK") {
						Console.WriteLine ("Participant: " + btn.TitleLabel.Text + " Deleted Successfully");
						if (roleID == 2)
							selectedAnestheologistList.Remove (participantDetails);

						if (roleID == 6)
							selectedCRNAList.Remove (participantDetails);

					}
					else
						NavigationController.PopToRootViewController(true);
				}
			}
		}
		public void BindParticipantsPopupover(List<UserDetails> listOfUsers,UIButton btnField,int FrameY,ProcedureParticipantDetails participantDetails)
		{
			
			if(btnField.CurrentTitle != "" && btnField.CurrentTitle != null){
				RemovePreviousParticipant(btnField,participantDetails.RoleID);
			}

			int uvwidth;
			ATlist.Clear();
			List<CodePickerModel> alist = SetParticipantsDataSource(listOfUsers, out  uvwidth);
			mcp = new mCodePicker(this,uvwidth,alist);
			mcp.TypeOfList = "Participants";

			float x = (float)btnField.Frame.X;
			float y = (float)btnField.Frame.Y+FrameY;

			mcp.PresentFromPopover(btnField, x, y,uvwidth);
			mcp.mDataSource(alist);
			mcp._ValueChanged += async delegate
			{
				try
				{
				if(mcp.SelectedItems.Count > 0){
					ATlist = mcp.SelectedItems;
					btnField.SetTitle(" " + ATlist[0].ItemText,UIControlState.Normal);
					participantDetails.UserID = ATlist[0].ItemID;
					ATlist.Clear();
					if(participantDetails.ProcParticipantID == 0)
					{
						participantDetails.ProcParticipantID = 0;
						participantDetails.Name = btnField.CurrentTitle.Trim();
						AddUpdateProcedureParticipants(participantDetails,btnField);
					}
					else
					{
						UpdateProcedureParticipants(participantDetails,btnField);
					}
				}
				}
				catch
				{
					
				}

			};

		}
		public void AddProviderView(ProcedureParticipantDetails participantDetails)
		{
			UIView view = uvProviderView.ViewWithTag(AnesCount+100);
			if (view != null) {
				UIButton checkbtn=(UIButton)view.ViewWithTag(2);
				if (checkbtn != null && string.IsNullOrEmpty (checkbtn.TitleLabel.Text)) {
					new UIAlertView("Anes Info", "Please Update Anes"+AnesCount+" Record."
											, null, "ok", null).Show();
					return; 
				}
			}

			AnesCount = AnesCount + 1;
			UIView  uvblock=new UIView();
			uvblock.Tag = AnesCount+100;
			uvblock.Frame = new CoreGraphics.CGRect (0, Anesheight, 497, 100);
			Anesheight = Anesheight+100;
			UILabel lbltitle=new UILabel(new CoreGraphics.CGRect(5, 10,100,40));
			lbltitle.Text="Anes ("+AnesCount+"):";			    		    
			UIButton nesNameBtn = new UIButton(new CoreGraphics.CGRect(145, 5,350,30));
			nesNameBtn.Tag =  2;
			nesNameBtn.Layer.BorderWidth = 1;
			nesNameBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			nesNameBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.Name)) {
				nesNameBtn.SetTitle (participantDetails.Name, UIControlState.Normal);
			}
			nesNameBtn.Layer.CornerRadius = 5; 
			nesNameBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			nesNameBtn.TouchUpInside += async delegate {
				if(listOfAnestheologists.Count > 0){
					if(participantDetails == null)
						participantDetails = new ProcedureParticipantDetails();

					participantDetails.RoleID = 2;
					BindParticipantsPopupover(listOfAnestheologists,nesNameBtn,(int)nesNameBtn.Frame.Y,participantDetails);
				}
			};
			UILabel lblstart= new UILabel(new CoreGraphics.CGRect(145, 50,85,30));
			lblstart.Text = "Start Time";
			UIButton startTimeBtn=new UIButton(new CoreGraphics.CGRect(230, 50,80,30));
			startTimeBtn.Layer.BorderWidth = 1;
			startTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			startTimeBtn.Layer.CornerRadius = 5; 
			startTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			startTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.StartTime)) {
				DateTime dt = DateTime.Parse(participantDetails.StartTime);
				//dt.ToString("HH:mm");
				startTimeBtn.SetTitle (dt.ToString("HH:mm tt"), UIControlState.Normal);

			}
			startTimeBtn.TouchUpInside+= (object sender, EventArgs e) => {
				TimePicker  tp = new TimePicker();
				tp.PresentFromPopover(startTimeBtn,40,35);
				tp._ValueChanged += delegate {		
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();
					
					startTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					participantDetails.StartTime = startTimeBtn.TitleLabel.Text;
					//BindParticipantsPopupover(listOfAnestheologists,nesNameBtn,(int)nesNameBtn.Frame.Y,participantDetails);
				};
			};

			UILabel lblendtime= new UILabel(new CoreGraphics.CGRect(330, 50,85,30));
			lblendtime.Text = "End Time";
			UIButton endTimeBtn=new UIButton(new CoreGraphics.CGRect(415, 50,80,30));
			endTimeBtn.Layer.BorderWidth = 1;
			endTimeBtn.Layer.BorderColor = UIColor.DarkGray.CGColor;
			endTimeBtn.Layer.CornerRadius = 5; 
			endTimeBtn.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
			endTimeBtn.SetTitleColor (UIColor.Black, UIControlState.Normal);
			if (participantDetails != null && !string.IsNullOrEmpty (participantDetails.EndTime)) {
				DateTime dt = DateTime.Parse(participantDetails.EndTime);
				//dt.ToString("HH:mm");
				endTimeBtn.SetTitle (dt.ToString("HH:mm tt"), UIControlState.Normal);
			}		
			endTimeBtn.TouchUpInside += async delegate {
				TimePicker  tp=new TimePicker();
				tp.PresentFromPopover(endTimeBtn,50,35);
				tp._ValueChanged += delegate {		
					if (participantDetails == null)
						participantDetails = new ProcedureParticipantDetails ();
					endTimeBtn.SetTitle(tp.SelectedTime,UIControlState.Normal);
					participantDetails.EndTime = endTimeBtn.TitleLabel.Text;
					//BindParticipantsPopupover(listOfAnestheologists,nesNameBtn,(int)nesNameBtn.Frame.Y,participantDetails);
				};
			};



			uvblock.Add(lblstart);
			uvblock.Add(nesNameBtn);
			uvblock.Add(lbltitle);
			uvblock.Add(startTimeBtn);
			uvblock.Add(lblendtime);
			uvblock.Add(endTimeBtn);
			UIView uvsp=new UIView(new CGRect(0,96,497,1));
			uvsp.BackgroundColor=UIColor.Black;
			UIView uvleftline=new UIView(new CGRect(497,0,1,100));
			uvleftline.BackgroundColor=UIColor.LightGray;
			uvblock.Add(uvleftline);
			uvblock.Add(uvsp);
			//uvProviderView
			uvProviderView.Add(uvblock);
			//svBillingInfo.Add(uvblock);
			if ((Anesheight - crnahheight) >= 100) {			    
				uvProviderView.Frame = new CGRect (0, 100, 1008, float.Parse (Anesheight.ToString ()) );

				uvBillingProcedureInfo.Frame = new CoreGraphics.CGRect (0, float.Parse (Anesheight.ToString ())+100 , 1008, 520);
				svBillingInfo.SizeToFit ();
				svBillingInfo.ContentSize = new SizeF (float.Parse (svBillingInfo.Frame.Width.ToString ()), float.Parse (svBillingInfo.Frame.Height.ToString ()) + Anesheight + 200);
			}


		}