/*****
     * Purpose: Write one record of CardsExchanged data
     *
     *
     * Parameter list:
     *  void
     *
     * Return value:
     *  int                     negative on error, 1 if okay
     ******/
    public int WriteOneRecord()
    {
        int    flag = 1;
        string sqlCommand;
        string date;

        if (dateReceived.Length > 0)
        {
            date = dateReceived;
        }
        else
        {
            date = dateSent;
        }

        sqlCommand = "UPDATE Friends SET LastContact = '" + date + // Build UPDATE command
                     "' WHERE ID = " + id.ToString();

        try
        {
            clsFriend myData = new clsFriend(connectStr);
            flag = myData.ProcessCommand(sqlCommand);
        }
        catch
        {
            return(flag);
        }

        // Build INSERT command
        sqlCommand = "INSERT INTO CardsExchanged" +
                     " (ID,TypeOfCard, Sent, Received) VALUES (";
        // Now add the values
        sqlCommand += id + "," + cardType + ",'" + dateSent + "','" + dateReceived + "')";

        try
        {
            using (SqlConnection myConnection = new SqlConnection(connectStr))
            {
                myConnection.Open();
                using (SqlCommand myCommand = new SqlCommand(sqlCommand, myConnection))
                {
                    myCommand.ExecuteNonQuery();
                }
                myConnection.Close();
            }
        }
        catch
        {
            return(-1);         // Something's amiss...
        }

        return(1);
    }
Ejemplo n.º 2
0
    /*****
     * Purpose: Save textbox info as a record in Friends table.
     *
     * Parameter list:
     *  object sender   control that caused the event
     *  EventArgs e     details about the sender
     *
     * Return value:
     *  void
     ******/
    private void btnSave_Click(object sender, EventArgs e)
    {
        int    status;
        int    flag;
        string sqlCommand;


        if (chkStatus.Checked == true)
        {
            status = 1;
        }
        else
        {
            status = 0;
        }

        myData = new clsFriend(connectStr);

        // Build UPDATE command
        sqlCommand = "UPDATE Friends SET " +
                     "FirstName = '" + txtFirstName.Text + "'," +
                     "LastName = '" + txtLastName.Text + "'," +
                     "Addr1 = '" + txtAddr1.Text + "'," +
                     "Addr2 = '" + txtAddr2.Text + "'," +
                     "City = '" + txtCity.Text + "'," +
                     "State = '" + txtState.Text.ToUpper() + "'," +
                     "Zip = '" + txtZip.Text + "'," +
                     "LastContact = '" + txtLastContact.Text + "'," +
                     "Status = " + status.ToString() +
                     " WHERE ID = " + txtFindRecordNumber.Text;
        try
        {
            flag = myData.ProcessCommand(sqlCommand);
            if (flag > 0)
            {
                MessageBox.Show("Record updated successfully.");
            }
            else
            {
                MessageBox.Show("Failed to update data.", "Process Error");
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex.Message);
        }
    }