/// <summary> /// 替换字符串里的$函数$和%%变量,结果不带"" /// 表达式结果如果为null,则用string.Empty代替 /// </summary> /// <param name="expression"></param> /// <param name="entity"></param> /// <returns></returns> public static string ReplaceExpression(string expression, object entity) { try { Match m = s_regexExpression.Match(expression); while (m.Success) { string ownExpression = m.Groups[1].Value; object result = EntityScript.CalculateExpression(ownExpression, entity); string replaceString = string.Empty; if (result != null) { replaceString = result.ToString(); } expression = expression.Replace(m.Groups[0].Value, replaceString); m = s_regexExpression.Match(expression); } } catch (Exception ex) { throw new ArgumentException("expression of " + expression + " format is invalid!", ex); } return(expression); }
/// <summary> /// 替换字符串里的%变量%(用entity内变量),用','连接 /// 内部参数带quoto引号 /// </summary> /// <param name="expression"></param> /// <param name="entities"></param> /// <param name="quoto"></param> /// <returns></returns> public static string ReplaceEntities(string expression, object[] entities, char quoto) { try { Match m = s_regexEntityParamter.Match(expression); while (m.Success) { StringBuilder sb = new StringBuilder(); sb.Append(quoto); foreach (object entity in entities) { object v = EntityScript.GetPropertyValue(entity, m.Groups[1].Value); string s = ConvertEntityParamToString(v, null); sb.Append(s); sb.Append(","); } if (sb[sb.Length - 1] == ',') { sb.Remove(sb.Length - 1, 1); } sb.Append(quoto); expression = expression.Replace(m.Groups[0].Value, sb.ToString()); m = s_regexEntityParamter.Match(expression); } } catch (Exception ex) { throw new ArgumentException("expression of " + expression + " format is invalid!", ex); } return(expression); }
//private bool m_needSearchExpression = true; ///// <summary> ///// 是否需要查找条件(如需要,刷新的时候必须要现有条件) ///// </summary> //protected bool NeedSearchConddition //{ // get { return m_needSearchExpression; } // set { m_needSearchExpression = value; } //} /// <summary> /// 重新读入当前行 /// </summary> public void ReloadItem(int idx) { //if (this.DisplayManager.CurrentItem == null) // return; if (this.DisplayManager.EntityInfo == null) { return; } if (idx < 0 || idx >= this.DisplayManager.Count) { return; } object entity = this.DisplayManager.Items[idx]; object id = EntityScript.GetPropertyValue(entity, this.DisplayManager.EntityInfo.IdName); IList list = this.GetData(SearchExpression.Eq(this.DisplayManager.EntityInfo.IdName, id), null) as IList; System.Diagnostics.Debug.Assert(list.Count <= 1); if (list.Count == 0) { return; } else if (list.Count == 1) { this.DisplayManager.Items[idx] = list[0]; } }
/// <summary> /// 替换字符串里的%变量%(用entity内变量)(只有entity变量) /// 注意,返回字符串会的entity变量会带""""(为了表达式计算需要),如果不需要,调用有quoto函数 /// 如果是Enum,例如收付标志.收,只需要写%收付标志%="收" /// </summary> /// <param name="expression"></param> /// <param name="entity"></param> /// <param name="quoto"></param> /// <returns></returns> public static string ReplaceEntity(string expression, object entity, char?quoto = '\"') { return(ReplaceEntity(expression, new GetReplaceValue(delegate(string paramName) { return EntityScript.GetPropertyValue(entity, paramName); }), quoto)); }
private void GenerateNewChild(T parent) { parent.ChildEntity = ReflectionHelper.CreateInstanceFromType(parent.ChildType) as S; parent.ChildEntity.ParentEntity = parent; EntityScript.SetPropertyValue(parent.ChildEntity, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(typeof(S)).IdName, EntityScript.GetPropertyValue(parent, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(typeof(T)).IdName)); }
///// <summary> ///// 在显示当前位置数据前发生 ///// </summary> //public event EventHandler CurrentDisplaying; /// <summary> /// 显示当前位置实体类数据 /// </summary> public virtual void DisplayCurrent() { foreach (IDataControl dc in this.DataControls) { // if in tab control, the data control may be invisible //if (!dc.Visible) // continue; switch (dc.ControlType) { case DataControlType.Unbound: break; case DataControlType.Normal: { if (string.IsNullOrEmpty(dc.PropertyName)) { continue; } if (this.CurrentItem == null) { dc.SelectedDataValue = null; } else { try { dc.SelectedDataValue = EntityScript.GetPropertyValue(this.CurrentItem, dc.Navigator, dc.PropertyName); } catch (Exception ex) { throw new ArgumentException(string.Format("DataControl of {0} is Invalid!", dc.Name), ex); } } } break; case DataControlType.Expression: if (string.IsNullOrEmpty(dc.PropertyName)) { continue; } if (dc.PropertyName.Contains("%")) { dc.SelectedDataValue = EntityScript.CalculateExpression(dc.PropertyName, this.CurrentItem); } else { } break; default: throw new ArgumentException(string.Format("DataControl of {0} is Invalid!", dc.Name)); } } }
/// <summary> /// /// </summary> /// <param name="dm"></param> /// <param name="checkForm"></param> /// <param name="presetValues"></param> /// <returns></returns> public static ArchiveCheckForm Execute(IDisplayManager dm, ArchiveCheckForm checkForm, Dictionary <string, object> presetValues) { if (presetValues != null) { foreach (KeyValuePair <string, object> kvp in presetValues) { if (kvp.Value == null) { MessageForm.ShowError("请先填写" + kvp.Key + "!"); return(null); } } ISearchManager smc = checkForm.DisplayManager.SearchManager; if (smc != null) { foreach (KeyValuePair <string, object> kvp in presetValues) { smc.SearchControls[kvp.Key].SelectedDataValues = new System.Collections.ArrayList { kvp.Value }; } } } DialogResult ret = checkForm.ShowDialog(); if (ret == DialogResult.OK) { if (presetValues != null) { foreach (KeyValuePair <string, object> kvp in presetValues) { dm.DataControls[kvp.Key].ReadOnly = true; // save controlValue to entity EntityScript.SetPropertyValue(dm.CurrentItem, kvp.Key, dm.DataControls[kvp.Key].SelectedDataValue); } } //IControlManager detailCm = ((ArchiveDetailFormAutoWithDetailGrid)detailForm).DetailGrid.ControlManager; return(checkForm); } return(null); }
private void Load() { m_buffers = new System.Collections.Generic.Dictionary <object, object>(); using (IRepository rep = ServiceProvider.GetService <IRepositoryFactory>().GenerateRepository(m_persistentClass)) { rep.BeginTransaction(); IList list = rep.List(m_persistentClass); rep.CommitTransaction(); foreach (object i in list) { object id = EntityScript.GetPropertyValue(i, ServiceProvider.GetService <IEntityMetadataGenerator>().GenerateEntityMetadata(m_persistentClass).IdName); m_buffers[id] = i; } } }
///// <summary> ///// 在保存当前位置数据前发生 ///// </summary> //public event EventHandler SavingCurrent; ///// <summary> ///// 在保存当前位置数据后发生 ///// </summary> //public event EventHandler CurrentSaved; /// <summary> /// 保存当前数据 /// </summary> public virtual bool SaveCurrent() { //if (this.SavingCurrent != null) //{ // this.SavingCurrent(this, System.EventArgs.Empty); //} if (!this.CheckControlsValue()) { return(false); } if (this.DisplayManager.CurrentItem == null) { throw new InvalidOperationException("DisplayManager's CurrentItem is null"); } foreach (IDataControl dc in this.DisplayManager.DataControls) { // if in tab control, the data control may be invisible //if (!dc.Visible) // continue; if (dc.ReadOnly) { continue; } switch (dc.ControlType) { case DataControlType.Unbound: break; case DataControlType.Normal: { if (string.IsNullOrEmpty(dc.PropertyName)) { continue; } //if (this.State == StateType.Add) //{ // if (!dc.Insertable) // continue; //} //else if (this.State == StateType.Edit) //{ // if (!dc.Editable) // continue; //} //else //{ // throw new NotSupportedException("Invalid State of " + this.State); //} EntityScript.SetPropertyValue(this.DisplayManager.CurrentItem, dc.Navigator, dc.PropertyName, dc.SelectedDataValue); } break; case DataControlType.Expression: { Script.ExecuteStatement(dc.Navigator, new Dictionary <string, object> { { "entity", this.DisplayManager.CurrentItem }, { "cm", this } }); } break; } } return(true); }