Esempio n. 1
0
        private async Task monthlyReport()
        {
            DBHandler    db      = new linqDBHandler();
            ExcelBuilder builder = new ExcelBuilder();
            AzureBlob    blob    = new AzureBlob();

            foreach (Company c in db.getAllCompanies())
            {
                List <string> columns = new List <string>();
                columns.Add("userName");
                columns.Add("Start Time");
                columns.Add("End Time");
                List <List <string> > rows  = new List <List <string> >();
                DateTime     monthDate      = new DateTime();
                TimeZoneInfo israelTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Israel Standard Time");
                monthDate = TimeZoneInfo.ConvertTime(monthDate, israelTimeZone);

                int year  = monthDate.Year;
                int month = monthDate.Month - 1;
                if (month == 0)
                {
                    month = 12;
                    year -= 1;
                }

                monthDate = new DateTime(year, month, 1);

                foreach (User u in db.getAllCompanyWorkers(c.id))
                {
                    long         userId = u.id;
                    List <Clock> clocks = db.getClocks(userId, monthDate);

                    foreach (Clock shift in clocks)
                    {
                        List <string> row = new List <string>();
                        row.Add(u.name);
                        row.Add(shift.startTime.ToString());
                        row.Add(shift.endTime.ToString());

                        rows.Add(row);
                    }
                }


                Workbook workBook = builder.write(columns, rows);
                workBook.SaveAs("temp.xlsx");
                string url = await blob.uploadFileAsync("temp.xlsx", c.id + "_" + monthDate + ".xlsx");

                File.Delete("temp.xlsx");

                Report report = new Report();
                report.companyId = c.id;
                report.date      = monthDate;
                report.url       = url;

                db.addReport(report);

                Trace.TraceInformation("new report : " + url);
            }
        }
Esempio n. 2
0
        private async Task weeklyReport()
        {
            DBHandler    db      = new linqDBHandler();
            ExcelBuilder builder = new ExcelBuilder();
            AzureBlob    blob    = new AzureBlob();

            // TODO: Replace the following with your own logic.

            foreach (Company c in db.getAllCompanies())
            {
                List <string> columns = new List <string>();
                columns.Add("userName");
                columns.Add("Start Time");
                columns.Add("End Time");
                List <List <string> > rows = new List <List <string> >();

                DateTime     weekDate       = new DateTime();
                TimeZoneInfo israelTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Israel Standard Time");
                weekDate = TimeZoneInfo.ConvertTime(weekDate, israelTimeZone);

                foreach (User u in db.getAllCompanyWorkers(c.id))
                {
                    long         userId = u.id;
                    List <Clock> clocks = db.getClocks(userId, weekDate);

                    foreach (Clock shift in clocks)
                    {
                        List <string> row = new List <string>();
                        row.Add(u.name);
                        row.Add(shift.startTime.ToString());
                        row.Add(shift.endTime.ToString());

                        rows.Add(row);
                    }
                }


                Workbook workBook = builder.write(columns, rows);
                workBook.SaveAs("temp.xlsx");
                string url = await blob.uploadFileAsync("temp.xlsx", c.id + "_" + weekDate + ".xlsx");

                File.Delete("temp.xlsx");

                Report report = new Report();
                report.companyId = c.id;
                report.date      = weekDate;
                report.url       = url;

                db.addReport(report);

                Trace.TraceInformation("new report : " + url);
            }
        }
Esempio n. 3
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            AzureQueue   queue   = new AzureQueue();
            DBHandler    db      = new linqDBHandler();
            ExcelBuilder builder = new ExcelBuilder();
            AzureBlob    blob    = new AzureBlob();

            while (!cancellationToken.IsCancellationRequested)
            {
                var message = await queue.deleteMessageAsync();

                string[] splitted = message.Split(',');
                DateTime weekDate = DateTime.Parse(splitted[1]);
                long     userId;
                long.TryParse(splitted[0], out userId);
                List <Clock>  clocks  = db.getClocks(userId, weekDate);
                List <string> columns = new List <string>();
                columns.Add("Company");
                columns.Add("Start Time");
                columns.Add("End Time");

                List <List <string> > rows = new List <List <string> >();
                foreach (Clock shift in clocks)
                {
                    List <string> row = new List <string>();
                    row.Add(shift.Shift.Company.name);
                    row.Add(shift.startTime.ToString());
                    row.Add(shift.endTime.ToString());

                    rows.Add(row);
                }

                Workbook workBook = builder.write(columns, rows);
                workBook.SaveAs("temp.xlsx");
                string url = await blob.uploadFileAsync("temp.xlsx", userId + "_" + weekDate + ".xlsx");

                File.Delete("temp.xlsx");

                WorkerReport workerReport = new WorkerReport();
                workerReport.workerId = userId;
                workerReport.url      = url;
                workerReport.date     = weekDate;

                db.addWorkerReport(workerReport);

                Trace.TraceInformation("new report : " + url);
            }
        }