public void UpdateDataPoints(EtyDataLogDPTrend sampleGrpEty, List <EtyDataLogDPTrend> selectedDataPoints)
        {
            SimpleDatabase.GetInstance().BeginTransaction();
            bool bResult = UpdateOPCDataPointByGrpId(sampleGrpEty.Disabled, sampleGrpEty.OPCSampleGrpId);

            if (bResult)
            {
                for (int i = 0; i < selectedDataPoints.Count; i++)
                {
                    bResult = UpdateOPCDataPointByName(selectedDataPoints[i]);
                }
            }
            if (bResult)
            {
                bResult = DatalogConfigSettingsDAO.GetInstance().UpdateTrendVersionNum();
            }
            if (bResult)
            {
                SimpleDatabase.GetInstance().CommitTransaction();
            }
            else
            {
                SimpleDatabase.GetInstance().RollbackTransaction();
            }
            return;
        }
        public static void ReleaseInstance()
        {
            string Function_Name = "ReleaseInstance";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");
            if (m_instance != null)
            {
                m_instance = null;
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
        }
        public static DatalogConfigSettingsDAO GetInstance()
        {
            string Function_Name = "GetInstance";

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Entered");

            if (m_instance == null)
            {
                LogHelper.Debug(CLASS_NAME, Function_Name, "Creating static DatalogConfigSettings instance!");
                m_instance = new DatalogConfigSettingsDAO();
            }
            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(m_instance);
        }
        /// <summary>
        /// Delete  opc Sample Group by key
        /// </summary>
        /// <param name="opcGrpId">Sample group key</param>
        public bool DeleteOPCSampleGroupById(string opcGrpId)
        {
            string Function_Name = "DeleteOPCSampleGroupById";

            LogHelper.Trace(CLASS_NAME, Function_Name, string.Format("Function_Entered with params -  SampleGroup ID  = {0}", opcGrpId));
            bool result = true;

            SimpleDatabase.GetInstance().BeginTransaction();
            try
            {
                List <string> sqlStrings = new List <string>();
                for (int i = 0; i < 2; i++)
                {
                    string sql = "DELETE FROM DATALOG_DP_GROUP_TREND WHERE PKEY = " + opcGrpId;
                    sqlStrings.Add(sql);
                }
                List <SqlParameter> parameters = DAOHelper.CreateEnqueneParameters(sqlStrings);
                result = SimpleDatabase.GetInstance().ExecuteEnqueneProcedure(parameters);
            }
            catch (Exception localException)
            {
                LogHelper.Error(CLASS_NAME, Function_Name, localException.ToString());
            }
            if (result)
            {
                //update datapoint table also.
                result = DatalogDPTrendDAO.GetInstance().DisableGrpDataPoint(Convert.ToDouble(opcGrpId));
            }
            if (result)
            {
                result = DatalogConfigSettingsDAO.GetInstance().UpdateTrendVersionNum();
            }
            if (!result)
            {
                SimpleDatabase.GetInstance().RollbackTransaction();
            }
            else
            {
                SimpleDatabase.GetInstance().CommitTransaction();
            }

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(result);
        }
        /// <summary>
        ///  Inserts new sample group into database
        /// </summary>
        /// <param name="etyOPCGrp">new sample group entity</param>
        public bool InsertOPCGrpData(EtyDataLogDPGroupTrend etyDPGroupTrend)
        {
            string Function_Name = "InsertOPCGrpData";

            LogHelper.Trace(CLASS_NAME, Function_Name, string.Format("Function_Entered with params -  SampleGroup Name  = {0}", etyDPGroupTrend.SampleGrpName));

            SimpleDatabase.GetInstance().BeginTransaction();

            // Get The max pkey from the database first and then insert the group with pkey value.
            // To avoid having incorrect pkey value between stations , hence avoid concurrency problem
            SqlStatements sqlQueries = new SqlStatements();

            sqlQueries.OracleSql = DAOHelper.ORACLE_SEQ_FUNC_SQL;
            sqlQueries.MySqlStr  = DAOHelper.MYSQL_SEQ_FUNC_SQL;
            System.Data.IDataReader drReader = SimpleDatabase.GetInstance().ExecuteQueryWithSqls(sqlQueries);
            double nextPkey = 1;

            if (drReader != null && drReader.Read())
            {
                if (drReader.FieldCount == 1)
                {
                    nextPkey = Convert.ToDouble(drReader[0]);
                }
            }
            if (drReader != null)
            {
                drReader.Close();
                drReader.Dispose();
            }
            //
            //
            string enabled   = DAOHelper.GetEnabledStr(DAOHelper.ChangeBoolToStr(etyDPGroupTrend.Disabled));
            string startTime = "";

            if (etyDPGroupTrend.StartTime.Length != 0)
            {
                startTime = DateTime.Parse(etyDPGroupTrend.StartTime).ToString("dd/MM/yyyy HH:mm:ss");
            }
            string sample_grp_name = DAOHelper.convertEscapeStringAndGB2312To8859P1(etyDPGroupTrend.SampleGrpName);

            List <string> sqlStrings = new List <string>();

            for (int i = 0; i < 2; i++)
            {
                string date_func   = (i == 0) ? DAOHelper.ORACLE_DATE_FUNCTION : DAOHelper.MYSQL_DATE_FUNCTION;
                string date_format = (i == 0) ? DAOHelper.ORACLE_DATE_FORMAT : DAOHelper.MYSQL_DATE_FORMAT;
                if (startTime.Trim().Length != 0)
                {
                    string sql = "INSERT INTO DATALOG_DP_GROUP_TREND "
                                 + " (PKEY,NAME,DESCRIPTION,SAMPLE_INTERVAL,START_TIME,DELTA_VALUE,ENABLED,INTERVAL_TYPE,LOCATION_KEY)"
                                 + " VALUES"
                                 + " (" + nextPkey + ",'" + sample_grp_name + "'"
                                 + ",'" + DAOHelper.convertEscapeStringAndGB2312To8859P1(etyDPGroupTrend.SampleGrpDescription) + "'"
                                 + "," + etyDPGroupTrend.Interval
                                 + "," + date_func + "('" + startTime + "','" + date_format
                                 + "')," + etyDPGroupTrend.DeltaValue
                                 + ",'" + enabled + "'"
                                 + ",'" + etyDPGroupTrend.IntervalType + "',"
                                 + LocationKeyHelper.GetInstance().LocationKey.ToString() + ")";
                    sqlStrings.Add(sql);
                }
                else
                {
                    string sql = "INSERT INTO DATALOG_DP_GROUP_TREND "
                                 + " (PKEY,NAME,DESCRIPTION,SAMPLE_INTERVAL,DELTA_VALUE,ENABLED,INTERVAL_TYPE,LOCATION_KEY)"
                                 + " VALUES"
                                 + " (" + nextPkey + ",'" + sample_grp_name + "'"
                                 + ",'" + DAOHelper.convertEscapeStringAndGB2312To8859P1(etyDPGroupTrend.SampleGrpDescription) + "'"
                                 + "," + etyDPGroupTrend.Interval
                                 + "," + etyDPGroupTrend.DeltaValue
                                 + ",'" + enabled + "'"
                                 + ",'" + etyDPGroupTrend.IntervalType + "',"
                                 + LocationKeyHelper.GetInstance().LocationKey.ToString() + ")";
                    sqlStrings.Add(sql);
                }
            }

            List <SqlParameter> parameters = DAOHelper.CreateEnqueneParameters(sqlStrings);
            bool rRes = true;

            rRes = SimpleDatabase.GetInstance().ExecuteEnqueneProcedure(parameters);

            if (rRes)
            {
                rRes = DatalogConfigSettingsDAO.GetInstance().UpdateTrendVersionNum();
            }
            if (!rRes)
            {
                SimpleDatabase.GetInstance().RollbackTransaction();
            }
            else
            {
                SimpleDatabase.GetInstance().CommitTransaction();
            }

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(rRes);
        }
        /// <summary>
        /// Updates the given sample group entity.
        /// </summary>
        /// <param name="etyDPGroupTrend">sample group entity</param>
        public bool UpdateOPCGrpData(EtyDataLogDPGroupTrend etyDPGroupTrend)
        {
            string Function_Name = "UpdateOPCGrpData";

            LogHelper.Trace(CLASS_NAME, Function_Name, string.Format("Function_Entered with params - SampleGroup Name = {0}", etyDPGroupTrend.SampleGrpName));

            SimpleDatabase.GetInstance().BeginTransaction();

            string enabled = DAOHelper.GetEnabledStr(DAOHelper.ChangeBoolToStr(etyDPGroupTrend.Disabled));

            string startTime = "";

            if (etyDPGroupTrend.StartTime.Length != 0)
            {
                startTime = DateTime.Parse(etyDPGroupTrend.StartTime).ToString("dd/MM/yyyy HH:mm:ss");
            }
            string sample_grp_name = DAOHelper.convertEscapeStringAndGB2312To8859P1(etyDPGroupTrend.SampleGrpName);

            List <string> sqlStrings = new List <string>();

            for (int i = 0; i < 2; i++)
            {
                string date_func   = (i == 0)?DAOHelper.ORACLE_DATE_FUNCTION :DAOHelper.MYSQL_DATE_FUNCTION;
                string date_format = (i == 0)?DAOHelper.ORACLE_DATE_FORMAT :DAOHelper.MYSQL_DATE_FORMAT;
                if (startTime.Trim().Length != 0)
                {
                    string sql = " UPDATE DATALOG_DP_GROUP_TREND "
                                 + " SET DESCRIPTION = '" + DAOHelper.convertEscapeStringAndGB2312To8859P1(etyDPGroupTrend.SampleGrpDescription) + "'"
                                 + ",SAMPLE_INTERVAL = " + etyDPGroupTrend.Interval
                                 + ",INTERVAL_TYPE = '" + etyDPGroupTrend.IntervalType + "'"
                                 + ",START_TIME = " + date_func
                                 + "('" + startTime + "','" + date_format
                                 + "') ,DELTA_VALUE = " + etyDPGroupTrend.DeltaValue
                                 + ",ENABLED = '" + enabled + "'"
                                 + " WHERE NAME = '" + sample_grp_name + "' AND LOCATION_KEY = "
                                 + etyDPGroupTrend.LocationKey.ToString();
                    sqlStrings.Add(sql);
                }
                else
                {
                    string sql = " UPDATE DATALOG_DP_GROUP_TREND "
                                 + " SET DESCRIPTION = '" + DAOHelper.convertEscapeStringAndGB2312To8859P1(etyDPGroupTrend.SampleGrpDescription) + "'"
                                 + ",SAMPLE_INTERVAL = " + etyDPGroupTrend.Interval
                                 + ",INTERVAL_TYPE = '" + etyDPGroupTrend.IntervalType + "'"
                                 + ",START_TIME = null, DELTA_VALUE = " + etyDPGroupTrend.DeltaValue
                                 + ",ENABLED = '" + enabled + "'"
                                 + " WHERE NAME = '" + sample_grp_name + "' AND LOCATION_KEY = "
                                 + etyDPGroupTrend.LocationKey.ToString();
                    sqlStrings.Add(sql);
                }
            }
            List <SqlParameter> parameters = DAOHelper.CreateEnqueneParameters(sqlStrings);
            bool rRes = true;

            rRes = SimpleDatabase.GetInstance().ExecuteEnqueneProcedure(parameters);

            if (rRes)
            {
                rRes = DatalogConfigSettingsDAO.GetInstance().UpdateTrendVersionNum();
            }
            if (!rRes)
            {
                SimpleDatabase.GetInstance().RollbackTransaction();
            }
            else
            {
                SimpleDatabase.GetInstance().CommitTransaction();
            }

            LogHelper.Trace(CLASS_NAME, Function_Name, "Function_Exited");
            return(rRes);
        }