예제 #1
0
 private void UpdateGroup(券商 Group)
 {
     try
     {
         var matchItem = Regex.Match(txtServerInfo.Text, "([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}):([0-9]+)");
         if (matchItem.Success && string.IsNullOrEmpty(txtIP.Text) || string.IsNullOrEmpty(txtPort.Text))
         {
             txtIP.Text   = matchItem.Groups[1].Value;
             txtPort.Text = matchItem.Groups[2].Value;
         }
         Group.IP    = txtIP.Text.Trim();
         Group.Port  = short.Parse(txtPort.Text.Trim());
         Group.版本号   = txtVersion.Text.Trim();
         Group.登录帐号  = txtLogAccount.Text.Trim();
         Group.交易服务器 = txtServerInfo.Text;
         Group.交易密码  = Cryptor.MD5Encrypt(txtTradePsw.Text);
         Group.交易帐号  = txtTradeAccount.Text.Trim();
         Group.称     = txtName.Text.Trim();
         Group.启用    = cbIsUse.Checked;
         Group.通讯密码  = Cryptor.MD5Encrypt(txtCommunicatePsw.Text);
         Group.营业部代码 = short.Parse(txtDepartment.Text.Trim());
         CommonUtils.SetConfig(Group.称, Cryptor.MD5Encrypt(Group.ToJson()));
     }
     catch (Exception ex)
     {
         ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", string.Format("<script>alert('修改异常,{0}!');</script>", ex.Message));
     }
 }
예제 #2
0
        /// <summary>
        /// 通达信接口-交易数据查询
        /// </summary>
        /// <param name="o">券商</param>
        /// <param name="tradeDataType">表示查询信息的种类,0资金  1股份   2当日委托  3当日成交     4可撤单   5股东代码  6融资余额   7融券余额  8可融证券</param>
        /// <returns></returns>
        public static DataTable QueryTradeData(券商 o, int tradeDataType)
        {
            DataTable     dt      = null;
            StringBuilder ErrInfo = new StringBuilder(256);
            StringBuilder result  = new StringBuilder(1024 * 1024);

            if (o.营业部代码 == 8888 && (DateTime.Now.Hour > 15 || DateTime.Now.Hour < 9))
            {
                o.营业部代码 = 24;
                o.IP    = "124.74.242.150";
                o.Port  = 443;
            }

            var ClientID = TdxApi.Logon(o.IP, o.Port, o.版本号, o.营业部代码, o.登录帐号, o.交易帐号, o.TradePsw, o.CommunicatePsw, ErrInfo);

            if (ErrInfo.Length > 0)
            {
                CommonUtils.ShowMsg(ErrInfo.ToString());
            }
            else
            {
                TdxApi.QueryData(ClientID, tradeDataType, result, ErrInfo);
                if (ErrInfo.Length == 0)
                {
                    dt = CommonUtils.ChangeDataStringToTable(result.ToString());
                }
                else
                {
                    CommonUtils.ShowMsg(ErrInfo.ToString());
                }
            }
            TdxApi.Logoff(ClientID);
            return(dt);
        }
예제 #3
0
파일: DataAdapter.cs 프로젝트: webs3c/E
        public static DataTable QueryHisDelivery(DateTime st, DateTime et, 券商 o)
        {
            int dataType = 3;

            if (o.称 == "F17")
            {
                dataType = 2;
            }
            return(QueryHisData(st, et, o, dataType));
        }
예제 #4
0
        /// <summary>
        /// 数据检查,查看是否需要根据历史成交进行补充。
        /// </summary>
        /// <param name="st"></param>
        /// <param name="et"></param>
        /// <param name="o"></param>
        /// <param name="dt"></param>
        /// <param name="ErrInfo"></param>
        /// <param name="result"></param>
        /// <param name="ClientID"></param>
        private static void CheckDataIntegrity(DateTime st, DateTime et, 券商 o, DataTable dt, StringBuilder ErrInfo, StringBuilder result, int ClientID)
        {
            #region 成交金额修正
            if (dt.Columns.Contains("成交金额"))
            {
                foreach (DataRow row in dt.Rows)
                {
                    row["成交金额"] = Math.Abs(CommonUtils.GetDecimal(row["成交金额"]));
                }
            }
            else if (dt.Columns.Contains("成交数量") && dt.Columns.Contains("成交价格"))
            {
                dt.Columns.Add("成交金额");
                foreach (DataRow row in dt.Rows)
                {
                    row["成交金额"] = Math.Abs(CommonUtils.GetDecimal(row["成交价格"]) * CommonUtils.GetDecimal(row["成交数量"]));
                }
            }
            #endregion

            #region 买卖标志修正
            if (dt.Columns.Contains("买卖标志") && dt.Rows.Count > 0 && Regex.IsMatch(dt.Rows[0]["买卖标志"] + "", "[012]"))
            {
                foreach (DataRow row in dt.Rows)
                {
                    row["买卖标志"] = GetTradeSymble(row);
                }
            }
            else if (!dt.Columns.Contains("买卖标志") && !HasBuySaleColumn(dt) && dt.Columns.Contains("备注"))
            {
                dt.Columns.Add("买卖标志");
                foreach (DataRow row in dt.Rows)
                {
                    row["买卖标志"] = Regex.Match(row["备注"] + "", "买|卖").Value;
                }
            }
            #endregion

            List <string> VIPColumns = new List <string>()
            {
                "证券代码", "证券名称", "成交价格", "成交数量", "成交金额"
            };
            var needAddColumn = VIPColumns.Where(_ => !dt.Columns.Contains(_)).ToList();

            if (needAddColumn.Count > 0)
            {
                TdxApi.QueryHistoryData(ClientID, 1, st.ToString("yyyyMMdd"), et.ToString("yyyyMMdd"), result, ErrInfo);
                if (ErrInfo.Length == 0)
                {
                    var dt1 = CommonUtils.ChangeDataStringToTable(result.ToString());
                    needAddColumn = needAddColumn.Where(_ => dt1.Columns.Contains(_)).ToList();
                    AddDataColumnFromHisTrade(dt, dt1, needAddColumn);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 通达信接口-历史数据查询(默认查询交割单)
        /// </summary>
        /// <param name="st">开始时间</param>
        /// <param name="et">结束时间</param>
        /// <param name="o">券商</param>
        /// <param name="historyDataType">表示查询信息的种类,0历史委托  1历史成交   2交割单</param>
        /// <returns></returns>
        public static DataTable QueryHisData(DateTime st, DateTime et, 券商 o, int historyDataType = 2, bool originalData = false)
        {
            DataTable     dt      = null;
            StringBuilder ErrInfo = new StringBuilder(256);

            //StringBuilder result = new StringBuilder(1024 * 1024);
            queryHisResult.Clear();
            if (o.营业部代码 == 8888)
            {
                if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday ||
                    DateTime.Today.DayOfWeek == DayOfWeek.Saturday ||
                    DateTime.Now.Hour <= 9 ||
                    DateTime.Now.Hour >= 15)
                {
                    o.营业部代码 = 24;
                    o.IP    = "124.74.242.150";
                    o.Port  = 443;
                }
            }

            var ClientID = TdxApi.Logon(o.IP, o.Port, o.版本号, o.营业部代码, o.登录帐号, o.交易帐号, o.TradePsw, o.CommunicatePsw, ErrInfo);

            if (ErrInfo.Length > 0)
            {
                CommonUtils.Log(string.Format("通达信接口登录失败, 组合号:{0}, 起始日期:{1},结束日期:{2} ,错误信息:{3}", o.称, st.ToString(), et.ToString(), ErrInfo.ToString()));
            }
            else
            {
                DateTime searchEndDate = et;
                if (StrangeGroups.Contains(o.称) && st == et)
                {
                    searchEndDate = et.AddDays(1);
                }
                TdxApi.QueryHistoryData(ClientID, historyDataType, st.ToString("yyyyMMdd"), searchEndDate.ToString("yyyyMMdd"), queryHisResult, ErrInfo);
                if (ErrInfo.Length == 0)
                {
                    dt = CommonUtils.ChangeDataStringToTable(queryHisResult.ToString());
                    if (!originalData && historyDataType == 2)
                    {
                        FilteTableData(o, st, et, dt);
                        CheckDataIntegrity(st, et, o, dt, ErrInfo, queryHisResult, ClientID);
                        RepairData(o, dt);
                    }
                }
                else
                {
                    CommonUtils.Log("通达信接口查询失败,错误信息" + ErrInfo.ToString());
                }
            }
            TdxApi.Logoff(ClientID);
            return(dt);
        }
예제 #6
0
 /// <summary>
 /// 过滤数据,如B08,如果只查一天的数据,会查不出来,必须查两天的,再根据日期过滤
 /// </summary>
 /// <param name="o"></param>
 /// <param name="st"></param>
 /// <param name="et"></param>
 /// <param name="dt"></param>
 private static void FilteTableData(券商 o, DateTime st, DateTime et, DataTable dt)
 {
     if (StrangeGroups.Contains(o.称) && st == et)
     {
         for (int i = dt.Rows.Count - 1; i > -1; i--)
         {
             if (dt.Rows[i]["成交日期"].ToString() != st.ToString("yyyyMMdd"))
             {
                 dt.Rows.RemoveAt(i);
             }
         }
     }
 }
예제 #7
0
        public void Init(券商 o)
        {
            Entity             = o;
            this.txt名称.Text    = o.称;
            this.txt版本号.Text   = o.版本号;
            this.txt交易服务器.Text = o.交易服务器;
            this.txtIP.Text    = o.IP;
            this.txtPort.Text  = o.Port + "";
            this.txt营业部代码.Text = o.营业部代码 + "";
            this.txt登录帐号.Text  = o.登录帐号;
            this.txt交易帐号.Text  = o.交易帐号;
            this.txt交易密码.Text  = o.交易密码;
            this.txt通讯密码.Text  = o.通讯密码;

            this.ckIsEnable.IsChecked = o.启用;
        }
예제 #8
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            券商 Group = null;

            if (string.IsNullOrEmpty(this.Request.Params["name"]) && WebConfigurationManager.AppSettings.AllKeys.Contains(txtName.Text.Trim()))
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('已存在该组合号!');</script>");
                return;
            }
            else
            {
                Group = new 券商();
            }

            UpdateGroup(Group);

            //ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('修改完毕!'); window.location.url='Manage.aspx'</script>");
            //Response.Redirect("Manage.aspx");
            Server.Transfer("~/Manage.aspx");
        }
예제 #9
0
        private static void RepairData(券商 o, DataTable dt)
        {
            if (dt.Columns.Count == 0)
            {
                return;
            }

            dt.Columns.Add("组合号");
            foreach (DataRow item in dt.Rows)
            {
                item["组合号"] = o.称;
            }

            for (int i = dt.Columns.Count - 1; i > -1; i--)
            {
                if (regFilter.IsMatch(dt.Columns[i].ColumnName))
                {
                    dt.Columns.RemoveAt(i);
                }
            }
        }
예제 #10
0
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            if (Validate())
            {
                try
                {
                    券商            o       = GetPageEntity();
                    StringBuilder ErrInfo = new StringBuilder(256);
                    //int clientID = TdxApi.Logon(o.IP, o.Port, o.版本号, o.营业部代码, o.登录帐号, o.交易帐号, o.TradePsw, o.CommunicatePsw, ErrInfo);
                    //if (clientID > -1)
                    //{

                    //    TdxApi.Logoff(clientID);
                    //}
                    //else
                    //{
                    //    MessageBox.Show("登录验证失败, 错误信息:" + ErrInfo.ToString());
                    //}
                    using (var db = new DataComparisionDataset())
                    {
                        var oldEntity = db.券商ds.FirstOrDefault(_ => _.称 == o.称);
                        if (oldEntity != null)
                        {
                            db.券商ds.Remove(oldEntity);
                        }


                        db.券商ds.Add(o);
                        db.SaveChanges();
                        MessageBox.Show("保存完毕", "组合号编辑");
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    CommonUtils.ShowMsg(ex.Message);
                }
            }
        }
예제 #11
0
 public GroupEdit(券商 o)
 {
     InitializeComponent();
     Init(o);
 }