Showing posts with label Flex dotnet. Show all posts
Showing posts with label Flex dotnet. Show all posts

Monday, 24 March 2008

Flex dot net example, Flex .net, Flex asp.net, Flex dotnet, Flex with asp.net, HTTPServices example
The asp.net code for the Previous Flex example. default.aspx I am just posting the body part of default.aspx
The User table has three fields UserId,UserName,email

<form id="form1" runat="server">
<div>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="Flex3" width="100%" height="100%"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="FlexDotNet.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#869ca7">
<param name="allowScriptAccess" value="sameDomain">
<embed src="FlexDotNet.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="Flex3" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer"></embed>

</object>
</div>
</form>

------------------ Code behind code default.aspx.cs -----

using System;
using System.Configuration;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
displaydata();

}
public void displaydata()
{
SqlConnection con = new SqlConnection(@"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=yourUserId;Password=YourPassword;Initial Catalog=YourDatabaseName;Data Source=yourServerName" );
con.Open();

SqlCommand cmd = new SqlCommand("select * from Users",con);
cmd.con.open();
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds, "Users");

mxmlStr = "<users>";
foreach (DataRow dr in myDataSet.Tables["EmployeeData"].Rows)

{

mxmlStr = mxmlStr + "<user><userid>" + dr[0].ToString() + "</userid><username>" + dr[1].ToString() + "</username><emailaddress>" + accessSqlArray(2,mxmLoop) + "</emailaddress></user>";



}
mxmlStr = mxmlStr & "</users>";
response.write(mxmlStr);

}
}


------------------------ Code Behind DeleteRequest.aspx.cs---------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.SqlClient;

public partial class deleteRequest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
displaydata();
}

public void displaydata()
{
string mxmlStr;
string strUserId;

SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=yourServerName;Initial Catalog=yourDataBase;User ID=yourUserId;Password=yourPassword;";
con.Open();

strUserId = Request.Form["user_id"];


if (Request.Form["user_id"] != "")
{
SqlCommand cmd = new SqlCommand("Delete from Users WHERE UserId =" + Request.Form["user_id"] , con);
cmd.ExecuteNonQuery();
}
Server.Transfer("default.aspx");

}
}
------- Code Behind for addRequest.aspx -----------------

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;


public partial class addRequest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
displaydata();
}

public void displaydata()
{
string mxmlStr;
string strUserName, strEmail, strMaxId;

Int32 intMaxId;
//SqlConnection con = new SqlConnection("User ID=yourUserId;Password=yourPassword;Initial Catalog=yourDataBase;Data Source=yourServerName");
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=ARULM;Initial Catalog=guest1;User ID=sa;Password=sa;";
con.Open();

strUserName = Request.Form["add_username"];
strEmail = Request.Form["add_email"];

if (Request.Form["add_username"] != "")
{
SqlCommand cmd = new SqlCommand("select max(UserId) as strMaxId FROM Users", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Users");

mxmlStr = "";
//DataRow dr = new DataRow();
//ds.Tables["
strMaxId = ds.Tables["Users"].Rows[0][0].ToString();
intMaxId = Convert.ToInt32(strMaxId) + 1;

SqlCommand cmd2 = new SqlCommand("insert into Users (UserId,UserName,email) values (" + intMaxId + ",'" + strUserName + "','" + strEmail + "')", con);
cmd2.ExecuteNonQuery();
}
Server.Transfer("default.aspx");
}

}

---------- SaveRequest.aspx.cs-------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class saveRequest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
displaydata();
}

public void displaydata()
{
string mxmlStr;
string strUserName, strEmail, strMaxId;
string strUserId;

Int32 intMaxId;
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=yourServerName;Initial Catalog=yourDatabaseName;User ID=yourUserId;Password=yourPassword;";
con.Open();
strUserName = Request.Form["add_username"];
strEmail = Request.Form["add_email"];

strUserId = Request.Form["adduser_id"];

if (Request.Form["adduser_id"] != "")
{
intMaxId = Convert.ToInt32(strUserId);

SqlCommand cmd2 = new SqlCommand("update users set UserName ='" + strUserName + "',email ='" + strEmail + "' where UserId = " + intMaxId, con);
cmd2.ExecuteNonQuery();
}
Server.Transfer("default.aspx");
}
}

----- addRequest.aspx.cs -----

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;


public partial class addRequest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
displaydata();
}

public void displaydata()
{
string mxmlStr;
string strUserName, strEmail, strMaxId;

Int32 intMaxId;

SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=yourServerName;Initial Catalog=yourDatabaseName;User ID=yourUserId;Password=yourPassword;";
con.Open();

strUserName = Request.Form["add_username"];
strEmail = Request.Form["add_email"];

if (Request.Form["add_username"] != "")
{
SqlCommand cmd = new SqlCommand("select max(UserId) as strMaxId FROM Users", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Users");

mxmlStr = "";
strMaxId = ds.Tables["Users"].Rows[0][0].ToString();
intMaxId = Convert.ToInt32(strMaxId) + 1;

SqlCommand cmd2 = new SqlCommand("insert into Users (UserId,UserName,email) values (" + intMaxId + ",'" + strUserName + "','" + strEmail + "')", con);
cmd2.ExecuteNonQuery();
}
Server.Transfer("default.aspx");
}
}

Flex dot net example, Flex .net, Flex asp.net, Flex dotnet, Flex with asp.net, HTTPServices example
Source MXML

<mx:application mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationcomplete="userRequest.send()"><mx:httpservice id="deleteRequest" url="deleteRequest.aspx" useproxy="false" method="POST"></mx:httpservice><mx:form x="22" y="10" width="493"><mx:hbox>


<mx:application mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationcomplete="userRequest.send()">
<mx:script>
<!--[CDATA[ import mx.collections.ArrayCollection; [Bindable]-->
</mx:script>
<mx:httpservice id="userRequest" url="default.aspx" useproxy="false" method="POST">
<mx:request xmlns="">
<user_name>{username.text}</user_name>
<user_id>{dgUserRequest.selectedItem.userid}</user_id>
</mx:request>
</mx:httpservice>
<mx:httpservice id="saveRequest" url="saveRequest.aspx" useproxy="false" method="POST">
<mx:request xmlns="">
<adduser_id>{dgUserRequest.selectedItem.userid}</adduser_id>
<add_username>{dgUserRequest.selectedItem.username}</add_username>
<add_email>{dgUserRequest.selectedItem.emailaddress}</add_email>
</mx:request>
</mx:httpservice>
<mx:httpservice id="addRequest" url="addRequest.aspx" useproxy="false" method="POST">
<mx:request xmlns="">
<add_username>{frmName.text}</add_username>
<add_email>{email.text}</add_email>
</mx:request>
</mx:httpservice>
<mx:httpservice id="deleteRequest" url="deleteRequest.aspx" useproxy="false" method="POST">
<mx:request xmlns="">
<user_id>{dgUserRequest.selectedItem.userid}</user_id>
</mx:request>
</mx:httpservice>
<mx:form x="22" y="10" width="493">
<mx:hbox>
<mx:label text="Username">
<mx:textinput id="username">
</mx:textinput>
<mx:button label="Submit" click="showData()">
<mx:button label="Delete" click="deleteRow()">
</mx:button>
<mx:datagrid id="dgUserRequest" itemfocusout="updateRow()" itemeditend="updateRow()" dataprovider="{userRequest.lastResult.users.user}" x="22" y="140" width="493" height="225" editable="true">
<mx:columns>
<mx:datagridcolumn headertext="User ID" datafield="userid" editable="false">
<mx:datagridcolumn headertext="User Name" datafield="username" editable="true">
<mx:datagridcolumn headertext="E-Mail" datafield="emailaddress" editable="true">
</mx:datagridcolumn>
</mx:datagridcolumn>
<mx:form width="302" height="113" x="22" y="373">
<mx:formitem label="Name">
<mx:textinput id="frmName" width="200" text="{dgUserRequest.selectedItem.username}">
</mx:textinput>
<mx:formitem label="Email">
<mx:textinput id="email" width="200" text="{dgUserRequest.selectedItem.emailaddress}">
</mx:textinput>
<mx:formitem>
<mx:hbox>
<mx:button label="Update" click="updateRow()">
<mx:button label="Add" click="addRow()">
<mx:button label="Delete" click="deleteRow()">
</mx:button>
</mx:button>
</mx:button>
</mx:hbox><mx:application mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationcomplete="userRequest.send()"><mx:form x="22" y="10" width="493"><mx:hbox><mx:label text="Username"><mx:button label="Submit" click="showData()"><mx:datagrid id="dgUserRequest" itemfocusout="updateRow()" itemeditend="updateRow()" dataprovider="{userRequest.lastResult.users.user}" x="22" y="140" width="493" height="225" editable="true"><mx:columns><mx:datagridcolumn headertext="User ID" datafield="userid" editable="false"><mx:form width="302" height="113" x="22" y="373"><mx:formitem label="Name"><mx:formitem label="Email"><mx:formitem><mx:label text="Username"><mx:button label="Submit" click="showData()"><mx:datagrid id="dgUserRequest" itemfocusout="updateRow()" itemeditend="updateRow()" dataprovider="{userRequest.lastResult.users.user}" x="22" y="140" width="493" height="225" editable="true"><mx:columns><mx:datagridcolumn headertext="User ID" datafield="userid" editable="false"><mx:form width="302" height="113" x="22" y="373"><mx:formitem label="Name"><mx:formitem label="Email"><mx:formitem><mx:hbox>
</mx:hbox></mx:formitem></mx:formitem></mx:formitem></mx:form></mx:datagridcolumn></mx:columns></mx:datagrid></mx:button></mx:label></mx:formitem></mx:formitem></mx:formitem></mx:form></mx:datagridcolumn></mx:columns></mx:datagrid></mx:button></mx:label></mx:hbox></mx:form></mx:application></mx:formitem></mx:formitem></mx:formitem></mx:form></mx:datagridcolumn></mx:columns></mx:datagrid></mx:button></mx:label></mx:hbox></mx:form></mx:application></mx:hbox></mx:form></mx:application>

 
© The contents of all personal web pages and blogs are published by me. Statements made and opinions expressed are strictly those of the me and not my employer.