/// <summary> /// add new attribute in the component /// </summary> /// <param name="ca"></param> /// <returns></returns> internal bool AddAttribute(ComponentAttribute ca) { try { if (this.TableID != "") { Tz.ClientManager.ClientServer c = new Tz.ClientManager.ClientServer(this.ClientID); Tz.ClientManager.Server s = c.GetServer(); DataManager dm = new DataManager(this.TableID, s.ServerID, this.ClientID); if (ca.IsPrimaryKey) { dm.AddPrimarykey(ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length); } else { dm.AddField(ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length, ca.IsNullable); } dm.AcceptChanges(); TableID = dm.GetTable().TableID; Net.Entity.IField f = dm.GetTable().Fields.Where(x => x.FieldName == ca.AttributeName.Replace(" ", "_")).FirstOrDefault(); if (f != null) { ca.setFieldID(f.FieldID); } else { return(false); } } else { ca.setFieldID(""); } var dataComponentAttr = new Data.Component.ComponentAttribute(ck.GetServer().Connection()); dataComponentAttr.Save(this.ClientID, this.ComponentID, ca.FieldID, ca.IsRequired, ca.IsCore, ca.IsUnique, ca.IsReadOnly, ca.IsSecured, ca.IsAuto, ca.LookUpID, ca.DefaultValue, ca.FileExtension, ca.RegExp, ca.AttributeName, (int)ca.AttributeType, ca.IsNullable, ca.IsPrimaryKey, ca.Length); return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// save component /// </summary> /// <returns></returns> internal bool Save() { Tz.ClientManager.ClientServer c = new Tz.ClientManager.ClientServer(this.ClientID); Tz.ClientManager.Server s = c.GetServer(); if (ComponentID == "") { var dm = new DataManager(s, c.ClientID); dm.NewTable(this.ComponentName, getCategory()); var pk = ""; foreach (ComponentAttribute ca in this.Attributes) { if (ca.IsPrimaryKey) { pk = pk + ca.AttributeName.Replace(" ", "_"); dm.AddPrimarykey(ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length); } else { dm.AddField(ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length, ca.IsNullable); } } if (pk.StartsWith(",")) { pk = pk.Substring(1); PrimaryKeys = pk; } else { PrimaryKeys = pk; } if (PrimaryKeys == null) { PrimaryKeys = ""; } try { dm.AcceptChanges(); if (dm.GetTable().TableID == "") { return(false); } TableID = dm.GetTable().TableID; foreach (ComponentAttribute ca in this.Attributes) { Net.Entity.IField f = dm.GetTable().Fields.Where(x => x.FieldName == ca.AttributeName.Replace(" ", "_")).FirstOrDefault(); if (f != null) { ca.setFieldID(f.FieldID); } } this.ComponentID = dataComponent.SaveComponent(ClientID, ComponentName, (int)ComponentType, TableID, Title, PrimaryKeys, TitleFormat, "", "", Category); if (this.ComponentID != "") { var dataComponentAttr = new Data.Component.ComponentAttribute(ck.GetServer().Connection()); foreach (ComponentAttribute ca in this.Attributes) { dataComponentAttr.Save(this.ClientID, this.ComponentID, ca.FieldID, ca.IsRequired, ca.IsCore, ca.IsUnique, ca.IsReadOnly, ca.IsSecured, ca.IsAuto, ca.LookUpID, ca.DefaultValue, ca.FileExtension, ca.RegExp, ca.AttributeName, (int)ca.AttributeType, ca.IsNullable, ca.IsPrimaryKey, ca.Length); } return(true); } else { return(false); } } catch (System.Exception ex) { throw ex; } } else { try { var dm = new DataManager(this.TableID, s.ServerID, c.ClientID); dm.Rename(this.ComponentName, this.getCategory()); if (dataComponent.UpdateComponent(ClientID, ComponentID, ComponentName, (int)ComponentType, Title, PrimaryKeys, TitleFormat, "", "", Category)) { return(true); } else { return(false); } } catch (System.Exception ex) { throw ex; } } }