public BasicResponse Update(DailyLog log, bool isOverNight = false)
        {
            if (!IsValidDate(log))
            {
                return(Common.Common.SendResponse(500, "date entered is not correct"));
            }

            var punchlog = SetPropValue(log);

            if (isOverNight)
            {
                punchlog.IsAutoSplit = isOverNight;
            }

            if (!IsOverNight(log))
            {
                if (punchlog.IsAutoSplit)
                {
                    Delete(punchlog.ID);
                    punchlog.SplitLogId  = 0;
                    punchlog.IsAutoSplit = false;
                }
                _work.DailyPunchLogsRepo.Update(punchlog);
                _work.Commit();
            }

            return(Common.Common.SendResponse(200, "record updated successfully"));
        }
Exemple #2
0
        public ActionResult Save(DailyLog aDailyLog)
        {
            DailyLogManager aDailyLogManager = new DailyLogManager();

            ViewBag.Message = aDailyLogManager.Save(aDailyLog);
            return(View());
        }
Exemple #3
0
 public List <DailyLog> GetAllDailyLog()
 {
     try
     {
         List <DailyLog> DailyLogList = new List <DailyLog>();
         SqlConnection   connection   = new SqlConnection(connectionString);
         string          query        = "SELECT DISTINCT Lorry_Number FROM DailyLog";
         SqlCommand      command      = new SqlCommand(query, connection);
         command.Connection.Open();
         SqlDataReader reader = command.ExecuteReader();
         while (reader.Read())
         {
             DailyLog aDailyLog = new DailyLog
             {
                 //Id = Convert.ToInt32(reader["Id"]),
                 LorryNumber = Convert.ToString(reader["Lorry_Number"])
             };
             DailyLogList.Add(aDailyLog);
         }
         command.Connection.Close();
         return(DailyLogList);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemple #4
0
        public DailyLog GetDailyLog(string id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id, CreateTime from DailyLog");
            strSql.Append(" where Id = @Id");

            Database  db        = DatabaseFactory.CreateDatabase("MYLOGConn");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "Id", DbType.String, id);

            DataTable dt = db.ExecuteDataSet(dbCommand).Tables[0];

            if (dt.Rows.Count > 0)
            {
                DailyLog log = new DailyLog();
                log.Id = dt.Rows[0]["Id"].ToString();
                DateTime CreateTime;
                if (DateTime.TryParse(dt.Rows[0]["CreateTime"].ToString(), out CreateTime))
                {
                    log.CreateTime = CreateTime;
                }
                return(log);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        public void Start()
        {
            DailyLogClient logClient = new DailyLogClient();

            FitbitClient fitbitClient = new FitbitClient(ConsumerKey, ConsumerSecret, AccessTokenKey, AccessTokenSecret);
            //for (DateTime dt = fitbitClient.GetActivityTrackerFirstDay().Value; dt <= DateTime.Today; dt = dt.AddDays(1))
            //{


            DateTime queryDate = DateTime.Today;

            var day   = fitbitClient.GetDayActivity(queryDate).Summary;
            var sleep = fitbitClient.GetSleep(queryDate).Summary;

            DailyLog log = logClient.Get(queryDate);

            log.Distance             = day.Distances.FirstOrDefault(x => x.Activity == "total").Distance;
            log.CaloriesOut          = day.CaloriesOut;
            log.FairlyActiveMinutes  = day.FairlyActiveMinutes;
            log.LightlyActiveMinutes = day.LightlyActiveMinutes;
            log.SedentaryMinutes     = day.SedentaryMinutes;
            log.Steps             = day.Steps;
            log.VeryActiveMinutes = day.VeryActiveMinutes;
            log.TimeInBadMinutes  = sleep.TotalTimeInBed;
            log.SleepMinutes      = sleep.TotalMinutesAsleep;
            logClient.InsertOrReplace(log);
            //}
        }
Exemple #6
0
        public IActionResult Get(string id)
        {
            DailyLog currentRecipe = accessor.Get <DailyLog>(id);


            return(Json(currentRecipe));
        }
Exemple #7
0
        public int?CreateUpdateDailyLog(DailyLogViewModel dailyLogViewModel)
        {
            DailyLog dailyLog = null;

            if (dailyLogViewModel.DailyLogId > 0)
            {
                dailyLog = _repository.Find <DailyLog>(x => x.DailyLogId == dailyLogViewModel.DailyLogId);

                if (dailyLog == null)
                {
                    return(null);
                }

                dailyLog.CustomerId = dailyLogViewModel.CustomerId;
                dailyLog.GuardId    = dailyLogViewModel.GuardId;
                dailyLog.Comments   = dailyLogViewModel.Comments;
                dailyLog.Dated      = dailyLogViewModel.Dated;

                _repository.Modify <DailyLog>(dailyLog);
                return(dailyLog.CustomerId);
            }

            Mapper.CreateMap <DailyLogViewModel, DailyLog>();
            dailyLog = Mapper.Map <DailyLogViewModel, DailyLog>(dailyLogViewModel);


            dailyLog.CreatedDate = DateTime.Now;
            dailyLog.Dated       = dailyLogViewModel.Dated;

            dailyLog.IsDeleted = false;
            return(_repository.Insert <DailyLog>(dailyLog));
        }
Exemple #8
0
        public void Test_DailyLogUpdate()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IRepository repository = new Repository(context);

                    var dailyLog = new DailyLog
                    {
                        LogID            = 1,
                        LogDate          = new DateTime(2016, 9, 7),
                        BeginningMileage = 899201,
                        EndingMileage    = 899423,
                        TruckNumber      = "3082",
                        TrailerNumber    = "9225",
                        IsSigned         = true,
                        Notes            = "Dropped trailer  9225 at Whirlpool and picked up loaded trailer 9159",
                        DriverID         = 4
                    };

                    repository.Create <DailyLog>(dailyLog);
                    repository.Save();

                    var test = repository.Find <DailyLog>(log => log.LogID == dailyLog.LogID);

                    Assert.NotNull(test);
                    Assert.Equal(new DateTime(2016, 9, 7), dailyLog.LogDate);

                    test.LogDate = new DateTime(2016, 9, 9);
                    repository.Update <DailyLog>(test);
                    repository.Save();

                    test = repository.Find <DailyLog>(log => log.LogID == dailyLog.LogID);
                    Assert.Equal(new DateTime(2016, 9, 9), test.LogDate);
                }
            } finally {
                connection.Close();
            }
        }
        public int insert(DailyLog log)
        {
            var punchlog = SetPropValue(log);

            punchlog.SplitLogId = log.SplitLogID;
            _work.DailyPunchLogsRepo.Insert(punchlog);
            _work.Commit();
            return(punchlog.ID);
        }
 private void SetDailyLogSelected(int dailylogId)
 {
     using (SQLiteConnection conn = new SQLiteConnection(Settings.DBPATH, SQLiteOpenFlags.ReadWrite, false))
     {
         DailyLog dl = conn.Table <DailyLog>().FirstOrDefault(x => x.DailyLogID == dailylogId);
         dl.DailyLogIsSelected = true;
         conn.Update(dl);
     }
 }
Exemple #11
0
 List <DailyLog> LoadGridData()
 {
     for (int i = 0; i < 31; i++)
     {
         DailyLog dayLog = new DailyLog();
         log.Add(dayLog);
     }
     return(log);
 }
 public DailyLog(int slavesDied, int goodsProduced, int toolsUsed)
 {
     day            = CampaignTime.Now;
     _slavesDied    = slavesDied;
     _goodsProduced = goodsProduced;
     _toolsUsed     = toolsUsed;
     _nextDay       = null;
     _previousDay   = null;
 }
        public void DailyLog_CanBeCreated()
        {
            //Given
            DailyLog dailyLog;

            //When
            dailyLog = new DailyLog();

            //Then
            Assert.NotNull(dailyLog);
        }
        public string Save(DailyLog aDailyLog)
        {
            DailyLogGateway aDailyLogGateway = new DailyLogGateway();
            int             rowAffected      = aDailyLogGateway.Save(aDailyLog);

            if (rowAffected > 0)
            {
                return("Daily Log Saved Successfully.");
            }
            return("Daily Log Saved Fail");
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="log"></param>
        public static void SaveDailyLog(DailyLog log)
        {
            var dir = prepareDailyRecordsPath(log.TargetDate);

            foreach (var record in log.Records)
            {
                var path = getRecordFilePath(record);
                using (var fs = File.OpenWrite(path))
                    SaveTimeRecord(fs, record);
            }
        }
Exemple #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DailyLogViewModel GetDailyLog(int id)
        {
            DailyLog dailylog = _repository.Find <DailyLog>(x => x.DailyLogId == id);

            if (dailylog == null)
            {
                return(null);
            }

            Mapper.CreateMap <DailyLog, DailyLogViewModel>();
            return(Mapper.Map <DailyLog, DailyLogViewModel>(dailylog));
        }
Exemple #17
0
        public int DeleteDailyLog(int id, int UserId)
        {
            DailyLog dailylog = _repository.Find <DailyLog>(x => x.DailyLogId == id);

            if (dailylog == null)
            {
                return(0);
            }
            dailylog.IsDeleted   = true;
            dailylog.DeletedBy   = UserId;
            dailylog.DeletedDate = DateTime.Now;
            return(_repository.Modify <DailyLog>(dailylog));
        }
        public static DailyLog Load(DateTime date)
        {
            var dir    = prepareDailyRecordsPath(date);
            var files  = Directory.GetFiles(dir, "*." + DAT_EXTENSION, SearchOption.TopDirectoryOnly);
            var result = new DailyLog(date);

            foreach (var f in files)
            {
                using (var fs = File.OpenRead(f))
                    result.AddRecord(LoadRecordFrom(fs));
            }

            return(result);
        }
Exemple #19
0
        public IActionResult Get(int month, int day, int year)
        {
            DateTime date     = new DateTime(year, month, day);
            DailyLog dailyLog = accessor.GetDailyLogByDate(date);

            if (dailyLog == null)
            {
                Response r = new Response();
                r.Success = true;
                r.Message = "Log does not exist.";

                return(Json(r));
            }
            return(Json(dailyLog));
        }
        public void AddToLogs(int slavesDied, int goodsProduced, int toolsUsed)
        {
            DailyLog newEntry = new DailyLog(slavesDied, goodsProduced, toolsUsed);

            if (_logs == null)
            {
                _logs = new List <DailyLog>();
            }

            if (_logs.Count > 0)
            {
                _logs.Last <DailyLog>().NextDay = newEntry;
                newEntry.PreviousDay            = _logs.Last <DailyLog>();
            }
            _logs.Add(newEntry);
        }
Exemple #21
0
        public int AddDailyLog(DailyLog model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into DailyLog(");
            strSql.Append("Id,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("@Id,@CreateTime)");

            Database  db        = DatabaseFactory.CreateDatabase("MYLOGConn");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "Id", DbType.String, model.Id);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, model.CreateTime);

            return(db.ExecuteNonQuery(dbCommand));
        }
        private DailyStatisticViewModel GenerateDailyLogViewModel(DailyLog dailyLog)
        {
            var todayStatisticViewModel = new DailyStatisticViewModel
            {
                Date              = dailyLog.Date,
                City              = dailyLog.City,
                Fasted            = dailyLog.Fasted,
                Id                = dailyLog.Id,
                LastMealTimeStamp = dailyLog.LastMealTimeStamp,
                MorningWeight     = dailyLog.MorningWeight,
                Steps             = dailyLog.Steps,
                Stretched         = dailyLog.Stretched,
                Sport             = dailyLog.Sport
            };

            return(todayStatisticViewModel);
        }
        private void BT_SaveEvent_Click(object sender, EventArgs e)
        {
            int count = FLP_Events.Controls.Count;

            if (count > 0)
            {
                DailyLog dailyLog;
                dailyLog = db.GetDailyLog(DateTime.Now.ToShortDateString());

                if (dailyLog == null)
                {
                    dailyLog            = new DailyLog();
                    dailyLog.Id         = DailyLogId;
                    dailyLog.CreateTime = DateTime.Now;
                    db.AddDailyLog(dailyLog);
                }
                foreach (EventControl item in FLP_Events.Controls)
                {
                    switch (item.Status)
                    {
                    case EventControl.StatusType.Create:
                        CreateEvent(item, dailyLog.Id);
                        break;

                    case EventControl.StatusType.Delete:
                        DeleteEvent(item);
                        break;

                    case EventControl.StatusType.Keep:
                        break;

                    case EventControl.StatusType.Update:
                        UpdateEvent(item);
                        break;
                    }
                }

                MessageBox.Show("已保存");
            }
            else
            {
                // if nothing delete
                return;
            }
        }
Exemple #24
0
        public Response Post(string id, [FromBody] DailyLog value)
        {
            Response r = new Response();

            if (value == null)
            {
                r.Success = false;
                r.Message = "Null DailyLog Found";
                return(r);
            }

            value = GlobalFunctions.AddIdIfNeeded(value, id);
            accessor.Post(value);

            r.Message = value.idString;

            return(r);
        }
        private List <DailyLog> GetDailyLogs(Timesheets log, int groupID = 0)
        {
            List <DailyLog> dailyLogs = new List <DailyLog>();

            if (log.SplitLogId.HasValue && log.SplitLogId.Value > 0)
            {
                return(null);
            }
            foreach (var column in Constants.Columns)
            {
                var prop  = GetPropValue(log, column);
                var value = prop.GetValue(log);

                var idProp = GetPropValue(log, "ID");
                var idVal  = idProp.GetValue(log);

                if (prop.Name.ToLower() == Constants.Columns[1].ToLower())
                {
                    var isAutoSplitProp = GetPropValue(log, "IsAutoSplit");
                    var isAutoSplitVal  = (bool)isAutoSplitProp.GetValue(log);
                    if (isAutoSplitVal)
                    {
                        var splitLog = _work.DailyPunchLogsRepo.Get(x => x.SplitLogId.HasValue && x.SplitLogId.Value == log.ID).FirstOrDefault();
                        value = splitLog.ClockedOut;
                    }
                }

                if (value != null)
                {
                    var time     = Convert.ToDateTime(value);
                    var dailyLog = new DailyLog
                    {
                        ID        = (int)idVal,
                        PunchName = prop.Name,
                        PunchTime = time,
                        Time      = time.ToString("HH:mm"),
                        PunchDate = time.Date,
                        GroupID   = groupID
                    };
                    dailyLogs.Add(dailyLog);
                }
            }
            return(dailyLogs);
        }
 public int Save(DailyLog aDailyLog)
 {
     try
     {
         SqlConnection connection = new SqlConnection();
         SqlCommand    command    = new SqlCommand();
         command.CommandText = "INSERT INTO DailyLog (Date,SupplierName,Destination,Lorry_Number,SupplierPriceRent,SupplierAdvancedPayment,PartyName,PartyPrice,PartyAdvancedReceived,CnF) VALUES ('" + aDailyLog.Date + "','" + aDailyLog.SupplierName + "','" + aDailyLog.Destination + "','" + aDailyLog.LorryNumber + "','" + aDailyLog.SupplierPriceRent + "','" + aDailyLog.SupplierAdvancedPayment + "','" + aDailyLog.PartyName + "','" + aDailyLog.PartyPrice + "','" + aDailyLog.PartyAdvancedReceived + "','" + aDailyLog.CnF + "')";
         command.Connection  = connection;
         command.Connection.ConnectionString = connectionString;
         command.Connection.Open();
         int rowAffected = command.ExecuteNonQuery();
         command.Connection.Close();
         return(rowAffected);
     }
     catch (Exception exception)
     {
         return(0);
     }
 }
        public bool IsOverNight(DailyLog dLog)
        {
            var log = DailyPunch(dLog.PunchTime.AddDays(-1));

            if (log != null && log.SubmitTime == null && !dLog.IsAutoSplit)
            {
                if (log.ClockedIn.Value.Date < dLog.PunchTime.Date)
                {
                    var newLog  = (DailyLog)dLog.Clone();
                    var newDate = new DateTime(log.ClockedIn.Value.Date.Year, log.ClockedIn.Value.Date.Month, log.ClockedIn.Value.Date.Day, 23, 59, 59);
                    newLog.PunchTime   = newDate;
                    newLog.IsAutoSplit = true;
                    //insert entry to old
                    Update(newLog, true);

                    //clock In entry for current Day
                    var newDayClockIn = new DailyLog
                    {
                        SplitLogID  = log.ID,
                        PunchName   = "clockedIn",
                        PunchTime   = new DateTime(dLog.PunchTime.Date.Year, dLog.PunchTime.Date.Month, dLog.PunchTime.Date.Day, 00, 00, 00),
                        IsAutoSplit = true
                    };
                    var id = insert(newDayClockIn);

                    //clockout for the day
                    dLog.ID          = id;
                    dLog.IsAutoSplit = true;
                    Update(dLog);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemple #28
0
        public JsonResult InsertLog(DailyLog log)
        {
            int logID = HttpContext.Session.Get <int>("LogID");

            if (logID > 0)
            {
                log.ID = logID;
                _pService.Update(log);
                if (log.PunchName.ToLower() == Constants.ClockedOut.Replace(" ", "").ToLower())
                {
                    HttpContext.Session.Set <int>("LogID", 0);
                }
            }
            else
            {
                logID = _pService.insert(log);
                HttpContext.Session.Set("LogID", logID);
            }


            return(Json("data inserted successfully"));
        }
Exemple #29
0
        public DailyLog GetLogs(int offset, int limit, DateTime day)
        {
            var logsList = new List <Log>();

            logsList.Add(new Log()
            {
                LogId    = null,
                LogType  = 2,
                DateTime = DateTime.Now.ToString(),
                Error    = "Test error",
                Status   = ""
            });


            var data = new DailyLog()
            {
                Logs       = logsList,
                TotalCount = 1
            };

            return(data);
        }
Exemple #30
0
        public static void SaveTest()
        {
            // 正常系

            var yesterdayDailyLog = DailyLog.LoadExistOrCreate(DateTime.Today - TimeSpan.FromDays(1));

            if (yesterdayDailyLog.Records.Count != 0)
            {
                Console.WriteLine("すでに {0} 件のレコードが存在しております。", yesterdayDailyLog.Records.Count);
            }
            yesterdayDailyLog.AddRecord(new TimeRecord()
            {
                Time = DateTime.Now - TimeSpan.FromDays(1)
            });
            DailyLogManager.SaveDailyLog(yesterdayDailyLog);

            var todayDailyLog = DailyLog.LoadExistOrCreate(DateTime.Today);

            if (todayDailyLog.Records.Count != 0)
            {
                Console.WriteLine("すでに {0} 件のレコードが存在しております。", todayDailyLog.Records.Count);
            }
            todayDailyLog.AddRecord(new TimeRecord()
            {
                Time = DateTime.Now
            });
            DailyLogManager.SaveDailyLog(todayDailyLog);


            // 異常系
#if FALSE
            var errorDailyLog = new DailyLog(DateTime.Today - TimeSpan.FromDays(2));
            errorDailyLog.AddRecord(new TimeRecord()
            {
                Time = DateTime.Now - TimeSpan.FromDays(3)
            });
#endif
        }