发新话题
打印

非常紧急 ,C#.net高手请帮忙

非常紧急 ,C#.net高手请帮忙

谁会C#.net??
我有东西想向高手请教。

我出现的问题.
当我click  radiobtn $5  和 radiobtn $2  是 我的 A lbl 会显示 $5, B lbl 会显示 $2, C lbl 会 lbl A + lbl B = $ 7.  如果我转去click $10 我的 Albl 就会显示 $10 , 而 Clbl 就会 $5 + $2 + $10 = $17 . 同样的如过 我选回 $5 我的 总数(C lbl ) 就会回到 $5 + $2 + $10 + $5 = $22 ......问题就是我的总数只有加没减....



我想要的是这样。

当我click  radiobtn $5  和 radiobtn $2  是 我的 A lbl 会显示 $5, B lbl 会显示 $2, C lbl 会 lbl A + lbl B = $ 7.  如果我转去click $10 我的 Albl 就会显示 $10 , 而 Clbl 就会 $12 . 同样的如过 我选回 $5 我的 总数(C lbl ) 就会回到 $7.

所有的操作一定不需按任何键,这是最重要的地方

----------------------------------------             -----------------
Radiobtn $5   Radiobtn $10  |           |                |   A label
----------------------------------------             -----------------

----------------------------------------             ------------------
Radiobtn $2   Radiobtn $15  |            |                |   B label
----------------------------------------             ------------------

                           Total                   -------------------  
                                                     |                 |  C label
                                                      ------------------

以下是我的 coding.........谁可以跟我说哪里错,要怎样改
        [STAThread]
                static void Main()
                {
                        Application.Run(new Form1());
                }
                decimal decTotalPrice = 0;
                const decimal
                        decFRENCHFRIESSMALL_PRICE = 1.60M,
                        decFRENCHFRIESMEDIUM_PRICE = 2.20M,
                        decFRENCHFRIESLARGE_PRICE = 3.00M,
                        decBURGERSSMALL_PRICE = 2.25m,
                        decBURGERSMEDIUM_PRICE = 3.10M,
                        decBURGERSLARGE_PRICE = 3.65M,
                        decSALADSSMALL_PRICE = 1.85M,
                        decSALADSMEDIUM_PRICE = 2.35M,
                        decSALADSLARGE_PRICE = 3.40M,
                        decDRINKSSMALL_PRICE = 1.65M,
                        decDRINKSMEDIUM_PRICE = 2.10M,
                        decDRINKSLARGE_PRICE = 2.80M,
                        decCAKESSMALL_PRICE = 2.10M,
                        decCAKESMEDIUM_PRICE = 2.95M,
                        decCAKESLARGE_PRICE = 3.85M;

               
               
                       
                                private void radioBtnSmallFF_CheckedChanged(object sender, System.EventArgs e)
                        {
                                decimal decPrice = 0M;
                                if (radioBtnSmallFF.Checked)
                                {
                                        decPrice = decFRENCHFRIESSMALL_PRICE;
                                        lblFrenchFries.Text = decPrice.ToString("C");
                                        decTotalPrice += decPrice;
                                        lblTotalPrice.Text = decTotalPrice.ToString("C");
                                }
                         
                        }

                        private void radioBtnSmallBG_CheckedChanged(object sender, System.EventArgs e)
                        {
                                decimal decPrice = 0M;
                                if (radioBtnSmallBG.Checked)
                                {
                                        decPrice = decBURGERSSMALL_PRICE;
                                        lblBurgers.Text = decPrice.ToString("C");
                                        decTotalPrice += decPrice;
                                                lblTotalPrice.Text = decTotalPrice.ToString("C");
                                }
                        }

                        private void radioBtnSmallSL_CheckedChanged(object sender, System.EventArgs e)
                        {
                                decimal decPrice = 0M;
                                if (radioBtnSmallSL.Checked)
                                {
                                        decPrice = decSALADSSMALL_PRICE;
                                        lblSalads.Text = decPrice.ToString("C");
                                        decTotalPrice += decPrice;
                                        lblTotalPrice.Text = decTotalPrice.ToString("C");
                                }
                        }

                        private void radioBtnSmallDR_CheckedChanged(object sender, System.EventArgs e)
                        {
                                decimal decPrice = 0M;
                                if (radioBtnSmallDR.Checked)
                                {
                                        decPrice = decDRINKSSMALL_PRICE;
                                        lblDrinks.Text = decPrice.ToString("C");
                                        decTotalPrice += decPrice;
                                        lblTotalPrice.Text = decTotalPrice.ToString("C");
                                }
                        }

               
       

                private void radioBtnSmallCK_CheckedChanged(object sender, System.EventArgs e)
                {
                        decimal decPrice = 0M;
                        if (radioBtnSmallCK.Checked)
                        {
                                decPrice = decCAKESSMALL_PRICE;
                                lblCakes.Text = decPrice.ToString("C");
                                decTotalPrice += decPrice;
                                lblTotalPrice.Text = decTotalPrice.ToString("C");
                        }
                }

[ 本帖最后由 vzhen 于 10-4-2007 15:00 编辑 ]

TOP

总的来说。。
你按 Radio $5,Label A 就变 $5
你按 Radio $2,Label B 就变 $2
Label C 就变 Label A + Label B ,是要这样吗?

我不懂 C#,但语法差不多,大概可以改。
首先请你告诉我,radioBtnSmallFF,radioBtnSmallBG,radioBtnSmallSL,radioBtnSmallDR 和 radioBtnSmallCK
是对应你例子里面的哪个 radio ?

你的例子只给四个 radio,可是 coding 却有 5 个。。。

TOP

引用:
原帖由 劍贼啊爸 于 10-4-2007 15:18 发表
总的来说。。
你按 Radio $5,Label A 就变 $5
你按 Radio $2,Label B 就变 $2
Label C 就变 Label A + Label B ,是要这样吗?

我不懂 C#,但语法差不多,大概可以改。
首先请你告诉我,radioBtnSmall ...
我的例子只是coding 里的一部分。
而我的coding 是我功课里的一部分而已。

你就把 radioBtnSmallFF 当作 $5
radioBtnSmallGB 当作 $10
radioBtnSmallSL 当作$2
radioBtnSmallDR  当作 $20

记得重点是直接显示出来,不需要click任何button 去操作。

谢谢

TOP

引用:
原帖由 vzhen 于 10-4-2007 15:24 发表


我的例子只是coding 里的一部分。
而我的coding 是我功课里的一部分而已。

你就把 radioBtnSmallFF 当作 $5
radioBtnSmallGB 当作 $10
radioBtnSmallSL 当作$2
radioBtnSmallDR  当作 $20

记得重 ...
原来只是一部分。。。
难怪。。

你遇到的问题是你的总数只有加没减吧?
那是肯定的。。从你的 coding  上面,你就是有 tick 到就加。。
当然就一直加下去咯。。

问你一个问题,当 radioBtnSmallFF 有 tick 的时候,decPrice 一定是等于 decFRENCHFRIESSMALL_PRICE 的 value 吗?
如果是的话,全部改成这样试试看。

private void radioBtnSmallFF_CheckedChanged(object sender, System.EventArgs e)
{
 decimal decPrice = decFRENCHFRIESSMALL_PRICE;
 if (radioBtnSmallFF.Checked){
   decTotalPrice += decPrice;
 }else{
   decTotalPrice -= decPrice;
 }
 lblFrenchFries.Text = decPrice.ToString("C");
 lblTotalPrice.Text = decTotalPrice.ToString("C");
}

其他的食物照跟这样。


[ 本帖最后由 劍贼啊爸 于 10-4-2007 15:40 编辑 ]

TOP

 
不好意思,没有回复你的短消息。。
我觉得与其用短消息讨论,不如公开让大家一起讨论会更好。
集思广益,可能会有人有更好的方法。
引用:
我解决到了,谢谢你的帮忙

现在是另一个问题
比如,有一架机器要找回 $80 给你
然后那架机器就会有这样的 显示。

Total $80
$50 -------  1
$10 -------- 3

你明白吗??
这样的coding 要怎样写。。。。
简单来说就是找钱的机器吧?
你的这个作业是做自动点菜系统?

本身还没有解过自动找钱的,可以一起来思考一下。
先来说说我的思路:

首先找出找回的钱的总数的所在币值范围,
币值范围设 $100,$50,$10,$5,$1

然后把 x 值带进去。
x 值减去币值范围最大值之后整除币值范围所在最大值。
除得完的就计算加1,除不完继续相减去币值范围最大值,以此类推。
就可以求出找回钱币的数目了。

PHP 底下是这么写,你要自己转成 C#....逻辑一样,语法不同而已。。
复制内容到剪贴板
代码:
<?php

$returnType  = array('100', '50', '10', '5', '1');
$returnAns   = array();

$x = $_GET['x'];

echo "Change: $".$x."<br><br><table>";

for($i = 0; $i < count($returnType); $i++)
{
        $num    = $x % $returnType[$i];
        $returnAns[$i] = ($x - $num) / $returnType[$i];
        $x      = $x - $returnAns[$i] * $returnType[$i];

        echo "<tr><td>$".$returnType[$i]."</td><td>= ".$returnAns[$i]."</td></tr>";
}

echo "</table>";

?>
演示看这里:

http://file.e-dyn.com/calc.php?x=86

x=86是模拟找回的钱是 $86,你可以自己换掉它。

先说明,不包括小数点,小数点你要自己想。。逻辑给你了。。


[ 本帖最后由 劍贼啊爸 于 10-4-2007 23:05 编辑 ]

TOP

发新话题