示例#1
0
        /// <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;
            }
        }
示例#2
0
        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);
        }
示例#3
0
        /// <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;
            }
        }
示例#4
0
 /// <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;
         }
     }
 }