public async Task <bool> RemoveAsync(CuentaMayor cuenta, aVMTabBase VM) { if (!this._ObjModels.ContainsKey(cuenta.Id)) { return(false); } QueryBuilder SQL = await Task.Run(() => GetDeleteSQL(cuenta.Id)).ConfigureAwait(false); ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.equal, 1); var tuple = new Tuple <QueryBuilder, IConditionToCommit>(SQL, condition); if (!await AddTransactionWaitingForCommitAsync(tuple, VM)) { return(false); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed RemoveObjectWaitingForCommitAsync(cuenta, VM).Forget().ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await base._RepoSphr.WaitAsync(); int idump; Tuple <int, long> key = new Tuple <int, long>(cuenta.NumCuenta, cuenta.IdOwnerComunidad.CantorPair(cuenta.IdOwnerEjercicio)); this._CuentasIds.TryRemove(key, out idump); base._RepoSphr.Release(); return(true); }
public async Task <bool> AddNewAsync(CuentaMayor cuenta, aVMTabBase VM) { //¡¡¡¡OJO!!!!! AQUI HAY QUE AĂ‘ADIR "SELECT LAST_INSERT_ID()" MANUALMENTE AL QUERYBUILDER //El problema es que LAST_INSERT_ID() trabaja por conexion, por tanto si se realizan varios inserts no servirĂa de nada if (!base._NewObjects[VM].Add(cuenta)) { return(false); } QueryBuilder SQL = await Task.Run(() => GetInsertSQL(cuenta)).ConfigureAwait(false); ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.greater, -1); SQL.Append("SELECT LAST_INSERT_ID();"); var tuple = new Tuple <QueryBuilder, IConditionToCommit>(SQL, condition); await base._RepoSphr.WaitAsync(); this._CuentasIds.TryAdd( new Tuple <int, long>(cuenta.NumCuenta, cuenta.IdOwnerComunidad.CantorPair(cuenta.IdOwnerEjercicio)), cuenta.Id); base._RepoSphr.Release(); if (!await AddTransactionWaitingForCommitAsync(tuple, VM)) { base._NewObjects[VM].Remove(cuenta); return(false); } return(true); }
protected async Task AddToFalloAlCargarMultiBindingsAsync(aVMTabBase newTab, FalloAlCargarUC UC) { MultiBinding falloMultiBinding = BindingOperations.GetMultiBindingExpression(UC, FalloAlCargarUC.VisibilityProperty).ParentMultiBinding; falloMultiBinding.Bindings.Add(new Binding() { Source = newTab, Path = new PropertyPath("TaskCargando.IsNotCompleted"), Mode = BindingMode.OneWay }); SetVisibilityConverter(falloMultiBinding, "FalseCollapsed"); falloMultiBinding.NotifyOnSourceUpdated = true; UC.SetBinding(FalloAlCargarUC.VisibilityProperty, falloMultiBinding); falloMultiBinding = BindingOperations.GetMultiBindingExpression(UC, FalloAlCargarUC.MensajeFalloProperty).ParentMultiBinding; falloMultiBinding.Bindings.Add(new Binding() { Source = newTab, Path = new PropertyPath("TaskCargando.ErrorMessage"), Mode = BindingMode.OneWay }); SetVisibilityConverter(falloMultiBinding); falloMultiBinding.NotifyOnSourceUpdated = true; UC.SetBinding(FalloAlCargarUC.MensajeFalloProperty, falloMultiBinding); }
public UnitOfWork(IEnumerable <aRepositoryInternal> repositories, aVMTabBase tab, bool rollbackAllIfRollback = false) { this.RollbackAllIfRollback = rollbackAllIfRollback; this.Repositories = new HashSet <aRepositoryInternal>(repositories); this._Tab = tab; InitRepositories(); }
private static void OnSelectedIndexPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { AbleTabControl control = source as AbleTabControl; int newIndex = (int)e.NewValue; int oldIndex = (int)e.OldValue; if (newIndex > control.ItemsSourceProperty.Count - 1 || newIndex < 0 || oldIndex > control.ItemsSourceProperty.Count - 1 || oldIndex < 0) { return; } aVMTabBase newTab = control.ItemsSourceProperty[newIndex]; aVMTabBase oldTab = control.ItemsSourceProperty[oldIndex]; oldTab.IsSelected = false; oldTab.PublicNotifyPropChanged("IsSelected"); newTab.IsSelected = true; newTab.PublicNotifyPropChanged("IsSelected"); //control.SelectedIndex = newIndex; control.Dispatcher.BeginInvoke((Action)(() => control.RootTabControl.SelectedIndex = newIndex)); //control.NotifyPropChanged("SelectedIndex"); //control.RootTabControl.ContentTemplateSelector.SelectTemplate(oldTab, control.RootTabControl as DependencyObject); TabbedExpander TopTabExp = control.RootTabControl.FindVisualChild <TabbedExpander>(x => (x as FrameworkElement).Name == "TopTabbedExpander"); TabbedExpander BottomTabExp = control.RootTabControl.FindVisualChild <TabbedExpander>(x => (x as FrameworkElement).Name == "BottomTabbedExpander"); Grid BTEGrid = control.RootTabControl.FindVisualChild <Grid>(x => (x as Grid).Name == "TabControlGrid"); RowDefinition rowDef = BTEGrid.RowDefinitions[3]; TabbedExpanderBindingChanger filler = new TabbedExpanderBindingChanger(newTab as aTabsWithTabExpVM, ref TopTabExp, ref BottomTabExp, ref rowDef); control.RootTabControl.FindVisualChild <CargandoUC>(x => (x as FrameworkElement).Name == "CargandoUC") .SetBinding(UserControl.VisibilityProperty, control.NewCargandoMultiBinding(newTab)); }
public async Task <Persona> GetByIdAsync(int id, aVMTabBase VM) { Persona p = null; if (!this._ObjModels.TryGetValue(id, out p)) { Task <QueryBuilder> qBuilder = Task.Run(() => GetSelectSQL(id)); dynamic result; using (SqlConnection con = new SqlConnection(this._strCon)) { await con.OpenAsync().ConfigureAwait(false); await qBuilder.ConfigureAwait(false); result = await con.QueryAsync(qBuilder.Result.Query, qBuilder.Result.Parameters).ConfigureAwait(false); con.Close(); } p = await Task.Run(() => this._Mapper.Map(result)).ConfigureAwait(false); AddToDictionariesObjectRetrievedFromDBAsync(p, Task.Run(() => base._Mapper.Map(result)).Result, VM) .Forget() .ConfigureAwait(false); } return(p); }
internal override async Task RollbackRepoAsync(aVMTabBase VM, Func <Task> doFirstInsideSemaphoreWaiting = null, Func <Task> doLastInsideSemaphoreWaiting = null) { IEnumerable <int> VMIds = base._DirtyMembers[VM].Keys.Union(this._NewObjects[VM].Select(x => x.Id)).AsEnumerable(); //To delete dependent later await base.RollbackRepoAsync(VM); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed ((IRepositoryDependent <CuentaMayor>) this).RollbackDependentAsync(VMIds).Forget().ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }
internal override async Task ApplyChangesAsync(aVMTabBase VM, Func <Task> doFirstInsideSemaphoreWaiting = null, Func <Task> doLastInsideSemaphoreWaiting = null) { int[] VMIdsToAdd = base._DirtyMembers[VM].Keys.ToArray(); //To delete dependent later int[] VMIdsToRemove = this._ObjectsRemoved[VM].Select(x => x.Id).ToArray(); await base.ApplyChangesAsync(VM); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed ((IRepositoryDependent <CuentaMayor>) this).ApplyDependentAsync(VMIdsToAdd, VMIdsToRemove).Forget().ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }
protected async Task RemoveBindingFromFalloalCargarAsync(aVMTabBase removedTab, FalloAlCargarUC UC) { MultiBinding falloMultiBinding = BindingOperations.GetMultiBindingExpression(UC, FalloAlCargarUC.VisibilityProperty).ParentMultiBinding; var bindingsToRemove = falloMultiBinding.Bindings.Where(binding => ((Binding)binding).Source == removedTab); foreach (BindingBase binding in bindingsToRemove) { falloMultiBinding.Bindings.Remove(binding); } }
internal override async Task RemoveVMTabReferencesAsync(aVMTabBase VM, Func <Task> doFirstInsideSemaphoreWaiting = null, Func <Task> doLastInsideSemaphoreWaiting = null) { Func <Task> thisFunc = async() => { this._VMs.Remove(VM); if (this._VMs.Count == 0) { await CleanDLOsDictionariesAsync(); } }; await base.RemoveVMTabReferencesAsync(VM, doFirstInsideSemaphoreWaiting, doLastInsideSemaphoreWaiting += thisFunc); }
public async Task <bool> UpdateAsync(Persona p, aVMTabBase VM) { Task <QueryBuilder> SQL = Task.Run(() => GetUpdateSQL(p.Id, VM)); ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.equal, 1); if (await SQL.ConfigureAwait(false) == null) { return(false); } var tuple = new Tuple <QueryBuilder, IConditionToCommit>(SQL.Result, condition); return(await AddTransactionWaitingForCommitAsync(tuple, VM)); }
public async Task <bool> UpdateAsync(CuentaMayor cuenta, aVMTabBase VM) { QueryBuilder SQL = await Task.Run(() => GetUpdateSQL(cuenta.Id, VM)).ConfigureAwait(false); if (SQL == null) { return(false); } ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.equal, 1); var tuple = new Tuple <QueryBuilder, IConditionToCommit>(SQL, condition); return(await AddTransactionWaitingForCommitAsync(tuple, VM)); }
public async Task <bool> UpdateAsync(Asiento AsientoObj, aVMTabBase VM) { QueryBuilder SQL = await Task.Run(() => GetUpdateSQL(AsientoObj.Id, VM)).ConfigureAwait(false); if (SQL == null) { return(false); } ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.equal, SQL.CountNumberOfOcurrencesInQuery("UPDATE")); var tuple = new Tuple <QueryBuilder, IConditionToCommit>(SQL, condition); return(await AddTransactionWaitingForCommitAsync(tuple, VM)); }
internal override async Task ApplyChangesAsync(aVMTabBase VM, Func <Task> doFirstInsideSemaphoreWaiting = null, Func <Task> doLastInsideSemaphoreWaiting = null) { await base._RepoSphr.WaitAsync(); //All old new objects are now normal objects foreach (CuentaMayor objModel in base._NewObjects[VM]) { base._ObjModels.TryAdd(objModel.Id, objModel); base._VMsThatOwnsObjModels.AddOrUpdate( objModel.Id, new HashSet <aVMTabBase>() { VM }, (id, hashset) => new HashSet <aVMTabBase>(base._VMsThatOwnsObjModels[id].AddAndGetUpdatedHashSet(VM))); Tuple <int, long> key = new Tuple <int, long>(objModel.NumCuenta, objModel.IdOwnerComunidad.CantorPair(objModel.IdOwnerEjercicio)); this._CuentasIds.TryAdd(key, objModel.Id); } base._NewObjects[VM].Clear(); //Therefore, clear new objects base.Transactions[VM].Clear(); //Transactions made, clear transactions //Apply deletes CuentaMayor dump; HashSet <aVMTabBase> hDump; int iDump; foreach (CuentaMayor objModel in base._ObjectsRemoved[VM]) { base._OriginalObjModels.TryRemove(objModel.Id, out dump); this._VMsThatOwnsObjModels.TryRemove(objModel.Id, out hDump); Tuple <int, long> key = new Tuple <int, long>(objModel.NumCuenta, objModel.IdOwnerComunidad.CantorPair(objModel.IdOwnerEjercicio)); this._CuentasIds.TryRemove(key, out iDump); } base._ObjectsRemoved[VM].Clear(); //Apply members modified to original objects foreach (KeyValuePair <int, string[]> kvp in base._DirtyMembers[VM]) { base._OriginalObjModels[kvp.Key] = base._ObjModels[kvp.Key]; } base._DirtyMembers[VM].Clear(); //Clear objects members modified base._RepoSphr.Release(); }
public async Task <bool> AddNewAsync(Persona p, aVMTabBase VM) { if (!this._NewObjects[VM].Add(p)) { return(false); } Task <QueryBuilder> SQL = Task.Run(() => GetInsertSQL(p)); ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.equal, 1); var tuple = new Tuple <QueryBuilder, IConditionToCommit>(await SQL.ConfigureAwait(false), condition); if (!await AddTransactionWaitingForCommitAsync(tuple, VM)) { base._NewObjects[VM].Remove(p); return(false); } return(true); }
protected override QueryBuilder GetUpdateSQL(int id, aVMTabBase VM) { if (this._NewObjects[VM].Select(x => x.Id).Contains(id) || //If the object have been newly created it needs an INSERT not an UPDATE !this._DirtyMembers[VM].ContainsKey(id)) //If there are no dirty members the object haven't been modified { return(null); } Type t = GetObjModelType(); QueryBuilder qBuilder = new QueryBuilder(); qBuilder .Update(t) .UpdateSet(this._DirtyMembers[VM][id]) .Where(new SQLCondition("Id", "@id")); qBuilder.StoreParametersFrom(this._ObjModels[id]); qBuilder.StoreParameter("@id", id); return(qBuilder); }
private void TabItem_Drop(object sender, DragEventArgs e) { aVMTabBase tabItemTarget = (e.Source as TabItem).DataContext as aVMTabBase; aVMTabBase tabItemSource = (e.Data.GetData(typeof(TabItem)) as TabItem).DataContext as aVMTabBase; if (!tabItemTarget.Equals(tabItemSource)) { int sourceIndex = this.ItemsSourceProperty.IndexOf(tabItemSource); int targetIndex = this.ItemsSourceProperty.IndexOf(tabItemTarget); this.ItemsSourceProperty.Remove(tabItemSource); this.ItemsSourceProperty.Insert(targetIndex, tabItemSource); this.ItemsSourceProperty.Remove(tabItemTarget); this.ItemsSourceProperty.Insert(sourceIndex, tabItemTarget); NotifyPropChanged("ItemsSourceProperty"); } }
public async Task <bool> RemoveAsync(Persona p, aVMTabBase VM) { if (!this._ObjModels.ContainsKey(p.Id)) { return(false); } Task <QueryBuilder> SQL = Task.Run(() => GetDeleteSQL(p.Id)); ConditionToCommitScalar <int> condition = new ConditionToCommitScalar <int>(ConditionTCType.equal, 1); var tuple = new Tuple <QueryBuilder, IConditionToCommit>(await SQL.ConfigureAwait(false), condition); if (!await AddTransactionWaitingForCommitAsync(tuple, VM)) { return(false); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed RemoveObjectWaitingForCommitAsync(p, VM).Forget().ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(true); }
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously protected MultiBinding NewCargandoMultiBinding(aVMTabBase tab) { MultiBinding cargandoBinding = new MultiBinding(); cargandoBinding.Bindings.Add(new Binding() { Source = (App)Application.Current, Path = new PropertyPath("Initialized.IsNotCompleted"), Mode = BindingMode.OneWay }); cargandoBinding.Bindings.Add(new Binding() { Source = tab, Path = new PropertyPath("TaskCargando.IsNotCompleted"), Mode = BindingMode.OneWay }); SetVisibilityConverter(cargandoBinding, "FalseCollapsed"); cargandoBinding.NotifyOnSourceUpdated = true; return(cargandoBinding); }
public override DataTemplate SelectTemplate(object item, DependencyObject container) { App Application = App.Current as App; aVMTabBase tab = item as aVMTabBase; switch (tab.TabType) { case TabType.Mayor: return((DataTemplate)Application.Resources["TabMayor"]); case TabType.Diario: return((DataTemplate)Application.Resources["TabDiario"]); case TabType.Props: return((DataTemplate)Application.Resources["TabProps"]); case TabType.Cdad: return((DataTemplate)Application.Resources["TabCdad"]); default: return(null); } }
public async Task <CuentaMayor> GetByIdAsync(int id, aVMTabBase VM) { CuentaMayor cuenta; if (!base._ObjModels.TryGetValue(id, out cuenta)) { QueryBuilder qBuilder = await Task.Run(() => GetSelectSQL(id)).ConfigureAwait(false); dynamic result; using (SqlConnection con = new SqlConnection(this._strCon)) { await con.OpenAsync().ConfigureAwait(false); result = await con.QueryAsync(qBuilder.Query, qBuilder.Parameters).ConfigureAwait(false); con.Close(); } cuenta = await Task.Run(() => base._Mapper.Map(result)).ConfigureAwait(false); AddToDictionariesObjectRetrievedFromDBAsync( cuenta, await Task.Run(() => base._Mapper.Map(result)).ConfigureAwait(false), VM) .Forget() .ConfigureAwait(false); await base._RepoSphr.WaitAsync(); this._CuentasIds.TryAdd( new Tuple <int, long>(cuenta.NumCuenta, cuenta.IdOwnerComunidad.CantorPair(cuenta.IdOwnerEjercicio)), cuenta.Id); base._RepoSphr.Release(); } return(cuenta); }
public Command_NewAsientoSimple(aVMTabBase tab) { this._tab = tab; }
protected override QueryBuilder GetUpdateSQL(int id, aVMTabBase VM) { if (base._NewObjects[VM].Select(asiento => asiento.Id).Contains(id) || //If the object have been newly created it needs an INSERT not an UPDATE !base._DirtyMembers[VM].ContainsKey(id)) //If there are no dirty members the object haven't been modified { return(null); } Type t = GetObjModelType(); QueryBuilder qBuilder = new QueryBuilder(); if (!base._DirtyMembers[VM][id].Contains("Apuntes")) { qBuilder .Update(t) .UpdateSet(this._DirtyMembers[VM][id]) .Where(new SQLCondition("Id", "@id")); qBuilder.StoreParametersFrom(this._ObjModels[id]); qBuilder.StoreParameter("id", id); } else { Type tApunte = typeof(Apunte); qBuilder .Update(t) .UpdateSet(this._DirtyMembers[VM][id]) .Where(new SQLCondition("Id", "@id")) .SemiColon() .Append(Environment.NewLine); qBuilder.StoreParametersFrom(this._ObjModels[id]); qBuilder.StoreParameter("id", id); if (base._ObjModels[id].Apuntes.Count > 20) { SemaphoreSlim sphr = new SemaphoreSlim(1); int n = 0; Parallel.ForEach(base._ObjModels[id].Apuntes.Where(apunte => apunte.DirtyMembers.Count > 0), apunte => { sphr.Wait(); int i = n++; sphr.Release(); qBuilder .Update(tApunte) .UpdateSet(apunte.DirtyMembers) .Where(new SQLCondition("Id", $"@apuid{i}")) .SemiColon() .Append(Environment.NewLine); qBuilder.StoreParametersFrom(apunte, apunte.DirtyMembers, i.ToString()); qBuilder.StoreParameter($"apuid{i}", apunte.Id); }); } else { int i = 0; foreach (Apunte apunte in this._ObjModels[id].Apuntes.Where(apunte => apunte.DirtyMembers.Count > 0)) { qBuilder .Update(tApunte) .UpdateSet(apunte.DirtyMembers) .Where(new SQLCondition("Id", $"@apuid{i}")) .SemiColon() .Append(Environment.NewLine); qBuilder.StoreParametersFrom(apunte, apunte.DirtyMembers, i.ToString()); qBuilder.StoreParameter($"apuid{i}", apunte.Id); i++; } } } return(qBuilder); }
public async Task <bool> RemoveAsync(Asiento AsientoObj, aVMTabBase VM) { throw new NotImplementedException(); }
public async Task <Asiento> GetByIdAsync(int id, aVMTabBase VM) { throw new NotImplementedException(); }
internal override async Task RollbackRepoAsync(aVMTabBase VM, Func <Task> doFirstInsideSemaphoreWaiting = null, Func <Task> doLastInsideSemaphoreWaiting = null) { Func <Task> thisFunc = async() => await UpdateDLOsDictionariesAsync(VM.GetOwners()); await base.RollbackRepoAsync(VM, doFirstInsideSemaphoreWaiting, doLastInsideSemaphoreWaiting += thisFunc); }
internal override async Task ApplyChangesAsync(aVMTabBase VM, Func <Task> doFirstInsideSemaphoreWaiting, Func <Task> doLastInsideSemaphoreWaiting) { Func <Task> thisFunc = async() => await UpdateDLOsDictionariesAsync(VM.GetOwners()); await base.ApplyChangesAsync(VM, doFirstInsideSemaphoreWaiting, doLastInsideSemaphoreWaiting += thisFunc); }
public Command_Punteo(aVMTabBase tab) { this._tab = tab; }
public async Task <bool> RemoveAsync(Propietario PropietarioObj, aVMTabBase VM) { throw new NotImplementedException(); }
protected override QueryBuilder GetUpdateSQL(int id, aVMTabBase VM) { throw new NotImplementedException(); }