public ActionResult ExportExcel(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId) { try { DataTable templateData = new DataTable(); // add IEnumerable<AdjustAcceptedViewModels> List<AdjustAcceptedViewModels> viewModel = new List<AdjustAcceptedViewModels>(); //filter department var q = from d in objBs.acceptedDelayBs.GetByFilter(DepartmentId, SectionId, Convert.ToInt32(MonthId), Convert.ToInt32(YearId)) select d; //filter matname if (!String.IsNullOrEmpty(MatNameId)) { q = q.Where(x => x.MATFRIGRP == MatNameId); } //int c = q.Count(); foreach (var item in q) { AdjustAcceptedViewModels model = new AdjustAcceptedViewModels(); model.Shipment = item.SHPMNTNO; model.CarrierId = item.CARRIER_ID; model.RegionId = item.REGION_ID; model.RegionName = item.REGION_NAME_TH; model.Soldto = item.SOLDTO; model.SoldtoName = item.SOLDTO_NAME; model.Shipto = item.SHIPTO; model.Segment = item.SEGMENT; model.SubSegment = item.SUBSEGMENT; model.ShiptoName = item.LAST_SHPG_LOC_NAME; model.ShippingPoint = item.SHPPOINT; model.TruckType = item.TRUCK_TYPE; model.LastTender = item.LTNRDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")); model.PlanAccept = item.PLNACPDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")); model.LastAccept = item.LACPDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")); viewModel.Add(model); } templateData.Merge(ExcelModels.ToDataTable(viewModel)); templateData.Columns.Add("Remark", typeof(string)); ExcelModels ex = new ExcelModels(); ex.DumpExcel(templateData, "ExportedAdjustAccept_" + DateTime.Now.ToString("yyyyMMddHHmm", new CultureInfo("th-TH")));//dump return View(); } catch (Exception e) { TempData["Msg"] = "Error" + e.ToString(); return View(); } }
public JsonResult JsonAdjustAcceptTable(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId) { ViewBag.DepartmentId = DepartmentId; ViewBag.SectionId = SectionId; ViewBag.MatNameId = MatNameId; ViewBag.YearId = YearId; ViewBag.MonthId = MonthId; // add IEnumerable<AdjustAcceptedViewModels> List<AdjustAcceptedViewModels> viewModel = new List<AdjustAcceptedViewModels>(); //filter department var q = from d in objBs.acceptedDelayBs.GetByFilter(DepartmentId, SectionId, Convert.ToInt32(MonthId), Convert.ToInt32(YearId)) select d; //filter matname if (!String.IsNullOrEmpty(MatNameId)) { q = q.Where(x => x.MATFRIGRP == MatNameId); } //int c = q.Count(); foreach (var item in q) { AdjustAcceptedViewModels model = new AdjustAcceptedViewModels(); model.Shipment = item.SHPMNTNO; model.CarrierId = item.CARRIER_ID; model.RegionId = item.REGION_ID; model.RegionName = item.REGION_NAME_TH; model.Soldto = item.SOLDTO; model.SoldtoName = item.SOLDTO_NAME; model.Shipto = item.SHIPTO; model.ShiptoName = item.LAST_SHPG_LOC_NAME; model.ShippingPoint = item.SHPPOINT; model.Segment = item.SEGMENT; model.SubSegment = item.SUBSEGMENT; model.TruckType = item.TRUCK_TYPE; model.LastTender = item.LTNRDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")); model.PlanAccept = item.PLNACPDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")); model.LastAccept = item.LACPDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")); viewModel.Add(model); } var ddlReason = (from r in objBs.reasonAcceptedBs.GetAll() select new { Id = r.Id, Name = r.Name }).Distinct().OrderBy(x => x.Name); ViewBag.ReasonId = new SelectList(ddlReason.ToList(), "Id", "Name"); var jsonResult = Json(viewModel, JsonRequestBehavior.AllowGet); jsonResult.MaxJsonLength = int.MaxValue; return jsonResult; }