public BuildEntityRefrence(BEColumn col)
     : base(col)
 {
     if (string.IsNullOrEmpty(_col.RefColGuid))
     {
         _templateCode = BECodeTemplate.RefrenceTemplate;
     }
     else
     {
         _templateCode = BECodeTemplate.RefrenceCompositionTemplate;
     }
 }
        private bool DataCollect()
        {
            if (this._currentProj == null || this._currentProjNode == null) return true;
            this._currentProj.Namespace = this.tbNameSpace.Text;
            if (this._collectDataNode == null) return true;
            try
            {
                #region 实体类型
                if (this._collectDataNode.NodeType == NodeType.BEEntity)
                {
                    BEEntity prevEntity = this._currentProj.Get(this._collectDataNode.Guid) as BEEntity;
                    if (prevEntity != null)
                    {
                        if (prevEntity == null) return true;
                        prevEntity.ViewRange = (ViewRangeEnum)this.cbViewRange.SelectedIndex;
                        prevEntity.OrgFilter = this.cbOrgFilter.Checked;
                        prevEntity.Code = this.tbCode.Text;
                        prevEntity.Name = this.tbDisplayName.Text;
                        prevEntity.TableName = this.tbTableName.Text;
                        prevEntity.InhertGuid = this.tbInhertGuid.Text;
                        prevEntity.InhertName = this.tbInhertClass.Text;
                        foreach (BEEntity entity in this._currentProj.EntityList)
                        {
                            if (entity.Guid != prevEntity.Guid)
                            {
                                if (prevEntity.Code == entity.Code)
                                {
                                    MessageBox.Show("当前实体的编码不能与项目中已有的实体编码相同,实体名称:" + entity.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    //return false;
                                }
                            }
                        }
                        for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
                        {
                            DataGridViewRow r = this.dataGridView1.Rows[i];
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                continue;
                            }
                            string guid = r.Cells[0].Value == null ? string.Empty : r.Cells[0].Value.ToString();
                            BEColumn col = prevEntity.Get(guid);
                            if (col == null)
                            {
                                col = new BEColumn(r.Cells[0].Value.ToString(), this._currentProj as BEProj, prevEntity);
                                prevEntity.ColumnList.Add(col);
                            }
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性编码不能为空,行号:" + i, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //return false;
                            }
                            col.Code = r.Cells[1].EditedFormattedValue.ToString();
                            if (r.Cells[2].EditedFormattedValue == null)
                            {
                                r.Cells[2].Value = string.Empty;
                            }
                            col.Name = r.Cells[2].EditedFormattedValue.ToString();
                            string strDataType = string.Empty;
                            if (r.Cells[3].EditedFormattedValue != null)
                            {
                                strDataType = r.Cells[3].EditedFormattedValue.ToString();
                            }
                            if (string.IsNullOrEmpty(strDataType))
                            {
                                MessageBox.Show("属性类型不能为空,属性:" + col.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                // return false;
                            }
                            //基础类型
                            //引用类型
                            //聚合类型
                            if (strDataType == "基础类型")
                            {
                                col.DataType = DataTypeEnum.CommonType;
                            }
                            else if (strDataType == "引用类型")
                            {
                                col.DataType = DataTypeEnum.RefreceType;
                            }
                            else
                            {
                                col.DataType = DataTypeEnum.CompositionType;
                            }
                            if (r.Cells[4].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[4].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性类型名称不能为空,属性:" + col.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                // return false;
                            }
                            col.TypeString = r.Cells[4].EditedFormattedValue.ToString();
                            col.IsNull = (bool)r.Cells[5].EditedFormattedValue;
                            col.IsViewer = (bool)r.Cells[9].EditedFormattedValue;
                            col.IsBizKey = (bool)r.Cells[10].EditedFormattedValue;

                            col.RefGuid = r.Cells[6].EditedFormattedValue.ToString();

                            if (string.IsNullOrEmpty(col.RefGuid) && col.TypeString == "string")
                            {
                                try
                                {
                                    if (string.IsNullOrEmpty(r.Cells[7].EditedFormattedValue.ToString()))
                                    {
                                        col.Length = 100;
                                    }
                                    else
                                    {
                                        col.Length = int.Parse(r.Cells[7].EditedFormattedValue.ToString());
                                    }
                                }
                                catch (Exception ex)
                                {
                                    col.Length = 100;
                                }
                            }
                            else
                            {
                                col.Length = 0;
                            }
                        }
                    }

                }
                #endregion

                #region DTO类型
                else if (this._bindDataNode.NodeType == NodeType.DTOEntity)
                {
                    DTOEntity prevEntity = this._currentProj.Get(this._collectDataNode.Guid) as DTOEntity;
                    if (prevEntity != null)
                    {
                        prevEntity.Code = this.tbCode.Text;
                        prevEntity.Name = this.tbDisplayName.Text;
                        prevEntity.InhertGuid = this.tbInhertGuid.Text;
                        prevEntity.InhertName = this.tbInhertClass.Text;
                        foreach (DTOEntity entity in this._currentProj.DTOList)
                        {
                            if (entity.Guid != prevEntity.Guid)
                            {
                                if (prevEntity.Code == entity.Code)
                                {
                                    MessageBox.Show("当前DTO的编码不能与项目中已有的DTO编码相同,DTO名称:" + entity.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    //   return false;
                                }
                            }
                        }
                        for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
                        {
                            DataGridViewRow r = this.dataGridView1.Rows[i];
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                continue;
                            }
                            string guid = r.Cells[0].Value == null ? string.Empty : r.Cells[0].Value.ToString();
                            DTOColumn col = prevEntity.Get(guid);
                            if (col == null)
                            {
                                col = new DTOColumn(r.Cells[0].Value.ToString(), this._currentProj, prevEntity);
                                prevEntity.ColumnList.Add(col);
                            }
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性编码不能为空,行号:" + i, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //  return false;
                            }
                            col.Code = r.Cells[1].EditedFormattedValue.ToString();
                            if (r.Cells[2].EditedFormattedValue == null)
                            {
                                r.Cells[2].Value = string.Empty;
                            }
                            col.Name = r.Cells[2].EditedFormattedValue.ToString();
                            string strDataType = string.Empty;
                            if (r.Cells[3].EditedFormattedValue != null)
                            {
                                strDataType = r.Cells[3].EditedFormattedValue.ToString();
                            }
                            if (string.IsNullOrEmpty(strDataType))
                            {
                                MessageBox.Show("属性类型不能为空,属性:" + col.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //  return false;
                            }
                            //基础类型
                            //引用类型
                            //聚合类型
                            if (strDataType == "基础类型")
                            {
                                col.DataType = DataTypeEnum.CommonType;
                            }
                            else if (strDataType == "引用类型")
                            {
                                col.DataType = DataTypeEnum.RefreceType;
                            }
                            else
                            {
                                col.DataType = DataTypeEnum.CompositionType;
                            }
                            if (r.Cells[4].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[4].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性类型名称不能为空,属性:" + col.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //   return false;
                            }
                            col.TypeString = r.Cells[4].EditedFormattedValue.ToString();
                            col.IsNull = (bool)r.Cells[5].EditedFormattedValue;
                            col.IsViewer = (bool)r.Cells[9].EditedFormattedValue;
                            col.RefGuid = r.Cells[6].EditedFormattedValue.ToString();
                        }
                    }
                }
                #endregion

                #region BP类型
                else if (this._bindDataNode.NodeType == NodeType.BPEntity)
                {
                    BPEntity prevEntity = this._currentProj.Get(this._collectDataNode.Guid) as BPEntity;
                    if (prevEntity != null)
                    {
                        prevEntity.Code = this.tbCode.Text;
                        prevEntity.Name = this.tbDisplayName.Text;
                        prevEntity.ReturnGuid = this.tbInhertGuid.Text;
                        prevEntity.ReturnName = this.tbReturnType.Text;
                        prevEntity.IsList = this.cbList.Checked;
                        prevEntity.IsAuth = this.cbAuth.Checked;
                        prevEntity.Trans = this.cbTrans.SelectedIndex;
                        prevEntity.IsEntity = this.ckIsEntity.Checked;
                        foreach (BPEntity entity in this._currentProj.EntityList)
                        {
                            if (entity.Guid != prevEntity.Guid)
                            {
                                if (prevEntity.Code == entity.Code)
                                {
                                    MessageBox.Show("当前BP的编码不能与项目中已有的BP编码相同,BP名称:" + entity.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    //   return false;
                                }
                            }
                        }
                        for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
                        {
                            DataGridViewRow r = this.dataGridView1.Rows[i];
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                continue;
                            }
                            string guid = r.Cells[0].Value == null ? string.Empty : r.Cells[0].Value.ToString();
                            BPColumn col = prevEntity.Get(guid);
                            if (col == null)
                            {
                                col = new BPColumn(r.Cells[0].Value.ToString(), this._currentProj as BPProj, prevEntity);
                                prevEntity.ColumnList.Add(col);
                            }
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性编码不能为空,行号:" + i, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //  return false;
                            }
                            col.Code = r.Cells[1].EditedFormattedValue.ToString();
                            if (r.Cells[2].EditedFormattedValue == null)
                            {
                                r.Cells[2].Value = string.Empty;
                            }
                            col.Name = r.Cells[2].EditedFormattedValue.ToString();
                            string strDataType = string.Empty;
                            if (r.Cells[3].EditedFormattedValue != null)
                            {
                                strDataType = r.Cells[3].EditedFormattedValue.ToString();
                            }
                            if (string.IsNullOrEmpty(strDataType))
                            {
                                MessageBox.Show("属性类型不能为空,属性:" + col.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //  return false;
                            }
                            //基础类型
                            //引用类型
                            //聚合类型
                            if (strDataType == "基础类型")
                            {
                                col.DataType = DataTypeEnum.CommonType;
                            }
                            else if (strDataType == "引用类型")
                            {
                                col.DataType = DataTypeEnum.RefreceType;
                            }
                            else
                            {
                                col.DataType = DataTypeEnum.CompositionType;
                            }
                            if (r.Cells[4].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[4].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性类型名称不能为空,属性:" + col.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //   return false;
                            }
                            col.TypeString = r.Cells[4].EditedFormattedValue.ToString();
                            col.IsNull = (bool)r.Cells[5].EditedFormattedValue;
                            col.RefGuid = r.Cells[6].EditedFormattedValue.ToString();
                        }
                    }

                }
                #endregion

                #region 枚举类型
                else if (this._bindDataNode.NodeType == NodeType.EnumEntity)
                {
                    EnumEntity prevEntity = this._currentProj.Get(this._collectDataNode.Guid) as EnumEntity;
                    if (prevEntity != null)
                    {
                        prevEntity.Code = this.tbCode.Text;
                        prevEntity.Name = this.tbDisplayName.Text;

                        foreach (EnumEntity entity in this._currentProj.EnumList)
                        {
                            if (entity.Guid != prevEntity.Guid)
                            {
                                if (prevEntity.Code == entity.Code)
                                {
                                    MessageBox.Show("当前Enum的编码不能与项目中已有的Enum编码相同,DTO名称:" + entity.Name, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    //   return false;
                                }
                            }
                        }
                        for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
                        {
                            DataGridViewRow r = this.dataGridView1.Rows[i];
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                continue;
                            }
                            string guid = r.Cells[0].Value == null ? string.Empty : r.Cells[0].Value.ToString();
                            EnumColumn col = prevEntity.Get(guid);
                            if (col == null)
                            {
                                col = new EnumColumn(r.Cells[0].Value.ToString(), this._currentProj, prevEntity);
                                prevEntity.ColumnList.Add(col);
                            }
                            if (r.Cells[1].EditedFormattedValue == null || string.IsNullOrEmpty(r.Cells[1].EditedFormattedValue.ToString()))
                            {
                                MessageBox.Show("属性编码不能为空,行号:" + i, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                //  return false;
                            }
                            col.Code = r.Cells[1].EditedFormattedValue.ToString();
                            if (r.Cells[2].EditedFormattedValue == null)
                            {
                                r.Cells[2].Value = string.Empty;
                            }
                            col.Name = r.Cells[2].EditedFormattedValue.ToString();
                            col.EnumValue = int.Parse(r.Cells[8].EditedFormattedValue.ToString());
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show("录入数据有误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return true;
        }
 public BuildEntityColumn(BEColumn col)
 {
     _col = col;
 }
 public BuildEntityEnumColumn(BEColumn col)
     : base(col)
 {
     _templateCode = BECodeTemplate.EnumRefrenceTemplate;
 }
 public BuildEntityCommon(BEColumn col)
     : base(col)
 {
     _templateCode = BECodeTemplate.CommonTemplate;
 }
예제 #6
0
        /// <summary>
        /// 新增当前实体下面colcode的引用
        /// </summary>
        /// <param name="entityGuid"></param>
        /// <param name="colGuid"></param>
        private void addPrimaryRefNode(XmlDocument xmlDoc, string entityGuid, string colGuid)
        {
            if (this.DataType == DataTypeEnum.CompositionType)
            {
                XmlNode refreceNode = xmlDoc.SelectSingleNode("EntityProj/EntityList/Entity[@Guid='" + entityGuid + "']/Attributes");
                //查找到引用的实体
                if (refreceNode != null)
                {
                    XmlNode refNode = refreceNode.SelectSingleNode("Attribute[@RefColGuid='" + colGuid + "']");
                    if (refNode == null)
                    {
                        XmlElement newEL = xmlDoc.CreateElement("Attribute");
                        newEL.SetAttribute("Guid", System.Guid.NewGuid().ToString());
                        newEL.SetAttribute("RefGuid", this.Entity.Guid);
                        newEL.SetAttribute("RefColGuid", this.Guid);
                        newEL.SetAttribute("Code", "P" + this.Entity.Code);
                        newEL.SetAttribute("Name", this.Entity.Name);
                        newEL.SetAttribute("DataType", DataTypeEnum.RefreceType.ToString());
                        newEL.SetAttribute("IsNull", "0");
                        refreceNode.AppendChild(newEL);

                        BEEntity entity = this.Entity.Proj.Get(refreceNode.ParentNode.Attributes["Guid"].Value.ToString()) as BEEntity;
                        if (entity == null)
                        {
                            throw new Exception("实体没有找到Guid:" + refreceNode.ParentNode.Attributes["Guid"].Value.ToString());
                        }
                        //在缓存中加入当前数据
                        BEColumn col = new BEColumn(newEL.Attributes["Guid"].Value.ToString(), this.Entity.Proj as BEProj, entity);
                        col.RefGuid = newEL.Attributes["RefGuid"].Value.ToString();
                        col.RefColGuid = this.Guid;
                        col.Code = newEL.Attributes["Code"].Value.ToString();
                        col.Name = newEL.Attributes["Name"].Value.ToString();
                        col.DataType = DataTypeEnum.RefreceType;
                        col.IsNull = false;
                        col.DataState = DataState.Update;
                        entity.ColumnList.Add(col);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// 从xml文件中初始化对象
        /// </summary>
        /// <param name="xml"></param>
        public override void FromXML(XmlNode node)
        {
            this._guid = node.Attributes["Guid"].Value;
            this.Code = node.Attributes["Code"].Value;
            this.Name = node.Attributes["Name"].Value;
            if (string.IsNullOrEmpty(this.Code))
            {
                this.Code = "BizEntity";
            }
            if (string.IsNullOrEmpty(this.Name))
            {
                this.Name = "未命名实体";
            }
            if (node.Attributes["FloderGuid"] != null)
            {
                this.FloderGuid = node.Attributes["FloderGuid"].Value.ToString();
            }
            if (node.Attributes["Table"] == null)
            {
                this._tableName = "T_" + this.Code;
            }
            else
            {
                this._tableName = node.Attributes["Table"].Value.ToString();
            }
            if (node.Attributes["ViewRange"] == null)
            {
                this._viewRange = ViewRangeEnum.UPPER;
            }
            else
            {
                this._viewRange = (ViewRangeEnum)Convert.ToInt32((node.Attributes["ViewRange"].Value));
            }

            if (node.Attributes["OrgFilter"] == null)
            {
                this._orgFilter = true;
            }
            else
            {
                string str = node.Attributes["OrgFilter"].Value;
                if (str.Trim() == "1")
                {
                    this._orgFilter = true;
                }
                else
                {
                    this._orgFilter = false;
                }
            }
            if (!this._orgFilter)
            {
                this._viewRange = ViewRangeEnum.NONE;
            }
            if (node.Attributes["InhertGuid"] != null)
            {
                this._inhertGuid = node.Attributes["InhertGuid"].Value;
                XmlNode entityNode = this.Proj.GetEntityNode(this.InhertGuid);
                if (entityNode != null)
                {
                    string inhertNameSpace = entityNode.ParentNode.ParentNode.Attributes["namespace"].Value.ToString();
                    if (!string.IsNullOrEmpty(inhertNameSpace))
                    {
                        this._inhertName = inhertNameSpace + ".";
                    }
                    this._inhertName += entityNode.Attributes["Code"].Value.ToString();
                }
            }
            this.DataState = DataState.Update;

            //初始化基类列成员
            this._inhertColumnList.Clear();
            //如果该类是继承下来的话,需要生成基类
            if (!string.IsNullOrEmpty(this.InhertGuid))
            {
                List<XmlNode> nodeList = this.GetInhertNodes(this.InhertGuid);
                foreach (XmlNode inhertNode in nodeList)
                {
                    BEColumn col = new BEColumn(string.Empty, this.Proj as BEProj, this);
                    col.FromXML(inhertNode);
                    _inhertColumnList.Add(col);
                }
            }
            this._columnList.Clear();
            XmlNodeList xmlNodeList = node.SelectNodes("Attributes/Attribute");
            //查找当前工程文件下所有的实体
            foreach (XmlNode n in xmlNodeList)
            {
                BEColumn col = new BEColumn(string.Empty, this.Proj as BEProj, this);
                col.FromXML(n);
                this._columnList.Add(col);
            }

            this.IsChanged = false;
        }
예제 #8
0
 /// <summary>
 /// 从BEColumn转换成DTOColumn
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="col"></param>
 public DTOColumn(DTOEntity entity, BEColumn col)
     : base(col.Guid)
 {
     this._proj = col.BEProj;
     this._entity = entity;
     this.Code = col.Code;
     this.Name = col.Name;
     this._isnull = col.IsNull;
     this._isViewer = col.IsViewer;
     if (!string.IsNullOrEmpty(col.RefGuid))
     {
         //引用类型需要加上标签
         if (col.DataType == Base.DataTypeEnum.RefreceType)
         {
             if (col.IsEnum)
             {
                 this._typeString = "int";
             }
             else
             {
                 this._typeString = "long";
             }
             this._dataType = DataTypeEnum.CommonType;
             this._entityRefrence = true;
         }
         else//聚合类型也是DTO也需要加上标签
         {
             this.TypeString = Util.UtilHelper.GetDTOColumnTypeByBEColumn(col.TypeString);
             this.DataType = col.DataType;
             this._entityRefrence = true;
             //聚合类型都不能浏览
             this._isViewer = false;
         }
     }
     else
     {
         this._typeString = col.TypeString;
         this.DataType = col.DataType;
         this._entityRefrence = false;
     }
 }