public string UploadFaktorBorongan(IEnumerable <HttpPostedFileBase> filesFaktorBorongan)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesFaktorBorongan != null)
            {
                foreach (var file in filesFaktorBorongan)
                {
                    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 &&
                                    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)
                                {
                                    int id = 0;
                                    int resId;
                                    if (workSheet.Cells[rowIterator, 19].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 19].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }
                                    Context.FaktorBorongan dbitem = new Context.FaktorBorongan();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            if (RepoFaktorBorongan.isExist(RepoMasterPool.FindByNamePool(workSheet.Cells[rowIterator, 1].Value.ToString()).Id,
                                                                           RepoJenisTruck.FindByStrJenisTruck(workSheet.Cells[rowIterator, 2].Value.ToString()).Id, id))
                                            {
                                                continue;
                                            }
                                            dbitem = RepoFaktorBorongan.FindByPK(id);
                                        }
                                        else
                                        {
                                            if (RepoFaktorBorongan.isExist(RepoMasterPool.FindByNamePool(workSheet.Cells[rowIterator, 1].Value.ToString()).Id,
                                                                           RepoJenisTruck.FindByStrJenisTruck(workSheet.Cells[rowIterator, 2].Value.ToString()).Id))
                                            {
                                                continue;
                                            }
                                        }
                                        dbitem.IdMasterPool      = RepoMasterPool.FindByNamePool(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;
                                        dbitem.IdJenisTruck      = RepoJenisTruck.FindByStrJenisTruck(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        dbitem.RasioDlmKota      = Decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());
                                        dbitem.RasioDlmKota2     = Decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString());
                                        dbitem.RasioJawaBali     = Decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        dbitem.RasioSumatra      = Decimal.Parse(workSheet.Cells[rowIterator, 6].Value.ToString());
                                        dbitem.RasioKosong       = Decimal.Parse(workSheet.Cells[rowIterator, 7].Value.ToString());
                                        dbitem.UangMakanJawaBali = Decimal.Parse(workSheet.Cells[rowIterator, 8].Value.ToString());
                                        dbitem.UangMakanSumatra  = Decimal.Parse(workSheet.Cells[rowIterator, 9].Value.ToString());
                                        dbitem.FaktorPengaliGaji = Decimal.Parse(workSheet.Cells[rowIterator, 10].Value.ToString());
                                        dbitem.FaktorPengaliTips = Decimal.Parse(workSheet.Cells[rowIterator, 11].Value.ToString());
                                        dbitem.PotonganDriver1   = workSheet.Cells[rowIterator, 12].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 12].Value.ToString());

                                        dbitem.PotonganDriver2 = workSheet.Cells[rowIterator, 13].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 13].Value.ToString());

                                        dbitem.BiayaKapalBali = workSheet.Cells[rowIterator, 14].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 14].Value.ToString());

                                        dbitem.BiayaKapalBaliNTB = workSheet.Cells[rowIterator, 15].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 15].Value.ToString());

                                        dbitem.BiayaKapalSumatra = workSheet.Cells[rowIterator, 16].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 16].Value.ToString());

                                        dbitem.BiayaKapalKalimantan = workSheet.Cells[rowIterator, 17].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 17].Value.ToString());

                                        dbitem.BiayaKapalSulawesi = workSheet.Cells[rowIterator, 18].Value == null?Convert.ToDecimal(null) : Decimal.Parse(workSheet.Cells[rowIterator, 18].Value.ToString());

                                        RepoFaktorBorongan.save(dbitem, UserPrincipal.id, new Context.FaktorBoronganHistory());
                                    }
                                    catch (Exception e)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }
Exemplo n.º 2
0
        public string UploadDataTruck(IEnumerable <HttpPostedFileBase> filesDataTruck)
        {
            ResponeModel response = new ResponeModel();

            //algoritma
            if (filesDataTruck != null)
            {
                foreach (var file in filesDataTruck)
                {
                    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 && RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()) != null)
                                {
                                    int id = 0;

                                    int resId;
                                    if (workSheet.Cells[rowIterator, 38].Value != null)
                                    {
                                        if (int.TryParse(workSheet.Cells[rowIterator, 38].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }

                                    Context.DataTruck dbitem = new Context.DataTruck();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoDataTruck.FindByPK(id);
                                            if (RepoDataTruck.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id))
                                            {
                                                continue;
                                            }
                                        }
                                        else
                                        {
                                            if (RepoDataTruck.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString()))
                                            {
                                                continue;
                                            }
                                            dbitem.urutan  = RepoDataTruck.getUrutan() + 1;
                                            dbitem.NoTruck = RepoDataTruck.generateCode(dbitem.urutan);
                                        }

                                        dbitem.VehicleNo = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        if (workSheet.Cells[rowIterator, 2].Value != null)
                                        {
                                            dbitem.IdMerk = RepoLookup.FindByName(workSheet.Cells[rowIterator, 2].Value.ToString()).Id;
                                        }
                                        if (workSheet.Cells[rowIterator, 3].Value != null)
                                        {
                                            dbitem.IdJenisTruck = JenisTruck.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                        }
                                        if (workSheet.Cells[rowIterator, 4].Value != null)
                                        {
                                            dbitem.TahunBuat = int.Parse(workSheet.Cells[rowIterator, 4].Value.ToString());
                                        }
                                        if (workSheet.Cells[rowIterator, 5].Value != null)
                                        {
                                            dbitem.TahunBeli = int.Parse(workSheet.Cells[rowIterator, 5].Value.ToString());
                                        }
                                        if (workSheet.Cells[rowIterator, 6].Value != null)
                                        {
                                            dbitem.IdPool = MasterPool.FindByNamePool(workSheet.Cells[rowIterator, 6].Value.ToString()).Id;
                                        }
                                        if (workSheet.Cells[rowIterator, 7].Value != null && RepoLookup.FindByName(workSheet.Cells[rowIterator, 7].Value.ToString()) != null)
                                        {
                                            dbitem.IdUnit = RepoLookup.FindByName(workSheet.Cells[rowIterator, 7].Value.ToString()).Id;
                                        }
                                        dbitem.Keterangan = workSheet.Cells[rowIterator, 8].Value != null ? workSheet.Cells[rowIterator, 8].Value.ToString() : "";
                                        dbitem.Kondisi    = workSheet.Cells[rowIterator, 9].Value != null ? workSheet.Cells[rowIterator, 9].Value.ToString() : "";
                                        dbitem.SpecModel  = workSheet.Cells[rowIterator, 10].Value != null ? workSheet.Cells[rowIterator, 10].Value.ToString() : "";
                                        dbitem.KmLimit    = workSheet.Cells[rowIterator, 11].Value != null?int.Parse(workSheet.Cells[rowIterator, 11].Value.ToString()) : 0;

                                        dbitem.NoMesin  = workSheet.Cells[rowIterator, 12].Value != null ? workSheet.Cells[rowIterator, 12].Value.ToString() : "";
                                        dbitem.NoRangka = workSheet.Cells[rowIterator, 13].Value != null ? workSheet.Cells[rowIterator, 13].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 14].Value != null)
                                        {
                                            dbitem.GaransiStr = DateTime.Parse(workSheet.Cells[rowIterator, 14].Value.ToString());
                                        }
                                        if (workSheet.Cells[rowIterator, 15].Value != null)
                                        {
                                            dbitem.GaransiEnd = DateTime.Parse(workSheet.Cells[rowIterator, 15].Value.ToString());
                                        }
                                        dbitem.SpecKeterangan = workSheet.Cells[rowIterator, 16].Value != null ? workSheet.Cells[rowIterator, 16].Value.ToString() : "";
                                        dbitem.AtasNama       = workSheet.Cells[rowIterator, 17].Value != null ? workSheet.Cells[rowIterator, 17].Value.ToString() : "";
                                        dbitem.BPKB           = workSheet.Cells[rowIterator, 18].Value != null ? workSheet.Cells[rowIterator, 18].Value.ToString() : "";
                                        dbitem.keteranganBPKB = workSheet.Cells[rowIterator, 19].Value != null ? workSheet.Cells[rowIterator, 19].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 20].Value != null)
                                        {
                                            dbitem.STNK = DateTime.Parse(workSheet.Cells[rowIterator, 20].Value.ToString());
                                        }
                                        dbitem.keteranganSTNK = workSheet.Cells[rowIterator, 21].Value != null ? workSheet.Cells[rowIterator, 21].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 22].Value != null)
                                        {
                                            dbitem.KIR = DateTime.Parse(workSheet.Cells[rowIterator, 22].Value.ToString());
                                        }
                                        dbitem.keteranganKIR = workSheet.Cells[rowIterator, 23].Value != null ? workSheet.Cells[rowIterator, 23].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 24].Value != null)
                                        {
                                            dbitem.KIU = DateTime.Parse(workSheet.Cells[rowIterator, 24].Value.ToString());
                                        }
                                        dbitem.keteranganKIU = workSheet.Cells[rowIterator, 25].Value != null ? workSheet.Cells[rowIterator, 25].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 26].Value != null)
                                        {
                                            dbitem.IBM = DateTime.Parse(workSheet.Cells[rowIterator, 26].Value.ToString());
                                        }
                                        dbitem.keteranganIBM = workSheet.Cells[rowIterator, 27].Value != null ? workSheet.Cells[rowIterator, 27].Value.ToString() : "";
                                        if (workSheet.Cells[rowIterator, 28].Value != null)
                                        {
                                            dbitem.Asuransi = DateTime.Parse(workSheet.Cells[rowIterator, 28].Value.ToString());
                                        }
                                        dbitem.keteranganAsuransi = workSheet.Cells[rowIterator, 29].Value != null ? workSheet.Cells[rowIterator, 29].Value.ToString() : null;
                                        if (workSheet.Cells[rowIterator, 30].Value != null)
                                        {
                                            dbitem.Reklame = DateTime.Parse(workSheet.Cells[rowIterator, 30].Value.ToString());
                                        }
                                        else
                                        {
                                            dbitem.Reklame = null;
                                        }
                                        dbitem.keteranganReklame  = workSheet.Cells[rowIterator, 31].Value != null ? workSheet.Cells[rowIterator, 31].Value.ToString() : "";
                                        dbitem.NoPolis            = workSheet.Cells[rowIterator, 32].Value != null ? workSheet.Cells[rowIterator, 32].Value.ToString() : null;
                                        dbitem.keteranganNoPolis  = workSheet.Cells[rowIterator, 33].Value != null ? workSheet.Cells[rowIterator, 33].Value.ToString() : "";
                                        dbitem.Peminjam           = workSheet.Cells[rowIterator, 34].Value != null ? workSheet.Cells[rowIterator, 34].Value.ToString() : null;
                                        dbitem.keteranganPeminjam = workSheet.Cells[rowIterator, 35].Value != null ? workSheet.Cells[rowIterator, 35].Value.ToString() : "";
                                        dbitem.Leasing            = workSheet.Cells[rowIterator, 36].Value != null ? workSheet.Cells[rowIterator, 36].Value.ToString() : null;
                                        dbitem.keteranganLeasing  = workSheet.Cells[rowIterator, 37].Value != null ? workSheet.Cells[rowIterator, 37].Value.ToString() : "";

                                        RepoDataTruck.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                        response.Message = response.Message + Environment.NewLine + " " + rowIterator;
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

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