void RaiseBeginUpdate(VisualTreeItem element) { if (Parent != null) { Parent.RaiseBeginUpdate(element); return; } BeginUpdate?.Invoke(element, EventArgs.Empty); }
void ImportData() { BeginUpdate?.Invoke(); foreach (uint idTable in m_importData.Keys) { using (IDatumProvider dp = AppContext.TableManager.GetTable(idTable).DataProvider) { dp.Connect(); foreach (IDataRow row in m_importData[idTable]) { dp.Insert(row); } } } m_importedTable = m_importData.Keys.ToArray(); }
/// <summary> /// 通过EF进行更新 /// </summary> /// <param name="model"></param> /// <param name="sameValueWhere"></param> public void UpdateByEF(T model, Expression <Func <T, bool> > sameValueWhere) { if (BeginUpdate != null) { BeginUpdate.Invoke(model); } PropertyInfo editProperty = model.GetType().GetProperty("EditTime"); if (editProperty != null) { editProperty.SetValue(model, DateTime.Now, null); } if (_provider.UpdateByEF(model, sameValueWhere)) { if (EndUpdate != null) { EndUpdate.Invoke(model); } } }
/// <summary> /// 更新 /// </summary> /// <param name="model">对象</param> /// <param name="fields">更新字段</param> /// <param name="idPropertyName">Id字段名</param> /// <param name="sameValuePropertyName">检测相同值字段名</param> /// <returns></returns> public bool Update(T model, string[] fields = null, string idPropertyName = "Id", string sameValuePropertyName = "") { if (BeginUpdate != null) { BeginUpdate.Invoke(model); } PropertyInfo editProperty = model.GetType().GetProperty("EditTime"); if (editProperty != null) { editProperty.SetValue(model, DateTime.Now, null); } PropertyInfo propertyId = model.GetType().GetProperty(idPropertyName); if (!string.IsNullOrEmpty(sameValuePropertyName)) { PropertyInfo propertySameValue = model.GetType().GetProperty(sameValuePropertyName); string check = new ConditionHelper().And(idPropertyName, propertyId.GetValue(model, null), CompareType.Unequal) .And(sameValuePropertyName, propertySameValue.GetValue(model, null), CompareType.Equal).ToString(); DynamicParameters p = new DynamicParameters(); p.Add($"@{idPropertyName}", propertyId.GetValue(model, null)); p.Add($"@{sameValuePropertyName}", propertySameValue.GetValue(model, null)); if (_provider.GetItem <T>(check, p) != null) { throw new SameValueException(); } } string fieldsStr = ""; if (fields != null) { List <string> builder = new List <string>(); foreach (var field in fields) { builder.Add($"{field} = @{field}"); } fieldsStr = string.Join(",", builder.ToArray()); } else { Type type = typeof(T); PropertyInfo[] propertys = type.GetProperties(); List <string> builder = new List <string>(); foreach (var property in propertys) { if (property.Name != sameValuePropertyName) { builder.Add($"{property.Name} = @{property.Name}"); } } fieldsStr = string.Join(",", builder); } string condition = new ConditionHelper().And(idPropertyName, propertyId.GetValue(model, null), CompareType.Equal).ToString(); if (_provider.Update(condition, fieldsStr, model)) { if (EndUpdate != null) { EndUpdate.Invoke(model); } return(true); } else { return(false); } }