public ActionResult Edit(ApplyCreditCard ApplyCreditCard)
 {
     ViewBag.IsSave = checkPower("Save");
     if (ApplyCreditCard.Id != 0)
     {
         ApplyCreditCard = Entity.ApplyCreditCard.FirstOrDefault(n => n.Id == ApplyCreditCard.Id);
     }
     if (ApplyCreditCard == null)
     {
         ViewBag.ErrorMsg = "数据不存在";
         return(View("Error"));
     }
     ViewBag.ApplyCreditCard = ApplyCreditCard;
     if (Request.UrlReferrer != null)
     {
         Session["Url"] = Request.UrlReferrer.ToString();
     }
     ViewBag.ApplyCreditCard = ApplyCreditCard;
     return(View());
 }
        /// <summary>
        /// 上传报表
        /// </summary>
        public ActionResult UpLoad(ApplyCreditCard ApplyCreditCard, string BankId)
        {
            if (Request.UrlReferrer != null)
            {
                Session["Url"] = Request.UrlReferrer.ToString();
            }
            ApplyCreditCard = Request.ConvertRequestToModel <ApplyCreditCard>(ApplyCreditCard, ApplyCreditCard);
            if (ApplyCreditCard.UserName == "System.Web.HttpPostedFileWrapper")
            {
                ViewBag.ErrorMsg = "文件类型错误";
                //RedirectToAction("Error");
                //return;
                return(View("Error"));
            }
            bool Result = false;

            //处理报表数据
            switch (BankId)
            {
            case "1":    //兴业银行
                Result = XingYe(BankId, ApplyCreditCard.UserName);
                break;

            case "2":    //交通银行
                Result = JiaoTong(BankId, ApplyCreditCard.UserName);
                break;

            default:
                ViewBag.ErrorMsg = "上传数据有误,请查看是否选择了对应银行.";
                return(View("Error"));
            }
            if (Result == false)
            {
                ViewBag.ErrorMsg = "上传数据有误,请查看是否选择了对应银行.";
                return(View("Error"));
            }
            BaseRedirect();
            return(View("Succeed"));
        }
        public void Save(ApplyCreditCard ApplyCreditCard)
        {
            ApplyCreditCard baseApplyCredit = Entity.ApplyCreditCard.FirstOrDefault(n => n.Id == ApplyCreditCard.Id);

            baseApplyCredit.State            = ApplyCreditCard.State;
            baseApplyCredit.SettlementAmount = ApplyCreditCard.SettlementAmount;
            if (ApplyCreditCard.SettlementAmount > 0)
            {
                baseApplyCredit.SettlementState = 1;
                baseApplyCredit.SettlementTime  = DateTime.Now;
            }
            if (ApplyCreditCard.FirstAgentAmount > 0)
            {
                baseApplyCredit.FirstAgentAmountState = 1;
                baseApplyCredit.FirstAgentTime        = DateTime.Now;
            }
            if (ApplyCreditCard.SettlementAmount > 0 && ApplyCreditCard.FirstAgentAmount > 0)
            {
                baseApplyCredit.State = 7;
            }
            baseApplyCredit.FirstAgentAmount = ApplyCreditCard.FirstAgentAmount;
            Entity.SaveChanges();
            BaseRedirect();
        }
        //
        // GET: /ApplyCreditCard/

        public ActionResult Index(ApplyCreditCard ApplyCreditCard, EFPagingInfo <ApplyCreditCard> p, DateTime?STime, DateTime?ETime, int IsFirst = 0, int IsShowSupAgent = -1, string BankName = "")
        {
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.Entity         = Entity;
            if (STime.IsNullOrEmpty())
            {
                STime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (ETime.IsNullOrEmpty())
            {
                // ETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                ETime = DateTime.Now;
            }
            ViewBag.ETime           = ETime;
            ViewBag.STime           = STime;
            ViewBag.BasicBankList   = Entity.BasicBank.Where(n => n.CreditCardUrl != null).ToList();
            ViewBag.ApplyCreditCard = ApplyCreditCard;
            ViewBag.BankName        = BankName;
            ViewBag.BasicAgent      = BasicAgent;
            if (IsFirst == 0)
            {
                PageOfItems <ApplyCreditCard> ApplyCreditCardList1 = new PageOfItems <ApplyCreditCard>(new List <ApplyCreditCard>(), 0, 10, 0, new Hashtable());
                ViewBag.ApplyCreditCardList = ApplyCreditCardList1;
                return(View());
            }
            // ETime = ETime.Value.AddDays(1);
            p.SqlWhere.Add(f => f.AddTime >= STime && f.AddTime <= ETime);
            //if (BasicAgent.Tier == 1)
            //{
            //    p.SqlWhere.Add(f => f.FirstAgentId == BasicAgent.Id);
            //}
            //else
            //{
            //    p.SqlWhere.Add(f => f.AgentId == BasicAgent.Id);
            //}
            if (IsShowSupAgent == 1)
            {
                List <Int32>     AgentId      = new List <Int32>();
                IList <SysAgent> SysAgentList = BasicAgent.GetSupAgent(Entity);
                foreach (var pp in SysAgentList)
                {
                    AgentId.Add(pp.Id);
                }
                p.SqlWhere.Add(f => AgentId.Contains(f.AgentId));
            }
            else
            {
                p.SqlWhere.Add(f => f.AgentId == BasicAgent.Id);
            }
            if (!BankName.IsNullOrEmpty())
            {
                IList <BasicBank> BasicBankList = Entity.BasicBank.Where(b => b.Name.Contains(BankName)).ToList();
                IList <int>       BasicBankId   = new List <int>();
                foreach (var item in BasicBankList)
                {
                    BasicBankId.Add(item.Id);
                }
                p.SqlWhere.Add(f => BasicBankId.Contains(f.BankId));
            }
            if (!ApplyCreditCard.OrderNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OrderNum == ApplyCreditCard.OrderNum);
            }
            if (!ApplyCreditCard.UserMobile.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UserMobile == ApplyCreditCard.UserMobile);
            }
            if (!ApplyCreditCard.UserName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UserName == ApplyCreditCard.UserName);
            }
            if (!ApplyCreditCard.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == ApplyCreditCard.State);
            }
            if (!ApplyCreditCard.FirstAgentAmount.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FirstAgentAmount == ApplyCreditCard.FirstAgentAmount);
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <ApplyCreditCard> ApplyCreditCardList = Entity.Selects <ApplyCreditCard>(p);

            ViewBag.ApplyCreditCardList = ApplyCreditCardList;

            return(View());
        }
        //
        // GET: /ApplyCreditCard/

        public ActionResult Index(ApplyCreditCard ApplyCreditCard, EFPagingInfo <ApplyCreditCard> p, DateTime?STime, DateTime?ETime, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (STime.IsNullOrEmpty())
            {
                STime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (ETime.IsNullOrEmpty())
            {
                // ETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                ETime = DateTime.Now;
            }
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            ViewBag.Save            = checkPower("Save");
            ViewBag.IsUpLoad        = checkPower("UpLoad");
            ViewBag.ETime           = ETime;
            ViewBag.STime           = STime;
            ViewBag.BasicBankList   = Entity.BasicBank.Where(n => n.CreditCardUrl != null).ToList();
            ViewBag.ApplyCreditCard = ApplyCreditCard;
            ViewBag.SysAgentList    = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent  = IsShowSupAgent;

            // ETime = ETime.Value.AddDays(1);
            p.SqlWhere.Add(f => f.AddTime > STime && f.AddTime < ETime);
            if (!ApplyCreditCard.BankId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.BankId == ApplyCreditCard.BankId);
            }
            if (!ApplyCreditCard.UserMobile.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UserMobile == ApplyCreditCard.UserMobile);
            }
            if (!ApplyCreditCard.OrderNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OrderNum == ApplyCreditCard.OrderNum);
            }
            if (!ApplyCreditCard.UserName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UserName == ApplyCreditCard.UserName);
            }
            if (!ApplyCreditCard.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == ApplyCreditCard.State);
            }
            if (!ApplyCreditCard.FirstAgentAmount.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FirstAgentAmount == ApplyCreditCard.FirstAgentAmount);
            }
            if (!ApplyCreditCard.FirstAgentId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FirstAgentId == ApplyCreditCard.FirstAgentId);
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <ApplyCreditCard> ApplyCreditCardList = null;

            if (IsFirst == 0)
            {
                ApplyCreditCardList = new PageOfItems <ApplyCreditCard>(new List <ApplyCreditCard>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                ApplyCreditCardList = Entity.Selects <ApplyCreditCard>(p);
            }
            ViewBag.ApplyCreditCardList = ApplyCreditCardList;

            return(View());
        }
        public void AddNew(ApplyCredit ApplyCredit, int BankId, string IDcard)
        {
            IList <SMSCode> List = Entity.SMSCode.Where(n => n.UId == BasicUsers.Id && n.Mobile == ApplyCredit.Mobile && n.CType == 1 && n.State == 1).ToList();

            foreach (var p in List)
            {
                p.State = 0;
            }
            Entity.SaveChanges();
            IList <SysAgent> parentAgents = BasicAgent.GetAgentsById(Entity);
            string           Agents       = "|";

            foreach (var item in parentAgents)
            {
                Agents += item.Id + "|";
            }
            ApplyCreditCard AC = new ApplyCreditCard()
            {
                AgentId               = BasicAgent.Id,
                BankId                = BankId,
                Uid                   = BasicUsers.Id,
                FirstAgentAmount      = 0,
                FirstAgentAmountState = 0,
                UserName              = ApplyCredit.TrueName,
                UserMobile            = ApplyCredit.Mobile,
                UserIdCard            = IDcard,
                FirstAgentId          = BasicAgent.GetTopAgent(Entity).Id,
                Relation              = Agents,
                OrderNum              = DateTime.Now.ToString("yyyyMMddHHmmssfff"),
                SettlementAmount      = 0,
                SettlementState       = 0,
                AddTime               = DateTime.Now,
                State                 = 1
            };

            //已审核之前的状态不添加第二条数据 包括已审核的状态
            if (Entity.ApplyCreditCard.FirstOrDefault(ACC => ACC.BankId == BankId && ACC.UserIdCard == IDcard && ACC.State < 3) == null)
            {
                Entity.ApplyCreditCard.AddObject(AC);
                Entity.SaveChanges();
            }

            //ApplyCredit AC = new ApplyCredit();
            //AC = Request.ConvertRequestToModel<ApplyCredit>(AC, ApplyCredit);
            //AC.BankId = BankId;
            //AC.UId = BasicUsers.Id;
            //AC.AId = 0;
            //AC.State = 1;
            //AC.AddTime = DateTime.Now;
            //AC.AgentId = BasicAgent.Id;
            //AC.AgentAId = AdminUser.Id;
            //AC.PayState = 0;
            //AC.AgentPay = 0;
            ////这里是利润计算==========
            //AC.Amoney = 0;//获取价格
            //AC.AIdMoney = AC.Amoney;//总利润
            //AC.AgentMoney = 0;//分支机构佣金设置为0,待分润计算后再写入
            //AC.Company = "";
            //AC.CompanyNature = "";
            //AC.SheBao = "";
            //AC.HasSheBao = 0;
            //AC.Marry = 0;
            //AC.HasCar = 0;
            //AC.HasCredit = 0;
            //Entity.ApplyCredit.AddObject(AC);
            //Entity.SaveChanges();
            Response.Write("<script>location.href=\"" + Entity.BasicBank.FirstOrNew(b => b.Id == BankId).CreditCardUrl + "\";</script>");
        }