Mostrando las entradas con la etiqueta WebServices. Mostrar todas las entradas
Mostrando las entradas con la etiqueta WebServices. Mostrar todas las entradas

miércoles, octubre 25, 2006

Menu de árbol - TreeView en ASPX y C#



--- ASPX ---

<%@ Page language="c#" Codebehind="Menu.aspx.cs" AutoEventWireup="false" Inherits="Sorteo.Menu" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE>Menu</TITLE>
<META content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<META content="C#" name="CODE_LANGUAGE">
<META content="JavaScript" name="vs_defaultClientScript">
<META content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="default.css" type="text/css" rel="stylesheet">
</HEAD>
<BODY ms_positioning="GridLayout">
<!--<FORM runat="server">
<TABLE width="100%">
<TR>
<TD colspan="3">
<DIV style="BACKGROUND-IMAGE: url(http://localhost/Sorteo/images/logo sorteo jaguar ur - watermark 1.jpg);WIDTH: 783px;POSITION: relative;HEIGHT: 144px"
ms_positioning="GridLayout">
<ASP:IMAGE id="Image1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server"
height="128px" width="128px" imageurl="images/logo sorteo jaguar ur.jpg"></ASP:IMAGE>
<ASP:LABEL id="Label1" style="Z-INDEX: 102; LEFT: 152px; POSITION: absolute; TOP: 24px" runat="server"
width="352px" font-size="XX-Large" font-names="Times New Roman">Sorteo Jaguar UR</ASP:LABEL>
<ASP:LABEL id="lblSorteo" style="Z-INDEX: 103; LEFT: 512px; POSITION: absolute; TOP: 24px"
runat="server" font-size="XX-Large" font-names="Times New Roman">2006</ASP:LABEL></DIV>
</TD>
</TR>
<TR>
<TD width="209" style="WIDTH: 209px">
<DIV style="MARGIN: 0px; OVERFLOW: scroll; WIDTH: 208px; CLIP: rect(0px auto auto 0px); POSITION: static; HEIGHT: 500px">-->
<DIV>
<SCRIPT languaje="javascript">
classPath = "class.tree";
ftv2blank = "ftv2/ftv2blank.gif";
ftv2doc = "ftv2/ftv2doc.gif";
ftv2folderclosed = "ftv2/ftv2folderclosed.gif";
ftv2folderopen = "ftv2/ftv2folderopen.gif";
ftv2lastnode = "ftv2/ftv2lastnode.gif";
ftv2link = "ftv2/ftv2link.gif";
ftv2mlastnode = "ftv2/ftv2mlastnode.gif";
ftv2mnode = "ftv2/ftv2mnode.gif";
ftv2node = "ftv2/ftv2node.gif";
ftv2plastnode = "ftv2/ftv2plastnode.gif";
ftv2pnode = "ftv2/ftv2pnode.gif";
ftv2vertline = "ftv2/ftv2vertline.gif";
basefrm = "main";
</SCRIPT>
<SCRIPT src="class.tree/ftiens4.js" type="text/javascript">
</SCRIPT>
<SPAN id="spnJavaScript" runat="server"></SPAN>
</DIV>
<!--</TD>
<TD width="60%" align="center" valign="middle"><IMG height="400" alt="" src="images/logo sorteo jaguar ur - fondo.jpg" width="425">
</TD>
<TD width="25%"></TD>
</TR>
</TABLE>
</FORM>-->
</BODY>
</HTML>


--- C# ---

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Sorteo;

namespace Sorteo
{
/// <summary>
/// Summary description for Menu.
/// </summary>
public class Menu : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl spnJavaScript;

void Page_Load(Object sender, EventArgs e)
{

buildMenu();


}

protected void buildMenu()
{
MenuWS ws = new MenuWS();

DataSet menuDS = ws.getMenu();
DataTable menuDT = menuDS.Tables["Menu"];
string varName="";
string papaVarName="";
string treeCommand = "";
string hayHijos;
string caption;
string url;

spnJavaScript.Controls.Add(new LiteralControl("<scr" + "ipt languaje=\"javascript\">\n"));

foreach(DataRow opcion in menuDT.Rows)
{
varName = "aux" + opcion["Nivel"];
papaVarName = "aux" + Convert.ToString(Convert.ToInt32(opcion["Nivel"])-1);
caption = Convert.ToString(opcion["Opcion"]).Trim();
url = Convert.ToString(opcion["URL"]).Trim();

if (Convert.ToInt32(opcion["Nivel"]) == 0)
{
treeCommand = varName + "= gFld(\"" + caption + "\", \"" + url + "\")\n";
}
else
{
hayHijos = Convert.ToString(opcion["hayHijos"]);
if (hayHijos.Equals("Y"))
{
treeCommand = varName + "= insFld(" + papaVarName + ", gFld(\"" + caption + "\", \"" + url + "\"))\n";
}
else
{
treeCommand = "insDoc(" + papaVarName + ", gLnk(" + papaVarName + ", \"" + caption + "\", \"" + url + "\"))\n";
}
}

treeCommand = treeCommand.Replace("aux0","foldersTree");
spnJavaScript.Controls.Add(new LiteralControl(treeCommand));
}
spnJavaScript.Controls.Add(new LiteralControl("initializeDocument()\n"));
spnJavaScript.Controls.Add(new LiteralControl("</scr" + "ipt>\n"));
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

--- WebService ---


<%@ WebService Language="c#" Codebehind="MenuWS.asmx.cs" Class="Sorteo.MenuWS" %>


--- WebService C# ---


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

namespace Sorteo
{
/// <summary>
/// Summary description for CartasWS.
/// </summary>
public class MenuWS : System.Web.Services.WebService
{
public MenuWS()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

private System.Data.SqlClient.SqlConnection con;
private System.Data.SqlClient.SqlDataAdapter spGetMenuDA;
private System.Data.SqlClient.SqlCommand spGetMenu;

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.con = new System.Data.SqlClient.SqlConnection();
this.spGetMenuDA = new System.Data.SqlClient.SqlDataAdapter();
this.spGetMenu = new System.Data.SqlClient.SqlCommand();
//
// con
//
this.con.ConnectionString = ((string)(configurationAppSettings.GetValue("con.ConnectionString", typeof(string))));
this.con.InfoMessage += new System.Data.SqlClient.SqlInfoMessageEventHandler(this.con_InfoMessage);
//
// spGetMenuDA
//
this.spGetMenuDA.SelectCommand = this.spGetMenu;
this.spGetMenuDA.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Menu", new System.Data.Common.DataColumnMapping[0])});
//
// spGetMenu
//
this.spGetMenu.CommandText = "dbo.[spGetMenu]";
this.spGetMenu.CommandType = System.Data.CommandType.StoredProcedure;
this.spGetMenu.Connection = this.con;
this.spGetMenu.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));
this.spGetMenu.Parameters.Add(new System.Data.SqlClient.SqlParameter("@iIDMenu", System.Data.SqlDbType.Int, 4));

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

/// <summary>
/// Regresa el arbol del menu ordenado ... por default el menu 1
/// </summary>
/// <returns>Regresa un DataSet con los datos del menu, ya ordenado, en forma de arbol.</returns>
[WebMethod]
public DataSet getMenu()
{
DataSet ds = new DataSet();

con.Open();
spGetMenu.Parameters["@iIDMenu"].Value = 1; // Cargar el menu por default
spGetMenuDA.Fill(ds,"Menu");
con.Close();

return ds;
}

private void con_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e)
{

}
}
}

viernes, octubre 20, 2006

Web Services para Flex en java y FDS (jrun)


/*
* BalanceGeneral.java
*
* Created on 20 de abril de 2005, 05:07 PM
*/

package sinapsys.contabilidad.ws;


import java.sql.*;
import java.util.ArrayList;
import java.util.Properties;
import sinapsys.acceso.ws.*;

/**
*
* @author Administrator
*/
public class BalanceGeneral {

private String JDBC2ODBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver"; // Driver de JDBC a utilizar, en este caso JDBC2ODBC

/** Creates a new instance of BalanceGeneral */
public BalanceGeneral() {
}

protected String getUrl(UserDSNEmpresa dsn) {
return "jdbc:odbc:" + dsn.getDSN();
}

public ArrayList getBalanceGeneral(UserDSNEmpresa dsn, String fechaInicio, String fechaFin) {

// get UserDSNEmpresa
String urlEmpresa = getUrl(dsn);
String DB_USER = dsn.getDB_USER();
String DB_PSW = dsn.getDB_PSW();

String strSQL = "SELECT * FROM CON_BALANCE ("+fechaInicio+","+fechaFin+")";

Connection con;
Statement stmt;


try {
Class.forName(JDBC2ODBC_DRIVER);

try {
con = DriverManager.getConnection(urlEmpresa, DB_USER, DB_PSW);

stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(strSQL);

ArrayList balanceList = new ArrayList();

while (rs.next()) {
int ID = rs.getInt("ID");
String CUENTA = rs.getString("CUENTA");
String DESCRIPCION = rs.getString("DESCRIPCION");
String T1 = rs.getString("T1");
String T2 = rs.getString("T2");
String T3 = rs.getString("T3");
String T4 = rs.getString("T4");
String T5 = rs.getString("T5");
String T6 = rs.getString("T6");
String TIPO = rs.getString("TIPO");
String HIJO = rs.getString("HIJO");

BalanceRow balancerow = new BalanceRow(ID,CUENTA,DESCRIPCION,T1,T2,T3,T4,T5,T6,TIPO,HIJO);
balanceList.add(balanceList);
}

stmt.close();
con.close();

return balanceList;

} catch(SQLException ex) {
String COD_ERROR = "SQLException: " + ex.getMessage();
System.err.println(COD_ERROR);
return null;
}

} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
return null;
}
}
}