Beispiel #1
0
        public ActionResult Index(string key, string cardgroupids, string customergroupids, string userids, string fromdate, string todate, int page = 1, string chkExport = "0")
        {
            var Dictionary = FunctionHelper.GetLocalizeDictionary("ActiveCardList", "Index");

            if (string.IsNullOrWhiteSpace(fromdate))
            {
                fromdate = DateTime.Now.ToString("dd/MM/yyyy 00:00:00");
            }

            if (string.IsNullOrWhiteSpace(todate))
            {
                todate = DateTime.Now.ToString("dd/MM/yyyy 23:59:59");
            }

            if (chkExport == "1")
            {
                var listExcel = _tblActiveCardService.ReportAllByFirst(key, "", fromdate, todate, cardgroupids, customergroupids, userids);

                //Xuất file theo format
                PK_ActiveCardListFormatCell(listExcel, Dictionary["TitleEx"], "Sheet1", "", Dictionary["Title"], fromdate + " - " + todate);

                return(RedirectToAction("Index"));
            }

            int pageSize = 20;

            var list = _tblActiveCardService.GetAllPagingByFirst(key, "", fromdate, todate, cardgroupids, customergroupids, userids, page, pageSize);

            if (list.Any())
            {
                var strCustomer = new List <string>();
                foreach (var item in list)
                {
                    strCustomer.Add(item.CustomerID);
                }

                ViewBag.CustomerList = _tblCustomerService.GetAllByListId(strCustomer).ToList();
            }

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

            //
            ViewBag.keyValue              = key;
            ViewBag.cardgroupidsValue     = cardgroupids;
            ViewBag.customergroupidsValue = customergroupids;
            ViewBag.usersValue            = userids;
            ViewBag.fromdateValue         = fromdate;
            ViewBag.todateValue           = todate;

            //
            ViewBag.cardgroups     = GetListCardGroup().ToDataTableNullable();
            ViewBag.users          = GetListUser().ToDataTableNullable();
            ViewBag.customergroups = GetMenuList();

            return(View(gridModel));
        }
        public JsonResult GetListCardWantToUse(SelectListModelCardUpload obj)
        {
            var totalPage = 0;
            var totalItem = 0;
            var pageSize  = 0;

            var dtg = new List <AccessUploadMultiDevice>();

            //Lấy người dùng hiện tại
            var user = GetCurrentUser.GetUser();

            var model = new SelectListModelCardUploadReturn();

            model.ListSelfHost   = GetSetFromSessionSelfHost(null);
            model.ListController = GetSetFromSessionController(null);


            if (obj.isall)
            {
                var customergroups = GetListChild("", obj.customergroupid);

                var list      = _tblCardService.GetAllPagingByFirstForUpload(obj.key, "", obj.cardgroupids, customergroups, "", "", obj.pageIndex, obj.pageSize, obj.accesslevelids, "", "");
                var gridModel = PageModelCustom <tblCardExtend> .GetPage(list, obj.pageIndex, obj.pageSize);

                totalPage = gridModel.TotalPage;
                totalItem = gridModel.TotalItem;
                pageSize  = gridModel.PageSize;

                model.ListCard = gridModel.Data.ToList();
            }
            else
            {
                model.ListCard = GetSetFromSessionCard(null);

                model.ListCard = _tblCardService.GetAllByFirst_v2(model.ListCard);
            }

            var listCustomerId = new List <string>();

            foreach (var item in model.ListCard)
            {
                if (!string.IsNullOrWhiteSpace(item.CustomerId))
                {
                    listCustomerId.Add(item.CustomerId);
                }
            }

            //Danh sách khách hàng
            var ListCustomer = _tblCustomerService.GetAllByListId(listCustomerId);

            if (model.ListCard.Any())
            {
                foreach (var item in model.ListSelfHost)
                {
                    var ko = new AccessUploadMultiDevice()
                    {
                        Address   = item.Address,
                        pageIndex = obj.pageIndex,
                        totalPage = totalPage,
                        totalItem = totalItem,
                        pageSize  = pageSize
                    };

                    var lines = _tblAccessLineService.GetAllActiveByListPC(item.PCID);

                    var ControllerByPC = model.ListController.Where(n => lines.Any(m => m.LineID.ToString() == n.LineID)).ToList();

                    model.ListEmployee = new List <Employee>();

                    //
                    ko.totalItem       = ko.totalItem * ControllerByPC.Count;
                    ko.totalController = ControllerByPC.Count;

                    foreach (var itemCard in model.ListCard)
                    {
                        foreach (var itemController in ControllerByPC)
                        {
                            var map = new Employee();

                            map.CardNumber = itemCard.CardNumber.Trim();

                            map.AccessLevelID = itemCard.AccessLevelID.Trim();

                            map.ControllerIDs = itemController.ControllerID.ToString();

                            map.UserID = user.Id;

                            //Lấy khách hàng
                            if (!string.IsNullOrWhiteSpace(itemCard.CustomerId))
                            {
                                var objCustomer = ListCustomer.FirstOrDefault(n => n.CustomerID.ToString() == itemCard.CustomerId);
                                if (objCustomer != null)
                                {
                                    map.UserIDofFinger = objCustomer.UserIDofFinger;

                                    map.Passwords = objCustomer.Password;
                                }
                                else
                                {
                                    map.UserIDofFinger = 0;

                                    map.Passwords = "";
                                }
                            }
                            else
                            {
                                map.UserIDofFinger = 0;

                                map.Passwords = "";
                            }

                            if (obj.isusenewdate)
                            {
                                map.ExpireDate = Convert.ToDateTime(obj.newdateexpire).ToString("yyyyMMdd").Trim();
                            }
                            else
                            {
                                map.ExpireDate = Convert.ToDateTime(itemCard.AccessExpireDate).ToString("yyyyMMdd").Trim();
                            }

                            model.ListEmployee.Add(map);
                        }
                    }

                    ko.DataSend = model.ListEmployee;

                    dtg.Add(ko);
                }
            }

            //var t = new SelectListModelCardUploadReturn2()
            //{
            //    ListEmployee = model.ListEmployee,
            //    ListSelfHost = model.ListSelfHost
            //};

            //var red = JsonConvert.SerializeObject(t);

            var a = new JsonResult {
                Data = dtg, MaxJsonLength = Int32.MaxValue
            };

            return(a);
        }