コード例 #1
0
        public ActionResult ExportExcel(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId)
        {
            try
            {
                DataTable templateData = new DataTable();
                // add IEnumerable<AdjustAcceptedViewModels>
                List <AdjustDocReturnedViewModels> viewModel = new List <AdjustDocReturnedViewModels>();

                //filter department
                var q = from d in objBs.docReturnDelayBs.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();

                //int c = q.Count();

                foreach (var item in q)
                {
                    AdjustDocReturnedViewModels model = new AdjustDocReturnedViewModels();
                    model.Shipment        = item.SHPMNTNO;
                    model.DeliveryNote    = item.DELVNO;
                    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.TO_SHPG_LOC_NAME;
                    model.ShippingPoint   = item.SHPPOINT;
                    model.TruckType       = item.TRUCK_TYPE;
                    model.PlanDocReturn   = item.PLNDOCRETDATE_SCGL.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    model.ActualDocReturn = item.DOCRETDATE_SCGL.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    model.ActualGI        = item.ACTGIDATE.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, "ExportedAdjustDocReturn_" + DateTime.Now.ToString("yyyyMMddHHmm", new CultureInfo("th-TH")));//dump

                return(View());
            }
            catch (Exception e)
            {
                TempData["Msg"] = "Error" + e.ToString();
                return(View());
            }
        }
コード例 #2
0
        public ActionResult ExportExcel(string TenderUser, string SegmentId, string YearId, string MonthId, string ShipPoint, string ShipTo, string TruckType)
        {
            try
            {
                DataTable templateData = new DataTable();
                // add IEnumerable<AdjustAcceptedViewModels>
                List <AdjustTenderedViewModels> viewModel = new List <AdjustTenderedViewModels>();

                //filter department
                //var q = from d in objBs.tenderedDelayBs.GetByFilter(SegmentId, Convert.ToInt32(YearId), Convert.ToInt32(MonthId))
                //        select d;

                var month = Convert.ToInt16(MonthId);
                var year  = Convert.ToInt16(YearId);
                var q     = from d in objBs.tenderedDelayBs.GetAll().Where(x => x.CRTD_USR_CD == TenderUser && x.PLNTNRDDATE_D.Value.Year == year && x.PLNTNRDDATE_D.Value.Month == month)
                            select d;
                q.ToList();

                ////filter Shipping Point
                //if (!String.IsNullOrEmpty(ShipPoint))
                //    q = q.Where(x => x.SHPPOINT == ShipPoint);

                ////filter Shipping To
                //if (!String.IsNullOrEmpty(ShipTo))
                //    q = q.Where(x => x.SHIPTO == ShipTo);

                ////filter Truck Type
                //if (!String.IsNullOrEmpty(TruckType))
                //    q = q.Where(x => x.TRUCK_TYPE == TruckType);

                //int c = q.Count();
                foreach (var item in q)
                {
                    AdjustTenderedViewModels model = new AdjustTenderedViewModels();
                    model.TenderUser    = item.CRTD_USR_CD;
                    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.ShcrDate      = item.SHCRDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    model.PlanTender    = item.PLNTNRDDATE.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH"));
                    model.FirstTender   = item.FTNRDDATE.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, "ExportedAdjustTender_" + DateTime.Now.ToString("yyyyMMddHHmm", new CultureInfo("th-TH")));//dump

                return(View());
            }
            catch (Exception e)
            {
                TempData["Msg"] = "Error" + e.ToString();
                return(View());
            }
        }