Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Purushottam Dwivedi on Dec 08, 2008 04:56
open dhtmlx forum
Save,update and delete is not working which condition action in inserted,deleted,updated

Package.aspx page

<input type="button" id="BtnNext" value="Next...." onclick="save_data();" style="display:inline;"/>
var x=$get('<%=ddlPacakageNames.ClientID %>').value;

mygrid.loadXML("http://"+location.host+"/t2india/PackageLoadData.aspx?PCode="+ x + "",sumColumn);

myDataProcessor = new dataProcessor("http://"+location.host+"/t2india/Savepackage.aspx?PCode="+ x +"");

myDataProcessor.setVerificator(1)

myDataProcessor.setUpdateMode("off");//available values: cell (default), row, off
myDataProcessor.init(mygrid);


function save_data()
{

myDataProcessor.sendData();
window.location='http://'+location.host+'/t2india/';

}


Savepackage.aspx.cs


protected XmlDocument xmlDoc = null;
public string xmlfile;
private String xmlConfigFile = string.Empty;
string a = HttpContext.Current.Request.QueryString["PageName"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
xmlConfigFile = System.Web.HttpContext.Current.Server.MapPath("xmlfiles/Itinerary.xml");
PI.Bll.package.BllPackage objbllpackage = new PI.Bll.package.BllPackage(xmlConfigFile, Request.QueryString["Pcode"].ToString());
Response.Write(objbllpackage.Save(Request.QueryString));
}


.bll file
namespace PI.Bll.package
{
public class BllPackage
{
protected String strFileName = "";
protected string strPICode = "";
protected string strPageName = string.Empty;
public BllPackage(String xmlFile, string pstrICode)
{
this.strFileName = xmlFile;
this.strPageName = "Package";
strPICode = pstrICode;
}
~BllPackage()
{
}

public String getXML()
{
// PIInfoSoft.DLL.TripPlanner.dalDataLink objDalDataLink = new PIInfoSoft.DLL.TripPlanner.dalDataLink(strFileName, strICode, strPageName);
PI.Dal.Package.dalDataLink objdaldatalink = new PI.Dal.Package.dalDataLink(strFileName, strPICode);
String res = objdaldatalink.getXML();
return res;
}
public String Save(NameValueCollection data)
{

PI.Dal.Package.dalDataLink objdalpackage = new PI.Dal.Package.dalDataLink(strFileName, strPICode);
String res = objdalpackage.Save(data);
return res;
}
}
}


Dal file

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Xml;
using System.Collections.Specialized;
using System.Collections;
using PIInfosoft.Framework.Data;
using Microsoft.Xml.XQuery;
using System.IO;
using System.Data.SqlClient;

/// <summary>
/// Summary description for dalDataLink
/// </summary>
///
namespace PI.Dal.Package
{
public class dalDataLink
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ToString());

protected XmlDocument xmlDoc = null;
//protected IDbConnection conn = null;
protected String tag = "";
protected string strICode = "";
protected string strPageName = "";
public dalDataLink( String xmlFile,string pstrICode)
{
this.xmlDoc = new XmlDocument();
this.xmlDoc.Load(xmlFile);
strICode = pstrICode;
strPageName = "Package";
}
~dalDataLink()
{ }


private String PrintXMLHeader()
{
return this.PrintXMLHeader("data", "");
}
private String PrintXMLHeader(String tag, String add)
{
this.tag = tag;
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><" + tag + " " + add + ">";

}
private String PrintXMLFooter()
{
return "</" + this.tag + ">";
}
/// <summary>
///
/// </summary>
/// <param name="action"></param>
/// <param name="sid"></param>
/// <param name="tid"></param>
/// <returns></returns>
private String PrintAction(String action, String sid, String tid)
{
return "<action type='" + action + "' sid='" + sid + "' tid='" + tid + "'/>";
}



/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public String Save(NameValueCollection data)
{

String res = this.PrintXMLHeader();
////
String action = (xmlDoc.GetElementsByTagName("action")[0] == null) ? "" : data[xmlDoc.GetElementsByTagName("action")[0].InnerText];
if (xmlDoc.DocumentElement.Attributes["type"] != null &&
xmlDoc.DocumentElement.Attributes["type"].Value == "tree")
{

}
else
{
switch (action)
{
case "deleted":
res += this.Delete(data);
break;
case "inserted":
res += this.Insert(data);
break;
default:
res += this.Update(data);
//res += this.Insert(data);
break;
}
}
res += this.PrintXMLFooter();
//conn.Close();
return res;
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private String Delete(NameValueCollection data)
{
String tableName = xmlDoc.GetElementsByTagName("table")[0].Attributes["name"].Value;
String tableKey = xmlDoc.GetElementsByTagName("key")[0].Attributes["name"].Value;
String tableKeyValue = data[xmlDoc.GetElementsByTagName("key")[0].InnerText];
if (tableName != "")
{
String sql = "DELETE FROM " + tableName + " WHERE " + tableKey + "='" + tableKeyValue + "'";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
return this.PrintAction("delete", tableKeyValue, "0");

}
return "";
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private String Insert(NameValueCollection data)
{
String strA = "";
String strB = "";
int count = 0;
foreach (XmlElement param in xmlDoc.GetElementsByTagName("param"))
{
if (count++ > 0)
{
strA += ",";
strB += ",";
}
strA += param.Attributes["name"].Value;
strB += "'" + data[param.InnerText] + "'";
}
String sql = "INSERT INTO " + xmlDoc.GetElementsByTagName("table")[0].Attributes["name"].Value + " (" + strA + ") VALUES ( " + strB + " ); SELECT scope_identity();";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Connection.Open();
object res = cmd.ExecuteScalar();
cmd.Connection.Close();
return this.PrintAction("insert", data[xmlDoc.GetElementsByTagName("key")[0].InnerText], (res != null) ? res.ToString() : "0");
}
/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
private String Update(NameValueCollection data)
{
String sql = "UPDATE " + xmlDoc.GetElementsByTagName("table")[0].Attributes["name"].Value + " SET ";
int count = 0;
foreach (XmlElement param in xmlDoc.GetElementsByTagName("param"))
{
if (count++ > 0)
sql += ",";
sql += param.Attributes["name"].Value + " = '" + data[param.InnerText] + "'";
}
sql += " WHERE " + xmlDoc.GetElementsByTagName("key")[0].Attributes["name"].Value + " ='" + data[xmlDoc.GetElementsByTagName("key")[0].InnerText] + "'";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
return this.PrintAction("update", data[xmlDoc.GetElementsByTagName("key")[0].InnerText], "0");
}




public String getXML()
{
String res = "";
String type = (xmlDoc.DocumentElement.Attributes["type"] != null) ? xmlDoc.DocumentElement.Attributes["type"].Value : "";
switch (type)
{
case "tree":
break;
default:
if(strPageName=="Package")
{
res += this.PrintXMLHeader("rows", "");
res += "<head> " +
" <column width='50' type='ro' align='center' color='#d5f1ff' >Sr No.</column> " +
" <column width='0' type='ro' align='left' >vcItineraryCode</column> " +
" <column width='65' type='ro' align='Left' >From Date</column> " +
" <column width='80' type='ro' align='Left' > From Place</column> " +
" <column width='80' type='ro' align='Left' >To Place </column> " +
" <column width='50' type='coro' align='left' >" +
" Mode " +
" <option value='Air'>Air</option> " +
" <option value='Train'>Train</option> " +
" <option value='Road'>Road</option> " +
" <option value='Other'>Other</option> " +
" </column> " +
" <column width='35' type='ed' align='Center'> Over Night</column> " +
" <column width='60' type='ro' align='Left' >To Date</column> " +
" <column width='65' type='ro' align='left' >stayNight</column> " +
" <column width='60' type='ro' align='left' >FromPlaceCode</column> " +
" <column width='60' type='ro' align='left' >ToPlaceCode</column> " +

" <settings> " +
" <colwidth>px</colwidth> " +
" </settings> " +
" </head> ";
res += this.GetXmlGrid();
}
break;
}
res += this.PrintXMLFooter();
//conn.Close();
return res;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private String GetXmlGrid()
{
String res = "";
String where = xmlDoc.GetElementsByTagName("where")[0].InnerText;
if (strPageName == "Package")
{

String sql = "SELECT * FROM " + xmlDoc.GetElementsByTagName("table")[0].Attributes["name"].Value;
if (where != "" && strICode != "")
sql += " WHERE " + where + "='" + strICode.Trim() + "' order by inSrNo";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Connection.Open();
IDataReader r = cmd.ExecuteReader();
while (r.Read())
{

res += "<row id=\"" + r[xmlDoc.GetElementsByTagName("key")[0].Attributes["name"].Value] + "\">";

foreach (XmlElement param in xmlDoc.GetElementsByTagName("param"))
{
if (param.Attributes["name"].Value == "inSrNo")
{
res += "<cell >" + r[1] + "</cell>";
}
else if (param.Attributes["name"].Value=="dtFromDate")
{
res += "<cell >" + DateTime.Now.Date + "</cell>";
}
else if (param.Attributes["name"].Value == "inStayingNights")
{
res += "<cell >" + r[9] + "</cell>";
}
else if (param.Attributes["name"].Value == "dtToDate")
{
res += "<cell >" + DateTime.Now.Date + "</cell>";
}
else
{



res += "<cell>" + r[param.Attributes["name"].Value] + "</cell>";





}
}

res += "</row>";
}

cmd.Connection.Close();
return res;
}
else{return res;}

}



}
}

Answer posted by Support on Dec 08, 2008 05:57
Please try to include dhtmlxdataprocessor_debug.js ( included in your package ) , it will add debug console output. 
If there was some errors on server side during update process - extended error info will be shown.