Exemple #1
0
        public IActionResult Index()
        {
            var model = new DeviceViewModel()
            {
                //Devices = DeviceDB.GetInstance().GetAllDevices(userObj),
                TerminalProtocols  = TerminalProtocolDB.GetInstance().GetAllTerminalProtocols(),
                Gateways           = GatewayDB.GetInstance().GetAllGateways(),
                DeviceMontageTypes = DeviceMontageTypeDB.GetInstance().GetAllDeviceMontageTypes(),
                RefTelemetryTypes  = RefTelemetryTypeDB.GetInstance().GetAllRefTelemetryTypes(),
                ServiceTypes       = ServiceTypeDB.GetInstance().GetAllServiceTypes(),
                TerminalTypes      = TerminalTypeDB.GetInstance().GetAllTerminalTypes(),
                UsingStatus        = UsingStatusDB.GetInstance().GetAllUsingStatuses(),
                Vehicles           = VehicleDB.GetInstance().GetAllVehicles(),
                WocheckerFlags     = WocheckerFlagDB.GetInstance().GetAllWocheckerFlags(),
                Companies          = CompanyDB.GetInstance().GetAllCompaniesForAdminPanel(userObj),
                Messagings         = MessagingDB.GetInstance().GetAllMessagings(),
                CompanyTypes       = CompanyTypeDB.GetInstance().GetAllCompanyTypes()
            };

            return(View(model));
        }
        public JsonResult ImportFile(string _excelData)
        {
            _excelData = HttpUtility.HtmlDecode(_excelData);
            var list2 = JsonConvert.DeserializeObject <List <DeviceExcelObject> >(_excelData);

            try
            {
                foreach (var item in list2)
                {
                    Device device = new Device()
                    {
                        CompanyId                  = CompanyDB.GetInstance().GetCompanyByName(item.Sirket).Id,
                        CarPlateNumber             = item.Plaka,
                        CustomerPlateNumber        = item.MusteriPlakasi,
                        DeviceId                   = item.CihazId,
                        DeviceGsmNumber            = item.CihazGsmNo,
                        IMEINumber                 = item.IMEINo,
                        VehiclePhone               = item.AracTelefonu,
                        AveaPlaka                  = item.AveaPlaka,
                        TerminalProtocolId         = TerminalProtocolDB.GetInstance().GetTerminalProtocolByNameOrInsert(item.TerminalProtokol).Id,
                        GatewayId                  = GatewayDB.GetInstance().GetGatewayByNameOrInsert(item.Gateway).Id,
                        TerminalTypeId             = TerminalTypeDB.GetInstance().GetTerminalTypeByNameOrInsert(item.TerminalTipi).Id,
                        SoftwareVersionId          = SoftwareVersionDB.GetInstance().GetSoftwareVersionByNameOrInsert(item.YazilimVers, TerminalTypeDB.GetInstance().GetTerminalTypeByNameOrInsert(item.TerminalTipi).Id).Id,
                        OdometreStatusId           = OdometreStatusDB.GetInstance().GetOdometreStatusByNameOrInsert(item.OdometreDurumu).Id,
                        ProgrammedLocationSendTime = Convert.ToInt32(item.ProgramlananKonumSuresi.Trim()),
                        ProgrammedLocationDistance = Convert.ToInt32(item.ProgramlananKonumMesafe.Trim()),
                        ProgrammedSpeedLimit       = Convert.ToInt32(item.ProgramlananHizLimiti.Trim()),
                        ProgrammedHeartBeat        = Convert.ToInt32(item.ProgramlananHeartBeat.Trim()),
                        ProgrammedWaitingTime      = Convert.ToInt32(item.ProgramlananBekleme.Trim()),
                        ActivityTime               = Convert.ToInt32(item.AktiflikSuresi.Trim()),
                        Journey          = item.Sefer.Trim() == "Var" ? true : false,
                        MessagingId      = MessagingDB.GetInstance().GetMessagingByNameOrInsert(item.Mesajlasma).Id,
                        Telemetry        = item.Telemetri.Trim() == "Var" ? true : false,
                        HeatSensor       = item.IsiSensoru.Trim() == "Var" ? true : false,
                        DoorSensor       = item.KapiSensoru.Trim() == "Var" ? true : false,
                        ConstantMobile   = item.SabitMobil.Trim() == "Aktif" ? true : false,
                        ConstantLatitude = item.SabitLatitude,
                        //ConstantLongitude= ?????????????????????????????????????????????
                        WocheckerFlagId       = WocheckerFlagDB.GetInstance().GetWocheckerFlagByNameOrInsert(item.WocheckerFlag).Id,
                        MobileNote            = item.MobilNot,
                        TechnicalNote         = item.TeknikNot,
                        MontageDate           = GetExcelDateTime(item.MontajTarihi),
                        MontagePerson         = item.MontajiYapan,
                        DeviceMontageTypeId   = DeviceMontageTypeDB.GetInstance().GetDeviceMontageTypeByNameOrInsert(item.CihazMontajTuru).Id,
                        EngineBlock           = item.MotorBlokaji.Trim() == "Var" ? true : false,
                        EngineBlockStatus     = item.MotorBlokajDurumu.Trim() == "Aktif" ? true : false,
                        GSensor               = item.GSensor.Trim() == "Var" ? true : false,
                        DriverScoring         = item.SurucuSkorlama.Trim() == "Var" ? true : false,
                        RFIDEngineBlock       = item.RFIDMotorBlokaj.Trim() == "Var" ? true : false,
                        RFIDEngineBlockStatus = item.RFIDMotorBlokajDurumu.Trim() == "Aktif" ? true : false,
                        CreationDate          = DateTime.Now,
                        Status = 1
                    };
                    if (device != null)
                    {
                        DeviceDB.GetInstance().AddNewDevice(device);
                    }
                }
                return(Json(true));
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        public JsonResult UploadFile(IFormFile file)
        {
            if (file == null)
            {
                return(Json(false));
            }

            if (file.FileName.EndsWith(".xlsx") || file.FileName.EndsWith(".xls"))
            {
                var fileName = Path.Combine(_env.WebRootPath, "Content", "TempUploads", Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName));

                try
                {
                    using (var fileStream = new FileStream(fileName, FileMode.Create))
                    {
                        var task = file.CopyToAsync(fileStream);
                        task.Wait();
                    }

                    Workbook workbook = new Workbook();
                    workbook.LoadFromFile(fileName);
                    Worksheet sheet = workbook.Worksheets[0];
                    var       dt    = sheet.ExportDataTable();

                    foreach (DataRow dr in dt.Rows)
                    {
                        var company             = dr["Şirket"].ToString().Trim();
                        var carPlateNumber      = dr["Plaka"].ToString().Trim();
                        var customerPlateNumber = dr["Müşteri Plakası"].ToString().Trim();
                        var deviceId            = dr["Cihaz ID (Comm_id)"].ToString().Trim();
                        var deviceGsmNumber     = dr["Cihaz Gsm No"].ToString().Trim();
                        var imei                       = dr["IMEI No"].ToString().Trim();
                        var carPhoneNumber             = dr["Araç Telefonu"].ToString().Trim();
                        var aveaPlaka                  = dr["Avea Plaka"].ToString().Trim();
                        var terminalProtocol           = dr["Terminal Protokol"].ToString().Trim();
                        var gateway                    = dr["Gateway"].ToString().Trim();
                        var terminalType               = dr["Terminal Tipi"].ToString().Trim();
                        var odometreStatus             = dr["Odometre Durumu"].ToString().Trim();
                        var softwareVersion            = dr["Yazılım Ver."].ToString().Trim();
                        var programmedLocationSendTime = dr["Programlanan Konum Süresi(dk)"].ToString().Trim();
                        var programmedLocationDistance = dr["Programlanan Konum Mesafe(mt)"].ToString().Trim();
                        var programmedSpeedLimit       = dr["Programlanan Hız Limiti(km)"].ToString().Trim();
                        var ProgrammedWaitingTime      = dr["Programlanan Bekleme(dk)"].ToString().Trim();
                        var ProgrammedHeartBeat        = dr["Programlanan HeartBeat(sn)"].ToString().Trim();
                        var activityTime               = dr["Aktiflik Süresi(dk)"].ToString().Trim();
                        var journey                    = dr["Sefer"].ToString().Trim();
                        var messaging                  = dr["Mesajlaşma"].ToString().Trim();
                        var telemetry                  = dr["Telemetri"].ToString().Trim();
                        var heatSensor                 = dr["Isı Sensörü"].ToString().Trim();
                        var doorSensor                 = dr["Kapı Sensörü"].ToString().Trim();
                        var constantMobile             = dr["Sabit Mobil"].ToString().Trim();
                        var lastActivityTime           = dr["Son Aktiflik Zamanı"].ToString().Trim();
                        var constantLatitude           = dr["Sabit Lat. (DD.DDDDDD)"].ToString().Trim();
                        var wocheckerFlag              = dr["WocheckerFlag"].ToString().Trim();
                        var mobileNote                 = dr["Mobil Not"].ToString().Trim();
                        var techinalNote               = dr["Teknik Not"].ToString().Trim();
                        var montageDate                = dr["Montaj Tarihi"].ToString().Trim();
                        var montagePerson              = dr["Montajı Yapan"].ToString().Trim();
                        var deviceMontageType          = dr["Cihaz Montaj Türü"].ToString().Trim();
                        var engineBlock                = dr["Motor Blokajı"].ToString().Trim();
                        var engineBlockStatus          = dr["Motor Blokaj Durumu"].ToString().Trim();
                        var vehicleBlock               = dr["Araç Blokajı"].ToString().Trim();
                        var refTelemetryType           = dr["Ref. Telemetri Reçetesi"].ToString().Trim();
                        var gSensor                    = dr["G Sensör"].ToString().Trim();
                        var driverScoring              = dr["Sürücü Skorlama"].ToString().Trim();
                        var rfidEngineBlock            = dr["RFID Motor Blokaj"].ToString().Trim();
                        var rfidEngineBlockStatus      = dr["RFID Motor Blokaj Durumu"].ToString().Trim();

                        var device = new Device()
                        {
                            CompanyId                  = CompanyDB.GetInstance().GetCompanyByName(company).Id,
                            CarPlateNumber             = carPlateNumber,
                            CustomerPlateNumber        = customerPlateNumber,
                            DeviceId                   = deviceId,
                            DeviceGsmNumber            = deviceGsmNumber,
                            IMEINumber                 = imei,
                            CarPhoneNumber             = carPhoneNumber,
                            AveaPlaka                  = aveaPlaka,
                            TerminalProtocolId         = TerminalProtocolDB.GetInstance().GetTerminalProtocolByNameOrInsert(terminalProtocol).Id,
                            GatewayId                  = GatewayDB.GetInstance().GetGatewayByNameOrInsert(gateway).Id,
                            TerminalTypeId             = TerminalTypeDB.GetInstance().GetTerminalTypeByNameOrInsert(terminalType).Id,
                            SoftwareVersionId          = SoftwareVersionDB.GetInstance().GetSoftwareVersionByNameOrInsert(softwareVersion, TerminalTypeDB.GetInstance().GetTerminalTypeByNameOrInsert(terminalType).Id).Id,
                            OdometreStatusId           = OdometreStatusDB.GetInstance().GetOdometreStatusByNameOrInsert(odometreStatus).Id,
                            ProgrammedLocationSendTime = Convert.ToInt32(programmedLocationSendTime),
                            ProgrammedLocationDistance = Convert.ToInt32(programmedLocationDistance),
                            ProgrammedSpeedLimit       = Convert.ToInt32(programmedSpeedLimit),
                            ProgrammedWaitingTime      = Convert.ToInt32(ProgrammedWaitingTime),
                            ProgrammedHeartBeat        = Convert.ToInt32(ProgrammedHeartBeat),
                            ActivityTime               = Convert.ToInt32(activityTime),
                            Journey               = journey == "Var" ? true : false,
                            MessagingId           = MessagingDB.GetInstance().GetMessagingByNameOrInsert(messaging).Id,
                            Telemetry             = telemetry == "Var" ? true : false,
                            HeatSensor            = heatSensor == "Var" ? true : false,
                            DoorSensor            = doorSensor == "Var" ? true : false,
                            ConstantMobile        = constantMobile == "Aktif" ? true : false,
                            LastActivityTime      = GetExcelDateTime(lastActivityTime),
                            ConstantLatitude      = constantLatitude,
                            WocheckerFlagId       = WocheckerFlagDB.GetInstance().GetWocheckerFlagByNameOrInsert(wocheckerFlag).Id,
                            MobileNote            = mobileNote,
                            TechnicalNote         = techinalNote,
                            MontageDate           = GetExcelDateTime(montageDate),
                            MontagePerson         = montagePerson,
                            DeviceMontageTypeId   = DeviceMontageTypeDB.GetInstance().GetDeviceMontageTypeByNameOrInsert(deviceMontageType).Id,
                            EngineBlock           = engineBlock == "Var" ? true : false,
                            EngineBlockStatus     = engineBlockStatus == "Aktif" ? true : false,
                            VehicleBlock          = vehicleBlock == "Var" ? true : false,
                            RefTelemetryRecipeId  = RefTelemetryTypeDB.GetInstance().GetRefTelemetryTypeByNameOrInsert(refTelemetryType).Id,
                            GSensor               = gSensor == "Var" ? true : false,
                            DriverScoring         = driverScoring == "Var" ? true : false,
                            RFIDEngineBlock       = rfidEngineBlock == "Var" ? true : false,
                            RFIDEngineBlockStatus = rfidEngineBlockStatus == "Var" ? true : false,
                            CreationDate          = DateTime.Now,
                            Status = 1,
                        };

                        var result = DeviceDB.GetInstance().AddNewDevice(device);
                    }

                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }

                    return(Json(true));
                }
                catch (Exception exc)
                {
                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }

                    return(Json(exc.Message));
                }
            }
            else
            {
                return(Json(false));
            }
        }