// This method checks to see if the database exists, and if it doesn't, it creates
		// it and inserts some data. It also sets our database to be the default database
		// connection.
		protected void CheckAndCreateDatabase (string dbName)
		{	
			// determine whether or not the database exists
			bool dbExists = File.Exists (GetDBPath (dbName));
			
			// configure the current database, create if it doesn't exist, and then run the anonymous
			// delegate method after it's created
			CSConfig.SetDB (GetDBPath (dbName), SqliteOption.CreateIfNotExists, () => {
				CSDatabase.ExecuteNonQuery ("CREATE TABLE People (PersonID INTEGER PRIMARY KEY AUTOINCREMENT, FirstName text, LastName text)");
				
				// if the database had to be created, let's populate with initial data
				if (!dbExists) {
					// declare vars
					CSList<Person> people = new CSList<Person> ();
					Person person;
					
					// create a list of people that we're going to insert
					person = new Person () { FirstName = "Peter", LastName = "Gabriel" };
					people.Add (person);
					person = new Person () { FirstName = "Thom", LastName = "Yorke" };
					people.Add (person);
					person = new Person () { FirstName = "J", LastName = "Spaceman" };
					people.Add (person);
					person = new Person () { FirstName = "Benjamin", LastName = "Gibbard" };
					people.Add (person);
					
					// save the people collection to the database
					people.Save ();
				}
			});
		}
		protected void Initialize ()
		{
			this.Title = "Vici Cool Storage";
			
			// performance timing
			System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch ();
			stopwatch.Start ();
			
			string dbName = "db_viciCoolStorage.db3";
			
			// check the database, if it doesn't exist, create it
			this.CheckAndCreateDatabase (dbName);
			
			// performance timing
			Console.WriteLine ("database creation: " + stopwatch.ElapsedMilliseconds.ToString ());
			
			// query a list of people from the db			
			people = Person.List();
				
			// performance timing
			Console.WriteLine ("database query: " + stopwatch.ElapsedMilliseconds.ToString ());
		
			// create a new table source from our people collection
			tableSource = new BasicOperations.TableSource (people);
			
			// initialize the table view and set the source
			this.TableView = new UITableView (){
				Source = tableSource
			};
			
		}
Esempio n. 3
0
        public CSList <TObjectType> LimitTo(int numRecords)
        {
            CSList <TObjectType> newCollection = Clone();

            newCollection.MaxRecords = numRecords;

            return(newCollection);
        }
Esempio n. 4
0
        public CSList <TObjectType> FilteredBy(Predicate <TObjectType> predicate)
        {
            CSList <TObjectType> newCollection = Clone();

            newCollection.FilterPredicate += predicate;

            return(newCollection);
        }
Esempio n. 5
0
        public static CSList <T> OrderedList(string orderBy, string filter, string paramName1, object paramValue1, string paramName2, object paramValue2, string paramName3, object paramValue3)
        {
            CSList <T> list = List(filter, paramName1, paramValue1, paramName2, paramValue2, paramName3, paramValue3);

            list.OrderBy = orderBy;

            return(list);
        }
Esempio n. 6
0
        public CSList <TObjectType> OrderedBy(string orderBy)
        {
            CSList <TObjectType> newCollection = Clone();

            newCollection.OrderBy = orderBy;

            return(newCollection);
        }
Esempio n. 7
0
        public static CSList <T> OrderedList(string orderBy, string filter, object parameters)
        {
            CSList <T> list = List(filter, parameters);

            list.OrderBy = orderBy;

            return(list);
        }
Esempio n. 8
0
        public static CSList <T> OrderedList(string orderBy, string filter)
        {
            CSList <T> list = List(filter);

            list.OrderBy = orderBy;

            return(list);
        }
Esempio n. 9
0
        public static CSList <T> OrderedList(string orderBy)
        {
            CSList <T> list = List();

            list.OrderBy = orderBy;

            return(list);
        }
Esempio n. 10
0
        public CSList <TObjectType> FilteredBy(CSFilter filter)
        {
            CSList <TObjectType> newCollection = Clone();

            newCollection.Filter = Filter.And(filter);

            return(newCollection);
        }
Esempio n. 11
0
        public CSList <TObjectType> WithPrefetch(params string[] prefetchPaths)
        {
            CSList <TObjectType> newCollection = Clone();

            newCollection.PrefetchPaths = prefetchPaths;

            return(newCollection);
        }
Esempio n. 12
0
        public CSList <TObjectType> Range(int from, int numRecords)
        {
            CSList <TObjectType> newCollection = Clone();

            newCollection.MaxRecords  = numRecords;
            newCollection.StartRecord = from;

            return(newCollection);
        }
Esempio n. 13
0
        public CSList <TObjectType> ThenBy(string orderBy)
        {
            if (string.IsNullOrEmpty(OrderBy))
            {
                throw new CSException(".ThenBy() called without .OrderedBy()");
            }

            CSList <TObjectType> newCollection = Clone();

            newCollection.OrderBy += "," + orderBy;

            return(newCollection);
        }
Esempio n. 14
0
        public CSList(CSList <TObjectType> sourceCollection)
            : this()
        {
            OrderBy     = sourceCollection.OrderBy;
            MaxRecords  = sourceCollection.MaxRecords;
            StartRecord = sourceCollection.StartRecord;

            Filter          = sourceCollection.Filter;
            FilterPredicate = sourceCollection.FilterPredicate;
            Relation        = sourceCollection.Relation;
            RelationObject  = sourceCollection.RelationObject;
            PrefetchPaths   = sourceCollection.PrefetchPaths;
        }
Esempio n. 15
0
        public static T ReadFirst(CSFilter filter)
        {
            CSList <T> objects = new CSList <T>(filter);

            objects.MaxRecords = 1;

            if (objects.Count < 1)
            {
                return(null);
            }
            else
            {
                return(objects[0]);
            }
        }
Esempio n. 16
0
        private CSList <TObjectType> Clone()
        {
            CSList <TObjectType> newCollection = (CSList <TObjectType>)Activator.CreateInstance(GetType());

            newCollection.OrderBy         = OrderBy;
            newCollection.MaxRecords      = MaxRecords;
            newCollection.StartRecord     = StartRecord;
            newCollection.FilterPredicate = FilterPredicate;
            newCollection.Filter          = Filter;
            newCollection.Relation        = Relation;
            newCollection.RelationObject  = RelationObject;
            newCollection.PrefetchPaths   = newCollection.PrefetchPaths;

            return(newCollection);
        }
Esempio n. 17
0
        private void ReadRelationToMany(CSSchemaField schemaField)
        {
//            if (_schema.KeyColumns.Count != 1)
//                throw new CSException("...ToMany only supported with single primary key");
//
            try
            {
                CSList relationCollection = (CSList)Activator.CreateInstance(schemaField.FieldType);

                relationCollection.Relation       = schemaField.Relation;
                relationCollection.RelationObject = this;

                _fieldData[schemaField.Name].ValueDirect = relationCollection;
                _fieldData[schemaField.Name].ValueState  = CSFieldValueState.Read;
            }
            catch (TargetInvocationException ex)
            {
                throw ex.InnerException;
            }
        }
Esempio n. 18
0
        private void CreateMonthlyEmployeeSredPDFReport(CSList<TimeProjectHours> projects, TimeEmployees employee, DateTime dt)
        {
            try
            {
                string templatePdfPath = Server.MapPath("PDFimages");
                string oldFile = templatePdfPath + "\\MonthlyEmployeeTemplate.pdf";

                List<byte[]> pages = WriteToPdfForEmployeeMonthly(oldFile, projects, employee, dt, 2);

                if (pages == null) return;
                using (var output = new MemoryStream())
                {
                    var document = new Document();
                    var writer = new PdfCopy(document, output);
                    document.Open();
                    for (int index = 0; index < pages.Count; index++)
                    {
                        var file = pages[index];
                        var reader = new PdfReader(file);
                        int n = reader.NumberOfPages;
                        PdfImportedPage page;
                        for (int p = 1; p <= n; p++)
                        {
                            page = writer.GetImportedPage(reader, p);
                            writer.AddPage(page);
                        }
                    }
                    document.Close();
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}-{1}.pdf", "MonthlyTimeCard-", employee.FirstName + "_" + employee.LastName));
                    Response.BinaryWrite(output.ToArray());
                    Response.Flush();
                    Response.End();
                }

            }
            catch (Exception ex)
            {
                lblErrorMonthly.Text = "Error: " + ex.Message;
            }
        }
			public TableSource (CSList<Person> items) : base() { this.items = items; }
Esempio n. 20
0
        public List<byte[]> WriteToPdfForEmployeeMonthly(string sourceFile, CSList<TimeProjectHours> projects,
            TimeEmployees employee, DateTime dt, int repType)
        {
            var pages = new List<byte[]>();

            int totalItemCount = 0;
            int currentLoopCount = 0;
            int totalHours = 0;

            while (totalItemCount < projects.Count)
            {
                var reader = new PdfReader(sourceFile);

                using (var memoryStream = new MemoryStream())
                {
                    // PDFStamper is the class we use from iTextSharp to alter an existing PDF.
                    var pdfStamper = new PdfStamper(reader, memoryStream);

                    Rectangle pageSize = reader.GetPageSizeWithRotation(1);

                    PdfContentByte pdfPageContents = pdfStamper.GetOverContent(1);
                    pdfPageContents.BeginText(); // Start working with text.

                    BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, Encoding.ASCII.EncodingName, false);
                    if (repType == 2)
                    {
                        pdfPageContents.SetFontAndSize(baseFont, 20); // 20 point font
                        //show the project name for SRED
                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Project: " + ddlMonthlyProjectsSRED.SelectedItem, 75,
                            (pageSize.Height - 125), 0);
                    }
                    pdfPageContents.SetFontAndSize(baseFont, 10); // 10 point font
                    pdfPageContents.SetRGBColorFill(0, 0, 0);

                    //Name
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, employee.FirstName + " " + employee.LastName, 210, (pageSize.Height - 150), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "AIS-0" + employee.TimeEmployeeID, 525, (pageSize.Height - 150), 0);

                    //find out how many days are in the month
                    int days = DateTime.DaysInMonth(dt.Year, dt.Month);

                    //Date of report
                    //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, dt.ToShortDateString(), 155, (pageSize.Height - 188), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:MMMM dd, yyyy}", dt), 210, (pageSize.Height - 172), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:MMMM dd, yyyy}", dt.AddDays(days - 1)), 525, (pageSize.Height - 172), 0);

                    int yPos = 221;
                    int localLoopCount = 0;
                    foreach (var timeProjectHourse in projects)
                    {
                        if (localLoopCount > currentLoopCount || currentLoopCount == 0)
                        {
                            TimeResources resource = TimeResources.ReadFirst("TimeResourceID = @TimeResourceID", "@TimeResourceID", timeProjectHourse.TimeResourceID);
                            TimeAISCodes classCode = TimeAISCodes.ReadFirst("TimeAISCodeID = @TimeAISCodeID", "@TimeAISCodeID", resource.TimeAISCodeID);
                            TimeDepartments deptCode = TimeDepartments.ReadFirst("TimeDepartmentID = @TimeDepartmentID", "@TimeDepartmentID", timeProjectHourse.TimeDepartmentID);
                            TimeProjects project = TimeProjects.ReadFirst("TimeProjectID = @TimeProjectID", "@TimeProjectID", timeProjectHourse.TimeProjectID);

                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:MMM d}", timeProjectHourse.DateOfWork), 70, (pageSize.Height - yPos), 0);
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, project.ProjectNumber, 115, (pageSize.Height - yPos), 0);
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, classCode.AISCode, 175, (pageSize.Height - yPos), 0);

                            //show the function
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deptCode.DepartmentName, 220, (pageSize.Height - yPos), 0);

                            //show the hours worked
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, timeProjectHourse.HoursOfWork.ToString(), 730, (pageSize.Height - yPos), 0);

                            const int NUM_CHARS_ALLOWED = 85;
                            int numLines = 0;
                            if (timeProjectHourse.Description.Length <= NUM_CHARS_ALLOWED)
                                numLines = 1;
                            else if (timeProjectHourse.Description.Length > NUM_CHARS_ALLOWED && timeProjectHourse.Description.Length <= (NUM_CHARS_ALLOWED * 2))
                                numLines = 2;
                            else if (timeProjectHourse.Description.Length > (NUM_CHARS_ALLOWED * 2) && timeProjectHourse.Description.Length <= (NUM_CHARS_ALLOWED * 3))
                                numLines = 3;

                            int partCount = numLines;
                            string input = timeProjectHourse.Description;
                            var results = new string[partCount];
                            int rem = timeProjectHourse.Description.Length % NUM_CHARS_ALLOWED;
                            for (var i = 0; i < partCount; i++)
                            {
                                if (i == partCount - 1)
                                    results[i] = input.Substring(NUM_CHARS_ALLOWED * i, rem);
                                else
                                    results[i] = input.Substring(NUM_CHARS_ALLOWED * i, NUM_CHARS_ALLOWED);
                            }

                            for (var l = 0; l < numLines; l++)
                            {
                                pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, results[l], 345, (pageSize.Height - yPos), 0);
                                yPos += 10;
                            }

                            //increment the total hours
                            totalHours += timeProjectHourse.HoursOfWork;

                            var botPos = (int)(pageSize.Height - yPos);
                            pdfPageContents.SetLineWidth((float).5);
                            pdfPageContents.MoveTo(65, botPos);
                            pdfPageContents.LineTo(pageSize.Width - 35, botPos);
                            pdfPageContents.Stroke();

                            yPos += 10;

                            totalItemCount++;

                            //check to see if we are at the bottom of the page
                            if (yPos > 480) //540
                            {
                                break;
                            }
                        }
                        localLoopCount++;
                    }

                    currentLoopCount = localLoopCount;

                    if (totalItemCount == projects.Count)
                    {
                        //Total
                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Total Hours " + totalHours.ToString(), 730, (pageSize.Height - yPos), 0);
                    }

                    #region LEGEND SECTION
                    //horizontal
                    pdfPageContents.MoveTo(68, 40);
                    pdfPageContents.LineTo(pageSize.Width - 325, 40);
                    pdfPageContents.Stroke();

                    pdfPageContents.SetLineWidth((float).5);
                    pdfPageContents.MoveTo(68, 55);
                    pdfPageContents.LineTo(pageSize.Width - 325, 55);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(68, 70);
                    pdfPageContents.LineTo(pageSize.Width - 325, 70);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(68, 85);
                    pdfPageContents.LineTo(pageSize.Width - 325, 85);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(68, 100);
                    pdfPageContents.LineTo(pageSize.Width - 325, 100);
                    pdfPageContents.Stroke();
                    //horizontal

                    //vertical
                    pdfPageContents.MoveTo(68, 40);
                    pdfPageContents.LineTo(68, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(191, 40);
                    pdfPageContents.LineTo(191, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(204, 40);
                    pdfPageContents.LineTo(204, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(304, 40);
                    pdfPageContents.LineTo(304, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(318, 40);
                    pdfPageContents.LineTo(318, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(445, 40);
                    pdfPageContents.LineTo(445, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(pageSize.Width - 325, 40);
                    pdfPageContents.LineTo(pageSize.Width - 325, 100);
                    pdfPageContents.Stroke();
                    //end vertical

                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " CODE LEGEND", 70, 105, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " Assistant Project Engineer   B   Software Developer       D   Advanced Specialist Engineer   F+   ", 78, 90, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " General Management           C   Specialist Engineer        D   Report Writing                           R   ", 78, 75, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " Mathematician                     D   User Experience (GUI)  D   Technician                                  T4   ", 78, 60, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "                                                                                                 Technical Meeting                     TM", 78, 45, 0);
                    #endregion

                    pdfPageContents.EndText(); // Done working with text
                    pdfStamper.FormFlattening = true; // enable this if you want the PDF flattened.
                    pdfStamper.Close(); // Always close the stamper or you'll have a 0 byte stream.

                    pages.Add(memoryStream.ToArray());
                }
            }

            return pages;
        }
Esempio n. 21
0
        private void CreateProjectWeeklyPDFReport(CSList<TimeProjectHours> projects, DateTime dt, TimeProjects projectDetails, WeeklyReportResult[] results)
        {
            try
            {
                string templatePdfPath = Server.MapPath("PDFimages");
                string oldFile = templatePdfPath + "\\WeeklyProjectTemplate.pdf";

                List<byte[]> pages = WriteToPdfForProjectWeekly(oldFile, projects, dt, projectDetails, results);

                //if (b == null) return;
                //HttpResponse response = HttpContext.Current.Response;
                //response.Clear();
                //response.ContentType = "application/pdf";
                //response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", "WeeklyProjectTimeCard"));
                //response.BinaryWrite(b);
                //response.Flush();
                //response.End();

                if (pages == null) return;
                using (var output = new MemoryStream())
                {
                    var document = new Document();
                    var writer = new PdfCopy(document, output);
                    document.Open();
                    for (int index = 0; index < pages.Count; index++)
                    {
                        var file = pages[index];
                        var reader = new PdfReader(file);
                        int n = reader.NumberOfPages;
                        for (int p = 1; p <= n; p++)
                        {
                            PdfImportedPage page = writer.GetImportedPage(reader, p);
                            writer.AddPage(page);
                        }
                    }
                    document.Close();
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}.pdf", "WeeklyProjectTimeCard"));
                    Response.BinaryWrite(output.ToArray());
                    Response.Flush();
                    Response.End();
                }
            }
            catch (Exception ex)
            {
                lblErrorWeeklyReport.Text = "Error: " + ex.Message;
            }
        }
Esempio n. 22
0
        public byte[] WriteToPdfForEmployeeDaily(string sourceFile, CSList<TimeProjectHours> projects, TimeEmployees employee, DateTime dt)
        {
            var reader = new PdfReader(sourceFile);

            using (var memoryStream = new MemoryStream())
            {
                // PDFStamper is the class we use from iTextSharp to alter an existing PDF.
                var pdfStamper = new PdfStamper(reader, memoryStream);

                Rectangle pageSize = reader.GetPageSizeWithRotation(1);

                PdfContentByte pdfPageContents = pdfStamper.GetOverContent(1);
                pdfPageContents.BeginText(); // Start working with text.

                BaseFont baseFont = BaseFont.CreateFont(BaseFont.COURIER, Encoding.ASCII.EncodingName, false);
                pdfPageContents.SetFontAndSize(baseFont, 11); // 11 point font
                pdfPageContents.SetRGBColorFill(0, 0, 0);

                // Note: The x,y of the Pdf Matrix is from bottom left corner.
                // This command tells iTextSharp to write the text at a certain location with a certain angle.
                // Again, this will angle the text from bottom left corner to top right corner and it will
                // place the text in the middle of the page.
                //
                //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, playerName, pageSize.Width / 2, (pageSize.Height / 2) + 115, 0);
                //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, teamName, pageSize.Width / 2, (pageSize.Height / 2) + 80, 0);

                //user Name
                pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, employee.FirstName + " " + employee.LastName + " (AIS-0" + employee.TimeEmployeeID + ")", 155, (pageSize.Height - 168), 0);

                //Date of report
                pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, dt.ToShortDateString(), 155, (pageSize.Height - 188), 0);

                int yPos = 241;
                int totalHours = 0;
                foreach (var timeProjectHourse in projects)
                {
                    TimeResources resource = TimeResources.ReadFirst("TimeResourceID = @TimeResourceID", "@TimeResourceID", timeProjectHourse.TimeResourceID);
                    TimeAISCodes classCode = TimeAISCodes.ReadFirst("TimeAISCodeID = @TimeAISCodeID", "@TimeAISCodeID", resource.TimeAISCodeID);

                    TimeProjects project = TimeProjects.ReadFirst("TimeProjectID = @TimeProjectID", "@TimeProjectID", timeProjectHourse.TimeProjectID);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, project.ProjectNumber, 55, (pageSize.Height - yPos), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, classCode.AISCode, 125, (pageSize.Height - yPos), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, project.ProjectName, 185, (pageSize.Height - yPos), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, timeProjectHourse.HoursOfWork.ToString(), 500, (pageSize.Height - yPos), 0);

                    //increment the total hours
                    totalHours += timeProjectHourse.HoursOfWork;

                    yPos += 20;
                }

                //Total

                pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, totalHours.ToString(), 500, (pageSize.Height - 685), 0);

                pdfPageContents.EndText(); // Done working with text
                pdfStamper.FormFlattening = true; // enable this if you want the PDF flattened.
                pdfStamper.Close(); // Always close the stamper or you'll have a 0 byte stream.

                return memoryStream.ToArray();
            }
        }
Esempio n. 23
0
        public List<byte[]> WriteToPdfForProjectWeekly(string sourceFile, CSList<TimeProjectHours> projects, DateTime dt, TimeProjects projectDetails, WeeklyReportResult[] results)
        {
            var pages = new List<byte[]>();

            int totalItemCount = 0;
            int currentLoopCount = 0;
            int totalHours = 0;
            decimal totalCharge = 0;

            int pageCount = 0;
            while (totalItemCount < projects.Count)
            {
                pageCount += 1;
                var reader = new PdfReader(sourceFile);

                using (var memoryStream = new MemoryStream())
                {
                    // PDFStamper is the class we use from iTextSharp to alter an existing PDF.
                    var pdfStamper = new PdfStamper(reader, memoryStream);

                    Rectangle pageSize = reader.GetPageSizeWithRotation(1);

                    PdfContentByte pdfPageContents = pdfStamper.GetOverContent(1);
                    pdfPageContents.BeginText(); // Start working with text.

                    BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, Encoding.ASCII.EncodingName, false);
                    pdfPageContents.SetFontAndSize(baseFont, 10); // 10 point font
                    pdfPageContents.SetRGBColorFill(0, 0, 0);

                    //      //customer
                    //TimeCustomers customer = TimeCustomers.ReadFirst("TimeCustomerID = @TimeCustomerID", "@TimeCustomerID", projectDetails.TimeCustomerID);
                    //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, customer.CustomerName, 210, (pageSize.Height - 150), 0);

                    //project name
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, projectDetails.ProjectName, 210, (pageSize.Height - 150), 0);

                    //Project Number
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, projectDetails.ProjectNumber, 525, (pageSize.Height - 150), 0);

                    //Date of report, shows week span
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:MMMM dd, yyyy}", dt), 210, (pageSize.Height - 172), 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:MMMM dd, yyyy}", dt.AddDays(6)), 525, (pageSize.Height - 172), 0);

                    int yPos = 221;
                    int localLoopCount = 0;
                    foreach (var timeProjectHourse in projects)
                    {
                        if (localLoopCount > currentLoopCount || currentLoopCount == 0)
                        {
                            TimeResources resource = TimeResources.ReadFirst("TimeResourceID = @TimeResourceID", "@TimeResourceID", timeProjectHourse.TimeResourceID);
                            TimeAISCodes classCode = TimeAISCodes.ReadFirst("TimeAISCodeID = @TimeAISCodeID", "@TimeAISCodeID", resource.TimeAISCodeID);
                            TimeDepartments deptCode = TimeDepartments.ReadFirst("TimeDepartmentID = @TimeDepartmentID", "@TimeDepartmentID", timeProjectHourse.TimeDepartmentID);
                            TimeProjects project = TimeProjects.ReadFirst("TimeProjectID = @TimeProjectID", "@TimeProjectID", timeProjectHourse.TimeProjectID);
                            //TimeEmployees employee = TimeEmployees.ReadFirst("TimeEmployeeID = @TimeEmployeeID", "@TimeEmployeeID", timeProjectHourse.TimeEmployeeID);

                            //show the date worked
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:MMM d}", timeProjectHourse.DateOfWork), 82, (pageSize.Height - yPos), 0);
                            //show the employee id
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "AIS-0" + timeProjectHourse.TimeEmployeeID, 121, (pageSize.Height - yPos), 0);
                            //show the code
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, classCode.AISCode, 176, (pageSize.Height - yPos), 0);
                            //show the function
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deptCode.DepartmentName, 205, (pageSize.Height - yPos), 0);
                            //show the hours worked
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, timeProjectHourse.HoursOfWork.ToString(), 640, (pageSize.Height - yPos), 0);
                            //show the hourly rate
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:C}", resource.HourlyRate), 662, (pageSize.Height - yPos), 0);

                            decimal totalForDay = timeProjectHourse.HoursOfWork * resource.HourlyRate;

                            //show the total dollars for that day
                            pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:C}", totalForDay), 705, (pageSize.Height - yPos), 0);

                            const int NUM_CHARS_ALLOWED = 65;
                            int numLines = 0;
                            if (timeProjectHourse.Description.Length <= NUM_CHARS_ALLOWED)
                                numLines = 1;
                            else if (timeProjectHourse.Description.Length > NUM_CHARS_ALLOWED && timeProjectHourse.Description.Length <= (NUM_CHARS_ALLOWED * 2))
                                numLines = 2;
                            else if (timeProjectHourse.Description.Length > (NUM_CHARS_ALLOWED * 2) && timeProjectHourse.Description.Length <= (NUM_CHARS_ALLOWED * 3))
                                numLines = 3;
                            else if (timeProjectHourse.Description.Length > (NUM_CHARS_ALLOWED * 3) && timeProjectHourse.Description.Length <= (NUM_CHARS_ALLOWED * 4))
                                numLines = 4;

                            int partCount = numLines;
                            string input = timeProjectHourse.Description;
                            var descResults = new string[partCount];
                            int rem = timeProjectHourse.Description.Length % NUM_CHARS_ALLOWED;
                            for (var i = 0; i < partCount; i++)
                            {
                                if (i == partCount - 1)
                                    descResults[i] = input.Substring(NUM_CHARS_ALLOWED * i, rem);
                                else
                                    descResults[i] = input.Substring(NUM_CHARS_ALLOWED * i, NUM_CHARS_ALLOWED);
                            }

                            for (var l = 0; l < numLines; l++)
                            {
                                pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, descResults[l], 325, (pageSize.Height - yPos), 0);
                                yPos += 10;
                            }

                            //increment the total hours
                            totalHours += timeProjectHourse.HoursOfWork;

                            //increment the total charge-out
                            totalCharge += totalForDay;

                            var botPos = (int)(pageSize.Height - yPos);
                            pdfPageContents.SetLineWidth((float).5);
                            pdfPageContents.MoveTo(68, botPos);
                            pdfPageContents.LineTo(pageSize.Width - 38, botPos);
                            pdfPageContents.Stroke();

                            yPos += 10;

                            totalItemCount++;

                            //check to see if we are at the bottom of the page
                            if (yPos > 480) //540
                            {
                                break;
                            }
                        }
                        localLoopCount++;
                    }

                    currentLoopCount = localLoopCount;

                    if (totalItemCount == projects.Count)
                    {
                        //Total
                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Totals", 620, (pageSize.Height - yPos), 0);
                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, totalHours.ToString(), 640, (pageSize.Height - yPos), 0);
                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, String.Format("{0:C}", totalCharge), 705, (pageSize.Height - yPos), 0);

                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Page " + pageCount, 705, (pageSize.Height - (yPos + 20)), 0);
                    }
                    else
                    {
                        pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Page " + pageCount, 705, (pageSize.Height - (yPos + 20)), 0);
                    }

                    #region LEGEND SECTION
                    //horizontal
                    pdfPageContents.MoveTo(68, 40);
                    pdfPageContents.LineTo(pageSize.Width - 325, 40);
                    pdfPageContents.Stroke();

                    pdfPageContents.SetLineWidth((float).5);
                    pdfPageContents.MoveTo(68, 55);
                    pdfPageContents.LineTo(pageSize.Width - 325, 55);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(68, 70);
                    pdfPageContents.LineTo(pageSize.Width - 325, 70);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(68, 85);
                    pdfPageContents.LineTo(pageSize.Width - 325, 85);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(68, 100);
                    pdfPageContents.LineTo(pageSize.Width - 325, 100);
                    pdfPageContents.Stroke();
                    //horizontal

                    //vertical
                    pdfPageContents.MoveTo(68, 40);
                    pdfPageContents.LineTo(68, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(191, 40);
                    pdfPageContents.LineTo(191, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(204, 40);
                    pdfPageContents.LineTo(204, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(304, 40);
                    pdfPageContents.LineTo(304, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(318, 40);
                    pdfPageContents.LineTo(318, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(445, 40);
                    pdfPageContents.LineTo(445, 100);
                    pdfPageContents.Stroke();

                    pdfPageContents.MoveTo(pageSize.Width - 325, 40);
                    pdfPageContents.LineTo(pageSize.Width - 325, 100);
                    pdfPageContents.Stroke();
                    //end vertical

                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " CODE LEGEND", 70, 105, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " Assistant Project Engineer   B   Software Developer       D   Advanced Specialist Engineer   F+   ", 78, 90, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " General Management           C   Specialist Engineer        D   Report Writing                           R   ", 78, 75, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, " Mathematician                     D   User Experience (GUI)  D   Technician                                  T4   ", 78, 60, 0);
                    pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "                                                                                                 Technical Meeting                     TM", 78, 45, 0);
                    #endregion

                    pdfPageContents.EndText(); // Done working with text
                    pdfStamper.FormFlattening = true; // enable this if you want the PDF flattened.
                    pdfStamper.Close(); // Always close the stamper or you'll have a 0 byte stream.

                    pages.Add(memoryStream.ToArray());
                }
            }

            return pages;
        }
Esempio n. 24
0
        private void Populate()
        {
            if (Populated)
            {
                return;
            }

            if (Relation != null && RelationObject != null && Relation.RelationType == CSSchemaRelationType.OneToMany && RelationObject.IsNew)
            {
                _objectArray = new List <TObjectType>();
                Populated    = true;

                return;
            }

            CSTable table = new CSTable(Schema);

            //string mainAlias = CSHelper.NextTableAlias;

            List <string> columnList             = new List <string>(Schema.ColumnsToRead.Count);
            List <string> aliasList              = new List <string>(Schema.ColumnsToRead.Count);
            Dictionary <string, string> aliasMap = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            foreach (string columnName in Schema.ColumnsToRead)
            {
                string alias = CSNameGenerator.NextFieldAlias;

                columnList.Add(table.TableAlias + "." + columnName);
                aliasList.Add(alias);
                aliasMap.Add(alias, columnName);
            }

            CSJoinList filterJoins = new CSJoinList();

            List <PrefetchField> prefetchFields = CSObject.GetPrefetchFieldsOne(table, columnList, aliasList, filterJoins, PrefetchPaths);

            CSFilter whereFilter;

            if (PrefetchFilter != null)
            {
                whereFilter = new CSFilter(DB.QuoteField(table.TableAlias + "." + PrefetchFilter.ForeignKey) + " in (" + PrefetchFilter.InStatement + ")", PrefetchFilter.Parameters);
            }
            else
            {
                string parsedFilterExpression = CSExpressionParser.ParseFilter(Filter.Expression, Schema, table.TableAlias, filterJoins);

                whereFilter = new CSFilter(parsedFilterExpression, Filter.Parameters);

                CSFilter relationFilter = BuildRelationFilter(table.TableAlias);

                whereFilter = whereFilter.And(CSExpressionParser.ParseFilter(relationFilter.Expression, Schema, table.TableAlias, filterJoins), relationFilter.Parameters);
            }

            string parsedOrderBy = CSExpressionParser.ParseOrderBy(OrderBy, Schema, table.TableAlias, filterJoins);

            string sqlQuery = DB.BuildSelectSQL(table.TableName, table.TableAlias, columnList.ToArray(), aliasList.ToArray(), filterJoins.BuildJoinExpressions(), whereFilter.Expression, parsedOrderBy, StartRecord, MaxRecords, true, false);

            _objectArray = GetObjects(sqlQuery, whereFilter.Parameters, aliasMap, prefetchFields);

            if (Schema.KeyColumns.Count == 1)
            {
                string columnName = Schema.KeyColumns[0].Name;

                _objectMap = new Dictionary <object, TObjectType>();

                foreach (TObjectType csObject in _objectArray)
                {
                    _objectMap.Add(csObject.Data["#" + columnName].Value, csObject);
                }
            }

            foreach (CSSchemaField prefetchField in GetPrefetchFieldsMany())
            {
                CSRelation relation = prefetchField.Relation;

                Dictionary <object, TObjectType> prefetchMap = new Dictionary <object, TObjectType>();

                // Creates empty lists in each object of this list
                foreach (TObjectType csObject in _objectArray)
                {
                    prefetchMap[csObject.Data["#" + relation.LocalKey].Value] = csObject;

                    CSList relationCollection = (CSList)Activator.CreateInstance(prefetchField.FieldType);

                    relationCollection.Relation       = relation;
                    relationCollection.RelationObject = csObject;

                    relationCollection.InitializePrefetch();

                    csObject.Data[prefetchField.Name].ValueDirect = relationCollection;
                    csObject.Data[prefetchField.Name].ValueState  = CSFieldValueState.Read;
                }

                Type objectType = relation.ForeignSchema.ClassType;

                CSList csList = (CSList)Activator.CreateInstance(typeof(CSList <>).MakeGenericType(objectType));

                //string prefetchTableAlias = CSNameGenerator.NextTableAlias;

                string prefetchFilter = DB.BuildSelectSQL(table.TableName, table.TableAlias, new[] { table.TableAlias + "." + relation.LocalKey }, new[] { CSNameGenerator.NextFieldAlias }, filterJoins.BuildJoinExpressions(), whereFilter.Expression, parsedOrderBy, StartRecord, MaxRecords, true, true);

                csList.PrefetchFilter = new PrefetchFilter(relation.ForeignKey, prefetchFilter, whereFilter.Parameters);

                if (PrefetchPaths != null && PrefetchPaths.Length > 0)
                {
                    List <string> newPrefetchPaths = new List <string>();

                    foreach (string path in PrefetchPaths)
                    {
                        if (path.StartsWith(prefetchField.Name + "."))
                        {
                            newPrefetchPaths.Add(path.Substring(prefetchField.Name.Length + 1));
                        }
                    }

                    if (newPrefetchPaths.Count > 0)
                    {
                        csList.PrefetchPaths = newPrefetchPaths.ToArray();
                    }
                }

                foreach (CSObject csObject in csList)
                {
                    object localKey = csObject.Data["#" + relation.ForeignKey].ValueDirect;

                    CSList relationCollection = (CSList)prefetchMap[localKey].Data[prefetchField.Name].ValueDirect;

                    relationCollection.AddFromPrefetch(csObject);
                }
            }


            Populated = true;
        }
Esempio n. 25
0
        private void CreateDailyEmployeePDFReport(CSList<TimeProjectHours> projects, TimeEmployees employee, DateTime dt)
        {
            try
            {
                string templatePdfPath = Server.MapPath("PDFimages");
                string oldFile = templatePdfPath + "\\DailyTemplate.pdf";

                byte[] b = WriteToPdfForEmployeeDaily(oldFile, projects, employee, dt);
                if (b == null) return;
                HttpResponse response = HttpContext.Current.Response;
                response.Clear();
                response.ContentType = "application/pdf";
                response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}-{1}.pdf", "DailyTimeCard-", employee.FirstName + "_" + employee.LastName));
                response.BinaryWrite(b);
                response.Flush();
                response.End();
            }
            catch (Exception ex)
            {
                lblError.Text = "Error: " + ex.Message;
            }
        }