/// <summary>
        /// Imports records from source database to target database/template
        /// </summary>
        /// <param name="selectedNids"></param>
        /// <param name="allSelected">Set true to import all records</param>
        public override void ImportValues(List<string> selectedNids, bool allSelected)
        {
            DI6SubgroupBuilder SGBuilderObj = new DI6SubgroupBuilder(this._TargetDBConnection, this._TargetDBQueries);
            DI6SubgroupInfo SourceDBSubgroup;
            DataRow Row;
            int ProgressBarValue = 0;

            foreach (string Nid in selectedNids)
            {
                try
                {
                    //get subgroup from source table
                    Row = this.SourceTable.Select(Subgroup.SubgroupNId + "=" + Nid)[0];
                    SourceDBSubgroup = new DI6SubgroupInfo();
                    SourceDBSubgroup.Name = DICommon.RemoveQuotes(Row[Subgroup.SubgroupName].ToString());
                    SourceDBSubgroup.GID = Row[Subgroup.SubgroupGId].ToString();
                    SourceDBSubgroup.Global = Convert.ToBoolean(Row[Subgroup.SubgroupGlobal]);
                    SourceDBSubgroup.Nid = Convert.ToInt32(Row[Subgroup.SubgroupNId]);
                    SourceDBSubgroup.Type = Convert.ToInt32(Row[Subgroup.SubgroupType]);

                    //import into target database
                    SGBuilderObj.ImportSubgroup(SourceDBSubgroup, SourceDBSubgroup.Nid, this.SourceDBQueries, this.SourceDBConnection);

                }
                catch (Exception ex)
                {
                    ExceptionFacade.ThrowException(ex);
                }
                this.RaiseIncrementProgessBarEvent(ProgressBarValue);
                ProgressBarValue++;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add subgroup record into collection
        /// </summary>
        /// <param name="subgroupInfo">object of subgroupInfo</param>

        private void AddSubgroupIntoCollection(DI6SubgroupInfo subgroupInfo)
        {
            if (!this.SubgroupCollection.ContainsKey(subgroupInfo.Name))
            {
                this.SubgroupCollection.Add(subgroupInfo.Name, subgroupInfo);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the instance of SubgroupInfo on the basis of Subgroup Nid
        /// </summary>
        /// <param name="sourceQuery"></param>
        /// <param name="sourceDBConnection"></param>
        /// <param name="subgroupNid"></param>
        /// <returns></returns>
        public static DI6SubgroupInfo GetSubgroupInfoByNid(DIQueries sourceQuery, DIConnection sourceDBConnection, int subgroupNid)
        {
            DI6SubgroupInfo RetVal = new DI6SubgroupInfo();

            RetVal = DI6SubgroupBuilder.GetSubgroupInfo(sourceQuery, sourceDBConnection, FilterFieldType.NId, subgroupNid.ToString());
            return(RetVal);
        }
Esempio n. 4
0
        /// <summary>
        /// Check and create Subgroup record
        /// </summary>
        /// <param name="subgroupInfo">object of DI6SubgroupInfo </param>
        /// <returns>Nid</returns>
        public int CheckNCreateSubgroup(DI6SubgroupInfo subgroupInfo)
        {
            int RetVal = 0;

            try
            {
                // check Subgroup exists or not
                RetVal = this.CheckSubgroupExists(subgroupInfo);

                // if Subgroup does not exist then create it.
                if (RetVal <= 0)
                {
                    // insert subgroup
                    if (this.InsertIntoDatabase(subgroupInfo))
                    {
                        RetVal = this.GetSubgroupByName(subgroupInfo.Name);
                    }
                }

                // add Subgroup information into collection
                subgroupInfo.Nid = RetVal;
                this.AddSubgroupIntoCollection(subgroupInfo);
            }
            catch (Exception)
            {
                RetVal = 0;
            }

            return(RetVal);
        }
Esempio n. 5
0
        /// <summary>
        /// Insert  record into subgroup table
        /// </summary>
        /// <param name="subgroupInfo">object of SubgroupInfo </param>
        /// <returns>Ture/False. Return true after successful insertion otherwise false</returns>

        private bool InsertIntoDatabase(DI6SubgroupInfo subgroupInfo)
        {
            bool   RetVal              = false;
            string SubgroupName        = subgroupInfo.Name;
            string subgroupGID         = subgroupInfo.GID;
            string SubgroupGId         = Guid.NewGuid().ToString();
            string LanguageCode        = string.Empty;
            string DefaultLanguageCode = string.Empty;
            string SubgroupForDatabase = string.Empty;
            int    LastOrder           = 0;

            try
            {
                DefaultLanguageCode = this.DBQueries.LanguageCode;

                //replace GID only if given gid is not empty or null.
                if (!string.IsNullOrEmpty(subgroupGID))
                {
                    SubgroupGId = subgroupGID;
                }

                // if subgroup order <= 0 then set the subgroup order
                if (subgroupInfo.SubgroupOrder <= 0)
                {
                    try
                    {
                        LastOrder = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(this.DBQueries.Subgroup.GetMaxSubgroupOrder(subgroupInfo.Type)));
                    }
                    catch (Exception)
                    {
                    }

                    // set subgroup order
                    subgroupInfo.SubgroupOrder = LastOrder + 1;
                }

                foreach (DataRow languageRow in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows)
                {
                    LanguageCode = languageRow[Language.LanguageCode].ToString();
                    if (LanguageCode == DefaultLanguageCode.Replace("_", String.Empty))
                    {
                        SubgroupForDatabase = SubgroupName;
                    }
                    else
                    {
                        SubgroupForDatabase = Constants.PrefixForNewValue + SubgroupName;
                    }
                    this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Subgroup.Insert.InsertSubgroup(this.DBQueries.DataPrefix, "_" + LanguageCode, SubgroupForDatabase, SubgroupGId, subgroupInfo.Global, subgroupInfo.Type, DBConnection.ConnectionStringParameters.ServerType, subgroupInfo.SubgroupOrder));
                }

                RetVal = true;
            }
            catch (Exception)
            {
                RetVal = false;
            }

            return(RetVal);
        }
Esempio n. 6
0
        /// <summary>
        /// Check existance of Subgroup first in collection Then In database
        /// </summary>
        /// <param name="subgroupInfo">object of UnitInfo</param>
        /// <returns> Nid</returns>
        private int CheckSubgroupExists(DI6SubgroupInfo subgroupInfo)
        {
            int RetVal = 0;

            //Step 1: check subgroup exists in Unit collection
            RetVal = this.CheckSubgroupInCollection(subgroupInfo.Name);

            //Step 2: check unit exists in database.
            if (RetVal <= 0)
            {
                RetVal = this.GetSubgroupNid(subgroupInfo.GID, subgroupInfo.Name);
            }

            return(RetVal);
        }
        /// <summary>
        /// Returns the instance of SubgroupInfo on the basis of Subgroup Nid
        /// </summary>
        /// <param name="sourceQuery"></param>
        /// <param name="sourceDBConnection"></param>
        /// <param name="subgroupNid"></param>
        /// <returns></returns>
        public static DI6SubgroupInfo GetSubgroupInfo(DIQueries queries, DIConnection dbConnection, FilterFieldType filterClause, string filterText)
        {
            string Query = string.Empty;
            DI6SubgroupInfo RetVal = new DI6SubgroupInfo();
            DataTable SubgroupTable;
            DI6SubgroupTypeBuilder SGTypeBuilder;
            try
            {
                Query = queries.Subgroup.GetSubgroup(filterClause, filterText);
                SubgroupTable = dbConnection.ExecuteDataTable(Query);

                //set Subgroup info
                if (SubgroupTable != null)
                {
                    if (SubgroupTable.Rows.Count > 0)
                    {
                        RetVal.GID = SubgroupTable.Rows[0][Subgroup.SubgroupGId].ToString();
                        RetVal.Global = Convert.ToBoolean(SubgroupTable.Rows[0][Subgroup.SubgroupGlobal]);
                        RetVal.Name = SubgroupTable.Rows[0][Subgroup.SubgroupName].ToString();
                        RetVal.Nid = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupNId].ToString());
                        RetVal.Type = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupType].ToString());

                        // Get subgrouptype info
                        if (RetVal.Type > 0)
                        {
                            SGTypeBuilder = new DI6SubgroupTypeBuilder(dbConnection, queries);
                            RetVal.DISubgroupType = SGTypeBuilder.GetSubgroupTypeInfoByNid(RetVal.Type);

                        }

                    }
                }
            }
            catch (Exception)
            {
                RetVal = null;
            }
            return RetVal;
        }
Esempio n. 8
0
        /// <summary>
        /// Returns the instance of SubgroupInfo on the basis of Subgroup Nid
        /// </summary>
        /// <param name="sourceQuery"></param>
        /// <param name="sourceDBConnection"></param>
        /// <param name="subgroupNid"></param>
        /// <returns></returns>
        public static DI6SubgroupInfo GetSubgroupInfo(DIQueries queries, DIConnection dbConnection, FilterFieldType filterClause, string filterText)
        {
            string                 Query  = string.Empty;
            DI6SubgroupInfo        RetVal = new DI6SubgroupInfo();
            DataTable              SubgroupTable;
            DI6SubgroupTypeBuilder SGTypeBuilder;

            try
            {
                Query         = queries.Subgroup.GetSubgroup(filterClause, filterText);
                SubgroupTable = dbConnection.ExecuteDataTable(Query);

                //set Subgroup info
                if (SubgroupTable != null)
                {
                    if (SubgroupTable.Rows.Count > 0)
                    {
                        RetVal.GID    = SubgroupTable.Rows[0][Subgroup.SubgroupGId].ToString();
                        RetVal.Global = Convert.ToBoolean(SubgroupTable.Rows[0][Subgroup.SubgroupGlobal]);
                        RetVal.Name   = SubgroupTable.Rows[0][Subgroup.SubgroupName].ToString();
                        RetVal.Nid    = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupNId].ToString());
                        RetVal.Type   = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupType].ToString());

                        // Get subgrouptype info
                        if (RetVal.Type > 0)
                        {
                            SGTypeBuilder         = new DI6SubgroupTypeBuilder(dbConnection, queries);
                            RetVal.DISubgroupType = SGTypeBuilder.GetSubgroupTypeInfoByNid(RetVal.Type);
                        }
                    }
                }
            }
            catch (Exception)
            {
                RetVal = null;
            }
            return(RetVal);
        }
        /// <summary>
        /// Check existance of Subgroup first in collection Then In database
        /// </summary>
        /// <param name="subgroupInfo">object of UnitInfo</param>
        /// <returns> Nid</returns>
        private int CheckSubgroupExists(DI6SubgroupInfo subgroupInfo)
        {
            int RetVal = 0;

            //Step 1: check subgroup exists in Unit collection
            RetVal = this.CheckSubgroupInCollection(subgroupInfo.Name);

            //Step 2: check unit exists in database.
            if (RetVal <= 0)
            {
                RetVal = this.GetSubgroupNid(subgroupInfo.GID, subgroupInfo.Name);
            }

            return RetVal;
        }
Esempio n. 10
0
 /// <summary>
 /// Add subgroup record into collection
 /// </summary>
 /// <param name="subgroupInfo">object of subgroupInfo</param>
 private void AddSubgroupIntoCollection(DI6SubgroupInfo subgroupInfo)
 {
     if (!this.SubgroupCollection.ContainsKey(subgroupInfo.Name))
     {
         this.SubgroupCollection.Add(subgroupInfo.Name, subgroupInfo);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// To Import  Subgroup information from mapped subgroup
        /// </summary>
        /// <param name="subgroupInfo"></param>
        /// <param name="NidInSourceDB"></param>
        /// <param name="NidInTrgDB"></param>
        /// <param name="sourceQurey"></param>
        /// <param name="sourceDBConnection"></param>
        /// <returns></returns>
        public int ImportSubgroupFrmMappedSubgroup(DI6SubgroupInfo subgroupInfo, int NidInSourceDB, int NidInTrgDB, DIQueries sourceQurey, DIConnection sourceDBConnection)
        {
            int RetVal = -1;
            int SGTypeNIdInTargetDB = 0;
            bool SkipRecord = false;
            DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);
            DI6SubgroupTypeInfo SourceSGTypeInfo = new DI6SubgroupTypeInfo();
            DI6SubgroupInfo TargetSGInfo;

            try
            {

                // set RetVal to NidInTrgDB
                RetVal = NidInTrgDB;

                if (!SkipRecord)
                {

                    // get subgroupTypeInfo from source database
                    SourceSGTypeInfo = (new DI6SubgroupTypeBuilder(sourceDBConnection, sourceQurey)).GetSubgroupTypeInfoByNid(subgroupInfo.Type);

                    // import SubgroupType
                    SGTypeNIdInTargetDB = SGTypeBuilder.ImportSubgroupType(SourceSGTypeInfo, SourceSGTypeInfo.Nid, sourceQurey, sourceDBConnection);

                    //insert or update subgroup record
                    if (RetVal > 0)
                    {
                        // get target subgroup info
                        TargetSGInfo = this.GetSubgroupInfo(FilterFieldType.NId, RetVal.ToString());

                        // Dont update if target is global and source is local
                        if (!(subgroupInfo.Global == false & TargetSGInfo.Global))
                        {
                            try
                            {
                                //update the gid,name and global on the basis of nid
                                this.DBConnection.ExecuteNonQuery(DALQueries.Subgroup.Update.UpdateSubgroupByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, subgroupInfo.Name, subgroupInfo.GID, subgroupInfo.Global, SGTypeNIdInTargetDB, RetVal));
                            }
                            catch (Exception)
                            {
                                RetVal = -1;
                            }
                        }

                    }
                    else
                    {
                        // get the last subgroup Type order and update order in source subgrouptype
                        subgroupInfo.Type = SGTypeNIdInTargetDB;

                        if (this.InsertIntoDatabase(subgroupInfo))
                        {
                            //get nid
                            RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }

            return RetVal;
        }
Esempio n. 12
0
        /// <summary>
        /// Import Subgroup: by SubgroupGID and Name
        /// </summary>
        /// <param name="subgroupName"></param>
        /// <param name="subgroupGID"></param>
        /// <param name="subgroupType"></param>
        /// <param name="isGlobal"></param>
        /// <returns></returns>
        public int ImportSubgroup(string subgroupName,string subgroupGID,string subgroupTypeName,bool isGlobal)
        {
            int RetVal = -1;
            int NIDByName = 0;
            int SGTypeNIdInTargetDB = 0;
            bool SkipRecord = false;
            DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);
            DI6SubgroupTypeInfo SourceSGTypeInfo = new DI6SubgroupTypeInfo();
            DI6SubgroupInfo TargetSGInfo;
            DI6SubgroupInfo SubgroupInfoObj=new DI6SubgroupInfo();

            try
            {
                SubgroupInfoObj.Name = subgroupName;
                SubgroupInfoObj.GID = subgroupGID;
                SubgroupInfoObj.Global = isGlobal;

                //check  already exists in database or not

                //Get NId by Name
                if (!string.IsNullOrEmpty(SubgroupInfoObj.GID))
                {
                    //first check by gid and then by name
                    RetVal = this.GetNidByGID(SubgroupInfoObj.GID);

                    if (RetVal > 0)
                    {
                        // check for the duplicacy by name
                        NIDByName = this.GetSubgroupByName(SubgroupInfoObj.Name);
                        if (RetVal != NIDByName & NIDByName > 0)
                        {
                            //skip records
                            SkipRecord = true;
                            RetVal = -1;
                        }
                    }
                }

                //if GID is empty or GID doesnt match  then get NId by name
                if (RetVal <= 0 & SkipRecord == false)
                {

                    RetVal = this.GetSubgroupByName(SubgroupInfoObj.Name);
                }

                if (!SkipRecord)
                {
                    //-- PreRequisite to Import SubgroupType First
                    // get subgroupTypeInfo from source database
                    SourceSGTypeInfo.Name = subgroupTypeName;
                    SGTypeNIdInTargetDB = (new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries)).CheckNCreateSubgroupType(SourceSGTypeInfo);

                    //insert or update subgroup record
                    if (RetVal > 0)
                    {
                        // get target subgroup info
                        TargetSGInfo = this.GetSubgroupInfo(FilterFieldType.NId, RetVal.ToString());
                        // Dont update if target is global and source is local
                        if (!(SubgroupInfoObj.Global == false & TargetSGInfo.Global))
                        {
                            try
                            {
                                //update the gid,name and global on the basis of nid
                                this.DBConnection.ExecuteNonQuery(DALQueries.Subgroup.Update.UpdateSubgroupByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, SubgroupInfoObj.Name, SubgroupInfoObj.GID, SubgroupInfoObj.Global, SGTypeNIdInTargetDB, RetVal));
                            }
                            catch (Exception)
                            {
                                RetVal = -1;
                            }
                        }

                    }
                    else
                    {
                        // get the last subgroup Type order and update order in source subgrouptype
                        SubgroupInfoObj.Type = SGTypeNIdInTargetDB;

                        if (this.InsertIntoDatabase(SubgroupInfoObj))
                        {
                            //get nid
                            RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }

            return RetVal;
        }
Esempio n. 13
0
        /// <summary>
        /// Check and create Subgroup record
        /// </summary>
        /// <param name="subgroupInfo">object of DI6SubgroupInfo </param>
        /// <returns>Nid</returns>
        public int CheckNCreateSubgroup(DI6SubgroupInfo subgroupInfo)
        {
            int RetVal = 0;

            try
            {
                // check Subgroup exists or not
                RetVal = this.CheckSubgroupExists(subgroupInfo);

                // if Subgroup does not exist then create it.
                if (RetVal <= 0)
                {
                    // insert subgroup
                    if (this.InsertIntoDatabase(subgroupInfo))
                    {
                        RetVal = this.GetSubgroupByName(subgroupInfo.Name);
                    }

                }

                // add Subgroup information into collection
                subgroupInfo.Nid = RetVal;
                this.AddSubgroupIntoCollection(subgroupInfo);
            }
            catch (Exception)
            {
                RetVal = 0;
            }

            return RetVal;
        }
Esempio n. 14
0
        /// <summary>
        /// To Import  Subgroup information from mapped subgroup
        /// </summary>
        /// <param name="subgroupInfo"></param>
        /// <param name="NidInSourceDB"></param>
        /// <param name="NidInTrgDB"></param>
        /// <param name="sourceQurey"></param>
        /// <param name="sourceDBConnection"></param>
        /// <returns></returns>
        public int ImportSubgroupFrmMappedSubgroup(DI6SubgroupInfo subgroupInfo, int NidInSourceDB, int NidInTrgDB, DIQueries sourceQurey, DIConnection sourceDBConnection)
        {
            int  RetVal = -1;
            int  SGTypeNIdInTargetDB                = 0;
            bool SkipRecord                         = false;
            DI6SubgroupTypeBuilder SGTypeBuilder    = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);
            DI6SubgroupTypeInfo    SourceSGTypeInfo = new DI6SubgroupTypeInfo();
            DI6SubgroupInfo        TargetSGInfo;

            try
            {
                // set RetVal to NidInTrgDB
                RetVal = NidInTrgDB;



                if (!SkipRecord)
                {
                    // get subgroupTypeInfo from source database
                    SourceSGTypeInfo = (new DI6SubgroupTypeBuilder(sourceDBConnection, sourceQurey)).GetSubgroupTypeInfoByNid(subgroupInfo.Type);


                    // import SubgroupType
                    SGTypeNIdInTargetDB = SGTypeBuilder.ImportSubgroupType(SourceSGTypeInfo, SourceSGTypeInfo.Nid, sourceQurey, sourceDBConnection);


                    //insert or update subgroup record
                    if (RetVal > 0)
                    {
                        // get target subgroup info
                        TargetSGInfo = this.GetSubgroupInfo(FilterFieldType.NId, RetVal.ToString());

                        // Dont update if target is global and source is local
                        if (!(subgroupInfo.Global == false & TargetSGInfo.Global))
                        {
                            try
                            {
                                //update the gid,name and global on the basis of nid
                                this.DBConnection.ExecuteNonQuery(DALQueries.Subgroup.Update.UpdateSubgroupByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, subgroupInfo.Name, subgroupInfo.GID, subgroupInfo.Global, SGTypeNIdInTargetDB, RetVal));
                            }
                            catch (Exception)
                            {
                                RetVal = -1;
                            }
                        }
                    }
                    else
                    {
                        // get the last subgroup Type order and update order in source subgrouptype
                        subgroupInfo.Type = SGTypeNIdInTargetDB;

                        if (this.InsertIntoDatabase(subgroupInfo))
                        {
                            //get nid
                            RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }

            return(RetVal);
        }
Esempio n. 15
0
        /// <summary>
        /// Insert  record into subgroup table
        /// </summary>
        /// <param name="subgroupInfo">object of SubgroupInfo </param>
        /// <returns>Ture/False. Return true after successful insertion otherwise false</returns>
        private bool InsertIntoDatabase(DI6SubgroupInfo subgroupInfo)
        {
            bool RetVal = false;
            string SubgroupName = subgroupInfo.Name;
            string subgroupGID = subgroupInfo.GID;
            string SubgroupGId = Guid.NewGuid().ToString();
            string LanguageCode = string.Empty;
            string DefaultLanguageCode = string.Empty;
            string SubgroupForDatabase = string.Empty;
            int LastOrder = 0;

            try
            {
                DefaultLanguageCode = this.DBQueries.LanguageCode;

                //replace GID only if given gid is not empty or null.
                if (!string.IsNullOrEmpty(subgroupGID))
                {
                    SubgroupGId = subgroupGID;
                }

                // if subgroup order <= 0 then set the subgroup order
                if (subgroupInfo.SubgroupOrder <= 0)
                {
                    try
                    {
                        LastOrder = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(this.DBQueries.Subgroup.GetMaxSubgroupOrder(subgroupInfo.Type)));
                    }
                    catch (Exception)
                    {
                    }

                    // set subgroup order
                    subgroupInfo.SubgroupOrder = LastOrder + 1;
                }

                foreach (DataRow languageRow in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows)
                {
                    LanguageCode = languageRow[Language.LanguageCode].ToString();
                    if (LanguageCode == DefaultLanguageCode.Replace("_", String.Empty))
                    {
                        SubgroupForDatabase = SubgroupName;
                    }
                    else
                    {
                        SubgroupForDatabase = Constants.PrefixForNewValue + SubgroupName;
                    }
                    this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.Subgroup.Insert.InsertSubgroup(this.DBQueries.DataPrefix, "_" + LanguageCode, SubgroupForDatabase, SubgroupGId, subgroupInfo.Global, subgroupInfo.Type, DBConnection.ConnectionStringParameters.ServerType,subgroupInfo.SubgroupOrder ));
                }

                RetVal = true;
            }
            catch (Exception)
            {
                RetVal = false;
            }

            return RetVal;
        }
Esempio n. 16
0
        /// <summary>
        /// Import Subgroup: by SubgroupGID and Name
        /// </summary>
        /// <param name="subgroupName"></param>
        /// <param name="subgroupGID"></param>
        /// <param name="subgroupType"></param>
        /// <param name="isGlobal"></param>
        /// <returns></returns>
        public int ImportSubgroup(string subgroupName, string subgroupGID, string subgroupTypeName, bool isGlobal)
        {
            int  RetVal                             = -1;
            int  NIDByName                          = 0;
            int  SGTypeNIdInTargetDB                = 0;
            bool SkipRecord                         = false;
            DI6SubgroupTypeBuilder SGTypeBuilder    = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);
            DI6SubgroupTypeInfo    SourceSGTypeInfo = new DI6SubgroupTypeInfo();
            DI6SubgroupInfo        TargetSGInfo;
            DI6SubgroupInfo        SubgroupInfoObj = new DI6SubgroupInfo();

            try
            {
                SubgroupInfoObj.Name   = subgroupName;
                SubgroupInfoObj.GID    = subgroupGID;
                SubgroupInfoObj.Global = isGlobal;

                //check  already exists in database or not

                //Get NId by Name
                if (!string.IsNullOrEmpty(SubgroupInfoObj.GID))
                {
                    //first check by gid and then by name
                    RetVal = this.GetNidByGID(SubgroupInfoObj.GID);

                    if (RetVal > 0)
                    {
                        // check for the duplicacy by name
                        NIDByName = this.GetSubgroupByName(SubgroupInfoObj.Name);
                        if (RetVal != NIDByName & NIDByName > 0)
                        {
                            //skip records
                            SkipRecord = true;
                            RetVal     = -1;
                        }
                    }
                }

                //if GID is empty or GID doesnt match  then get NId by name
                if (RetVal <= 0 & SkipRecord == false)
                {
                    RetVal = this.GetSubgroupByName(SubgroupInfoObj.Name);
                }

                if (!SkipRecord)
                {
                    //-- PreRequisite to Import SubgroupType First
                    // get subgroupTypeInfo from source database
                    SourceSGTypeInfo.Name = subgroupTypeName;
                    SGTypeNIdInTargetDB   = (new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries)).CheckNCreateSubgroupType(SourceSGTypeInfo);

                    //insert or update subgroup record
                    if (RetVal > 0)
                    {
                        // get target subgroup info
                        TargetSGInfo = this.GetSubgroupInfo(FilterFieldType.NId, RetVal.ToString());
                        // Dont update if target is global and source is local
                        if (!(SubgroupInfoObj.Global == false & TargetSGInfo.Global))
                        {
                            try
                            {
                                //update the gid,name and global on the basis of nid
                                this.DBConnection.ExecuteNonQuery(DALQueries.Subgroup.Update.UpdateSubgroupByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, SubgroupInfoObj.Name, SubgroupInfoObj.GID, SubgroupInfoObj.Global, SGTypeNIdInTargetDB, RetVal));
                            }
                            catch (Exception)
                            {
                                RetVal = -1;
                            }
                        }
                    }
                    else
                    {
                        // get the last subgroup Type order and update order in source subgrouptype
                        SubgroupInfoObj.Type = SGTypeNIdInTargetDB;

                        if (this.InsertIntoDatabase(SubgroupInfoObj))
                        {
                            //get nid
                            RetVal = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery("SELECT @@IDENTITY"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }

            return(RetVal);
        }
Esempio n. 17
0
 /// <summary>
 /// Returns the instance of SubgroupInfo on the basis of Subgroup Nid
 /// </summary>
 /// <param name="sourceQuery"></param>
 /// <param name="sourceDBConnection"></param>
 /// <param name="subgroupNid"></param>
 /// <returns></returns>
 public static DI6SubgroupInfo GetSubgroupInfoByNid(DIQueries sourceQuery, DIConnection sourceDBConnection, int subgroupNid)
 {
     DI6SubgroupInfo RetVal = new DI6SubgroupInfo();
     RetVal = DI6SubgroupBuilder.GetSubgroupInfo(sourceQuery, sourceDBConnection, FilterFieldType.NId, subgroupNid.ToString());
     return RetVal;
 }
Esempio n. 18
0
        public bool UpdateSubgroupValsInOthersSGDimensionInTables()
        {
            bool RetVal = false;
            string SqlQuery = string.Empty;
            DataTable SubgroupTable = null;
            int SubgroupNid = 0;
            int Others_SubgroupTypeNid = -1;
            DI6SubgroupBuilder subgroupBuilder = new DI6SubgroupBuilder(this.DBConnection, this.DBQueries);
            DI6SubgroupInfo subgroupInfo = null;

            try
            {

                subgroupBuilder = new DI6SubgroupBuilder(this.DBConnection,this.DBQueries);

                Others_SubgroupTypeNid = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(this.DBQueries.SubgroupTypes.GetSubgroupTypes(FilterFieldType.GId, "'OTHERS'")));

                if (Others_SubgroupTypeNid > 0)
                {
                    SqlQuery = "select * from " + this.DBQueries.TablesName.SubgroupVals + " sv where " + SubgroupVals.SubgroupValNId + " not in(select " + SubgroupVals.SubgroupValNId + " from " + this.DBQueries.TablesName.SubgroupValsSubgroup + " svs where svs." + SubgroupVals.SubgroupValNId + "=sv." + SubgroupVals.SubgroupValNId + ")";

                    //Get those subgroupVals which is not exists in ut_subgroup_val_subgroup
                    DataTable SubgroupValsTable = this.DBConnection.ExecuteDataTable(SqlQuery);

                    foreach (DataRow SGRow in SubgroupValsTable.Rows)
                    {
                        SubgroupTable = this.DBConnection.ExecuteDataTable(this.DBQueries.Subgroup.GetSubgroup(FilterFieldType.Name, "'" + Convert.ToString(SGRow[SubgroupVals.SubgroupVal]) + "'"));

                        if (SubgroupTable.Rows.Count == 0)
                        {
                            subgroupInfo = new DI6SubgroupInfo();
                            subgroupInfo.Name = Convert.ToString(SGRow[SubgroupVals.SubgroupVal]);
                            subgroupInfo.GID = Convert.ToString(SGRow[SubgroupVals.SubgroupValGId]);
                            subgroupInfo.Global = Convert.ToBoolean(SGRow[SubgroupVals.SubgroupValGlobal]);
                            subgroupInfo.Type = Others_SubgroupTypeNid;

                            SubgroupNid = subgroupBuilder.CheckNCreateSubgroup(subgroupInfo);
                        }
                        else
                        {
                            SubgroupNid = Convert.ToInt32(SubgroupTable.Rows[0][Subgroup.SubgroupNId]);
                        }

                        this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.SubgroupValSubgroup.Insert.InsertSubgroupValRelation(this.DBQueries.DataPrefix, Convert.ToInt32(SGRow[SubgroupVals.SubgroupValNId]), SubgroupNid));

                    }

                }

                RetVal = true;
            }
            catch (Exception ex)
            {
                ExceptionFacade.ThrowException(ex);
            }

            return RetVal;
        }