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: Save a new card type into DB * * 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) { string sqlCommand; myCardTypes = new clsCardTypes(connectStr); records++; // Going to add new record SqlConnection myConnection = new SqlConnection(connectStr); try { myConnection.Open(); } catch (Exception ex) { MessageBox.Show("Error openning database: " + ex.Message); return; } // Build INSERT command sqlCommand = "INSERT INTO CardTypes" + " (CardType,Description) VALUES ('"; // Now add the values sqlCommand += records.ToString() + "','" + txtCardDescription.Text + "')"; try { SqlCommand myCommand = new SqlCommand(sqlCommand, myConnection); myCommand.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("Failed to add data, Error: " + ex.Message); return; } try { myConnection.Close(); } catch (Exception ex) { MessageBox.Show("Failed to close database, Error: " + ex.Message); return; } MessageBox.Show("Card type added to database"); }
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; }
public frmAddNewCardType(frmMain me) { InitializeComponent(); this.mdiParent = me; serverName = me.getServerName; databaseName = me.getDatabaseName; connectStr = me.getConnectString; myCardTypes = new clsCardTypes(connectStr); try { records = myCardTypes.GetCardTypesCount(); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }