Example #1
0
        public async Task <ActionResult> ChangeDeadline(ChangeDeadlineModel model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "参数设置不正确");
                return(View(model));
            }
            Log log = LogFactory.GetLogger("ChangeDeadline");

            try
            {
                CWICCard cwiccd = new CWICCard();
                Customer cust   = await cwiccd.FindCustAsync(model.ID);

                if (cust != null)
                {
                    if ((int)cust.Type < 2)
                    {
                        ModelState.AddModelError("", "临时卡,无法设置使用期限");
                        return(View(model));
                    }
                    string olddeadline = cust.Deadline.ToString();

                    cust.Deadline = model.NewDeadline;
                    Response resp = cwiccd.UpdateCust(cust);
                    if (resp.Code == 1)
                    {
                        string oprtname = User.Identity.Name;
                        string utype    = "";
                        if (cust.Type == EnmICCardType.FixedLocation)
                        {
                            utype = "固定";
                        }
                        else if (cust.Type == EnmICCardType.Periodical)
                        {
                            utype = "定期";
                        }

                        FixUserChargeLog fixlog = new FixUserChargeLog
                        {
                            UserName     = cust.UserName,
                            PlateNum     = cust.PlateNum,
                            UserType     = utype,
                            Proof        = "手动",
                            LastDeadline = olddeadline,
                            CurrDeadline = cust.Deadline.ToString(),
                            FeeType      = "",
                            FeeUnit      = 0,
                            CurrFee      = 0,
                            RecordDTime  = DateTime.Now,
                            OprtCode     = oprtname
                        };
                        await new CWTariffLog().AddFixLogAsync(fixlog);
                    }
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());

                ModelState.AddModelError("", "系统异常,请联系厂家!");
                return(View(model));
            }
        }
Example #2
0
        public async Task <ActionResult> SetFixUserFee()
        {
            Log      log  = LogFactory.GetLogger("SetFixUserFee");
            Response resp = new Response();

            #region
            CWICCard cwiccd = new CWICCard();
            try
            {
                string proof = Request.Form["uiccd"];
                //计费类型
                string feetype = Request.Form["feetype"];
                //费用标准
                string feeStd = Request.Form["feeunit"];
                //实收费用
                string actualfee = Request.Form["actualfee"];

                if (TempData["CustInfo"] == null)
                {
                    resp.Message = "请先点击< 查询信息 >,再 确认缴费 !";
                    return(Json(resp));
                }

                FixCustInfo oldInfo = (FixCustInfo)TempData["CustInfo"];
                if (proof.Trim() != oldInfo.Proof.Trim())
                {
                    resp.Message = "查询条件已改变,请先点击< 查询信息 >,再 确认缴费 !";
                    return(Json(resp));
                }
                Customer cust = await cwiccd.FindCustAsync(oldInfo.CustID);

                float standard = Convert.ToSingle(feeStd);
                float actual   = Convert.ToSingle(actualfee);
                int   rnd      = (int)(actual / standard);

                EnmFeeUnit unit   = (EnmFeeUnit)Convert.ToInt16(feetype);
                int        months = 0;
                switch (unit)
                {
                case EnmFeeUnit.Month:
                    months = 1 * rnd;
                    break;

                case EnmFeeUnit.Season:
                    months = 3 * rnd;
                    break;

                case EnmFeeUnit.Year:
                    months = 12 * rnd;
                    break;

                default:
                    break;
                }
                if (months == 0)
                {
                    resp.Message = "系统异常,rnd- " + rnd + " , Unit- " + unit.ToString();
                    return(Json(resp));
                }
                DateTime current = cust.Deadline;
                if (current == DateTime.Parse("2017-1-1"))
                {
                    current = DateTime.Now;
                }
                cust.StartDTime = DateTime.Now;
                cust.Deadline   = current.AddMonths(months);
                //更新期限
                resp = cwiccd.UpdateCust(cust);

                oldInfo.LastDeadline = oldInfo.CurrDeadline;
                oldInfo.CurrDeadline = cust.Deadline.ToString();

                if (resp.Code == 1)
                {
                    #region 记录日志
                    string uty = "";
                    switch (cust.Type)
                    {
                    case EnmICCardType.Periodical:
                        uty = "定期用户";
                        break;

                    case EnmICCardType.FixedLocation:
                        uty = "固定用户";
                        break;

                    default:
                        uty = cust.Type.ToString();
                        break;
                    }
                    string umsg = "";
                    switch (unit)
                    {
                    case EnmFeeUnit.Month:
                        umsg = "月";
                        break;

                    case EnmFeeUnit.Season:
                        umsg = "季";
                        break;

                    case EnmFeeUnit.Year:
                        umsg = "年";
                        break;

                    default:
                        break;
                    }
                    string           oprt   = User.Identity.Name;
                    FixUserChargeLog fixlog = new FixUserChargeLog
                    {
                        UserName     = cust.UserName,
                        PlateNum     = cust.PlateNum,
                        UserType     = uty,
                        Proof        = oldInfo.Proof,
                        LastDeadline = oldInfo.LastDeadline,
                        CurrDeadline = oldInfo.CurrDeadline,
                        FeeType      = umsg,
                        FeeUnit      = standard,
                        CurrFee      = actual,
                        OprtCode     = oprt,
                        RecordDTime  = DateTime.Now
                    };

                    await new CWTariffLog().AddFixLogAsync(fixlog);

                    #endregion

                    resp.Message = "缴费成功!";

                    NBackInfo nback = new NBackInfo()
                    {
                        LastDeadline = oldInfo.LastDeadline,
                        CurrDeadline = oldInfo.CurrDeadline
                    };
                    resp.Data = nback;
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
            #endregion
            return(Json(resp));
        }
Example #3
0
        public ActionResult Edit(CustomerModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            CWICCard cwiccd = new CWICCard();

            #region 验证用户名、车牌号
            //顾客姓名保证唯一的
            Customer other = cwiccd.FindCust(cu => cu.UserName == model.UserName && cu.ID != model.ID);
            if (other != null)
            {
                ModelState.AddModelError("", "当前顾客名-  " + model.UserName +
                                         " 已被占用,其车牌号- " + other.PlateNum + " ,请输入唯一的用户名!");
                return(View(model));
            }
            //车牌号码保证唯一的
            other = cwiccd.FindCust(cu => cu.PlateNum == model.PlateNum && cu.ID != model.ID);
            if (other != null)
            {
                ModelState.AddModelError("", "当前车牌号-  " + model.PlateNum +
                                         " 已被绑定,其顾客名- " + other.UserName + " ,请输入正确的车牌号!");
                return(View(model));
            }
            #endregion
            #region
            Customer cust    = cwiccd.FindCust(model.ID);
            Location origloc = null;
            //原来是否绑定
            if (cust.Type == EnmICCardType.FixedLocation)
            {
                origloc = new CWLocation().FindLocation(l => l.Warehouse == cust.Warehouse && l.Address == cust.LocAddress);
            }

            //是固定卡时
            if (model.Type == EnmICCardType.FixedLocation)
            {
                #region
                if (model.Warehouse == 0 || string.IsNullOrEmpty(model.LocAddress))
                {
                    ModelState.AddModelError("", "固定卡,请指定绑定的库区及车位号!");
                    return(View(model));
                }
                Location lctn = new CWLocation().FindLocation(lc => lc.Warehouse == model.Warehouse && lc.Address == model.LocAddress);
                if (lctn == null)
                {
                    ModelState.AddModelError("", "固定卡,请正确的库区及车位地址!");
                    return(View(model));
                }
                else
                {
                    //固定车位时,当前车位没有存车
                    if (lctn.Status != EnmLocationStatus.Space)
                    {
                        ModelState.AddModelError("", "当前车位:" + lctn.Address + " 已存车,卡号- " + lctn.ICCode + " ,请等待取车完成后再绑定!");
                        return(View(model));
                    }
                }

                Customer custo = cwiccd.FindCust(cc => cc.Warehouse == model.Warehouse && cc.LocAddress == model.LocAddress);
                if (custo != null)
                {
                    if (custo.ID != cust.ID)
                    {
                        ModelState.AddModelError("", "当前车位已被别的用户绑定");
                        return(View(model));
                    }
                }
                cust.Type       = model.Type;
                cust.Warehouse  = (int)model.Warehouse;
                cust.LocAddress = model.LocAddress;

                //释放原车位
                if (origloc != null)
                {
                    if (origloc.Address != lctn.Address)
                    {
                        SingleCallback.Instance().WatchFixLocation(origloc, 0, "", "", "");
                    }
                }
                //绑定当前车位
                SingleCallback.Instance().WatchFixLocation(lctn, 1, cust.UserName, cust.Deadline.ToString(), cust.PlateNum);
                #endregion
            }
            else
            {
                cust.Type       = model.Type;
                cust.Warehouse  = 0;
                cust.LocAddress = "";
                cust.StartDTime = DateTime.Parse("2017-1-1");
                cust.Deadline   = DateTime.Parse("2017-1-1");

                //释放原车位
                if (origloc != null)
                {
                    SingleCallback.Instance().WatchFixLocation(origloc, 0, "", "", "");
                }
            }

            ICCard oriIccd = cwiccd.Find(ic => ic.CustID == model.ID);
            ICCard newIccd = null;
            if (!string.IsNullOrEmpty(model.UserCode))
            {
                newIccd = cwiccd.Find(ic => ic.UserCode == model.UserCode);
                if (newIccd == null)
                {
                    ModelState.AddModelError("", "当前卡号没有注册!");
                    return(View(model));
                }
            }
            if (oriIccd == null)
            {
                //原先没有绑定的
                if (newIccd != null)
                {
                    newIccd.CustID = cust.ID;
                    cwiccd.Update(newIccd);
                }
            }
            else
            {
                if (newIccd == null)
                {
                    //释放原来卡号
                    //释放旧卡
                    oriIccd.CustID = 0;
                    cwiccd.Update(oriIccd);
                }
                else //两卡都存在
                {
                    //不是同一张卡
                    if (oriIccd.UserCode != newIccd.UserCode)
                    {
                        #region
                        if (newIccd.Status != EnmICCardStatus.Normal)
                        {
                            ModelState.AddModelError("", "卡已挂失或注销,无法绑定用户!");
                            return(View(model));
                        }
                        if (newIccd.CustID != 0)
                        {
                            Customer oricust = cwiccd.FindCust(newIccd.CustID);
                            if (oricust != null)
                            {
                                ModelState.AddModelError("", "该卡已被绑定,车主姓名:" + oricust.UserName);
                                return(View(model));
                            }
                        }
                        #endregion
                        //释放旧卡
                        oriIccd.CustID = 0;
                        cwiccd.Update(oriIccd);
                        //绑定新卡
                        newIccd.CustID = cust.ID;
                        cwiccd.Update(newIccd);
                    }
                }
            }

            //允许更新
            cust.PlateNum      = model.PlateNum;
            cust.MobilePhone   = model.MobilePhone;
            cust.UserName      = model.UserName;
            cust.FamilyAddress = model.FamilyAddress;

            cwiccd.UpdateCust(cust);


            #region 更新指纹
            CWFingerPrint cwfprint = new CWFingerPrint();
            if (model.FingerPrint1 != "")
            {
                int         fpvalue = Convert.ToInt32(model.FingerPrint1);
                FingerPrint fp      = cwfprint.Find(fi => fi.SN_Number == fpvalue);
                if (fp != null)
                {
                    if (fp.CustID == 0)
                    {
                        fp.CustID = cust.ID;
                        cwfprint.Update(fp);
                    }
                }
            }
            if (model.FingerPrint2 != "")
            {
                int         fpvalue = Convert.ToInt32(model.FingerPrint2);
                FingerPrint fp      = cwfprint.Find(fi => fi.SN_Number == fpvalue);
                if (fp != null)
                {
                    if (fp.CustID == 0)
                    {
                        fp.CustID = cust.ID;
                        cwfprint.Update(fp);
                    }
                }
            }
            if (model.FingerPrint3 != "")
            {
                int         fpvalue = Convert.ToInt32(model.FingerPrint3);
                FingerPrint fp      = cwfprint.Find(fi => fi.SN_Number == fpvalue);
                if (fp != null)
                {
                    if (fp.CustID == 0)
                    {
                        fp.CustID = cust.ID;
                        cwfprint.Update(fp);
                    }
                }
            }
            #endregion

            #endregion
            return(RedirectToAction("Index"));
        }