2016-12-27 12 views
1

私はC#MVCを使用しています。私はCSV ExcelファイルをエクスポートするLinqを使用しているクラスを持っていて、0の可能な無限量でちょうど小数の代わりに価格として1つの列をフォーマットしたいと思います。Linqを価格にフォーマットすることは可能ですか

EDIT

コントローラー:

public ActionResult Summary() 
     { 
      _logger.Debug("Request made for File."); 

      var currentYearSetup = _db.GetYearSetupForMostRecentOrCurrentReportingPeriod(); 
      var types = _db.GetAnimalTypes().ToArray(); 
      var rows = _db.GetSummaryRows(); 
      var file = _sm.CreateSummaryFile(rows); 
      var filename = String.Format("Summary_{0}.csv", DateTime.Now.ToString("yyyy_MM_dd__HH_mm")); 
      _logger.DebugFormat("Serving {0}", filename); 
      return File(file, System.Net.Mime.MediaTypeNames.Application.Octet, filename); 
     } 

IRepository:

IEnumerable<SummaryRow> GetSummaryRows(); 

リポジトリ:

public IEnumerable<SummaryRow> GetSummaryRows() 
     { 
      var thing = _db.YearSetups.Select(i => new 
      { 
       Year = i.Name, 
       Transfer = _db.BatchPaymentSplits 
        .Where(bps => bps.YearSetupId == i.YearSetupId) 
        .Where(bps => bps.CustomerIdEntered != null) 
        .Where(bps => _db.BatchPayments 
         .Where(bp => _db.Batches.Where(b => b.BatchTypeId.Equals("T")) 
               .Select(b => b.BatchId) 
               .Contains(bp.BatchId) 
         ) 
         .Select(bp => bp.BatchPaymentId).Contains(bps.BatchPaymentId) 
        ) 

        .Sum(bps => (decimal?)bps.Amount) ?? 0, 
      }); 

      return _db.YearSetups.Where(y => _db.BatchPaymentSplits.Select(bps => bps.YearSetupId).Contains(y.YearSetupId)) 
      .Select(i => new 
      { 
       Year = i.Name, 
       Deposit = _db.BatchPaymentSplits 
        .Where(bps => bps.YearSetupId == i.YearSetupId) 
        .Where(bps => bps.CustomerIdEntered != null) 
        .Where(bps => _db.BatchPayments 
         .Where(bp => _db.Batches.Where(b => b.BatchTypeId.Equals("C") || b.BatchTypeId.Equals("E") || b.BatchTypeId.Equals("M")) 
               .Select(b => b.BatchId) 
               .Contains(bp.BatchId) 
         ) 
         .Select(bp => bp.BatchPaymentId).Contains(bps.BatchPaymentId) 
        ) 
        .Sum(bps => (decimal?)bps.Amount) ?? 0, 
       Transfer = _db.BatchPaymentSplits 
        .Where(bps => bps.YearSetupId == i.YearSetupId) 
        .Where(bps => bps.CustomerIdEntered != null) 
        .Where(bps => _db.BatchPayments 
         .Where(bp => _db.Batches.Where(b => b.BatchTypeId.Equals("T")) 
               .Select(b => b.BatchId) 
               .Contains(bp.BatchId) 
         ) 
         .Select(bp => bp.BatchPaymentId).Contains(bps.BatchPaymentId) 
        ) 

        .Sum(bps => (decimal?)bps.Amount) ?? 0, 
       NSF = _db.BatchPaymentSplits 
        .Where(bps => bps.YearSetupId == i.YearSetupId) 
        .Where(bps => bps.CustomerIdEntered != null) 
        .Where(bps => _db.BatchPayments 
         .Where(bp => _db.Batches.Where(b => b.BatchTypeId.Equals("N")) 
               .Select(b => b.BatchId) 
               .Contains(bp.BatchId) 
         ) 
         .Select(bp => bp.BatchPaymentId).Contains(bps.BatchPaymentId) 
        ) 

        .Sum(bps => (decimal?)bps.Amount) ?? 0, 
       BankCorrection = _db.BatchPaymentSplits 
        .Where(bps => bps.YearSetupId == i.YearSetupId) 
        .Where(bps => bps.CustomerIdEntered != null) 
        .Where(bps => _db.BatchPayments 
         .Where(bp => _db.Batches.Where(b => b.BatchTypeId.Equals("B")) 
               .Select(b => b.BatchId) 
               .Contains(bp.BatchId) 
         ) 
         .Select(bp => bp.BatchPaymentId).Contains(bps.BatchPaymentId) 
        ) 

        .Sum(bps => (decimal?)bps.Amount) ?? 0, 
       Reverse = _db.BatchPaymentSplits 
        .Where(bps => bps.YearSetupId == i.YearSetupId) 
        .Where(bps => bps.CustomerIdEntered != null) 
        .Where(bps => _db.BatchPayments 
         .Where(bp => _db.Batches.Where(b => b.BatchTypeId.Equals("R")) 
               .Select(b => b.BatchId) 
               .Contains(bp.BatchId) 
         ) 
         .Select(bp => bp.BatchPaymentId).Contains(bps.BatchPaymentId) 
        ) 

        .Sum(bps => (decimal?)bps.Amount) ?? 0, 

      }).AsEnumerable().Select(r => new PaymentTransactionSummaryRow() { 
       Year = r.Year, 
       DepositedRaw = r.Deposit, 
       TransferedRaw = r.Transfer, 
       NSFRaw = r.NSF, 
       BankCorrectionRaw = r.BankCorrection, 
       ReversedRaw = r.Reverse, 
      }); 
     } 
+0

はどのようにCSVにエクスポートされますか?標準的な方法は、[標準通貨形式コード](https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx#Anchor_1)を使用してフィールドを文字列として出力することです。 。しかし、文脈を知らなくても、それを問合せや他のどこかで行うのかどうかは不明です。 –

+0

私はいくつかのコードを追加しました。私はビュー内のリンクを使用してコントローラを呼び出します。 – BlowFish

答えて

1

あなたなしで、あなたの構造については何も言うこと少し難しいです転記任意のコード。しかし、あなたは通貨文字列にintを変換することができ方法を示しています。

var intArray = new[] {3,5,6,7}; 
var currencyArray = intArray.Select(x => x.ToString("C")); 

それは私に与えは:

kr. 3,00 
kr. 5,00 
kr. 6,00 
kr. 7,00 
関連する問題