.NET MVC2018.07.11 11:44

        public ActionResult GetInventoryExcel(GetInventoryListModel getInventoryListModel)

        {

            // Validation

            if (getInventoryListModel.SearchStartDate == DateTime.MinValue) { getInventoryListModel.SearchStartDate = DateTime.Now.AddYears(-50); }

            if (getInventoryListModel.SearchEndDate == DateTime.MinValue) { getInventoryListModel.SearchEndDate = DateTime.Now; }


            getInventoryListModel.CustomerNo = LoginService.GetLoginInfo.cust_no;

            getInventoryListModel.PlaceCode = LoginService.GetLoginInfo.pl_cd;


            if ("inventoryNo".Equals(getInventoryListModel.searchOption)) { getInventoryListModel.InventoryCode = getInventoryListModel.searchOptionDetail; }

            if ("inventoryName".Equals(getInventoryListModel.searchOption)) { getInventoryListModel.InventoryName = getInventoryListModel.searchOptionDetail; }


            Response.Clear();

            Response.Buffer = true;

            Response.ContentType = "application/vnd.ms-excel";

            Response.AddHeader("content-disposition", "attachment; filename=Inventory"+DateTime.Now.ToShortDateString()+".xls");

            Response.ContentEncoding = System.Text.Encoding.UTF8;

            Response.Charset = "UTF-8";

            

            

            System.IO.StringWriter sw = new System.IO.StringWriter();

            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);


            this.InventoryBiz.GetGridViewForExcel(base.InventoryBiz.GetInventoryList(getInventoryListModel)).RenderControl(htw);

            Response.Write(@"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><style> TD { mso-number-format:\@; } </style>");


            Response.Output.Write(sw.ToString());

            Response.Flush();

            Response.End();

            

            return new EmptyResult();

        }


public GridView GetGridViewForExcel(DataTable dt)

        {

            var inventoryDT = new System.Data.DataTable("Inventory");

            inventoryDT.Columns.Add("Inventory No ", typeof(string));

            inventoryDT.Columns.Add("Inventory Name", typeof(string));

            inventoryDT.Columns.Add("Inventory Total Qty", typeof(int));

            inventoryDT.Columns.Add("Registration Date", typeof(System.DateTime));


            if (dt != null)

            {

                for (int i = 0; i < dt.Rows.Count; i++)

                {

                    inventoryDT.Rows.Add(dt.Rows[i]["inv_code"], dt.Rows[i]["inv_name"], dt.Rows[i]["inv_qty"], dt.Rows[i]["reg_dt"]);

                }

            }


            var gridView = new System.Web.UI.WebControls.GridView { AllowPaging = false, DataSource = inventoryDT };

            gridView.DataBind();


            return gridView;

        }




Posted by James jangjeonghun
.NET MVC2018.06.21 17:30


Call

ConvertToList<TestModel>(datatableResource)


Method

public List<T> ConvertToList<T>(DataTable dt)

        {

            dt = dt ?? new DataTable();


            var columnNames = dt.Columns.Cast<DataColumn>()

                    .Select(c => c.ColumnName)

                    .ToList();


            var properties = typeof(T).GetProperties();


            return dt.AsEnumerable().Select(row =>

            {

                var objT = System.Activator.CreateInstance<T>();

                foreach (var pro in properties)

                {

                    if (columnNames.Contains(pro.Name))

                        pro.SetValue(objT, row[pro.Name]);

                }

                return objT;

            }).ToList();

        }



Posted by James jangjeonghun
.NET MVC2018.06.07 14:55

string[] arrivalSkuNo


if (arrivalSkuNo.Count(n => n == skuNo) > 1)

{

ModelState.AddModelError("", ""); break;

}


Posted by James jangjeonghun

티스토리 툴바