public FileResult ExportShopingInfo()
        {
            var reslut = (from sp in server.GetAllShopingInfo()
                          join st in server.GetAllShopingType() on sp.ShopingTypeId equals st.ID into temp
                          from st in temp.DefaultIfEmpty()
                          select new ShopingInfoViewModel
            {
                ShopingName = sp.ShopingName,
                ShopingCount = sp.ShopingCount,
                ShopingPric = sp.ShopingPric,
                Stock = sp.Stock,
                Volumeofvolume = sp.Volumeofvolume,
                ShopingTypeName = st.ShopingName
            }).ToList();
            ExportServer exportServer = new ExportServer();
            var          result       = exportServer.Export("商品信息报表", reslut);

            MemoryStream ms = new MemoryStream();

            result.Write(ms);
            ms.Seek(0, SeekOrigin.Begin);
            return(File(ms, "application/vnd.ms-excel", "商品信息.xls"));
        }
Exemple #2
0
        private Boolean GenerateTransferFileModel(ProductMediaModel productMediaModel, out TransferResourceModel transferResourceModel)
        {
            transferResourceModel = new TransferResourceModel();

            if (productMediaModel == null)
            {
                TraceError("Unable to setup TranferResourceModel. ProductMediaModel is NUll or empty.");
                return(false);
            }

            var fileName = GenerateFileName(productMediaModel);

            if (fileName.IsNullOrWhiteSpace())
            {
                TraceError("Unable to setup TranferResourceModel. Remote fileName cannot be setup.");
                return(false);
            }

            try
            {
                var source =
                    new Uri(
                        string.Format(@"file:///{0}?productId={1}&sequence={2}",
                                      Path.Combine(MediaLocationBasePath, productMediaModel.MediaPath),
                                      productMediaModel.ProductID,
                                      productMediaModel.Sequence),
                        true);

                var destination = new Uri(
                    string.Format(@"sftp://{0}@{1}/{2}?privateKeyFile={3}", ExportUser, ExportServer.Replace("sftp://", ""), fileName, ExportCertPath), true);

                transferResourceModel.Source      = source;
                transferResourceModel.Destination = destination;
            }
            catch (Exception e)
            {
                TraceError("Error setting up TranferResourceModel for product # {1}. Error: {0}", e.Message, productMediaModel.ProductID);
                return(false);
            }

            return(true);
        }