private bool CanNew() { if (!CanCud()) { return(false); } //HACK: VarFilter if (ParentViewModelSource.GetType() == typeof(EpsTask) && typeof(EpsConfig).IsAssignableFrom(_itemType)) { return(!string.IsNullOrEmpty(((EpsTask)ParentViewModelSource).TaskType)); } return(true); }
public virtual void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { ParentViewModelSource = DataContext as WMSBusinessObject; if (ParentViewModelSource != null) { //HACK: Используется для VarFilter и многого другого RaiseCanExecuteChanged(); SubscribeSource(); var members = (ParentViewModelSource.GetType()).GetMembers(); var prop = members.FirstOrDefault(m => m.Name.ToUpper().Equals(SubListParentFieldName)); if (prop != null) { var attributes = prop.GetCustomAttributes(typeof(GCFieldAttribute), true); if (attributes.Length == 1) { ShouldUpdateSeparately = false; } } } }
private void OnNew() { if (!ConnectionManager.Instance.AllowRequest()) { return; } if (!CanNew()) { return; } try { var newItem = Activator.CreateInstance(_itemType); //var parentdatatypename = ParentViewModelSource.GetType().Name; var parentdatatypename = SourceNameHelper.Instance.GetSourceName(ParentViewModelSource.GetType()); //Получаем детализацию по манданту принимаемой позиции или непривязанные к мандантам var mId = TypeDescriptor.GetProperties(ParentViewModel).Cast <PropertyDescriptor>().FirstOrDefault(i => i.Name.EqIgnoreCase("MANDANTID")); if (mId != null) { var mandantId = mId.GetValue(ParentViewModel); var fields = DataFieldHelper.Instance.GetDataFields(_itemType, SettingDisplay.Detail); var fieldQlf = fields.FirstOrDefault(i => i.Name.EqIgnoreCase("QLFDETAILCODE_R")); if (fieldQlf != null) { var lookupInfo = LookupHelper.GetLookupInfo(fieldQlf.LookupCode); //TODO: при передаче в [...] этот фильтр зачем то TOUPPER делается, если указать WMSQLFDETAIL.QLFDETAILCODE то TOUPPER обходится и передается корректный фильтр. Передать Оле на доанализ и доделку lookupInfo.Filter = String.Format(" WMSQLFDETAIL.QLFDETAILCODE in (select QLFDETAILCODE_R from wmsqlfdetail2mandant where PARTNERID_R = {0}) or WMSQLFDETAIL.QLFDETAILCODE not in (select QLFDETAILCODE_R from wmsqlfdetail2mandant)", mandantId); } } var properties = IsLookupExist(newItem, parentdatatypename); var property = properties.Select(p => new { Name = p.Name.ToUpper(), Property = p }) .FirstOrDefault(p => p.Name.Contains("MASTER") || p.Name.Contains("PARENT")); SetValueByLookup(newItem, property == null ? (properties.Length > 0 ? properties[0] : null) : property.Property, ((IKeyHandler)ParentViewModelSource).GetKey()); var parentProperty = TypeDescriptor.GetProperties(ParentViewModelSource).Cast <PropertyDescriptor>().FirstOrDefault(i => i.Name.EqIgnoreCase("MANDANTID")); if (parentProperty != null) { var mandants = IsLookupExist(newItem, "MANDANT"); foreach (var m in mandants) { SetValueByLookup(newItem, m, parentProperty.GetValue(ParentViewModelSource)); } } //Hack: Для позиций груза приходной накладной. Проставляем типы по умолчанию для факта и документа var pos = newItem as CargoIWBPos; if (pos != null && SubListParentFieldName != null) { pos.CargoIwbPosType = SubListParentFieldName == "CARGOIWBPOSLCLIENT" ? "CLIENT" : "FACT"; } //var propertysys = IsLookupExist(newItem, SourceNameHelper.GetSourceName(typeof (SysObject))); //SetValueByLookup(newItem, propertysys, parentdatatypename); //HACK: Заполнение EpsConfig2Entity используется для VarFilter'а. Можно сделать через лукап от SysObj. if (typeof(EpsConfig).IsAssignableFrom(_itemType)) { if (string.IsNullOrEmpty(((EpsConfig)newItem).EpsConfig2Entity)) { ((EpsConfig)newItem).EpsConfig2Entity = SourceNameHelper.Instance.GetSourceName(ParentViewModelSource.GetType()).ToUpper(); } var keyHandler = ParentViewModelSource as IKeyHandler; if (keyHandler != null && string.IsNullOrEmpty(((EpsConfig)newItem).EpsConfigKey)) { ((EpsConfig)newItem).EpsConfigKey = keyHandler.GetKey <string>(); } } //HACK: Заполнение Report2ReportEntity if (typeof(Report2Report).IsAssignableFrom(_itemType) && !string.IsNullOrEmpty(SubListParentFieldName)) { switch (SubListParentFieldName) { case Report.ChildReportsPropertyName: ((Report2Report)newItem).ReportCode = null; break; case Report.ParentsReportsPropertyName: ((Report2Report)newItem).ReportCode = ((Report2Report)newItem).R2Rparent; ((Report2Report)newItem).R2Rparent = null; break; } } if (newItem is EditableBusinessObject) { ((EditableBusinessObject)newItem).AcceptChanges(true); } if (ViewObject(ref newItem, true) == true) { if (ShouldUpdateSeparately) { //HACK: Добавление связок Working -> W2E2Working var working = newItem as Working; var parentvm = ParentViewModel as CustomObjectListViewModelBase <InputPlPos>; if (parentvm != null && working != null) { var plpos = parentvm.Source.FirstOrDefault(); if (plpos != null) { Work2Entity w2E; using (var mgrW2E = IoC.Instance.Resolve <IBaseManager <Work2Entity> >()) { w2E = mgrW2E.GetFiltered(String.Format(" workid_r = {0} and work2entityentity = 'PL' and work2entitykey = {1}", working.WORKID_R, plpos.PlIdR)).FirstOrDefault(); } if (w2E != null) { var ww2 = new W2E2Working() { WorkingId = working.WORKINGID, Work2EntityId = w2E.Work2EntityId }; using (var mgrWw2 = IoC.Instance.Resolve <IBaseManager <W2E2Working> >()) { mgrWw2.Insert(ref ww2); } } } } ParentRefresh(); } } } catch (Exception ex) { throw new OperationException(ExceptionResources.ItemCantInsert, ex); } }
private void UpdateSource(Entity2GC obj) { if (Source == null) { return; } try { ParentViewModelSource.SuspendNotifications(); ParentViewModelSource.SuspendValidating(); Source.SuspendNotifications(); var parentViewModelSourceName = GetParentViewModelSourceName(); using (var mgr = IoC.Instance.Resolve <IBaseManager <Entity2GC> >()) { // Перевычитываем из БД весь Source if (obj == null) { var keys = Source.Select(item => (object)item.ENTITY2GCID).ToList(); if (keys.Count <= 0) { return; } var array = mgr.GetFiltered(FilterHelper.GetFilterIn(Entity2GC.ENTITY2GCIDPropertyName, keys)).ToArray(); foreach (var itParent in array.Cast <IHasParent>().Where(itParent => itParent != null)) { itParent.SourceTypeName = _itemType.Name.ToUpper(); itParent.TargetTypeName = parentViewModelSourceName; } Source.Clear(); Source.AddRange(array); ParentViewModelSource.AcceptChanges(); } else { var isDirty = ParentViewModelSource.IsDirty; var index = Source.IndexOf(obj); Source.RemoveAt(index); var it = mgr.Get(obj.GetKey()); var itParent = (IHasParent)it; if (itParent != null) { itParent.SourceTypeName = _itemType.Name.ToUpper(); itParent.TargetTypeName = GetParentViewModelSourceName(); } Source.Insert(index, it); if (!isDirty) { ParentViewModelSource.AcceptChanges(); } } } } finally { Source.ResumeNotifications(); ParentViewModelSource.ResumeValidating(); ParentViewModelSource.ResumeNotifications(); ParentViewModelSource.Validate(); } }
private string GetParentViewModelSourceName() { return(ParentViewModelSource == null ? null : SourceNameHelper.Instance.GetSourceName(ParentViewModelSource.GetType()).ToUpper()); }