private async void getAndSetData() { FirebaseResponse response = client.Get("hoadon"); dynamic EInvoices = JsonConvert.DeserializeObject(response.Body); // Trả về object hóa đơn dưới dạng JSON foreach (var EInvoice in EInvoices) // Duyệt từng hóa đơn { string a = EInvoice.Name; //Lấy key of Hóa đơn dưới dạng JSON if (listKeyTempt.Contains(a) == false) { // listKeyTempt.Add(a); listKey.Add(a); } listKeyTempt.Add(a); } foreach (var key in listKey) // Duyệt từng hóa đơn { FirebaseResponse responseInfor = await client.GetTaskAsync("hoadon/" + key); //Lấy value của hóa đơn EInvoicing temp = new EInvoicing(); //Tạo một Class Einvoice tạm temp = responseInfor.ResultAs <EInvoicing>(); //Kéo dữ liệu hóa đơn từ server đổ về class tạm này if (einvoiceArray.Count == 0) { einvoiceArray.Add(temp);//Thêm dữ liệu vào List Einvoice } else { if (einvoiceArray.Count < listKey.Count) { einvoiceArray.Add(temp);//Thêm dữ liệu vào List Einvoice } else { if (einvoiceArray.Contains(temp) == true) { einvoiceArray.Add(temp);//Thêm dữ liệu vào List Einvoice } } } } foreach (var einvoice in einvoiceArray) { DataRow row = data.NewRow(); row["Ngày lập hóa đơn"] = einvoice.InvoiceArisingDate; row["Tên hóa đơn"] = einvoice.InvoiceName; row["Mã số hóa đơn"] = einvoice.InvoiceNo; row["Kí hiệu hóa đơn"] = einvoice.InvoiceSerialNo; row["Tên công ty"] = einvoice.ComName; row["Tên khách hàng"] = einvoice.CusName; row["Hình thức thanh toán"] = einvoice.Payment; row["Tổng tiền"] = einvoice.TotalPrice; data.Rows.Add(row); string query = "EXEC dbo.AddtoDataBase @ComName , @ComAddress , @ComPhone , @CusName , @CusEmail , @CusAddress , @CusBankName , @Cusphone , @CusBankNo , @InvoiceArisingDate , @InvoiceName , @InvoiceNo , @InvoiceSerialNo , @Payment , @TotalPrice "; int check = DataProvide.Instance.ExecuteNonQuery(query, new object[] { einvoice.ComName, einvoice.ComAddress, einvoice.ComPhone, einvoice.CusName, einvoice.CusEmail, einvoice.CusAddress, einvoice.CusBankName, einvoice.CusPhone, einvoice.CusBankNo, einvoice.InvoiceArisingDate, einvoice.InvoiceName, einvoice.InvoiceNo, einvoice.InvoiceSerialNo, einvoice.Payment, einvoice.TotalPrice }); foreach (var item in einvoice.itemsData) { string queryItem = "EXEC dbo.AddInvoicetoDataBase @ItemsName , @ItemsPrice , @ItemsNum , @InvoiceSerialNo "; DataProvide.Instance.ExecuteNonQuery(queryItem, new object[] { item.ItemsName, item.ItemsPrice, item.ItemsNum, einvoice.InvoiceSerialNo }); } } listKey.Clear(); einvoiceArray.Clear(); }
private async void button2_Click(object sender, EventArgs e) { FirebaseResponse response = client.Get("hoadon"); dynamic EInvoices1 = JsonConvert.DeserializeObject(response.Body); // Trả về object hóa đơn dưới dạng JSON foreach (var EInvoice in EInvoices1) // Duyệt từng hóa đơn { string a = EInvoice.Name; //Lấy key of Hóa đơn dưới dạng JSON if (listKeyTempt1.Contains(a) == false) { // listKeyTempt.Add(a); listKey1.Add(a); } listKeyTempt1.Add(a); } foreach (var key in listKey1) // Duyệt từng hóa đơn { FirebaseResponse responseInfor = await client.GetTaskAsync("hoadon/" + key); //Lấy value của hóa đơn EInvoicing temp = new EInvoicing(); //Tạo một Class Einvoice tạm temp = responseInfor.ResultAs <EInvoicing>(); //Kéo dữ liệu hóa đơn từ server đổ về class tạm này if (einvoiceArray1.Count == 0) { einvoiceArray1.Add(temp);//Thêm dữ liệu vào List Einvoice } else { if (einvoiceArray1.Count < listKey1.Count) { einvoiceArray1.Add(temp);//Thêm dữ liệu vào List Einvoice } else { if (einvoiceArray1.Contains(temp) == true) { einvoiceArray1.Add(temp);//Thêm dữ liệu vào List Einvoice } } } } foreach (var einvoice in einvoiceArray1) { if (einvoice.ComName == ComName && einvoice.CusName == CusName && einvoice.InvoiceSerialNo == EName) { string pdfPath = "Result.pdf"; CharacterFormat textFormat = new CharacterFormat() { Size = 15, FontColor = SautinSoft.Document.Color.Black }; DocumentCore dc = new DocumentCore(); Section section = new Section(dc); dc.Sections.Add(section); section.PageSetup.PaperType = PaperType.A4; section.PageSetup.Orientation = SautinSoft.Document.Orientation.Landscape; Paragraph par1 = new Paragraph(dc); par1.ParagraphFormat.Alignment = SautinSoft.Document.HorizontalAlignment.Center; section.Blocks.Add(par1); CharacterFormat cf = new CharacterFormat() { FontName = "Verdana", Size = 20, FontColor = SautinSoft.Document.Color.Red, Bold = true }; Run text1 = new Run(dc, einvoice.InvoiceName); text1.CharacterFormat = cf; par1.Inlines.Add(text1); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Ngày lập hóa đơn : " + einvoice.InvoiceArisingDate, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Số hóa đơn : " + einvoice.InvoiceNo, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Số hiệu hóa đơn : " + einvoice.InvoiceSerialNo, textFormat); // Let's add a line break into our paragraph. par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); // Way 2 (easy): Add 2nd paragraph using ContentRange. dc.Content.End.Insert("Tên khách hàng : " + einvoice.CusName, textFormat); SpecialCharacter lBr = new SpecialCharacter(dc, SpecialCharacterType.LineBreak); dc.Content.End.Insert(lBr.Content); dc.Content.End.Insert("Địa chỉ khách hàng : " + einvoice.CusAddress, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Email khách hàng : " + einvoice.CusEmail, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Số điện thoại khách hàng : " + einvoice.CusPhone, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Số tài khoản : " + einvoice.CusBankNo, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Tên ngân hàng : " + einvoice.CusBankName, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Tên công ty : " + einvoice.ComName, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Địa chỉ công ty : " + einvoice.ComAddress, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Số điện thoại công ty : " + einvoice.ComPhone, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); foreach (var items in einvoice.itemsData) { dc.Content.End.Insert("Món hàng : " + items.ItemsName, textFormat); dc.Content.End.Insert("\t\t", textFormat); dc.Content.End.Insert("Số lượng : " + items.ItemsNum, textFormat); dc.Content.End.Insert("\t\t", textFormat); dc.Content.End.Insert("Đơn giá : " + items.ItemsPrice + " đồng", textFormat); dc.Content.End.Insert("\t\t", textFormat); // dc.Content.End.Insert("------------------------------------", textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); } par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Hình thức thanh toán : " + einvoice.Payment, textFormat); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Tổng tiền : " + einvoice.TotalPrice + " đồng", new CharacterFormat() { Size = 30, FontColor = SautinSoft.Document.Color.Red }); Paragraph par2 = new Paragraph(dc); par2.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); par2.ParagraphFormat.Alignment = SautinSoft.Document.HorizontalAlignment.Justify; section.Blocks.Add(par2); par2.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); dc.Content.End.Insert("Chữ ký của khách hàng \t\t\t\t\t Chữ ký của nhà bán hàng ", new CharacterFormat() { Size = 20, FontColor = SautinSoft.Document.Color.Red }); //Add a signature String picPath = System.AppDomain.CurrentDomain.BaseDirectory + "signature.png"; // File located in Resources SDD::Picture signaturePic = new SDD::Picture(dc, picPath); signaturePic.Layout = SDD::Layout.Floating( new HorizontalPosition(16.5, LengthUnit.Centimeter, HorizontalPositionAnchor.Page), new VerticalPosition(10.5, LengthUnit.Centimeter, VerticalPositionAnchor.Page), new SDD::Size(20 * 3, 10 * 3, LengthUnit.Millimeter)); dc.Content.End.Insert(signaturePic.Content); // Save PDF to a file dc.Save(pdfPath, new PdfSaveOptions()); // Open the result for demonstation purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfPath) { UseShellExecute = true }); break; } } listKey1.Clear(); einvoiceArray1.Clear(); }