/// <summary> /// 自动加载进所有编辑控件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAll_Click(object sender, EventArgs e) { this._saves.Clear(); this._warningTable.Clear(); DataEntity dataEntity = _formDataEntityTreeChoose.SelectedDataEntity; WindowEntity windowEntity = this.HostAdapter.HostFormEntity; DataSourceProvideArgs dataSourceProvideArgs = new DataSourceProvideArgs() { WindowEntity = windowEntity }; foreach (UIElement formElement in windowEntity.Elements) { if (formElement.DataSourceUseable == false) { continue; } IUIElementEditControl iFormElementEditControl = formElement as IUIElementEditControl; if (iFormElementEditControl == null) { continue; } if (String.IsNullOrEmpty(iFormElementEditControl.DataItemId)) { continue; } string[] ids = iFormElementEditControl.DataItemId.Split('.'); string dataEntityId = ids[0]; string dataItemId = ids[1]; if (dataEntityId != dataEntity.Id) { continue; } DataItemEntity dataItemEntity = dataEntity.Items.GetEntityById(dataItemId); if (dataItemEntity == null) { continue; } string source = _dataSourceProvideFactory.GetDataSourceString(formElement, dataSourceProvideArgs); string sourceName = _dataSourceProvideFactory.GetDisplayString(source, dataSourceProvideArgs); SaveDataEvent.SaveItem save = new SaveDataEvent.SaveItem() { DataItem = dataItemId, DataItemName = dataItemEntity.Name, Source = source, SourceName = sourceName }; this._saves.Add(save); } }
public void Create(WindowEntity formEntity) { //不能在FormDesignSurfaceHosting的VisibleChanged事件中,设置当前活动设计器或撤销重做引擎这些当前对象 //在多个设计窗体切换时,要显示的窗体的Visible=true,然后被切掉的窗体才Visible=false,永远走到false里去 if (OnDesign(formEntity.Id)) { //激活 foreach (IDockContent dockContent in this.dockPanel.Documents) { FormDesignSurfaceHosting hosting = dockContent as FormDesignSurfaceHosting; if (hosting.WindowEntity.Id == formEntity.Id) { dockContent.DockHandler.Activate(); } } } else { //创建新的设计器容器 FormDesignSurfaceHosting hosting = new FormDesignSurfaceHosting(formEntity, this._designSurfaceManager.NewDesignSurface(), this); hosting.SelectionService.SelectionChanged += new EventHandler(SelectionService_SelectionChanged); hosting.InitFormElementsComponentComplete += new FormDesignSurfaceHosting.OnInitFormElementsComponentCompleteHandler(hosting_InitFormElementsComponentComplete); hosting.DockAreas = DockAreas.Document; hosting.Show(this.dockPanel); } }
public FormDesignSurfaceHosting(WindowEntity windowEntity, SEDesignSurface designSurface, FormHostingContainer hostingContainer) { InitializeComponent(); if (DesignMode) { return; } this._windowEntity = windowEntity; this.Icon = DrawingTool.ImageToIcon(IconsLibrary.Form); this.SetTabText(); this.HideOnClose = false; this._undoEngine = new SEUndoEngineFormDesigner(this); this._designSurface = designSurface; this.HostingContainer = hostingContainer; this.TabPageContextMenuStrip = HostingTabPageContextMenuStrip.Instance.MenuStrip; //初始化DesignSurface //在此初始化,保证FormHostingContainer中的dockPanel_ActiveDocumentChanged执行时 //能拿到DesignSurface中的服务 this._designSurface = InitialseDesignSurface(); }
public WindowEntity GetWindowEntity(string id) { //首先尝试从缓存中获取 XElement cachingElement = (XElement)_cachingService.GetData(id); string strEntity; if (cachingElement == null) { string file = Path.Combine(Constant.PACKAGE_WINDOW_FOLDER, id); bool fileExist = _packageService.Current.Container(file); Debug.Assert(fileExist, "窗体文件不存在"); if (fileExist == false) { return(null); } strEntity = _packageService.Current.GetFileContent(file); XElement entityElement = XElement.Parse(strEntity); _cachingService.Add(id, entityElement); } else { strEntity = cachingElement.ToString(); } WindowEntity entity = _windowElementContainer.CreateWindowEntity(); entity.FromXml(strEntity); return(entity); }
/// <summary> /// 根据给定的实体对象更新控件的属性 /// </summary> /// <param name="control"></param> /// <param name="formEntity"></param> public static void PropertyDescriptorUpdate(Control control, WindowEntity formEntity) { SetProperty(control, "Text", formEntity.Text); SetProperty(control, "Size", formEntity.Size); SetProperty(control, "BackColor", formEntity.BackColor); SetProperty(control, "ForeColor", formEntity.ForeColor); PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(control); PropertyDescriptor pds; //font还是这样手动设置,因为在不设置字体时,既不能设一个过去,也不能设null //只有不设字体,才能使其使用系统默认并与父容器同步 pds = pdc.Find("Font", false); if (pds != null) { if (formEntity.Font != null) { if (!pds.GetValue(control).Equals(formEntity.Font.Font)) { pds.SetValue(control, formEntity.Font.Font); } } else { pds.SetValue(control, SystemFonts.DefaultFont); } } }
public void Update(WindowEntity entity) { Debug.Assert(entity != null, "FormEntity 为 null"); if (entity == null) { return; } //更新索引信息 XElement element = _indexXml.XPathSelectElement(String.Format(XPATH_index_SelectWindow, entity.Id)); Debug.Assert(element != null, "更新窗体索引时未找到指定窗体的索引记录"); if (element != null) { element.ReplaceWith(GetArchiveIndex(entity)); SaveIndexFile(); string xml = entity.ToXml(); XElement xElement = XElement.Parse(xml); //更新实体文件 _packageService.Current.AddFileContent(xml, Path.Combine(Constant.PACKAGE_WINDOW_FOLDER, entity.Id)); //更新缓存 _cachingService.Add(entity.Id, xElement); //发布事件 WindowEventArgs args = new WindowEventArgs(entity); _eventAggregator.GetEvent <WindowUpdatedEvent>().Publish(args); } }
public void Add(WindowEntity entity) { Debug.Assert(entity != null, "FormEntity 为 null"); if (entity == null) { return; } //添加索引信息 _indexXml.XPathSelectElement(XPATH_Index_Window).Add(GetArchiveIndex(entity)); SaveIndexFile(); string xml = entity.ToXml(); XElement xElement = XElement.Parse(xml); //添加实体文件 _packageService.Current.AddFileContent(xml, Path.Combine(Constant.PACKAGE_WINDOW_FOLDER, entity.Id)); _cachingService.Add(entity.Id, xElement); //发布事件 WindowEventArgs args = new WindowEventArgs(entity); _eventAggregator.GetEvent <WindowAddedEvent>().Publish(args); }
public WindowEntity CreateWindowEntity() { Debug.Assert(_windowEntityType != null, "_windowEntityType 为 null"); WindowEntity entity = (WindowEntity)Activator.CreateInstance(_windowEntityType); return(entity); }
public FormFormElementChoose(WindowEntity formEntity) { InitializeComponent(); Unity.ApplyResource(this); ApplyLanguageResource(); this.formEntity = formEntity; }
public FormEventDataListDataSet(WindowEntity formEntity) { InitializeComponent(); Unity.ApplyResource(this); ApplyLanguageResource(); this.formEntity = formEntity; this.txtDataColumn.Location = this.ddlDataColumn.Location; this.txtDataColumn.Size = this.ddlDataColumn.Size; }
public FormEventReceiveDataSet(WindowEntity formEntity) { InitializeComponent(); Unity.ApplyResource(this); ApplyLanguageResource(); this.formEntity = formEntity; this.ddlFormElement.AllowDataSource = EnumEventDataSource.FormElement; this.ddlFormElement.AllowFormElementControlType = ReceiveDataDev.AllowTargetFormElementControlType; this.ddlFormElement.FormEntity = this.formEntity; }
void IArchiveService.Delete(object obj) { WindowEntity entity = obj as WindowEntity; Debug.Assert(entity != null, "entity为null"); if (entity != null) { Delete(entity); } }
public FormEventDataItemDataSet(WindowEntity formEntity) { InitializeComponent(); _dataEntityComponentService = ServiceUnity.Container.Resolve <IDataEntityComponentService>(); Unity.ApplyResource(this); ApplyLanguageResource(); this.txtDataItem.Location = this.ddlDataItem.Location; this.txtDataItem.Size = this.ddlDataItem.Size; this.formEntity = formEntity; }
public void Delete(WindowEntity entity) { Debug.Assert(entity != null, "FormEntity 为 null"); if (entity == null) { return; } Delete(entity.Id); }
public FormEventOpenFormSendDataSet(WindowEntity formEntity) { InitializeComponent(); this.txtDataCode.Regex = CoreConstant.ENTITY_CODE_REGEX; Unity.ApplyResource(this); ApplyLanguageResource(); this.formEntity = formEntity; this.ddlFormElement.AllowDataSource = EnumEventDataSource.FormElement; this.ddlFormElement.AllowFormElementControlType = OpenWindowDev.AllowFormElementControlType; this.ddlFormElement.FormEntity = this.formEntity; }
public WindowEntityCollection GetAllWindow() { WindowEntityCollection list = new WindowEntityCollection(); foreach (XElement element in _indexXml.XPathSelectElements(XPATH_Index_Window_Entity)) { WindowEntity entity = GetWindowEntity(element.Attribute("Id").Value); list.Add(entity); } return(list); }
public FormEventReturnDataToCallerFormSet(WindowEntity formEntity) { InitializeComponent(); Unity.ApplyResource(this); ApplyLanguageResource(); this.formEntity = formEntity; this.ddlFormElement.AllowDataSource = EnumEventDataSource.FormElement; this.ddlFormElement.AllowFormElementControlType.Add(typeof(UIElementTextBoxEntity)); this.ddlFormElement.AllowFormElementControlType.Add(typeof(UIElementComboBoxEntity)); this.ddlFormElement.AllowFormElementControlType.Add(typeof(UIElementDataListTextBoxColumnEntity)); this.ddlFormElement.FormEntity = this.formEntity; }
public void CreateEntity(WindowEntity formEntity) { FormElementDataListEntityDev entity = new FormElementDataListEntityDev(); entity.Id = Guid.NewGuid().ToString(); entity.Code = ShellControlHelper.EntityCodeCreation(PREFIX, formEntity); entity.Name = entity.Code; formEntity.Elements.Add(entity); this.Entity = entity; }
/// <summary> /// 获取用于存储在XML索引文件中的索引节点 /// </summary> /// <param name="entity"></param> /// <returns></returns> private XElement GetArchiveIndex(WindowEntity entity) { Debug.Assert(entity != null, "entity 为 null"); XElement ele = new XElement("Entity", new XAttribute("Id", entity.Id), new XAttribute("Name", entity.Name), new XAttribute("Code", entity.Code), new XAttribute("Sys", entity.Sys), new XAttribute("Folder", entity.FolderId)); return(ele); }
public WindowEntityCollection GetWindowList(string folderId) { WindowEntityCollection list = new WindowEntityCollection(); foreach (XElement element in _indexXml.XPathSelectElements( String.Format(XPATH_Index_SelectWindow_ByFolderId, folderId))) { WindowEntity entity = GetWindowEntity(element.Attribute("Id").Value); list.Add(entity); } return(list); }
public override void SetParameter(EventBase even) { OpenWindowDev _event = even as OpenWindowDev; this.txtName.Text = _event.Name; this.txtCode.Text = _event.Code; _selectedFormEntity = _windowComponentService.GetWindowEntity(_event.WindowId); if (_selectedFormEntity != null) { this.txtFormName.Text = this._selectedFormEntity.Name; } this.cbIsDiablog.Checked = _event.IsDialog; this.ddlIfOpend.SelectedValue = ((int)_event.IfOpend).ToString(); }
/// <summary> /// 提交 /// 根据Id进行判断,如果已存在,调用update,如果不存在,调用add /// </summary> /// <param name="dataEntity"></param> public void Commit(WindowEntity entity) { Debug.Assert(entity != null, "FormEntity 为 null"); if (entity == null) { return; } if (CheckExistById(entity.Id)) { Update(entity); } else { Add(entity); } }
private void ChooseForm() { using (FormFormChoose formFormChoose = new FormFormChoose()) { if (formFormChoose.ShowDialog() == DialogResult.OK) { _selectedFormEntity = formFormChoose.SelectedForm; } } if (_selectedFormEntity != null) { txtFormName.Text = _selectedFormEntity.Name; } else { txtFormName.Text = String.Empty; } }
public static string DataSourceVisibleString(WindowEntity formEntity, string str, out bool warning) { warning = false; if (str == null || str == String.Empty) { warning = true; return(String.Empty); } if (!str.StartsWith("FormElement.") && !str.StartsWith("System.")) { warning = true; throw new ArgumentException(); } string visibleStr; string[] strArray = str.Split('.'); switch (strArray[0]) { case "FormElement": UIElement formElement = formEntity.FindFormElementById(strArray[1]); if (formElement == null) { warning = true; return(String.Empty); } visibleStr = FormElementVisibleString(formElement); break; case "System": EnumSystemDataSource enumSystemDataSource = (EnumSystemDataSource)Enum.Parse(typeof(EnumSystemDataSource), strArray[1]); visibleStr = EnumSystemDataSourceVisibleString(enumSystemDataSource); break; default: throw new NotImplementedException(); } return(visibleStr); }
private void btnOK_Click(object sender, EventArgs e) { if (!this.DoValidate()) { return; } if (WindowArchive.Instance.CheckExistByCode(txtCode.Text)) { MessageBox.Show(Language.Current.WindowEditView_MessageFormEntityCodeExist, CommonLanguage.Current.MessageCaption_Notice, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this.FormEntity = ServiceUnity.WindowElementContainer.CreateWindowEntity(); this.FormEntity.Name = txtName.Text; this.FormEntity.Code = txtCode.Text; this.FormEntity.Text = txtName.Text; this.FormEntity.FolderId = this.folderId; WindowArchive.Instance.Add(this.FormEntity); this.DialogResult = DialogResult.OK; this.Close(); }
//否决,转到WindowEntity中了 /// <summary> /// 根据指定的实体类型,获取一个新的code /// </summary> /// <param name="prefix"></param> /// <param name="formEntity"></param> /// <returns></returns> public static string EntityCodeCreation(string prefix, WindowEntity formEntity) { int value = 0; //当前编号数组 List <int> codes = new List <int>(); //这里需要连同InnerElement一起获取 foreach (UIElement element in formEntity.GetFormElement(true)) { string name = element.Code; if (name.StartsWith(prefix)) { if (Int32.TryParse(name.Substring(prefix.Length), out value)) { codes.Add(value); } } } codes.Sort(); int lastValue = 0; //上一个值,用于判断是否中间有空缺要补 foreach (int code in codes) { if (code - lastValue > 1) { break; } else { lastValue = code; } } return(prefix + (lastValue + 1)); }
public System.Collections.IEnumerable GetChildren(TreePath treePath) { if (treePath.IsEmpty()) { foreach (WindowFolderEntity folder in _windowComponentService.GetFolderCollection()) { FolderItem item = new FolderItem(folder); yield return(item); } foreach (WindowEntity form in _windowComponentService.GetWindowList(String.Empty)) { FormItem item = new FormItem(form, null); yield return(item); } } else { List <GlobalFormElementTreeItemBase> items = new List <GlobalFormElementTreeItemBase>(); GlobalFormElementTreeItemBase parent = treePath.LastNode as GlobalFormElementTreeItemBase; if (parent != null) { if (parent is FolderItem) { FolderItem folderItem = (FolderItem)parent; WindowFolderEntity formFolderEntity = folderItem.Folder; if (formFolderEntity != null) { foreach (WindowEntity formEntityItem in _windowComponentService.GetWindowList(formFolderEntity.Id)) { GlobalFormElementTreeItemBase elementItem = new FormItem(formEntityItem, parent); items.Add(elementItem); } } } WindowEntity formEntity = parent.Entity as WindowEntity; if (formEntity != null) { foreach (UIElement formElementItem in formEntity.GetFormElement()) { if (this.AllowFormElementControlType.Allowable(formElementItem)) { GlobalFormElementTreeItemBase elementItem = new FormElementItem(formElementItem, parent); items.Add(elementItem); } else { foreach (UIElement innerElement in formElementItem.GetInnerElement()) { if (this.AllowFormElementControlType.Allowable(innerElement)) { GlobalFormElementTreeItemBase elementItem = new FormElementItem(formElementItem, parent); items.Add(elementItem); break; } } } } } UIElement formElement = parent.Entity as UIElement; if (formElement != null) { foreach (UIElement formElementItem in formElement.GetInnerElement()) { if (this.AllowFormElementControlType.Allowable(formElementItem) == false) { continue; } GlobalFormElementTreeItemBase elementItem = new FormElementItem(formElementItem, parent); items.Add(elementItem); } } foreach (GlobalFormElementTreeItemBase item in items) { yield return(item); } } else { yield break; } } }
public WindowEntityIndex(WindowEntity entity) { _window = entity; _initialized = true; }
public void Save(WindowEntity formEntity) { _windowArchive.Commit(formEntity); }
public FormPropertyGrid(FormHostingContainer container) { InitializeComponent(); _container = container; _container.ActiveHostingChanged += new FormHostingContainer.OnActiveHostingChangedHandler(_container_ActiveHostingChanged); _container.HostingSelectionChanged += new FormHostingContainer.OnHostingSelectionChangedHandler(_container_HostingSelectionChanged); _container.HostingInitFormElementsComponentComplete += new FormHostingContainer.OnHostingInitFormElementsComponentCompleteHandler(_container_HostingInitFormElementsComponentComplete); #region PropertyGridValidator PropertyGridValidator validator = new PropertyGridValidator(typeof(EntityBase)) { ActOnSub = true, }; validator.Validator = (e) => { bool success = true; string message = null; //因为C#是区分大小写的,所以这里不转为全小写或全大写,避免Code和CODE两个不同Property //理论上我不会这么做 if (e.Property == EntityBase.Property_Code) { //判断是否使用了系统保留字 if (Keywords.Container(e.Value.ToString())) { success = false; message = CommonLanguage.Current.ValueInefficacyUseKeywords; } else { Debug.Assert(e.Objects.Length == 1, "验证 Code 时对象数目只能是一个"); object obj = e.Objects[0]; string value = e.Value.ToString(); //判断在此窗体范围内,代码是否已被占用 if (FormHostingContainer.Instance.ActiveFormEntity.ValidateCode(value) == false) { success = false; message = Language.Current.FormDesigner_FormPropertyGrid_MessageFormElementCodeExist; } else { //如果当前选择的目标对象是一个窗体,则还需判断指定的代码是否与其它窗体的代码冲突 //此处不用考虑多选的情况,因为多选状态下,代码属性不显示 WindowEntity windowEntity = e.Objects[0] as WindowEntity; if (windowEntity != null) { //判断code是否已被占用 if (_windowComponentService.CheckExistByCode(value)) { success = false; message = Language.Current.FormDesigner_FormPropertyGrid_MessageFormEntityExist; } } } } } return(new PropertyGridValidateResult(success, message)); }; propertyGrid.AddValidator(validator); #endregion //注意,ComboBox里绑定的对象是实际控件,不是Entity this.comboBoxFormElementList.DrawMode = DrawMode.OwnerDrawFixed; this.comboBoxFormElementList.Sorted = false; this.comboBoxFormElementList.DrawItem += new DrawItemEventHandler(ComboBoxDrawItem); this.comboBoxFormElementList.MeasureItem += new MeasureItemEventHandler(ComboBoxMeasureItem); this.comboBoxFormElementList.SelectedIndexChanged += new EventHandler(ComboBoxSelectedIndexChanged); this.VisibleChanged += new EventHandler(FormPropertyGrid_VisibleChanged); this.Icon = DrawingTool.ImageToIcon(IconsLibrary.Property); this.TabText = Language.Current.FormPropertyGrid_TabText; }