Exemple #1
0
        /// <summary>
        /// 根据录屏结果生成实体及映射
        /// </summary>
        /// <param name="categoryID">分类ID</param>
        /// <param name="recordCollection">录屏集合</param>
        public string RecordResultGenerate(string categoryID, RecordResultCollection recordCollection)
        {
            categoryID.CheckStringIsNullOrEmpty <ArgumentNullException>("categoryID");
            recordCollection.NullCheck <ArgumentNullException>("录屏集合不能为空!");

            string masterEntityID = string.Empty;

            #region 验证
            //只验证主表,子表可以为空
            recordCollection.Any().FalseThrow("没有找到信息项,请重新填写!");

            //验证CodeName唯一性
            recordCollection.Select(p => p.EntityName).Distinct().ForEach(p =>
                                                                          DESchemaObjectAdapter.Instance.CheckCodeNameExist(categoryID, p).TrueThrow(string.Format("已存在同名[{0}]", p)));
            #endregion

            List <string> listFullName = recordCollection.Select(p => p.TempFullPath).Distinct().ToList();

            //按长度倒序排序,确保从最子级节点开始添加实体
            listFullName = listFullName.OrderByDescending(p => p.Split('/').Length).ToList();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                listFullName.ForEach(fullName =>
                {
                    //准备数据
                    var entityRecordList = recordCollection.Where(r => r.TempFullPath.Equals(fullName));
                    var entityResultColl = new RecordResultCollection();
                    entityResultColl.CopyFrom(entityRecordList);

                    //实体入库
                    var childEntity = entityResultColl.BuildEntity(categoryID);
                    DEObjectOperations.InstanceWithoutPermissions.DoOperation(SCObjectOperationMode.Add, childEntity, null);

                    //为父实体指定“引用实体”属性值
                    if (fullName.Contains("/"))
                    {
                        string parentFullName  = fullName.Substring(0, fullName.LastIndexOf("/"));
                        string parentFieldName = fullName.Replace(parentFullName + "/", "");
                        recordCollection.First(pe => pe.TempFullPath.Equals(parentFullName) && pe.FieldName.Equals(parentFieldName)).ReferenceEntityCodeName =
                            childEntity.CodeName;
                    }

                    //映射入库
                    EntityMapping childMapping = BuildEntityMapping(childEntity);
                    DEObjectOperations.InstanceWithoutPermissions.AddEntityMapping(childMapping);

                    //最后一个被添加的实体为主实体
                    masterEntityID = childEntity.ID;
                });

                scope.Complete();

                #region 以前方法,先注释掉
                ///////////////////////////////////////////////////////////////////////////////////////
                //#region 实体定义
                ////先入子表
                //recordCollection.Where(p => !p.IsMasterTable).GroupBy(p => p.EntityName).ToList().ForEach(p =>
                //{
                //    RecordResultCollection child = new RecordResultCollection();
                //    child.CopyFrom(p.ToList());

                //    var childEntity = child.BuildEntity(categoryID);
                //    DEObjectOperations.InstanceWithoutPermissions.DoOperation(SCObjectOperationMode.Add, childEntity, null);

                //    //添加子类引用
                //    recordCollection.Add(new Dynamics.Objects.RecordResult()
                //    {
                //        EntityName = recordCollection.FirstOrDefault(m => m.IsMasterTable).EntityName,
                //        EntityDesc = recordCollection.FirstOrDefault(m => m.IsMasterTable).EntityName,
                //        IsMasterTable = true,
                //        FieldName = p.Key,
                //        FieldType = FieldTypeEnum.Collection,
                //        ReferenceEntityCodeName = childEntity.CodeName,
                //        FieldDesc = p.Key,
                //        FieldLength = 99999,
                //        SortNo = recordCollection.Count(m => m.IsMasterTable) + 1,
                //        IsStruct = p.All(f => f.EntityDesc == "STRUCTURE")
                //    });
                //});

                //// 主表
                //RecordResultCollection master = new RecordResultCollection();
                //master.CopyFrom(recordCollection.Where(p => p.IsMasterTable).ToList());
                //var masterEntity = master.BuildEntity(categoryID);

                //DEObjectOperations.InstanceWithoutPermissions.DoOperation(SCObjectOperationMode.Add, masterEntity, null);
                //#endregion

                //// 主表映射
                //EntityMapping masterMapping = BuildEntityMapping(masterEntity);
                //DEObjectOperations.InstanceWithoutPermissions.AddEntityMapping(masterMapping);

                ////子表映射
                //masterEntity.Fields.Where(p => p.FieldType == FieldTypeEnum.Collection).ForEach(f =>
                //{
                //    DynamicEntity childEntity = DEDynamicEntityAdapter.Instance.LoadByCodeName(f.ReferenceEntityCodeName) as DynamicEntity;
                //    EntityMapping childMapping = BuildEntityMapping(childEntity);

                //    DEObjectOperations.InstanceWithoutPermissions.AddEntityMapping(childMapping);
                //});

                //masterEntityID = masterEntity.ID;
                //scope.Complete();
                #endregion
            }

            return(masterEntityID);
        }
        protected void btn_getEntityDefine_Click(object sender, EventArgs e)
        {
            center_panel.Visible = true;



            RecordResultCollection rrc = GetData(txt_Code.Text.Trim());

            List <string> cou = rrc.Select(p => p.EntityName).Distinct().ToList();

            foreach (string entityName in cou)
            {
                ClientGrid gr = new ClientGrid();

                gr.EnableViewState = false;


                gr.ID                 = entityName;
                gr.AllowPaging        = false;
                gr.ShowEditBar        = true;
                gr.AutoPaging         = false;
                gr.ShowCheckBoxColumn = true;
                gr.ID                 = Guid.NewGuid().ToString();
                controlIDs.Add(gr.ID);
                var recordCollention = rrc.Where(p => p.EntityName.Equals(entityName));
                ClientGridColumn cgc = new ClientGridColumn();  //checkbox
                cgc.SelectColumn  = true;
                cgc.ShowSelectAll = true;
                cgc.HeaderStyle   = "{width:'30px',textAlign:'left',fontWeight:'bold'}";
                cgc.ItemStyle     = "{width:'30px',textAlign:'left'}";

                gr.Columns.Add(cgc);

                ClientGridColumn cgIndex = new ClientGridColumn();

                cgIndex.DataField   = "rowIndex";
                cgIndex.HeaderText  = "序号";
                cgIndex.HeaderStyle = "{width:'30px',textAlign:'center'}";
                cgIndex.ItemStyle   = "{width:'30px',textAlign:'center'}";
                cgIndex.DataType    = DataType.Integer;
                gr.Columns.Add(cgIndex);

                ClientGridColumn cgFieldName = new ClientGridColumn();
                cgFieldName.DataField             = "FieldName";
                cgFieldName.HeaderText            = "字段名";
                cgFieldName.HeaderStyle           = "{textAlign:'left'}";
                cgFieldName.ItemStyle             = "{textAlign:'left'}";
                cgFieldName.DataType              = DataType.String;
                cgFieldName.EditTemplate.EditMode = ClientGridColumnEditMode.TextBox;
                gr.Columns.Add(cgFieldName);

                ClientGridColumn cgFieldDesc = new ClientGridColumn();
                cgFieldDesc.DataField             = "FieldDesc";
                cgFieldDesc.HeaderText            = "字段描述";
                cgFieldDesc.HeaderStyle           = "{textAlign:'left'}";
                cgFieldDesc.ItemStyle             = "{textAlign:'left'}";
                cgFieldDesc.DataType              = DataType.String;
                cgFieldDesc.EditTemplate.EditMode = ClientGridColumnEditMode.TextBox;
                gr.Columns.Add(cgFieldDesc);

                ClientGridColumn cgFieldTypeName = new ClientGridColumn();
                cgFieldTypeName.DataField             = "FieldType";
                cgFieldTypeName.HeaderText            = "字段类型";
                cgFieldTypeName.HeaderStyle           = "{textAlign:'left'}";
                cgFieldTypeName.ItemStyle             = "{textAlign:'left'}";
                cgFieldTypeName.DataType              = DataType.String;
                cgFieldTypeName.EditTemplate.EditMode = ClientGridColumnEditMode.TextBox;
                gr.Columns.Add(cgFieldTypeName);


                ClientGridColumn cgFieldLength = new ClientGridColumn();
                cgFieldLength.DataField             = "FieldLength";
                cgFieldLength.HeaderText            = "字段长度";
                cgFieldLength.HeaderStyle           = "{textAlign:'left'}";
                cgFieldLength.ItemStyle             = "{textAlign:'left'}";
                cgFieldLength.DataType              = DataType.String;
                cgFieldLength.EditTemplate.EditMode = ClientGridColumnEditMode.TextBox;
                gr.Columns.Add(cgFieldLength);

                ClientGridColumn cgFieldDefaultValue = new ClientGridColumn();
                cgFieldDefaultValue.DataField             = "DefaultValue";
                cgFieldDefaultValue.HeaderText            = "字段默认值";
                cgFieldDefaultValue.HeaderStyle           = "{textAlign:'left'}";
                cgFieldDefaultValue.ItemStyle             = "{textAlign:'left'}";
                cgFieldDefaultValue.DataType              = DataType.String;
                cgFieldDefaultValue.EditTemplate.EditMode = ClientGridColumnEditMode.TextBox;
                gr.Columns.Add(cgFieldDefaultValue);

                ClientGridColumn cgOuterFieldName = new ClientGridColumn();
                cgOuterFieldName.DataField   = "FieldName";
                cgOuterFieldName.HeaderText  = "关联字段/结构";
                cgOuterFieldName.HeaderStyle = "{textAlign:'left'}";
                cgOuterFieldName.ItemStyle   = "{textAlign:'left'}";
                cgOuterFieldName.DataType    = DataType.String;
                gr.Columns.Add(cgOuterFieldName);
                gr.InitialData = recordCollention.ToList();



                DataBindingItem dbItem = new DataBindingItem();
                dbItem.ControlID           = entityName;
                dbItem.DataPropertyName    = "EntityFieldMappingCollection";
                dbItem.ControlPropertyName = "InitialData";
                dbItem.Direction           = BindingDirection.Both;

                Panel pa = new Panel();

                Label lb = new Label();
                lb.Text = string.Format(@"<div class='dialogTitle'>
                                <div class='lefttitle' style='text-align: left;'>
                                    <img src='../Images/icon_01.gif'/>
                                    编辑{0}主实体字段及关联</div>
                            </div>", entityName);
                pa.Controls.Add(lb);

                Panel pn = new Panel();
                pn.ID       = "Panel_" + entityName;
                pn.CssClass = "dialogContent";

                pn.Controls.Add(gr);

                center_panel.Controls.Add(pa);
                center_panel.Controls.Add(pn);
            }



            ViewState["controlids"] = controlIDs;



            EntityMapping mapping = new EntityMapping();
        }