Exemple #1
0
        public void setDb(Context.RuteTol dbitem)
        {
            dbitem.Id          = Id;
            dbitem.IdRute      = IdRute;
            dbitem.NamaRuteTol = NamaRuteTol;

            dbitem.ListTolBerangkat.Clear();
            dbitem.ListTolPulang.Clear();

            TolPP[] resultBerangkat = JsonConvert.DeserializeObject <TolPP[]>(strBerangkat);
            TolPP[] resultPulang    = JsonConvert.DeserializeObject <TolPP[]>(strPulang);

            foreach (TolPP item in resultBerangkat)
            {
                dbitem.ListTolBerangkat.Add(new Context.TolBerangkat()
                {
                    IdTol     = item.IdTol,
                    IdRuteTol = item.IdRuteTol
                });
            }

            foreach (TolPP item in resultPulang)
            {
                dbitem.ListTolPulang.Add(new Context.TolPulang()
                {
                    IdTol     = item.IdTol,
                    IdRuteTol = item.IdRuteTol
                });
            }
        }
Exemple #2
0
        public RuteTol(Context.RuteTol dbitem)
        {
            Id               = dbitem.Id;
            IdRute           = dbitem.IdRute;
            KodeRute         = dbitem.Rute.Kode;
            NamaRute         = dbitem.Rute.Nama;
            NamaRuteTol      = dbitem.NamaRuteTol;
            ListTolBerangkat = new List <TolPP>();
            ListTolPulang    = new List <TolPP>();
            TolB             = new List <string>();
            TolP             = new List <string>();

            foreach (Context.TolBerangkat item in dbitem.ListTolBerangkat.ToList())
            {
                ListTolBerangkat.Add(new TolPP(item));
                TolB.Add(item.JnsTol.NamaTol);
            }

            strBerangkat = string.Join("-", TolB);

            foreach (Context.TolPulang item in dbitem.ListTolPulang.ToList())
            {
                ListTolPulang.Add(new TolPP(item));
                TolP.Add(item.JnsTol.NamaTol);
            }

            strPulang = string.Join("-", TolP);
        }
Exemple #3
0
        public ActionResult Edit(int id)
        {
            Context.RuteTol dbitem = RepoRuteTol.FindByPK(id);
            RuteTol         model  = new RuteTol(dbitem);

            ViewBag.name = model.NamaRute;
            return(View("Form", model));
        }
Exemple #4
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.RuteTol dbItem = RepoRuteTol.FindByPK(id);

            RepoRuteTol.delete(dbItem);

            return(Json(response));
        }
Exemple #5
0
        public ActionResult Edit(RuteTol model)
        {
            if (ModelState.IsValid)
            {
                Context.RuteTol dbitem = RepoRuteTol.FindByPK(model.Id);
                model.setDb(dbitem);
                RepoRuteTol.save(dbitem, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            TolPP[] resultBerangkat = JsonConvert.DeserializeObject <TolPP[]>(model.strBerangkat);
            TolPP[] resultPulang    = JsonConvert.DeserializeObject <TolPP[]>(model.strPulang);
            model.ListTolBerangkat = resultBerangkat.ToList();
            model.ListTolPulang    = resultPulang.ToList();
            return(View("Form", model));
        }
Exemple #6
0
        public string UploadRuteTol(IEnumerable <HttpPostedFileBase> filesRuteTol)
        {
            ResponeModel response = new ResponeModel();

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

                            // sheet 1
                            for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                            {
                                if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null)
                                {
                                    int             id     = 0;
                                    Context.RuteTol dbitem = new Context.RuteTol();
                                    if (workSheet.Cells[rowIterator, 5].Value != null)
                                    {
                                        int resId;
                                        if (int.TryParse(workSheet.Cells[rowIterator, 5].Value.ToString(), out resId))
                                        {
                                            id = resId;
                                        }
                                    }
                                    if (id != 0)
                                    {
                                        dbitem = RepoRuteTol.FindByPK(id);
                                        dbitem.ListTolBerangkat.Clear();
                                        dbitem.ListTolPulang.Clear();
                                    }

                                    try
                                    {
                                        //parent
                                        dbitem.IdRute      = RepoRute.FindByKode(workSheet.Cells[rowIterator, 1].Value.ToString()).Id;
                                        dbitem.NamaRuteTol = workSheet.Cells[rowIterator, 2].Value.ToString();
                                        //child 1
                                        int idx = 0;
                                        for (idx = rowIterator; idx <= noOfRow; idx++)
                                        {
                                            if (workSheet.Cells[idx, 1].Value == null || idx == rowIterator)
                                            {
                                                if (workSheet.Cells[idx, 3].Value != null)
                                                {
                                                    Context.TolBerangkat item = new Context.TolBerangkat();
                                                    item.IdTol = RepoJnsTol.FindByNamaTol(workSheet.Cells[idx, 3].Value.ToString()).Id;
                                                    dbitem.ListTolBerangkat.Add(item);
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        //child 1
                                        idx = 0;
                                        for (idx = rowIterator; idx <= noOfRow; idx++)
                                        {
                                            if (workSheet.Cells[idx, 1].Value == null || idx == rowIterator)
                                            {
                                                if (workSheet.Cells[idx, 4].Value != null)
                                                {
                                                    Context.TolPulang item = new Context.TolPulang();
                                                    item.IdTol = RepoJnsTol.FindByNamaTol(workSheet.Cells[idx, 4].Value.ToString()).Id;
                                                    dbitem.ListTolPulang.Add(item);
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }

                                        if (idx != 0)
                                        {
                                            rowIterator = idx - 1;
                                        }
                                        RepoRuteTol.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }

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