sharepoint 增删改查

前端提交

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MeetingOneWeekNotifyList.aspx.cs" Inherits="MeetingOneWeekNotifyList" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %>
<%@ Assembly Name="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" %>

<asp:content id="ContentHead" contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
 <%--   <link href="commom_new_shenergy.css" rel="stylesheet" />--%>
<link href="commom_new_201611081702.css" rel="stylesheet" />
    <script src="js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript">
        $.ajax({
            url: "./Handler/HandlerMeetList.ashx",//查询
            type: "post",
            async: false,
            dataType: "json",
            data: {
                
            },
            success: function (arr) {
                for (var i = 0; i < arr.length; i++) {
                    var en = arr[i];
                    alert(en.MeetTitle);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('错误!');
            }
        });

        function Save() {
            var entity = {};
            entity.MeetId = 1;
            entity.MeetTitle = "bbbb";
            $.ajax({
                url: "./Handler/HandlerMeetReq.ashx",//查询
                type: "post",
                async: false,
                dataType: "text",
                data: {
                    method: "ADD",
                    req: JSON.stringify(entity)
                },
                success: function (arr) {
                    alert(arr);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert('错误!');
                }
            });
        }

        function Save() {
            var entity = {};
            entity.MeetId = 1;
            entity.MeetTitle = "bbbb";
            $.ajax({
                url: "./Handler/HandlerMeetReq.ashx",//查询
                type: "post",
                async: false,
                dataType: "text",
                data: {
                    method: "Del",
                    req: JSON.stringify(entity)
                },
                success: function (arr) {
                    alert(arr);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert('错误!');
                }
            });
        }
    </script>


    </asp:content>
<asp:content id="Content1" contentplaceholderid="PlaceHolderMain" runat="Server">
    <input type="button" value="Update" onclick="Save()" />
    <div class="wrap">

        <div class="contentDiv">
            <div class="inCon" >

            <div class="right">
        <div class="InRight">一周会议通知    
      <a href="http://tuvaudit:41182/_layouts/15/shenergy/MeetingOneWeekApplyForm.aspx" style="color:white;margin-left:65%">+新增会议申请</a>
        </div>
                    <div class="tableDiv" >
                        <table cellpadding="0" cellspacing="0" width="100%" id="meetingNotifyOneWeekTable">
                            <tr>
                                <td>序列号</td>
                                <td>会议室名称</td>
                                <td>会议名称</td>
                                <td>申请时间</td>
                                <td>操作</td>
                            </tr>
                            <tr>
                                <td class="meetingNotifyOneWeekId">1</td>
                                <td class="meetingNotifyOneWeekRoom">会议室(918)</td>
                                <td >共同探讨党的18大会议精神1</td>
                                <td>2014-03-12 10:20-11:20</td>
                                <td>
                        <span>
                            <input type="button" class="btnModify" value="变更" />

                        </span>
                        <span>
                            <input type="button" class="btnCancel2" value="撤销" />

                        </span>
                                </td>
                            </tr>
                            <tr>
                                <td class="meetingNotifyOneWeekId">1</td>
                                <td class="meetingNotifyOneWeekRoom">会议室(918)</td>
                                <td >共同探讨党的18大会议精神1</td>
                                <td>2014-03-12 10:20-11:20</td>
                                <td>
                        <span><input type="button" class="btnModify" value="变更" /></span>
                                    <span><input type="button" class="btnCancel2" value="撤销"  /></span>
                                </td>
                            </tr>
                                                                                                    
                        </table>
                    </div>
                    <div class="InRight1">共有3个会议<span>&lt;</span><span>1</span><span>&gt;</span></div>
                    
                </div>
            </div>
        </div>
        </body>
    <script src="commom_shenergy.js"></script>
    </asp:content>

一般处理程序  

<%@ WebHandler Language="C#" Class="HandlerMeetReq" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %>
<%@ Assembly Name="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" %>

using System;
using System.Web;
using Microsoft.SharePoint;
using CodeArt.SharePoint.CamlQuery;
using EntityLib;

public class HandlerMeetReq : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        MeetEntity meetingEntity = new MeetEntity();
        
        try
        {
            string strReq = context.Request["req"];
            string strMethod = context.Request["method"];
            MeetEntity entity = Newtonsoft.Json.JsonConvert.DeserializeObject<MeetEntity>(strReq);

            SPContext.Current.Web.AllowUnsafeUpdates = true;
            SPList list = SPContext.Current.Web.Lists["会议申请"];
            SPListItem item = null;
            if (strMethod == "Add")
            {
                item = list.AddItem();
            }
            else
            {
                item = list.GetItemById(int.Parse(entity.MeetId));
            }

            if (strMethod == "Add" || strMethod == "Update")
            {
                item["标题"] = entity.MeetTitle;
                item.Update();
            }
            else if (strMethod == "Del")
            {
                item.Delete();
            }

            context.Response.Write("OK");
        }
        catch (Exception ex)
        {
            context.Response.Write(ex.Message);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

//public class MeetEntity
//{
//    public MeetEntity()
//    {
//    }

//    public string MeetId;

//    public string MeetTitle;

//    public string MeetRoomId;

//    public string MeetRoomTitle;

//    public string MeetContent;
//}

  查看数据页面 :http://tuvaudit:41182/Lists/List/AllItems.aspx

 

<%@ WebHandler Language="C#" Class="HandlerMeetList" %>

<%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="CodeArt.SharePoint.CamlQuery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=43536cfde91ea799" %>
<%@ Assembly Name="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" %>
<%@ Assembly Name="EntityLib, Version=1.0.0.0, Culture=neutral" %>

using System;
using System.Web;
using System.Collections.Generic;
using Microsoft.SharePoint;
using CodeArt.SharePoint.CamlQuery;
using EntityLib;

public class HandlerMeetList : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        SPList list = SPContext.Current.Web.Lists["会议申请"];
        QueryField qfId = new QueryField("ID");
        SPListItemCollection items = ListQuery.From(list).Where(qfId > 0).GetItems();

        List<MeetEntity> lstEntities = new List<MeetEntity>();
        foreach (SPListItem item in items)
        {
            MeetEntity entity = new MeetEntity();
            entity.MeetId = item.ID.ToString();
            entity.MeetTitle = ConvertObj(item["序列号"]);
            entity.MeetRoomId = ConvertObj(item["会议室名称"]);
            entity.MeetRoomTitle = ConvertObj(item["会议名称"]);
            entity.MeetContent = ConvertObj(item["申请时间"]);
            lstEntities.Add(entity);
        }

        //context.Response.Write("Hello World");
        context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(lstEntities));
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

    private string ConvertObj(object obj)
    {
        return obj == null ? "" : obj.ToString();
    }
}

//public class MeetEntity
//{
//    public MeetEntity()
//    {
//    }

//    public string MeetId;

//    public string MeetTitle;

//    public string MeetRoomId;

//    public string MeetRoomTitle;

//    public string MeetContent;
//}

 

  <script type="text/javascript">
      
            
             //$.ajax({
             //    url: "./Handler/HandlerMeetList.ashx",//查询
             //    type: "post",
             //    async: false,
             //    dataType: "json",
             //    data: {

             //    },
             //    success: function (arr) {
             //        for (var i = 0; i < arr.length; i++) {
             //            var en = arr[i];
             //            alert(en.MeetTitle);
             //        }
             //    },
             //    error: function (XMLHttpRequest, textStatus, errorThrown) {
             //        alert('错误!');
             //    }
             //});
             //$("#MeetingAdd").bind("click", Add);
         $("#MeetingQuery").bind("click", Query);
         
            
             function Query() {
                

                 alert("查询:");
                 $.ajax({
                     url: "./Handler/HandlerMeetList.ashx",//查询
                     type: "post",
                     async: false,
                     dataType: "json",
                     data: {

                     },
                     success: function (arr) {
                         for (var i = 0; i < arr.length; i++) {
                             var en = arr[i];
                             alert("序列号:"+en.MeetingId +"会议室名:"+en.MeetingRoomName);
                         }
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         alert('错误!');
                     }
                 });
             }

             function Save() {
                 var entity = {};
                 entity.MeetId = 1;
                 entity.MeetTitle = "bbbb";
                 $.ajax({
                     url: "./Handler/HandlerMeetReq.ashx",//查询
                     type: "post",
                     async: false,
                     dataType: "text",
                     data: {
                         method: "ADD",
                         req: JSON.stringify(entity)
                     },
                     success: function (arr) {
                         alert(arr);
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         alert('错误!');
                     }
                 });
             }

             function Add() {
                 alert("增加")
                 var MeetingApply = {};
                 MeetingApply.MeetingId = 1;
                 MeetingApply.MeetingRoomName = "会议室(918)";
                 MeetingApply.MeetingName = "共同探讨党的18大";
                 MeetingApply.MeetingName = "共同探讨党的18大";
                 MeetingApply.MeetingApplyTime = "2016-11-14 12:10"
                 entity.
                 $.ajax({
                     url: "./Handler/HandlerMeetReq.ashx",//查询
                     type: "post",
                     async: false,
                     dataType: "text",
                     data: {
                         method: "Add",
                         req: JSON.stringify(entity)
                     },
                     success: function (arr) {
                         alert(arr);
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         alert('错误!');
                     }
                 });
             }

             function Del() {
                 var entity = {};
                 entity.MeetId = 1;
                 entity.MeetTitle = "bbbb";
                 $.ajax({
                     url: "./Handler/HandlerMeetReq.ashx",//查询
                     type: "post",
                     async: false,
                     dataType: "text",
                     data: {
                         method: "Del",
                         req: JSON.stringify(entity)
                     },
                     success: function (arr) {
                         alert(arr);
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         alert('错误!');
                     }
                 });
             }

            </script>

 

posted @ 2016-11-14 11:39  每天进步一点点!  阅读(487)  评论(0编辑  收藏  举报