private void btnSubmit_Click(object sender, RoutedEventArgs e) { if (Valid()) { CommonUtils.SetConfig("user", txtAccount.Text); CommonUtils.SetConfig("password", Cryptor.MD5Encrypt(txtPassword.Password)); this.Close(); } }
private void Button_SearchAccountInfo_Click(object sender, RoutedEventArgs e) { var entity = this.GetPageEntity(); ImsApi.Init(ImsNotify); string errMsg = string.Empty; bool isLogin = ImsApi.Login(entity.交易帐号, Cryptor.MD5Decrypt(entity.交易密码), entity.版本号, out errMsg); if (!string.IsNullOrEmpty(errMsg) || isLogin) { MessageBox.Show(errMsg); return; } StringBuilder Result = new StringBuilder(1024); StringBuilder ErrInfo = new StringBuilder(1024); if (string.IsNullOrEmpty(txt产品信息.Text)) { ImsApi.ImsPbClient_RequestProductList(0, Result, ErrInfo); lblErrInfo产品信息.Text = ErrInfo.ToString(); var dt = CommonUtils.ChangeDataStringToTable(Result.ToString()); if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("productid")) { this.txt产品信息.Text = dt.Rows[0]["productid"] + ""; } } if (string.IsNullOrEmpty(txt资产单元.Text)) { ImsApi.ImsPbClient_RequestProductList(1, Result, ErrInfo); //this.txt资产单元.Text = Result.ToString(); this.lblErrInfo资产单元.Text = ErrInfo.ToString(); var dt = CommonUtils.ChangeDataStringToTable(Result.ToString()); if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("productunitid")) { this.txt资产单元.Text = dt.Rows[0]["productunitid"] + ""; } } if (string.IsNullOrEmpty(txt投资组合.Text)) { ImsApi.ImsPbClient_RequestProductList(2, Result, ErrInfo); //this.txt投资组合.Text = Result.ToString(); this.lblErrInfo投资组合.Text = ErrInfo.ToString(); var dt = CommonUtils.ChangeDataStringToTable(Result.ToString()); if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("portfolioid")) { this.txt投资组合.Text = dt.Rows[0]["portfolioid"] + ""; } } btnSave.IsEnabled = true; }
private bool Validate() { if (GroupEntity == null && !string.IsNullOrEmpty(CommonUtils.GetConfig(this.txt名称.Text))) { MessageBox.Show("已存在该组合号配置信息!", this.Title); return(false); } if (!Regex.IsMatch(this.txt名称.Text, "^[A-Z][0-9]{2,}$")) { MessageBox.Show("名称不符合规范,格式应为大写字母后带两个以上的数字!", this.Title); return(false); } //if (!Regex.IsMatch(this.txt交易服务器.Text, "[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}")) //{ // MessageBox.Show("交易服务器不符合规范,格式应为ip地址或网址带端口号,如 192.168.1.1", this.Title); // return false; //} if (string.IsNullOrEmpty(this.txt版本号.Text)) { MessageBox.Show("版本号不能为空!", this.Title); return(false); } if (string.IsNullOrEmpty(this.txt帐号.Text)) { MessageBox.Show("帐号不能为空!", this.Title); return(false); } if (string.IsNullOrEmpty(this.txt密码.Password)) { MessageBox.Show("密码不能为空!", this.Title); return(false); } else if (this.ckIsEncrypt.IsChecked == true) { try { Cryptor.MD5Decrypt(txt密码.Password); } catch (Exception) { MessageBox.Show("密码解密失败,请确认输入的是加密后的密码!", this.Title); return(false); } } return(true); }
public string Logon() { StringBuilder ErrInfo = new StringBuilder(256); if (IsIMSAccount) { string Msg; ImsApi.Init(ImsNotify); bool isLogin = ImsApi.Login(this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), this.版本号, out Msg); if (isLogin) { this.ClientID = 0; return("登录成功"); } else { return(Msg); } } else { try { this.ClientID = TdxApi.Logon(this.IP, this.Port, this.版本号, this.营业部代码, this.登录帐号, this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), Cryptor.MD5Decrypt(this.通讯密码), ErrInfo); } catch (Exception ex) { CommonUtils.Log("组合号登录异常", ex); } string strError = ErrInfo.ToString(); if (!string.IsNullOrEmpty(strError)) { //交易中心(-10016):您使用的版本太低已因为安全原因停止使用,请到官网上下载最新版本重新安装。 if (strError.Contains("密码") || strError.Contains("您使用的版本太低已因为安全原因停止使用")) { //ErrInfo.Append("登录异常,将自动禁用,请检查组合号信息!"); CommonUtils.Log("登录密码错误或版本过低导致登录失败,将自动停用,错误信息:{0}", strError); this.启用 = false; } return("登录失败:" + ErrInfo.ToString()); } else { return("登录成功"); } } }
private 券商 GetPageEntity() { if (this.GroupEntity == null) { GroupEntity = new 券商() { IsIMSAccount = true } } ; var o = GroupEntity; o.称 = this.txt名称.Text.Trim(); o.启用 = this.ckIsEnable.IsChecked == true; o.版本号 = this.txt版本号.Text.Trim(); //o.交易服务器 = this.txt交易服务器.Text.Trim(); //var serverInfo = Regex.Match(o.交易服务器, "[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}").Value; //o.IP = serverInfo; o.交易帐号 = this.txt帐号.Text.Trim(); if (ckIsEncrypt.IsChecked == true) { o.交易密码 = this.txt密码.Password; o.通讯密码 = Cryptor.MD5Encrypt(string.Empty);; } else { o.交易密码 = Cryptor.MD5Encrypt(this.txt密码.Password); o.通讯密码 = Cryptor.MD5Encrypt(string.Empty); } o.产品信息 = this.txt产品信息.Text.Trim(); o.资产单元 = this.txt资产单元.Text.Trim(); o.投资组合 = this.txt投资组合.Text.Trim(); int time = 0; if (int.TryParse(this.txt查询时间间隔.Text.Trim(), out time)) { o.查询间隔时间 = time; } //o.Multithreading = ckIsMultiThread.IsChecked == true; return(o); }
public static bool UpdateGroup(券商 o) { try { var groupJson = (new GroupInfo(o)).ToJson(); CommonUtils.SetConfig(o.称, Cryptor.MD5Encrypt(groupJson)); if (o.ClientID == -1 && o.启用) { o.Start(); } } catch (Exception ex) { CommonUtils.Log("新增或编辑组合号出错", ex); return(false); } return(true); }
private bool Valid() { var userName = CommonUtils.GetConfig("user"); //admin var psw = CommonUtils.GetConfig("password"); //12345 if (string.IsNullOrEmpty(userName)) { userName = "******"; CommonUtils.SetConfig("user", "admin"); } if (string.IsNullOrEmpty(psw)) { psw = Cryptor.MD5Decrypt("57DDBC28E53C7DEA"); CommonUtils.SetConfig("password", "57DDBC28E53C7DEA"); } if (txtUserName.Text == userName && Cryptor.MD5Encrypt(pb.Password) == psw) { return(true); } return(false); }
private 券商 GetPageEntity() { if (this.GroupEntity == null) { GroupEntity = new 券商(); } var o = GroupEntity; o.IP = this.txtIP.Text; o.Port = short.Parse(this.txtPort.Text.Trim()); o.版本号 = this.txt版本号.Text.Trim(); o.登录帐号 = this.txt登录帐号.Text.Trim(); o.交易服务器 = this.txt交易服务器.Text.Trim(); o.交易帐号 = this.txt交易帐号.Text.Trim(); o.称 = this.txt名称.Text.Trim(); o.启用 = this.ckIsEnable.IsChecked == true; if (ckIsEncrypt.IsChecked == true) { o.交易密码 = this.txt交易密码.Password; o.通讯密码 = this.txt通讯密码.Password; } else { o.交易密码 = Cryptor.MD5Encrypt(this.txt交易密码.Password); o.通讯密码 = Cryptor.MD5Encrypt(this.txt通讯密码.Password); } int time = 0; if (int.TryParse(this.txt查询时间间隔.Text.Trim(), out time)) { o.查询间隔时间 = time; } o.营业部代码 = short.Parse(this.txt营业部代码.Text); o.Multithreading = ckIsMultiThread.IsChecked == true; return(o); }
public void Repay(string amount, StringBuilder Result, StringBuilder ErrInfo) { try { if (this.ClientID == -1) { this.ClientID = TdxApi.Logon(this.IP, this.Port, this.版本号, this.营业部代码, this.登录帐号, this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), Cryptor.MD5Decrypt(this.通讯密码), ErrInfo); isLogonInterim = this.ClientID > -1; } if (this.ClientID > -1) { TdxApi.Repay(this.ClientID, amount, Result, ErrInfo); } } catch (Exception ex) { ErrInfo.AppendFormat("Repay异常:{0}", ex.Message); } if (isLogonInterim) { isLogonInterim = false; } }
/// <summary> /// /// </summary> /// <param name="dataType">表示查询信息的种类,0资金 1股份 2当日委托 3当日成交 4可撤单 5股东代码 6融资余额 7融券余额 8可融证券</param> /// <returns></returns> internal void QueryAccountData(int dataType, GroupClient.GroupService.Queryinfo QueryResult) { StringBuilder result = new StringBuilder(1024 * 1024); StringBuilder errInfo = new StringBuilder(256); try { if (this.ClientID == -1) { this.ClientID = TdxApi.Logon(this.IP, this.Port, this.版本号, this.营业部代码, this.登录帐号, this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), Cryptor.MD5Decrypt(this.通讯密码), errInfo); isLogonInterim = this.ClientID > -1; } if (this.ClientID > -1) { TdxApi.QueryData(this.ClientID, dataType, result, errInfo); } } catch (Exception ex) { errInfo.AppendFormat("查询接口异常:{0}", ex.Message); } QueryResult.Error = errInfo.ToString(); QueryResult.Result = result.ToString(); if (isLogonInterim) { isLogonInterim = false; } }
private void Button_Save_Click(object sender, RoutedEventArgs e) { if (Validate()) { var entity = GetPageEntity(); bool isLogon = Test(entity.IP, entity.Port, entity.版本号, entity.营业部代码, entity.登录帐号, entity.交易帐号, Cryptor.MD5Decrypt(entity.交易密码), Cryptor.MD5Decrypt(entity.通讯密码)); if (isLogon) { if (Adapter.UpdateGroup(entity)) { MessageBox.Show("保存成功!"); if (OnAddComplete != null) { OnAddComplete.Invoke(entity); } this.Close(); } else { MessageBox.Show("保存失败!"); } } //else //{ // MessageBox.Show("帐号或密码不正确!"); //} } }
private bool Validate() { if (GroupEntity == null && !string.IsNullOrEmpty(CommonUtils.GetConfig(this.txt名称.Text))) { MessageBox.Show("已存在该组合号配置信息!", this.Title); return(false); } if (!Regex.IsMatch(this.txt名称.Text, "^[A-Z][0-9]{2,}$")) { MessageBox.Show("名称不符合规范,格式应为大写字母后带两个以上的数字!", this.Title); return(false); } if (Regex.IsMatch(this.txt交易服务器.Text, "[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}:[0-9]+")) { var ipInfo = Regex.Match(this.txt交易服务器.Text, "[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}:[0-9]+").Value.Split(':'); if (string.IsNullOrEmpty(txtIP.Text)) { this.txtIP.Text = ipInfo[0]; } else if (txtIP.Text != ipInfo[0]) { MessageBox.Show("交易服务器中包含的ip信息与ip地址栏中填写的不一致!", this.Title); return(false); } if (string.IsNullOrEmpty(txtPort.Text)) { this.txtPort.Text = ipInfo[1]; } else if (txtPort.Text != ipInfo[1]) { MessageBox.Show("交易服务器中包含的端口信息与Port地址栏中填写的不一致!", this.Title); return(false); } } if (!CommonUtils.IsIP(this.txtIP.Text)) { MessageBox.Show("ip不符合规范,应在0~255.0~255.0~255.0~255范围内,请在交易服务器中包含或单独填写", this.Title); return(false); } if (!Regex.IsMatch(this.txtPort.Text, "^[1-9][0-9]+$")) { MessageBox.Show("端口号不符合规范,应为数字,如80,请在交易服务器中包含或单独填写", this.Title); } if (string.IsNullOrEmpty(this.txt版本号.Text)) { MessageBox.Show("版本号不能为空!", this.Title); return(false); } if (string.IsNullOrEmpty(this.txt营业部代码.Text)) { MessageBox.Show("营业部代码不能为空!", this.Title); return(false); } if (string.IsNullOrEmpty(this.txt登录帐号.Text)) { MessageBox.Show("登录帐号不能为空!", this.Title); return(false); } if (string.IsNullOrEmpty(this.txt交易帐号.Text)) { MessageBox.Show("交易帐号不能为空!", this.Title); return(false); } if (string.IsNullOrEmpty(this.txt交易密码.Password)) { MessageBox.Show("交易密码不能为空!", this.Title); return(false); } else if (this.ckIsEncrypt.IsChecked == true) { try { var psw = Cryptor.MD5Decrypt(txt交易密码.Password); var psw1 = Cryptor.MD5Decrypt(txt通讯密码.Password); } catch (Exception) { MessageBox.Show("密码解密失败,请确认输入的是加密后的密码!", this.Title); return(false); } } return(true); }