Skip to main content

Reading HTML Table data using JavaScript and send to backend


Javar Script
****************
//records_table
var Products = [];
var table;
table = document.getElementById("records_table");
// Loop through each row and get ItemCode and Qty.
for (var r = 0; r < table.rows.length; r++)
{
// This takes qty from Imput Field
        var qty = table.rows[r].cells[3].getElementsByTagName('input')[0].value;
        // This takes text field data
var itemCode = table.rows[r].cells[1].innerHTML;
// Push the data to the Product array
Products.push({ ItemCode: itemCode, Qty: qty });
}
jQuery.ajax({
type: "POST",
url: "Sales.aspx/MakeIncompleteSale",
data: "{Data:'" + JSON.stringify(Products) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
},
failure: function (response) {
alert(response.d);
}
});


C# Backend
****************

 [WebMethod]
   public static string MakeIncompleteSale(string Data)
   {
       string ConnectionString = ConfigurationManager.ConnectionStrings["PointofSaleConstr"].ConnectionString;
       JavaScriptSerializer json = new JavaScriptSerializer();
       List<CartProduct> cartProducts = json.Deserialize<List<CartProduct>>(Data);
       string ShopId = HttpContext.Current.Session["ShopID"].ToString();
       SqlConnection cn = new SqlConnection(ConnectionString);
       if (cartProducts.Count != 0)
       {
           SqlCommand cmd1 = new SqlCommand();
           SqlCommand cmd2 = new SqlCommand();
           SqlCommand cmd3 = new SqlCommand();
           cmd1.CommandType = CommandType.Text;
           cmd2.CommandType = CommandType.Text;
           cmd3.CommandType = CommandType.Text;
           cmd1.CommandText = " INSERT INTO [tbl_Incomplete_sale] ([DateTime],[ShopId]) VALUES ('" + DateTime.Now.Date + "', '" + ShopId + "')";
           cmd1.Connection = cn;
           cn.Open();
           SqlDataReader reader1 = cmd1.ExecuteReader();
           cn.Close();
           // get the last id.
           int InCompleteSaleId = 0;
           // SELECT TOP 1 * FROM Table ORDER BY ID DESC
           cmd3.CommandText = "SELECT TOP 1 * from [tbl_Incomplete_sale] where ShopId ='" + ShopId + "' order by Id DESC";
           cmd3.Connection = cn;
           cn.Open();
           SqlDataReader reader3 = cmd3.ExecuteReader();
           if (reader3.HasRows)
           {
               while (reader3.Read())
               {
                   InCompleteSaleId = Convert.ToInt32(reader3["ID"]);
               }
           }
           cn.Close();
           for (int i = 0; i < cartProducts.Count; i++)
           {
               cmd2.CommandText = " INSERT INTO [tbl_IncompleteSale_Products] ([InCompleteSaleId],[ProductId],[Qty],[Date],[ShopId]) VALUES ('" + InCompleteSaleId + "','" + cartProducts[i].ItemCode + "','" + cartProducts[i].Qty + "', '" + DateTime.Now.Date + "','" + ShopId + "' )";
               cmd2.Connection = cn;
               cn.Open();
               SqlDataReader reader2 = cmd2.ExecuteReader();
               cn.Close();
           }
       }
       return "Success";
   }

Comments

Popular posts from this blog

Intigrate POS Printer in asp.net core 6. Web Project

There are two methods to call POS printer to print PrintGuestCheck PayBill_Print using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Tawoon.IT_SoftwareTemplate.BusinnessModels.BaseVM.Dashboard; using Tawoon.IT_SoftwareTemplate.BusinnessModels.Enum; using Tawoon.IT_SoftwareTemplate.Entities; using Tawoon.IT_SoftwareTemplate.Entities.Models; using System.IO; using System.Drawing.Printing; using System.Drawing; using System.Net.Sockets; using System.Text; using Microsoft.AspNetCore.Hosting; using Tawoon.IT_SoftwareTemplate.BusinnessModels.BaseVM; using Microsoft.Extensions.Options; using Tawoon.IT_SoftwareTemplate.Helper; using Microsoft.AspNetCore.Http; using System.Drawing.Imaging; namespace Tawoon.IT_SoftwareTemplate.Controllers { public class Dashboard...

Linux server setup

   New Linux server Config ------------------------------ 1. mongod 2. redis 3. nginx 4. postgresql 5. docker 6. rabbitMQ 7. ssh 8. kuberneies 9. Jenkins 10. HAproxy  11. Github 12. NVM 13. npm  Server Restart Check list ------------------------------ 1. mongod 2. redis 3. nginx 4. postgresql 5.docker 6. rabbitMQ 7. ssh Note: sudo systemctl status nginx Microservice Deployment Check list --------------------------------------- 1. change port in .env 2. change port in dockerfile 3. change port in docker-compose.yml file 4.  make sure using the right port when you  run docker -d -p 0000:0000 iamgeName