Beispiel #1
0
 public void setDb(Context.Multidrop dbitem)
 {
     dbitem.Id          = Id;
     dbitem.tujuan      = tujuan;
     dbitem.JumlahKota  = JumlahKota.Value;
     dbitem.WaktuTempuh = WaktuTempuh;
     dbitem.WaktuKerja  = WaktuKerja;
 }
Beispiel #2
0
 public MultiDrop(Context.Multidrop dbitem)
 {
     Id          = dbitem.Id;
     tujuan      = dbitem.tujuan;
     JumlahKota  = dbitem.JumlahKota;
     WaktuTempuh = dbitem.WaktuTempuh;
     WaktuKerja  = dbitem.WaktuKerja;
 }
Beispiel #3
0
        public ActionResult Edit(int id)
        {
            Context.Multidrop dbitem = RepoMultidrop.FindByPK(id);
            MultiDrop         model  = new MultiDrop(dbitem);

            ViewBag.name      = model.tujuan;
            ViewBag.Locations = RepoLocation.FindAll();
            return(View("Form", model));
        }
Beispiel #4
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.Multidrop dbItem = RepoMultidrop.FindByPK(id);

            RepoMultidrop.delete(dbItem);

            return(Json(response));
        }
Beispiel #5
0
        public ActionResult Edit(MultiDrop model)
        {
            if (ModelState.IsValid)
            {
                Context.Multidrop dbitem = RepoMultidrop.FindByPK(model.Id);
                model.setDb(dbitem);
                RepoMultidrop.save(dbitem);

                return(RedirectToAction("Index"));
            }
            ViewBag.Locations = RepoLocation.FindAll();
            return(View("Form", model));
        }
Beispiel #6
0
        public string Upload(IEnumerable <HttpPostedFileBase> filesMultidrop)
        {
            ResponeModel response = new ResponeModel();

            if (filesMultidrop != null)
            {
                foreach (var file in filesMultidrop)
                {
                    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;
                            bool isSaved      = true;

                            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)
                                {
                                    int id = 0;
                                    int resId;

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

                                    List <String>     listLocation = new List <string>();
                                    Context.Multidrop dbMultiDrop  = new Context.Multidrop();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbMultiDrop = RepoMultidrop.FindByPK(id);
                                        }

                                        dbMultiDrop.JumlahKota  = int.Parse(workSheet.Cells[rowIterator, 1].Value.ToString());
                                        dbMultiDrop.WaktuTempuh = int.Parse(workSheet.Cells[rowIterator, 2].Value.ToString());
                                        dbMultiDrop.WaktuKerja  = int.Parse(workSheet.Cells[rowIterator, 3].Value.ToString());

                                        Context.Location revLocation = RepoLocation.FindByCode(workSheet.Cells[rowIterator, 4].Value.ToString());
                                        if (revLocation != null)
                                        {
                                            listLocation.Add(revLocation.Nama);
                                        }

                                        for (int x = rowIterator + 1; x <= noOfRow; x++)
                                        {
                                            if (workSheet.Cells[x, 4].Value != null && workSheet.Cells[x, 1].Value == null &&
                                                workSheet.Cells[x, 2].Value == null && workSheet.Cells[x, 3].Value == null)
                                            {
                                                Context.Location loc = RepoLocation.FindByCode(workSheet.Cells[x, 4].Value.ToString());
                                                if (loc != null)
                                                {
                                                    listLocation.Add(loc.Nama);
                                                }
                                                else
                                                {
                                                    isSaved = false;
                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                //isSaved = false;
                                                break;
                                            }
                                        }
                                        if (listLocation.Count > 1)
                                        {
                                            dbMultiDrop.tujuan = string.Join(" - ", listLocation);
                                        }

                                        if (RepoMultidrop.FindByTujuan(dbMultiDrop.tujuan.ToString()) != null)
                                        {
                                            continue;
                                        }

                                        if (isSaved)
                                        {
                                            RepoMultidrop.save(dbMultiDrop);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }
                        }
                        response.Success = true;
                    }
                    catch (Exception e)
                    {
                        response.Success = false;
                        response.Message = e.Message.ToString();
                    }
                }
            }
            return(new JavaScriptSerializer().Serialize(new { Response = response }));
        }