public DdsSellsView(DdsDnevnikModel model, DdsDnevnicItem item, DdsViewModel.RefreshElement vmRefreshExecuted, DdsViewModel.RefreshElement vmSavedExecuted, DdsViewModel.CancelSaveElement vmCanelExecuted) { vm = new DdsViewModel(model, item); vm.RefreshExecuted += vmRefreshExecuted; vm.DdsSaved += vmSavedExecuted; vm.CancelSave += vmCanelExecuted; InitializeComponent(); this.DataContext = vm; }
public DdsSallesViewModel(DdsDnevnikModel ddsmodel, DdsDnevnicItem item) { ddsDnevnikModel = ddsmodel; KindDocLookup = new ObservableCollection <LookUpSpecific>(context.GetAllDocTypes()); KindDoc = KindDocLookup.FirstOrDefault(e => e.CodetId == ddsDnevnikModel.CodeDoc); SelectedLookup = new ObservableCollection <ContragentInfo>(); ActivityTypeLookup = new ObservableCollection <LookUpSpecific> { new LookUpSpecific { CodetId = "01", Id = 1, Name = "Покупки" }, new LookUpSpecific { CodetId = "02", Id = 2, Name = "Продажби" }, new LookUpSpecific { CodetId = "03", Id = 3, Name = "Други" }, }; this.Lookups = new ObservableCollection <LookUpMetaData>(context.GetAllLookups(" where NAMEENG='k'")); AllFields = new ObservableCollection <DdsDnevnicItem>(); foreach (var litem in ddsDnevnikModel.DetailItems) { if (litem.Name == item.Name) { litem.DdsSuma = item.DdsSuma; } AllFields.Add(new DdsDnevnicItem(litem)); } if (ddsmodel.LookupID > 0) { Lookup = Lookups.FirstOrDefault(e => e.Id == ddsmodel.LookupID); } if (ddsmodel.LookupElementID > 0) { LookupElementInfo = SelectedLookup.FirstOrDefault(e => e.Id == ddsmodel.LookupElementID); } }
public DdsViewModel(DdsDnevnikModel ddsmodel, DdsDnevnicItem item) { ddsDnevnikModel = ddsmodel; KindDocLookup = new ObservableCollection <LookUpSpecific>(Context.GetAllDocTypes()); if (ddsDnevnikModel.CodeDoc == null) { ddsDnevnikModel.CodeDoc = "01"; } KindDoc = KindDocLookup.FirstOrDefault(e => e.CodetId == ddsDnevnikModel.CodeDoc); ActivityTypeLookup = new ObservableCollection <LookUpSpecific> { new LookUpSpecific { CodetId = "01", Id = 1, Name = "Покупки" }, new LookUpSpecific { CodetId = "02", Id = 2, Name = "Продажби" }, new LookUpSpecific { CodetId = "03", Id = 3, Name = "Други" }, }; this.Lookups = new ObservableCollection <LookUpMetaData>(Context.GetAllLookups(" where NAMEENG='k'")); AllFields = new ObservableCollection <DdsDnevnicItem>(); foreach (var litem in ddsDnevnikModel.DetailItems) { if (ddsDnevnikModel.IsSuma == 0) { if (litem.Name == item.Name) { if (litem.DdsSuma > 0 && litem.DdsSuma != item.DdsSuma) { _kor = true; _oldsum = litem.DdsSuma.ToString(Vf.LevFormatUI); } else { _kor = false; } litem.DdsSuma = item.DdsSuma; litem.In = true; } } else { if (!ddsDnevnikModel.IsLinked) { if (litem.Name == item.Name) { litem.DdsSuma = item.DdsSuma; ddsDnevnikModel.Total = item.DdsSuma.ToString(Vf.LevFormatUI); litem.In = true; } } } AllFields.Add(new DdsDnevnicItem(litem)); } if (ddsmodel.LookupID > 0) { Lookup = Lookups.FirstOrDefault(e => e.Id == ddsmodel.LookupID); if (Lookup == null) { Lookup = ddsmodel.KindActivity == 2 ? Lookups.FirstOrDefault(e => e.Name == "Клиенти") : Lookups.FirstOrDefault(e => e.Name == "Доставчици"); ddsmodel.LookupElementID = 0; } } else { Lookup = ddsmodel.KindActivity == 2 ? Lookups.FirstOrDefault(e => e.Name == "Клиенти") : Lookups.FirstOrDefault(e => e.Name == "Доставчици"); } if (ddsmodel.LookupElementID > 0) { string SerachedField = ""; if (Lookup != null) { SerachedField = Context.GetLookup(Lookup.Id).Fields[0].NameEng; } var list = Context.GetLookupDictionary(_lookUpMetaData.Tablename, ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, string.Format("And \"{0}\"={1}", SerachedField, ddsmodel.LookupElementID)); foreach (var li in list) { if (li != null) { if (li.ContainsKey("Name")) { SelectedItem.Lookupval = li["Name"].ToString(); ClName = SelectedItem.Lookupval; } if (li.ContainsKey("VAT")) { DdsId = li["VAT"].ToString(); } if (li.ContainsKey("BULSTAT")) { Bustad = li["BULSTAT"].ToString(); } if (li.ContainsKey("KONTRAGENT")) { SelectedItem.Value = li["KONTRAGENT"].ToString(); } } } } else { if (ddsmodel.ClNum != null) { string SerachedField = ""; if (Lookup != null) { SerachedField = Context.GetLookup(Lookup.Id).Fields[1].NameEng; } var list = Context.GetLookupDictionary(_lookUpMetaData.Tablename, ConfigTempoSinglenton.GetInstance().CurrentFirma.Id, string.Format("And \"{0}\"={1}", SerachedField, ddsmodel.ClNum)); foreach (var li in list) { if (li != null) { if (li.ContainsKey("Name")) { SelectedItem.Lookupval = li["Name"].ToString(); ClName = SelectedItem.Lookupval; } if (li.ContainsKey("VAT")) { DdsId = li["VAT"].ToString(); } if (li.ContainsKey("BULSTAT")) { Bustad = li["BULSTAT"].ToString(); } if (li.ContainsKey("KONTRAGENT")) { SelectedItem.Value = li["KONTRAGENT"].ToString(); } if (li.ContainsKey("Id")) { int id; ddsDnevnikModel.LookupElementID = int.TryParse(li["Id"].ToString(), out id)?id:0; } } } } } }