Пример #1
0
        private 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;
            }

            var totalPrices = cc.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));

            total = total + totalPrices;
            lbxList.Items.Add("单价:" + txtPrice.Text + " 数量:" + txtNum.Text + " " + cbxType.SelectedItem + " 合计:" + totalPrices);
            lblResult.Text = total.ToString();
        }
Пример #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //利用简单工厂模式根据下拉选择框,生成相应的对象
            CashContext csuper = new CashContext(cbxType.SelectedItem.ToString());
            //通过多态,可以得到收取费用的结果
            var totalPrices = csuper.GetResult(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text));

            total = total + totalPrices;
            lbxList.Items.Add("单价:" + txtPrice.Text + " 数量:" + txtNum.Text + " " + cbxType.SelectedItem + " 合计:" + totalPrices);
            lblResult.Text = total.ToString();
        }
Пример #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            CashContext ccontext    = new CashContext(cbxType.SelectedItem.ToString());
            double      totalPrices = 0.0d;

            totalPrices = ccontext.GetResult(Convert.ToDouble(txt_Price.Text) * Convert.ToDouble(txt_Num.Text));
            total       = total + totalPrices;

            lbxList.Items.Add("单价:" + txt_Price.Text + " 数量: " + txt_Num.Text + " 合计:" + totalPrices.ToString());
            lblResult.Text = total.ToString();
        }
Пример #4
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();
 }
Пример #5
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();
 }
Пример #6
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();
        }
Пример #7
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();
        }