public ActionResult Edit(DataPendingin model) { if (ModelState.IsValid) { if (RepoPendingin.IsBoxExist(model.IdDataTruk.Value, model.Id)) { ModelState.AddModelError("IdDataTruk", "Truck sudah tepasang pendingin, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataPendingin dbitem = RepoPendingin.FindByPK(model.Id); model.setDb(dbitem); Context.DataPendinginHistory dbitemhistory = new Context.DataPendinginHistory(); model.setDbHistory(dbitemhistory, UserPrincipal.firstname + ' ' + UserPrincipal.lastname); dbitem.ListHistoryPendingin.Add(dbitemhistory); Context.DataTruckPendinginHistory dbtruckhistory = new Context.DataTruckPendinginHistory(); model.setDbTruckHistory(dbtruckhistory, UserPrincipal.firstname + ' ' + UserPrincipal.lastname); RepoPendingin.save(dbitem, UserPrincipal.id, dbitemhistory, dbtruckhistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruk.Value); dbtruck.DataTruckPendinginHistory.Add(dbtruckhistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public DataPendingin(Context.DataPendinginHistory dbitem) { Id = dbitem.Id; NoPendingin = dbitem.ForPendingin.NoPendingin; VechileNo = dbitem.strDataTruk; Merk = dbitem.Merk; ModelPendingin = dbitem.Model; HmLimit = dbitem.HmLimit; Tahun = dbitem.Tahun; NamaJenisPendingin = dbitem.strJenisPendingin; NoMesin = dbitem.NoMesin; NoKompresor = dbitem.NoKompresor; tglPasang = dbitem.tglPasang; tanggal = dbitem.Tanggal; username = dbitem.user; }
public void setDbHistory(Context.DataPendinginHistory dbitem, string user) { dbitem.Id = Id; dbitem.Tanggal = DateTime.Now; dbitem.NoPendingin = NoPendingin; dbitem.user = user; dbitem.strDataTruk = VechileNo; dbitem.Merk = Merk; dbitem.Model = ModelPendingin; dbitem.HmLimit = HmLimit; dbitem.Tahun = Tahun; dbitem.strJenisPendingin = NamaJenisPendingin; dbitem.NoMesin = NoMesin; dbitem.NoKompresor = NoKompresor; dbitem.tglPasang = tglPasang; }
public ActionResult Add(DataPendingin model) { if (ModelState.IsValid) { if (RepoPendingin.IsBoxExist(model.IdDataTruk.Value)) { ModelState.AddModelError("IdDataTruk", "Truck sudah tepasang pendingin, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataPendingin dbitem = new Context.DataPendingin(); model.setDb(dbitem); //generate code dbitem.Urutan = RepoPendingin.getUrutan() + 1; dbitem.NoPendingin = RepoPendingin.generateCode(dbitem.Urutan); Context.DataPendinginHistory dbitemhistory = new Context.DataPendinginHistory(); model.setDbHistory(dbitemhistory, UserPrincipal.firstname + ' ' + UserPrincipal.lastname); dbitemhistory.NoPendingin = dbitem.NoPendingin; dbitemhistory.strDataTruk = RepoDataTruck.FindByPK(dbitem.IdDataTruk).VehicleNo; dbitemhistory.strJenisPendingin = dbitem.IdJenisPendingin.HasValue ? RepoLookup.FindByPK(dbitem.IdJenisPendingin).Nama : ""; dbitem.ListHistoryPendingin.Add(dbitemhistory); Context.DataTruckPendinginHistory dbtruckhistory = new Context.DataTruckPendinginHistory(); model.setDbTruckHistory(dbtruckhistory, UserPrincipal.firstname + ' ' + UserPrincipal.lastname); RepoPendingin.save(dbitem, UserPrincipal.id, dbitemhistory, dbtruckhistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruk.Value); dbtruckhistory.NoPendingin = dbitem.NoPendingin; dbtruckhistory.strDataTruk = RepoDataTruck.FindByPK(dbitem.IdDataTruk).VehicleNo; dbtruckhistory.strJenisPendingin = dbitem.IdJenisPendingin.HasValue ? RepoLookup.FindByPK(dbitem.IdJenisPendingin).Nama : ""; dbtruck.DataTruckPendinginHistory.Add(dbtruckhistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
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 })); }