示例#1
0
 public void deleteRecordByType(object record)
 {
     try
     {
         using (var dbc = new DailyTaskContext())
         {
             if ("AccountRecord" == record.GetType().Name)
             {
                 var accountRecord = record as AccountRecord;
                 var query         = dbc.accountRecords.Single(p => p.ID == accountRecord.ID);
                 dbc.Remove(query);
             }
             else if ("Daily" == record.GetType().Name)
             {
                 var dailyRecord = record as Daily;
                 var query       = dbc.Daily.Single(p => p.Id == dailyRecord.Id);
                 dbc.Remove(query);
             }
             else
             {
                 m_logger.Error($"invalid record type {record.GetType().Name}!");
                 MessageBox.Show($"invalid record type {record.GetType().Name}!");
                 throw new Exception("invalid record type!");
             }
             dbc.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#2
0
 public void deleteRecordByID(int recordID)
 {
     try
     {
         using (var dbc = new DailyTaskContext())
         {
             var query = dbc.Daily.Single(p => p.Id == recordID);
             dbc.Remove(query);
             dbc.SaveChanges();
         }
     }
     catch (System.InvalidOperationException e)
     {
         m_logger.Error($"can't delete record{recordID}. {e.Message}");
         MessageBox.Show($"can't delete record{recordID}. {e.Message}");
     }
 }