未获得总金额(不含增值税)

时间:2018-01-19 10:19:03

标签: c#

Country: Bahrain( i am selecting)
Amount:1000
Bank charges: 100(i am entering)
Vat:5%(entering)            result:50(autogenerate)
Discount:6%(entering)        result:60(autogenerate)
Total:1070(autogenerate)

这很正常。我得到总计(含增值税)。

    Country:India(i am selecting)
    Amount:1000
    Bank charges: 100(i am entering)
    Discount:5%(entering)        result:50(autogenerate)
    Total:(here i am not getting the amount)(may be because i set the visibility of VAT field false)

我在这里使用vattr.Visible = false来隐藏增值税。我该怎么办才能解决这个问题?

代码背后:

protected void lstCountryy_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (lstCountryy.SelectedItem.Text == "U.A.E" || lstCountryy.SelectedItem.Text == "BAHRAIN" || lstCountryy.SelectedItem.Text=="SAUDI ARABIA")
        {

            vattr.Visible = true;
            trdeclaration.Visible = false;

        }
        else
        {

            vattr.Visible = false;
            trdeclaration.Visible = true;
        }
    }

使用Javascript:

function calculate(amount) {
            var bankcharge = document.getElementById("<%=txtBankCharge.ClientID%>").value;
            var vat = document.getElementById("<%=txtvatt.ClientID%>").value;
          var discount = document.getElementById("<%=txtDiscount.ClientID%>").value;

            var sum = 0;

            $(".amt").each(function () {

                if  (isNaN(this.value))
                {
                    alert("Please enter numbers only");
                    return false;
                }

                if (!isNaN(this.value) && this.value.length != 0) {
                    sum += parseFloat(this.value);

                }

            });


            if (bankcharge.length > 0) {
                if (isNaN(bankcharge)) {
                    alert("Bank charge should be numbers only !!");
                    return false;
                }
                else {
                    sum = sum + parseFloat(bankcharge);
                }
            }

            if (vat.length > 0)
            {
                if (isNaN(vat)) {
                    alert("VAT should be numbers only !!");
                    return false;
                }
                else {
                    sum = sum + parseFloat(vat);
                }
            }


            if (discount.length > 0) {
                if (isNaN(discount)) {
                    alert("Discount amount should be numbers only !!");
                    return false;
                }
                else {
                    sum = sum - parseFloat(discount);
                }
            }
            var atemp = sum.toString().split(".");
            if (atemp.length > 1) {
                sum = sum.toFixed(2);
            }
             document.getElementById("<%=txtTotal.ClientID%>").value = sum;
            document.getElementById("<%=txtAmountInWords.ClientID%>").value = convertNumberToWords(sum);
        }



        function vatCalc()//added by chetan
        {
            var sum = 0;

            $(".amt").each(function () {

                if (isNaN(this.value)) {
                    alert("Please enter numbers only");
                    return false;
                }

                if (!isNaN(this.value) && this.value.length != 0) {
                    sum += parseFloat(this.value);

                }

            });

        var _txt2 = document.getElementById('<%= txtvat.ClientID %>');
        var _txt3 = document.getElementById('<%= txtvatt.ClientID %>');
        var t1=0, t2=0;

        //if(_txt1.value != "") t1=_txt1.value;
        if(_txt2.value != "") t2=_txt2.value;

        _txt3.value = (sum * parseFloat(t2) )/ 100;

        }

        function discountCalc()
        {
             var sum = 0;

            $(".amt").each(function () {

                if (isNaN(this.value)) {
                    alert("Please enter numbers only");
                    return false;
                }

                if (!isNaN(this.value) && this.value.length != 0) {
                    sum += parseFloat(this.value);

                }

            });

        var _txt2 = document.getElementById('<%= txtDiscountText.ClientID %>');
        var _txt3 = document.getElementById('<%= txtDiscount.ClientID %>');
        var t1=0, t2=0;

        //if(_txt1.value != "") t1=_txt1.value;
        if(_txt2.value != "") t2=_txt2.value;

        _txt3.value = (sum * parseFloat(t2)) / 100;

        }

问题在于:

 if (vat.length > 0)
            {
                if (isNaN(vat)) {
                    alert("VAT should be numbers only !!");
                    return false;
                }
                else {
                    sum = sum + parseFloat(vat);
                }
            }

我想以这样的方式写这个条件:当使用选择bahrain时,vat应该是可见的并且应该被计算。 当用户选择印度时,应该隐藏增值税并产生总金额。

1 个答案:

答案 0 :(得分:0)

最后我得到了解决方案。这完美无缺。

 if (lstCountryy.SelectedValue == "U.A.E" || lstCountryy.SelectedValue == "BAHRAIN" || lstCountryy.SelectedValue == "SAUDI ARABIA")
                {


                    txtvat.Text = "";
                    txtvatt.Text = "";
                    txtBankCharge.Text = "";
                    txtDiscount.Text = "";
                    txtDiscountText.Text = "";
                    txtTotal.Text = "";

                    vattr.Style.Add("display", "float");
                    trdeclaration.Visible = false;

                    //txtvat.Enabled = true;

                }
                else
                {
                    txtvat.Text = "";
                    txtvatt.Text = "";
                    txtBankCharge.Text = "";
                    txtDiscount.Text = "";
                    txtDiscountText.Text = "";
                    txtTotal.Text = "";


                    vattr.Style.Add("display", "none");



                    trdeclaration.Visible = true;
                }