private void btn_save_Click(object sender, EventArgs e) { try { DataTable dt = this.dataGridView1.Tag as DataTable; Dictionary <string, AssetInfoConfig> ret = new Dictionary <string, AssetInfoConfig>(); for (int i = 0; i < dt.Rows.Count; i++) { AssetInfoConfig aic = new AssetInfoConfig(); int.TryParse(dt.Rows[i]["cnt"]?.ToString(), out aic.value); //int.TryParse(dt.Rows[i]["needSelectTime"]?.ToString(), out aic.NeedSelectTimes); aic.NeedSelectTimes = (bool)dt.Rows[i]["needSelectTime"] == true ? 1 : 0; double.TryParse(dt.Rows[i]["gainedUbound"]?.ToString(), out aic.maxStopGainedValue); ret.Add(dt.Rows[i]["id"].ToString(), aic); } Program.gc.AssetUnits = ret; SaveToServer(ret); GlobalClass.SetConfig(Program.gc.ForWeb); this.Close(); } catch (Exception ce) { MessageBox.Show(ce.Message); } }
private void btn_login_Click(object sender, EventArgs e) { this.btn_login.Enabled = false; this.Cursor = Cursors.WaitCursor; if (this.ddl_websites.SelectedIndex < 0) { MessageBox.Show("请选择平台!"); return; } if (Program.allGc == null) { Program.allGc = Program.gc.CopyTo <GlobalClass>(); } // GlobalClass.resetTypeDataPoints();//必须重新设置,每个平台投注品种不一样 Program.gc.ClientUserName = this.txt_user.Text.Trim(); Program.gc.ClientPassword = this.txt_password.Text.Trim(); Program.gc.ForWeb = this.ddl_websites.SelectedValue.ToString(); GlobalClass.SetConfig(); GlobalClass sgc = new GlobalClass(this.ddl_websites.SelectedValue.ToString()); if (sgc.loadSucc) { Program.gc = sgc; //Program.gc.ForWeb = this.ddl_websites.SelectedValue.ToString(); //return; } CommunicateToServer cts = new CommunicateToServer(); CommResult cr = cts.Login(GlobalClass.strLoginUrlModel, this.txt_user.Text, this.txt_password.Text); if (cr == null) { this.Cursor = Cursors.Default; MessageBox.Show("无法返回对象!"); this.btn_login.Enabled = true; return; } if (cr.Succ == false) { this.Cursor = Cursors.Default; MessageBox.Show(cr.Message); this.btn_login.Enabled = true; return; } this.Cursor = Cursors.WaitCursor; this.Hide(); UserInfoClass ret = cr.Result[0] as UserInfoClass; Program.UserId = ret.BaseInfo.UserId; Program.gc.ClientUserName = ret.BaseInfo.UserCode; Program.gc.ClientPassword = ret.BaseInfo.Password; Program.gc.Odds = ret.BaseInfo.Odds; Program.gc.WXLogNoticeUser = ret.BaseInfo.WXToUser; Program.gc.ClientAliasName = string.IsNullOrEmpty(ret.BaseInfo.AliasName)?ret.BaseInfo.UserCode:ret.BaseInfo.AliasName; XmlDocument xmldoc = new XmlDocument(); try { string strXml = HttpUtility.UrlDecode(ret.BaseInfo.AssetConfig, Encoding.UTF8); xmldoc.LoadXml(strXml); XmlNodeList items = xmldoc.SelectNodes("config[@type='AssetUnits']/item"); Dictionary <string, AssetInfoConfig> assetconfig = new Dictionary <string, AssetInfoConfig>(); if (items.Count > 0) { for (int i = 0; i < items.Count; i++) { string key = items[i].SelectSingleNode("@key").Value; //int val = int.Parse(items[i].SelectSingleNode("@value").Value); //if (!assetconfig.ContainsKey(key)) // assetconfig.Add(key, val); AssetInfoConfig aic = new AssetInfoConfig(GlobalClass.readXmlItems(items[i].OuterXml)); if (!assetconfig.ContainsKey(key)) { assetconfig.Add(key, aic); } } } Program.gc.AssetUnits = assetconfig; } catch (Exception ce) { //return; } if (Program.gc.SvrConfigUrl != null)//获取服务器默认配置 { string strConfig = AccessWebServerClass.GetData(string.Format(Program.gc.SvrConfigUrl, Program.gc.InstHost), Encoding.UTF8); if (strConfig != null && strConfig.Trim().Length > 0) { SvrConfigClass scc = new SvrConfigClass().getObjectByJsonString(strConfig); if (scc.DefaultExchangeHost != null) { Program.gc.LoginDefaultHost = scc.DefaultExchangeHost; } if (scc.WXSvrHost != null) { Program.gc.WXSVRHost = scc.WXSvrHost; } if (scc.DefaultNavHost != null) { Program.gc.NavHost = scc.DefaultNavHost; } } } try { //Program.gc.LoginDefaultHost = WebRuleBuilder.Create(Program.gc).GetChanle(Program.gc.WebNavUrl, Program.gc.LoginDefaultHost); ; GlobalClass.SetConfig(Program.gc.ForWeb); this.Hide(); this.Cursor = Cursors.Default; //必须重新指定登录用户 Program.wxl = new WolfInv.com.LogLib.WXLogClass(Program.gc.ClientAliasName, Program.gc.WXLogNoticeUser, Program.gc.WXLogUrl); MainWindow mw = new MainWindow(); //testWeb mw = new testWeb(); DialogResult res = mw.ShowDialog(); //////while ( res == DialogResult.OK)//如果frm退出是因为要求重启 //////{ ////// if (mw.ForceReboot) ////// { ////// mw.ForceReboot = false; ////// Program.Reboot = false; ////// mw = new MainWindow(); ////// res = mw.ShowDialog(); ////// } ////// //GC.SuppressFinalize(frm); //////} Application.Exit(); } catch (Exception ce1) { MessageBox.Show(string.Format("{0}:{1}", ce1.Message, ce1.StackTrace)); } }
public string getUserInsts(GlobalClass setting, DataTypePoint dtp, string NewExpectNo, string forweb, Func <string, string, int, SelectTimeInstClass> getRemoteCnt) { string ret = ""; List <string> allTxt = new List <string>(); AmoutSerials amts = setting.DefaultHoldAmtSerials; for (int i = 0; i < this.Count; i++) { ChanceClass cc = this[i]; string strAssetId = cc.AssetId; int AssetCnt = 0; string strccNewInst = ""; if (cc.ChanceCode.Trim().Length == 0) { continue; } if (cc.UnitCost == 0) { continue; } string strCurrExpect = cc.ExpectCode; int calcHoldTimes = (int)DataReader.getInterExpectCnt(strCurrExpect, NewExpectNo, dtp); if (cc.HoldTimeCnt + 1 < calcHoldTimes) { continue; } if (!cc.Tracerable) //只要是非跟踪策略 { if (calcHoldTimes > 1) //和要下注的期数大于1就过滤,因为不要跟踪,只有当期才要下注 { continue; } } if (setting.AssetUnits.ContainsKey(strAssetId)) { AssetInfoConfig aic = setting.AssetUnits[strAssetId]; if (aic == null) { continue; } AssetCnt = aic.value; if (aic.NeedSelectTimes == 1) { int newVal = 0; if (SelectTimeDic == null) { SelectTimeDic = new Dictionary <string, int>(); } if (SelectTimeDic.ContainsKey(cc.GUID)) { newVal = SelectTimeDic[cc.GUID]; } else { SelectTimeInstClass obj = getSelectTimeAmt(dtp, cc.ExpectCode, AssetCnt, getRemoteCnt); if (obj == null) { continue; } newVal = obj.RetCnt; SelectTimeChanged?.Invoke(strAssetId, AssetCnt, obj); AssetCnt = obj.RetCnt; setting.AssetUnits[strAssetId].value = newVal; SelectTimeDic.Add(cc.GUID, newVal); } AssetCnt = newVal; } } //修改为自动计算出来的结果 //Int64 Amt = cc.UnitCost*setting.SerTotal(cc.ChipCount); int chips = cc.ChipCount - 1; int maxcnt = 1; if (amts.MaxHoldCnts.Length < chips)//只支持小注数策略,大注数全部使用1 { maxcnt = amts.MaxHoldCnts[chips]; } int bShift = 0; if (cc.HoldTimeCnt > maxcnt) { bShift = (int)maxcnt * 2 / 3; } int RCnt = (cc.HoldTimeCnt % (maxcnt + 1)) + bShift - 1; Int64 Amt = 1; if (amts.MaxHoldCnts.Length < chips) { Amt = amts.Serials[chips][RCnt] * AssetCnt; } if (cc.ChanceType != 2) //非对冲 { if (cc.ChanceType == 1) //一次性下注 { Amt = cc.UnitCost * setting.SerTotal(1) * AssetCnt; } strccNewInst = string.Format("{0}/{1}", cc.ChanceCode.Replace("+", string.Format("/{0}+", Amt)), Amt); } else { if (!setting.JoinHedge)//不参与对冲 { continue; } Amt = cc.UnitCost * setting.HedgeTimes * AssetCnt;//对冲倍数 if (setting.AllowHedge) { Int64 BaseAmt = cc.BaseCost * setting.HedgeTimes * AssetCnt; strccNewInst = string.Format("{0}/{1}+{2}/{3}", cc.ChanceCode, Amt + BaseAmt, ChanceClass.getRevChance(cc.ChanceCode), BaseAmt); } else { strccNewInst = string.Format("{0}/{1}", cc.ChanceCode, Amt); } } allTxt.Add(strccNewInst); } GlobalClass.SetConfig(forweb); return(string.Join(" ", allTxt.ToArray()).Trim()); }