コード例 #1
0
        public ActionResult EditFilter(int id, int dbId)
        {
            List <TargetDetailsVm> targetDetailsVm = new List <TargetDetailsVm>();

            var skuList = from a in Db.tbld_SKU
                          join c in Db.tbld_SKU_unit on a.SKUUnit equals c.id into qs
                          from q in qs.DefaultIfEmpty()
                          where a.SKUStatus == 1
                          select new { SkuId    = a.SKU_id,
                                       SkuName  = a.SKUName,
                                       PackSize = q.qty, };

            foreach (var skuitem in skuList)
            {
                int tgtqty            = 0;
                var tbldTargetDetails = Db.tbld_Target_Details
                                        .SingleOrDefault(x => x.target_id == id && x.db_id == dbId && x.sku_id == skuitem.SkuId);
                if (tbldTargetDetails != null)
                {
                    tgtqty = (int)tbldTargetDetails.total_Qty;
                }

                TargetDetailsVm targetDetailsitem = new TargetDetailsVm
                {
                    TargetId = id,
                    DbId     = dbId,
                    SkuId    = skuitem.SkuId,
                    SkuName  = skuitem.SkuName,
                    PackSize = skuitem.PackSize,
                    QtyinCs  = Convert.ToInt32(tgtqty / skuitem.PackSize),
                    QtyinPs  = Convert.ToInt32(tgtqty % skuitem.PackSize),
                };
                targetDetailsVm.Add(targetDetailsitem);
            }


            //  var data = Db.tbld_Target_Details.Where(x => x.target_id == id && x.db_id == dbId);
            return(PartialView(targetDetailsVm));
        }
コード例 #2
0
        public ActionResult DownloadDbTargetFormat(int id)
        {
            var tgt = Db.tbld_Target.SingleOrDefault(x => x.id == id);

            if (tgt != null)
            {
                List <TargetDetailsVm> targetDetailsList = new List <TargetDetailsVm>();


                var skuList = from a in Db.tbld_SKU
                              join b in Db.tbld_SKU_unit on a.SKUUnit equals b.id
                              where a.SKUStatus == 1
                              orderby a.SKU_id, a.SKUbrand_id
                    select new
                {
                    sku_id    = a.SKU_id,
                    sku_name  = a.SKUName,
                    pack_size = b.qty
                };

                var dblist = Db.tbld_db_zone_view.Where(x => x.Status == 1);


                foreach (var dbitem in dblist)
                {
                    foreach (var skuitem in skuList)
                    {
                        TargetDetailsVm targetDetailsitem = new TargetDetailsVm
                        {
                            TargetId   = tgt.id,
                            TargetName = tgt.name,
                            RegionName = dbitem.REGION_Name,
                            AreaName   = dbitem.AREA_Name,
                            CeAreaName = dbitem.CEAREA_Name,
                            DbId       = dbitem.DB_Id,
                            DbName     = dbitem.DB_Name,
                            SkuId      = skuitem.sku_id,
                            SkuName    = skuitem.sku_name,
                            PackSize   = skuitem.pack_size
                        };
                        targetDetailsList.Add(targetDetailsitem);
                    }
                }



                var gv = new GridView {
                    DataSource = targetDetailsList
                };

                gv.DataBind();
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=" + tgt.name + ".xls");
                Response.ContentType = "application/ms-excel";
                Response.Charset     = "";
                StringWriter   objStringWriter   = new StringWriter();
                HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter);
                gv.RenderControl(objHtmlTextWriter);
                Response.Output.Write(objStringWriter.ToString());

                Response.Flush();
                Response.End();
            }
            return(View("Index"));
        }