public JsonResult RegisterLockerWithCardNumber(string lockerid, string cardnumber)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                var objLocker = _tblLockerService.GetById(lockerid);
                if (objLocker != null)
                {
                    var objCard = _tblCardService.GetByCardNumber(cardnumber);
                    if (objCard != null)
                    {
                        objLocker.LockerType = "1"; //Cố định
                        objLocker.CardNumber = objCard.CardNumber;
                        objLocker.CardNo     = objCard.CardNo;

                        result = _tblLockerService.Update(objLocker);
                    }
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public JsonResult DeleteEvent(string id)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            if (!string.IsNullOrEmpty(id))
            {
                var obj = new tblActiveCard();

                var activecard = _tblActiveCardService.GetById(id);

                if (activecard != null)
                {
                    var subid = activecard.SubId;
                    var card  = _tblCardService.GetByCardNumber(activecard.CardNumber);
                    if (card != null)
                    {
                        if (Convert.ToDateTime(card.ExpireDate).Date == Convert.ToDateTime(activecard.NewExpireDate).Date)
                        {
                            card.ExpireDate = activecard.OldExpireDate;
                            _tblCardService.Update(card);
                            result = _tblActiveCardService.DeleteById(id);
                        }
                        else
                        {
                            result = new MessageReport(false, "Không thể xóa");
                        }

                        //xóa chi tiết gia hạn
                        if (result.isSuccess)
                        {
                            _tblActiveCardService.DeleteExtendBySubId(subid);
                        }
                    }
                }

                if (result.isSuccess)
                {
                    WriteLog.Write(result, GetCurrentUser.GetUser(), id, "", "tblActiveCard", ConstField.ParkingCode, ActionConfigO.Delete);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
        public HttpResponseMessage ExtendCardByOrder(HttpRequestMessage request, PMC_CustomerOrder model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            //Check Auth
            var objAuth = _API_AuthService.GetDefault();

            if (objAuth != null)
            {
                if (objAuth.AccessToken != model.AccessToken)
                {
                    result = new MessageReport(false, "Token không khớp");

                    //Trả lại response
                    return(CreateHttpResponse(request, () =>
                    {
                        var response = request.CreateResponse(result.isSuccess ? HttpStatusCode.OK : HttpStatusCode.BadRequest, result);
                        return response;
                    }));
                }
            }

            //Xử lý logic gia hạn
            var obj = _tblCardService.GetByCardNumber(model.CardNumber);

            if (obj != null)
            {
                string dateextend = Convert.ToDateTime(obj.ExpireDate).AddDays(model.DayExtend).ToString("MM/dd/yyyy");
                var    money      = model.Money.ToString().Replace(".", "").Replace(",", "");

                var isSuccess = _tblCardService.AddCardExpireByListCardNumber("'" + model.CardNumber + "'", int.Parse(money), dateextend, "Từ APP", false);

                if (isSuccess)
                {
                    //result = new MessageReport(true, FunctionHelper.GetLocalizeDictionary("Home", "notification")["updateSuccess"]);
                    result = new MessageReport(true, "Gia hạn thành công");
                }
                else
                {
                    //result = new MessageReport(false, FunctionHelper.GetLocalizeDictionary("Home", "notification")["updateFailed"]);
                    result = new MessageReport(false, "Gia hạn thất bại");
                }
            }
            else
            {
                result = new MessageReport(false, "Thẻ không tồn tại");
            }

            //Trả lại response
            return(CreateHttpResponse(request, () =>
            {
                var response = request.CreateResponse(result.isSuccess ? HttpStatusCode.OK : HttpStatusCode.BadRequest, result);
                return response;
            }));
        }
        public ActionResult ReportEvent(string KeyWord = "", string status = "", string controllerid = "", string cardgroup = "", string fromdate = "", string todate = "", int page = 1, string chkExport = "0", string datefrompicker = "")
        {
            var    totalItem  = 0;
            var    pageSize   = 20;
            var    user       = GetCurrentUser.GetUser();
            string CustomerID = "";


            if (!string.IsNullOrWhiteSpace(fromdate) && !string.IsNullOrWhiteSpace(todate))
            {
                datefrompicker = fromdate + "-" + todate;
            }

            #region Excel
            //Excel
            if (chkExport.Equals("1"))
            {
                ////Query lấy dữ liệu
                var listExcel = _ReportService.GetReportEventExcel(KeyWord, status, controllerid, fromdate, todate, cardgroup);

                if (listExcel != null && listExcel.Rows.Count > 0)
                {
                    foreach (DataRow dr in listExcel.Rows)
                    {
                        var customer = new tblCustomer();
                        var cg       = new tblCardGroup();

                        if (!string.IsNullOrEmpty(dr["CardNumber"].ToString()))
                        {
                            var card = _tblCardService.GetByCardNumber(dr["CardNumber"].ToString());

                            if (card != null)
                            {
                                if (!string.IsNullOrEmpty(card.CustomerID))
                                {
                                    customer = _tblCustomerService.GetById(Guid.Parse(card.CustomerID));
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(dr["CardGroupID"].ToString()))
                        {
                            cg = _tblCardGroupService.GetById(Guid.Parse(dr["CardGroupID"].ToString()));
                        }

                        if (!string.IsNullOrEmpty(dr["ControllerID"].ToString()))
                        {
                            var controller = _tblAccessControllerService.GetById(Guid.Parse(dr["ControllerID"].ToString()));
                            var door       = _tblAccessDoorService.GetByController_Readerindex(dr["ControllerID"].ToString(), dr["ReaderIndex"].ToString());

                            dr["ControllerName"] = controller != null ? controller.ControllerName : "";
                            dr["DoorName"]       = door != null ? door.DoorName : "";
                        }

                        dr["CustomerName"]  = customer != null ? customer.CustomerName : "";
                        dr["CardGroupName"] = cg != null ? cg.CardGroupName : "";
                        dr["Address"]       = customer != null ?  customer.Address : "";
                    }
                }

                listExcel.Columns.Remove("RowNumber");
                listExcel.Columns.Remove("ControllerID");
                listExcel.Columns.Remove("ReaderIndex");
                listExcel.Columns.Remove("CardGroupID");

                //Xuất file theo format
                ReportEventFormatCell(listExcel, "Sự_kiện_quẹt_thẻ", "Sheet1", "", "Sự kiện quẹt thẻ", datefrompicker);

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

            #region Giao diện
            var list = _ReportService.GetReportEvent(KeyWord, status, controllerid, fromdate, todate, page, pageSize, ref totalItem, cardgroup);

            var gridModel = PageModelCustom <ReportEvent_Access> .GetPage(list, page, pageSize, totalItem);

            ViewBag.CardGroups  = GetCardGroupListMonth().ToList();
            ViewBag.CardGroupDT = GetCardGroupListMonth().ToDataTableNullable();
            ViewBag.CardGroupId = cardgroup;

            ViewBag.Controllers  = GetControllerList().ToList();
            ViewBag.ControllerDT = GetControllerList().ToDataTableNullable();
            ViewBag.ControllerID = controllerid;

            ViewBag.Status    = status;
            ViewBag.StatusDDL = FunctionHelper.StatusEventAccess();
            ViewBag.Doors     = GetDoor();

            ViewBag.DateFromPickerValue = datefrompicker;
            ViewBag.KeyWord             = KeyWord;

            ViewBag.fromdateValue = fromdate;
            ViewBag.todateValue   = !string.IsNullOrWhiteSpace(todate) ? Convert.ToDateTime(todate).ToString("dd/MM/yyyy HH:mm:59") : DateTime.Now.ToString("dd/MM/yyyy 23:59:59");

            return(View(gridModel));

            #endregion
        }
        public ActionResult Create(tblCardSubmit tblCard, HttpPostedFileBase FileUpload, string key, string cardgroups, string customergroups, string active, string fromdate, string todate, string isCheckByTime = "0", bool SaveAndCountinue = false)
        {
            ViewBag.CardGroups          = GetListCardGroup();
            ViewBag.lcustomergroups     = GetMenuList();
            ViewBag.CardGroups          = GetListCardGroup();
            ViewBag.lcustomergroups     = GetMenuList();
            ViewBag.keyValue            = key;
            ViewBag.cardgroupsValue     = cardgroups;
            ViewBag.customergroupsValue = customergroups;
            ViewBag.activeValue         = active;
            ViewBag.fromdateValue       = fromdate;
            ViewBag.todateValue         = todate;
            ViewBag.isCheckByTimeValue  = isCheckByTime;
            if (!ModelState.IsValid)
            {
                return(View(tblCard));
            }
            // valid thẻ
            if ((string.IsNullOrEmpty(tblCard.CardNo) || string.IsNullOrWhiteSpace(tblCard.CardNo)) || (string.IsNullOrWhiteSpace(tblCard.CardNumber) || string.IsNullOrEmpty(tblCard.CardNumber)) || (string.IsNullOrWhiteSpace(tblCard.CardNumber)))
            {
                if ((string.IsNullOrEmpty(tblCard.CardNo) || string.IsNullOrWhiteSpace(tblCard.CardNo)))
                {
                    ModelState.AddModelError("", "Hãy nhập lại mã thẻ");
                }
                if ((string.IsNullOrWhiteSpace(tblCard.CardNumber) || string.IsNullOrEmpty(tblCard.CardNumber)))
                {
                    ModelState.AddModelError("", "Hãy nhập lại Số thẻ ");
                }
                if (string.IsNullOrWhiteSpace(tblCard.CardNumber))
                {
                    ModelState.AddModelError("", "NHập lại ID ");
                }
                return(View(tblCard));
            }

            // check mã thẻ có tồn tại k
            var cardNumber = _itblCardService.GetByCardNumber(tblCard.CardNumber.Trim());

            if (cardNumber != null)
            {
                ModelState.AddModelError("CardNumber", "mã thẻ đã tồn tại");
                return(View(tblCard));
            }

            // map
            var map = new tblCard()
            {
                CardID      = Guid.NewGuid(),
                CardNo      = tblCard.CardNo,
                CardNumber  = tblCard.CardNumber.Trim(),
                CardGroupID = tblCard.CardGroupID,

                CustomerID = GetOrSetCustomer(tblCard, FileUpload),



                AccessLevelID    = "",
                ChkRelease       = false,
                ImportDate       = DateTime.Now,
                DateRegister     = Convert.ToDateTime(tblCard.DtpDateRegisted),
                DateRelease      = Convert.ToDateTime(tblCard.DtpDateReleased),
                ExpireDate       = Convert.ToDateTime(tblCard.DtpDateExpired),
                DateActive       = Convert.ToDateTime(tblCard.DtpDateActive),
                Description      = !string.IsNullOrWhiteSpace(tblCard.CardDescription) ? tblCard.CardDescription : "",
                IsDelete         = false,
                IsLock           = tblCard.CardInActive,
                Plate1           = tblCard.Plate1,
                Plate2           = tblCard.Plate2,
                Plate3           = tblCard.Plate3,
                VehicleName1     = tblCard.VehicleName1,
                VehicleName2     = tblCard.VehicleName2,
                VehicleName3     = tblCard.VehicleName3,
                DVT              = tblCard.DVT,
                AccessExpireDate = Convert.ToDateTime("2099/12/31"),
                DateCancel       = DateTime.Now,

                isAutoCapture = tblCard.IsAutoCapture
            };

            //thực hiện thêm mới
            var result = _itblCardService.Create(map);

            if (result.isSuccess)
            {
                return(RedirectToAction("Index", new { key = key, cardgroups = cardgroups, customergroups = customergroups, fromdate = fromdate, todate = todate, active = active, isCheckByTime = isCheckByTime, selectedId = tblCard.CardID }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(tblCard));
            }
        }