/// <summary> /// retreives the first row from the network Table which contains the given 'profileName' /// </summary> /// <param name="profileName">profileName of which profile network page details desired</param> /// <returns>NetworkPageDetails instance containing retreived network page details</returns> public static NetworkPageDetails Read_networkTable(string profileName) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; SQLiteDataReader rdr = null; NetworkPageDetails npd = new NetworkPageDetails(); try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM network WHERE profileName = @profileName"; cmd.Prepare(); cmd.Parameters.AddWithValue("@profileName", profileName); rdr = cmd.ExecuteReader(); if (!rdr.HasRows) return new NetworkPageDetails(); while (rdr.Read()) { npd.profileName = rdr.GetString(0); if (rdr[1].Equals(DBNull.Value)) npd.nicName = null; else npd.nicName = rdr.GetString(1); if (rdr[2].Equals(DBNull.Value)) npd.dhcp = -1; else npd.dhcp = rdr.GetBoolean(2) ? 1 : 0; if (rdr[3].Equals(DBNull.Value)) npd.manual = -1; else npd.manual = rdr.GetBoolean(3) ? 1 : 0; if (rdr[4].Equals(DBNull.Value)) npd.ipAddress = null; else npd.ipAddress = rdr.GetString(4); if (rdr[5].Equals(DBNull.Value)) npd.subnetMask = null; else npd.subnetMask = rdr.GetString(5); if (rdr[6].Equals(DBNull.Value)) npd.gateway = null; else npd.gateway = rdr.GetString(6); if (rdr[7].Equals(DBNull.Value)) npd.dnsServer = null; else npd.dnsServer = rdr.GetString(7); break; } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return npd; } catch (SQLiteException ex) { Console.WriteLine("Error: {0}", ex.ToString()); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return new NetworkPageDetails(); } finally { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } } }
/// <summary> /// Insert the given networkpage details in to the network Table in database /// </summary> /// <param name="npd">NetworkPageDetails instance containig network page details</param> /// <returns>DatabaseMessage</returns> public static DatabaseMessage Insert_to_networkTable(NetworkPageDetails npd) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO network(profileName, nicName, dhcp, manual, ipAddress, subnetMask, gateway, dnsServer) VALUES(@profileName, @nicName, @dhcp, @manual, @ipAddress, @subnetMask, @gateway, @dnsServer)"; cmd.Prepare(); if (string.IsNullOrEmpty(npd.profileName)) return DatabaseMessage.noProfileNameError; else { cmd.Parameters.AddWithValue("@profileName", npd.profileName); if (string.IsNullOrEmpty(npd.nicName)) cmd.Parameters.AddWithValue("@nicName", null); else cmd.Parameters.AddWithValue("@nicName", npd.nicName); if (npd.dhcp == -1) cmd.Parameters.AddWithValue("@dhcp", null); else cmd.Parameters.AddWithValue("@dhcp", npd.dhcp == 1 ? true : false); if (npd.manual == -1) cmd.Parameters.AddWithValue("@manual", null); else cmd.Parameters.AddWithValue("@manual", npd.manual == 1 ? true : false); if (string.IsNullOrEmpty(npd.ipAddress)) cmd.Parameters.AddWithValue("@ipAddress", null); else cmd.Parameters.AddWithValue("@ipAddress", npd.ipAddress); if (string.IsNullOrEmpty(npd.subnetMask)) cmd.Parameters.AddWithValue("@subnetMask", null); else cmd.Parameters.AddWithValue("@subnetMask", npd.subnetMask); if (string.IsNullOrEmpty(npd.gateway)) cmd.Parameters.AddWithValue("@gateway", null); else cmd.Parameters.AddWithValue("@gateway", npd.gateway); if (string.IsNullOrEmpty(npd.dnsServer)) cmd.Parameters.AddWithValue("@dnsServer", null); else cmd.Parameters.AddWithValue("@dnsServer", npd.dnsServer); } cmd.ExecuteNonQuery(); //ExecuteNonQuery used since no return expected 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); }
public void Insert_to_networkTableTest() { NetworkPageDetails npd = new NetworkPageDetails(); npd.profileName = "TestingProfile"; Assert.AreEqual(DatabaseMessage.databaseError, Database_Helper.Insert_to_networkTable(npd)); }
/// <summary> /// Insert the given networkpage details in to the network Table in database /// </summary> /// <param name="npd">NetworkPageDetails instance containig network page details</param> /// <returns>DatabaseMessage</returns> public static DatabaseMessage Insert_to_networkTable(NetworkPageDetails npd) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; cmd.CommandText = "INSERT INTO network(profileName, nicName, dhcp, manual, ipAddress, subnetMask, gateway, dnsServer) VALUES(@profileName, @nicName, @dhcp, @manual, @ipAddress, @subnetMask, @gateway, @dnsServer)"; cmd.Prepare(); if (string.IsNullOrEmpty(npd.profileName)) { return(DatabaseMessage.noProfileNameError); } else { cmd.Parameters.AddWithValue("@profileName", npd.profileName); if (string.IsNullOrEmpty(npd.nicName)) { cmd.Parameters.AddWithValue("@nicName", null); } else { cmd.Parameters.AddWithValue("@nicName", npd.nicName); } if (npd.dhcp == -1) { cmd.Parameters.AddWithValue("@dhcp", null); } else { cmd.Parameters.AddWithValue("@dhcp", npd.dhcp == 1 ? true : false); } if (npd.manual == -1) { cmd.Parameters.AddWithValue("@manual", null); } else { cmd.Parameters.AddWithValue("@manual", npd.manual == 1 ? true : false); } if (string.IsNullOrEmpty(npd.ipAddress)) { cmd.Parameters.AddWithValue("@ipAddress", null); } else { cmd.Parameters.AddWithValue("@ipAddress", npd.ipAddress); } if (string.IsNullOrEmpty(npd.subnetMask)) { cmd.Parameters.AddWithValue("@subnetMask", null); } else { cmd.Parameters.AddWithValue("@subnetMask", npd.subnetMask); } if (string.IsNullOrEmpty(npd.gateway)) { cmd.Parameters.AddWithValue("@gateway", null); } else { cmd.Parameters.AddWithValue("@gateway", npd.gateway); } if (string.IsNullOrEmpty(npd.dnsServer)) { cmd.Parameters.AddWithValue("@dnsServer", null); } else { cmd.Parameters.AddWithValue("@dnsServer", npd.dnsServer); } } cmd.ExecuteNonQuery(); //ExecuteNonQuery used since no return expected 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(); } } }
/// <summary> /// retreives the first row from the network Table which contains the given 'profileName' /// </summary> /// <param name="profileName">profileName of which profile network page details desired</param> /// <returns>NetworkPageDetails instance containing retreived network page details</returns> public static NetworkPageDetails Read_networkTable(string profileName) { string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString; SQLiteConnection conn = null; SQLiteDataReader rdr = null; NetworkPageDetails npd = new NetworkPageDetails(); try { conn = new SQLiteConnection(ConString); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT * FROM network WHERE profileName = @profileName"; cmd.Prepare(); cmd.Parameters.AddWithValue("@profileName", profileName); rdr = cmd.ExecuteReader(); if (!rdr.HasRows) { return(new NetworkPageDetails()); } while (rdr.Read()) { npd.profileName = rdr.GetString(0); if (rdr[1].Equals(DBNull.Value)) { npd.nicName = null; } else { npd.nicName = rdr.GetString(1); } if (rdr[2].Equals(DBNull.Value)) { npd.dhcp = -1; } else { npd.dhcp = rdr.GetBoolean(2) ? 1 : 0; } if (rdr[3].Equals(DBNull.Value)) { npd.manual = -1; } else { npd.manual = rdr.GetBoolean(3) ? 1 : 0; } if (rdr[4].Equals(DBNull.Value)) { npd.ipAddress = null; } else { npd.ipAddress = rdr.GetString(4); } if (rdr[5].Equals(DBNull.Value)) { npd.subnetMask = null; } else { npd.subnetMask = rdr.GetString(5); } if (rdr[6].Equals(DBNull.Value)) { npd.gateway = null; } else { npd.gateway = rdr.GetString(6); } if (rdr[7].Equals(DBNull.Value)) { npd.dnsServer = null; } else { npd.dnsServer = rdr.GetString(7); } break; } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(npd); } catch (SQLiteException ex) { Console.WriteLine("Error: {0}", ex.ToString()); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return(new NetworkPageDetails()); } finally { if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } } }