private void btnOK_Click(object sender, EventArgs e)
        {
            // 純策略模式
            //CashContext cc = null;

            //switch (cbxType.SelectedItem.ToString())
            //{
            //    case "正常收費":
            //        cc = new CashContext(new CashNormal());
            //        break;
            //    case "滿300返100":
            //        cc = new CashContext(new CashReturn("300", "100"));
            //        break;
            //    case "打8折":
            //        cc = new CashContext(new CashRebate("0.8"));
            //        break;
            //    default:
            //        break;
            //}

            // 策略 + 簡單工廠模式
            CashContextFactory cc          = new CashContextFactory(cbxType.SelectedItem.ToString());
            double             totalPrices = cc.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtCount.Text));

            total = total + totalPrices;
            txtList.AppendText("單價: " + txtPrice.Text + " 數量: " + txtCount.Text + " " + cbxType.SelectedItem + " 合計: " + totalPrices.ToString() + "\r\n");
            lblResult.Text = total.ToString();
        }
Пример #2
0
 public static void Main(string[] args)
 {
     double total = 0.0d;
     CashContextFactory csuper = new CashContextFactory("Normal");
     double totalPrices = csuper.GetResult(288 * 3);
     total += totalPrices;
     Console.WriteLine("Result3: {0}", total);
 }
Пример #3
0
    public static void Main(string[] args)
    {
        double             total       = 0.0d;
        CashContextFactory csuper      = new CashContextFactory("Normal");
        double             totalPrices = csuper.GetResult(288 * 3);

        total += totalPrices;
        Console.WriteLine("Result3: {0}", total);
    }