private void dataGrid_UnloadingRow(object sender, DataGridRowEventArgs e)
        {
            if (((DataGrid)sender).SelectedItem != null || ((DataGrid)sender).CurrentItem == null)
            {
                return;
            }
            JobApplicationKeywords myJobApplicationkeywords = (JobApplicationKeywords)((DataGrid)sender).CurrentItem;

            keywordManager.Delete(myJobApplicationkeywords.Id);
        }
Exemple #2
0
        public void Upsert(JobApplicationKeywords myKeyword)
        {
            SqlConnection thisConnection = null;

            if (String.IsNullOrEmpty(ConnectionString1.SqlConnString))
            {
                return;
            }
            else
            {
                thisConnection = new SqlConnection(ConnectionString1.SqlConnString);
            }

            //Create Command object
            SqlCommand nonqueryCommand = thisConnection.CreateCommand();

            try
            {
                // Open Connection
                thisConnection.Open();
                Console.WriteLine("Connection Opened");

                // Create INSERT statement with Keywordd parameters
                nonqueryCommand.CommandText =
                    " IF NOT EXISTS(SELECT* FROM dbo.JobApplicationKeywords WHERE ID = @Id)" +

                    "INSERT INTO [dbo].[JobApplicationKeywords] " +
//"           ([Id] " +
                    "           ([Keyword] " +
                    "           ,[Enabled]) " +
                    "     VALUES " +
//"           (@Id " +
                    "           (@Keyword " +
                    "           ,@Enabled) " +
                    " ELSE " +
                    "UPDATE [dbo].[JobApplicationKeywords] " +
                    "   SET [Keyword] = @Keyword " +
                    "      ,[Enabled] = @Enabled " +
                    " WHERE Id = @Id " +
                    "          ";


                // Add Parameters to Command Parameters collection
                nonqueryCommand.Parameters.Add("@Id", SqlDbType.Int);
                nonqueryCommand.Parameters.Add("@Keyword", SqlDbType.VarChar, 500);
                nonqueryCommand.Parameters.Add("@Enabled", SqlDbType.Bit);


                // Prepare command for repeated execution
                nonqueryCommand.Prepare();

                // Data to be inserted

                nonqueryCommand.Parameters["@Id"].Value      = myKeyword.Id;
                nonqueryCommand.Parameters["@Keyword"].Value = myKeyword.Keyword;
                nonqueryCommand.Parameters["@Enabled"].Value = myKeyword.Enabled;


                Console.WriteLine("Executing {0}", nonqueryCommand.CommandText);
                Console.WriteLine("Number of rows affected : {0}", nonqueryCommand.ExecuteNonQuery());
            }
            catch (SqlException ex)
            {
                // Display error
                Console.WriteLine("Error: " + ex.ToString());
            }
            finally
            {
                // Close Connection
                thisConnection.Close();
                Console.WriteLine("Connection Closed");
            }
        }
Exemple #3
0
        public ObservableCollection <JobApplicationKeywords> GetKeywords()
        {
            ObsCollJobApplicationKeywords = new ObservableCollection <JobApplicationKeywords>();
            // ********************************************************************
            // Code Generated by Ideal Tools Organizer at http://idealautomate.com
            // ********************************************************************
            // Define Query String
            string queryString =
                "Select * from jobapplicationkeywords " +
                "";

            // Define .net fields to hold each column selected in query

            Int32   int_jobapplicationkeywords_Id;
            String  str_jobapplicationkeywords_Keyword;
            Boolean bool_jobapplicationkeywords_Enabled;
            // Define a datatable that we will define columns in to match the columns
            // selected in the query. We will use sqldatareader to read the results
            // from the sql query one row at a time. Then we will add each of those
            // rows to the datatable - this is where you can modify the information
            // returned from the sql query one row at a time. Finally, we will
            // bind the table to the gridview.
            DataTable dt = new DataTable();


            if (!String.IsNullOrEmpty(ConnectionString1.SqlConnString))
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString1.SqlConnString))
                {
                    SqlCommand command = new SqlCommand(queryString, connection);

                    connection.Open();

                    SqlDataReader reader = command.ExecuteReader();
                    // Define a column in the table for each column that was selected in the sql query
                    // We do this before the sqldatareader loop because the columns only need to be
                    // defined once.

                    DataColumn column = null;
                    column = new DataColumn("jobapplicationkeywords_Id", Type.GetType("System.Int32"));
                    dt.Columns.Add(column);
                    column = new DataColumn("jobapplicationkeywords_Keyword", Type.GetType("System.String"));
                    dt.Columns.Add(column);
                    column = new DataColumn("jobapplicationkeywords_Enabled", Type.GetType("System.Boolean"));
                    dt.Columns.Add(column);
                    // Read the results from the sql query one row at a time
                    while (reader.Read())
                    {
                        // define a new datatable row to hold the row read from the sql query
                        DataRow dataRow = dt.NewRow();
                        // Move each field from the reader to a holding field in .net
                        // ********************************************************************
                        // The holding field in .net is where you can alter the contents of the
                        // field
                        // ********************************************************************
                        // Then, you move the contents of the holding .net field to the column in
                        // the datarow that you defined above
                        JobApplicationKeywords _jobapplicationkeywords = new JobApplicationKeywords();
                        if (!(reader.IsDBNull(0)))
                        {
                            int_jobapplicationkeywords_Id        = reader.GetInt32(0);
                            dataRow["jobapplicationkeywords_Id"] = int_jobapplicationkeywords_Id;
                            _jobapplicationkeywords.Id           = int_jobapplicationkeywords_Id;
                        }
                        if (!(reader.IsDBNull(1)))
                        {
                            str_jobapplicationkeywords_Keyword        = reader.GetString(1);
                            dataRow["jobapplicationkeywords_Keyword"] = str_jobapplicationkeywords_Keyword;
                            _jobapplicationkeywords.Keyword           = str_jobapplicationkeywords_Keyword;
                        }
                        if (!(reader.IsDBNull(2)))
                        {
                            bool_jobapplicationkeywords_Enabled       = reader.GetBoolean(2);
                            dataRow["jobapplicationkeywords_Enabled"] = bool_jobapplicationkeywords_Enabled;
                            _jobapplicationkeywords.Enabled           = bool_jobapplicationkeywords_Enabled;
                        }
                        // Add the row to the datatable
                        dt.Rows.Add(dataRow);
                        ObsCollJobApplicationKeywords.Add(_jobapplicationkeywords);
                    }

                    // Call Close when done reading.
                    reader.Close();
                }
            }
            // assign the datatable as the datasource for the gridview and bind the gridview
            return(ObsCollJobApplicationKeywords);
        }