コード例 #1
0
        //2018-03-18 保存至数据库
        public static void SaveToDB_Analysis2(System.Collections.ArrayList list)
        {
            string sql;

            sql = "truncate table Ope_Analysis2;";
            db.RunSql(sql);

            System.Collections.ArrayList sqllist = new System.Collections.ArrayList();
            SQLMassImport rulefile = new SQLMassImport("Analysis2SQL");

            for (int i = 0; i < list.Count; i++)
            {
                StockOpeItem item      = (StockOpeItem)list[i];
                string[]     attristrs = new string[11];
                attristrs[0]  = item.type.ToString();
                attristrs[1]  = item.stockcode;
                attristrs[2]  = item.buyrule;
                attristrs[3]  = item.sellrule.ToString();
                attristrs[4]  = item.buydate.ToString();
                attristrs[5]  = item.buyindex.ToString();
                attristrs[6]  = item.buyprice.ToString();
                attristrs[7]  = item.grade.ToString();
                attristrs[8]  = item.selldate.ToString();
                attristrs[9]  = item.sellindex.ToString();
                attristrs[10] = item.sellprice.ToString();
                rulefile.AddRow(attristrs);
            }
            rulefile.ImportClose(db, StockSQL.TABLE_ANALYZE2);
        }
コード例 #2
0
        //更新Stock数据
        public static void InsertStockWithItem(StockData stock)
        {
            int    size = stock.items.Length;
            string code = stock.code;

            StockItem[]   items     = stock.items;
            SQLMassImport itemfile  = new SQLMassImport("Item");
            SQLMassImport attrifile = new SQLMassImport("Attribute");
            SQLMassImport kpifile   = new SQLMassImport("KPI");


            StockItem lastitem = stock.items[stock.items.Length - 1];
            string    sql      = "insert into stock_header(code, name, lastindex, lastprice) values('";

            sql += stock.code + "','" + stock.name + "','" + lastitem.index;
            sql += "', '" + lastitem.end + "');";
            db.RunSql(sql);

            for (int i = 0; i < size; i++)
            {
                StockItem item     = items[i];
                string[]  filestrs = new string[8];
                filestrs[0] = code;
                filestrs[1] = i.ToString();
                filestrs[2] = item.date.ToString();
                filestrs[3] = item.start.ToString();
                filestrs[4] = item.high.ToString();
                filestrs[5] = item.low.ToString();
                filestrs[6] = item.end.ToString();
                filestrs[7] = item.volume.ToString();
                itemfile.AddRow(filestrs);

                foreach (object key in items[i].attributes.Keys)
                {
                    string[] attristrs = new string[4];
                    attristrs[0] = code;
                    attristrs[1] = i.ToString();
                    attristrs[2] = key.ToString();
                    attristrs[3] = items[i].attributes[key].ToString();
                    attrifile.AddRow(attristrs);
                }

                foreach (object key in items[i].kpi.Keys)
                {
                    string[] attristrs = new string[5];
                    attristrs[0] = code;
                    attristrs[1] = i.ToString();
                    attristrs[2] = item.date.ToString();
                    attristrs[3] = key.ToString();
                    attristrs[4] = items[i].kpi[key].ToString();
                    kpifile.AddRow(attristrs);
                }
            }
            itemfile.ImportClose(db, TABLE_STOCK_ITEM);
            attrifile.ImportClose(db, TABLE_STOCK_ATTRI);
            kpifile.ImportClose(db, TABLE_STOCK_KPI);
        }
コード例 #3
0
ファイル: StockSimulateSQL.cs プロジェクト: pippolei/NewStock
        //保存至数据库
        public static void SaveToDB(int type, int startdate, int enddate, string buyrule, string sellrule, System.Collections.ArrayList list)
        {
            ClearDB(type, startdate, enddate, buyrule, sellrule);

            string sql = "insert into Ope_Simulate values(" + type + ",'" + startdate + "','" + enddate + "','" + buyrule + "','" + sellrule + "');";

            db.RunSql(sql);
            int maxid = db.GetMaxTableId("Ope_Simulate");

            //有可能是上次没删干净的记录
            sql = "delete from Ope_Simulate_Item where id = '" + maxid.ToString() + "';";
            db.RunSql(sql);
            System.Collections.ArrayList sqllist = new System.Collections.ArrayList();


            SQLMassImport rulefile = new SQLMassImport("Simulate");

            for (int i = 0; i < list.Count; i++)
            {
                StockSimulateItem item = (StockSimulateItem)list[i];
                string[]          strs = new string[18];
                strs[0]  = maxid.ToString();
                strs[1]  = item.type.ToString();
                strs[2]  = item.buyrule;
                strs[3]  = item.sellrule;
                strs[4]  = item.stockcode;
                strs[5]  = item.buydate.ToString();
                strs[6]  = item.buyindex.ToString();
                strs[7]  = item.buyprice.ToString();
                strs[8]  = item.selldate.ToString();
                strs[9]  = item.sellindex.ToString();
                strs[10] = item.sellprice.ToString();
                strs[11] = item.buyvolume.ToString();
                strs[12] = item.stockvalue.ToString();
                strs[13] = item.winvalue.ToString();
                strs[14] = item.holdstocknum.ToString();
                strs[15] = item.totalstockvalue.ToString();
                strs[16] = item.leftmoney.ToString();
                strs[17] = item.totalamount.ToString();
                rulefile.AddRow(strs);
            }

            rulefile.ImportClose(db, StockSQL.TABLE_SIMULATE_ITEM);
        }
コード例 #4
0
ファイル: StockDapan.cs プロジェクト: pippolei/NewStock
        //更新大盘分数
        private static void UpdateDaPan()
        {
            SQLMassImport itemfile = new SQLMassImport("Overall");

            //从数据库读入基本大盘数据
            string sql = "select * from [stock_DaPan] order by seq";

            System.Data.DataTable table = db.GetTable(sql);
            int size = table.Rows.Count;

            DaPanItem[] dapan_items = new DaPanItem[size];

            //初始化overallitem
            for (int i = 0; i < size; i++)
            {
                DataRow   row  = table.Rows[i];
                DaPanItem item = new DaPanItem();
                item.seq      = Convert.ToInt32(row["seq"]);
                item.grade    = STATUS_NEUTRAL;
                item.num_rize = Convert.ToInt32(row["num_rize"]);
                item.num_down = Convert.ToInt32(row["num_down"]);
                item.avg1     = 0;
                item.avg2     = 0;
                item.avg3     = 0;
                item.avg4     = 0;
                item.avg5     = 0;

                item.date = Convert.ToInt32(row["date"]);
                item.rize = Convert.ToDouble(row["RIZE"]) + 1000 * StockApp.MIN_ZERO; //防止为0

                dapan_items[i] = item;
            }
            //计算平均值
            double[] avg1 = InitAverage(dapan_items, 5);
            double[] avg2 = InitAverage(dapan_items, 10);
            double[] avg3 = InitAverage(dapan_items, 30);
            double[] avg4 = InitAverage(dapan_items, 60);
            double[] avg5 = InitAverage(dapan_items, 100);
            for (int i = 0; i < size; i++)
            {
                DaPanItem item = dapan_items[i];
                item.avg1 = avg1[i];
                item.avg2 = avg2[i];
                item.avg3 = avg3[i];
                item.avg4 = avg4[i];
                item.avg5 = avg5[i];
            }
            //grade默认为NEUTRAL,此处许需要更新

            /*string[] grade = new string[]{STATUS_NEUTRAL};
             * for (int i = 0; i < size; i++)
             * {
             *  DaPanItem item = dapan_items[i];
             *  item.grade = grade[i];
             * }*/

            //准备导入数据
            for (int i = 0; i < size; i++)
            {
                string[]  filestrs = new string[11];
                DaPanItem item     = dapan_items[i];
                filestrs[0]  = item.seq.ToString();
                filestrs[1]  = item.date.ToString();
                filestrs[2]  = item.rize.ToString(); //每日的涨幅
                filestrs[3]  = item.num_rize.ToString();
                filestrs[4]  = item.num_down.ToString();
                filestrs[5]  = Math.Round(item.avg1, 8).ToString();
                filestrs[6]  = Math.Round(item.avg2, 8).ToString();
                filestrs[7]  = Math.Round(item.avg3, 8).ToString();
                filestrs[8]  = Math.Round(item.avg4, 8).ToString();
                filestrs[9]  = Math.Round(item.avg5, 8).ToString();
                filestrs[10] = item.grade.ToString();
                itemfile.AddRow(filestrs);
            }
            sql = "truncate table stock_DaPan;";
            db.RunSql(sql);
            itemfile.ImportClose(db, "stock_DaPan");
        }