public void Submit()
        {
            if (string.IsNullOrEmpty(id) || price * count == 0)
            {
                Debug.Log("输入不正确"); return;
            }

            ReadDbStockS();
            sumCB = UpdateSumCB();
            StockDb submitSotck = new StockDb();

            submitSotck.id = id;
            StockDb stock库里已存在的 = stockS.FirstOrDefault(s => s.id == submitSotck.id);

            if (stock库里已存在的 == null)
            {
                InsertData(submitSotck);
            }
            else
            {
                UpdateData();
            }
            id    = "";
            price = 0;
            count = 0;
        }
        public static List <StockDb> GetStockCCS(DataTable dt)
        {
            List <StockDb> res = new List <StockDb>();

            foreach (DataRow item in dt.Rows)
            {
                StockDb stock = StockMgr.SwitchToStockCC(item);
                res.Add(stock);
            }
            return(res);
        }
        public static StockDb SwitchToStockCC(DataRow row)
        {
            StockDb res = new StockDb();

            res.id      = row[0].ToString();
            res.name    = row[1].ToString();
            res.cbPrice = float.Parse(row[2].ToString());
            res.count   = int.Parse(row[3].ToString());
            res.cb      = float.Parse(row[4].ToString());
            res.cbK     = float.Parse(row[5].ToString());
            res.ratio   = float.Parse(row[6].ToString());
            res.plate   = int.Parse(row[7].ToString());
            return(res);
        }
        void InsertData(StockDb stock)
        {
            StockTx stockWeb = U_Stock.GetStock(id.ToString());

            if (stockWeb == null)
            {
                Debug.Log("查不到该编号");
                return;
            }
            if (count < 0)
            {
                Debug.Log("并没有持有,无法为负数");
                return;
            }
            stock.cbPrice = price;
            stock.name    = stockWeb.name;
            stock.count   = count;
            stock.cb      = count * price;
            stock.cbK     = stock.cb / 1000f;
            sumCB        += stock.cb;
            stock.ratio   = stock.cb / sumCB * 100;
            stockS.Add(stock);
            OpenSql();
            sql.Insert(
                holdStocks,
                new string[] { "id", "name", "cbPrice", "count", "cb", "cbK", "ratio" },
                new string[] {
                stock.id.ToString(),
                stock.name,
                stock.cbPrice.ToStringF3(),
                stock.count.ToString(),
                stock.cb.ToStringF2(),
                stock.cbK.ToStringF2(),
                stock.ratio.ToStringF2()
            }
                );
            UpdateEveryRatio();
            CloseSql();
            Debug.Log("买入:" + stock.name + "\tprice" + price + "\tcount" + count);
        }
        void UpdateData()
        {
            OpenSql();
            StockDb ori = stockS.FirstOrDefault(s => s.id == id);

            if (count < 0 && count < -ori.count)
            {
                Debug.LogError("没有这么多持仓");
                return;
            }
            float byMoeny = count * price;

            sumCB += byMoeny;
            int    newCount   = ori.count + count;
            float  newCb      = ori.cb + byMoeny;
            float  newCbPrice = newCb / newCount;
            float  newCbK     = newCb / 1000;
            float  newRatio   = newCb / sumCB;
            string debugStr   = "";

            ori.count   = newCount;
            ori.cb      = newCb;
            ori.cbPrice = newCbPrice;
            ori.cbK     = newCbK;

            if (newCount == 0)
            {
                sql.Delete(holdStocks, "id", id);
                //sql.Delete();
                stockS.Remove(ori);
                debugStr = "清仓";
            }
            else
            {
                //sqlite
                sql.Update(
                    holdStocks,
                    new string[] { "cbPrice", "count", "cb", "cbK", "ratio" },
                    new string[] { newCbPrice.ToString(), newCount.ToString(), newCb.ToString(), newCbK.ToString(), newRatio.ToString() },
                    "id", id.ToString()
                    );
                //mysql
                //sql.Update(
                //   holdStocks,
                //  new string[] { "cbPrice", "count", "cb", "cbK", "ratio" },
                //  new string[] { newCbPrice.ToString(), newCount.ToString(), newCb.ToString(), newCbK.ToString(), newRatio.ToString() },
                //  "id", id.ToString()
                //  );
            }
            if (count > 0)
            {
                debugStr = "买入";
            }
            else if (count < 0)
            {
                if (newCount != 0)
                {
                    debugStr = "卖出";
                }
            }
            Debug.Log(debugStr + ori.name + "\tprice" + price + "\tcount" + count);
            UpdateEveryRatio();
            CloseSql();
        }