コード例 #1
0
        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            try
            {
                timer.Stop();
                if (!workstationLocked || checkBoxTrackWhilstLocked.Checked)
                {
    #if DEBUG
                    // Open database (or create if doesn't exist)
                    using (var db = new LiteDatabase(@"C:\temp\sut-test.db"))
    #else
                    // Open database (or create if doesn't exist)
                    using (var db = new LiteDatabase("sut.db"))
    #endif
                    {
                        // Get a collection (or create, if doesn't exist)
                        var databaseCollection = db.GetCollection <WorkingDay>("WorkingDays");
                        // Use Linq to query documents
                        var persistedWorkingDay = databaseCollection.FindOne(x => x.Id == DateTime.Now.ToString("yyyyMMdd"));
                        if (persistedWorkingDay != null)
                        {
                            workingDay = persistedWorkingDay;
                            var bar = workingDay.TotalTime();
                            workingDay.AddServiceUnit();
                            SetLabelTotalServiceUnitCountText(workingDay.TotalServiceUnits().ToString("D2"));

                            // Update a document inside a collection
                            databaseCollection.Update(workingDay);
                        }
                        else
                        {
                            // Create your new customer instance
                            workingDay = new WorkingDay();
                            SetLabelTotalServiceUnitCountText(workingDay.TotalServiceUnits().ToString("D2"));
                            databaseCollection.Insert(workingDay);
                        }

                        databaseCollection.Update(workingDay);
                    }
                }
                timer.Start();
            }
            catch (Exception exception)
            {
#if DEBUG
                throw exception;
#else
                Log.Fatal(exception, "Timed event failed.");
                Application.Exit();
#endif
            }
        }
コード例 #2
0
        private static void PopulateCellsWithWorkingDayData(Worksheet sheet, DateTime dateTimeOfWorkingDay, int rowNumber)
        {
            try
            {
#if DEBUG
                // Open database (or create if doesn't exist)
                using (var db = new LiteDatabase(@"C:\temp\sut-test.db"))
#else
                // Open database (or create if doesn't exist)
                using (var db = new LiteDatabase("sut.db"))
#endif
                {
                    // Get a collection (or create, if doesn't exist)
                    var databaseCollection = db.GetCollection <WorkingDay>("WorkingDays");

                    var persistedWorkingDay = databaseCollection.FindOne(x => x.Id == dateTimeOfWorkingDay.ToString("yyyyMMdd"));
                    if (persistedWorkingDay != null)
                    {
                        SetBodyCell(sheet, string.Format("B{0}", rowNumber), persistedWorkingDay.TotalServiceUnitsMorning);
                        SetBodyCell(sheet, string.Format("C{0}", rowNumber), persistedWorkingDay.TotalServiceUnitsAfternoon);
                        SetBodyCell(sheet, string.Format("D{0}", rowNumber), persistedWorkingDay.TotalServiceUnitsEvening);
                        SetBodyCell(sheet, string.Format("E{0}", rowNumber), persistedWorkingDay.TotalServiceUnitsNight);
                        SetBodyCellFormula(sheet, string.Format("F{0}", rowNumber), string.Format(@"=SUM(B{0}:E{0})", rowNumber));
                        SetBodyCellFormula(sheet, string.Format("G{0}", rowNumber), string.Format(@"=CONVERT((F{0}*{1}),""mn"",""hr"")", rowNumber, persistedWorkingDay.OneServiceUnitInMinutes));
                    }
                    else
                    {
                        SetBodyCell(sheet, string.Format("B{0}", rowNumber), 0);
                        SetBodyCell(sheet, string.Format("C{0}", rowNumber), 0);
                        SetBodyCell(sheet, string.Format("D{0}", rowNumber), 0);
                        SetBodyCell(sheet, string.Format("E{0}", rowNumber), 0);
                        var workingDay = new WorkingDay();
                        SetBodyCellFormula(sheet, string.Format("F{0}", rowNumber), string.Format(@"=SUM(B{0}:E{0})", rowNumber), true);
                        SetBodyCellFormula(sheet, string.Format("G{0}", rowNumber), string.Format(@"=CONVERT((F{0}*{1}),""mn"",""hr"")", rowNumber, workingDay.OneServiceUnitInMinutes), true);
                    }
                }
            }
            catch (Exception exception)
            {
#if DEBUG
                throw exception;
#else
                Log.Fatal(exception, "Populate cells failed.");
                Application.Exit();
#endif
            }
        }