private void BtnDelete_Click(object sender, RoutedEventArgs e) { try { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { if (objToEditOrRemove != null) { DocInvestigations obj = MyViewModel.db.DocInvestigations.Find(objToEditOrRemove.IDocInvestigationsId); if (obj != null) { obj.BIsActive = false; MyViewModel.db.SaveChanges(); MyViewModel.ObjNewDoctor.DocInvestigations.Remove(objToEditOrRemove); this.DocInvestigations.ItemsSource = MyViewModel.ObjNewDoctor.DocInvestigations; } else { MyViewModel.ObjNewDoctor.DocInvestigations.Remove(objToEditOrRemove); this.DocInvestigations.ItemsSource = MyViewModel.ObjNewDoctor.DocInvestigations; } } MyViewModel.ObjNewDoctor.DocInvestigations = MyViewModel.GetActiveDocInvestigations(); Globalized.SetMsg("DOC03", DataHolders.MsgType.Info); Globalized.ShowMsg(lblErrorMsg); } } catch (Exception ex) { // throw; } }
public DocInvestigations GetActiveDocInvestigations(long DocInvId) { ObservableCollection <DocInvestigations> returnList = new ObservableCollection <DocInvestigations>(); if (DocInvId > 0) { if (this.ObjNewDoctor != null && this.ObjNewDoctor.IDocid > 0) { returnList = (from Dinv in db.DocInvestigations join Inv in db.Investigations on Dinv.IInvid equals Inv.IInvid where Dinv.IDocid == ObjNewDoctor.IDocid && Dinv.BIsActive == true && Dinv.IDocInvestigationsId == DocInvId select new { Dinv.IDocid, Dinv.IDocCommission, Dinv.IDocInvestigationsId, Inv.IInvid, Inv.VInvName, Inv.VInvDesc, Inv.IInvCharges, Inv.bIsActive } ).ToList() .Select(x => new DocInvestigations { IDocid = x.IDocid, IDocCommission = x.IDocCommission, IDocInvestigationsId = x.IDocInvestigationsId, IInvid = x.IInvid, VInvName = x.VInvName, VInvDesc = x.VInvDesc, IInvCharges = x.IInvCharges, BIsActive = x.bIsActive } ).ToObservableCollection(); } } DocInvestigations ObjReturn = new DocInvestigations(); if (returnList.First() != null) { ObjReturn = returnList.First(); } return(ObjReturn); }
private void TxtIInvestigationID_TargetUpdated(object sender, System.Windows.Data.DataTransferEventArgs e) { if (this.MyViewModel == null) { return; } int InvId; int.TryParse(txtIInvestigationID.Text.ToString(), out InvId); Investigations ObjInv = this.MyViewModel.db.Investigations.Where(I => I.bIsActive == true && I.IInvid == InvId).FirstOrDefault(); //iFacede.GetdhItem(Globalized.ObjDbName, new dhItems { IItemID = Convert.ToInt32(ItemList.SelectedValue) }); //ObjDhItem.IQuantity = 0; // creat the new object of doctor investigation if (ObjInv == null) { return; } DocInvestigations objDocInv = new DocInvestigations(); objDocInv.IInvid = InvId; objDocInv.IDocid = this.MyViewModel.ObjNewDoctor.IDocid; objDocInv.VInvName = ObjInv.VInvName; objDocInv.VInvDesc = ObjInv.VInvDesc; objDocInv.IInvCharges = ObjInv.IInvCharges; this.MyViewModel.ObjNewDoctor.DocInvestigations.Add(objDocInv); // update the source this.DocInvestigations.ItemsSource = this.MyViewModel.ObjNewDoctor.DocInvestigations; // clear the source // this.InvestigationList.SelectedItem = null; // this.InvestigationList.SelectedValue = ""; //this.InvestigationList }
private void BtnSaveDoctor_Click(object sender, RoutedEventArgs e) { try { if (objNewDoctor.IUpdate == 0 || objNewDoctor.IUpdate == null) { if (objNewDoctor.TokenStart == "" || objNewDoctor.TokenStart == null) { objNewDoctor.TokenStart = objNewDoctor.VfName.Substring(0, 2).ToUpper(); } MyViewModel.db.Doctors.Add(objNewDoctor); MyViewModel.db.SaveChanges();; // for investigations foreach (DocInvestigations item in objNewDoctor.DocInvestigations) { item.IDocid = objNewDoctor.IDocid; item.BIsActive = true; MyViewModel.db.DocInvestigations.Add(item); } // for doc procedures dhAccount objAccount = MyViewModel.InsertUpdateAccount(objNewDoctor); MyViewModel.db.Accounts.Add(objAccount); // need to set for doc proc this.AddEditDocProcedures(); Globalized.SetMsg("DOC01", DataHolders.MsgType.Info); } // if update flag is set if (objNewDoctor.IUpdate == 1) { // dhDoctors temp = MyViewModel.db.Doctors.Find(objNewDoctor.IDocid); objNewDoctor = (dhDoctors)this.NewDoctorGrid.DataContext; if (objNewDoctor.TokenStart == "" || objNewDoctor.TokenStart == null) { objNewDoctor.TokenStart = objNewDoctor.VfName.Substring(0, 2).ToUpper(); } MyViewModel.db.Doctors.Attach(objNewDoctor); //.State = EntityState.Added; MyViewModel.db.Entry(objNewDoctor).State = EntityState.Modified; dhAccount objAccount = MyViewModel.InsertUpdateAccount(objNewDoctor); // MyViewModel.db.Accounts.Attach(objAccount); MyViewModel.db.Entry(objAccount).State = EntityState.Modified; // check existing investigation ObservableCollection <DocInvestigations> crntInv = MyViewModel.db.DocInvestigations.Where(x => x.IDocid == objNewDoctor.IDocid && x.BIsActive == true).ToObservableCollection(); foreach (DocInvestigations item in objNewDoctor.DocInvestigations) { item.IDocid = objNewDoctor.IDocid; // make this investigation active item.BIsActive = true; if (crntInv.Select(x => x.IDocInvestigationsId == item.IDocInvestigationsId).FirstOrDefault() == false) { MyViewModel.db.DocInvestigations.Add(item); } else { DocInvestigations tempDoinv = this.MyViewModel.db.DocInvestigations.Find(item.IDocInvestigationsId); if (tempDoinv != null) { tempDoinv = item; } } // if(crntInv.fi) } // need to set for doc proc this.AddEditDocProcedures(); Globalized.SetMsg("DOC02", DataHolders.MsgType.Info); } // final save and update model objNewDoctor.IUpdate = 1; // now it will ebe update object MyViewModel.db.SaveChanges(); // set Doctor MyViewModel.ObjNewDoctor = objNewDoctor; MyViewModel.ObjNewDoctor.DocInvestigations = MyViewModel.GetActiveDocInvestigations(); MyViewModel.DoctorAccount = MyViewModel.GetDocAccount(); this.AccountInfo.DataContext = MyViewModel.DoctorAccount; Globalized.ShowMsg(lblErrorMsg); } catch (Exception ex) { Globalized.SetMsg(ex.Message, MsgType.Error); Globalized.ShowMsg(lblErrorMsg); } // this.DataContext }
private void DocInvestigations_SelectionChanged(object sender, SelectionChangedEventArgs e) { objToEditOrRemove = DocInvestigations.SelectedItem as DocInvestigations; }