/// <summary> /// Print out Shipping Label /// for the product Buyer /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OrderSellItemList_RowCommand(object sender, GridViewCommandEventArgs e) { // Print out PDF Shipping Label // Create a new PDF document String directory1 = Server.MapPath("~/PDF/Course Request Form_fillable format.pdf"); PdfDocument document = PdfReader.Open(directory1, PdfDocumentOpenMode.Modify); //document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfPage page = document.Pages[0]; // Retrieve Order Information int id = Convert.ToInt32(e.CommandArgument); List<WebApplication1.HalonModels.Class> allclass = _db.Classes.ToList(); List<WebApplication1.HalonModels.Course> allcourse = _db.Courses.ToList(); WebApplication1.HalonModels.Class cl = new WebApplication1.HalonModels.Class(); cl = allclass.Where(c => c.Class_ID == id).FirstOrDefault(); int temp1 = Convert.ToInt32(cl.Course_ID.ToString()); // Get its Course_ID // Look for the course related to above class WebApplication1.HalonModels.Course co = allcourse.Where(d => d.Course_ID == temp1).FirstOrDefault(); // Look for the teacher teaches this class int fid = Convert.ToInt32(cl.Firefighter_ID.ToString()); WebApplication1.HalonModels.Firefighter t = _db.Firefighters.Where(f => f.Firefighter_ID == fid).FirstOrDefault(); // Get the current Department WebApplication1.HalonModels.Department de = _db.Departments.ToList().FirstOrDefault(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 11, XFontStyle.Bold); XFont font1 = new XFont("Arial", 30, XFontStyle.Bold); XFont font2 = new XFont("Arial", 28, XFontStyle.Regular); XFont font3 = new XFont("Arial", 32, XFontStyle.Bold); // Retrieve Information String class_name = co.Course_Name; String request_date = DateTime.Now.ToShortDateString(); String department_name = de.Dept_Name; String department_address = de.Dept_Address + " " + de.Dept_City; String user = Context.User.Identity.Name + "'s role"; String department_phone = de.Dept_Tel_No; String teacher = t.Firefighter_Fname + " " + t.Firefighter_Lname; // Draw the text gfx.DrawString(class_name, font, XBrushes.Black, new XRect(143, 148, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(request_date, font, XBrushes.Black, new XRect(475, 148, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(department_name, font, XBrushes.Black, new XRect(228, 175, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(department_address, font, XBrushes.Black, new XRect(228, 202, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(user, font, XBrushes.Black, new XRect(156, 229, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(department_phone, font, XBrushes.Black, new XRect(279, 267, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(teacher, font, XBrushes.Black, new XRect(156, 498, page.Width, page.Height), XStringFormat.TopLeft); String directory = @"R:\"; // Save the document... string filename = "NewClass" + id + "request.pdf"; document.Save(Path.Combine(directory, filename)); // ...and start a viewer. // Process.Start(filename); var fileName1 = @"R:\" + filename; var startInfo = new ProcessStartInfo(fileName1); string verbToUse = "Open"; startInfo.Verb = verbToUse; Process print = Process.Start(startInfo); ClassTable.DataBind(); }
public void CreatePDF(int id, String tag) { PdfDocument document = null; string filename = ""; if (tag.Equals("Label")) { // Print out PDF Shipping Label // Create a new PDF document String directory1 = Server.MapPath("~/PDF/Course Request Form_fillable format.pdf"); document = PdfReader.Open(directory1, PdfDocumentOpenMode.Modify); //document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfPage page = document.Pages[0]; // Retrieve Order Information List<WebApplication1.HalonModels.Class> allclass = _db.Classes.ToList(); List<WebApplication1.HalonModels.Course> allcourse = _db.Courses.ToList(); WebApplication1.HalonModels.Class cl = new WebApplication1.HalonModels.Class(); cl = allclass.Where(c => c.Class_ID == id).FirstOrDefault(); int temp1 = Convert.ToInt32(cl.Course_ID.ToString()); // Get its Course_ID // Look for the course related to above class WebApplication1.HalonModels.Course co = allcourse.Where(d => d.Course_ID == temp1).FirstOrDefault(); // Look for the teacher teaches this class int fid = Convert.ToInt32(cl.Firefighter_ID.ToString()); WebApplication1.HalonModels.Firefighter t = _db.Firefighters.Where(f => f.Firefighter_ID == fid).FirstOrDefault(); String user1 = Context.User.Identity.Name; WebApplication1.HalonModels.Firefighter rank = _db.Firefighters.Where(f => f.Firefighter_Account_Username.Equals(user1)).FirstOrDefault(); String user = rank.Firefighter_Rank; // Get the current Department WebApplication1.HalonModels.Department de = _db.Departments.ToList().FirstOrDefault(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 11, XFontStyle.Bold); XFont font1 = new XFont("Arial", 30, XFontStyle.Bold); XFont font2 = new XFont("Arial", 28, XFontStyle.Regular); XFont font3 = new XFont("Arial", 32, XFontStyle.Bold); // Retrieve Information String class_name = co.Course_Name; String request_date = DateTime.Now.ToShortDateString(); String department_name = de.Dept_Name; String department_address = de.Dept_Address + " " + de.Dept_City; String department_phone = de.Dept_Tel_No; String teacher = t.Firefighter_Fname + " " + t.Firefighter_Lname; // Draw the text gfx.DrawString(class_name, font, XBrushes.Black, new XRect(143, 148, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(request_date, font, XBrushes.Black, new XRect(475, 148, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(department_name, font, XBrushes.Black, new XRect(228, 175, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(department_address, font, XBrushes.Black, new XRect(228, 202, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(user, font, XBrushes.Black, new XRect(156, 229, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(department_phone, font, XBrushes.Black, new XRect(279, 267, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(teacher, font, XBrushes.Black, new XRect(156, 498, page.Width, page.Height), XStringFormat.TopLeft); // Save the document... filename = "NewClass" + id + "request.pdf"; } else { if (tag.Equals("Label2")) { // Print out PDF Shipping Label // Create a new PDF document String directory1 = Server.MapPath("~/PDF/Copy of roster.pdf"); document = PdfReader.Open(directory1, PdfDocumentOpenMode.Modify); //document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfPage page = document.Pages[0]; // Retrieve Order Information List<WebApplication1.HalonModels.Class> allclass = _db.Classes.ToList(); List<WebApplication1.HalonModels.Course> allcourse = _db.Courses.ToList(); List<WebApplication1.HalonModels.Department> alldept = _db.Departments.ToList(); WebApplication1.HalonModels.Class cl = new WebApplication1.HalonModels.Class(); cl = allclass.Where(c => c.Class_ID == id).FirstOrDefault(); int temp1 = Convert.ToInt32(cl.Course_ID.ToString()); // Get its Course_ID // Look for the course related to above class WebApplication1.HalonModels.Course co = allcourse.Where(d => d.Course_ID == temp1).FirstOrDefault(); // Look for the teacher teaches this class int fid = Convert.ToInt32(cl.Firefighter_ID.ToString()); WebApplication1.HalonModels.Firefighter t = _db.Firefighters.Where(f => f.Firefighter_ID == fid).FirstOrDefault(); // Look for all the enrollments for this class List<WebApplication1.HalonModels.Enrollment> enrollList = cl.Enrollments.ToList(); // Get the current Department WebApplication1.HalonModels.Department de = _db.Departments.ToList().FirstOrDefault(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 11, XFontStyle.Bold); XFont font1 = new XFont("Arial", 9, XFontStyle.Bold); XFont font2 = new XFont("Arial", 28, XFontStyle.Regular); XFont font3 = new XFont("Arial", 32, XFontStyle.Bold); // Retrieve Information String class_name = co.Course_Name; String course_num = co.Course_ID.ToString(); String course_hour = co.Course_Credit_Hours.ToString(); String course_start = cl.Class_Date.ToString(); // Draw the text gfx.DrawString(class_name, font, XBrushes.Black, new XRect(110, 157, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(course_num, font, XBrushes.Black, new XRect(290, 157, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(course_hour, font, XBrushes.Black, new XRect(390, 157, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(course_start, font, XBrushes.Black, new XRect(485, 157, page.Width, page.Height), XStringFormat.TopLeft); // Populate roster for (int i = 0; i < enrollList.Count; i++) { int y = (i * 15) + 252; String ffter_lname = enrollList[i].Firefighter.Firefighter_Lname.ToString(); String ffter_fname = enrollList[i].Firefighter.Firefighter_Fname.ToString(); String ffter_mname = enrollList[i].Firefighter.Firefighter_MI.ToString(); String ffter_dob = enrollList[i].Firefighter.Firefighter_DOB.ToString(); int? temp = enrollList[i].Firefighter.Dept_ID; String ffter_dept = alldept.Where(d => d.Dept_ID == temp.Value).FirstOrDefault().Dept_Name.ToString(); String ffter_fdid = alldept.Where(d => d.Dept_ID == temp.Value).FirstOrDefault().Dept_FDID.ToString(); gfx.DrawString(ffter_lname, font1, XBrushes.Black, new XRect(110, y, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(ffter_fname, font1, XBrushes.Black, new XRect(251, y, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(ffter_mname, font1, XBrushes.Black, new XRect(330, y, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(ffter_dob, font1, XBrushes.Black, new XRect(348, y, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(ffter_dept, font1, XBrushes.Black, new XRect(430, y, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(ffter_fdid, font1, XBrushes.Black, new XRect(540, y, page.Width, page.Height), XStringFormat.TopLeft); } // Save the document... filename = "Class " + id + "Roster.pdf"; } } String directory = Server.MapPath("~"); document.Save(Path.Combine(directory, filename)); // ...and start a viewer. // Process.Start(filename); var fileName1 = directory + filename; var startInfo = new ProcessStartInfo(fileName1); string verbToUse = "Open"; startInfo.Verb = verbToUse; Process print = Process.Start(startInfo); ClassInfo.DataBind(); }
public void CreatePDF(int id, String tag) { PdfDocument document = null; string filename = ""; if (tag.Equals("AA")) { // Print out PDF Shipping Label // Create a new PDF document String directory1 = Server.MapPath("~/PDF/afta_course_app_rev9-10.pdf"); document = PdfReader.Open(directory1, PdfDocumentOpenMode.Modify); //document.Info.Title = "Created with PDFsharp"; // Create an empty page PdfPage page = document.Pages[0]; // Retrieve Order Information List<WebApplication1.HalonModels.Class> allclass = _db.Classes.ToList(); List<WebApplication1.HalonModels.Course> allcourse = _db.Courses.ToList(); List<WebApplication1.HalonModels.Department> alldept = _db.Departments.ToList(); List<WebApplication1.HalonModels.Enrollment> allen = _db.Enrollments.ToList(); List<WebApplication1.HalonModels.State> allstate = _db.States.ToList(); // Look for this enrollment based on the ID WebApplication1.HalonModels.Enrollment en = allen.Where(e => e.Enrollment_ID == id).FirstOrDefault(); int cid = Convert.ToInt32(en.Class_ID.ToString()); // Look for the class related to this enrollment WebApplication1.HalonModels.Class cl = new WebApplication1.HalonModels.Class(); cl = allclass.Where(c => c.Class_ID == cid).FirstOrDefault(); int temp1 = Convert.ToInt32(cl.Course_ID.ToString()); // Get its Course_ID // Look for the course related to above class WebApplication1.HalonModels.Course co = allcourse.Where(d => d.Course_ID == temp1).FirstOrDefault(); // Look for the student/firefighter related to this enrollment int fid = Convert.ToInt32(en.Firefighter_ID.ToString()); WebApplication1.HalonModels.Firefighter t = _db.Firefighters.Where(f => f.Firefighter_ID == fid).FirstOrDefault(); // Look for the state this student live in int sid = Convert.ToInt32(t.State_ID.ToString()); WebApplication1.HalonModels.State st = allstate.Where(s => s.State_ID == sid).FirstOrDefault(); // Get the current Department int did = Convert.ToInt32(t.Dept_ID.ToString()); WebApplication1.HalonModels.Department de = _db.Departments.Where(d => d.Dept_ID == did).FirstOrDefault(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 10, XFontStyle.Bold); XFont font1 = new XFont("Verdana", 8, XFontStyle.Bold); XFont font2 = new XFont("Verdana", 7, XFontStyle.Bold); XFont font3 = new XFont("Arial", 32, XFontStyle.Bold); // Retrieve Information String fname = t.Firefighter_Lname + " " + t.Firefighter_MI + " " + t.Firefighter_Fname; String faddress = t.Firefighter_Address + " " + t.Firefighter_City + " " + st.State_Name + " " + t.Firefighter_Zip; String fphone = t.Firefighter_Cell_Ph; String fdob1 = t.Firefighter_DOB.Substring(0, 2); String fdob2 = t.Firefighter_DOB.Substring(3, 2); String fdob3 = "20" + t.Firefighter_DOB.Substring(6, 2); String fsex = t.Firefighter_Gender; String frace = t.Firefighter_Race; String class_name = co.Course_Name; String class_date = cl.Class_Date; String dept_fdid = de.Dept_FDID; String dept_name = de.Dept_Name; String dept_phone = de.Dept_Tel_No; String dept_address = de.Dept_Address + ", " + de.Dept_City + " " + de.Dept_Zip; // Draw the text gfx.DrawString(fname, font, XBrushes.Black, new XRect(155, 75, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(faddress, font, XBrushes.Black, new XRect(57, 100, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(fphone, font, XBrushes.Black, new XRect(330, 95, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(fdob1, font, XBrushes.Black, new XRect(421, 100, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(fdob2, font, XBrushes.Black, new XRect(464.75, 100, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(fdob3, font, XBrushes.Black, new XRect(500, 100, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(fsex, font, XBrushes.Black, new XRect(464.75, 150, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(frace, font1, XBrushes.Black, new XRect(346, 166, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(class_name, font, XBrushes.Black, new XRect(135, 321, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(class_date, font, XBrushes.Black, new XRect(443, 321, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(dept_fdid, font, XBrushes.Black, new XRect(86, 458, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(dept_name, font, XBrushes.Black, new XRect(186, 458, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(dept_phone, font, XBrushes.Black, new XRect(436, 458, page.Width, page.Height), XStringFormat.TopLeft); gfx.DrawString(dept_address, font1, XBrushes.Black, new XRect(57, 493, page.Width, page.Height), XStringFormat.TopLeft); // Save the document... filename = fname + " " + id + "ClassApplication.pdf"; } else { } String directory = @"D:\"; document.Save(Path.Combine(directory, filename)); // ...and start a viewer. // Process.Start(filename); var fileName1 = @"D:\" + filename; var startInfo = new ProcessStartInfo(fileName1); string verbToUse = "Open"; startInfo.Verb = verbToUse; Process print = Process.Start(startInfo); EnrollmentInfo.DataBind(); }