Exemple #1
0
        //交易账号登陆
        public WindData tlogon(string brokerID, string departmentID, string accountID, string password, string accountType, string options = "", TradeCallback callback = null)
        {
            checkConnection();
            object ofields, odata;
            int    errCode;

            if (callback != null)
            {
                options += ";PushCallBack=A";
                lock (TradeCallbackList)
                {
                    TradeCallbackList[0] = callback;
                }
            }
            odata = wdc.tLogon(brokerID, departmentID, accountID, password, accountType, options, out ofields, out errCode);

            WindData retData = formatWD(null, ofields, null, odata, errCode);

            if (callback != null && retData.errorCode == 0)
            {
                lock (TradeCallbackList)
                {
                    TradeCallbackList.Remove(0);
                    string strLongId = retData.GetLogonId();
                    ulong  LogonID   = 0;
                    if ((!string.IsNullOrEmpty(strLongId)) && (LogonID = Convert.ToUInt32(strLongId)) != 0)
                    {
                        TradeCallbackList[LogonID] = callback;
                    }
                }
            }

            return(retData);
        }
Exemple #2
0
        //统一处理返回值
        private WindData formatWD(object ocodes, object ofields, object otimes, object odata, int errorCode)
        {
            WindData wd = new WindData();

            wd.errorCode = errorCode;
            if (ocodes == null && ofields == null && otimes == null)
            {
                return(wd);
            }
            if (ocodes != null)
            {
                wd.codeList = (string[])ocodes;
            }
            if (ofields != null)
            {
                wd.fieldList = (string[])ofields;
            }
            if (otimes != null)
            {
                double[] tmpTimes = (double[])otimes;
                int      length   = tmpTimes.Length;
                wd.timeList = new DateTime[length];
                for (int i = 0; i < length; i++)
                {
                    wd.timeList[i] = DateTime.FromOADate(tmpTimes[i]).AddYears(-1900);
                }
            }
            wd.data = odata;
            return(wd);
        }
Exemple #3
0
        private static string GetDataByFiledName(WindData wd, string strFiledName)
        {
            if (null == wd)
            {
                return(string.Empty);
            }
            if (wd.errorCode != 0)
            {
                return(string.Empty);
            }
            if (null == wd.fieldList || null == wd.data || !(wd.data is object[, ]))
            {
                return(string.Empty);
            }
            int nFieldIndex = -1;

            for (int i = 0; i < wd.fieldList.Length; i++)
            {
                if (0 == string.Compare(wd.fieldList[i], strFiledName, true))
                {
                    nFieldIndex = i;
                    break;
                }
            }

            if (-1 == nFieldIndex)
            {
                return(string.Empty);
            }

            object[,] obj = (object[, ])wd.data;

            return(obj[nFieldIndex, 0].ToString());
        }
Exemple #4
0
 private void ReqHandler(int state, ulong rid, int err)
 {
     if (ReqList.ContainsKey(rid))
     {
         WSQReq wr = ReqList[rid];
         if (state == 1 && err == 0)
         {
             int    reqState, errCode;
             object ocodes, ofields, otimes, odata;
             odata = wdc.readdata(rid, out ocodes, out ofields, out otimes, out reqState, out errCode);
             if (wr.updateAll)
             {
                 wr.callback(updataReqData(wr.rdata, ocodes, ofields, odata));
             }
             else
             {
                 wr.callback(formatWD(ocodes, ofields, otimes, odata, errCode));
             }
         }
         else if (err != 0)
         {
             WindData wd = new WindData();
             wd.errorCode = err;
             wd.fieldList = new String[] { "ErrorMessage" };
             wd.data      = new String[] { getErrorMsg(err) };
             wr.callback(wd);
         }
     }
     return;
 }
Exemple #5
0
        private WindData setData(WindData rd, object odata, int codeIndex, int fieldIndex, int dataIndex)
        {
            object tmpdata = rd.data;

            if (codeIndex >= rd.codeList.Length || fieldIndex >= rd.fieldList.Length)
            {
                throw new Exception("数组越界");
            }
            if (rd.data is double[])
            {
                ((double[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((double[])odata)[dataIndex];
            }
            else if (rd.data is int[])
            {
                ((int[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((int[])odata)[dataIndex];
            }
            else if (rd.data is String[])
            {
                ((String[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((String[])odata)[dataIndex];
            }
            else if (rd.data is DateTime[])
            {
                ((DateTime[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((DateTime[])odata)[dataIndex];
            }
            else if (rd.data is Int64[])
            {
                ((Int64[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((Int64[])odata)[dataIndex];
            }
            else if (rd.data is object[])
            {
                ((object[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((object[])odata)[dataIndex];
            }
            rd.data = tmpdata;
            return(rd);
        }
Exemple #6
0
        public void myCallback(WindData wd)
        {
            //用户代码区域
            //订阅返回数据存放在WindData参数wd中,可以对其进行分析操作

            string s = WindDataMethod.WindDataToString(wd, "wsq");
            DisplayWindData(new ShowWindData(ShowInRichText), s);
        }
Exemple #7
0
 public void myCallback(WindData wd)
 {
     wsqData = wd;
     //System.Console.WriteLine(((double[])wd.data)[0]);
     sd = new SetDelegate(SetCb);
     this.cbRequest.Invoke(sd);
     this.cbFuncList.Invoke(sd);
     this.dataGridView1.Invoke(sd);
 }
Exemple #8
0
 private int getCodeIndex(WindData rd, string codeName)
 {
     if (rd != null)
     {
         string[] clist  = rd.codeList;
         int      length = clist.Length;
         for (int i = 0; i < length; i++)
         {
             if (codeName == clist[i])
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Exemple #9
0
 private int getFieldIndex(WindData rd, string fieldName)
 {
     if (rd != null)
     {
         string[] flist  = rd.fieldList;
         int      length = flist.Length;
         for (int i = 0; i < length; i++)
         {
             if (fieldName == flist[i])
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Exemple #10
0
        private WindData updataReqData(WindData rd, object ocodes, object ofields, object odata)
        {
            if (null == rd.data && null == rd.codeList && null == rd.fieldList && null == rd.timeList)
            {
                rd = formatWD(ocodes, ofields, null, odata, 0);
                return(rd);
            }

            if (ocodes is string)
            {
                if (ofields is string)
                {
                    rd = setData(rd, odata, getCodeIndex(rd, (string)ocodes), getFieldIndex(rd, (string)ofields), 0);
                }
                else if (ofields is string[])
                {
                    string[] flist = (string[])ofields;
                    for (int i = 0; i < flist.Length; i++)
                    {
                        rd = setData(rd, odata, getCodeIndex(rd, (string)ocodes), getFieldIndex(rd, flist[i]), i);
                    }
                }
            }
            else if (ocodes is string[])
            {
                string[] clist = (string[])ocodes;
                for (int j = 0; j < clist.Length; j++)
                {
                    if (ofields is string)
                    {
                        rd = setData(rd, odata, getCodeIndex(rd, clist[j]), getFieldIndex(rd, (string)ofields), j);
                    }
                    else if (ofields is string[])
                    {
                        string[] flist = (string[])ofields;
                        for (int k = 0; k < flist.Length; k++)
                        {
                            rd = setData(rd, odata, getCodeIndex(rd, clist[j]), getFieldIndex(rd, flist[k]), j * flist.Length + k);
                        }
                    }
                }
            }
            return(rd);
        }
Exemple #11
0
        private string GetDataByFiledName(WindData wd, string strFiledName)
        {
            if (wd.errorCode != 0)
                return string.Empty;

            int nFieldIndex = -1;
            for (int i = 0; i < wd.fieldList.Length; i++)
            {
                if (0 == string.Compare(wd.fieldList[i], strFiledName, true))
                {
                    nFieldIndex = i;
                    break;
                }
            }

            if (-1 == nFieldIndex)
                return string.Empty;

            object[,] obj = (object[,])wd.data;
            return obj[nFieldIndex, 0].ToString();
        }
Exemple #12
0
 private void updateGrid(WindData wd,string func)
 {
     int clength = wd.codeList.Length, flength = wd.fieldList.Length, tlength = wd.timeList.Length;
     if (wd.errorCode != 0) {
         this.dataGridView1.ColumnCount = 2;
         this.dataGridView1.RowCount = 1;
         this.dataGridView1.Columns[0].HeaderText = "ErrCode";
         this.dataGridView1.Columns[1].HeaderText = "ErrMessage";
         this.dataGridView1.Rows[0].Cells[0].Value = wd.errorCode;
         this.dataGridView1.Rows[0].Cells[1].Value = w.getErrorMsg(wd.errorCode);
         return;
     }
     switch (func) {
         case "wsd":
         case "wsi":
         case "wst":{
             this.dataGridView1.ColumnCount = clength * flength;
             this.dataGridView1.RowCount = tlength+1;
             this.dataGridView1.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
             for (int i = 0; i < this.dataGridView1.ColumnCount; i++)
             {
                 this.dataGridView1.Columns[i].HeaderText = "";
                 if (i % flength == flength / 2)
                     this.dataGridView1.Columns[i].HeaderText = wd.codeList[i / flength];
             }
             for (int m = 0; m < clength; m++)
                 for (int j = 0; j < flength; j++)
                 {
                     this.dataGridView1.Rows[0].Cells[m * flength + j].Value = wd.fieldList[j];
                 }
             this.dataGridView1.Rows[0].HeaderCell.Value = "";
             for (int k = 1; k < this.dataGridView1.RowCount; k++) {
                 if (func == "wsd")
                 {
                     this.dataGridView1.RowHeadersWidth = 120;
                     this.dataGridView1.Rows[k].HeaderCell.Value = wd.timeList[k - 1].ToString("yyyy-MM-dd");
                 }
                 else
                 {
                     this.dataGridView1.RowHeadersWidth = 160;
                     this.dataGridView1.Rows[k].HeaderCell.Value = wd.timeList[k - 1].ToString("yyyy-MM-dd HH:mm:ss");
                 }
             }
             object[,] odata = (object[,])wd.getDataByFunc(func, false);
             for (int l = 0; l < tlength; l++)
                 for (int n = 0; n < clength * flength;n++ )
                     this.dataGridView1.Rows[l+1].Cells[n].Value = string.Format("{0}",odata[l,n]);
             break;
         }
         case "wss":
         case "wset":
         case "wsq": {
             this.dataGridView1.ColumnCount = flength;
             this.dataGridView1.RowCount = clength;
             this.dataGridView1.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
             this.dataGridView1.RowHeadersWidth = 120;
             for (int i = 0; i < this.dataGridView1.ColumnCount; i++)
             {
                 this.dataGridView1.Columns[i].HeaderText = wd.fieldList[i];
             }
             for (int j = 0; j < this.dataGridView1.RowCount; j++) {
                 this.dataGridView1.Rows[j].HeaderCell.Value = wd.codeList[j];
             }
             object[,] odata = (object[,])wd.getDataByFunc(func, false);
             //System.Console.WriteLine(odata[0,0]);
             for (int l = 0; l < clength; l++)
                 for (int n = 0; n < flength; n++)
                     this.dataGridView1.Rows[l].Cells[n].Value = string.Format("{0}", odata[l, n]);
             break;
         }
         default: {
             this.dataGridView1.ColumnCount = 1;
             this.dataGridView1.RowCount = ((Array)wd.data).Length;
             this.dataGridView1.Columns[0].HeaderText = wd.fieldList[0];
             for (int j = 0; j < this.dataGridView1.RowCount;j++ )
                 this.dataGridView1.Rows[j].Cells[0].Value = ((Array)wd.data).GetValue(j);
             break;
         }
     }
     return;
 }
Exemple #13
0
 public void drawKLines(WindData wd,int cycle,int colorNum)
 {
     double[,] data = (double[,])wd.getDataByFunc("wsi");
     gph = Graphics.FromImage(bmap);
     DateTime[] tlist = wd.timeList;
     PointF cpt = new PointF(50, 175);
     int oNum = (int)originNums[colorNum];
     //注释这段代码的功能是画K线
     //for (int i = 0; i < tlist.Length; i++) {
     //    int per = cycle * 2;
     //    PointF tmp = new PointF(48+per*(i+oNum),-(float)((10*data[i,0])/open-10)*175*beHigh+175);
     //    PointF tmp1 = new PointF(48 + per * (i + oNum) + per * 4 / 5, -(float)((10 * data[i, 1]) / open - 10) * 175 * beHigh + 175);
     //    PointF tmp2 = new PointF(48 + per * (i + oNum) + per * 2 / 5, -(float)((10 * data[i, 2]) / open - 10) * 175 * beHigh + 175);
     //    PointF tmp3 = new PointF(48 + per * (i + oNum) + per * 2 / 5, -(float)((10 * data[i, 3]) / open - 10) * 175 * beHigh + 175);
     //    if (tmp1.Y == tmp.Y)
     //        gph.DrawLine(myPens[colorNum%7], tmp, tmp1);
     //    else
     //        gph.DrawRectangle(myPens[colorNum%7], System.Math.Min(tmp.X, tmp1.X), System.Math.Min(tmp1.Y, tmp.Y), per * 4 / 5, System.Math.Abs(tmp1.Y - tmp.Y));
     //    gph.DrawLine(myPens[colorNum % 7],tmp2,tmp3);
     //}
     pictureBox1.Image = bmap;
     originNums[colorNum] = (int)originNums[colorNum] + tlist.Length;
 }
Exemple #14
0
        private void UpdateChart(WindData wd)
        {
            SetChartTitle();

            if (wd.GetDataLength() < 1 || wd.GetTimeLength() < 1)
                return;

            if (!(wd.data is double[]))
                return;
            double[] closeData = (double[])wd.data;
            if (closeData.Length != wd.GetTimeLength())
                return;

            AddChartSerie();
            Series ser = this.myChart.Series[0];
            double dClose = 0.0;
            string strDate = string.Empty;
            for (int i = 0; i < closeData.Length; i++)
            {
                dClose = closeData[i];
                ser.Points.AddXY(wd.timeList[i].ToString("yy/MM"), dClose);
            }
        }
Exemple #15
0
 private void btExecute_Click(object sender, EventArgs e)
 {
     int index = this.cbFuncList.SelectedIndex;
     String windCodes, indicators, startTime, endTime, options;
     windCodes = this.tbWindCodes.Text;
     indicators = this.tbIndicators.Text;
     startTime = this.dtpStartTime.Text;
     endTime =this.dtpEndTime.Text;
     options = this.tbOptions.Text;
     WindData wd = new WindData();
     switch (index) {
         case 0:{
             wd = w.wsd(windCodes, indicators, startTime, endTime, options);
             updateGrid(wd,"wsd");
             break;
         }
         case 1: {
             wd = w.wss(windCodes, indicators, options);
             updateGrid(wd,"wss");
             break;
         }
         case 2: {
             wd = w.wsi(windCodes, indicators, startTime, endTime, options);
             updateGrid(wd,"wsi");
             break;
         }
         case 3: {
             wd = w.wst(windCodes,indicators,startTime,endTime,options);
             updateGrid(wd,"wst");
             break;
         }
         case 4: {
             wd = w.wsq(windCodes,indicators,options);
             updateGrid(wd,"wsq");
             break;
         }
         case 5: {
             wd = w.wset(windCodes,options);
             updateGrid(wd,"wset");
             break;
         }
         case 6: {
             wd = w.weqs(windCodes, options);
             updateGrid(wd,"weqs");
             break;
         }
         case 7: {
             wd = w.tdays(startTime, endTime, options);
             updateGrid(wd,"tdays");
             break;
         }
         case 8: {
             wd = w.tdaysoffset(startTime, -30, options);
             updateGrid(wd,"tdaysoffset");
             break;
         }
         case 9: {
             wd = w.tdayscount(startTime, endTime, options);
             updateGrid(wd,"tdayscount");
             break;
         }
     }
 }
Exemple #16
0
 //统一处理返回值
 private WindData formatWD(object ocodes, object ofields, object otimes, object odata, int errorCode)
 {
     WindData wd = new WindData();
     wd.errorCode = errorCode;
     if (ocodes == null && ofields == null && otimes == null)
         return wd;
     if (ocodes != null)
         wd.codeList = (string[])ocodes;
     if (ofields != null)
         wd.fieldList = (string[])ofields;
     if (otimes != null)
     {
         double[] tmpTimes = (double[])otimes;
         int length = tmpTimes.Length;
         wd.timeList = new DateTime[length];
         for (int i = 0; i < length; i++)
             wd.timeList[i] = DateTime.FromOADate(tmpTimes[i]).AddYears(-1900);
     }
     wd.data = odata;
     return wd;
 }
Exemple #17
0
 private void ReqHandler(int state, ulong rid, int err)
 {
     if (state != 4)
     {
         lock (ReqList)
         {
             if (ReqList.ContainsKey(rid))
             {
                 WSQReq wr = ReqList[rid];
                 if (state == 1 && err == 0)
                 {
                     int    reqState, errCode;
                     object ocodes, ofields, otimes, odata;
                     odata = wdc.readdata(rid, out ocodes, out ofields, out otimes, out reqState, out errCode);
                     if (wr.updateAll)
                     {
                         wr.callback(rid, updataReqData(wr.rdata, ocodes, ofields, odata));
                     }
                     else
                     {
                         wr.callback(rid, formatWD(ocodes, ofields, otimes, odata, errCode));
                     }
                 }
                 else if (err != 0)
                 {
                     WindData wd = new WindData();
                     wd.errorCode = err;
                     wd.fieldList = new String[] { "ErrorMessage" };
                     wd.data      = new String[] { getErrorMsg(err) };
                     wr.callback(rid, wd);
                 }
             }
         }
     }
     else
     {
         ulong LogonID       = rid;
         bool  find_callback = false;
         lock (TradeCallbackList)
         {
             if (TradeCallbackList.ContainsKey(LogonID))
             {
                 find_callback = true;
             }
             else if (TradeCallbackList.ContainsKey(0))
             {
                 find_callback = true;
                 LogonID       = 0;
             }
             if (find_callback)
             {
                 int    reqState, errCode;
                 object ocodes, ofields, otimes, odata;
                 odata = wdc.readdata_trade(LogonID, out ocodes, out ofields, out otimes, out reqState, out errCode);
                 //调用回调函数
                 TradeCallbackList[LogonID](LogonID, formatWD(ocodes, ofields, otimes, odata, errCode));
             }
         }
     }
     return;
 }
Exemple #18
0
 private void updateGrid(WindData wd)
 {
     dataGridView1.RowHeadersWidth = 120;
     if (wd.data is object[])
     {
         object[] tmpdata = (object[])wd.data;
         int dlength = tmpdata.Length;
         dataGridView1.ColumnCount = 1;
         dataGridView1.RowCount = dlength;
         for (int i = 0; i < dlength; i++)
         {
              dataGridView1.Rows[i].HeaderCell.Value = wd.fieldList[i];
              dataGridView1.Rows[i].Cells[0].Value = string.Format("{0}", ((Array)wd.data).GetValue(i));
         }
      }
      else {
         object[,] tmpdata = (object[,])wd.data;
         int dlength = tmpdata.Length;
         int flength = wd.fieldList.Length;
         int width = dlength / flength;
         dataGridView1.ColumnCount = width;
         dataGridView1.RowCount = flength;
         for (int i = 0; i < flength; i++)
             for (int j = 0; j < width;j++ )
             {
                 dataGridView1.Rows[i].HeaderCell.Value = wd.fieldList[i];
                 dataGridView1.Rows[i].Cells[j].Value = string.Format("{0}", ((object[,])wd.data)[i, j]);
             }
      }
 }
Exemple #19
0
 private WindData setData(WindData rd, object odata, int codeIndex, int fieldIndex, int dataIndex)
 {
     object tmpdata = rd.data;
     if (codeIndex >= rd.codeList.Length || fieldIndex >= rd.fieldList.Length)
     {
         throw new Exception("数组越界");
     }
     if (rd.data is double[])
         ((double[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((double[])odata)[dataIndex];
     else if (rd.data is int[])
         ((int[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((int[])odata)[dataIndex];
     else if (rd.data is String[])
         ((String[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((String[])odata)[dataIndex];
     else if (rd.data is DateTime[])
         ((DateTime[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((DateTime[])odata)[dataIndex];
     else if (rd.data is Int64[])
         ((Int64[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((Int64[])odata)[dataIndex];
     else if (rd.data is object[])
         ((object[])tmpdata)[fieldIndex + codeIndex * rd.fieldList.Length] = ((object[])odata)[dataIndex];
     rd.data = tmpdata;
     return rd;
 }
Exemple #20
0
 private string GetLogonId(WindData wd)
 {
     return GetDataByFiledName(wd, "LogonID");
 }
Exemple #21
0
 private string GetOrderNumber(WindData wd)
 {
     return GetDataByFiledName(wd, "OrderNumber");
 }
Exemple #22
0
 public void Callback(ulong reqId, WindData wd)
 {
     //Fill data here
     Console.WriteLine(reqId);
 }
Exemple #23
0
 private int getFieldIndex(WindData rd, string fieldName)
 {
     if (rd != null)
     {
         string[] flist = rd.fieldList;
         int length = flist.Length;
         for (int i = 0; i < length; i++)
         {
             if (fieldName == flist[i])
                 return i;
         }
     }
     return -1;
 }
Exemple #24
0
 private WindData updataReqData(WindData rd, object ocodes, object ofields, object odata)
 {
     if (ocodes is string)
     {
         if (ofields is string)
         {
             rd = setData(rd, odata, getCodeIndex(rd, (string)ocodes), getFieldIndex(rd, (string)ofields), 0);
         }
         else if (ofields is string[])
         {
             string[] flist = (string[])ofields;
             for (int i = 0; i < flist.Length; i++)
             {
                 rd = setData(rd, odata, getCodeIndex(rd, (string)ocodes), getFieldIndex(rd, flist[i]), i);
             }
         }
     }
     else if (ocodes is string[])
     {
         string[] clist = (string[])ocodes;
         for (int j = 0; j < clist.Length; j++)
         {
             if (ofields is string)
                 rd = setData(rd, odata, getCodeIndex(rd, clist[j]), getFieldIndex(rd, (string)ofields), j);
             else if (ofields is string[])
             {
                 string[] flist = (string[])ofields;
                 for (int k = 0; k < flist.Length; k++)
                 {
                     rd = setData(rd, odata, getCodeIndex(rd, clist[j]), getFieldIndex(rd, flist[k]), j * flist.Length + k);
                 }
             }
         }
     }
     return rd;
 }
Exemple #25
0
 public void myCallback(WindData wd)
 {
     if (wd.errorCode == 0)
     {
         wsqData = wd;
         sd = new SetDelegate(drawLines);
         sd1 = new SetDelegate(doBreakThrough);
         sd2 = new SetDelegate(updatePrice);
         this.pictureBox1.Invoke(sd);
         this.richTextBox1.Invoke(sd1);
         this.label6.Invoke(sd2);
     }
 }
Exemple #26
0
 private int getCodeIndex(WindData rd, string codeName)
 {
     if (rd != null)
     {
         string[] clist = rd.codeList;
         int length = clist.Length;
         for (int i = 0; i < length; i++)
         {
             if (codeName == clist[i])
                 return i;
         }
     }
     return -1;
 }
Exemple #27
0
 private string GetRequestID(WindData wd)
 {
     return GetDataByFiledName(wd, "RequestID");
 }
Exemple #28
0
 private void ReqHandler(int state, ulong rid, int err)
 {
     if (ReqList.ContainsKey(rid))
     {
         WSQReq wr = ReqList[rid];
         if (state == 1 && err == 0)
         {
             int reqState, errCode;
             object ocodes, ofields, otimes, odata;
             odata = wdc.readdata(rid, out ocodes, out ofields, out otimes, out reqState, out errCode);
             if (wr.updateAll)
                 wr.callback(updataReqData(wr.rdata, ocodes, ofields, odata));
             else
                 wr.callback(formatWD(ocodes, ofields, otimes, odata, errCode));
         }
         else if (err != 0)
         {
             WindData wd = new WindData();
             wd.errorCode = err;
             wd.fieldList = new String[] { "ErrorMessage" };
             wd.data = new String[] { getErrorMsg(err) };
             wr.callback(wd);
         }
     }
     return;
 }
Exemple #29
0
 static void OutputWindData(WindData wd, string strFuncName)
 {
     string s = WindDataMethod.WindDataToString(wd, strFuncName);
     Console.Write(s);
 }
Exemple #30
0
        public static string WindDataToString(WindData wd, string strFuncName)
        {
            if (null == wd)
                return string.Empty;

            string s = string.Empty;
            string str = string.Empty;

            //请求出错,获取错误信息
            if (wd.errorCode != 0)
            {
                s += wd.GetErrorMsg() + Environment.NewLine;

                return s;
            }

            if (null != wd.codeList)
            {
                s += "Windcode = " + Environment.NewLine;
                foreach (String code in wd.codeList)
                    s += "  " + code + "\t";
                s += Environment.NewLine;
            }
            if (null != wd.fieldList)
            {
                s += "Indicators = " + Environment.NewLine;
                foreach (String field in wd.fieldList)
                    s += "  " + field + "\t";
                s += Environment.NewLine;
            }
            if (null != wd.timeList)
            {
                s += "Times = " + Environment.NewLine;
                foreach (DateTime time in wd.timeList)
                    s += "  " + time.ToString() + "\t";
                s += Environment.NewLine;
            }

            s += "Data = " + Environment.NewLine;
            object getData = wd.getDataByFunc(strFuncName, false);
            if (getData is object[,])//转化为2维数组
            {
                object[,] odata = (object[,])getData;

                switch (strFuncName)
                {
                    case "wsd":
                        {
                            string strColHead = string.Empty;
                            strColHead += "Time" + "\t\t";
                            foreach (String field in wd.fieldList)
                                strColHead += field + "\t";
                            strColHead += Environment.NewLine;

                            s = strColHead;

                            int nTimeLength = wd.timeList.Length;
                            int nCodeLength = wd.codeList.Length;
                            int nFieldLength = wd.fieldList.Length;
                            for (int i = 0; i < nTimeLength; i++)
                            {
                                s += wd.timeList[i].ToString("yyyy-MM-dd") + "\t";
                                for (int j = 0; j < nCodeLength * nFieldLength; j++)
                                {
                                    str = odata[i, j].ToString();
                                    s += str + "\t";
                                }
                                s += Environment.NewLine;
                            }
                        }
                        break;
                    case "wsi":
                    case "wst":
                        {
                            string strColHead = string.Empty;
                            bool bNeedOutputTime = true;
                            foreach (String field in wd.fieldList)
                            {
                                if (field == "time")
                                {
                                    strColHead += field + "\t\t\t";
                                    bNeedOutputTime = false;
                                }
                                else
                                    strColHead += field + "\t";
                            }
                            if (bNeedOutputTime)
                                strColHead = "time" + "\t\t\t" + strColHead;
                            strColHead += Environment.NewLine;

                            s = strColHead;

                            int nTimeLength = wd.timeList.Length;
                            int nCodeLength = wd.codeList.Length;
                            int nFieldLength = wd.fieldList.Length;
                            for (int i = 0; i < nTimeLength; i++)
                            {
                                if (bNeedOutputTime)
                                {
                                    s += wd.timeList[i].ToString() + "\t";
                                }

                                for (int j = 0; j < nCodeLength * nFieldLength; j++)
                                {
                                    str = odata[i, j].ToString();
                                    s += str + "\t";
                                }
                                s += Environment.NewLine;
                            }
                        }
                        break;
                    case "wsq":
                    case "wss":
                    case "wset":
                    case "wpf":
                        {
                            string strColHead = string.Empty;
                            foreach (String field in wd.fieldList)
                            {
                                strColHead += field + "\t";
                            }

                            s = strColHead + Environment.NewLine;

                            int nTimeLength = wd.timeList.Length;
                            int nCodeLength = wd.codeList.Length;
                            int nFieldLength = wd.fieldList.Length;
                            for (int i = 0; i < nCodeLength; i++)
                            {
                                if (i > 100)
                                    break;
                                s += wd.codeList[i] + "\t";
                                for (int j = 0; j < nTimeLength * nFieldLength; j++)
                                {
                                    if (null != odata[i, j])
                                    {
                                        str = odata[i, j].ToString();
                                        s += str + "\t";
                                    }
                                }
                                s += Environment.NewLine;
                            }
                        }
                        break;
                    default:
                        {
                            foreach (object o in odata)
                            {
                                str = o.ToString();
                                s += str + "\t";
                            }
                            s += Environment.NewLine;
                        }
                        break;
                }
            }
            else if (getData is object[])//一维数组
            {
                object[] odata = (object[])getData;
                foreach (object o in odata)
                {
                    str = o.ToString();
                    s += str + Environment.NewLine;
                }
            }
            else//简单对象
            {
                s += getData.ToString() + Environment.NewLine;
            }

            return s;
        }