private void SaveAppointment(object sender, RoutedEventArgs e) { try { blAppointment objBlAppointment = new blAppointment(); dhAppointment ObjNewAppointment = (dhAppointment)this.AppointmentInfo.DataContext; // cehck for patient dhPatient ObjPatient = (dhPatient)this.PatientInformationGrid.DataContext; // doctor long iDocId = ((dhDoctorView)this.DoctorInformationGrid.DataContext).IDocid; dhDoctors objDoc = MyViewModel.db.Doctors.AsNoTracking().Where(x => x.IDocid == iDocId && x.BActive == true).FirstOrDefault(); if (objDoc == null) { return; } if (ObjPatient.iPatid == 0 || ObjPatient.iPatid < 0) { BlPatient objBl = new BlPatient(); objBl.AddNewPatient(ObjPatient); // need to save the patient first //MyViewModel.db.Patients.Add(ObjPatient); //MyViewModel.db.SaveChanges(); // set for patatient id ObjNewAppointment.IPatid = ObjPatient.iPatid; } // check for doctors if (ObjNewAppointment != null) { Dictionary <long, string> objDic = objBlAppointment.GetNextToken(objDoc, ObjNewAppointment); ObjNewAppointment.FormatedTokenNumber = objDic.First().Value; ObjNewAppointment.IToken_Number = objDic.First().Key; MyViewModel.db.Appointments.Add(ObjNewAppointment); MyViewModel.db.SaveChanges(); } this.AppointmentInfo.DataContext = ObjNewAppointment; Globalized.SetMsg("AOC01", DataHolders.MsgType.Info); Globalized.ShowMsg(lblErrorMsg); } catch (Exception ex) { Globalized.SetMsg(ex.Message, MsgType.Error); Globalized.ShowMsg(lblErrorMsg); } }
//class functions public dhPatient AddNewPatient(dhPatient ObjNewPatient) { if (ObjNewPatient == null) { return(new dhPatient()); } db.Patients.Add(ObjNewPatient); db.SaveChanges(); MyPatient = ObjNewPatient; long?AccountID = InsertUpdatePatientAccount(); ObjNewPatient.IAccountid = Convert.ToInt64(AccountID); // db.Patients.Attach(ObjNewPatient); db.SaveChanges(); return(ObjNewPatient); }
private void TxtiPatid_TargetUpdated(object sender, DataTransferEventArgs e) { TextBox txtbox = sender as TextBox; long iPatid; long.TryParse(txtbox.Text.ToString(), out iPatid); if (iPatid > 0) { // find the doc dhPatient objPat = this.MyViewModel.db.Patients.Where(d => d.iPatid == iPatid).FirstOrDefault(); // bind the information if (objPat != null) { this.PatientInformationGrid.DataContext = objPat; ((dhAppointment)this.AppointmentInfo.DataContext).IPatid = objPat.iPatid; } } }