Ejemplo n.º 1
0
 //
 #region 类别列表
 public ActionResult ClassList(string currentpage, long del = 0)
 {
     #region 翻页定义
     ViewBag.CurrentPage = 0;  //当前页
     ViewBag.PPage       = 0;  //上一页
     ViewBag.NPage       = 0;  //下一页
     ViewBag.PageCount   = 0;  //总页数
     ViewBag.RecordCount = 0;  //记录总数
     ViewBag.IsFirstPage = ""; //第一条记录,禁用首页和上一页
     ViewBag.IsEndPage   = ""; //最后条记录,禁用首页和下一页
     #endregion
     //
     ViewBag.Headline = "类别管理";//栏目主题
     //
     ViewBag.DataList   = null;
     ViewBag.RecordItem = null;
     ViewBag.Operate    = "add";                                           //add添加;edit编辑取出数据;editsave编辑保存
     //
     StatusData myStatusData = new StatusData();                           //返回状态
     //
     using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities()) //数据库操作
     {
         #region  除
         if (del > 0)
         {
             Child_Video_Class myDelRecord = myOperating.Child_Video_Class.FirstOrDefault(p => p.ClassId == del);
             if (myDelRecord != null)
             {
                 FunctionClass.delFile(myDelRecord.ClassImage);
                 myOperating.Child_Video_Class.Remove(myDelRecord);
                 myOperating.SaveChanges();
             }
         }
         #endregion
         //
         #region 翻页属性
         int    recordCount  = 0;
         int    pageCount    = 0;
         string orderbyfiled = "OrderBy";
         //
         //当前页
         int sqlCurrentpage = 1;
         if (!String.IsNullOrWhiteSpace(currentpage))
         {
             bool isOk = int.TryParse(currentpage, out sqlCurrentpage);
             if (!isOk)
             {
                 sqlCurrentpage = 1;
             }
         }
         //页大小
         int sqlPagesize = 10;
         #endregion
         //
         #region 取出内容
         IQueryable <Child_Video_Class> myIQueryable = null;
         myIQueryable = myOperating.Child_Video_Class;
         //
         if (myIQueryable != null)
         {
             List <Child_Video_Class> BookTable = QueryableExtensions.OrderBy(myIQueryable, orderbyfiled, out recordCount, out pageCount, ref sqlCurrentpage, sqlPagesize, true).ToList();
             //
             ViewBag.DataList = BookTable;
             #region 页数取值
             ViewBag.CurrentPage = sqlCurrentpage;
             ViewBag.PageCount   = pageCount;
             ViewBag.RecordCount = recordCount;
             if (sqlCurrentpage > 1)
             {
                 ViewBag.PPage = sqlCurrentpage - 1;
             }
             else
             {
                 ViewBag.IsFirstPage = "disabled";
                 ViewBag.PPage       = 1;
             }
             if (sqlCurrentpage < pageCount)
             {
                 ViewBag.NPage = sqlCurrentpage + 1;
             }
             else
             {
                 ViewBag.NPage     = sqlCurrentpage;
                 ViewBag.IsEndPage = "disabled";
             }
             #endregion
         }
         #endregion
     }
     return(View());
 }
Ejemplo n.º 2
0
 //
 #region 类别添加-编辑
 public ActionResult ClassAdd(VideoClassModel model, string ReturnUrl, Nullable <int> myid = 0)
 {
     #region 获取来路路径
     if (System.Web.HttpContext.Current.Request.UrlReferrer != null)
     {
         ViewBag.ReturnUrl = System.Web.HttpContext.Current.Request.UrlReferrer.PathAndQuery;
     }
     #endregion
     ViewBag.Headline    = "类别添加";                                         //栏目主题
     ViewBag.ButtonValue = "添加";                                           //按钮名称
     using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities()) //数据库操作
     {
         if ((myid > 0) && (model.ClassId == null))
         {
             int mySelfId = 0;
             int.TryParse(myid.ToString(), out mySelfId);
             ViewBag.Headline    = "类别编辑";
             ViewBag.ButtonValue = "修改";
             model.Operate       = "edit";
             //
             #region 取出数据
             Child_Video_Class editRecord = myOperating.Child_Video_Class.FirstOrDefault(p => p.ClassId == mySelfId);
             if (editRecord != null)
             {
                 model.ClassId    = editRecord.ClassId;
                 model.ClassTitle = editRecord.ClassTitle;
                 model.OrderBy    = editRecord.OrderBy;
             }
             #endregion
         }
         else if (model.Operate == "add")
         {
             #region 保存添加
             if (ModelState.IsValid)
             {
                 Child_Video_Class addRecord = new Child_Video_Class();
                 addRecord.ClassId    = int.Parse(model.ClassId.ToString());
                 addRecord.ClassTitle = model.ClassTitle;
                 addRecord.AddDate    = DateTime.Now;
                 addRecord.OrderBy    = model.OrderBy;
                 addRecord.Status     = 200;
                 //
                 myOperating.Child_Video_Class.Add(addRecord);
                 myOperating.SaveChanges();
                 model = null;
                 //
                 return(RedirectToLocal(ReturnUrl));
             }
             else
             {
                 ModelState.AddModelError("", "输入错误");
             }
             #endregion
         }
         else if (model.Operate == "edit")
         {
             #region 保存编辑
             if (ModelState.IsValid)
             {
                 Child_Video_Class editSaveRecord = myOperating.Child_Video_Class.FirstOrDefault(p => p.ClassId == model.ClassId);
                 if (editSaveRecord != null)
                 {
                     editSaveRecord.ClassTitle = model.ClassTitle;
                     editSaveRecord.OrderBy    = model.OrderBy;
                     //
                     myOperating.SaveChanges();
                     //
                     return(RedirectToLocal(ReturnUrl));
                 }
             }
             else
             {
                 ModelState.AddModelError("", "输入错误");
             }
             #endregion
         }
         else
         {//初次加载,默认值
             model.Operate = "add";
             #region 默认值
             try
             {
                 model.ClassId = myOperating.Child_Video_Class.Max(p => p.ClassId) + 1;
                 model.OrderBy = myOperating.Child_Video_Class.Max(p => p.OrderBy) + 1;
             }
             catch
             {
                 model.ClassId = 1;
                 model.OrderBy = 0;
             }
             if (model.ClassId == null)
             {
                 model.ClassId = 1;
             }
             if (model.OrderBy == null)
             {
                 model.OrderBy = 1;
             }
             #endregion
         }
     }
     //
     return(View(model));
 }