easyui页面代码(.net)

List.aspx页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StudioWeightList.aspx.cs" Inherits="RiskManageWeb.StudioWeightList" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>机构列表</title>
    <link href="jquery-easyui-1.5/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.5/themes/color.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.5/demo/demo.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.5/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    
    <script src="Js/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.5/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="Js/easyui-lang-zh_CN.js" type="text/javascript"></script>
    
    <style type="text/css">
        html, body
        {
            margin: 0;
            height: 100%;
        }

        form
        {
            height: 100%;
            width: 100%;
        }

        .Panel
        {
            float: left;
        }

        .leftButtom
        {
            height: 50%;
        }

        #buttumdiv > div
        {
            float: left;
        }

        #topdiv > div
        {
            float: left;
        }
    </style>
</head>
<body>
<div id="rightPanel" style="width: 100%; height: 90%;">
    <div id="tt" class="easyui-tabs">
        <div title="机构列表" style="padding: 10px;">
            <table id="StudioWeightList">
            </table>
        </div>
    </div>

</div>
    <script type="text/javascript">
    var $width = $("#rightPanel").width();
    var $height = $("#rightPanel").height();
         //初始化
        $(function () {
            Get_StudioWeightList();         
        })
        
          function Get_StudioWeightList() {

            var editRow = undefined;
            var $datagrid = $("#StudioWeightList");
            $datagrid.datagrid({
                height: $height - 20,
                width: $width - 20,
                fitColumns: true,
                collapsible: true,
                singleSelect: true,
                url: '/Common/studioweighthandler.ashx',
                queryParams: { action: 'Get_StudioWeightList'  },
                idField: 'NUMBER',
                columns: [[
                 { field: 'NUMBER', title: 'ID', hidden: true },

                  {
                      field: 'Studio_name', width: 100, title: "机构名", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                   {
                       field: 'weight_key', width: 100, title: "权重号", align: 'center', editor: { type: 'text', options: { required: true } }
                   },
                  {
                      field: 'SL_weight', width: 150, title: "世联权重", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'RD_weight', width: 150, title: "仁达权重", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'GC_weight', width: 150, title: "国策权重", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'HF_weight', width: 150, title: "汇丰权重", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'Studio_name_RD', width: 150, title: "机构名(仁达)", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'CityName', width: 150, title: "城市名", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'SRG', width: 150, title: "世联仁达国策", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'SR', width: 150, title: "世联仁达", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'SG', width: 150, title: "世联国策", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'RG', width: 150, title: "仁达国策", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'S', width: 150, title: "世联", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'R', width: 150, title: "仁达", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'G', width: 150, title: "国策", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'OrgID', width: 150, title: "机构ID", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'SRH', width: 150, title: "世联仁达汇丰", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'H', width: 150, title: "汇丰", align: 'center', editor: { type: 'text', options: { required: true } }
                  },
                  {
                      field: 'SH', width: 150, title: "世联汇丰", align: 'center', editor: { type: 'text', options: { required: true } }
                  }
                  ,
                  {
                      field: 'RH', width: 150, title: "仁达汇丰", align: 'center', editor: { type: 'text', options: { required: true } }
                  }


                ]],
                toolbar: [{
                    text: '添加', iconCls: 'icon-add', handler: function () {
                        if (editRow != undefined) {
                            $datagrid.datagrid('endEdit', editRow);
                        }
                        if (editRow == undefined) {


                            $datagrid.datagrid('insertRow', {
                                index: 0,
                                row: {  }
                            });

                            $datagrid.datagrid('beginEdit', 0);
                            editRow = 0;
                        }
                    }

                }, '-', {
                    text: '保存', iconCls: 'icon-save', handler: function () {

                        var editIndex = editRow;

                        $datagrid.datagrid('endEdit', editRow);

                        $datagrid.datagrid('selectRow', editIndex)
                        var rowstr = $datagrid.datagrid('getSelected', editIndex)
                        //如果调用acceptChanges(),使用getChanges()则获取不到编辑和新增的数据。

                        //使用JSON序列化datarow对象,发送到后台。
                        //  var rows = $("#Student_Table").datagrid('getChanges');

                        //  var rowstr = JSON.stringify(rows[0]);
                        $.post('/Common/studioweighthandler.ashx?action=Save_StudioWeight', rowstr, function (data) {
                        if(data!="机构名和权重号不能为空!")
                        {
                            alert(data);
                            window.location.reload();
                            }
                                else
                            {
                                alert(data);
                                $datagrid.datagrid('beginEdit', editRow);
                            }
                        });
                        

                    }
                }, '-', {
                    text: '删除', iconCls: 'icon-remove', handler: function () {
                        var row = $datagrid.datagrid('getSelected');
                        var index = $datagrid.datagrid('getRowIndex', row);

                        if(row)
                        {
                            if(confirm("确认删除吗?")){
                            $.post('/Common/studioweighthandler.ashx?action=Delete_StudioWeight', { _nUMBER: row.NUMBER }, function (data) {
                                if (data == "删除成功") {
                                    $datagrid.datagrid('deleteRow', index);
                                }

                                alert(data);
                                });
                            }
                        }
                        else {
                            $.messager.alert({
                                title: '系统提示',
                                msg: '请选择需要删除的行'
                            });
                            }
                    }
                }],
                onAfterEdit: function (rowIndex, rowData, changes) {
                    $datagrid.datagrid('endEdit', editRow);
                },
                onDblClickRow: function (rowIndex, rowData) {
                    if (editRow != undefined) {
                        $datagrid.datagrid('endEdit', editRow);
                    }

                    if (editRow == undefined) {
                        $datagrid.datagrid('beginEdit', rowIndex);
                        editRow = rowIndex;
                    }
                },
                onClickRow: function (rowIndex, rowData) {
                    //if (editRow != undefined) {
                    //    $datagrid.datagrid('endEdit', editRow);

                    //}

                }

            });
        }
    </script>
</body>
</html>



 

 

 

后台处理StudioWeightHandler.ashx

 

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using Fanhua.Risk.Entities;
using Entities;
using System.Collections.Generic;
using System.Reflection;
using Library.Common;

namespace RiskManageWeb.JIEKOU
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class StudioWeightHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string action = context.Request["action"] ?? "";
            string returnJsonStr = string.Empty;

            if (action=="Get_StudioWeightList")
            {
               returnJsonStr= GetStudioWeightInfo();
            }
            else if (action=="Save_StudioWeight")
            {
                context.Response.ContentType = "text/plain";
                Studio_Weight obj = new Studio_Weight();
                var form = context.Request.Form;
                string[] keys = form.AllKeys;
                if (keys[0] == null)
                {
                    returnJsonStr = "您未对数据做出修改";
                }
                else
                {
                    obj = ModelBing<Studio_Weight>(obj);
                    returnJsonStr = SaveStudioWeight(obj);
                }
            }
            else if (action == "Delete_StudioWeight")
            {
                context.Response.ContentType = "text/plain";
                int nUMBER = int.Parse(context.Request["_nUMBER"] ?? "");
                returnJsonStr = Delete_StudioWeight(nUMBER);
            }

            context.Response.Write(returnJsonStr);
        }
        //显示
        public string GetStudioWeightInfo()
        {
            string sql = string.Empty;
            sql = string.Format("SELECT * FROM [fanhua_risk].[dbo].[Studio_Weight]");
            DataTable dt = DAL.ControllerFactory.GetNewController(DAL.e_ConsType.Main2).GetDataTable(sql);
            return Newtonsoft.Json.JsonConvert.SerializeObject(dt);
        }
        //保存
        private string SaveStudioWeight(Studio_Weight obj)
        {
            string returnValue = string.Empty;
            DAL.ControllerBase con = DAL.ControllerFactory.GetNewController(DAL.e_ConsType.Main2);
            if (obj.Studio_name == "" || obj.weight_key == "")
            {
                returnValue = "机构名和权重号不能为空!";
            }
            else
            {
                try
                {
                    string sql = string.Empty;
                    if (obj.KeyValues[0].ToString() == "0")
                    {
                        sql = string.Format(@"INSERT INTO [fanhua_risk].[dbo].[Studio_Weight]
               ([Studio_name]
               ,[weight_key]
               ,[SL_weight]
               ,[RD_weight]
               ,[GC_weight]
               ,[HF_weight]
               ,[Studio_name_RD]
               ,[CityName]
               ,[SRG]
               ,[SR]
               ,[SG]
               ,[RG]
               ,[S]
               ,[R]
               ,[G]
               ,[OrgID]
               ,[SRH]
               ,[H]
               ,[SH]
               ,[RH])
                select '{0}','{1}',{2},{3},{4},{5},'{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',{15},'{16}','{17}','{18}','{19}'"
                , obj.Studio_name, obj.weight_key, obj.SL_weight, obj.RD_weight, obj.GC_weight, obj.HF_weight, obj.Studio_name_RD, obj.CityName, obj.SRG, obj.SR, obj.SG, obj.RG, obj.S, obj.R, obj.G, obj.OrgID == "" ? "0" : obj.OrgID, obj.SRH, obj.H, obj.SH, obj.RH);
                    }
                    else
                    {
                        sql = string.Format(@"UPDATE [fanhua_risk].[dbo].[Studio_Weight]
       SET [Studio_name] = '{0}'
          ,[weight_key] = '{1}'
          ,[SL_weight] = {2}
          ,[RD_weight] = {3}
          ,[GC_weight] = {4}
          ,[HF_weight] = {5}
          ,[Studio_name_RD] = '{6}'
          ,[CityName] = '{7}'
          ,[SRG] = '{8}'
          ,[SR] = '{9}'
          ,[SG] = '{10}'
          ,[RG] = '{11}'
          ,[S] = '{12}'
          ,[R] = '{13}'
          ,[G] = '{14}'
          ,[OrgID]={15}
          ,[SRH] = '{16}'
          ,[H] = '{17}'
          ,[SH] = '{18}'
          ,[RH] = '{19}'
     WHERE NUMBER={20}", obj.Studio_name, obj.weight_key, obj.SL_weight, obj.RD_weight, obj.GC_weight, obj.HF_weight, obj.Studio_name_RD, obj.CityName, obj.SRG, obj.SR, obj.SG, obj.RG, obj.S, obj.R, obj.G, obj.OrgID == "" ? "0" : obj.OrgID, obj.SRH, obj.H, obj.SH, obj.RH, obj.KeyValues[0]);
                    }
                    con.ExecuteNonQuery(sql);
                    //Studio_Weight obj1 = con.GetByKey(Studio_Weight.EntityType, CConvert.ObjectToInt(obj.NUMBER)) as Studio_Weight;
                    //obj1.Studio_name=obj.Studio_name;
                    //obj1.weight_key = obj.weight_key;
                    //obj1.SL_weight =obj.SL_weight;
                    //obj1.RD_weight = obj.RD_weight;
                    //obj1.GC_weight=obj.GC_weight;
                    //obj1.HF_weight=obj.HF_weight;
                    //obj1.Studio_name_RD=obj.Studio_name_RD;
                    //obj1.CityName=obj.CityName;
                    //obj1.SRG=obj.SRG;
                    //obj1.SR=obj.SR;
                    //obj1.SG=obj.SG;
                    //obj1.RG=obj.RG;
                    //obj1.S=obj.S;
                    //obj1.R=obj.R;
                    //obj1.G=obj.G;
                    //obj1.SRH=obj.SRH;
                    //obj1.H=obj.H;
                    //obj1.SH=obj.SH;
                    //obj1.RH = obj.RH;
                    //con.Update(obj1);
                    returnValue = "保存成功";
                }
                catch (Exception ex)
                {
                    con.RollbackTran();
                    returnValue = "保存失败" + ex.ToString();
                }               
            }
            return returnValue;
        }
        //删除
        public string Delete_StudioWeight(int nUMBER)
        {
            string returnValue = string.Empty;
            DAL.ControllerBase con = DAL.ControllerFactory.GetNewController(DAL.e_ConsType.Main2);
            try
            {
                string sql = string.Empty;
                sql = string.Format(@"DELETE FROM [fanhua_risk].[dbo].[Studio_Weight] WHERE NUMBER={0}", nUMBER);
                con.ExecuteNonQuery(sql);
                return "删除成功";
            }
            catch (Exception ex)
            {
                con.RollbackTran();
                returnValue = "保存失败" + ex.ToString();
            }
            return returnValue;
        }

        /// <summary>
        /// 从表单提交的数据中绑定model模型的值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static T ModelBing<T>(T entity)
        {
            object obj = Activator.CreateInstance(typeof(T));
            Type type = entity.GetType();
            PropertyInfo[] proInfos = type.GetProperties();
            Dictionary<string, PropertyInfo> dic = new System.Collections.Generic.Dictionary<string, PropertyInfo>();
            for (int i = 0; i < proInfos.Length; i++)
            {
                dic.Add(proInfos[i].Name, proInfos[i]);
            }
            HttpContext context = HttpContext.Current;
            var form = context.Request.Form;
            string[] keys = form.AllKeys;
            foreach (string key in keys)
            {

                if (dic.ContainsKey(key))
                {
                    PropertyInfo pInfo = dic[key];
                    var proType = pInfo.PropertyType;
                    object value = null;//存储转换对应类型后的值

                    if (string.IsNullOrEmpty(form[key]))//当post过来的值没有的时候
                    {
                        if (proType == typeof(string))  //判断该属性是否string类型给空字符串,因为我数据库该字段不允许为null
                        {                                 //这里我不对值类型的数据进行判断了,因为值类型会有默认值
                            pInfo.SetValue(obj, "", null);
                        }
                        continue;
                    }
                    try
                    {
                        if (proType.IsEnum)//如果属性是枚举类型,转换枚举类型
                        {
                            value = Enum.ToObject(proType, form[key]);

                        }
                        else if (proType.IsGenericType && proType.Name.StartsWith("Nullable"))//泛型类型
                        {
                            Type newproType = Nullable.GetUnderlyingType(proType);

                            value = Convert.ChangeType(form[key], newproType);

                        }
                        else
                        {
                            value = Convert.ChangeType(form[key], proType);
                        }

                        pInfo.SetValue(obj, value, null);
                    }
                    catch (Exception ex)
                    {
                        
                    }


                }
            }
            return (T)obj;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

posted @ 2016-09-28 15:38  突破零  阅读(398)  评论(0编辑  收藏  举报