Ejemplo n.º 1
0
        public dynamic Upload(int Id)
        {
            var model = new FPMachine();

            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        model
                    }, JsonRequestBehavior.AllowGet));
                }
                model = _fpMachineService.GetObjectById(Id);
                _fpMachineService.UploadAllUserData(model, true, true, _fpUserService, _fpTemplateService, _employeeService);
            }
            catch (Exception ex)
            {
                LOG.Error("Upload Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public dynamic Insert(FPMachine model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.FPMachine, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        model
                    }, JsonRequestBehavior.AllowGet));
                }

                //model.TimeZone = GeneralFunction.IanaToWindows(model.TimeZone);
                model = _fpMachineService.CreateObject(model, _companyInfoService);
            }
            catch (Exception ex)
            {
                LOG.Error("Insert Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }));
        }
Ejemplo n.º 3
0
        public dynamic CheckSync(int Id)
        {
            FPMachine model = new FPMachine();

            model.Errors = new Dictionary <string, string>();
            try
            {
                model          = _fpMachineService.GetObjectById(Id);
                model.IsInSync = _fpMachineService.IsInSync(model.Id);
            }
            catch (Exception ex)
            {
                LOG.Error("CheckSync", ex);

                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public dynamic Delete(FPMachine model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Delete", Core.Constants.Constant.MenuName.FPMachine, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Delete Record");

                    return(Json(new
                    {
                        model
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpMachineService.GetObjectById(model.Id);
                model = _fpMachineService.SoftDeleteObject(data);
            }

            catch (Exception ex)
            {
                LOG.Error("Delete Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }));
        }
Ejemplo n.º 5
0
        public dynamic UpdateEnable(bool isAutoConnect, FPMachine model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.FPMachine, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        model
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpMachineService.GetObjectById(model.Id);
                data.IsAutoConnect = isAutoConnect;
                model = _fpMachineService.UpdateObject(data, _companyInfoService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }));
        }
Ejemplo n.º 6
0
        public FPMachine ConnectObject(FPMachine fpMachine)
        {
            if (_validator.ValidConnectObject(fpMachine, this))
            {
                if (FPMachines.fpDevices[fpMachine.Id] == null)
                {
                    AddMachine(fpMachine.Id);                                             //FPMachines.fpDevices.Add(fpMachine.Id, new FPDevice.ZKEvents());
                }
                lock (FPMachines.fpDevices[fpMachine.Id]._locker)
                {
                    switch ((Constant.FPCommType)fpMachine.CommType)
                    {
                    case Constant.FPCommType.Ethernet: FPMachines.fpDevices[fpMachine.Id].ConnectIP(fpMachine.EthernetIP, fpMachine.EthernetPort); break;

                    case Constant.FPCommType.Serial: FPMachines.fpDevices[fpMachine.Id].ConnectRS232(fpMachine.SerialPort, fpMachine.SerialBaudRate, fpMachine.MachineNumber); break;

                    default: FPMachines.fpDevices[fpMachine.Id].ConnectUSB(true, fpMachine.MachineNumber); break;
                    }
                    fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id].bIsConnected;

                    if (fpMachine.IsConnected)
                    {
                        fpMachine.MachineNumber = FPMachines.fpDevices[fpMachine.Id].iMachineNumber;
                    }
                    else
                    {
                        //int idwErrorCode = FPMachines.fpDevices[fpMachine.Id].GetLastError();
                        string err = FPMachines.fpDevices[fpMachine.Id].GetLastErrorMsg();
                        fpMachine.Errors.Add("Generic", "Connect Error : " + err);
                    }
                }
                _repository.UpdateObject(fpMachine);
            }
            return(fpMachine);
        }
Ejemplo n.º 7
0
        public HttpResponseMessage GetFPMachine(string name)
        {
            FPMachineRepository fPMachineRepository = new FPMachineRepository(new Domain.Staff.ErpStaffDbContext());
            var fPMachine = fPMachineRepository.GetAllFPMachine()
                            .Where(item => item.Ten_may_tinh == name).FirstOrDefault();

            if (fPMachine == null)
            {
                fPMachine                 = new FPMachine();
                fPMachine.IsDeleted       = false;
                fPMachine.CreatedDate     = DateTime.Now;
                fPMachine.ModifiedDate    = DateTime.Now;
                fPMachine.UpdatedDate     = DateTime.Now;
                fPMachine.Ten_may_tinh    = name;
                fPMachine.Dia_chi_IP      = "192.168.1.201";
                fPMachine.Toc_do_truyen   = "115200";
                fPMachine.Port            = 4370;
                fPMachine.GetDataSchedule = "19:00";
                fPMachine.useurl          = false;

                fPMachineRepository.InsertFPMachine(fPMachine);
            }
            else
            {
                fPMachine.UpdatedDate = DateTime.Now;
                fPMachineRepository.UpdateFPMachine(fPMachine);
            }

            var res = Request.CreateResponse(HttpStatusCode.OK, fPMachine);

            return(res);
        }
Ejemplo n.º 8
0
        public bool ValidSyncObject(FPMachine fpMachine, IFPMachineService _fpMachineService, IFPUserService _fpUserService, IFPTemplateService _fpTemplateService)
        {
            fpMachine.Errors.Clear();
            VIsValidId(fpMachine, _fpMachineService);
            //if (!isValid(fpMachine)) { return false; }

            return(isValid(fpMachine));
        }
Ejemplo n.º 9
0
 public FPMachine VIsNotConnected(FPMachine fpMachine)
 {
     fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id] != null ? FPMachines.fpDevices[fpMachine.Id].bIsConnected : false;
     if (fpMachine.IsConnected)
     {
         fpMachine.Errors.Add("Generic", "Sudah tersambung");
     }
     return(fpMachine);
 }
Ejemplo n.º 10
0
        public FPMachine VIsValidId(FPMachine fpMachine, IFPMachineService _fpMachineService)
        {
            var obj = _fpMachineService.GetQueryable().Where(x => x.Id == fpMachine.Id && !x.IsDeleted).FirstOrDefault();

            if (obj == null)
            {
                fpMachine.Errors.Add("Generic", "Id Tidak valid");
            }
            return(fpMachine);
        }
Ejemplo n.º 11
0
 public bool ValidCreateObject(FPMachine fpMachine, IFPMachineService _fpMachineService, ICompanyInfoService _companyInfoService)
 {
     VHasCompany(fpMachine, _companyInfoService);
     if (!isValid(fpMachine))
     {
         return(false);
     }
     VHasUniqueName(fpMachine, _fpMachineService);
     return(isValid(fpMachine));
 }
Ejemplo n.º 12
0
        public FPMachine VHasCompany(FPMachine fpMachine, ICompanyInfoService _companyInfoService)
        {
            CompanyInfo companyInfo = _companyInfoService.GetObjectById(fpMachine.CompanyInfoId);

            if (companyInfo == null)
            {
                fpMachine.Errors.Add("Generic", "Company Tidak valid");
            }
            return(fpMachine);
        }
Ejemplo n.º 13
0
 public bool ValidRefreshObject(FPMachine fpMachine, IFPMachineService _fpMachineService)
 {
     fpMachine.Errors.Clear();
     VIsValidId(fpMachine, _fpMachineService);
     if (!isValid(fpMachine))
     {
         return(false);
     }
     VIsConnected(fpMachine);
     return(isValid(fpMachine));
 }
Ejemplo n.º 14
0
 public bool ValidUpdateObject(FPMachine fpMachine, IFPMachineService _fpMachineService, ICompanyInfoService _companyInfoService)
 {
     fpMachine.Errors.Clear();
     VIsValidId(fpMachine, _fpMachineService);
     if (!isValid(fpMachine))
     {
         return(false);
     }
     ValidCreateObject(fpMachine, _fpMachineService, _companyInfoService);
     return(isValid(fpMachine));
 }
Ejemplo n.º 15
0
 public bool IsConnected(FPMachine fpMachine)
 {
     if (GetObjectById(fpMachine.Id) != null)
     {
         if (FPMachines.fpDevices[fpMachine.Id] == null)
         {
             AddMachine(fpMachine.Id);                                             //FPMachines.fpDevices.Add(fpMachine.Id, new FPDevice.ZKEvents());
         }
         fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id].bIsConnected;
     }
     return(fpMachine.IsConnected);
 }
Ejemplo n.º 16
0
        //public FPMachine VIsValidMachineNumber(FPMachine fpMachine, IFPMachineService _fpMachineService)
        //{
        //    var obj = _fpMachineService.GetQueryable().Where(x => x.MachineNumber == fpMachine.MachineNumber && !x.IsDeleted && x.Id != fpMachine.Id).FirstOrDefault();
        //    if (obj != null)
        //    {
        //        fpMachine.Errors.Add("MachineNumber", "Tidak boleh ada duplikasi");
        //    }
        //    return fpMachine;
        //}

        public FPMachine VHasUniqueName(FPMachine fpMachine, IFPMachineService _fpMachineService)
        {
            if (String.IsNullOrEmpty(fpMachine.MachineName) || fpMachine.MachineName.Trim() == "")
            {
                fpMachine.Errors.Add("MachineName", "Tidak boleh kosong");
            }
            else if (_fpMachineService.IsNameDuplicated(fpMachine))
            {
                fpMachine.Errors.Add("MachineName", "Tidak boleh ada duplikasi");
            }
            return(fpMachine);
        }
Ejemplo n.º 17
0
        public string PrintError(FPMachine obj)
        {
            string erroroutput = "";
            KeyValuePair <string, string> first = obj.Errors.ElementAt(0);

            erroroutput += first.Key + "," + first.Value;
            foreach (KeyValuePair <string, string> pair in obj.Errors.Skip(1))
            {
                erroroutput += Environment.NewLine;
                erroroutput += pair.Key + "," + pair.Value;
            }
            return(erroroutput);
        }
Ejemplo n.º 18
0
        public dynamic Update(FPMachine model)
        {
            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.FPMachine, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Edit record");

                    return(Json(new
                    {
                        model
                    }, JsonRequestBehavior.AllowGet));
                }

                var data = _fpMachineService.GetObjectById(model.Id);
                data.CompanyInfoId = model.CompanyInfoId;
                data.MachineName   = model.MachineName;
                if (!data.IsConnected)
                {
                    data.MachineNumber = model.MachineNumber;
                }
                data.Password                = model.Password;
                data.CommType                = model.CommType;
                data.EthernetIP              = model.EthernetIP;
                data.EthernetPort            = model.EthernetPort;
                data.SerialPort              = model.SerialPort;
                data.SerialBaudRate          = model.SerialBaudRate;
                data.IsClearLogAfterDownload = model.IsClearLogAfterDownload;
                data.TimeZone                = model.TimeZone; // GeneralFunction.IanaToWindows(model.TimeZone);
                data.TimeZoneOffset          = model.TimeZoneOffset;

                model = _fpMachineService.UpdateObject(data, _companyInfoService);
            }
            catch (Exception ex)
            {
                LOG.Error("Update Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }));
        }
Ejemplo n.º 19
0
 public FPMachine CreateObject(FPMachine fpMachine, ICompanyInfoService _companyInfoService)
 {
     fpMachine.Errors = new Dictionary <String, String>();
     if (_validator.ValidCreateObject(fpMachine, this, _companyInfoService))
     {
         //fpMachine.fpDevice = new FPDevice.ZKEvents();
         _repository.CreateObject(fpMachine);
         if (GetObjectById(fpMachine.Id) != null)
         {
             AddMachine(fpMachine.Id); //FPMachines.fpDevices.Add(fpMachine.Id, new FPDevice.ZKEvents());
         }
     }
     return(fpMachine);
 }
Ejemplo n.º 20
0
        public dynamic Sync(int Id)
        {
            var model = new FPMachine();

            model.Errors = new Dictionary <string, string>();
            try
            {
                if (!AuthenticationModel.IsAllowed("Create", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting))
                {
                    model.Errors.Add("Generic", "You are Not Allowed to Add record");

                    return(Json(new
                    {
                        model
                    }, JsonRequestBehavior.AllowGet));
                }
                model = _fpMachineService.GetObjectById(Id);
                //if (model != null)
                {
                    //lock (FPMachines.fpDevices[model.Id]._locker)
                    //{
                    //    // Upload changed data to Machine
                    //    _fpMachineService.UploadAllUserData(model, false, true, _fpUserService, _fpTemplateService, _employeeService);
                    //    if (!model.Errors.Any())
                    //    {
                    //        // Download all data from Machine
                    //        _fpMachineService.DownloadAllUserData(model, _fpUserService, _fpTemplateService, _employeeService);
                    //    }
                    //}

                    _fpMachineService.SyncObject(model, _fpUserService, _fpTemplateService, _employeeService);
                }
            }
            catch (Exception ex)
            {
                LOG.Error("Sync Failed", ex);
                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 21
0
        public bool IsConnected(int FPMachineId)
        {
            FPMachine fpMachine = GetObjectById(FPMachineId);

            if (fpMachine != null)
            {
                if (FPMachines.fpDevices[FPMachineId] == null)
                {
                    return(false);                                           // FPMachines.fpDevices.Add(FPMachineId, new FPDevice.ZKEvents());
                }
                fpMachine.IsConnected = FPMachines.fpDevices[FPMachineId].bIsConnected;
                return(fpMachine.IsConnected);
            }
            return(false);
        }
Ejemplo n.º 22
0
 public FPMachine UpdateObject(FPMachine fpMachine, ICompanyInfoService _companyInfoService)
 {
     if (_validator.ValidUpdateObject(fpMachine, this, _companyInfoService))
     {
         //if (fpMachine.fpDevice == null) fpMachine.fpDevice = new FPDevice.ZKEvents();
         //if (fpMachine.fpDevice.bIsConnected) fpMachine.fpDevice.Disconnect();
         if (FPMachines.fpDevices[fpMachine.Id] == null)
         {
             AddMachine(fpMachine.Id);                                            //FPMachines.fpDevices.Add(fpMachine.Id, new FPDevice.ZKEvents());
         }
         fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id].bIsConnected; // fpMachine.fpDevice.bIsConnected;
         _repository.UpdateObject(fpMachine);
     }
     return(fpMachine);
 }
Ejemplo n.º 23
0
 public FPMachine DisconnectObject(FPMachine fpMachine)
 {
     if (_validator.ValidDisconnectObject(fpMachine, this))
     {
         fpMachine.IsConnected = false;
         if (FPMachines.fpDevices[fpMachine.Id] != null)
         {
             lock (FPMachines.fpDevices[fpMachine.Id]._locker)
             {
                 FPMachines.fpDevices[fpMachine.Id].Disconnect();
                 fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id].bIsConnected;
             }
         }
         _repository.UpdateObject(fpMachine);
     }
     return(fpMachine);
 }
Ejemplo n.º 24
0
        public ActionResult Create(FPMachineViewModel model)
        {
            if (ModelState.IsValid)
            {
                var FPMachine = new FPMachine();
                AutoMapper.Mapper.Map(model, FPMachine);
                FPMachine.IsDeleted      = false;
                FPMachine.CreatedUserId  = WebSecurity.CurrentUserId;
                FPMachine.ModifiedUserId = WebSecurity.CurrentUserId;
                FPMachine.AssignedUserId = WebSecurity.CurrentUserId;
                FPMachine.CreatedDate    = DateTime.Now;
                FPMachine.ModifiedDate   = DateTime.Now;
                FPMachineRepository.InsertFPMachine(FPMachine);

                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Ejemplo n.º 25
0
        public FPMachine SyncObject(FPMachine fpMachine, IFPUserService _fpUserService, IFPTemplateService _fpTemplateService, IEmployeeService _employeeService)
        {
            if (_validator.ValidSyncObject(fpMachine, this, _fpUserService, _fpTemplateService))
            {
                lock (FPMachines.fpDevices[fpMachine.Id]._locker)
                {
                    // Upload changed data to Machine
                    UploadAllUserData(fpMachine, false, true, _fpUserService, _fpTemplateService, _employeeService);
                    if (!fpMachine.Errors.Any())
                    {
                        // Download all data from Machine
                        DownloadAllUserData(fpMachine, _fpUserService, _fpTemplateService, _employeeService);
                    }
                }

                //fpMachine.IsInSync = true;
                //_repository.UpdateObject(fpMachine);
            }
            return(fpMachine);
        }
Ejemplo n.º 26
0
        public dynamic GetInfo(int Id)
        {
            FPMachine model = new FPMachine();

            model.Errors = new Dictionary <string, string>();
            try
            {
                model = _fpMachineService.GetObjectById(Id);
            }
            catch (Exception ex)
            {
                LOG.Error("GetInfo", ex);

                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model.Id,
                model.CompanyInfoId,
                CompanyInfo = model.CompanyInfo != null ? model.CompanyInfo.Name : "",
                model.MachineNumber,
                model.MachineName,
                model.Password,
                model.IsAutoConnect,
                model.IsClearLogAfterDownload,
                model.CommType,
                model.EthernetIP,
                model.EthernetPort,
                model.SerialPort,
                model.SerialBaudRate,
                model.TimeZone,
                model.TimeZoneOffset,
                model.Errors
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 27
0
        public dynamic Connect(int Id)
        {
            FPMachine model = new FPMachine();

            model.Errors = new Dictionary <string, string>();
            try
            {
                model = _fpMachineService.GetObjectById(Id);
                if (FPMachines.fpDevices[model.Id] == null)
                {
                    _fpMachineService.AddMachine(model.Id);
                    FPMachines.fpDevices[model.Id].OnAttTransactionEx = OnAttTransactionEx;
                    FPMachines.fpDevices[model.Id].OnDeleteTemplate   = OnDeleteTemplate;
                    FPMachines.fpDevices[model.Id].OnEnrollFinger     = OnEnrollFinger;
                    FPMachines.fpDevices[model.Id].OnConnected        = OnConnected;
                    FPMachines.fpDevices[model.Id].OnDisConnected     = OnDisConnected;
                    FPMachines.fpDevices[model.Id].OnEMData           = OnEMData;
                }
                model = _fpMachineService.ConnectObject(model);
            }
            catch (Exception ex)
            {
                LOG.Error("Connect", ex);

                model.Errors.Add("Generic", "Error " + ex);

                return(Json(new
                {
                    model
                }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new
            {
                model
            }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 28
0
 public FPMachine SoftDeleteObject(FPMachine fpMachine)
 {
     if (_validator.ValidDeleteObject(fpMachine, this))
     {
         fpMachine.IsConnected = false;
         if (FPMachines.fpDevices[fpMachine.Id] != null) // (fpMachine.fpDevice != null)
         {
             lock (FPMachines.fpDevices[fpMachine.Id]._locker)
             {
                 if (FPMachines.fpDevices[fpMachine.Id].bIsConnected)
                 {
                     FPMachines.fpDevices[fpMachine.Id].Disconnect();
                 }
                 fpMachine.IsConnected = FPMachines.fpDevices[fpMachine.Id].bIsConnected;
                 FPMachines.fpDevices[fpMachine.Id].bIsDestroying = true;
             }
             FPMachines.fpDevices[fpMachine.Id].Dispose();
             FPMachines.fpDevices[fpMachine.Id] = null;
             FPMachines.fpDevices.Remove(fpMachine.Id);
         }
         _repository.SoftDeleteObject(fpMachine);
     }
     return(fpMachine);
 }
Ejemplo n.º 29
0
        public bool isValid(FPMachine obj)
        {
            bool isValid = !obj.Errors.Any();

            return(isValid);
        }
Ejemplo n.º 30
0
 public bool ValidDeleteObject(FPMachine fpMachine, IFPMachineService _fpMachineService)
 {
     fpMachine.Errors.Clear();
     VIsValidId(fpMachine, _fpMachineService);
     return(isValid(fpMachine));
 }