/// <summary> /// 加载代理信息 /// </summary> private void LoadProxyInfo() { ComboBoxA cbProxyType = GetComboBox("cbProxyType"); TextBoxA txtProxyIP = GetTextBox("txtProxyIP"); SpinA spinProxyPort = GetSpin("spinProxyPort"); TextBoxA txtProxyUserName = GetTextBox("txtProxyUserName"); TextBoxA txtProxyUserPwd = GetTextBox("txtProxyUserPwd"); TextBoxA txtProxyDomain = GetTextBox("txtProxyDomain"); List <ProxyInfo> proxyInfos = new List <ProxyInfo>(); m_proxyService.GetProxyInfos(proxyInfos); int proxyInfosSize = proxyInfos.Count; for (int i = 0; i < proxyInfosSize; i++) { ProxyInfo proxyInfo = proxyInfos[i]; if (cbProxyType.SelectedIndex == proxyInfo.m_type) { txtProxyIP.Enabled = (proxyInfo.m_type == 1 || proxyInfo.m_type == 2); spinProxyPort.Enabled = (proxyInfo.m_type == 1 || proxyInfo.m_type == 2); txtProxyUserName.Enabled = (proxyInfo.m_type == 1 || proxyInfo.m_type == 2 || proxyInfo.m_type == 3); txtProxyUserPwd.Enabled = (proxyInfo.m_type == 1 || proxyInfo.m_type == 2 || proxyInfo.m_type == 3); txtProxyDomain.Enabled = proxyInfo.m_type == 2; txtProxyIP.Text = proxyInfo.m_ip; spinProxyPort.Value = proxyInfo.m_port; txtProxyUserName.Text = proxyInfo.m_name; txtProxyUserPwd.Text = proxyInfo.m_pwd; txtProxyDomain.Text = proxyInfo.m_domain; break; } } m_window.Invalidate(); proxyInfos.Clear(); }
/// <summary> /// 获取代理信息 /// </summary> /// <param name="proxyInfos">代理信息列表</param> /// <returns>状态</returns> public int GetProxyInfos(List <ProxyInfo> proxyInfos) { String sql = "SELECT * FROM PROXYINFOS"; SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { ProxyInfo proxyInfo = new ProxyInfo(); proxyInfo.m_type = reader.GetInt32(0); proxyInfo.m_ip = reader.GetString(1); proxyInfo.m_port = reader.GetInt32(2); proxyInfo.m_name = reader.GetString(3); proxyInfo.m_pwd = reader.GetString(4); proxyInfo.m_domain = reader.GetString(5); proxyInfo.m_use = reader.GetInt32(6) == 1; proxyInfos.Add(proxyInfo); } reader.Close(); conn.Close(); return(1); }
/// <summary> /// 加载数据 /// </summary> public override void LoadData() { //加载连接信息 List <ConnectInfo> connectInfos = new List <ConnectInfo>(); m_connectServer.GetConnects(connectInfos); int connectInfosSize = connectInfos.Count; for (int i = 0; i < connectInfosSize; i++) { ConnectInfo connectInfo = connectInfos[i]; String type = connectInfo.m_type; if (type == "主服务器") { m_cbMainServerIP.Text = connectInfo.m_ip; m_txtMainServerPort.Value = connectInfo.m_port; } } ComboBoxA cbProxyType = GetComboBox("cbProxyType"); List <ProxyInfo> proxyInfos = new List <ProxyInfo>(); m_proxyService.GetProxyInfos(proxyInfos); int proxyInfosSize = proxyInfos.Count; for (int i = 0; i < proxyInfosSize; i++) { ProxyInfo proxyInfo = proxyInfos[i]; if (proxyInfo.m_use) { cbProxyType.SelectedIndex = proxyInfo.m_type; } } }
/// <summary> /// 保存配置 /// </summary> private void SaveData() { List <ConnectInfo> connectInfos = new List <ConnectInfo>(); m_connectServer.GetConnects(connectInfos); int connectInfosSize = connectInfos.Count; for (int i = 0; i < connectInfosSize; i++) { ConnectInfo connectInfo = connectInfos[i]; String type = connectInfo.m_type; if (type == "主服务器") { connectInfo.m_ip = m_cbMainServerIP.Text; connectInfo.m_port = CStr.ConvertStrToInt(m_txtMainServerPort.Text); } m_connectServer.UpdateConnect(connectInfo); } connectInfos.Clear(); //保存代理信息 ComboBoxA cbProxyType = GetComboBox("cbProxyType"); TextBoxA txtProxyIP = GetTextBox("txtProxyIP"); SpinA spinProxyPort = GetSpin("spinProxyPort"); TextBoxA txtProxyUserName = GetTextBox("txtProxyUserName"); TextBoxA txtProxyUserPwd = GetTextBox("txtProxyUserPwd"); TextBoxA txtProxyDomain = GetTextBox("txtProxyDomain"); ProxyInfo proxyInfo = new ProxyInfo(); proxyInfo.m_domain = txtProxyDomain.Text; proxyInfo.m_ip = txtProxyIP.Text; proxyInfo.m_port = (int)spinProxyPort.Value; proxyInfo.m_name = txtProxyUserName.Text; proxyInfo.m_pwd = txtProxyUserPwd.Text; proxyInfo.m_type = cbProxyType.SelectedIndex; proxyInfo.m_use = true; List <ProxyInfo> proxyInfos = new List <ProxyInfo>(); m_proxyService.GetProxyInfos(proxyInfos); int proxyInfosSize = proxyInfos.Count; for (int i = 0; i < proxyInfosSize; i++) { ProxyInfo pInfo = proxyInfos[i]; if (cbProxyType.SelectedIndex == pInfo.m_type) { m_proxyService.UpdateConnect(proxyInfo); } else { pInfo.m_use = false; m_proxyService.UpdateConnect(pInfo); } } }
/// <summary> /// 更新代理信息 /// </summary> /// <param name="proxyInfo">代理信息</param> /// <returns>状态</returns> public int UpdateConnect(ProxyInfo proxyInfo) { String sql = String.Format("UPDATE PROXYINFOS SET IP = '{0}', PORT = {1}, NAME = '{2}', PASSWORD = '******', DOMAIN='{4}', USE = {5} WHERE TYPE = {6}", CStrA.GetDBString(proxyInfo.m_ip), proxyInfo.m_port, CStrA.GetDBString(proxyInfo.m_name), CStrA.GetDBString(proxyInfo.m_pwd), CStrA.GetDBString(proxyInfo.m_domain), proxyInfo.m_use ? 1 : 0, proxyInfo.m_type); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 添加代理信息 /// </summary> /// <param name="proxyInfo">代理信息</param> /// <returns>状态</returns> public int AddProxyInfo(ProxyInfo proxyInfo) { String sql = String.Format("INSERT INTO PROXYINFOS(TYPE, IP, PORT, NAME, PASSWORD, DOMAIN, USE) values ({0},'{1}',{2},'{3}','{4}','{5}',{6})", proxyInfo.m_type, CStrA.GetDBString(proxyInfo.m_ip), proxyInfo.m_port, CStrA.GetDBString(proxyInfo.m_name), CStrA.GetDBString(proxyInfo.m_pwd), CStrA.GetDBString(proxyInfo.m_domain), proxyInfo.m_use ? 1 : 0); SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 创建默认的代理信息 /// </summary> public void CreateDefaultProxyInfos() { ProxyInfo proxyInfo1 = new ProxyInfo(); proxyInfo1.m_use = true; AddProxyInfo(proxyInfo1); ProxyInfo proxyInfo2 = new ProxyInfo(); proxyInfo2.m_type = 1; AddProxyInfo(proxyInfo2); ProxyInfo proxyInfo3 = new ProxyInfo(); proxyInfo3.m_type = 2; AddProxyInfo(proxyInfo3); ProxyInfo proxyInfo4 = new ProxyInfo(); proxyInfo4.m_type = 3; AddProxyInfo(proxyInfo4); }
/// <summary> /// 连接到服务器 /// </summary> /// <returns>状态</returns> public static int Connect() { int socketID = -1; int qtSocketID = -1; List <ConnectInfo> connectInfos = new List <ConnectInfo>(); m_connectService.GetConnects(connectInfos); int connectInfosSize = connectInfos.Count; for (int i = 0; i < connectInfosSize; i++) { ConnectInfo connectInfo = connectInfos[i]; if (connectInfo.m_type == "主服务器") { List <ProxyInfo> proxyInfos = new List <ProxyInfo>(); m_proxyService.GetProxyInfos(proxyInfos); int proxyInfosSize = proxyInfos.Count; for (int j = 0; j < proxyInfosSize; j++) { ProxyInfo pInfo = proxyInfos[i]; if (pInfo.m_use) { String ip = connectInfo.m_ip, proxyIP = "", proxyUserName = pInfo.m_name, proxyPwd = pInfo.m_pwd, proxyDomain = pInfo.m_domain; int proxyPort = pInfo.m_port; if (pInfo.m_type == 3) { //CurlHttp *http = CurlHttp::GetInstance(); //http->GetIeProxySet(&proxyIP, &proxyPort); } else { proxyIP = pInfo.m_ip; } int cType = 0; if (pInfo.m_type == 1 || pInfo.m_type == 3) { cType = 1; } else if (pInfo.m_type == 2) { cType = 3; } socketID = BaseService.ConnectToServer(0, cType, ip, connectInfo.m_port, proxyIP, proxyPort, proxyUserName, proxyPwd, proxyDomain, 6); qtSocketID = BaseService.ConnectToServer(0, cType, ip, connectInfo.m_port, proxyIP, proxyPort, proxyUserName, proxyPwd, proxyDomain, 6); break; } } } } if (socketID > 0) { m_connectState = 1; m_loginService.SocketID = socketID; m_indicatorService.SocketID = socketID; m_quoteService.SocketID = qtSocketID; m_securityService.SocketID = socketID; m_chatService.SocketID = socketID; m_indicatorLayoutService.SocketID = socketID; m_macroService.SocketID = socketID; m_securityFilterService.SocketID = socketID; m_userSecurityService.SocketID = socketID; m_userSessionService.SocketID = socketID; } return(socketID); }