//添加或修改报销数据列表
 public ActionResult AddOrEditBxlistBill(T_BaoxiaoItems jkb)
 {
     if (jkb.ID <= 0)
     {
         if (T_BaoxiaoItemsService.LoadEntities(x => x.BaoXiaoID == jkb.BaoXiaoID && x.Del == 0).Count() >= 5)
         {
             return(Json(new { ret = "no", msg = "单据条数上线不可添加!" }, JsonRequestBehavior.AllowGet));
         }
         jkb.AddTime = MvcApplication.GetT_time();
         //int index = jkb.BaoXiaoName.IndexOf("(");
         //jkb.BaoXiaoName = jkb.BaoXiaoName.Remove(index);
         jkb.Del = 0;
         T_BaoxiaoItemsService.AddEntity(jkb);
         return(Json(new { ret = "ok", msg = "添加成功!" }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         if (T_BaoxiaoItemsService.EditEntity(jkb))
         {
             return(Json(new { ret = "ok", msg = "修改成功!" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new { msg = "修改出错,联系管理员!" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
        //软删除报销凭证
        public ActionResult DelBxlistbill()
        {
            var id = Request["DelID"] == null ? 0 : Convert.ToInt32(Request["DelID"]);

            if (id == 0)
            {
                return(Json(new { msg = "ID错误!" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var temp = T_BaoxiaoItemsService.LoadEntities(x => x.ID == id).FirstOrDefault();
                if (Convert.ToDateTime(temp.AddTime).ToString("yyyy-MM-dd") != MvcApplication.GetT_time().ToString("yyyy-MM-dd"))
                {
                    return(Json(new { msg = "过期删除,只可删除当天创建信息!" }, JsonRequestBehavior.AllowGet));
                }
                if (temp == null)
                {
                    return(Json(new { msg = "查询的数据为空!" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    temp.Del = 1;
                    if (T_BaoxiaoItemsService.EditEntity(temp))
                    {
                        return(Json(new { ret = "ok", msg = "修改成功!" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        return(Json(new { msg = "在修改中出错!" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
        //借款与报销详细表
        public ActionResult JieKuanBaoXiaoTable()
        {
            int pageIndex = Request["page"] != null?int.Parse(Request["page"]) : 1;

            int pageSize = Request["rows"] != null?int.Parse(Request["rows"]) : 15;

            string jkdw = Request["jkdw"] != null ? Request["jkdw"] : string.Empty;

            int totalCount = 0;
            var Bumen      = BumenInfoSetService.LoadEntities(x => x.ID == LoginUser.BuMenID).FirstOrDefault();
            IQueryable <T_JieKuanBill>  jktemp;
            IQueryable <T_BaoxiaoItems> Bxtable;

            if (Bumen.Name == "财务部" || Bumen.Name == "系统管理员")
            {
                jktemp = T_JieKuanBillService.LoadEntities(x => x.Del == 0);
                // jktemp = T_JieKuanBillService.LoadPageEntities(pageIndex, pageSize, out totalCount, x => x.Del == 0 , x => x.AddTime, false);
                Bxtable = T_BaoxiaoItemsService.LoadEntities(x => x.Del == 0).DefaultIfEmpty();
            }
            else
            {
                jktemp = T_JieKuanBillService.LoadEntities(x => x.Del == 0 && x.UserAdd == LoginUser.ID);
                //jktemp = T_JieKuanBillService.LoadPageEntities(pageIndex, pageSize, out totalCount, x => x.Del == 0 && x.UserAdd == LoginUser.ID, x => x.AddTime, false);
                Bxtable = T_BaoxiaoItemsService.LoadEntities(x => x.Del == 0 && x.T_BaoXiaoBill.AddUserID == LoginUser.ID).DefaultIfEmpty();
            }
            var temp = from a in jktemp
                       from b in Bxtable
                       where a.SkdwName == b.BaoXiaoName
                       select new jkbxdan
            {
                jkID     = a.ID,
                kename   = a.SkdwName,
                jkmoney  = a.JieKuanMoney,
                jkperson = a.JieKuanPerson,
                jktime   = a.BillTime,
                bxID     = b.ID,
                bxmoney  = b.BaoXiaoMoeny,
                bxperson = b.T_BaoXiaoBill.UserInfo.PerSonName,
                bxtime   = b.AddTime
            };

            totalCount = temp.Count();
            temp       = temp.OrderByDescending <jkbxdan, DateTime?>(x => x.bxtime).Skip <jkbxdan>((pageIndex - 1) * pageSize).Take <jkbxdan>(pageSize);

            return(Json(new
            {
                rows = temp,
                total = totalCount
            }, JsonRequestBehavior.AllowGet));
        }
        // 获取报表列数据
        public ActionResult GETBaoXiaolist()
        {
            int delflg    = Request["delflg"] == null ? 0 : int.Parse(Request["delflg"]);
            int pageIndex = Request["page"] != null?int.Parse(Request["page"]) : 1;

            int pageSize = Request["rows"] != null?int.Parse(Request["rows"]) : 15;

            int totalCount = 0;
            int BillId     = Request["BillId"] == null ? 0 : int.Parse(Request["BillId"]);
            var Adata      = T_BaoxiaoItemsService.LoadPageEntities(pageIndex, pageSize, out totalCount, x => x.Del == 0 && x.BaoXiaoID == BillId, x => x.AddTime, false);

            var temp = from a in Adata
                       select new
            {
                a.ID,
                a.BaoXiaoName,
                a.DanJiuInt,
                a.BaoXiaoMoeny,
                a.AddTime,
                a.Del
            };

            return(Json(new { rows = temp, total = totalCount }, JsonRequestBehavior.AllowGet));
        }
        //获取所有报销内容
        public ActionResult GetBaoXiaoall()
        {
            //获取所有本用户创建过的报销内容
            int uid               = LoginUser.ID;
            var tempBXB           = T_BaoXiaoBillService.LoadEntities(x => x.AddUserID == uid && x.Del == 0).DefaultIfEmpty();
            List <BaoXiaoLR> list = new List <BaoXiaoLR>();

            if (tempBXB.First() == null)
            {
                BaoXiaoLR bxlr = new BaoXiaoLR();
                bxlr.ID   = 0;
                bxlr.Text = "";
                list.Add(bxlr);
                return(Json(list, JsonRequestBehavior.AllowGet));
            }
            List <T_BaoxiaoItems> bilist = new List <T_BaoxiaoItems>();

            foreach (var a in tempBXB)
            {
                var tempBXI = T_BaoxiaoItemsService.LoadEntities(x => x.BaoXiaoID == a.ID).DefaultIfEmpty().ToList();
                foreach (var d in tempBXI)
                {
                    if (d == null || d.BaoXiaoName == null)
                    {
                        continue;
                    }
                    else
                    {
                        bilist.Add(d);
                    }
                }
            }
            List <T_BaoxiaoItems> sb1 = new List <T_BaoxiaoItems>();

            if (bilist.Count <= 1)
            {
                sb1.AddRange(bilist);
            }
            else
            {
                sb1 = bilist.Where((x, i) => bilist.FindIndex(z => z.BaoXiaoName == x.BaoXiaoName) == i).ToList();
            }
            Random rd = new Random();

            foreach (var c in sb1)
            {
                BaoXiaoLR bxlr = new BaoXiaoLR();
                bxlr.ID   = c.ID + rd.Next(100, 10000);
                bxlr.Text = c.BaoXiaoName;
                list.Add(bxlr);
            }
            //获取所有本部门创建过得借款单内容
            var tempJKB = T_JieKuanBillService.LoadEntities(x => x.UserAdd == uid && x.Del == 0).DefaultIfEmpty().ToList();
            List <T_JieKuanBill> sb2 = new List <T_JieKuanBill>();

            if (tempJKB.Count <= 1)
            {
                sb2.AddRange(tempJKB);
            }
            else
            {
                sb2 = tempJKB.Where((x, i) => tempJKB.FindIndex(z => z.SkdwName == x.SkdwName) == i).ToList();
            }
            List <BaoXiaoLR> JKBLR = new List <BaoXiaoLR>();

            foreach (var d in sb2)
            {
                if (d == null || d.SkdwName == null)
                {
                    continue;
                }
                else
                {
                    BaoXiaoLR jklr = new BaoXiaoLR();
                    jklr.ID   = d.ID;
                    jklr.Text = d.SkdwName;
                    JKBLR.Add(jklr);
                }
            }
            list.AddRange(JKBLR);
            //users.Where((x, i) => users.FindIndex(z => z.name == x.name) == i).ToList();拉姆达表达式去重
            return(Json(list, JsonRequestBehavior.AllowGet));
        }