public string registerSale(string idClient, string phonesQuantities, string total, string key) { EncryptionMethods em = new EncryptionMethods(); string conn = WebConfigurationManager.ConnectionStrings["KeggPhonesConnectionString"].ToString(); ClientBusiness cb = new ClientBusiness(conn); SaleBusiness sb = new SaleBusiness(conn); PhoneSaleBusiness psb = new PhoneSaleBusiness(conn); PhoneBusiness pb = new PhoneBusiness(conn); Client client = cb.getClientById(Int32.Parse(em.decrypting(idClient, key))); Sale sale = new Sale(0, client, Int32.Parse(em.decrypting(total, key)), DateTime.Today.ToString()); int r = sb.insertSale(sale); sale.IdSale = r; string phonesQ = em.decrypting(phonesQuantities, key); string[] phones = phonesQ.Split('#'); for (int i = 0; i < phones.Length; i++) { string[] data = phones[i].Split(';'); Phone phone = pb.getPhoneById(Int32.Parse(data[0])); PhoneSale ps = new PhoneSale(0, phone, sale, Int32.Parse(data[1])); psb.insertPhoneSale(ps); } string response = "1"; return(em.encrypt(response, key)); }
public void generatePhoneSaleReport() { Document doc = new Document(PageSize.A4, 10, 10, 10, 10); string filename = Path.GetFullPath("C:/Users/Brayan/Source/Repos/CoreVises/CoreVises/ReportsPDF/Report" + Guid.NewGuid().ToString().Substring(0, 7) + "_" + DateTime.Today.Date.ToString("yyyy-MM-dd") + ".pdf"); FileStream file = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); PdfWriter.GetInstance(doc, file); doc.Open(); Paragraph pTitle = new Paragraph(new Phrase("Kegg Phones", FontFactory.GetFont("ARIAL", 16, iTextSharp.text.Font.BOLD))); pTitle.Alignment = Element.ALIGN_CENTER; Paragraph pReport = new Paragraph(new Phrase("Report: Top sales of the week", FontFactory.GetFont("ARIAL", 12, iTextSharp.text.Font.NORMAL))); pReport.Alignment = Element.ALIGN_JUSTIFIED; Paragraph pDate = new Paragraph(new Phrase("Date Report: " + DateTime.Now.ToString("d"), FontFactory.GetFont("ARIAL", 12, iTextSharp.text.Font.NORMAL))); pDate.Alignment = Element.ALIGN_JUSTIFIED; Image waterMaker = Image.GetInstance("C:/Users/Brayan/Source/Repos/CoreVises/CoreVises/Images/KeggPhonesImage.png"); waterMaker.SetAbsolutePosition(100, 300); waterMaker.ScalePercent(75); Paragraph pSpace = new Paragraph(" "); PdfPTable informationTable = new PdfPTable(4); informationTable.WidthPercentage = 100; PdfPCell clPhone = new PdfPCell(new Phrase("Phone", FontFactory.GetFont("ARIAL", 12, iTextSharp.text.Font.BOLD))); clPhone.BorderWidth = 0.75f; PdfPCell clCharacteristics = new PdfPCell(new Phrase("Characteristics phone", FontFactory.GetFont("ARIAL", 12, iTextSharp.text.Font.BOLD))); clCharacteristics.BorderWidth = 0.75f; PdfPCell clPrice = new PdfPCell(new Phrase("Price", FontFactory.GetFont("ARIAL", 12, iTextSharp.text.Font.BOLD))); clPrice.BorderWidth = 0.75f; PdfPCell clQuantity = new PdfPCell(new Phrase("Quantity sale", FontFactory.GetFont("ARIAL", 12, iTextSharp.text.Font.BOLD))); clQuantity.BorderWidth = 0.75f; informationTable.AddCell(clPhone); informationTable.AddCell(clCharacteristics); informationTable.AddCell(clPrice); informationTable.AddCell(clQuantity); PhoneSaleBusiness psb = new PhoneSaleBusiness("Data Source = 163.178.107.130; Initial Catalog = KeggPhones; User Id = sqlserver; Password = saucr.12"); Object[] values = psb.getTop5PhoneSaleWeek(); List <Phone> phones = (List <Phone>)values[0]; List <int> quantities = (List <int>)values[1]; for (int i = 0; i < phones.Count; i++) { Phone phoneTemp = phones[i]; clPhone = new PdfPCell(new Phrase(phoneTemp.Brand.Name + " " + phoneTemp.Model, FontFactory.GetFont("ARIAL", 10, iTextSharp.text.Font.NORMAL))); clPhone.BorderWidth = 0.75f; string flash = ""; if (phoneTemp.Flash.ToString() == "True") { flash = "Yes"; } else { flash = "Not"; } string characteristics = "OS: " + phoneTemp.OS + "\n Network: " + phoneTemp.NetworkMode + "\n Internal memory: " + phoneTemp.InternalMemory + "\n External memory: " + phoneTemp.ExternalMemory + "\n Camera pixels: " + phoneTemp.Pixels + "\n Camera flash: " + flash + "\n Resolution screen: " + phoneTemp.Resolution; clCharacteristics = new PdfPCell(new Phrase(characteristics, FontFactory.GetFont("ARIAL", 10, iTextSharp.text.Font.NORMAL))); clCharacteristics.BorderWidth = 0.75f; clPrice = new PdfPCell(new Phrase("$" + phoneTemp.Price, FontFactory.GetFont("ARIAL", 10, iTextSharp.text.Font.NORMAL))); clPrice.BorderWidth = 0.75f; clQuantity = new PdfPCell(new Phrase(quantities[i] + "", FontFactory.GetFont("ARIAL", 10, iTextSharp.text.Font.NORMAL))); clQuantity.BorderWidth = 0.75f; informationTable.AddCell(clPhone); informationTable.AddCell(clCharacteristics); informationTable.AddCell(clPrice); informationTable.AddCell(clQuantity); } doc.Add(pTitle); doc.Add(pReport); doc.Add(pDate); doc.Add(waterMaker); doc.Add(pSpace); doc.Add(pSpace); doc.Add(informationTable); doc.Close(); Process.Start(filename); }