Beispiel #1
0
 public HttpResponseMessage GetAll(HttpRequestMessage request)
 {
     return(CreateHttpResponse(request, () => {
         var lstNSX = NSXService.GetAll().ToList();
         lstNSX = lstNSX.OrderBy(x => x.ProducerName).ToList();
         var lstResponse = Mapper.Map <List <Producer>, List <ProducerViewModel> >(lstNSX);
         var response = request.CreateResponse(HttpStatusCode.OK, lstResponse);
         return response;
     }));
 }
Beispiel #2
0
        public HttpResponseMessage GetAllPaging(HttpRequestMessage request,
                                                int page, int pageSize, string keyWord, int?categoryID, int?status)
        {
            return(CreateHttpResponse(request, () =>
            {
                IDictionary <string, object> dic = new Dictionary <string, object>();
                dic.Add("KeyWord", keyWord);
                if (categoryID.HasValue)
                {
                    dic.Add("ProductCategoryID", categoryID);
                }
                if (status.HasValue)
                {
                    dic.Add("Status", status);
                }

                List <Product> lstProduct = productService.Search(dic).ToList();

                List <Producer> lstProducer = NSXService.GetAll().ToList();
                List <Items> lstItemsProducer = lstProducer.Select(x => new Items {
                    Value = x.ProducerID, Text = x.ProducerName
                }).ToList();
                List <ProductCategory> lstProCategory = productCategoryService.GetAll().ToList();
                List <Items> lstItemsPC = lstProCategory.Select(x => new Items {
                    Value = x.ProductCategoryID, Text = x.ProductCategoryName
                }).ToList();

                List <ProductViewModel> lstResponse = lstProduct.Select(x => new ProductViewModel
                {
                    ProductID = x.ProductID,
                    ProductName = x.ProductName,
                    ProductAlias = x.ProductAlias,
                    Quantity = x.Quantity,
                    PriceSell = x.PriceSell,
                    PriceInput = x.PriceInput,
                    ProductCode = x.ProductCode,
                    Avatar = x.Avatar,
                    PromotionPrice = x.PromotionPrice,
                    ProductViewCount = x.ProductViewCount,
                    Warranty = x.Warranty,
                    Description = x.Description,
                    CreateBy = x.CreateBy,
                    CreateDate = x.CreateDate,
                    UpdateBy = x.UpdateBy,
                    UpdateDate = x.UpdateDate,
                    Status = x.Status,
                    ProductCategoryID = x.ProductCategoryID,
                    ProducerID = x.ProducerID,
                    ProductCategoryName = x.ProductCategoryID.HasValue ? (
                        lstItemsPC.FirstOrDefault(p => p.Value == x.ProductCategoryID) != null ?
                        lstItemsPC.FirstOrDefault(p => p.Value == x.ProductCategoryID).Text : Res.Get("Not_Yet"))
                                        : Res.Get("Not_Yet"),
                    ProducerName = x.ProducerID.HasValue ? (
                        lstItemsProducer.FirstOrDefault(p => p.Value == x.ProducerID) != null ?
                        lstItemsProducer.FirstOrDefault(p => p.Value == x.ProducerID).Text : Res.Get("Not_Yet"))
                                        : Res.Get("Not_Yet"),
                }).ToList();

                lstResponse = lstResponse.OrderByDescending(x => x.ProductCode)
                              .ThenBy(x => x.ProductName).ToList();
                int totalRow = lstResponse.Count();
                IEnumerable <ProductViewModel> lstResult = lstResponse.Skip((page) * pageSize).Take(pageSize);

                var paginationset = new PaginationSet <ProductViewModel>()
                {
                    Items = lstResult,
                    Page = page,
                    TotalCount = totalRow,
                    TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize)
                };
                var response = request.CreateResponse(HttpStatusCode.OK, paginationset);
                return response;
            }));
        }
Beispiel #3
0
        public void ExportExcel(string fullPath, string fileTemplatePath, IDictionary <string, object> dic)
        {
            FileInfo fileTemplate = new FileInfo(fileTemplatePath);
            FileInfo newFile      = new FileInfo(fullPath);

            List <Producer> lstNSX      = NSXService.GetAll().ToList();
            Producer        objProducer = null;
            List <Product>  lstResult   = Search(dic).ToList();
            Product         objProduct  = null;

            using (ExcelPackage pck = new ExcelPackage(newFile, fileTemplate))
            {
                // Lấy sheet thứ 1
                ExcelWorksheet sheet = pck.Workbook.Worksheets[1];



                int startRow = 9;
                int index    = 0;

                for (int i = 0; i < lstResult.Count; i++)
                {
                    objProduct = lstResult[i];
                    if (objProduct.ProducerID.HasValue && objProduct.ProducerID.Value > 0)
                    {
                        objProducer = lstNSX.Where(x => x.ProducerID == objProduct.ProducerID).FirstOrDefault();
                    }

                    index++;
                    // STT
                    sheet.SetValue(("A" + startRow), index);
                    // Mã SP
                    sheet.SetValue(("B" + startRow), objProduct.ProductCode);
                    sheet.SetValue(("C" + startRow), objProduct.ProductName);
                    sheet.SetValue(("D" + startRow), objProduct.Quantity);
                    sheet.SetValue(("E" + startRow), objProduct.PriceInput.ToString("N0"));
                    sheet.SetValue(("F" + startRow), objProduct.PriceSell.ToString("N0"));
                    sheet.SetValue(("G" + startRow), objProducer != null ? objProducer.ProducerName : "");
                    sheet.SetValue(("H" + startRow), objProduct.Warranty);
                    sheet.SetValue(("I" + startRow), objProduct.ProductHomeFlag.HasValue && objProduct.ProductHomeFlag == true ? "X" : "");
                    sheet.SetValue(("J" + startRow), objProduct.ProductHotFlag.HasValue && objProduct.ProductHotFlag == true ? "X" : "");
                    sheet.SetValue(("K" + startRow), objProduct.ProductSellingGood.HasValue && objProduct.ProductSellingGood == true ? "X" : "");
                    sheet.SetValue(("L" + startRow), objProduct.ProductNew.HasValue && objProduct.ProductNew == true ? "X" : "");
                    sheet.SetValue(("M" + startRow), objProduct.Status ? "X" : "");
                    sheet.SetValue(("N" + startRow), objProduct.Description);
                    sheet.SetValue(("O" + startRow), objProduct.MetaDescription);
                    sheet.SetValue(("P" + startRow), objProduct.MetaKeyword);

                    if (!objProduct.Status)
                    {
                        sheet.Cells[startRow, 1, startRow, 15].Style.Font.Strike = true;
                        sheet.Cells[startRow, 1, startRow, 15].Style.Font.Color.SetColor(Color.Red);
                        //sheet.Cells[startRow, 1, startRow, 15].Style.Locked = true;
                    }
                    else
                    {
                        //sheet.Cells[startRow, 1, startRow, 15].Style.Locked = false;
                    }

                    objProducer = null;
                    startRow++;
                }

                List <string> lstNSXName = lstNSX.Select(x => x.ProducerName).ToList();

                sheet.ListValidationExcel("G", 9, 500, lstNSXName);
                sheet.RenderBorderAll(8, 1, 509, 16, ExcelBorderStyle.Thin);
                List <DataImageValidatation> lstDataImage = new List <DataImageValidatation>();
                lstDataImage.Add(new DataImageValidatation {
                    PathFile = @"F:\Troll Pictures\Troll Pictures\44645_316025975209315_1696254844_n.jpg", Row = 1, Column = 2
                });
                //lstDataImage.Add(new DataImageValidatation {PathFile = @"F:\Troll Pictures\Troll Pictures\294935_537302912984840_1891609347_n.jpg", Row = 2, Column = 2 });
                sheet.InsertPicture(lstDataImage);
                //InsertPicture(this ExcelWorksheet sheet, List < DataImageValidatation > lstDataImage)

                //sheet.Protection.SetPassword("123456");
                // Lưu file mới
                pck.SaveAs(newFile);
            }
        }