Пример #1
0
        public ActionResult Edit(DataGPS model)
        {
            if (ModelState.IsValid)
            {
                if (RepoDataGps.IsBoxExist(model.IdDataTruck.Value, model.Id))
                {
                    ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang gps, harap ganti dengan truck yang lain");
                    return(View("Form", model));
                }
                Context.DataGPS dbitem = RepoDataGps.FindByPK(model.Id);
                model.SetDb(dbitem);
                Context.DataGPSHistory dbitemHistory = new Context.DataGPSHistory();
                model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                dbitem.DataGPSHistory.Add(dbitemHistory);
                Context.DataTruckGPSHistory dbtruckHistory = new Context.DataTruckGPSHistory();
                model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                RepoDataGps.save(dbitem, UserPrincipal.id, dbitemHistory);

                Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value);
                dbtruck.DataTruckGPSHistory.Add(dbtruckHistory);
                RepoDataTruck.save(dbtruck, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Пример #2
0
 public void SetDbHistory(Context.DataGPSHistory dbitem, string user)
 {
     dbitem.NoGPS          = NoGPS;
     dbitem.Vehicle        = VehicleNo;
     dbitem.strVendor      = Vendor;
     dbitem.ModelGps       = ModelGps;
     dbitem.NoDevice       = NoDevice;
     dbitem.SensorSuhu     = SensorSuhu;
     dbitem.SensorPintu    = SensorPintu;
     dbitem.Tahun          = Tahun;
     dbitem.TanggalPasang  = TanggalPasang;
     dbitem.TanggalGaransi = TanggalGaransi;
     dbitem.Tanggal        = DateTime.Now;
     dbitem.Username       = user;
 }
Пример #3
0
 public DataGPS(Context.DataGPSHistory dbitem)
 {
     Id             = dbitem.Id;
     NoGPS          = dbitem.DataGPS.NoGPS;
     VehicleNo      = dbitem.Vehicle;
     Vendor         = dbitem.strVendor;
     ModelGps       = dbitem.ModelGps;
     NoDevice       = dbitem.NoDevice;
     SensorSuhu     = dbitem.SensorSuhu;
     SensorPintu    = dbitem.SensorPintu;
     Tahun          = dbitem.Tahun;
     TanggalPasang  = dbitem.TanggalPasang;
     TanggalGaransi = dbitem.TanggalGaransi;
     Tanggal        = dbitem.Tanggal;
     username       = dbitem.Username;
 }
Пример #4
0
        public ActionResult Add(DataGPS model)
        {
            if (ModelState.IsValid)
            {
                if (RepoDataGps.IsBoxExist(model.IdDataTruck.Value))
                {
                    ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang gps, harap ganti dengan truck yang lain");
                    return(View("Form", model));
                }
                Context.DataGPS dbitem = new Context.DataGPS();
                model.SetDb(dbitem);
                //generate code
                dbitem.urutan = RepoDataGps.getUrutan() + 1;
                dbitem.NoGPS  = RepoDataGps.generateCode(dbitem.urutan);

                Context.DataGPSHistory dbitemHistory = new Context.DataGPSHistory();
                model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                dbitemHistory.Vehicle   = RepoDataTruck.FindByPK(dbitem.IdDataTruck.Value).VehicleNo;
                dbitemHistory.NoGPS     = dbitem.NoGPS;
                dbitemHistory.strVendor = dbitem.IdVendor.HasValue ? RepoVendorGPS.FindByPK(dbitem.IdVendor.Value).Nama : "";
                dbitem.DataGPSHistory.Add(dbitemHistory);
                Context.DataTruckGPSHistory dbtruckHistory = new Context.DataTruckGPSHistory();
                model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname);
                RepoDataGps.save(dbitem, UserPrincipal.id, dbitemHistory);

                Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value);
                dbtruckHistory.Vehicle   = dbtruck.VehicleNo;
                dbtruckHistory.NoGPS     = dbitem.NoGPS;
                dbtruckHistory.strVendor = dbitem.IdVendor.HasValue ? RepoVendorGPS.FindByPK(dbitem.IdVendor.Value).Nama : "";
                dbtruck.DataTruckGPSHistory.Add(dbtruckHistory);
                RepoDataTruck.save(dbtruck, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            return(View("Form", model));
        }
Пример #5
0
        public string UploadDataGPS(IEnumerable <HttpPostedFileBase> filesDataGPS)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesDataGPS != null)
            {
                foreach (var file in filesDataGPS)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfRow      = workSheet.Dimension.End.Row;

                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null /*&& workSheet.Cells[rowIterator, 2].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 3].Value != null && workSheet.Cells[rowIterator, 4].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 5].Value != null && workSheet.Cells[rowIterator, 6].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 7].Value != null && workSheet.Cells[rowIterator, 8].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 9].Value != null*/)
                                {
                                    int id = 0;
                                    int resId;
                                    if (workSheet.Cells[rowIterator, 10].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 10].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }

                                    Context.DataGPS dbitem = new Context.DataGPS();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoDataGps.FindByPK(id);
                                            if (RepoDataGps.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id, id))
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (RepoDataGps.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id))
                                            {
                                                continue;
                                            }
                                            dbitem.urutan = RepoDataGps.getUrutan() + 1;
                                            dbitem.NoGPS  = RepoDataGps.generateCode(dbitem.urutan);
                                        }
                                        dbitem.IdDataTruck    = RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;
                                        dbitem.IdVendor       = workSheet.Cells[rowIterator, 2].Value == null ? (int?)null : RepoVendorGPS.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        dbitem.ModelGps       = workSheet.Cells[rowIterator, 3].Value == null ? null : workSheet.Cells[rowIterator, 3].Value.ToString();
                                        dbitem.NoDevice       = workSheet.Cells[rowIterator, 4].Value == null ? null : workSheet.Cells[rowIterator, 4].Value.ToString();
                                        dbitem.SensorSuhu     = workSheet.Cells[rowIterator, 5].Value == null ? (bool?)null : bool.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        dbitem.SensorPintu    = workSheet.Cells[rowIterator, 6].Value == null ? (bool?)null : bool.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        dbitem.Tahun          = workSheet.Cells[rowIterator, 7].Value == null ? (int?)null : int.Parse(workSheet.Cells[rowIterator, 7].Value.ToString());
                                        dbitem.TanggalPasang  = workSheet.Cells[rowIterator, 8].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 8].Value.ToString());
                                        dbitem.TanggalGaransi = workSheet.Cells[rowIterator, 9].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 9].Value.ToString());

                                        //history
                                        Context.DataGPSHistory dbhistory = new Context.DataGPSHistory();
                                        dbhistory.NoGPS          = dbitem.NoGPS;
                                        dbhistory.Vehicle        = workSheet.Cells[rowIterator, 1].Value == null ? null : workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbhistory.strVendor      = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbhistory.ModelGps       = dbitem.ModelGps;
                                        dbhistory.NoDevice       = dbitem.NoDevice;
                                        dbhistory.SensorSuhu     = dbitem.SensorSuhu;
                                        dbhistory.SensorPintu    = dbitem.SensorPintu;
                                        dbhistory.Tahun          = dbitem.Tahun;
                                        dbhistory.TanggalPasang  = dbitem.TanggalPasang;
                                        dbhistory.TanggalGaransi = dbitem.TanggalGaransi;
                                        dbhistory.Tanggal        = DateTime.Now;
                                        dbhistory.Username       = UserPrincipal.firstname + " " + UserPrincipal.lastname;


                                        dbitem.DataGPSHistory.Add(dbhistory);

                                        RepoDataGps.save(dbitem, UserPrincipal.id, dbhistory);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }