コード例 #1
0
 private void addSec_Click(object sender, EventArgs e)
 {
     Security sec = new Security();
     sec.securityID = (int)id2.Value;
     sec.securityName = name2.Text;
     sec.securityPrice = (int)price.Value;
     try
     {
         controller.addSecurity(sec);
         MessageBox.Show("New Security added.",
             "Success!",
             MessageBoxButtons.OK,
             MessageBoxIcon.Information);
     }
     catch (DatabaseException modelException)
     {
         MessageBox.Show(modelException.error,
             "Error",
             MessageBoxButtons.OK,
             MessageBoxIcon.Exclamation);
     }
 }
コード例 #2
0
        /// <summary>
        /// Methdo to update an existing security.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addSec_Click(object sender, EventArgs e)
        {
            Security sec = new Security();
            sec.securityID = (int)id2.Value;
            sec.securityName = name2.Text;
            sec.securityPrice = (int)price.Value;
            try
            {
                controller.updateSecurity(sec);
                MessageBox.Show("Security Successfully deleted.",
                    "Success!",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                this.Close();
            }
            catch (DatabaseException err)
            {
                MessageBox.Show(err.error,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }
        }
コード例 #3
0
 /// <summary>
 /// Method to add a new Security to the databse
 /// </summary>
 /// <param name="sec">Security to be added</param>
 internal void addSecurity(Security sec)
 {
     // check if the model is already in the database
     foreach (Security other in securities)
     {
         if (sec.securityID == other.securityID)
             throw new DatabaseException("A Security with that ID alredy exits!");
     }
     try
     {
         database.addSecurity(sec);
         updateCollections();        // update the collections after a successful addition
     }
     catch (DatabaseException err)
     {
         throw new DatabaseException(err.error);
     }
 }
コード例 #4
0
 /// <summary>
 /// Method to update a security in the DB
 /// </summary>
 /// <param name="sec">security bject to update</param>
 internal void updateSecurity(Security sec)
 {
     try
     {
         database.updateSecurity(sec);
         updateCollections();
     }
     catch (DatabaseException err)
     {
         throw new DatabaseException(err.error);
     }
 }
コード例 #5
0
        /// <summary>
        /// Method to update an existing Security
        /// </summary>
        /// <param name="sec">new security to update with</param>
        internal void updateSecurity(Security sec)
        {
            string selectString = "UPDATE Securities SET " +
                "SecurityName = '" + sec.securityName + "', SecurityPrice = " + sec.securityPrice +
                " WHERE SecurityID = " + sec.securityID;

            UpdateDataSource(new SqlCommand(selectString, cnMain));
        }