private static OrderReport GenerateReportForOrder(
            Order order,
            OrderReportFormattingSettings orderReportFormattingSettings)
        {
            var sb = new MyStringBuilder();

            sb.AppendLine("Order date: " + FormatDate(order.OrderDate));

            if (!orderReportFormattingSettings.DontIncludeNumberOrOrderLines)
            {
                sb.AppendLine("Number of order lines: " + order.OrderLines.Length.AsString());
            }

            decimal total = 0m;

            foreach (var orderLine in order.OrderLines)
            {
                var lineTotal = orderLine.ItemCount * orderLine.ItemPrice;

                total += lineTotal;

                sb.AppendLine(orderLine.ProductName + ": " + orderLine.ItemCount.AsString() + " * " + orderLine.ItemPrice.AsString() + "$ = " + lineTotal.AsString() + "$");
            }

            sb.AppendLine("Total: " + total.AsString() + "$");

            return(new OrderReport(sb.ToString()));
        }
예제 #2
0
 public static string FormatCurrencyValueNoDecimals(this decimal source, string currencySymbol = "R")
 {
     return("{0} {1}".FormatInvariantCulture(currencySymbol, source.AsString("{0:# ##0}")));
 }
예제 #3
0
        /// <summary>
        /// 2.3台指選擇權(近月及一週到期)主要序列行情表
        /// </summary>
        /// <param name="ws"></param>
        /// <param name="tradeDate"></param>
        /// <param name="haveTradeTxw"></param>
        /// <param name="closePrice"></param>
        /// <returns></returns>
        protected bool wf_30055_tx(Worksheet ws, DateTime tradeDate, bool haveTradeTxw, decimal closePrice)
        {
            string sheetName     = "Sheet1";
            string sheetSubTitle = "台指選擇權(近月及一週到期)主要序列行情表";

            labMsg.Text = string.Format("{0} 資料轉出中......", sheetName);
            this.Refresh();

            //有無TXW,會當成參數條件
            int txo_row_cnt, txw_row_cnt;

            if (haveTradeTxw)
            {
                txo_row_cnt = 4;
                txw_row_cnt = 2;
            }
            else
            {
                txo_row_cnt = 6;
                txw_row_cnt = 0;
            }
            decimal StockStrikePrice = Math.Truncate(closePrice / 100) * 100;//取現貨收盤價,百元以下無條件捨去當價平

            DataTable dtOption = dao30055.wf_30055_tx(tradeDate, StockStrikePrice, txo_row_cnt, txw_row_cnt);

            if (dtOption.Rows.Count == 0)
            {
                showMsg(sheetName, sheetSubTitle, string.Format("價平:{0},無資料", StockStrikePrice.AsString()));
                return(false);
            }

            //write data (跟據每個商品的每個價位,分C和P兩邊寫入)
            string  kindId      = "";
            decimal strikePrice = 0;
            int     rowBegin    = 0;
            int     rowPos      = 0;
            int     colBegin    = 0;

            foreach (DataRow dr in dtOption.Rows)
            {
                //init(跟據每個商品)
                if (dr["AMIF_KIND_ID"].AsString() != kindId)
                {
                    kindId      = dr["AMIF_KIND_ID"].AsString();
                    rowBegin    = dr["RPT_SEQ_NO"].AsInt() - 1;
                    strikePrice = 0;
                    rowPos      = 0;
                }
                //跟據每個價位
                if (strikePrice != dr["AMIF_STRIKE_PRICE"].AsDecimal())
                {
                    strikePrice = dr["AMIF_STRIKE_PRICE"].AsDecimal();
                    rowPos      = rowPos + 1;
                    ws.Cells[rowBegin + rowPos, 5].Value = strikePrice;
                }

                colBegin = (dr["AMIF_PC_CODE"].AsString() == "C" ? 0 : 6);//call=A欄開始,put=G欄開始

                if (dr["AMIF_OPEN_PRICE"] != DBNull.Value)
                {
                    ws.Cells[rowBegin + rowPos, colBegin + 0].Value = dr["AMIF_OPEN_PRICE"].AsDecimal();
                }
                if (dr["AMIF_HIGH_PRICE"] != DBNull.Value)
                {
                    ws.Cells[rowBegin + rowPos, colBegin + 1].Value = dr["AMIF_HIGH_PRICE"].AsDecimal();
                }
                if (dr["AMIF_LOW_PRICE"] != DBNull.Value)
                {
                    ws.Cells[rowBegin + rowPos, colBegin + 2].Value = dr["AMIF_LOW_PRICE"].AsDecimal();
                }
                if (dr["AMIF_SETTLE_PRICE"] != DBNull.Value)
                {
                    ws.Cells[rowBegin + rowPos, colBegin + 3].Value = dr["AMIF_SETTLE_PRICE"].AsDecimal();
                }
                if (dr["AMIF_M_QNTY_TAL"] != DBNull.Value)
                {
                    ws.Cells[rowBegin + rowPos, colBegin + 4].Value = dr["AMIF_M_QNTY_TAL"].AsDecimal();
                }
            }//foreach (DataRow dr in dtOption.Rows) {

            showMsg(sheetName, sheetSubTitle, dtOption.Rows.Count.ToString());
            flag++;
            return(true);
        }
예제 #4
0
 public static string FormatPercentageValueOneDecimalPlace(this decimal source)
 {
     return("{0}{1}".FormatInvariantCulture(source.AsString("{0:#0.0}"), "%"));
 }