Пример #1
0
        public string OnDutyDetail(string VehicleNo, string NoSo)
        {
            Context.DataTruck item = RepoDataTruck.FindByName(VehicleNo);
            UnitList          unit = new UnitList(item);

            Context.MonitoringDetailSo mon_so = RepoMonitoringVehicle.FindMonitoringDetailSo(NoSo);

            return(new JavaScriptSerializer().Serialize(new { unit = unit, Delay = mon_so.TglTiba - mon_so.TargetTiba }));
        }
        public string UploadDataPendingin(IEnumerable <HttpPostedFileBase> filesDataPendingin)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesDataPendingin != null)
            {
                foreach (var file in filesDataPendingin)
                {
                    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.DataPendingin dbitem = new Context.DataPendingin();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoPendingin.FindByPK(id);
                                            if (RepoPendingin.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id, id))
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (RepoPendingin.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id))
                                            {
                                                continue;
                                            }
                                            dbitem.Urutan      = RepoPendingin.getUrutan() + 1;
                                            dbitem.NoPendingin = RepoPendingin.generateCode(dbitem.Urutan);
                                        }

                                        dbitem.IdDataTruk       = RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;
                                        dbitem.Merk             = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Model            = workSheet.Cells[rowIterator, 3].Value == null ? null : workSheet.Cells[rowIterator, 3].Value.ToString();
                                        dbitem.HmLimit          = workSheet.Cells[rowIterator, 4].Value == null ? null : workSheet.Cells[rowIterator, 4].Value.ToString();
                                        dbitem.Tahun            = workSheet.Cells[rowIterator, 5].Value == null ? (int?)null : int.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        dbitem.IdJenisPendingin = workSheet.Cells[rowIterator, 6].Value == null ? (int?)null : LookupCode.FindByName(workSheet.Cells[rowIterator, 6].Value.ToString()).Id;
                                        dbitem.NoMesin          = workSheet.Cells[rowIterator, 7].Value == null ? null : workSheet.Cells[rowIterator, 7].Value.ToString();
                                        dbitem.NoKompresor      = workSheet.Cells[rowIterator, 8].Value == null ? null : workSheet.Cells[rowIterator, 8].Value.ToString();

                                        //history
                                        Context.DataPendinginHistory dbhistory = new Context.DataPendinginHistory();
                                        dbhistory.Id                = dbitem.Id;
                                        dbhistory.Tanggal           = DateTime.Now;
                                        dbhistory.user              = UserPrincipal.firstname + " " + UserPrincipal.lastname;
                                        dbhistory.strDataTruk       = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbhistory.Merk              = dbitem.Merk;
                                        dbhistory.Model             = dbitem.Model;
                                        dbhistory.HmLimit           = dbitem.HmLimit;
                                        dbhistory.Tahun             = Convert.ToInt32(dbitem.Tahun);
                                        dbhistory.strJenisPendingin = workSheet.Cells[rowIterator, 6].Value == null ? null : workSheet.Cells[rowIterator, 6].Value.ToString();
                                        dbhistory.NoMesin           = dbitem.NoMesin;
                                        dbhistory.NoKompresor       = dbitem.NoKompresor;
                                        dbhistory.tglPasang         = Convert.ToDateTime(dbitem.tglPasang);
                                        dbitem.ListHistoryPendingin.Add(dbhistory);

                                        RepoPendingin.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 }));
        }
        public string Upload(IEnumerable <HttpPostedFileBase> filesPenetapanDriver)
        {
            ResponeModel response = new ResponeModel();


            if (filesPenetapanDriver != null)
            {
                foreach (var file in filesPenetapanDriver)
                {
                    try
                    {
                        using (var package = new ExcelPackage(file.InputStream))
                        {
                            var currentSheet = package.Workbook.Worksheets;
                            var workSheet    = currentSheet.First();
                            var noOfCol      = workSheet.Dimension.End.Column;
                            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 && RepoTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()) != 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.PenetapanDriver db = new Context.PenetapanDriver();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            db = RepoPenetapanDriver.FindByPK(id);
                                        }
                                        Context.Driver dr1 = RepoDriver.FindByCode(workSheet.Cells[rowIterator, 2].Value.ToString());
                                        Context.Driver dr2 = workSheet.Cells[rowIterator, 6].Value == null ? null : RepoDriver.FindByCode(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        db.IdDataTruck = RepoTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;

                                        if (id == 0 && RepoPenetapanDriver.IsExist(db.IdDataTruck.Value))
                                        {
                                            continue;
                                        }

                                        if (dr1 != null)
                                        {
                                            if (RepoPenetapanDriver.isExistDriver(dr1.Id, id))
                                            {
                                                continue;
                                            }
                                        }

                                        if (dr2 != null)
                                        {
                                            if (RepoPenetapanDriver.isExistDriver(dr2.Id, id))
                                            {
                                                continue;
                                            }
                                        }

                                        if (dr1 != null && dr2 != null)
                                        {
                                            if (dr2.Id.Equals(dr1.Id))
                                            {
                                                continue;
                                            }
                                        }

                                        db.IdDriver1       = dr1.Id;
                                        db.NoHp1Driver1    = workSheet.Cells[rowIterator, 3].Value == null ? dr1.NoHp1 : workSheet.Cells[rowIterator, 3].Value.ToString();
                                        db.NoHp2Driver1    = workSheet.Cells[rowIterator, 4].Value == null ? dr1.NoHp2 : workSheet.Cells[rowIterator, 4].Value.ToString();
                                        db.DitetapkanOleh1 = workSheet.Cells[rowIterator, 5].Value == null ? null : workSheet.Cells[rowIterator, 5].Value.ToString();

                                        if (dr2 != null)
                                        {
                                            db.IdDriver2       = dr2.Id;
                                            db.NoHp1Driver2    = workSheet.Cells[rowIterator, 7].Value == null ? dr2.NoHp1 : workSheet.Cells[rowIterator, 7].Value.ToString();
                                            db.NoHp2Driver2    = workSheet.Cells[rowIterator, 8].Value == null ? dr2.NoHp2 : workSheet.Cells[rowIterator, 8].Value.ToString();
                                            db.DitetapkanOleh2 = workSheet.Cells[rowIterator, 9].Value == null ? null : workSheet.Cells[rowIterator, 9].Value.ToString();
                                            dr2.NoHp1          = db.NoHp1Driver2;
                                            dr2.NoHp2          = db.NoHp2Driver2;
                                        }

                                        db.ModifiedBy   = UserPrincipal.username;
                                        db.ModifiedDate = DateTime.Now;

                                        dr1.NoHp1 = db.NoHp1Driver1;
                                        dr1.NoHp2 = db.NoHp2Driver1;

                                        RepoPenetapanDriver.save(db);

                                        int resultId = db.Id;

                                        //save penetapan driver history
                                        Context.PenetapanDriverHistory dbItemHistory = new Context.PenetapanDriverHistory();
                                        Context.PenetapanDriver        pd            = RepoPenetapanDriver.FindByPK(resultId);

                                        dbItemHistory.IdPenetapanDriver = resultId;
                                        dbItemHistory.Driver1           = dr1.NamaDriver;
                                        if (dr2 != null)
                                        {
                                            dbItemHistory.Driver2 = dr2.NamaDriver;
                                        }
                                        dbItemHistory.CreatedBy    = UserPrincipal.firstname + " " + UserPrincipal.lastname;
                                        dbItemHistory.ModifiedBy   = UserPrincipal.firstname + " " + UserPrincipal.lastname;
                                        dbItemHistory.ModifiedDate = DateTime.Now;
                                        pd.PenetapanDriverHistory.Add(dbItemHistory);

                                        //history driver

                                        Context.DriverTruckHistory dbdriverHistory1 = new Context.DriverTruckHistory();
                                        Context.DriverTruckHistory dbdriverHistory2 = new Context.DriverTruckHistory();
                                        Context.DataTruck          dbtruck          = RepoTruck.FindByPK(db.IdDataTruck.Value);

                                        dbdriverHistory1.Tanggal = DateTime.Now;
                                        dbdriverHistory1.Nopol   = dbtruck.VehicleNo;
                                        dbdriverHistory1.Type    = dbtruck.JenisTrucks.StrJenisTruck;

                                        dbdriverHistory2.Tanggal = DateTime.Now;
                                        dbdriverHistory2.Nopol   = dbtruck.VehicleNo;
                                        dbdriverHistory2.Type    = dbtruck.JenisTrucks.StrJenisTruck;

                                        dr1.DriverTruckHistory.Add(dbdriverHistory1);

                                        RepoDriver.save(dr1);
                                        string query = "UPDATE dbo.\"Driver\" SET \"NoHp1\" = " + dr1.NoHp1 + ", \"NoHp2\" = " + dr1.NoHp2 + " WHERE \"Id\" = " + dr1.Id + ";INSERT INTO dbo.\"DriverTruckHistory\" ( " +
                                                       "\"IdDriver\", \"Tanggal\", \"Type\", \"Nopol\") VALUES (" + dbdriverHistory1.IdDriver + ", " + dbdriverHistory1.Tanggal + ", " + dbdriverHistory1.Type + ", " +
                                                       dbdriverHistory1.Nopol + ");";
                                        RepoAuditrail.SetAuditTrail(query, "Penetapan Driver", "Import", UserPrincipal.id);
                                        if (dr2 != null)
                                        {
                                            dr2.NoHp1 = db.NoHp1Driver2;
                                            dr2.NoHp2 = db.NoHp2Driver2;
                                            dr2.DriverTruckHistory.Add(dbdriverHistory2);
                                            RepoDriver.save(dr2);
                                            query = "UPDATE dbo.\"Driver\" SET \"NoHp1\" = " + dr2.NoHp1 + ", \"NoHp2\" = " + dr2.NoHp2 + " WHERE \"Id\" = " + dr2.Id + ";INSERT INTO dbo.\"DriverTruckHistory\" ( " +
                                                    "\"IdDriver\", \"Tanggal\", \"Type\", \"Nopol\") VALUES (" + dbdriverHistory2.IdDriver + ", " + dbdriverHistory2.Tanggal + ", " + dbdriverHistory2.Type + ", " +
                                                    dbdriverHistory2.Nopol + ");";
                                            RepoAuditrail.SetAuditTrail(query, "Penetapan Driver", "Import", UserPrincipal.id);
                                        }
                                        RepoPenetapanDriver.save(pd);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }

                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }
            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Пример #4
0
        public string UploadDataBox(IEnumerable <HttpPostedFileBase> filesDataBox)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesDataBox != null)
            {
                foreach (var file in filesDataBox)
                {
                    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 && workSheet.Cells[rowIterator, 10].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 11].Value != null && workSheet.Cells[rowIterator, 12].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 13].Value != null && workSheet.Cells[rowIterator, 14].Value != null &&
                                                                                   * workSheet.Cells[rowIterator, 15].Value != null && workSheet.Cells[rowIterator, 16].Value != null*/)
                                {
                                    int id = 0;
                                    int resId;
                                    int temprow = rowIterator;
                                    if (workSheet.Cells[rowIterator, 17].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 17].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }

                                    Context.DataBox dbitem = new Context.DataBox();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            if (RepoDataBox.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id, id))
                                            {
                                                continue;
                                            }
                                            dbitem = RepoDataBox.FindByPK(id);
                                            dbitem.DataBoxLantai.Clear();
                                            dbitem.DataBoxDinding.Clear();
                                        }
                                        else
                                        {
                                            if (RepoDataBox.IsBoxExist(RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id))
                                            {
                                                continue;
                                            }
                                            dbitem.Urutan = RepoDataBox.getUrutan() + 1;
                                            dbitem.NoBox  = RepoDataBox.generateCode(dbitem.Urutan);
                                        }
                                        dbitem.IdDataTruck  = RepoDataTruck.FindByName(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;
                                        dbitem.Karoseri     = workSheet.Cells[rowIterator, 2].Value == null ? null : workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Tahun        = workSheet.Cells[rowIterator, 3].Value == null ? (int?)null : int.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.IdType       = workSheet.Cells[rowIterator, 4].Value == null ? (int?)null : RepoLookup.FindByName(workSheet.Cells[rowIterator, 4].Value.ToString()).Id;
                                        dbitem.IdKategori   = workSheet.Cells[rowIterator, 5].Value == null ? (int?)null : RepoLookup.FindByName(workSheet.Cells[rowIterator, 5].Value.ToString()).Id;
                                        dbitem.tglPasang    = workSheet.Cells[rowIterator, 6].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        dbitem.Lantai       = workSheet.Cells[rowIterator, 7].Value == null ? null : workSheet.Cells[rowIterator, 7].Value.ToString();
                                        dbitem.Dinding      = workSheet.Cells[rowIterator, 9].Value == null ? null : workSheet.Cells[rowIterator, 9].Value.ToString();
                                        dbitem.PintuSamping = workSheet.Cells[rowIterator, 11].Value == null ? (bool?)null : bool.Parse(workSheet.Cells[rowIterator, 11].Value.ToString());
                                        dbitem.Sekat        = workSheet.Cells[rowIterator, 12].Value == null ? (bool?)null : bool.Parse(workSheet.Cells[rowIterator, 12].Value.ToString());
                                        dbitem.garansiStr   = workSheet.Cells[rowIterator, 13].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 13].Value.ToString());
                                        dbitem.garansiEnd   = workSheet.Cells[rowIterator, 14].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 14].Value.ToString());
                                        dbitem.asuransiStr  = workSheet.Cells[rowIterator, 15].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 15].Value.ToString());
                                        dbitem.asuransiEnd  = workSheet.Cells[rowIterator, 16].Value == null ? (DateTime?)null : DateTime.Parse(workSheet.Cells[rowIterator, 16].Value.ToString());
                                        //lantai
                                        int idx1 = 0;
                                        for (idx1 = rowIterator; idx1 <= noOfRow; idx1++)
                                        {
                                            if (workSheet.Cells[idx1, 1].Value == null || idx1 == rowIterator)
                                            {
                                                if (workSheet.Cells[idx1, 8].Value != null)
                                                {
                                                    Context.DataBoxLantai item = new Context.DataBoxLantai();
                                                    item.IdLantaiCode = RepoLookup.FindByName(workSheet.Cells[idx1, 8].Value.ToString()).Id;
                                                    dbitem.DataBoxLantai.Add(item);
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        //dinding
                                        int idx2 = 0;
                                        for (idx2 = rowIterator; idx2 <= noOfRow; idx2++)
                                        {
                                            if (workSheet.Cells[idx2, 1].Value == null || idx2 == rowIterator)
                                            {
                                                if (workSheet.Cells[idx2, 10].Value != null)
                                                {
                                                    Context.DataBoxDinding item = new Context.DataBoxDinding();
                                                    item.IdDindingCode = RepoLookup.FindByName(workSheet.Cells[idx2, 10].Value.ToString()).Id;
                                                    dbitem.DataBoxDinding.Add(item);
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }

                                        if (idx1 > idx2)
                                        {
                                            rowIterator = idx1 - 1;
                                        }
                                        else
                                        {
                                            rowIterator = idx2 - 1;
                                        }

                                        //history
                                        Context.DataBoxHistory dbhistory = new Context.DataBoxHistory();
                                        dbhistory.NoBox        = dbitem.NoBox;
                                        dbhistory.Vehicle      = workSheet.Cells[rowIterator, 1].Value == null ? null : workSheet.Cells[temprow, 1].Value.ToString();
                                        dbhistory.Karoseri     = dbitem.Karoseri;
                                        dbhistory.Tahun        = dbitem.Tahun;
                                        dbhistory.strType      = workSheet.Cells[rowIterator, 4].Value == null ? null : workSheet.Cells[temprow, 4].Value.ToString();
                                        dbhistory.strKategori  = workSheet.Cells[rowIterator, 5].Value == null ? null : workSheet.Cells[temprow, 5].Value.ToString();
                                        dbhistory.Lantai       = dbitem.Lantai;
                                        dbhistory.Dinding      = dbitem.Dinding;
                                        dbhistory.PintuSamping = dbitem.PintuSamping;
                                        dbhistory.Sekat        = dbitem.Sekat;
                                        dbhistory.garansiStr   = dbitem.garansiStr;
                                        dbhistory.garansiEnd   = dbitem.garansiEnd;
                                        dbhistory.asuransiStr  = dbitem.asuransiStr;
                                        dbhistory.asuransiEnd  = dbitem.asuransiEnd;
                                        dbhistory.tglPasang    = dbitem.tglPasang;
                                        dbhistory.Tanggal      = DateTime.Now;
                                        dbhistory.username     = UserPrincipal.firstname + " " + UserPrincipal.lastname;

                                        //foreach (LantaiModel item in )
                                        //{
                                        //    if (item.IsSelect)
                                        //    {
                                        //        dbitem.Lantai = dbitem.Lantai + ", " + item.StrLantai;
                                        //    }
                                        //}
                                        //foreach (DindingModel item in ListDinding)
                                        //{
                                        //    if (item.IsSelect)
                                        //    {
                                        //        dbitem.Dinding = dbitem.Dinding + ", " + item.StrDinding;
                                        //    }
                                        //}

                                        dbitem.DataBoxHistory.Add(dbhistory);

                                        RepoDataBox.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 }));
        }
Пример #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 }));
        }