EasyUi+MVC+WCF 刪除資訊--考試系統

來源:互聯網
上載者:User

標籤:考試系統   mvc   wcf   easyui   大量刪除   

      直接奔入主題吧,主要想寫的是一個大量刪除,如何從前台的DataGrid中擷取相應的ID然後傳到後台進行大量刪除。

      前台DataGrid頁面:用EasyUI畫的

      

     具體的代碼:

     前台Js中要寫的:

//刪除$("#btn_Remove").unbind("click").click(function destroyExaminee() {    //擷取選中行數    var rows = $('#dg').datagrid('getSelections');    //判斷是否選擇行    if (!rows || rows.length == 0) {        $.messager.alert('提醒', '請至少要選擇一行資料!', 'Info');        return;    }    //擷取表格選擇行    var strId;    //迴圈給提交刪除參數賦值(考生ID)    $.each(rows, function (i, n) {        if (i == 0) {            strId = "ExamineeId=" + n.ExamineeId;        } else {            strId += "&ExamineeId=" + n.ExamineeId;        }                        });    //二次確認    $.messager.confirm('提示', '是否刪除選中資料?', function (r) {        if (!r) {            return;        }        //提交,將擷取的資料傳到後台        $.ajax({            type: "POST",            async: false,            url: "/Examinee/DeleteExaminee",            data: strId,            success: function (data) {                var jsondata = eval(data);                $('#dg').datagrid('loadData', data);            }        });    });});

      MVC的Controller中要寫的代碼:

        /// <summary>        /// 刪除考生資訊        /// </summary>        /// <param name="iList"></param>        /// <returns></returns>        public bool DeleteExaminee()        {            //從前台捕獲資料            string strExamineeId = Request.Form["ExamineeId"];            //將捕獲的資料轉換成數組            string[] listEnExamineeId = strExamineeId.Split(new char[] { ',' });            List<ExamExamineeExamRoomEntity> listExamineeId = new List<ExamExamineeExamRoomEntity>();            //3.把要刪除的id 存放到一個 考生實體集合中            for (int i = 0; i < listEnExamineeId.Count(); i++)            {                string tempStr = listEnExamineeId[i].ToString();                listExamineeId.Add(new ExamExamineeExamRoomEntity());                listExamineeId[i].ExamineeId = tempStr;                            }            //調用服務層的刪除方法            bool IsDeleteSuccess = examineeService.DeleteExamineeByExamineeId(listExamineeId);            return IsDeleteSuccess; //這裡返回的還是在前台選中的資料ID list集合,可以返回其他資料        }

  然後是WCF服務層,調用B層的方法

  下面是B層的方法

   底層架構是已經提前搭好的,該刪除是假刪除,為了保留學生的考試記錄,只是在表中添加了一個刪除的標識。

/// <summary>        /// 刪除考生資訊(按考生ID修改考生刪除標識)-- 2014-12-16 11:01:52        /// </summary>        /// <param name="listExamineeId">考生ID實體集合</param>        /// <returns>返回是否刪除成功,成功為True,失敗為False</returns>        public bool  DeleteExamineeByExamineeId(List<ExamExamineeExamEntity> listExamineeId)        {                        try            {                 for (int i = 0; i < listExamineeId.Count; i++)                 {                     //1.建立刪除考生的 實體 規則                     ExamExamineeExamEntity tempExaminee = new ExamExamineeExamEntity()                     {                         IsDeleteExamineeExam = 1                     };                     //刪除考生                     string guid = listExamineeId[i].ExamineeId;                     this.CurrentDal.Update(tempExaminee, u => u.ExamineeId == guid, "IsDeleteExamineeExam");                 }                 //儲存資訊,返回True                          this.DbSession.SaveChanges();                return true;            }            catch (Exception ex)            {                //拋出異常                throw (ex);            }  

     通過這次參加考試系統的項目,感觸最深的就是知識你可能已經學過了,但是你沒有辦法把它應用到實踐中去,所以你只是學過了,而不是學會了,實踐才是硬道理啊~~

EasyUi+MVC+WCF 刪除資訊--考試系統

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.