예제 #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (txtInstance.Text != "" && txtDatabase.Text != "" && txtLogin.Text != "" && txtPassword.Text != "")
            {
                btnConnect.Enabled       = false;
                txtDatabase.Enabled      = false;
                txtInstance.Enabled      = false;
                txtLogin.Enabled         = false;
                txtPassword.Enabled      = false;
                ckbxSQL_DirectIP.Enabled = false;
                btnConnect.Text          = "Please wait";

                SQLConnect.dataSource     = txtInstance.Text;
                SQLConnect.initialCatalog = txtDatabase.Text;
                SQLConnect.userID         = txtLogin.Text;
                SQLConnect.password       = txtPassword.Text;
                SQLConnect.useIPAdress    = ckbxSQL_DirectIP.Checked;

                try
                {
                    DataSource     = txtInstance.Text;
                    InitialCatalog = txtDatabase.Text;

                    SqlConnection sqlConnString = new SqlConnection("Data Source=" + SQLConnect.dataSource + ";Initial Catalog=" + SQLConnect.initialCatalog + ";User ID=" + SQLConnect.userID + ";Password="******";Connect Timeout = 10;");

                    if (SQLConnect.useIPAdress == true)
                    {
                        IPAddress ip = new IPHelper().get_ip_from_host_name(SQLConnect.dataSource);
                        sqlConnString = new SqlConnection("Data Source=" + ip.ToString() + ";Initial Catalog=" + SQLConnect.initialCatalog + ";User ID=" + SQLConnect.userID + ";Password="******";Connect Timeout = 10;");

                        //MessageBox.Show(ip.ToString());
                    }

                    //version
                    SqlDataAdapter read_version  = new SqlDataAdapter("select top 1 TABLE_NAME from INFORMATION_SCHEMA.TABLES", sqlConnString);
                    DataTable      version_table = new DataTable();

                    sqlConnString.Open();
                    read_version.Fill(version_table);
                    sqlConnString.Close();

                    btnConnect.Text          = "Valid";
                    grpFileImport.Enabled    = true;
                    grpFolderImport.Enabled  = true;
                    grpBoxExportType.Enabled = true;
                    version_table.Dispose();

                    //SQLGBSCustomProcess Tables = new SQLGBSCustomProcess();
                    //Tables.CreateTables();
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error connecting to database");
                    btnConnect.Enabled = true;
                    btnConnect.Text    = "Connect";
                }
            }
        }
예제 #2
0
        public void InsertVoter(Voters voter, SQLConnectionClass SQLConnect)
        {
            SqlConnection sqlConnString = new SqlConnection("Data Source=" + SQLConnect.dataSource + ";Initial Catalog=" + SQLConnect.initialCatalog + ";User ID=" + SQLConnect.userID + ";Password="******";Connect Timeout = 10;");

            try
            {
                if (SQLConnect.useIPAdress == true)
                {
                    IPAddress ip = new IPHelper().get_ip_from_host_name(SQLConnect.dataSource);
                    sqlConnString = new SqlConnection("Data Source=" + ip.ToString() + ";Initial Catalog=" + SQLConnect.initialCatalog + ";User ID=" + SQLConnect.userID + ";Password="******";Connect Timeout = 10;");

                    //MessageBox.Show(ip.ToString());
                }

                SqlCommand insertVoter = sqlConnString.CreateCommand();
                insertVoter.CommandText = _insertVoter;
                insertVoter.Parameters.Add("@SOSVoterId", SqlDbType.Char);
                insertVoter.Parameters["@SOSVoterId"].Value = voter.SOSVoterId;

                insertVoter.Parameters.Add("@CountyNumber", SqlDbType.Char);
                insertVoter.Parameters["@CountyNumber"].Value = voter.CountyNumber;

                insertVoter.Parameters.Add("@CountyId", SqlDbType.Char);
                insertVoter.Parameters["@CountyId"].Value = voter.CountyId;

                insertVoter.Parameters.Add("@LastName", SqlDbType.Char);
                insertVoter.Parameters["@LastName"].Value = voter.LastName;

                insertVoter.Parameters.Add("@FirstName", SqlDbType.Char);
                insertVoter.Parameters["@FirstName"].Value = voter.FirstName;

                insertVoter.Parameters.Add("@MiddleName", SqlDbType.Char);
                insertVoter.Parameters["@MiddleName"].Value = voter.MiddleName;

                insertVoter.Parameters.Add("@Suffix", SqlDbType.Char);
                insertVoter.Parameters["@Suffix"].Value = voter.Suffix;

                insertVoter.Parameters.Add("@DateOfBirth", SqlDbType.Char);
                insertVoter.Parameters["@DateOfBirth"].Value = voter.DateOfBirth;

                insertVoter.Parameters.Add("@RegistrationDate", SqlDbType.Char);
                insertVoter.Parameters["@RegistrationDate"].Value = voter.RegistrationDate;

                insertVoter.Parameters.Add("@VoterStatus", SqlDbType.Char);
                insertVoter.Parameters["@VoterStatus"].Value = voter.VoterStatus;

                insertVoter.Parameters.Add("@PartyAffiliation", SqlDbType.Char);
                insertVoter.Parameters["@PartyAffiliation"].Value = voter.PartyAffiliation;

                insertVoter.Parameters.Add("@ResidentialAddress1", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialAddress1"].Value = voter.ResidentialAddress1;

                insertVoter.Parameters.Add("@ResidentialAddress2", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialAddress2"].Value = voter.ResidentialAddress2;

                insertVoter.Parameters.Add("@ResidentialCity", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialCity"].Value = voter.ResidentialCity;

                insertVoter.Parameters.Add("@ResidentialState", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialState"].Value = voter.ResidentialState;

                insertVoter.Parameters.Add("@ResidentialZip", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialZip"].Value = voter.ResidentialZip;

                insertVoter.Parameters.Add("@ResidentialZipPlus4", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialZipPlus4"].Value = voter.ResidentialZipPlus4;

                insertVoter.Parameters.Add("@ResidentialCountry", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialCountry"].Value = voter.ResidentialCountry;

                insertVoter.Parameters.Add("@ResidentialPostalCode", SqlDbType.Char);
                insertVoter.Parameters["@ResidentialPostalCode"].Value = voter.ResidentialPostalCode;

                insertVoter.Parameters.Add("@MailingAddress1", SqlDbType.Char);
                insertVoter.Parameters["@MailingAddress1"].Value = voter.MailingAddress1;

                insertVoter.Parameters.Add("@MailingAddress2", SqlDbType.Char);
                insertVoter.Parameters["@MailingAddress2"].Value = voter.MailingAddress2;

                insertVoter.Parameters.Add("@MailingCity", SqlDbType.Char);
                insertVoter.Parameters["@MailingCity"].Value = voter.MailingCity;

                insertVoter.Parameters.Add("@MailingState", SqlDbType.Char);
                insertVoter.Parameters["@MailingState"].Value = voter.MailingState;

                insertVoter.Parameters.Add("@MailingZip", SqlDbType.Char);
                insertVoter.Parameters["@MailingZip"].Value = voter.MailingZip;

                insertVoter.Parameters.Add("@MailingZipPlus4", SqlDbType.Char);
                insertVoter.Parameters["@MailingZipPlus4"].Value = voter.MailingZipPlus4;

                insertVoter.Parameters.Add("@MailingCountry", SqlDbType.Char);
                insertVoter.Parameters["@MailingCountry"].Value = voter.MailingCountry;

                insertVoter.Parameters.Add("@MailingPostalCode", SqlDbType.Char);
                insertVoter.Parameters["@MailingPostalCode"].Value = voter.MailingPostalCode;

                insertVoter.Parameters.Add("@CareerCenter", SqlDbType.Char);
                insertVoter.Parameters["@CareerCenter"].Value = voter.CareerCenter;

                insertVoter.Parameters.Add("@City", SqlDbType.Char);
                insertVoter.Parameters["@City"].Value = voter.City;

                insertVoter.Parameters.Add("@CitySchoolDistrict", SqlDbType.Char);
                insertVoter.Parameters["@CitySchoolDistrict"].Value = voter.CitySchoolDistrict;

                insertVoter.Parameters.Add("@CountyCourtDistrict", SqlDbType.Char);
                insertVoter.Parameters["@CountyCourtDistrict"].Value = voter.CountyCourtDistrict;

                insertVoter.Parameters.Add("@CongressionalDistrict", SqlDbType.Char);
                insertVoter.Parameters["@CongressionalDistrict"].Value = voter.CongressionalDistrict;

                insertVoter.Parameters.Add("@CourtofAppeals", SqlDbType.Char);
                insertVoter.Parameters["@CourtofAppeals"].Value = voter.CourtofAppeals;

                insertVoter.Parameters.Add("@EducationServiceCenter", SqlDbType.Char);
                insertVoter.Parameters["@EducationServiceCenter"].Value = voter.EducationServiceCenter;

                insertVoter.Parameters.Add("@ExemptedVillageSchoolDistrict", SqlDbType.Char);
                insertVoter.Parameters["@ExemptedVillageSchoolDistrict"].Value = voter.ExemptedVillageSchoolDistrict;

                insertVoter.Parameters.Add("@LibraryDistrict", SqlDbType.Char);
                insertVoter.Parameters["@LibraryDistrict"].Value = voter.LibraryDistrict;

                insertVoter.Parameters.Add("@LocalSchoolDistrict", SqlDbType.Char);
                insertVoter.Parameters["@LocalSchoolDistrict"].Value = voter.LocalSchoolDistrict;

                insertVoter.Parameters.Add("@MunicipalCourtDistrict", SqlDbType.Char);
                insertVoter.Parameters["@MunicipalCourtDistrict"].Value = voter.MunicipalCourtDistrict;

                insertVoter.Parameters.Add("@Precinct", SqlDbType.Char);
                insertVoter.Parameters["@Precinct"].Value = voter.Precinct;

                insertVoter.Parameters.Add("@PrecinctCode", SqlDbType.Char);
                insertVoter.Parameters["@PrecinctCode"].Value = voter.PrecinctCode;

                insertVoter.Parameters.Add("@StateBoardofEducation", SqlDbType.Char);
                insertVoter.Parameters["@StateBoardofEducation"].Value = voter.StateBoardofEducation;

                insertVoter.Parameters.Add("@StateRepresentativeDistrict", SqlDbType.Char);
                insertVoter.Parameters["@StateRepresentativeDistrict"].Value = voter.StateRepresentativeDistrict;

                insertVoter.Parameters.Add("@StateSenateDistrict", SqlDbType.Char);
                insertVoter.Parameters["@StateSenateDistrict"].Value = voter.StateSenateDistrict;

                insertVoter.Parameters.Add("@Township", SqlDbType.Char);
                insertVoter.Parameters["@Township"].Value = voter.Township;

                insertVoter.Parameters.Add("@Village", SqlDbType.Char);
                insertVoter.Parameters["@Village"].Value = voter.Village;

                insertVoter.Parameters.Add("@Ward", SqlDbType.Char);
                insertVoter.Parameters["@Ward"].Value = voter.Ward;

                if (sqlConnString.State.ToString() == "Closed")
                {
                    sqlConnString.Open();
                }

                insertVoter.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            finally
            {
                if (sqlConnString.State.ToString() == "Open")
                {
                    sqlConnString.Close();
                }
            }
        }