/// <summary>
        /// Delete Invesor Group Config By Investor Group Config ID
        /// Using Delete In Talbe InvestorGroupConfig With ID
        /// </summary>
        /// <param name="InvestorGroupConfigID">int Investor GroupConfigID</param>
        internal bool DeleteInvestorGroupConfig(int InvestorGroupConfigID)
        {
            bool Result = false;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorGroupConfigTableAdapter adap = new DSTableAdapters.InvestorGroupConfigTableAdapter();

            try
            {
                conn.Open();
                adap.Connection = conn;

                adap.DeleteInvestorGroupConfig(InvestorGroupConfigID);
                Result = true;
            }
            catch (Exception ex)
            {
                Result = false;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// Add New Investor Group Config
        /// </summary>
        /// <param name="InvestorGroupID">int InvestorGroupID</param>
        /// <param name="CollectionValue">int CollectionValue</param>
        /// <param name="Name">string Name</param>
        /// <param name="Code">string Code</param>
        /// <param name="BoolValue">int BoolValue</param>
        /// <param name="StringValue">string StringValue</param>
        /// <param name="NumValue">string NumValue</param>
        /// <param name="DateValue">DateTime DateValue</param>
        /// <returns>int</returns>
        internal int AddNewInvestorGroupConfig(int InvestorGroupID, int CollectionValue, string Name, string Code, int BoolValue,
                                                string StringValue,string NumValue,DateTime DateValue)
        {
            int Result = -1;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorGroupConfigTableAdapter adap = new DSTableAdapters.InvestorGroupConfigTableAdapter();

            try
            {
                conn.Open();
                adap.Connection = conn;

                Result = int.Parse(adap.AddNewInvestorGroupConfig(InvestorGroupID, null, Name, Code, BoolValue, StringValue, NumValue, DateValue).ToString());
            }
            catch (Exception ex)
            {
                return -1;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        internal List<Business.InvestorGroup> GetAllInvestorGroup()
        {
            List<Business.InvestorGroup> Result = new List<Business.InvestorGroup>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorGroupTableAdapter adap = new DSTableAdapters.InvestorGroupTableAdapter();
            DSTableAdapters.InvestorGroupConfigTableAdapter adapInvestorGroupConfig = new DSTableAdapters.InvestorGroupConfigTableAdapter();

            DS.InvestorGroupDataTable tbInvestorGroup = new DS.InvestorGroupDataTable();
            DS.InvestorGroupConfigDataTable tbInvestorGroupConfig = new DS.InvestorGroupConfigDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                adapInvestorGroupConfig.Connection = conn;

                tbInvestorGroup = adap.GetData();
                if (tbInvestorGroup != null)
                {
                    int count = tbInvestorGroup.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.InvestorGroup newInvestorGroup = new Business.InvestorGroup();
                        newInvestorGroup.DefautDeposite = tbInvestorGroup[i].DefautDeposite;
                        newInvestorGroup.InvestorGroupID = tbInvestorGroup[i].InvestorGroupID;
                        newInvestorGroup.Name = tbInvestorGroup[i].Name;
                        newInvestorGroup.Owner = tbInvestorGroup[i].Owner;

                        //newInvestorGroup.ParameterItems = DBWInvestorGroup.DBWInvestorGroupConfigInstance.GetInvestorGroupConfigByInvestorGroupID(tbInvestorGroup[i].InvestorGroupID);
                        tbInvestorGroupConfig = adapInvestorGroupConfig.GetInvestorGroupConfigByInvestorGroupID(tbInvestorGroup[i].InvestorGroupID);

                        if (tbInvestorGroupConfig != null)
                        {
                            int countInvestorGroupConfig = tbInvestorGroupConfig.Count;
                            for (int j = 0; j < countInvestorGroupConfig; j++)
                            {
                                Business.ParameterItem newParameterItem = new Business.ParameterItem();
                                newParameterItem.BoolValue = tbInvestorGroupConfig[j].BoolValue;
                                newParameterItem.Code = tbInvestorGroupConfig[j].Code;
                                newParameterItem.DateValue = tbInvestorGroupConfig[j].DateValue;
                                newParameterItem.NumValue = tbInvestorGroupConfig[j].NumValue;
                                newParameterItem.ParameterItemID = tbInvestorGroupConfig[j].InvestorGroupConfigID;
                                newParameterItem.SecondParameterID = tbInvestorGroupConfig[j].InvestorGroupID;
                                newParameterItem.Name = tbInvestorGroupConfig[j].Name;
                                newParameterItem.StringValue = tbInvestorGroupConfig[j].StringValue;

                                if (tbInvestorGroupConfig[j].Code == "G01")
                                {
                                    bool isEnable = false;
                                    if (tbInvestorGroupConfig[j].BoolValue == 1)
                                        isEnable = true;
                                    newInvestorGroup.IsEnable = isEnable;
                                }

                                if (tbInvestorGroupConfig[j].Code == "G26")
                                {
                                    newInvestorGroup.FreeMargin = tbInvestorGroupConfig[j].StringValue;
                                }

                                if (tbInvestorGroupConfig[j].Code == "G19")
                                {
                                    double MarginCallLevel = 0;
                                    double.TryParse(tbInvestorGroupConfig[j].NumValue, out MarginCallLevel);
                                    newInvestorGroup.MarginCall = MarginCallLevel;
                                }

                                if (tbInvestorGroupConfig[j].Code == "G20")
                                {
                                    double MarginStopOutLevel = 0;
                                    double.TryParse(tbInvestorGroupConfig[j].NumValue, out MarginStopOutLevel);
                                    newInvestorGroup.MarginStopOut = MarginStopOutLevel;
                                }

                                if (tbInvestorGroupConfig[j].Code == "G38")
                                {
                                    if (tbInvestorGroupConfig[j].BoolValue == 1)
                                        newInvestorGroup.IsManualStopOut = true;
                                }

                                if (newInvestorGroup.ParameterItems == null)
                                    newInvestorGroup.ParameterItems = new List<Business.ParameterItem>();

                                newInvestorGroup.ParameterItems.Add(newParameterItem);
                            }
                        }

                        //if (newInvestorGroup.ParameterItems != null)
                        //{
                        //    int countParameter = newInvestorGroup.ParameterItems.Count;
                        //    for (int j = 0; j < countParameter; j++)
                        //    {
                        //        if (newInvestorGroup.ParameterItems[j].Code == "G26")
                        //        {
                        //            newInvestorGroup.FreeMargin = newInvestorGroup.ParameterItems[j].StringValue;
                        //        }

                        //        if (newInvestorGroup.ParameterItems[j].Code == "G19")
                        //        {
                        //            double MarginCallLevel=0;
                        //            double.TryParse(newInvestorGroup.ParameterItems[j].NumValue, out MarginCallLevel);
                        //            newInvestorGroup.MarginCall = MarginCallLevel;
                        //        }

                        //        if (newInvestorGroup.ParameterItems[j].Code == "G20")
                        //        {
                        //            double MarginStopOutLevel = 0;
                        //            double.TryParse(newInvestorGroup.ParameterItems[j].NumValue, out MarginStopOutLevel);
                        //            newInvestorGroup.MarginStopOut = MarginStopOutLevel;
                        //        }
                        //    }
                        //}

                        Result.Add(newInvestorGroup);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                adapInvestorGroupConfig.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// Update Investor Group Config By Investor Group Config ID
        /// </summary>
        /// <param name="InvestorGroupConfigID">int InvestorGroupConfigID</param>
        /// <param name="InvestorGroupID">int InvestorGroupID</param>
        /// <param name="CollectionValue">int CollectionValue</param>
        /// <param name="Name">string Name</param>
        /// <param name="Code">string Code</param>
        /// <param name="BoolValue">int BoolValue</param>
        /// <param name="StringValue">string StringValue</param>
        /// <param name="NumValue">string NumValue</param>
        /// <param name="DateValue">DateTime DateValue</param>
        internal bool UpdateInvestorGroupConfig(int InvestorGroupConfigID, int InvestorGroupID, int CollectionValue, string Name,
                                                string Code, int BoolValue, string StringValue, string NumValue, DateTime DateValue)
        {
            bool Result = true;
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorGroupConfigTableAdapter adap = new DSTableAdapters.InvestorGroupConfigTableAdapter();

            try
            {
                conn.Open();
                adap.Connection = conn;

                adap.UpdateInvestorGroupConfig(InvestorGroupID, null, Name, Code, BoolValue, StringValue, NumValue, DateValue, InvestorGroupConfigID);
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// Get Investor Group COnfig By Investor Group ID
        /// </summary>
        /// <param name="InvestorGroupID">int InvestorGroupID</param>
        /// <returns>List<Business.ParameterItem></returns>
        internal List<Business.ParameterItem> GetInvestorGroupConfigByInvestorGroupID(int InvestorGroupID)
        {
            List<Business.ParameterItem> Result = new List<Business.ParameterItem>();
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection);
            DSTableAdapters.InvestorGroupConfigTableAdapter adap = new DSTableAdapters.InvestorGroupConfigTableAdapter();
            DS.InvestorGroupConfigDataTable tbInvestorGroupConfig = new DS.InvestorGroupConfigDataTable();

            try
            {
                conn.Open();
                adap.Connection = conn;
                tbInvestorGroupConfig = adap.GetInvestorGroupConfigByInvestorGroupID(InvestorGroupID);

                if (tbInvestorGroupConfig != null)
                {
                    int count=tbInvestorGroupConfig.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Business.ParameterItem newParameterItem = new Business.ParameterItem();
                        newParameterItem.ParameterItemID = tbInvestorGroupConfig[i].InvestorGroupConfigID;
                        newParameterItem.SecondParameterID = tbInvestorGroupConfig[i].InvestorGroupID;
                        newParameterItem.Code = tbInvestorGroupConfig[i].Code;
                        newParameterItem.Name = tbInvestorGroupConfig[i].Name;
                        newParameterItem.BoolValue = tbInvestorGroupConfig[i].BoolValue;
                        newParameterItem.StringValue = tbInvestorGroupConfig[i].StringValue;
                        newParameterItem.NumValue = tbInvestorGroupConfig[i].NumValue;
                        newParameterItem.DateValue = tbInvestorGroupConfig[i].DateValue;

                        newParameterItem.CollectionValue = this.GetInvestorGroupConfigByCollectionValue(tbInvestorGroupConfig[i].InvestorGroupConfigID);

                        Result.Add(newParameterItem);
                    }
                }
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                adap.Connection.Close();
                conn.Close();
            }

            return Result;
        }
        /// <summary>
        /// delete InvestorGroupConfig by investorGroupID
        /// </summary>
        /// <param name="id"></param>
        /// <param name="connection">opened sqlconnection</param>
        /// <returns></returns>
        internal bool DFDeleteByGroupID(int id,SqlConnection connection,SqlTransaction trans)
        {
            DSTableAdapters.InvestorGroupConfigTableAdapter adap = new DSTableAdapters.InvestorGroupConfigTableAdapter();
            adap.Connection = connection;
            adap.Transaction = trans;
            adap.DeleteInvestorGroupConfigByInvestorGroupID(id);

            return true;
        }