Ejemplo n.º 1
0
        public static System.Data.Common.DbCommand LastDailyEntityCommand(string code, DatabaseAccessor accessor)
        {
            if (!IsValidCode(code, CODETYPE.stock) || accessor == null)
            {
                return(null);
            }

            var entity     = new DBTStkDailyEntity();
            var parameters = new List <System.Data.Common.DbParameter>();

            var where = new System.Text.StringBuilder();
            where.AppendLine("WHERE");

            // param:code
            var parm_code = accessor.CreateParameter("Code", code);

            parameters.Add(parm_code);
            where.AppendLine(string.Format("Code = {0}", parm_code.ParameterName));

            where.AppendLine("AND");
            where.AppendLine(string.Format("Date in (SELECT MAX(Date) from {0})", entity.TableName));

            var sql = new System.Text.StringBuilder();

            sql.AppendLine(entity.SQLTableSelect);
            sql.AppendLine(where.ToString());

            return(accessor.CreateCommand(sql.ToString(), parameters));
        }
Ejemplo n.º 2
0
        private static bool CreateTables(DatabaseAccessor accessor, out string message)
        {
            var lsb_messager = new StringBuilder();
            int li_errcnt    = 0;

            // Create Table:STK_FAVORITE_M
            try
            {
                if (!accessor.TableExists(TABLES.STK_FAVORITE_M.ToString()))
                {
                    var script = Config.Instance.INFO.ScriptSetting.Scripts.ContainsKey(TABLES.STK_FAVORITE_M.ToString()) ? Config.Instance.INFO.ScriptSetting.Scripts[TABLES.STK_FAVORITE_M.ToString()] : null;
                    accessor.ExecuteSQLCommand(accessor.CreateCommand(script, null));
                }
            }
            catch (Exception err)
            {
                li_errcnt++;
                lsb_messager.AppendLine(string.Format("{0}.Table({1}) creating failed.", li_errcnt, TABLES.STK_FAVORITE_M.ToString()));
                lsb_messager.AppendLine(err.ToString());
            }

            // Create Table:IDX_GENERAL_M
            try
            {
                if (!accessor.TableExists(TABLES.IDX_GENERAL_M.ToString()))
                {
                    var script = Config.Instance.INFO.ScriptSetting.Scripts.ContainsKey(TABLES.IDX_GENERAL_M.ToString()) ? Config.Instance.INFO.ScriptSetting.Scripts[TABLES.IDX_GENERAL_M.ToString()] : null;
                    accessor.ExecuteSQLCommand(accessor.CreateCommand(script, null));
                }
            }
            catch (Exception err)
            {
                li_errcnt++;
                lsb_messager.AppendLine(string.Format("{0}.Table({1}) creating failed.", li_errcnt, TABLES.IDX_GENERAL_M.ToString()));
                lsb_messager.AppendLine(err.ToString());
            }

            // Create Table:STK_GENERAL_M
            try
            {
                if (!accessor.TableExists(TABLES.STK_GENERAL_M.ToString()))
                {
                    var script = Config.Instance.INFO.ScriptSetting.Scripts.ContainsKey(TABLES.STK_GENERAL_M.ToString()) ? Config.Instance.INFO.ScriptSetting.Scripts[TABLES.STK_GENERAL_M.ToString()] : null;
                    accessor.ExecuteSQLCommand(accessor.CreateCommand(script, null));
                }
            }
            catch (Exception err)
            {
                li_errcnt++;
                lsb_messager.AppendLine(string.Format("{0}.Table({1}) creating failed.", li_errcnt, TABLES.STK_GENERAL_M.ToString()));
                lsb_messager.AppendLine(err.ToString());
            }

            // Create Table:STK_DAILY_TD
            try
            {
                if (!accessor.TableExists(TABLES.STK_DAILY_TD.ToString()))
                {
                    var script = Config.Instance.INFO.ScriptSetting.Scripts.ContainsKey(TABLES.STK_DAILY_TD.ToString()) ? Config.Instance.INFO.ScriptSetting.Scripts[TABLES.STK_DAILY_TD.ToString()] : null;
                    accessor.ExecuteSQLCommand(accessor.CreateCommand(script, null));
                }
            }
            catch (Exception err)
            {
                li_errcnt++;
                lsb_messager.AppendLine(string.Format("{0}.Table({1}) creating failed.", li_errcnt, TABLES.STK_DAILY_TD.ToString()));
                lsb_messager.AppendLine(err.ToString());
            }

            // Create Table:STK_MACD_TD
            try
            {
                if (!accessor.TableExists(TABLES.STK_MACD_TD.ToString()))
                {
                    var script = Config.Instance.INFO.ScriptSetting.Scripts.ContainsKey(TABLES.STK_MACD_TD.ToString()) ? Config.Instance.INFO.ScriptSetting.Scripts[TABLES.STK_MACD_TD.ToString()] : null;
                    accessor.ExecuteSQLCommand(accessor.CreateCommand(script, null));
                }
            }
            catch (Exception err)
            {
                li_errcnt++;
                lsb_messager.AppendLine(string.Format("{0}.Table({1}) creating failed.", li_errcnt, TABLES.STK_MACD_TD.ToString()));
                lsb_messager.AppendLine(err.ToString());
            }

            // Create Table:STK_RSI_TD
            try
            {
                if (!accessor.TableExists(TABLES.STK_RSI_TD.ToString()))
                {
                    var script = Config.Instance.INFO.ScriptSetting.Scripts.ContainsKey(TABLES.STK_RSI_TD.ToString()) ? Config.Instance.INFO.ScriptSetting.Scripts[TABLES.STK_RSI_TD.ToString()] : null;
                    accessor.ExecuteSQLCommand(accessor.CreateCommand(script, null));
                }
            }
            catch (Exception err)
            {
                li_errcnt++;
                lsb_messager.AppendLine(string.Format("{0}.Table({1}) creating failed.", li_errcnt, TABLES.STK_RSI_TD.ToString()));
                lsb_messager.AppendLine(err.ToString());
            }

            message = lsb_messager.ToString();
            return(li_errcnt <= 0);
        }