Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        ///// <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);
        }