Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }
            Console.Title = "正在读取数据,请不要手工关闭...";
            string sepChar = ",";

            if (args[0].ToLower() == "getdata" && args.Length >= 3)
            {
                string dataType, code, newFileName;
                dataType    = args[1];
                code        = args[2];
                newFileName = "";
                if (args.Length == 4)
                {
                    newFileName = args[3];
                }
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetData(dataType, code, newFileName, 0);
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1)
                            {
                                Console.Write(sepChar);
                            }
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "getfields")
            {
                string dataType;
                dataType = args[1];
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetFields(dataType);
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1)
                            {
                                Console.Write(sepChar);
                            }
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "gettabledef")
            {
                if (args.Length >= 3)
                {
                    string dataType, descDataType;
                    dataType     = args[1];
                    descDataType = args[2];
                    FinData.FxjData fxj = new FinData.FxjData();
                    if (fxj.Error == 0)
                    {
                        string x = fxj.GetTableDef(dataType, descDataType, false);
                        Console.WriteLine(x);
                    }
                }
            }
            else if (args[0].ToLower() == "gettables")
            {
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetTables();
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1)
                            {
                                Console.Write(sepChar);
                            }
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "getmarkets")
            {
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetMarkets();
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1)
                            {
                                Console.Write(sepChar);
                            }
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "getcodetype")
            {
                if (args.Length >= 2)
                {
                    string code;
                    code = args[1];
                    FinData.FxjData fxj = new FinData.FxjData();
                    if (fxj.Error == 0)
                    {
                        string x = fxj.GetCodeType(code);
                        Console.WriteLine(x);
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length < 1) return;
            Console.Title = "���ڶ�ȡ���ݣ��벻Ҫ�ֹ��ر�...";
            string sepChar = ",";
            if (args[0].ToLower() == "getdata" && args.Length>=3)
            {
                string dataType,code,newFileName;
                dataType=args[1];
                code = args[2];
                newFileName = "";
                if (args.Length == 4) newFileName = args[3];
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetData(dataType, code, newFileName,0);
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1) Console.Write(sepChar);
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "getfields")
            {
                string dataType;
                dataType = args[1];
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetFields(dataType);
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1) Console.Write(sepChar);
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "gettabledef")
            {

                if (args.Length >= 3)
                {
                    string dataType, descDataType;
                    dataType = args[1];
                    descDataType = args[2];
                    FinData.FxjData fxj = new FinData.FxjData();
                    if (fxj.Error == 0)
                    {
                        string x = fxj.GetTableDef(dataType, descDataType, false);
                        Console.WriteLine(x);
                    }
                }
            }
            else if (args[0].ToLower() == "gettables")
            {
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetTables();
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1) Console.Write(sepChar);
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "getmarkets")
            {
                FinData.FxjData fxj = new FinData.FxjData();
                string[,] x = fxj.GetMarkets();
                if (fxj.Error == 0)
                {
                    for (int ii = 0; ii < x.GetLength(0); ii++)
                    {
                        for (int jj = 0; jj < x.GetLength(1); jj++)
                        {
                            Console.Write(x[ii, jj]);
                            if (jj < x.GetLength(1) - 1) Console.Write(sepChar);
                        }
                        Console.WriteLine();
                    }
                }
            }
            else if (args[0].ToLower() == "getcodetype")
            {
                if (args.Length >= 2)
                {
                    string code;
                    code = args[1];
                    FinData.FxjData fxj = new FinData.FxjData();
                    if (fxj.Error == 0)
                    {
                        string x = fxj.GetCodeType(code);
                        Console.WriteLine(x);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private int InsertStockDataToSQLDb(string dataType, string CodeStr, string[,] CodeList, int iRecordCount)
        {


            //cmd.ExecuteNonQuery();
            string[,] dataArray;
            string SqlStr = string.Empty;
            FinData.FxjData fxj = new FinData.FxjData();

            if (CodeStr != "")
            {
                CodeList[0, 0] = CodeStr;
            }
            
            try
            {
                for (int j=0;j < CodeList.GetLength(1);j++)
                {
                    dataArray = fxj.GetData(dataType, CodeList[0,j],iRecordCount);

                    if (fxj.Error == 0 && dataArray.GetLength(0) > 0)
                    {
                        string[,] colname = fxj.GetFields(dataType);
                        try
                        {
                            SqlConnection con = new SqlConnection(ConStr);
                            con.Open();

                            //删除临时表中的原来记录
                            SqlStr = "Delete T_PRP_StockDataTemp From T_PRP_StockdataTemp";
                            SqlCommand cmd = new SqlCommand(SqlStr, con);
                            cmd.ExecuteNonQuery();

                            //向临时表添加数据
                            for (int i = 0; i < dataArray.GetLength(0); i++)
                            {
                                SqlStr = "Insert Into T_PRP_StockDataTemp(FCode,FDateTime,FOpen,FHigh,FLow,FClose,FVolume,FAmount) values('" +
                                dataArray[i, 0] + "','" + dataArray[i, 1] + "','" + dataArray[i, 2] + "','" + dataArray[i, 3] + "','"
                                + dataArray[i, 4] + "','" + dataArray[i, 5] + "','" + dataArray[i, 6] + "','" + dataArray[i, 7] + "')";
                                cmd.CommandText = SqlStr;
                                cmd.ExecuteNonQuery();
                            }

                            //从临时表向正式表添加不重复的记录
                            SqlStr = "Insert Into T_PRP_StockData(FCode,FDateTime,FOpen,FHigh,FLow,FClose,FVolume,FAmount)" +
                            "Select Distinct FCode,FDateTime,FOpen,FHigh,FLow,FClose,FVolume,FAmount From T_PRP_StockDataTemp " +
                            "Where  not exists(Select * From T_PRP_StockData Where (FDateTime=T_PRP_StockDataTemp.FDateTime And FCode=T_PRP_StockDataTemp.FCode))";
                            cmd.CommandText = SqlStr;
                            cmd.ExecuteNonQuery();

                            if (CodeStr != "")
                            {
                                con.Close();
                                return 0;
                            }


                        }
                        catch
                        {
                            //向SQl Server数据库添加数据失败!
                            MessageBox.Show("向SQl Server数据库添加数据失败!"); 
                            return 1;
                        }

                    }
                    else
                    {
                        //没有数据或发生错误 
                        //return 2;
                    }
                }
                }


            catch //(Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return 3;
            }

            return 0;
        }