public ContentResult GetHandwrittenExpressList(Lib.GridPager pager, string queryStr)
        {
            string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);
            IQueryable <T_HandwrittenExpress> queryData = db.T_HandwrittenExpress.Where(a => a.Isdelete == 0).AsQueryable();

            if (!string.IsNullOrEmpty(queryStr))
            {
                queryData = queryData.Where(a => a.Telephone != null && a.Telephone.Contains(queryStr));
            }
            pager.totalRows = queryData.Count();
            queryData       = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows);
            List <T_HandwrittenExpress> list = new List <T_HandwrittenExpress>();

            foreach (var item in queryData)
            {
                T_HandwrittenExpress i = new T_HandwrittenExpress();
                item.Warehouse = Com.GetWarehouseName(item.Warehouse);
                i = item;
                list.Add(i);
            }
            //分页
            // List<T_ManualBilling> list = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows).ToList();
            string json = "{\"total\":" + pager.totalRows + ",\"rows\":" + JsonConvert.SerializeObject(list, Lib.Comm.setTimeFormat()) + "}";

            return(Content(json));
        }
        public ContentResult GetHandwrittenExpressCheck(Lib.GridPager pager, string queryStr)
        {
            string name     = Server.UrlDecode(Request.Cookies["Name"].Value);
            string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);
            List <T_HandwrittenExpressGroup> GroupModel = db.T_HandwrittenExpressGroup.Where(a => a.Crew != null && (a.Crew.Contains(name) || a.Crew.Contains(Nickname))).ToList();

            string[] shenheName = new string[GroupModel.Count];
            for (int z = 0; z < GroupModel.Count; z++)
            {
                shenheName[z] = GroupModel[z].GroupName;
            }
            List <T_HandwrittenExpressAppRove> ApproveMod = db.T_HandwrittenExpressAppRove.Where(a => (shenheName.Contains(a.ApproveName) || a.ApproveName == name || a.ApproveName == Nickname) && a.ApproveTime == null).ToList();
            string arrID = "";

            for (int i = 0; i < ApproveMod.Count; i++)
            {
                if (i == 0)
                {
                    arrID += ApproveMod[i].Oid.ToString();
                }
                else
                {
                    arrID += "," + ApproveMod[i].Oid.ToString();
                }
            }
            string sql = "select * from T_HandwrittenExpress r  where isdelete=0  and (Status = -1 or Status = 0 or Status = 2) ";

            if (arrID != null && arrID != "")
            {
                sql += " and ID in (" + arrID + ")";
            }
            else
            {
                sql += " and 1=2";
            }
            IQueryable <T_HandwrittenExpress> queryData = db.Database.SqlQuery <T_HandwrittenExpress>(sql).AsQueryable();

            //  IQueryable<T_MajorInvoice> queryData = db.T_MajorInvoice.Where(a=>a.).AsQueryable();
            if (!string.IsNullOrEmpty(queryStr))
            {
                queryData = queryData.Where(a => a.Telephone != null && a.Telephone.Contains(queryStr));
            }
            pager.totalRows = queryData.Count();
            queryData       = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows);
            List <T_HandwrittenExpress> list = new List <T_HandwrittenExpress>();

            foreach (var item in queryData)
            {
                T_HandwrittenExpress i = new T_HandwrittenExpress();
                item.Warehouse = Com.GetWarehouseName(item.Warehouse);
                i = item;
                list.Add(i);
            }
            //分页
            //  List<T_ManualBilling> list = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows).ToList();
            string json = "{\"total\":" + pager.totalRows + ",\"rows\":" + JsonConvert.SerializeObject(list, Lib.Comm.setTimeFormat()) + "}";

            return(Content(json));
        }
        public ActionResult ViewHandwrittenExpressReportCheck(int ID)
        {
            GetApproveHistory(ID);
            ViewData["ID"] = ID;
            T_HandwrittenExpress model = db.T_HandwrittenExpress.SingleOrDefault(a => a.ID == ID);

            return(View(model));
        }
        public ActionResult ViewHandwrittenExpressDetail(int ID)
        {
            GetApproveHistory(ID);
            ViewData["ID"] = ID;
            T_HandwrittenExpress model = db.T_HandwrittenExpress.SingleOrDefault(a => a.ID == ID);

            model.Warehouse = Com.GetWarehouseName(model.Warehouse);
            return(View(model));
        }
        public JsonResult DeleteInvoiceFinance(int ID)
        {
            T_HandwrittenExpress model = db.T_HandwrittenExpress.Find(ID);

            model.Isdelete = 1;
            db.Entry <T_HandwrittenExpress>(model).State = System.Data.Entity.EntityState.Modified;
            int i = db.SaveChanges();

            return(Json(i, JsonRequestBehavior.AllowGet));
        }
        public JsonResult HandwrittenExpressAdd(T_HandwrittenExpress model, string jsonStr)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                try
                {
                    string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);
                    model.ApplyName = Nickname;
                    model.ApplyDate = DateTime.Now;
                    model.Status    = -1;
                    model.Step      = 0;
                    model.Isdelete  = 0;

                    db.T_HandwrittenExpress.Add(model);
                    int i = db.SaveChanges();
                    if (i > 0)
                    {
                        T_HandwrittenExpressConfig  modelconfig  = db.T_HandwrittenExpressConfig.SingleOrDefault(a => a.Step == 0 && a.Reason == "1");
                        T_HandwrittenExpressAppRove AppRoveModel = new T_HandwrittenExpressAppRove();
                        AppRoveModel.Status = -1;
                        AppRoveModel.Step   = "0";
                        if (modelconfig.Name == null || modelconfig.Name == "")
                        {
                            AppRoveModel.ApproveName = modelconfig.Type;
                        }
                        else
                        {
                            AppRoveModel.ApproveName = modelconfig.Name;
                        }
                        AppRoveModel.ApproveDName = modelconfig.Type;
                        AppRoveModel.Oid          = model.ID;
                        db.T_HandwrittenExpressAppRove.Add(AppRoveModel);
                        db.SaveChanges();
                    }
                    else
                    {
                        return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet));
                    }

                    sc.Complete();
                    return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { State = "Faile", Message = ex.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ContentResult GetHandwrittenExpressChecken(Lib.GridPager pager, string queryStr)
        {
            string name     = Server.UrlDecode(Request.Cookies["Name"].Value);
            string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);


            List <T_HandwrittenExpressAppRove> ApproveMod = db.T_HandwrittenExpressAppRove.Where(a => (a.ApproveName == name || a.ApproveName == Nickname) && (a.Status == 1 || a.Status == 2)).ToList();

            int[] Arry = new int[ApproveMod.Count];
            for (int i = 0; i < ApproveMod.Count; i++)
            {
                Arry[i] = int.Parse(ApproveMod[i].Oid.ToString());
            }
            IQueryable <T_HandwrittenExpress> queryData = from r in db.T_HandwrittenExpress
                                                          where Arry.Contains(r.ID) && r.Isdelete == 0
                                                          select r;

            if (!string.IsNullOrEmpty(queryStr))
            {
                queryData = queryData.Where(a => (a.Telephone != null && a.Telephone.Contains(queryStr)));
            }

            pager.totalRows = queryData.Count();
            //分页
            queryData = queryData.OrderByDescending(c => c.ID).Skip((pager.page - 1) * pager.rows).Take(pager.rows);
            List <T_HandwrittenExpress> list = new List <T_HandwrittenExpress>();

            foreach (var item in queryData)
            {
                T_HandwrittenExpress i = new T_HandwrittenExpress();
                item.Warehouse = Com.GetWarehouseName(item.Warehouse);
                i = item;
                list.Add(i);
            }
            string json = "{\"total\":" + pager.totalRows + ",\"rows\":" + JsonConvert.SerializeObject(list, Lib.Comm.setTimeFormat()) + "}";

            return(Content(json));
        }
        //审核
        public JsonResult HandwrittenExpressCheckCheck(T_HandwrittenExpress model, string status, string Memo, string CSG)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                int ID = model.ID;
                T_HandwrittenExpress Invoicemodel = db.T_HandwrittenExpress.SingleOrDefault(a => a.ID == ID && a.Isdelete == 0);
                if (Invoicemodel == null)
                {
                    return(Json("数据可能被删除", JsonRequestBehavior.AllowGet));
                }

                T_HandwrittenExpressAppRove modelApprove = db.T_HandwrittenExpressAppRove.FirstOrDefault(a => a.Oid == ID && a.ApproveTime == null);
                string Nickname = Server.UrlDecode(Request.Cookies["Nickname"].Value);

                string result = "";
                modelApprove.ApproveName = Nickname;
                modelApprove.Memo        = Memo;
                modelApprove.ApproveTime = DateTime.Now;
                modelApprove.Status      = int.Parse(status);
                db.Entry <T_HandwrittenExpressAppRove>(modelApprove).State = System.Data.Entity.EntityState.Modified;
                int i = db.SaveChanges();
                if (i > 0)
                {
                    if (CSG != null && CSG != "")
                    {
                        string[] CSGname = CSG.Split(',');
                        for (int f = 0; f < CSGname.Length; f++)
                        {
                            T_HandwrittenExpressCopy Copy = new T_HandwrittenExpressCopy();
                            Copy.Oid         = ID;
                            Copy.CCName      = Nickname;
                            Copy.ReceiveName = CSGname[f];
                            db.T_HandwrittenExpressCopy.Add(Copy);
                            db.SaveChanges();
                        }
                    }

                    if (status == "1")
                    {
                        T_HandwrittenExpressAppRove newApprove = new T_HandwrittenExpressAppRove();
                        int step = int.Parse(Invoicemodel.Step.ToString());
                        step++;
                        IQueryable <T_HandwrittenExpressConfig> config = db.T_HandwrittenExpressConfig.AsQueryable();
                        int stepLength = config.Count();//总共步骤
                        if (step < stepLength)
                        {
                            Invoicemodel.Status = 0;
                            T_HandwrittenExpressConfig stepMod = db.T_HandwrittenExpressConfig.SingleOrDefault(a => a.Step == step);
                            string nextName = stepMod.Name;
                            newApprove.Memo   = "";
                            newApprove.Oid    = ID;
                            newApprove.Status = -1;
                            newApprove.Step   = step.ToString();
                            if (nextName != null)
                            {
                                newApprove.ApproveName  = nextName;
                                newApprove.ApproveDName = stepMod.Type;
                            }
                            else
                            {
                                newApprove.ApproveName  = stepMod.Type;
                                newApprove.ApproveDName = stepMod.Type;
                            }
                            db.T_HandwrittenExpressAppRove.Add(newApprove);
                            db.SaveChanges();
                        }
                        else
                        {
                            Invoicemodel.Status = int.Parse(status);
                        }
                        Invoicemodel.Step = step;
                        db.Entry <T_HandwrittenExpress>(Invoicemodel).State = System.Data.Entity.EntityState.Modified;
                        int j = db.SaveChanges();
                        sc.Complete();
                        if (j > 0)
                        {
                            result = "保存成功";
                        }
                        else
                        {
                            result = "保存失败";
                        }
                    }
                    else
                    {
                        //不同意
                        Invoicemodel.Step   = 0;
                        Invoicemodel.Status = 2;
                        db.Entry <T_HandwrittenExpress>(Invoicemodel).State = System.Data.Entity.EntityState.Modified;
                        int j = db.SaveChanges();
                        //审核流程结束 申请人编辑后插入下一条记录
                        sc.Complete();
                        if (j > 0)
                        {
                            result = "保存成功";
                        }
                        else
                        {
                            result = "保存失败";
                        }
                    }
                }
                else
                {
                    result = "保存失败";
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }