示例#1
0
 public void addAccountRecord(AccountRecord newRecord)
 {
     try
     {
         using (var dbc = new DailyTaskContext())
         {
             var query = dbc.accountRecords.SingleOrDefault(p => p.ID == newRecord.ID);
             if (query != null)    //modify record
             {
                 query.AccountName = newRecord.AccountName;
                 query.Password    = newRecord.Password;
                 query.Comments    = newRecord.Comments;
                 dbc.SaveChanges();
                 MessageBox.Show($"modify account record {newRecord.ID}-{newRecord.Comments}");
             }
             else
             {
                 dbc.accountRecords.Add(newRecord);
                 dbc.SaveChanges();
                 MessageBox.Show($"add account record {newRecord.ID}-{newRecord.Comments}");
             }
         }
     }
     catch (Exception e)
     {
         m_logger.Error($"save account record {newRecord.ID} faile! {e.Message}");
         MessageBox.Show($"save account record {newRecord.ID} faile! {e.Message}");
     }
 }
示例#2
0
 public void save(Daily record)
 {
     try
     {
         using (var dbc = new DailyTaskContext())
         {
             var query = dbc.Daily.SingleOrDefault(p => p.Id == record.Id);
             if (query != null)  //exist, update
             {
                 //todo. better soluton? 遍历foreach所有的property
                 query.Id         = record.Id;
                 query.Date       = record.Date;
                 query.Week       = record.Week;
                 query.Baby       = record.Baby;
                 query.EarlyToBed = record.EarlyToBed;
                 query.Drink      = record.Drink;
                 query.Jl         = record.Jl;
                 query.EatTooMuch = record.EatTooMuch;
                 query.Washroom   = record.Washroom;
                 query.Coding     = record.Coding;
                 query.LearnDaily = record.LearnDaily;
                 query.Eng        = record.Eng;
                 query.Efficiency = record.Efficiency;
                 query.Hz         = record.Hz;
                 query.Score      = record.Score;
                 query.Comments   = record.Comments;
                 query.Reviewd    = record.Reviewd;
                 query.Sport      = record.Sport;
                 dbc.SaveChanges();
                 m_logger.Info($"modify {record.Id} {record.Week} {record.Date:yyyy/MM/dd} done!");
                 MessageBox.Show($"modify {record.Id}, {record.Date:yyyy/MM/dd}! score: {record.Score}");
             }
             else            //add new
             {
                 var dateQuery = dbc.Daily.SingleOrDefault(p => p.Date == record.Date);
                 if (dateQuery == null)
                 {
                     dbc.Daily.Add(record);
                     dbc.SaveChanges();
                     m_logger.Info($"add {record.Id} {record.Week} {record.Date:yyyy/MM/dd} done!");
                     MessageBox.Show($"add {record.Id}, {record.Date:yyyy/MM/dd}! score: {record.Score}");
                 }
                 else
                 {
                     MessageBox.Show("date exist!");
                 }
             }
         }
     }
     catch (Exception e)
     {
         m_logger.Error($"failt to save record {record.Id}\n. {e.InnerException.Message}");
         MessageBox.Show($"failt to save record {record.Id}\n. {e.InnerException.Message}");
     }
 }
示例#3
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;
     }
 }
示例#4
0
        public void updateReiveStatus(List <int> IDList)
        {
            int recordIndex = 0;

            try
            {
                using (var dbc = new DailyTaskContext())
                {
                    foreach (var item in IDList)
                    {
                        recordIndex++;
                        var query = dbc.Daily.Single(p => p.Id == item);
                        if (query.Reviewd == null)
                        {
                            query.Reviewd = 1;
                        }
                        else
                        {
                            query.Reviewd = query.Reviewd + 1;
                        }
                        dbc.SaveChanges();
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                m_logger.Error($"can't update record {IDList[recordIndex]}. review status. {e.Message}");
                MessageBox.Show($"can't update record {IDList[recordIndex]}. review status. {e.Message}");
            }
        }
示例#5
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}");
     }
 }
示例#6
0
 public void Add(TaskModel taskModel)
 {
     taskModel.CreatedAt = DateTime.Now;
     _context.TaskModels.Add(taskModel);
     _context.SaveChanges();
 }