public void Insert_to_proxyTableTest() { ProxyPageDetails ppd = new ProxyPageDetails(); ppd.profileName = "TestingProfile"; ppd.enableProxy = 0; Assert.AreEqual(DatabaseMessage.databaseError, Database_Helper.Insert_to_proxyTable(ppd)); }
/// <summary> /// retreives the first row from the proxy Table which contains the given 'profileName' /// </summary> /// <param name="profileName">profileName of which profile proxy page details desired</param> /// <returns>ProxyPageDetails instance containing retreived proxy page details</returns> public static ProxyPageDetails Readd_proxyTable(string profileName) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; SQLiteDataReader rdr = null; ProxyPageDetails ppd = new ProxyPageDetails(); try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM proxy WHERE profileName = @profileName"; cmd.Prepare(); cmd.Parameters.AddWithValue("@profileName", profileName); rdr = cmd.ExecuteReader(); if (!rdr.HasRows) return new ProxyPageDetails(); while (rdr.Read()) { ppd.profileName = rdr.GetString(0); ppd.enableProxy = rdr.GetBoolean(1) ? 1 : 0; if (rdr[2].Equals(DBNull.Value)) ppd.enableManual = -1; else ppd.enableManual = rdr.GetBoolean(2) ? 1 : 0; if (rdr[3].Equals(DBNull.Value)) ppd.sameProxy = -1; else ppd.sameProxy = rdr.GetBoolean(3) ? 1 : 0; if (rdr[4].Equals(DBNull.Value)) ppd.http = null; else ppd.http = rdr.GetString(4); if (rdr[5].Equals(DBNull.Value)) ppd.https = null; else ppd.https = rdr.GetString(5); if (rdr[6].Equals(DBNull.Value)) ppd.ftp = null; else ppd.ftp = rdr.GetString(6); if (rdr[7].Equals(DBNull.Value)) ppd.socks = null; else ppd.socks = rdr.GetString(7); if (rdr[8].Equals(DBNull.Value)) ppd.bypassProxy = -1; else ppd.bypassProxy = rdr.GetBoolean(8) ? 1 : 0; if (rdr[9].Equals(DBNull.Value)) ppd.enableScript = -1; else ppd.enableScript = rdr.GetBoolean(9) ? 1 : 0; if (rdr[10].Equals(DBNull.Value)) ppd.scriptURL = null; else ppd.scriptURL = rdr.GetString(10); if (rdr[11].Equals(DBNull.Value)) ppd.clearAtActivation = -1; else ppd.clearAtActivation = rdr.GetBoolean(11) ? 1 : 0; if (rdr[12].Equals(DBNull.Value)) ppd.autoDetect = -1; else ppd.autoDetect = rdr.GetBoolean(12) ? 1 : 0; if (rdr[13].Equals(DBNull.Value)) ppd.enableException = -1; else ppd.enableException = rdr.GetBoolean(13) ? 1 : 0; if (rdr[14].Equals(DBNull.Value)) ppd.exception = null; else ppd.exception = rdr.GetString(14); break; } return ppd; } catch (SQLiteException ex) { Console.WriteLine("Error: {0}", ex.ToString()); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return new ProxyPageDetails(); } finally { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } } }
/// <summary> /// Insert the given proxypage details in to the proxy Table in database /// </summary> /// <param name="ppd">ProxyPageDetails instance containig proxy page details</param> /// <returns>DatabaseMessage</returns> public static DatabaseMessage Insert_to_proxyTable(ProxyPageDetails ppd) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmdPrf = new SQLiteCommand(); cmdPrf.Connection = conn; cmdPrf.CommandText = "INSERT INTO proxy(profileName, enableProxy, enableManual, sameProxy, http, https, ftp, socks, byPassProxyForLocal, enableScript, scriptURL, clearAtActivation, autoDetect, enableException, exception) VALUES (@profileName, @enableProxy, @enableManual, @sameProxy, @http, @https, @ftp, @socks, @byPassProxyForLocal, @enableScript, @scriptURL, @clearAtActivation, @autoDetect, @enableException, @exception)"; cmdPrf.Prepare(); if (string.IsNullOrEmpty(ppd.profileName)) return DatabaseMessage.noProfileNameError; else { cmdPrf.Parameters.AddWithValue("@profileName", ppd.profileName); if (ppd.enableProxy == -1) return DatabaseMessage.proxyenableUnassignedError; else cmdPrf.Parameters.AddWithValue("@enableProxy", ppd.enableProxy == 1 ? true : false); if (ppd.enableManual == -1) cmdPrf.Parameters.AddWithValue("@enableManual", null); else cmdPrf.Parameters.AddWithValue("@enableManual", ppd.enableManual == 1 ? true : false); if (ppd.sameProxy == -1) cmdPrf.Parameters.AddWithValue("@sameProxy", null); else cmdPrf.Parameters.AddWithValue("@sameProxy", ppd.sameProxy == 1 ? true : false); if (string.IsNullOrEmpty(ppd.http)) cmdPrf.Parameters.AddWithValue("@http", null); else cmdPrf.Parameters.AddWithValue("@http", ppd.http); if (string.IsNullOrEmpty(ppd.https)) cmdPrf.Parameters.AddWithValue("@https", null); else cmdPrf.Parameters.AddWithValue("@https", ppd.https); if (string.IsNullOrEmpty(ppd.ftp)) cmdPrf.Parameters.AddWithValue("@ftp", null); else cmdPrf.Parameters.AddWithValue("@ftp", ppd.ftp); if (string.IsNullOrEmpty(ppd.socks)) cmdPrf.Parameters.AddWithValue("@socks", null); else cmdPrf.Parameters.AddWithValue("@socks", ppd.socks); if (ppd.bypassProxy == -1) cmdPrf.Parameters.AddWithValue("@byPassProxyForLocal", null); else cmdPrf.Parameters.AddWithValue("@byPassProxyForLocal", ppd.bypassProxy == 1 ? true : false); if (ppd.enableScript == -1) cmdPrf.Parameters.AddWithValue("@enableScript", null); else cmdPrf.Parameters.AddWithValue("@enableScript", ppd.enableScript == 1 ? true : false); if (string.IsNullOrEmpty(ppd.scriptURL)) cmdPrf.Parameters.AddWithValue("@scriptURL", null); else cmdPrf.Parameters.AddWithValue("@scriptURL", ppd.scriptURL); if (ppd.clearAtActivation == -1) cmdPrf.Parameters.AddWithValue("@clearAtActivation", null); else cmdPrf.Parameters.AddWithValue("@clearAtActivation", ppd.clearAtActivation == 1 ? true : false); if (ppd.autoDetect == -1) cmdPrf.Parameters.AddWithValue("@autoDetect", null); else cmdPrf.Parameters.AddWithValue("@autoDetect", ppd.autoDetect == 1 ? true : false); if (ppd.enableException == -1) cmdPrf.Parameters.AddWithValue("@enableException", null); else cmdPrf.Parameters.AddWithValue("@enableException", ppd.enableException == 1 ? true : false); if (string.IsNullOrEmpty(ppd.exception)) cmdPrf.Parameters.AddWithValue("@exception", null); else cmdPrf.Parameters.AddWithValue("@exception", ppd.exception); } cmdPrf.ExecuteNonQuery(); if (conn != null) { conn.Close(); } return DatabaseMessage.successfulInsertion; } catch (SQLiteException ex) { Console.WriteLine("Error: {0}", ex.ToString()); if (conn != null) { conn.Close(); } return DatabaseMessage.databaseError; } finally { if (conn != null) { conn.Close(); } } }
private void AddProfile_Button_Click(object sender, EventArgs e) { #region collec Network page details NetworkPageDetails npd = new NetworkPageDetails(); npd.profileName =ProfileSelection_ComboBox.Text; if (enableDHCP_radioButton.Checked) { npd.dhcp = 1; npd.manual = 0; } else if (enableManualIP_radioButton.Checked) { npd.dhcp = 0; npd.manual = 1; //set manual IPAddressing npd.nicName = NetworkCard_comboBox.Text; npd.ipAddress = IPAddress_textBox.Text; npd.subnetMask = subnetMask_textBox.Text; npd.gateway = gateway_textBox.Text; npd.dnsServer = DNSSever_textBox.Text; } #endregion #region collect Proxy page Details ProxyPageDetails ppd = new ProxyPageDetails(); ppd.profileName = ProfileSelection_ComboBox.Text; ppd.enableProxy = enableProxy_checkBox.Checked ? 1 : 0; ppd.enableManual = manualProxy_radioButton.Checked ? 1 : 0; if (!(string.IsNullOrEmpty(HTTP_textBox.Text) || string.IsNullOrEmpty(HTTPport_textBox.Text))) ppd.http = HTTP_textBox.Text + ":" + HTTPport_textBox.Text; if (!(string.IsNullOrEmpty(secure_textBox.Text) || string.IsNullOrEmpty(securePort_textBox.Text))) ppd.https = secure_textBox.Text + ":" + securePort_textBox.Text; if (!(string.IsNullOrEmpty(FTP_textBox.Text) || string.IsNullOrEmpty(FTPport_textBox.Text))) ppd.ftp = FTP_textBox.Text + ":" + FTPport_textBox.Text; if (!(string.IsNullOrEmpty(socks_textBox.Text) || string.IsNullOrEmpty(socksPort_textBox.Text))) ppd.socks = socks_textBox.Text + ":" + socksPort_textBox.Text; ppd.sameProxy = sameProxyForAllProtocols_checkBox.Checked ? 1 : 0; ppd.bypassProxy = byPassProxyForLocalAddrss_checkBox.Checked ? 1 : 0; ppd.enableScript = automaticProxyScript_radioButton.Checked ? 1 : 0; if (!string.IsNullOrEmpty(scriptURL_textBox.Text)) ppd.scriptURL = scriptURL_textBox.Text; ppd.clearAtActivation = clearProxyAtActivation_radioButton.Checked ? 1 : 0; ppd.autoDetect = autoProxyDetection_checkBox.Checked ? 1 : 0; ppd.enableException = enableProxyExceptions_checkBox.Checked ? 1 : 0; if (!string.IsNullOrEmpty(proxyExceptions_textBox.Text)) ppd.exception = proxyExceptions_textBox.Text; #endregion #region remarks string remark = string.Empty; if (!string.IsNullOrEmpty(remarks_textBox.Text)) { remark = remarks_textBox.Text; } #endregion if (string.IsNullOrEmpty(npd.profileName) || string.IsNullOrEmpty(ppd.profileName) || !ppd.profileName.Equals(npd.profileName)) { MessageBox.Show("profile name null or empty..!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (RemoveProfile_Button.Enabled) { DialogResult dialogResult = MessageBox.Show("are you sure, you want to change existing settings?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.No) { return; } } Database_Helper.DeleteIfExist_NetworkPage(npd.profileName); Database_Helper.DeleteIfExist_ProxyPage(ppd.profileName); Database_Helper.Insert_to_networkTable(npd); Database_Helper.Insert_to_proxyTable(ppd); Database_Helper.deleteRemarkIfExist(ProfileSelection_ComboBox.Text); Database_Helper.saveRemarks(ProfileSelection_ComboBox.Text, remark); MessageBox.Show("successfully added..!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// retreives the first row from the proxy Table which contains the given 'profileName' /// </summary> /// <param name="profileName">profileName of which profile proxy page details desired</param> /// <returns>ProxyPageDetails instance containing retreived proxy page details</returns> public static ProxyPageDetails Readd_proxyTable(string profileName) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; SQLiteDataReader rdr = null; ProxyPageDetails ppd = new ProxyPageDetails(); try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM proxy WHERE profileName = @profileName"; cmd.Prepare(); cmd.Parameters.AddWithValue("@profileName", profileName); rdr = cmd.ExecuteReader(); if (!rdr.HasRows) { return(new ProxyPageDetails()); } while (rdr.Read()) { ppd.profileName = rdr.GetString(0); ppd.enableProxy = rdr.GetBoolean(1) ? 1 : 0; if (rdr[2].Equals(DBNull.Value)) { ppd.enableManual = -1; } else { ppd.enableManual = rdr.GetBoolean(2) ? 1 : 0; } if (rdr[3].Equals(DBNull.Value)) { ppd.sameProxy = -1; } else { ppd.sameProxy = rdr.GetBoolean(3) ? 1 : 0; } if (rdr[4].Equals(DBNull.Value)) { ppd.http = null; } else { ppd.http = rdr.GetString(4); } if (rdr[5].Equals(DBNull.Value)) { ppd.https = null; } else { ppd.https = rdr.GetString(5); } if (rdr[6].Equals(DBNull.Value)) { ppd.ftp = null; } else { ppd.ftp = rdr.GetString(6); } if (rdr[7].Equals(DBNull.Value)) { ppd.socks = null; } else { ppd.socks = rdr.GetString(7); } if (rdr[8].Equals(DBNull.Value)) { ppd.bypassProxy = -1; } else { ppd.bypassProxy = rdr.GetBoolean(8) ? 1 : 0; } if (rdr[9].Equals(DBNull.Value)) { ppd.enableScript = -1; } else { ppd.enableScript = rdr.GetBoolean(9) ? 1 : 0; } if (rdr[10].Equals(DBNull.Value)) { ppd.scriptURL = null; } else { ppd.scriptURL = rdr.GetString(10); } if (rdr[11].Equals(DBNull.Value)) { ppd.clearAtActivation = -1; } else { ppd.clearAtActivation = rdr.GetBoolean(11) ? 1 : 0; } if (rdr[12].Equals(DBNull.Value)) { ppd.autoDetect = -1; } else { ppd.autoDetect = rdr.GetBoolean(12) ? 1 : 0; } if (rdr[13].Equals(DBNull.Value)) { ppd.enableException = -1; } else { ppd.enableException = rdr.GetBoolean(13) ? 1 : 0; } if (rdr[14].Equals(DBNull.Value)) { ppd.exception = null; } else { ppd.exception = rdr.GetString(14); } break; } return(ppd); } catch (SQLiteException ex) { Console.WriteLine("Error: {0}", ex.ToString()); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(new ProxyPageDetails()); } finally { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } } }
/// <summary> /// Insert the given proxypage details in to the proxy Table in database /// </summary> /// <param name="ppd">ProxyPageDetails instance containig proxy page details</param> /// <returns>DatabaseMessage</returns> public static DatabaseMessage Insert_to_proxyTable(ProxyPageDetails ppd) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmdPrf = new SQLiteCommand(); cmdPrf.Connection = conn; cmdPrf.CommandText = "INSERT INTO proxy(profileName, enableProxy, enableManual, sameProxy, http, https, ftp, socks, byPassProxyForLocal, enableScript, scriptURL, clearAtActivation, autoDetect, enableException, exception) VALUES (@profileName, @enableProxy, @enableManual, @sameProxy, @http, @https, @ftp, @socks, @byPassProxyForLocal, @enableScript, @scriptURL, @clearAtActivation, @autoDetect, @enableException, @exception)"; cmdPrf.Prepare(); if (string.IsNullOrEmpty(ppd.profileName)) { return(DatabaseMessage.noProfileNameError); } else { cmdPrf.Parameters.AddWithValue("@profileName", ppd.profileName); if (ppd.enableProxy == -1) { return(DatabaseMessage.proxyenableUnassignedError); } else { cmdPrf.Parameters.AddWithValue("@enableProxy", ppd.enableProxy == 1 ? true : false); } if (ppd.enableManual == -1) { cmdPrf.Parameters.AddWithValue("@enableManual", null); } else { cmdPrf.Parameters.AddWithValue("@enableManual", ppd.enableManual == 1 ? true : false); } if (ppd.sameProxy == -1) { cmdPrf.Parameters.AddWithValue("@sameProxy", null); } else { cmdPrf.Parameters.AddWithValue("@sameProxy", ppd.sameProxy == 1 ? true : false); } if (string.IsNullOrEmpty(ppd.http)) { cmdPrf.Parameters.AddWithValue("@http", null); } else { cmdPrf.Parameters.AddWithValue("@http", ppd.http); } if (string.IsNullOrEmpty(ppd.https)) { cmdPrf.Parameters.AddWithValue("@https", null); } else { cmdPrf.Parameters.AddWithValue("@https", ppd.https); } if (string.IsNullOrEmpty(ppd.ftp)) { cmdPrf.Parameters.AddWithValue("@ftp", null); } else { cmdPrf.Parameters.AddWithValue("@ftp", ppd.ftp); } if (string.IsNullOrEmpty(ppd.socks)) { cmdPrf.Parameters.AddWithValue("@socks", null); } else { cmdPrf.Parameters.AddWithValue("@socks", ppd.socks); } if (ppd.bypassProxy == -1) { cmdPrf.Parameters.AddWithValue("@byPassProxyForLocal", null); } else { cmdPrf.Parameters.AddWithValue("@byPassProxyForLocal", ppd.bypassProxy == 1 ? true : false); } if (ppd.enableScript == -1) { cmdPrf.Parameters.AddWithValue("@enableScript", null); } else { cmdPrf.Parameters.AddWithValue("@enableScript", ppd.enableScript == 1 ? true : false); } if (string.IsNullOrEmpty(ppd.scriptURL)) { cmdPrf.Parameters.AddWithValue("@scriptURL", null); } else { cmdPrf.Parameters.AddWithValue("@scriptURL", ppd.scriptURL); } if (ppd.clearAtActivation == -1) { cmdPrf.Parameters.AddWithValue("@clearAtActivation", null); } else { cmdPrf.Parameters.AddWithValue("@clearAtActivation", ppd.clearAtActivation == 1 ? true : false); } if (ppd.autoDetect == -1) { cmdPrf.Parameters.AddWithValue("@autoDetect", null); } else { cmdPrf.Parameters.AddWithValue("@autoDetect", ppd.autoDetect == 1 ? true : false); } if (ppd.enableException == -1) { cmdPrf.Parameters.AddWithValue("@enableException", null); } else { cmdPrf.Parameters.AddWithValue("@enableException", ppd.enableException == 1 ? true : false); } if (string.IsNullOrEmpty(ppd.exception)) { cmdPrf.Parameters.AddWithValue("@exception", null); } else { cmdPrf.Parameters.AddWithValue("@exception", ppd.exception); } } cmdPrf.ExecuteNonQuery(); if (conn != null) { conn.Close(); } return(DatabaseMessage.successfulInsertion); } catch (SQLiteException ex) { Console.WriteLine("Error: {0}", ex.ToString()); if (conn != null) { conn.Close(); } return(DatabaseMessage.databaseError); } finally { if (conn != null) { conn.Close(); } } }