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 BuildDTORefrence(DTOColumn col) : base(col) { _templateCode = DTOCodeTemplate.RefrenceTemplate; }
public BuildDTOComposition(DTOColumn col) : base(col) { _templateCode = DTOCodeTemplate.CompositionTemplate; }
public BuildDTOColumn(DTOColumn col) { _col = col; }
public DTOEntity(BEEntity entity) : base(entity.Guid) { this.Code = entity.Code + AttrEndTag; this.Name = entity.Name; if (entity.InhertName == Attributes.BaseEntity) { this.InhertName = Attributes.BaseDTO; } else { this.InhertName = string.Empty; //如果实体继承一个类的话我们生成的dto也需要继承这个类生成的dto string[] namespaceArray = entity.InhertName.Split('.'); int length = namespaceArray.Length; for (int i = 0; i < length - 2; i++) { this.InhertName += namespaceArray[i] + "."; } this.InhertName += namespaceArray[length - 2] + "." + DTOEntity.AssemblyEndTag + "."; this.InhertName += namespaceArray[length - 1] + DTOEntity.AttrEndTag; //this.InhertName = entity.Proj.Namespace + "." + DTOEntity.AssemblyEndTag + "." + entity.Code + DTOEntity.AttrEndTag; } this.InhertGuid = entity.InhertGuid; this._proj = entity.Proj; this._columnList.Clear(); foreach (BEColumn col in entity.ColumnList) { DTOColumn dtoCol = new DTOColumn(this, col); this._columnList.Add(dtoCol); } }
public override void FromXML(XmlNode node) { this._guid = node.Attributes["Guid"].Value; this.Code = node.Attributes["Code"].Value; if (string.IsNullOrEmpty(this.Code)) { this.Code = "BizDTO"; } this.Name = node.Attributes["Name"].Value; if (string.IsNullOrEmpty(this.Name)) { this.Name = "未命名DTO"; } if (node.Attributes["FloderGuid"] != null) { this.FloderGuid = node.Attributes["FloderGuid"].Value.ToString(); } 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 + "." + DTOEntity.AssemblyEndTag + "."; } if (entityNode.Name == "Entity") { this.InhertName += entityNode.Attributes["Code"].Value.ToString() + DTOEntity.AttrEndTag; } else { this.InhertName += entityNode.Attributes["Code"].Value.ToString(); } } } this.DataState = DataState.Update; this.ColumnList.Clear(); XmlNodeList nodeList = node.SelectNodes("Attributes/Attribute"); //查找当前工程文件下所有的实体 foreach (XmlNode n in nodeList) { DTOColumn col = new DTOColumn(string.Empty, this.Proj, this); col.FromXML(n); this.ColumnList.Add(col); } this.IsChanged = false; }