/***** * Purpose: Find a friend record * * Parameter list: * object sender control that caused the event * EventArgs e details about the sender * * Return value: * void ******/ private void btnFindRecord_Click(object sender, EventArgs e) { int retValue; string sql; myData = new clsFriend(); if (txtLastName.Text.Length == 0) { sql = "SELECT * FROM Friends WHERE ID = " + txtFindRecordNumber.Text; // Search by record ID } else { sql = "SELECT * FROM Friends WHERE LastName = '" + txtLastName.Text + "'"; // Search by Name } myData = new clsFriend(); retValue = myData.ReadOneRecord(sql, connectStr); if (retValue > 0) { ShowOneRecord(); } else { MessageBox.Show("Could not read friend record"); } }
public frmCardExchange(frmMain me) : this() { this.mdiParent = me; serverName = me.getServerName; databaseName = me.getDatabaseName; connectStr = me.getConnectString; myData = new clsFriend(); // Number of friends in DB countOfFriends = myData.RecordCount(connectStr); myExchange = new clsCardsExchanged(connectStr); // Number of cards in DB countOfExchanges = myExchange.RecordCount(connectStr); myTypes = new clsCardTypes(connectStr); // Number of card types... countOfCardTypes = myTypes.GetCardTypesCount(); myExchange.PopulateListboxWithCardTypes(myList); // ...displayed in combo box for (int i = 0; i < myList.Count; i++) { cmbList.Items.Add(myList[i]); } cmbList.SelectedIndex = 0; txtFindRecordNumber.Focus(); }
/***** * 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); }
/***** * 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); } }
public frmCardReport(frmMain me) : this() { int index; int i; string temp; this.mdiParent = me; serverName = me.getServerName; databaseName = me.getDatabaseName; connectStr = me.getConnectString; myData = new clsFriend(); myData.PopulatListWithFriend(myFriends, connectStr); for (i = 0; i < myFriends.Count; i++) { temp = myFriends[i].ToString(); index = temp.IndexOf(' '); myFriends[i] = temp.Substring(index + 1); cmbLastName.Items.Add(myFriends[i]); } cmbLastName.SelectedIndex = 0; myExchange = new clsCardsExchanged(connectStr); // num of cards countOfExchanges = myExchange.RecordCount(connectStr); myTypes = new clsCardTypes(connectStr); countOfCardTypes = myTypes.GetCardTypesCount(); myExchange.PopulateListboxWithCardTypes(myCardList); for (i = 0; i < myCardList.Count; i++) { temp = myCardList[i].ToString(); index = temp.IndexOf(' '); myCardList[i] = temp.Substring(index + 3); cmbList.Items.Add(myCardList[i]); } cmbList.SelectedIndex = 0; rbAll.Checked = true; cmbLastName.Enabled = false; cmbList.Enabled = false; txtDate.Enabled = false; }