Hi,
I am working with Client Side gridview and using ajax ,webmethod to save data in database,when Multiple users try to save data on sametime then webmethod save only one user Data or some time exchange the data of differenets users.
please help me my application is live working ...
I am using sql server 2008.
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Services;
/// <summary>
/// Summary description for ServiceCS
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class ServiceCS : System.Web.Services.WebService
{
public ServiceCS()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string SaveGridViewRowData(List<GridViewDate> GridData)
{
Dictionary<string, string> name = new Dictionary<string, string>();
DataLogic dl = new DataLogic();
SqlTransaction Transaction;
dl.con.Open();
String strQuery = "";
string mVchno;
Transaction = dl.con.BeginTransaction();
GridViewDate FirstDataRow = GridData.First();
if (FirstDataRow.Status == "NEW")
{
mVchno = Convert.ToString(dl.AutoNumber("vchno", "transmain where vchtype='" + FirstDataRow.Vchtype + "' and locid='" + FirstDataRow.Locid + "' and finid='" + FirstDataRow.Finid + "'", Transaction));
}
else { mVchno = FirstDataRow.Vchno; }
try
{
if (FirstDataRow.Status == "NEW")
{
strQuery = @"Insert into transmain (vchno,comp_id,locid,finid,vchtype)
Values('" + mVchno + "','" + FirstDataRow.Compid + "','" + FirstDataRow.Locid + "' , '" + FirstDataRow.Finid + "' ,'" + FirstDataRow.Vchtype + "')";
dl.ManData(strQuery, Transaction);
}
strQuery = "Delete tbltransvch where vchno = '" + mVchno + "' and locid = '" + FirstDataRow.Locid + "' and comp_id = '" + FirstDataRow.Compid + "' and finid = '" + FirstDataRow.Finid + "' and vchtype='" + FirstDataRow.Vchtype + "' ";
dl.ManData(strQuery, Transaction);
int sno = 0;
decimal Amount = 0;
foreach (GridViewDate Data in GridData)
{
sno = Convert.ToInt16(Data.Id);
strQuery = @"Insert into tbltransvch (vchno,srno,vchtype,Des,vchdate,code,mcode,qty,rate,puserid,finid,locid,tucks,comp_id,DEBIT,CREDIT,Lotno)
Values('" + mVchno + "','" + Data.Id + "','" + Data.Vchtype + "','" + Data.Remarks + "','" + Data.VchDate + "','" + Data.Code + "','" + Data.MainCode + "','" + Data.Qty + "','" + Data.Rate + "','" + Data.Uid + "','" + Data.Finid + "','" + Data.Locid + "','8','" + Data.Compid + "','0','" + Data.Amount + "','" + Data.Lotno + "')";
dl.ManData(strQuery, Transaction);
Amount = Amount + Convert.ToDecimal(Data.Amount);
}
sno = sno + 1;
strQuery = @"Insert into tbltransvch (vchno,srno,vchtype,Des,vchdate,code,puserid,finid,locid,tucks,comp_id,DEBIT,CREDIT)
Values('" + FirstDataRow.Vchno + "','" + sno + "','" + FirstDataRow.Vchtype + "','','" + FirstDataRow.VchDate + "','" + FirstDataRow.MainCode + "','" + FirstDataRow.Uid + "','" + FirstDataRow.Finid + "','" + FirstDataRow.Locid + "','9','" + FirstDataRow.Compid + "','" + Amount + "','0' )";
dl.ManData(strQuery, Transaction);
Transaction.Commit();
}
catch (SqlException)
{
Transaction.Rollback();
}
finally
{
dl.con.Close();
}
string myJsonString = (new JavaScriptSerializer()).Serialize(name);
return myJsonString;
}
public class GridViewDate
{
public string Id { get; set; }
public string Vchno { get; set; }
public string Code { get; set; }
public double Qty { get; set; }
public double Rate { get; set; }
public double Amount { get; set; }
public string Lotno { get; set; }
public string Remarks { get; set; }
public string VchDate { get; set; }
public string Status { get; set; }
public string Compid { get; set; }
public string Locid { get; set; }
public string Finid { get; set; }
public string Uid { get; set; }
public string Vchtype { get; set; }
public string MainCode { get; set; }
}
}