Esempio n. 1
0
        double total = 0.0d;//用於總計
        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;
            }

            double totalPrices = 0d;

            totalPrices = cc.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
            total       = total + totalPrices;
            lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " " + cbxType.SelectedItem + " 合計:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }
Esempio n. 2
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     //利用簡單工廠模式根據下拉選擇框,生成相應的物件
     CashContext csuper = new CashContext(cbxType.SelectedItem.ToString());
     double totalPrices = 0d;
     //透過多型,可以得到收取費用的結果
     totalPrices = csuper.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
     total = total + totalPrices;
     lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " "
         + cbxType.SelectedItem + " 合計:" + totalPrices.ToString());
     lblResult.Text = total.ToString();
 }
Esempio n. 3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //利用簡單工廠模式根據下拉選擇框,生成相應的物件
            CashContext csuper      = new CashContext(cbxType.SelectedItem.ToString());
            double      totalPrices = 0d;

            //透過多型,可以得到收取費用的結果
            totalPrices = csuper.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
            total       = total + totalPrices;
            lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " "
                              + cbxType.SelectedItem + " 合計:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }
Esempio n. 4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            CashContext cc = new CashContext();
            //根據用戶的選項,查詢用戶選擇項的相關行
            DataRow dr = ((DataRow[])ds.Tables[0].Select("name='" + cbxType.SelectedItem.ToString()+"'"))[0];
            //聲明一個參數的物件陣列
            object[] args =null;
            //若有參數,則將其分割成字串陣列,用於實體化時所用的參數
            if (dr["para"].ToString() != "")
                args = dr["para"].ToString().Split(',');
            //透過反射實例化出相應的演算法物件
            cc.setBehavior((CashSuper)Assembly.Load("商場管理軟體").CreateInstance("商場管理軟體." + dr["class"].ToString(), false, BindingFlags.Default, null, args, null, null));

            double totalPrices = 0d;
            totalPrices = cc.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
            total = total + totalPrices;
            lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " "+cbxType.SelectedItem+ " 合計:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }
Esempio n. 5
0
        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;
            }

            double totalPrices = 0d;
            totalPrices = cc.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
            total = total + totalPrices;
            lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " " + cbxType.SelectedItem + " 合計:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }
Esempio n. 6
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            CashContext cc = new CashContext();
            //根據用戶的選項,查詢用戶選擇項的相關行
            DataRow dr = ((DataRow[])ds.Tables[0].Select("name='" + cbxType.SelectedItem.ToString() + "'"))[0];

            //聲明一個參數的物件陣列
            object[] args = null;
            //若有參數,則將其分割成字串陣列,用於實體化時所用的參數
            if (dr["para"].ToString() != "")
            {
                args = dr["para"].ToString().Split(',');
            }
            //透過反射實例化出相應的演算法物件
            cc.setBehavior((CashSuper)Assembly.Load("商場管理軟體").CreateInstance("商場管理軟體." + dr["class"].ToString(), false, BindingFlags.Default, null, args, null, null));

            double totalPrices = 0d;

            totalPrices = cc.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));
            total       = total + totalPrices;
            lbxList.Items.Add("單價:" + txtPrice.Text + " 數量:" + txtNum.Text + " " + cbxType.SelectedItem + " 合計:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }