コード例 #1
0
 void grdExpenditures_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyValue == 46)
     {
         if (this.grdExpenditures.SelectedRows.Count == 1)
         {
             if (MessageBox.Show("Do you want to delete this!") == System.Windows.Forms.DialogResult.OK)
             {
                 ExpendituresView selected = (ExpendituresView)this.grdExpenditures.SelectedRows[0].DataBoundItem;
                 var         db            = new OOPCSEntities();
                 Expenditure deleted       = db.Expenditures.Find(selected.id);
                 db.Expenditures.Remove(deleted);
                 db.SaveChanges();
                 this.ViewAllExpenditures();
             }
         }
     }
 }
コード例 #2
0
        void btnSave_Click(object sender, EventArgs e)
        {
            DateTime date  = this.ptbDate.Value;
            string   note  = this.txtNote.Text;
            int      price = Decimal.ToInt32(this.nudPrice.Value);

            var expenditure = new Expenditure();

            expenditure.Date  = date;
            expenditure.Note  = note;
            expenditure.Price = price;

            var db = new OOPCSEntities();

            db.Expenditures.Add(expenditure);
            db.SaveChanges();
            this.Close();
        }