public int DeleteAccounts() { ClearDataGrid(Viewer.DataGridView_Delete); int count = 0; foreach (var resign in DeleteList) { if (Executioner.DeleteAccount(resign, out string erorr)) { resign.Status = RecordStatus.Deleted; Viewer.AddToDeleteGrid(resign, erorr, ActionOkColor); if (!Adapter.UpdateRecord(resign, out var error)) { throw new DbException(error); } count++; } else { resign.Status = RecordStatus.Erorr; Viewer.AddToDeleteGrid(resign, erorr, ActionFailColor); resign.AppendErrorMessage(erorr); if (!Adapter.UpdateRecord(resign, out var error)) { throw new DbException(error); } } } DeleteList.Clear(); return(count); }
protected override void BringOutYourDead() { if (DeleteList.Count > 0) { ActivatedList = (List <ScreenObject>)(ActivatedList.Except(DeleteList)).ToList(); DeleteList.Clear(); } }
/// <summary> /// 将封存的数据恢复到当前List,结束停止监控List的改变 /// <para>同时清空InsertList,UpdateList,DeleteList</para> /// </summary> public void RestoreList() { IsMonitChanges = false; //保存当前数据至[初始数据列表] CopyModelList <NotificationModel, NotificationModel>(_initialList, this); InsertList.Clear(); UpdateList.Clear(); DeleteList.Clear(); }
/// <summary> /// 结束监控List的改变,并将当前数据封存 /// <para>同时清空InsertList,UpdateList,DeleteList</para> /// </summary> public void EndMoinitChanges() { IsMonitChanges = false; //保存当前数据至[初始数据列表] CopyModelList <NotificationModel, NotificationModel>(this, _initialList); InsertList.Clear(); UpdateList.Clear(); DeleteList.Clear(); }
public async Task <int> CommitAsync() { return(await Task.Factory.StartNew(() => { ValidModel(); try { using (var trans = DbSession.Default.BeginTransaction()) //using(DbBatch batch = DbSession.Default.BeginBatchConnection(20)) { if (InsertList != null && InsertList.Any()) { // List<T> InsertNewList = InsertList.Distinct(new PropertyComparer<T>("Serialnum")).ToList();//按照特定规则排除重复项 trans.Insert(InsertList); //batch.Insert(InsertNewList.ToArray()); } if (DeleteList != null && DeleteList.Any()) { trans.Delete(DeleteList); } //DeleteList.ForEach(delete => //{ // batch.Delete(delete); //}); if (UpdateList != null && UpdateList.Any()) { //List<T> UpdateNewList = UpdateList.Distinct(new PropertyComparer<T>("Serialnum")).ToList();//按照特定规则排除重复项 int i = trans.UpdateAll <T>(UpdateList); //batch.UpdateAll(UpdateNewList.ToArray()); } trans.Commit(); //trans.Commit(); if (InsertList != null && InsertList.Any()) { InsertList.Clear(); } if (DeleteList != null && DeleteList.Any()) { DeleteList.Clear(); } if (UpdateList != null && UpdateList.Any()) { UpdateList.Clear(); } return 1; } } catch (Exception ex) { return 0; //throw; } })); }
public async Task <int> CommitAsync() { ValidModel(); using (var scope = AhnqIotContainer.Container.BeginLifetimeScope()) { var context = scope.Resolve <IDbContext>(new NamedParameter("connectionString", Connectstring)); var loggerFactory = ((DbContext)context).GetService <ILoggerFactory>(); loggerFactory.AddProvider(new DbLoggerProvider(Console.WriteLine)); var dbset = context.Set <T>(); if (InsertList != null && InsertList.Any()) { List <T> InsertNewList = InsertList.Distinct(new PropertyComparer <T>("Serialnum")).ToList();//按照特定规则排除重复项 dbset.AddRange(InsertNewList); } if (DeleteList != null && DeleteList.Any()) { dbset.RemoveRange(DeleteList); } //try //{ if (UpdateList != null && UpdateList.Any()) { List <T> UpdateNewList = UpdateList.Distinct(new PropertyComparer <T>("Serialnum")).ToList();//按照特定规则排除重复项 dbset.UpdateRange(UpdateNewList); } var result = await context.SaveChangesAsync(); //return result; //} //catch (Exception ex) //{ // Console.Clear(); // Console.WriteLine(ex.ToString()); // throw; //} if (InsertList != null && InsertList.Any()) { InsertList.Clear(); } if (DeleteList != null && DeleteList.Any()) { DeleteList.Clear(); } if (UpdateList != null && UpdateList.Any()) { UpdateList.Clear(); } return(result); } }
public int Commit() { ValidModel(); try { using (var trans = DbSession.Default.BeginTransaction()) { if (InsertList != null && InsertList.Any()) { //List<T> InsertNewList = InsertList.Distinct(new PropertyComparer<T>("Serialnum")).ToList();//按照特定规则排除重复项 trans.Insert(InsertList); } if (DeleteList != null && DeleteList.Any()) { trans.Delete(DeleteList); } if (UpdateList != null && UpdateList.Any()) { // List<T> UpdateNewList = UpdateList.Distinct(new PropertyComparer<T>("Serialnum")).ToList();//按照特定规则排除重复项 trans.Update(UpdateList); } trans.Commit(); if (InsertList != null && InsertList.Any()) { InsertList.Clear(); } if (DeleteList != null && DeleteList.Any()) { DeleteList.Clear(); } if (UpdateList != null && UpdateList.Any()) { UpdateList.Clear(); } return(1); } } catch (Exception ex) { return(0); //throw; } }
/// <summary> /// List清空后的处理 /// </summary> private void ItemReset() { InsertList.Clear(); UpdateList.Clear(); DeleteList.Clear(); }