コード例 #1
0
        /*Loads the data from textboxes to the record and add or edit the record in
         * database. Also shows the ID or whether the user might retry editing the record*/
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            m_record.Brand         = txtBrand.Text;
            m_record.Category      = txtCategory.Text;
            m_record.Condition     = txtCondition.Text;
            m_record.Location      = txtLocation.Text;
            m_record.Model         = txtModel.Text;
            m_record.Notes         = new TextRange(rtbNotes.Document.ContentStart, rtbNotes.Document.ContentEnd).Text;
            m_record.PurchasePrice = Convert.ToDouble(txtPurshasePrice.Text);
            m_record.ReceivedDate  = Convert.ToDateTime(txtReceivedDate.Text);
            m_record.SellingPrice  = Convert.ToDouble(txtSellingPrice.Text);
            m_record.Weight        = Convert.ToInt32(txtWeight.Text);

            if (btnSave.Content == "Save")
            {
                bool response = m_data.UpdateItemRecord(m_record);
                if (response)
                {
                    MessageBox.Show("Item Edited.");
                }
                else
                {
                    MessageBox.Show("It could not edit this item. Please retry.");
                }
            }

            else if (btnSave.Content == "Add")
            {
                int id = m_data.AddItemRecord(m_record);
                MessageBox.Show("Item Added. ID: " + id.ToString());
            }
            this.Close();
        }
コード例 #2
0
 //Adds a new row in database and returns its ID
 public int AddItemRecord(dbRecord itemRecord)
 {
     return(m_data.AddItemRecord(itemRecord));
 }