public static void GeneratePdf(Cart cart, ClientOfPark client) { if (!Directory.Exists("./facturi")) { Directory.CreateDirectory("./facturi"); } // pedefe var html = GetHtmlFromTemplateAndReplace(cart, client); var pdfBytes = HtmlToByteArray(html); File.WriteAllBytes("./facturi/" + cart.Id + " " + client.Name + " " + DateTime.Now.ToShortDateString() + ".pdf", pdfBytes); }
private void button1_Click(object sender, EventArgs e) { var myClient = new ClientOfPark() { Name = clientNameCB.Text, RegNo = clientBankTB.Text, J = clientJTB.Text, Address = clientJTB.Text, BankAccount = clientBankAccountTB.Text, BankName = clientBankTB.Text, Phone = clientPhoneTB.Text, }; //To be put on main page db.ClientOfParks.Add(myClient); db.SaveChanges(); // send the client to the parent form parent.PopulateClientObject(myClient); Close(); }
private static string GetHtmlFromTemplateAndReplace(Cart cart, ClientOfPark client) { var templatePath = "./invoice_template.html"; var templateAsString = File.ReadAllText(templatePath); // Replace what we need templateAsString = templateAsString .Replace("{{cart_id}}", cart.Id + "") .Replace("{{cart_username}}", cart.Username) .Replace("{{cart_date}}", cart.CreatedDate.ToShortDateString()) .Replace("{{client_name}}", client.Name) .Replace("{{client_address}}", client.Address) .Replace("{{client_regno}}", client.RegNo) .Replace("{{client_jno}}", client.J) .Replace("{{client_phone}}", client.Phone) .Replace("{{client_bankaccount}}", client.Phone) .Replace("{{client_bankname}}", client.Phone); var listOfItems = ""; double total = 0; var nrCrt = 1; var tvaPercentage = double.Parse(ConfigurationManager.AppSettings["tva"]); var utMas = ConfigurationManager.AppSettings["utmas"]; foreach (var detail in cart.CartDetails) { double p = detail.Price * detail.Quantity; total += p; double x = 100 * p / (100 + tvaPercentage); var tva = Math.Round(p - x, 2); listOfItems += "<tr class='products-row'><td align='center' class='tg-yw4l'>" + ((nrCrt++).ToString()) + "</td><td class='tg-yw4l'>" + detail.Part.Name + "</td><td class='tg-yw4l'>" + utMas + "</td><td class='tg-yw4l'>" + detail.Quantity + "</td><td class='tg-yw4l'>" + detail.Price + " RON</td><td class='tg-yw4l'>" + p + " RON</td><td class='tg-yw4l'>" + tva + " RON</td></tr>"; } templateAsString = templateAsString.Replace("{{cart_items}}", listOfItems) .Replace("{{cart_total}}", total + " RON"); return(templateAsString); }
private void button2_Click(object sender, EventArgs e) { if (CartService.Cart.CartDetails == null || !CartService.Cart.CartDetails.Any()) { MessageBox.Show("Nu aveti nimic in cos."); return; } foreach (var cartItem in CartService.Cart.CartDetails) { if (cartItem.PartId.HasValue) { // this is a part var part = mm.db.Parts.Find(cartItem.PartId.Value); if (part != null) { part.Quantity -= cartItem.Quantity; part.SoldQuantity += cartItem.Quantity; LoggingService.Log(Enums.ActionsEnum.Vanzare_Piesa, part.Price * cartItem.Quantity, "S-a vandut piesa- " + part.Name + " nr bucati vandute- " + cartItem.Quantity + " pret/buc" + part.Price); part.isAvailable = false; if (part.Quantity == 0) { part.InStock = false; } } } else { // this is a service // TODO } } DialogResult result = MessageBox.Show("Adaugare date cumparator? ", "Confirmare", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { // client is null here new ClientAddForm(this).ShowDialog(); // open the dialog and pass the null client to it to be populated // here we have the populated AND SAVED client via PopulateClient method if (client == null || client.Id <= 0) { client = new ClientOfPark() { Name = "_______________", RegNo = "_______________", J = "_______________", Address = "_______________", BankAccount = "_______________", BankName = "_______________", Phone = "_______________" }; } } else if (result == DialogResult.No) { client = new ClientOfPark() { Name = "_______________", RegNo = "_______________", J = "_______________", Address = "_______________", BankAccount = "_______________", BankName = "_______________", Phone = "_______________" }; } var dbCart = mm.db.Carts.Find(CartService.Cart.Id); dbCart.IsSold = true; client.IsActive = false; mm.db.SaveChanges(); // Trigger PDF gen PdfService.GeneratePdf(CartService.Cart, client); CartService.Cart = new Cart(); dataListView1.DataSource = new List <object>(); this.Close(); MessageBox.Show("Vandute."); mm.ReCheck(); }
// method to populate client public void PopulateClientObject(ClientOfPark client) { this.client = client; }