public ActionResult Edit(DataBox model) { if (ModelState.IsValid) { if (RepoDataBox.IsBoxExist(model.IdDataTruck.Value, model.Id)) { ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang box, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataBox dbitem = RepoDataBox.FindByPK(model.Id); model.SetDb(dbitem); Context.DataBoxHistory dbitemHistory = new Context.DataBoxHistory(); model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbitem.DataBoxHistory.Add(dbitemHistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value); Context.DataTruckBoxHistory dbtruckHistory = new Context.DataTruckBoxHistory(); RepoDataBox.save(dbitem, UserPrincipal.id, dbitemHistory, dbtruckHistory); model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbtruck.DataTruckBoxHistory.Add(dbtruckHistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public JsonResult Delete(int id) { ResponeModel response = new ResponeModel(true); Context.DataBox dbItem = RepoDataBox.FindByPK(id); RepoDataBox.delete(dbItem, UserPrincipal.id); return(Json(response)); }
public ActionResult Edit(int id) { Context.DataBox dbitem = RepoDataBox.FindByPK(id); DataBox model = new DataBox(dbitem); GenerateLantaiDinding(model); SetLantaiDinding(model, dbitem); ViewBag.name = model.NoBox; return(View("Form", model)); }
public void SetLantaiDinding(DataBox model, Context.DataBox dbitem) { foreach (Context.DataBoxLantai item in dbitem.DataBoxLantai) { model.ListLantai.Where(d => d.IdLantai == item.IdLantaiCode).First().IsSelect = true; } foreach (Context.DataBoxDinding item in dbitem.DataBoxDinding) { model.ListDinding.Where(d => d.IdDinding == item.IdDindingCode).First().IsSelect = true; } }
public string BindingHistory(int id) { Context.DataBox db = RepoDataBox.FindByPK(id); List <DataBox> listmodel = new List <DataBox>(); foreach (Context.DataBoxHistory item in db.DataBoxHistory.OrderByDescending(d => d.Id)) { listmodel.Add(new DataBox(item)); } return(new JavaScriptSerializer().Serialize(listmodel)); }
public void SetDb(Context.DataBox dbitem) { dbitem.Id = Id; dbitem.NoBox = NoBox; dbitem.IdDataTruck = IdDataTruck; dbitem.Karoseri = Karoseri; dbitem.Tahun = Tahun; dbitem.IdType = IdType; dbitem.IdKategori = IdKategori; dbitem.Lantai = Lantai; dbitem.Dinding = Dinding; dbitem.PintuSamping = PintuSamping; dbitem.Sekat = Sekat; dbitem.garansiStr = garansiStr; dbitem.garansiEnd = garansiEnd; dbitem.asuransiStr = asuransiStr; dbitem.asuransiEnd = asuransiEnd; dbitem.tglPasang = tglPasang; dbitem.DataBoxLantai.Clear(); dbitem.DataBoxDinding.Clear(); if (ListLantai.Count() > 0) { foreach (LantaiModel item in ListLantai) { if (item.IsSelect) { dbitem.DataBoxLantai.Add(new DataBoxLantai() { IdLantaiCode = item.IdLantai }); } } } if (ListDinding.Count() > 0) { foreach (DindingModel item in ListDinding) { if (item.IsSelect) { dbitem.DataBoxDinding.Add(new DataBoxDinding() { IdDindingCode = item.IdDinding }); } } } }
public DataBox(Context.DataBox dbitem) { List <string> dummyLantai = new List <string>(); List <string> dummyDinding = new List <string>(); Id = dbitem.Id; NoBox = dbitem.NoBox; IdDataTruck = dbitem.IdDataTruck; VehicleNo = dbitem.DataTruck.VehicleNo; Karoseri = dbitem.Karoseri; Tahun = dbitem.Tahun; IdType = dbitem.IdType; StrType = dbitem.IdType != null ? dbitem.LookupCodeType.Nama : ""; IdKategori = dbitem.IdKategori; StrKategori = dbitem.IdKategori != null ? dbitem.LookupCodeKategori.Nama : ""; Lantai = dbitem.Lantai; dummyLantai.Add(dbitem.Lantai); Dinding = dbitem.Dinding; dummyDinding.Add(dbitem.Dinding); PintuSamping = dbitem.PintuSamping; Sekat = dbitem.Sekat; garansiStr = dbitem.garansiStr; garansiEnd = dbitem.garansiEnd; asuransiStr = dbitem.asuransiStr; asuransiEnd = dbitem.asuransiEnd; tglPasang = dbitem.tglPasang; foreach (DataBoxLantai item in dbitem.DataBoxLantai) { dummyLantai.Add(item.LookupCodeLantaiCode.Nama); } foreach (DataBoxDinding item in dbitem.DataBoxDinding) { dummyDinding.Add(item.LookupCodeDinding.Nama); } if (dummyLantai.Count() > 0) { strLantai = string.Join(", ", dummyLantai); } if (dummyDinding.Count() > 0) { strDinding = string.Join(", ", dummyDinding); } }
public ActionResult Add(DataBox model) { if (ModelState.IsValid) { if (RepoDataBox.IsBoxExist(model.IdDataTruck.Value)) { ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang box, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataBox dbitem = new Context.DataBox(); model.SetDb(dbitem); //generate code dbitem.Urutan = RepoDataBox.getUrutan() + 1; dbitem.NoBox = RepoDataBox.generateCode(dbitem.Urutan); Context.DataBoxHistory dbitemHistory = new Context.DataBoxHistory(); model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbitemHistory.Vehicle = RepoDataTruck.FindByPK(model.IdDataTruck.Value).VehicleNo; dbitemHistory.NoBox = dbitem.NoBox; dbitemHistory.strKategori = model.IdKategori.HasValue ? RepoLookup.FindByPK(model.IdKategori.Value).Nama : ""; dbitemHistory.strType = model.IdType.HasValue ? RepoLookup.FindByPK(model.IdType.Value).Nama : ""; dbitem.DataBoxHistory.Add(dbitemHistory); Context.DataTruckBoxHistory dbtruckHistory = new Context.DataTruckBoxHistory(); model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); RepoDataBox.save(dbitem, UserPrincipal.id, dbitemHistory, dbtruckHistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value); dbtruckHistory.Vehicle = dbtruck.VehicleNo; dbtruckHistory.NoBox = dbitem.NoBox; dbtruckHistory.strKategori = model.IdKategori.HasValue ? RepoLookup.FindByPK(model.IdKategori.Value).Nama : ""; dbtruckHistory.strType = model.IdType.HasValue ? RepoLookup.FindByPK(model.IdType.Value).Nama : ""; dbtruck.DataTruckBoxHistory.Add(dbtruckHistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public DataTruckDetail(Context.DataTruck dbitem, List <Context.PenetapanDriver> dbPenetapanDriver = null, List <Context.SalesOrder> dbso = null) { Id = dbitem.Id; //cek status order StatusOrder = ""; StatusTruk = "Available"; if (dbso != null) { if (dbso.Any(d => (d.Status == "save" || d.Status == "draft planning") && ((d.SalesOrderOncallId.HasValue ? d.SalesOrderOncall.IdDataTruck == dbitem.Id : false) || (d.SalesOrderPickupId.HasValue ? d.SalesOrderPickup.IdDataTruck == dbitem.Id : false) || (d.SalesOrderProsesKonsolidasiId.HasValue ? d.SalesOrderProsesKonsolidasi.IdDataTruck == dbitem.Id : false) || (d.SalesOrderKontrakId.HasValue ? d.SalesOrderKontrak.SalesOrderKontrakTruck.Any(k => k.DataTruckId == dbitem.Id) : false)))) { StatusOrder = "Planning"; StatusTruk = "On Duty"; } else if (dbso.Any(d => (d.Status == "save planning" || d.Status == "draft konfirmasi") && ((d.SalesOrderOncallId.HasValue ? d.SalesOrderOncall.IdDataTruck == dbitem.Id : false) || (d.SalesOrderPickupId.HasValue ? d.SalesOrderPickup.IdDataTruck == dbitem.Id : false) || (d.SalesOrderProsesKonsolidasiId.HasValue ? d.SalesOrderProsesKonsolidasi.IdDataTruck == dbitem.Id : false) || (d.SalesOrderKontrakId.HasValue ? d.SalesOrderKontrak.SalesOrderKontrakTruck.Any(k => k.DataTruckId == dbitem.Id) : false)))) { StatusOrder = "Konfirmasi"; StatusTruk = "On Duty"; } else if (dbso.Any(d => (d.Status == "save konfirmasi" || d.Status == "dispatched") && ((d.SalesOrderOncallId.HasValue ? d.SalesOrderOncall.IdDataTruck == dbitem.Id : false) || (d.SalesOrderPickupId.HasValue ? d.SalesOrderPickup.IdDataTruck == dbitem.Id : false) || (d.SalesOrderProsesKonsolidasiId.HasValue ? d.SalesOrderProsesKonsolidasi.IdDataTruck == dbitem.Id : false) || (d.SalesOrderKontrakId.HasValue ? d.SalesOrderKontrak.SalesOrderKontrakTruck.Any(k => k.DataTruckId == dbitem.Id) : false)))) { StatusOrder = "Dispatched"; StatusTruk = "On Duty"; } } //StatusTruk = VehicleNo = dbitem.VehicleNo; Merk = dbitem.IdMerk != null ? dbitem.LookupCodeMerk.Nama : ""; JenisTruk = !dbitem.IdJenisTruck.HasValue ? "" : dbitem.JenisTrucks.StrJenisTruck; if (dbitem.DataPendingin.Count > 0) { Context.DataPendingin dbpendingin = dbitem.DataPendingin.FirstOrDefault(); Pendingin = dbpendingin.Merk + " - " + dbpendingin.Model; } if (dbitem.DataBox.Count > 0) { Context.DataBox dbbox = dbitem.DataBox.FirstOrDefault(); List <string> _lantai = new List <string>(); List <string> _dinding = new List <string>(); if (dbbox.Lantai != null && dbbox.Lantai != "") { _lantai.Add(dbbox.Lantai); } if (dbbox.Dinding != null && dbbox.Dinding != "") { _dinding.Add(dbbox.Dinding); } foreach (DataBoxLantai item in dbbox.DataBoxLantai) { _lantai.Add(item.LookupCodeLantaiCode.Nama); } foreach (DataBoxDinding item in dbbox.DataBoxDinding) { _dinding.Add(item.LookupCodeDinding.Nama); } if (_lantai.Count() > 0) { Lantai = string.Join(", ", _lantai); } if (_dinding.Count() > 0) { Dinding = string.Join(", ", _dinding); } } KondisiKhusus = dbitem.Kondisi; List <string> _dok = new List <string>(); if (dbitem.STNK != null && dbitem.STNK.Value >= DateTime.Now) { _dok.Add("STNK"); } if (dbitem.KIR != null && dbitem.KIR.Value >= DateTime.Now) { _dok.Add("KIR"); } if (dbitem.KIU != null && dbitem.KIU.Value >= DateTime.Now) { _dok.Add("KIU/SIPA"); } if (dbitem.IBM != null && dbitem.IBM.Value >= DateTime.Now) { _dok.Add("IBM"); } if (dbitem.Asuransi != null && dbitem.Asuransi.Value >= DateTime.Now) { _dok.Add("Asuransi"); } if (dbitem.Reklame != null && dbitem.Reklame.Value >= DateTime.Now) { _dok.Add("Pajak Reklame"); } if (_dok.Count > 0) { DokumenExp = string.Join(", ", _dok); } if (dbPenetapanDriver != null) { Context.PenetapanDriver dbPenetapan = dbPenetapanDriver.Where(d => d.IdDataTruck == dbitem.Id).FirstOrDefault(); if (dbPenetapan != null) { IdDriver1 = dbPenetapan.IdDriver1.Value; KodeDriver1 = dbPenetapan.Driver1.KodeDriver; NamaDriver1 = dbPenetapan.Driver1.NamaDriver; StatusDriver1 = dbPenetapan.Driver1.LookupCodeStatus.Nama; if (dbPenetapan.IdDriver2.HasValue) { IdDriver2 = dbPenetapan.IdDriver2.Value; KodeDriver2 = dbPenetapan.Driver2.KodeDriver; NamaDriver2 = dbPenetapan.Driver2.NamaDriver; StatusDriver2 = dbPenetapan.Driver2.LookupCodeStatus.Nama; } } } }
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 })); }