private void print(Estimate service) { RegistryHandler objRegistryHandler = new RegistryHandler(); // objRegistryHandler.TakeBackUp(); objRegistryHandler.SetPrintSetup(); var folderPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath); var file_path = System.IO.Path.Combine(folderPath, @"Reports\report-customer-service.html"); string billContent = System.IO.File.ReadAllText(file_path); billContent = billContent.Replace("{{DATE}}", service.Date.ToString("dd MMM, yyyy")); billContent = billContent.Replace("{{BILLNO}}", service.Id.ToString().PadLeft(6, '0')); billContent = billContent.Replace("{{CUSTOMER_NAME}}", service.CustomerName); billContent = billContent.Replace("{{CUSTOMER_ADDRESS}}", service.CustomerAddress); billContent = billContent.Replace("{{CUSTOMER_PHONE}}", service.CustomerPhone); var strTableRows = string.Empty; var index = 1; foreach (var d in service.EstimateDetails) { var serviceName = db.ServiceMasters.Find(d.ServiceId).Name; var _row = $@" <tr> <td style='text-align: center;'>{index++}</td> <td style='text-align: left;'>{serviceName}</td> <td style='text-align: right;'>{d.Amount.Value.ToString("0.00")}</td> </tr> "; strTableRows += _row; } var _totalRow = $@" <tr> <td colspan='2' style='text-align: right;'><b>Total:</b></td> <td style='text-align: right;'>{service.GrandTotal.Value.ToString("0.00")}</td> </tr>"; billContent = billContent.Replace("{{SERVICE_ROW}}", strTableRows); billContent = billContent.Replace("{{SERVICE_TOTAL_ROW}}", _totalRow); var outputFilePath = System.IO.Path.Combine(folderPath, "customer-service.html"); if (System.IO.File.Exists(outputFilePath)) { System.IO.File.Delete(outputFilePath); } System.IO.File.WriteAllText(outputFilePath, billContent); WebBrowser webBrowserForPrint = new WebBrowser(); webBrowserForPrint.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(printDocument); webBrowserForPrint.Url = new Uri(outputFilePath); objRegistryHandler.Restore(); }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateService()) { return; } if (Mode == Models.EntryMode.New) { var service = new Models.CustomerService(); service.CGST = 0;// Convert.ToDecimal(lblCGST.Text.Trim()); service.CustomerAddress = txtAddress.Text.Trim(); service.CustomerName = txtName.Text.Trim(); service.CustomerPhone = txtPhone.Text.Trim(); service.Date = dtpServiceDate.Value; service.GrandTotal = Convert.ToDecimal(lblGrandTotal.Text.Trim()); service.NetTotal = 0; // Convert.ToDecimal(lblNetTotal.Text.Trim()); service.Note = ""; service.SGST = 0; // Convert.ToDecimal(lblSGST.Text.Trim()); foreach (var r in grdService.Rows) { var row = (DataGridViewRow)r; var serviceId = Convert.ToInt32(row.Cells[0].Value); var note = row.Cells[2].Value.ToString(); var amount = Convert.ToInt32(row.Cells[3].Value); var serviceDetails = new Models.CustomerServiceDetail() { Amount = amount, Note = note, ServiceId = serviceId }; service.CustomerServiceDetails.Add(serviceDetails); } db.CustomerServices.Add(service); db.SaveChanges(); if (MessageBox.Show("Saved Successfully ! Do you want to print?", "Success", MessageBoxButtons.YesNo) == DialogResult.Yes) { RegistryHandler objRegistryHandler = new RegistryHandler(); objRegistryHandler.TakeBackUp(); objRegistryHandler.SetPrintSetup(); print(service); objRegistryHandler.Restore(); } ClearForm(); } else if (Mode == EntryMode.Edit) { var service = db.CustomerServices.Find(CustomerServiceId); if (service != null) { service.CGST = 0;// Convert.ToDecimal(lblCGST.Text.Trim()); service.CustomerAddress = txtAddress.Text.Trim(); service.CustomerName = txtName.Text.Trim(); service.CustomerPhone = txtPhone.Text.Trim(); service.Date = dtpServiceDate.Value; service.GrandTotal = Convert.ToDecimal(lblGrandTotal.Text.Trim()); service.NetTotal = 0; // Convert.ToDecimal(lblNetTotal.Text.Trim()); service.Note = ""; service.SGST = 0; // Convert.ToDecimal(lblSGST.Text.Trim()); service.CustomerServiceDetails.Clear(); foreach (var r in grdService.Rows) { var row = (DataGridViewRow)r; var serviceId = Convert.ToInt32(row.Cells[0].Value); var note = row.Cells[2].Value.ToString(); var amount = Convert.ToDouble(row.Cells[3].Value); var serviceDetails = new Models.CustomerServiceDetail() { Amount = Convert.ToDecimal(amount), Note = note, ServiceId = serviceId }; service.CustomerServiceDetails.Add(serviceDetails); } db.SaveChanges(); MessageBox.Show("Saved Successfully !"); } } DialogResult = DialogResult.OK; }