/// <summary> /// /// </summary> /// <param name="tableID"></param> /// <param name="serverID"></param> public DataManager(string tableID, string serverID, string clientID) { Server = new ClientManager.Server(serverID); ClientID = clientID; Table = new Entity.Table(serverID, tableID, ClientID); isPrimaryUpdated = false; }
/// <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; } }
internal bool Publish() { Tz.ClientManager.ClientServer c = new Tz.ClientManager.ClientServer(this.ClientID); Tz.ClientManager.Server s = c.GetServer(); var pk = ""; var dm = new DataManager(s, c.ClientID); dm.NewTable(this.ComponentName, getCategory()); foreach (ComponentAttribute ca in this.Attributes) { if (ca.IsPrimaryKey) { pk = pk + ca.AttributeName.Replace(" ", "_"); dm.AddPrimarykey(ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length, ca.FieldID); } else { dm.AddField(ca.AttributeName.Replace(" ", "_"), GetFieldType(ca), ca.Length, ca.IsNullable, ca.FieldID); } } if (pk.StartsWith(",")) { pk = pk.Substring(1); PrimaryKeys = pk; } else { PrimaryKeys = pk; } if (PrimaryKeys == null) { PrimaryKeys = ""; } 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); // } //} dataComponent.UpdateTableID(this.ClientID, this.ComponentID, this.TableID); dataComponent.ChangeState(this.ClientID, this.ComponentID, (int)ComponentState.published); // publish //foreach (ComponentAttribute ca in this.Attributes) //{ // this.UpdateAttribute(ca, s.ServerID); //} return(true); }
public static async Task <int> synSever(string ClientID) { System.Data.DataTable dt = new DataTable(); ClientServer c = new ClientServer(ClientID); Tz.ClientManager.Server s = c.GetServer(); Tech.Data.DBDatabase db = Tech.Data.DBDatabase.Create(s.Connection(), "MySql.Data.MySqlClient"); Tech.Data.Schema.DBSchemaProvider provider = db.GetSchemaProvider(); IEnumerable <Tech.Data.Schema.DBSchemaItemRef> tables = provider.GetAllTables(); int count = 0; List <Tz.Net.Entity.Table> dtTb = Net.Entity.Table.GetTables(ClientID, s.ServerID); await Task.Run(() => { var dm = new DataManager(s, c.ClientID); foreach (Tech.Data.Schema.DBSchemaItemRef df in tables) { if (dtTb.Where(x => x.TableName.ToLower() == df.Name.ToLower()).FirstOrDefault() != null) { continue; } dm.NewTable(df.Name, df.Catalog); DBSchemaTable schema = provider.GetTable(df.Name); foreach (Tech.Data.Schema.DBSchemaTableColumn dc in schema.Columns) { if (dc.ColumnFlags == Tech.Data.DBColumnFlags.Nullable) { dm.AddField(dc.Name, dc.DbType, dc.Size, true); } else if (dc.ColumnFlags == Tech.Data.DBColumnFlags.PrimaryKey) { dm.AddPrimarykey(dc.Name, dc.DbType, dc.Size); } else { dm.AddField(dc.Name, dc.DbType, dc.Size, false); } } try { dm.AcceptChanges(true); } catch (Exception ex) { } count = count + 1; } return(count); }); return(count); }
/// <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; } } }
/// <summary> /// /// </summary> /// <param name="server"></param> public DataManager(ClientManager.Server server, string clientID) { Server = server; ClientID = clientID; isPrimaryUpdated = false; }
/// <summary> /// /// </summary> /// <param name="serverID"></param> public DataManager(string serverID, string clientID) { Server = new ClientManager.Server(serverID); ClientID = clientID; isPrimaryUpdated = false; }