关闭

FluorinFx+AspNet+SQL 通信

标签: sqldatasetstringusernullcmd
452人阅读 评论(0) 收藏 举报
分类:

好友QQ:150935477

 

 

 

GetUserList.mxml

/*====================================================*/

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
    <mx:Style >Application{  fontSize:12; paddingTop:60; backgroundGradientColors: #2F1D1D,#3F3F3F;  }</mx:Style>


     
    <mx:RemoteObject
        id="FlexDoNet_ServiceLibrary_Sample"
        source="FlexDoNet.ServiceLibrary.Sample"
        destination="fluorine"
        showBusyCursor="true">
        <mx:method name="GetTime" result="onGetTime(event)" />
        <mx:method name="GetUsers" result="onResult(event)" fault="onFault(event)" />
    </mx:RemoteObject>
   
    <mx:Script>
        <![CDATA[
           
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;
            import mx.collections.ArrayCollection;
           
            [Bindable]
            private var Userslist:ArrayCollection;
           
            internal function onGetTime(evt:ResultEvent):void
            {
                txtResult.text = evt.result.toString();
            }
           
            internal function onResult(evt:ResultEvent):void
            {
                Userslist = evt.result as ArrayCollection;
            }
           
            internal function onFault(evt:FaultEvent):void
            {
                Alert.show("Data Not Fount, maybe cause at : "+evt.message);
            }
           
        ]]>
    </mx:Script>
   
 <mx:Panel x="53" y="52" width="947" height="391" title="测试FluorineFx" fontSize="12" paddingTop="10" paddingLeft="10">
     <mx:Button x="35" y="63" label="获取时间" fontWeight="normal" click="FlexDoNet_ServiceLibrary_Sample.GetTime()" />
     <mx:Label x="35" y="95" text="结 果:"/>
     <mx:TextInput x="35" y="123" width="260" id="txtResult"/>
     <mx:Button x="35" y="63" label="获取用户信息" fontWeight="normal" click="FlexDoNet_ServiceLibrary_Sample.GetUsers()" />
     <mx:Label x="35" y="95" text="结 果:"/>
     <mx:DataGrid id="grid" dataProvider="{Userslist}">
         <mx:columns>
             <mx:DataGridColumn headerText="编号" dataField="UserId" />
             <mx:DataGridColumn headerText="用户" dataField="UserName" />
             <mx:DataGridColumn headerText="密码" dataField="Userpass" />
             <mx:DataGridColumn headerText="登录次数" dataField="UserLogins" />
             <mx:DataGridColumn headerText="最后登录IP" dataField="UserLastLoginIp" />
             <mx:DataGridColumn headerText="最后登录时间" dataField="UserLastLoginTime" />
             <mx:DataGridColumn headerText="添加时间" dataField="UserAddTime" />
             <mx:DataGridColumn headerText="角色" dataField="UserStatus" />
             <mx:DataGridColumn headerText="启用状态" dataField="UserFlag" />            
         </mx:columns>
     </mx:DataGrid>
 </mx:Panel>
   
</mx:Application>

 

 

User.sql

 

/****** 对象:  Table [dbo].[Lihua_User]    脚本日期: 01/07/2011 18:28:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Lihua_User](
    [UserId] [int] NOT NULL,
    [UserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [UserPass] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [UserLogins] [int] NULL,
    [UserLastLoginIp] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [UserLastLoginTime] [datetime] NULL,
    [UserAddTime] [datetime] NULL,
    [UserStatus] [int] NULL,
    [UserFlag] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]

 

 

/****** 对象:  SqlHelper类   脚本日期: 01/07/2011 18:28:15 ******/

 

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace Flexzoo
{

    public static class SqlHelper
    {

        private static SqlConnection connection;
        public static SqlConnection Connection
        {
            get
            {
                string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
                if (connection == null)
                {
                    connection = new SqlConnection(connectionString);
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Closed)
                {
                    connection.Open();
                }
                else if (connection.State == System.Data.ConnectionState.Broken)
                {
                    connection.Close();
                    connection.Open();
                }
                return connection;
            }
        }

        public static bool Exists(string safeSql)
        {
            return (GetDataTable(safeSql).Rows.Count > 0) ? true : false;
        }

        public static bool Exists(string safeSql, params SqlParameter[] values)
        {
            return (GetDataTable(safeSql,values).Rows.Count > 0) ? true : false;
        }

        public static int ExecuteCommand(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            int result = cmd.ExecuteNonQuery();
            return result;
        }

        public static int ExecuteCommand(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            return cmd.ExecuteNonQuery();
        }

        public static object GetScalar(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            //int result = Convert.ToInt32(cmd.ExecuteScalar());
            return cmd.ExecuteScalar();
        }

        public static object GetScalar(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            return cmd.ExecuteScalar();
        }

        public static SqlDataReader GetReader(string safeSql)
        {
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            SqlDataReader reader = cmd.ExecuteReader();
            return reader;
        }

        public static SqlDataReader GetReader(string sql, params SqlParameter[] values)
        {
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            SqlDataReader reader = cmd.ExecuteReader();
            return reader;
        }

        public static DataTable GetDataTable(string safeSql)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            return ds.Tables[0];
        }

        public static DataTable GetDataTable(string sql, params SqlParameter[] values)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            return ds.Tables[0];
        }

        public static DataSet GetDataSet(string safeSql)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand(safeSql, Connection);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            return ds;
        }

        public static DataSet GetDataSet(string sql, params SqlParameter[] values)
        {
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand(sql, Connection);
            cmd.Parameters.AddRange(values);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            return ds;
        }

    }
}

 

/************** DTO ******************/

 

using System;
using System.Collections.Generic;
using System.Text;

namespace FlexDoNet.ServiceLibrary.DTO
{
    /// <summary>
    /// 实体类Lihua_User 。(属性说明自动提取数据库字段的描述信息)
    /// </summary>
    [Serializable]
    public class Lihua_User
    {
        #region Model
        private int _userid;
        private string _username;
        private string _userpass;
        private int _userlogins;
        private string _userlastloginip;
        private DateTime _userlastlogintime;
        private DateTime _useraddtime;
        private int _userstatus;
        private string _userflag;
        /// <summary>
        ///
        /// </summary>
        public int UserId
        {
            set { _userid = value; }
            get { return _userid; }
        }
        /// <summary>
        ///
        /// </summary>
        public string UserName
        {
            set { _username = value; }
            get { return _username; }
        }
        /// <summary>
        ///
        /// </summary>
        public string UserPass
        {
            set { _userpass = value; }
            get { return _userpass; }
        }
        /// <summary>
        ///
        /// </summary>
        public int UserLogins
        {
            set { _userlogins = value; }
            get { return _userlogins; }
        }
        /// <summary>
        ///
        /// </summary>
        public string UserLastLoginIp
        {
            set { _userlastloginip = value; }
            get { return _userlastloginip; }
        }
        /// <summary>
        ///
        /// </summary>
        public DateTime UserLastLoginTime
        {
            set { _userlastlogintime = value; }
            get { return _userlastlogintime; }
        }
        /// <summary>
        ///
        /// </summary>
        public DateTime UserAddTime
        {
            set { _useraddtime = value; }
            get { return _useraddtime; }
        }
        /// <summary>
        ///
        /// </summary>
        public int UserStatus
        {
            set { _userstatus = value; }
            get { return _userstatus; }
        }
        /// <summary>
        ///
        /// </summary>
        public string UserFlag
        {
            set { _userflag = value; }
            get { return _userflag; }
        }
        #endregion Model
    }
}

 

/**************************UserDataService****************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using FlexDoNet.ServiceLibrary.DTO;
using FluorineFx;
using FluorineFx.AMF3;

namespace FlexDoNet.ServiceLibrary
{
    public static class UserDataService
    {

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Lihua_User ReaderBind(DataRow dataReader)
        {
            Lihua_User model = new Lihua_User();
            object ojb;
            ojb = dataReader["UserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserId = (int)ojb;
            }
            model.UserName = dataReader["UserName"].ToString();
            model.UserPass = dataReader["UserPass"].ToString();
            ojb = dataReader["UserLogins"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserLogins = (int)ojb;
            }
            model.UserLastLoginIp = dataReader["UserLastLoginIp"].ToString();
            ojb = dataReader["UserLastLoginTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserLastLoginTime = (DateTime)ojb;
            }
            ojb = dataReader["UserAddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserAddTime = (DateTime)ojb;
            }
            ojb = dataReader["UserStatus"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserStatus = (int)ojb;
            }
            model.UserFlag = dataReader["UserFlag"].ToString();
            return model;
        }

        public static ArrayCollection GetUserList()
        {
            //IList<FlexDoNet.ServiceLibrary.DTO.Lihua_User> userList = new List<FlexDoNet.ServiceLibrary.DTO.Lihua_User>();
            DataTable table = Flexzoo.SqlHelper.GetDataTable("select * from Lihua_User");
            ArrayCollection array = new ArrayCollection();

            foreach (DataRow r in table.Rows)
            {
                Lihua_User user = new Lihua_User();
                user = ReaderBind(r);
                array.Add(user);
            }

            return array;
        }

        public static IList<Lihua_User> GetUserIList()
        {
            IList<Lihua_User> list = new List<Lihua_User>();
            DataTable table = Flexzoo.SqlHelper.GetDataTable("select * from Lihua_User");

            foreach (DataRow r in table.Rows)
            {
                Lihua_User user = new Lihua_User();
                user = ReaderBind(r);
                list.Add(user);
            }

            return list;
        }

    }
}

 

 

/*****************************ServiceLibrary****************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using FluorineFx;
using FluorineFx.AMF3;
using FlexDoNet.ServiceLibrary.DTO;

namespace FlexDoNet.ServiceLibrary
{
    /// <summary>
    /// Fluorine sample service.
    /// </summary>
    [RemotingService("Fluorine sample service")]
    public class Sample
    {
        public Sample()
        {
        }

        public string Echo(string text)
        {
            return "Gateway echo: " + text;
        }

        public string GetTime()
        {
            return DateTime.Now.ToString();
        }

        public IList<Lihua_User> GetUsers()
        {
            return UserDataService.GetUserIList();
        }

        [DataSetType("FlexDoNet.ServiceLibrary.DTO.Lihua_User")]
        public DataSet GetDataSet()
        {
            return Flexzoo.SqlHelper.GetDataSet("select * from Lihua_User");
        }
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:25698次
    • 积分:461
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:12篇
    • 译文:0篇
    • 评论:2条