/// <summary> /// this method load attribute of the component /// </summary> public override void LoadAttributes() { Data.Component.ComponentAttribute ca = new Data.Component.ComponentAttribute(ck.GetServer().Connection()); var dt = new DataTable(); dt = ca.GetAttributes(this.ComponentID); foreach (DataRow dr in dt.Rows) { string _fieldid = ""; _fieldid = dr.IsNull("FieldID") ? "" : dr["FieldID"].ToString(); ComponentAttribute c = new ComponentAttribute(this.ClientID, this.TableID, _fieldid); c.AttributeName = dr.IsNull("AttributeName") ? "" : dr["AttributeName"].ToString(); // c.FieldName = dr.IsNull("FieldName") ? "" : dr["FieldName"].ToString(); c.IsRequired = dr.IsNull("IsRequired") ? false : Convert.ToBoolean(dr["IsRequired"]); c.IsUnique = dr.IsNull("IsUnique") ? false : Convert.ToBoolean(dr["IsUnique"]); c.IsCore = dr.IsNull("IsCore") ? false : Convert.ToBoolean(dr["IsCore"]); c.IsReadOnly = dr.IsNull("IsReadOnly") ? false : Convert.ToBoolean(dr["IsReadOnly"]); c.IsSecured = dr.IsNull("IsSecured") ? false : Convert.ToBoolean(dr["IsSecured"]); c.IsAuto = dr.IsNull("IsAuto") ? false : Convert.ToBoolean(dr["IsAuto"]); c.DefaultValue = dr.IsNull("DefaultValue") ? "" : dr["DefaultValue"].ToString(); c.FileExtension = dr.IsNull("FileExtension") ? "" : dr["FileExtension"].ToString(); c.RegExp = dr.IsNull("RegExp") ? "" : dr["RegExp"].ToString(); c.LookUpID = dr.IsNull("LookUpID") ? "" : dr["LookUpID"].ToString(); c.AttributeType = dr.IsNull("AttributeType") ? ComponentAttribute.ComoponentAttributeType._string : (ComponentAttribute.ComoponentAttributeType)dr["AttributeType"]; // c.FieldType= dr.IsNull("FieldType") ? DbType.String :(DbType) dr["FieldType"]; c.Length = dr.IsNull("length") ? -1 : Convert.ToInt32(dr["length"]); c.IsNullable = dr.IsNull("IsNullable") ? false : Convert.ToBoolean(dr["IsNullable"]); c.IsPrimaryKey = dr.IsNull("ISPrimaryKey") ? false : Convert.ToBoolean(dr["ISPrimaryKey"]); this.Attributes.Add(c); } }
/// <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> /// attribute change /// </summary> /// <param name="ca"></param> /// <returns></returns> internal bool UpdateAttribute(ComponentAttribute ca, string serverid = "") { try { if (this.TableID != "") { if (serverid == "") { Tz.ClientManager.ClientServer c = new Tz.ClientManager.ClientServer(this.ClientID); Tz.ClientManager.Server s = c.GetServer(); serverid = s.ServerID; } DataManager dm = new DataManager(this.TableID, serverid, this.ClientID); dm.ChangeField(ca.FieldID, ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length, ca.IsNullable, ca.IsPrimaryKey, ca.AttributeName.Replace(" ", "_")); dm.AcceptChanges(); } var dataComponentAttr = new Data.Component.ComponentAttribute(ck.GetServer().Connection()); dataComponentAttr.Update(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, ca.Length, ca.IsNullable, ca.IsPrimaryKey); return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// remove component /// </summary> /// <returns></returns> internal bool Remove() { try { dataComponent.Remove(this.ClientID, this.ComponentID); var datacom = new Data.Component.ComponentAttribute(ck.GetServer().Connection()); datacom.RemoveAll(this.ComponentID); 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); dm.Remove(); } return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// remove attribute /// </summary> /// <param name="attributeID"></param> /// <returns></returns> internal bool RemoveAttribuet(string attributeID) { try { var datacom = new Data.Component.ComponentAttribute(ck.GetServer().Connection()); if (datacom.Remove(attributeID, this.ComponentID)) { datacom.RemoveAll(this.ComponentID); 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); dm.RemoveField(attributeID); return(true); } else { return(false); } } 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; } } }