示例#1
2
        static void Main(string[] args)
        {
            var connectionString = TestTaskConfiguration.Instance.ConnectionString;
            var context = new DataContext(connectionString);
            var repository = new EmployeeRepository(context);
            var service = new EmployeeService(repository);

            var node = new EmployeeReportModel();

            node.EmployeeDetails = service.All().OrderBy(x => x.FirstName).Select(x => new EmployeeReportDetailsModel
            {
                Name = x.FirstName,
                Wage = x.Wage
            }).ToList();

            dataList.Add(node);

            ReportViewer reportViewer = new ReportViewer();
            reportViewer.ProcessingMode = ProcessingMode.Local;
            reportViewer.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\EmployeeReportTemplate.rdlc";
            reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ReportViewer_OnSubreportProcessing);
            reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DSEmployee", dataList));

            Byte[] result = reportViewer.LocalReport.Render("PDF");

            using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"\Test.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
            {
                fs.Write(result, 0, result.Length);
                fs.Flush();
                fs.Close();
            }

            //Console.ReadKey();
        }
示例#2
0
        static void GenerateEmployees()
        {
            var connectionString = TestTaskConfiguration.Instance.ConnectionString;
            var context = new DataContext(connectionString);
            var repository = new EmployeeRepository(context);
            var service = new EmployeeService(repository);

            var wageRandom = new Random();
            var positionRandom = new Random();

            for (var i = 0; i < 100; i++)
            {
                var employee = new Employee
                {
                    FirstName = GenerateAnRandomString(),
                    Wage = wageRandom.Next(100, 100000),
                    Position = GenerateAnRandomString(),
                    Status = (EmployeeStatus)positionRandom.Next(1, 2),
                    CreatedDate = DateTime.UtcNow,
                    ModifiedDate = DateTime.UtcNow
                };

                service.Create(employee);

                Console.WriteLine($"{i} employee was added into DB");
            }
        }