//取消代理 private void btnCancel_Click(object sender, EventArgs e) { if (ProxySetting.UnsetProxy()) { lalMsg.ForeColor = Color.Black; lalMsg.Text = "已取消代理."; } else { lalMsg.ForeColor = Color.Red; lalMsg.Text = "取消代理失败."; } }
//应用代理 private void btnApply_Click(object sender, EventArgs e) { string ip = dataGridView.CurrentCell.OwningRow.Cells["地址"].Value.ToString(); string port = dataGridView.CurrentCell.OwningRow.Cells["端口"].Value.ToString(); if (ProxySetting.SetProxy(ip + ":" + port)) { lalMsg.ForeColor = Color.Black; lalMsg.Text = "已设置代理:" + ip + ":" + port; } else { lalMsg.ForeColor = Color.Red; lalMsg.Text = "设置代理失败. 原因:无效IP和端口."; } }
//窗口加载 private void Form1_Load(object sender, EventArgs e) { //读取是否已经设置代理 if (ProxySetting.UsedProxy()) { lalMsg.ForeColor = Color.Black; lalMsg.Text = "当前正在使用代理:" + ProxySetting.GetProxyProxyServer(); } else { lalMsg.ForeColor = Color.Black; lalMsg.Text = "当前没有使用代理."; } //判断数据库是否已存在 if (File.Exists(dbFileName) == false) { Console.WriteLine("数据库文件不存在"); //open/create the database sqlite.OpenDatabase(dbFileName); //创建Proxy表 string sql = "CREATE TABLE Proxy(ProxyName varchar(20) unique, IP varchar(20), Port varchar(10))"; sqlite.ExecuteNonQuery(sql); //添加一个代理 sql = "INSERT INTO Proxy VALUES('108', '10.108.12.56', '8085')"; sqlite.ExecuteNonQuery(sql); } //初始化dataGridView dataGridView.RowHeadersWidth = 30; dataGridView.ColumnCount = 3; dataGridView.Columns[0].Name = "名称"; dataGridView.Columns[1].Name = "地址"; dataGridView.Columns[2].Name = "端口"; dataGridView.Columns[2].Width = 88; //加载数据(代理) LoadData(); }