/// <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)
        {
            DI6SubgroupTypeBuilder SGTypeBuilderObj = new DI6SubgroupTypeBuilder(this._TargetDBConnection, this._TargetDBQueries);
            DI6SubgroupTypeInfo    SourceDBSubgroupType;

            DataRow Row;
            int     ProgressBarValue = 0;


            foreach (string Nid in selectedNids)
            {
                try
                {
                    //get subgroup Type from source table
                    Row = this.SourceTable.Select(SubgroupTypes.SubgroupTypeNId + "=" + Nid)[0];
                    SourceDBSubgroupType        = new DI6SubgroupTypeInfo();
                    SourceDBSubgroupType.Name   = DICommon.RemoveQuotes(Row[SubgroupTypes.SubgroupTypeName].ToString());
                    SourceDBSubgroupType.GID    = Row[SubgroupTypes.SubgroupTypeGID].ToString();
                    SourceDBSubgroupType.Global = Convert.ToBoolean(Row[SubgroupTypes.SubgroupTypeGlobal]);
                    SourceDBSubgroupType.Nid    = Convert.ToInt32(Row[SubgroupTypes.SubgroupTypeNId]);
                    SourceDBSubgroupType.Order  = Convert.ToInt32(Row[SubgroupTypes.SubgroupTypeOrder]);

                    //import into target database
                    SGTypeBuilderObj.ImportSubgroupType(SourceDBSubgroupType, SourceDBSubgroupType.Nid, this.SourceDBQueries, this.SourceDBConnection);
                }
                catch (Exception ex)
                {
                    ExceptionFacade.ThrowException(ex);
                }
                this.RaiseIncrementProgessBarEvent(ProgressBarValue);
                ProgressBarValue++;
            }
        }
Exemplo n.º 2
0
        public override void Import(string selectedNids)
        {
            DataTable Table           = null;
            int       ProgressCounter = 0;
            DI6SubgroupTypeBuilder       SGBuilderObj = null;
            DI6SubgroupTypeInfo          SGInfoObj    = null;
            Dictionary <string, DataRow> FileWithNids = new Dictionary <string, DataRow>();

            DIConnection           SourceDBConnection  = null;
            DIQueries              SourceDBQueries     = null;
            DI6SubgroupTypeBuilder SourceSGTypeBuilder = null;

            //-- Step 1: Get TempTable with Sorted SourceFileName
            Table = this._TargetDBConnection.ExecuteDataTable(this.ImportQueries.GetImportSubgroupDimensions(selectedNids));

            //-- Step 2:Initialise Indicator Builder with Target DBConnection
            SGBuilderObj = new DI6SubgroupTypeBuilder(this.TargetDBConnection, this.TargetDBQueries);

            // Initialize progress bar
            this.RaiseProgressBarInitialize(selectedNids.Split(',').GetUpperBound(0) + 1);


            //-- Step 3: Import Nids for each SourceFile
            foreach (DataRow Row in Table.Copy().Rows)
            {
                try
                {
                    string SourceFileWPath = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]);

                    SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SourceFileWPath, String.Empty, MergetTemplateConstants.DBPassword);
                    SourceDBQueries    = DataExchange.GetDBQueries(SourceDBConnection);

                    // get subgroup type info from source
                    SourceSGTypeBuilder = new DI6SubgroupTypeBuilder(SourceDBConnection, SourceDBQueries);
                    SGInfoObj           = SourceSGTypeBuilder.GetSubgroupTypeInfoByNid(Convert.ToInt32(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]));


                    // import subgroup type only if doesnt exist
                    SGBuilderObj.ImportSubgroupType(SGInfoObj, Convert.ToInt32(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]), SourceDBQueries, SourceDBConnection);
                    ProgressCounter += 1;
                    this.RaiseProgressBarIncrement(ProgressCounter);
                }
                catch (Exception ex) { ExceptionFacade.ThrowException(ex); }
                finally
                {
                    if (SourceDBConnection != null)
                    {
                        SourceDBConnection.Dispose();
                    }
                    if (SourceDBQueries != null)
                    {
                        SourceDBQueries.Dispose();
                    }
                }
            }
            this._AvailableTable = this.GetAvailableTable();
            this._UnmatchedTable = this.GetUnmatchedTable();
            // Close ProgressBar
            this.RaiseProgressBarClose();
        }
        /// <summary>
        /// Check and create Subgroup Type record
        /// </summary>
        /// <param name="subgroupTypeInfo">object of DI6SubgroupTypeInfo </param>
        /// <returns>Nid</returns>
        public int CheckNCreateSubgroupType(DI6SubgroupTypeInfo subgroupTypeInfo)
        {
            int RetVal = 0;

            try
            {
                // check Subgroup type exists or not
                RetVal = this.CheckSubgroupTypeExists(subgroupTypeInfo);

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

                }

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

            return RetVal;
        }
Exemplo n.º 4
0
        private void GetNSetLocationTypeInfo()
        {
            int LocationSGTypeNid = 0;
            DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);

            LocationSGTypeNid = SGTypeBuilder.GetSubgroupTypeNid(string.Empty, Constants.SubgroupType.Location);
            if (LocationSGTypeNid <= 0)
            {
                LocationSGTypeNid = SGTypeBuilder.GetSubgroupTypeNid(string.Empty, Constants.PrefixForNewValue + Constants.SubgroupType.Location);
            }

            this.LocationTypeInfo = SGTypeBuilder.GetSubgroupTypeInfoByNid(LocationSGTypeNid);
        }
Exemplo n.º 5
0
        private void GetNSetOthersTypeInfo()
        {
            int OthersSGTypeNid = 0;
            DI6SubgroupTypeBuilder SGTypeBuilder = new DI6SubgroupTypeBuilder(this.DBConnection, this.DBQueries);

            OthersSGTypeNid = SGTypeBuilder.GetSubgroupTypeNid(string.Empty, Constants.SubgroupType.Other);

            if (OthersSGTypeNid <= 0)
            {
                OthersSGTypeNid = SGTypeBuilder.GetSubgroupTypeNid(string.Empty, Constants.PrefixForNewValue + Constants.SubgroupType.Other);
            }

            this.OthersTypeInfo = SGTypeBuilder.GetSubgroupTypeInfoByNid(OthersSGTypeNid);
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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;
        }
        /// <summary>
        /// Insert  record into subgroup type table
        /// </summary>
        /// <param name="subgroupTypeInfo">object of DI6SubgroupTypeInfo </param>
        /// <returns>Ture/False. Return true after successful insertion otherwise false</returns>
        private bool InsertIntoDatabase(DI6SubgroupTypeInfo subgroupTypeInfo)
        {
            bool RetVal = false;
            string Name = subgroupTypeInfo.Name;
            string subgroupTypeGID = subgroupTypeInfo.GID;
            string SubgroupTypeGId = Guid.NewGuid().ToString();
            string LanguageCode = string.Empty;
            string DefaultLanguageCode = string.Empty;
            string SubgroupTypeForDatabase = string.Empty;
            DITables TablesName;
            int LastOrder = 0;

            try
            {
                DefaultLanguageCode = this.DBQueries.LanguageCode;

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

                // if subgroup type  order <= 0 then set the subgroup type order
                if (subgroupTypeInfo.Order <= 0)
                {
                    try
                    {
                        LastOrder = Convert.ToInt32(this.DBConnection.ExecuteScalarSqlQuery(this.DBQueries.SubgroupTypes.GetMaxSubgroupTypeOrder()));
                    }
                    catch (Exception)
                    {
                    }

                    // set subgroup order
                    subgroupTypeInfo.Order = LastOrder + 1;
                }

                foreach (DataRow languageRow in this.DBConnection.DILanguages(this.DBQueries.DataPrefix).Rows)
                {
                    LanguageCode = languageRow[Language.LanguageCode].ToString();

                    TablesName = new DITables(this.DBQueries.DataPrefix, LanguageCode);

                    if (LanguageCode == DefaultLanguageCode.Replace("_", String.Empty))
                    {
                        SubgroupTypeForDatabase = Name;
                    }
                    else
                    {
                        SubgroupTypeForDatabase = Constants.PrefixForNewValue + Name;
                    }

                    this.DBConnection.ExecuteNonQuery(DevInfo.Lib.DI_LibDAL.Queries.SubgroupTypes.Insert.InsertSubgroupType(TablesName.SubgroupType, SubgroupTypeForDatabase, SubgroupTypeGId, subgroupTypeInfo.Order, subgroupTypeInfo.Global));
                }

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

            return RetVal;
        }
        /// <summary>
        /// Check existance of Subgroup type first in collection Then In database
        /// </summary>
        /// <param name="subgroupInfo">object of DI6SubgroupTypeInfo</param>
        /// <returns> Nid</returns>
        private int CheckSubgroupTypeExists(DI6SubgroupTypeInfo subgroupTypeInfo)
        {
            int RetVal = 0;

            //Step 1: check subgroup type exists in  collection
            RetVal = this.CheckSubgroupTypeInCollection(subgroupTypeInfo.Name);

            //Step 2: check it  exists in database.
            if (RetVal <= 0)
            {
                RetVal = this.GetSubgroupTypeNid(subgroupTypeInfo.GID, subgroupTypeInfo.Name);
            }

            return RetVal;
        }
 /// <summary>
 /// Add subgroup type record into collection
 /// </summary>
 /// <param name="subgroupInfo">object of DI6SubgroupTypeInfo</param>
 private void AddSubgroupTypeIntoCollection(DI6SubgroupTypeInfo subgroupTypeInfo)
 {
     if (!this.SubgroupCollection.ContainsKey(subgroupTypeInfo.Name))
     {
         this.SubgroupCollection.Add(subgroupTypeInfo.Name, subgroupTypeInfo);
     }
 }
        /// <summary>
        /// To Import SubgroupType information  from mapped subgroup type
        /// </summary>
        /// <param name="subgroupTypeInfo"></param>
        /// <param name="NidInSourceDB"></param>
        /// <param name="NidInTrgDB"></param>
        /// <param name="sourceQurey"></param>
        /// <param name="sourceDBConnection"></param>
        /// <returns></returns>
        public int ImportSubgroupTypeFrmMappedSubgroupType(DI6SubgroupTypeInfo subgroupTypeInfo, int NidInSourceDB,int NidInTrgDB, DIQueries sourceQurey, DIConnection sourceDBConnection)
        {
            int RetVal = -1;
            bool SkipRecord = false;
            try
            {
                // set RetVal to NidInTrgDB
                RetVal = NidInTrgDB;

                if (!SkipRecord)
                {
                    //insert or update record
                    if (RetVal > 0)
                    {
                        // update only if source item is global
                        if (subgroupTypeInfo.Global)
                        {
                            try
                            {
                                // dont change the order into target  database

                                //update the gid,name and global on the basis of nid
                                this.DBConnection.ExecuteNonQuery(DALQueries.SubgroupTypes.Update.UpdateSubgroupTypeByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, subgroupTypeInfo.Name, subgroupTypeInfo.GID, subgroupTypeInfo.Global, this.GetSubgroupTypeInfoByNid(RetVal).Order, RetVal));
                            }
                            catch (Exception)
                            {
                                RetVal = -1;
                            }
                        }

                    }
                    else
                    {
                        // get the last subgroup Type order and update order in source subgrouptype
                        subgroupTypeInfo.Order = this.GetLastSubgroupTypeOrder() + 1;

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

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

            return RetVal;
        }
        /// <summary>
        /// Import Subgroup Type
        /// </summary>
        /// <param name="subgroupTypeInfo"></param>
        /// <param name="NidInSourceDB"></param>
        /// <param name="sourceQurey"></param>
        /// <param name="sourceDBConnection"></param>
        /// <returns></returns>
        public int ImportSubgroupType(string subgroupTypeName,string subgroupTypeGID,bool isGlobal)
        {
            int RetVal = -1;
            int NIDByName = 0;
            bool SkipRecord = false;
            DI6SubgroupTypeInfo SubgroupTypeInfo=new DI6SubgroupTypeInfo();

            try
            {
                SubgroupTypeInfo.Name = subgroupTypeName;
                SubgroupTypeInfo.GID = subgroupTypeGID;
                SubgroupTypeInfo.Global = isGlobal;

                //check  already exists in database or not

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

                    if (RetVal > 0)
                    {
                        // check for the duplicacy by name
                        NIDByName = this.GetSubgroupTypeByName(SubgroupTypeInfo.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.GetSubgroupTypeByName(SubgroupTypeInfo.Name);
                }

                if (!SkipRecord)
                {
                    //insert or update record
                    if (RetVal > 0)
                    {
                        // update only if source item is global
                        if (SubgroupTypeInfo.Global)
                        {
                            try
                            {
                                // dont change the order into target  database
                                //update the gid,name and global on the basis of nid
                                this.DBConnection.ExecuteNonQuery(DALQueries.SubgroupTypes.Update.UpdateSubgroupTypeByNid(this.DBQueries.DataPrefix, this.DBQueries.LanguageCode, SubgroupTypeInfo.Name, SubgroupTypeInfo.GID, SubgroupTypeInfo.Global, this.GetSubgroupTypeInfoByNid(RetVal).Order, RetVal));
                            }
                            catch (Exception)
                            {
                                RetVal = -1;
                            }
                        }

                    }
                    else
                    {
                        // get the last subgroup Type order and update order in source subgrouptype
                        SubgroupTypeInfo.Order = this.GetLastSubgroupTypeOrder() + 1;

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

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

            return RetVal;
        }
        /// <summary>
        /// Returns the instance of SubgroupTypeInfo on the basis of Subgroup Nid
        /// </summary>
        /// <param name="subgroupTypeNid"></param>
        /// <returns></returns>
        public DI6SubgroupTypeInfo GetSubgroupTypeInfoByNid(int subgroupTypeNid)
        {
            DI6SubgroupTypeInfo RetVal = new DI6SubgroupTypeInfo();
            string Query = string.Empty;
            DataTable Table;

            //get subgroup type info from source database
            try
            {
                if (subgroupTypeNid > 0)
                {
                    Query = this.DBQueries.SubgroupTypes.GetSubgroupTypes(FilterFieldType.NId, subgroupTypeNid.ToString());
                    Table = this.DBConnection.ExecuteDataTable(Query);

                    if (Table.Rows.Count > 0)
                    {
                        RetVal.Nid = subgroupTypeNid;
                        RetVal.GID = Table.Rows[0][SubgroupTypes.SubgroupTypeGID].ToString();
                        RetVal.Name = Table.Rows[0][SubgroupTypes.SubgroupTypeName].ToString();
                        RetVal.Global = Convert.ToBoolean(Table.Rows[0][SubgroupTypes.SubgroupTypeGlobal]);
                        RetVal.Order = Convert.ToInt32(Table.Rows[0][SubgroupTypes.SubgroupTypeOrder]);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
            return RetVal;
        }