在ASP.NET中运行的应用程序没有提供所需的输出

时间:2016-01-07 17:33:12

标签: c# asp.net

我有一个应用程序没有正确计算百分比。假设以百分比计算输入。但是某个地方存在阻止它这样做的错误。

例如,如果我输入任何以小数开头的数字,如0.010.0010.02等,它会输出10.12分别。如果我打入12310等任何整数,它将始终提供相同的输出,即0.01

这个应用程序是由一些承包商在5年前完成的。这个应用程序的主要负责人已离开。这让我和我在c#和asp.net中的经验很难搞清楚。在我寻求任何进一步的帮助之前,我想我应该问那些天才并看看他们要说些什么,也许我会在你的帮助下找出问题所在。我确实与我所在部门的其他IT人员交谈,他们猜测这可能是因为下面的代码。

    if (int.TryParse(string.IsNullOrEmpty(txtminup.Text) ? "0" : txtminup.Text, out n))

我不是100%确定如何调试或发现问题。如果有人可以指出任何可能有用的东西或为我提供一些我可以查找的资源,那将非常有帮助。我复制了几行代码。我可以提供更多信息,但不知道哪一个更相关。

    protected string MinUp
{
    get
    {
        return (string)ViewState["minup"];
    }
    set
    {
        ViewState["minup"] = value;
    }
}

==============

  MinUp = rows["process_minimum_up"].ToString();
                        PIMSSource = rows["pims_source"].ToString();
                        //MinUp = Convert.ToDouble()
                        if (MinUp != string.Empty || MinUp.Length > 0)
                        {
                            MinUp = Convert.ToString(Convert.ToDouble(MinUp) * 100);
                        }     

=====================

    if (DCFoption != "P")
        {
            MinUp = "";
        }

        if (DcfmSeq != "0")
        {
            int caret;
            caret = ddlvbcfmseq.SelectedValue.IndexOf("^");
            DcfmSeq = DcfmSeq.Substring(0, caret);
        }

        if (DCFoption != "P" && ddlpdwnlst.SelectedItem.Value == "0")
        {
            MinUp = "";
        }

        if (PIMSTagId == "Not specified")
        {
            PIMSTagId = "";
        }

        if (MinUp != string.Empty || MinUp.Length > 0)
        {
            int n;
            if (int.TryParse(string.IsNullOrEmpty(txtminup.Text) ? "0" : txtminup.Text, out n))
            {
                MinUp = Convert.ToString(Convert.ToInt32(MinUp) / 100);
                if (Convert.ToInt32(MinUp) < 0)
                {
                    MinUp = "0";
                }
                else if (Convert.ToInt32(MinUp) > 1)
                {
                    MinUp = "1";
                }
            }
        }

        if ((DCFoption == string.Empty || DCFoption.Length < 1) || DCFoption == "D")
        {
            MinUp = "";
        }

        if (MinUp != string.Empty || MinUp.Length > 0)
        {
            int n;
            if (int.TryParse(string.IsNullOrEmpty(txtminup.Text) ? "0" : txtminup.Text, out n))
            {
              if (Convert.ToDouble(MinUp) <= 0)
              {
                  MinUp = ".0001";
              }
            }
        }

=======================

    if (rdbProcess.Checked == true && (txtminup.Text == string.Empty || txtminup.Text.Length < 1) && ddlpdwnlst.SelectedItem.Value == "0")
                                                            {
                                                                Utilities.ShowAlert(this.Page, Resources.Resource.RIPimsUpload_MinUptime.ToString());
                                                                txtminup.Focus();

======================

    int n;
                                                                        if (!int.TryParse(string.IsNullOrEmpty(txtRound.Text) ? "0" : txtRound.Text, out n))
                                                                        {
                                                                            Utilities.ShowAlert(this.Page, Resources.Resource.RIPimsUpload_RoundingNum.ToString());
                                                                        }
                                                                        else if (!IsDouble(txtminup.Text))

======================

    try
    {
        DBResults objDBResult = new DBResults();
        WEIS.RIPimsUpload objRI = new WEIS.RIPimsUpload();
        objDBResult = objRI.SaveItemInsert(reciseq, shortname, name, eiscprocess2, period, media, euseq, eqmtseq, eiscuom, pollseq, dcfmseq, rounding, formula, physmin, physmax, warn1min, warn1max, warn2min, warn2max, pimsStatus, pimsTagidp, datapoint, freq, periodoffset, initpimstTagId, initDataPoint, initLoadFrequency, initperiodoffset, day0result, retention, audituser, dcfoption, minup, pimssource);

        if (objDBResult.oraErrMsg.Trim().ToString().Length > 1)
        {
            Exception ex = new Exception(objDBResult.oraErrMsg.ToString());
            throw ex;
        }

        return objDBResult.oraIntReturn;
    }

===============================

    protected int SaveItemUpdate(int reciseq, string shortname, string name, int eiscprocess2, int period, int media, int euseq, int eqmtseq, int eiscuom, int pollseq, int dcfmseq, string rounding, string formula, string physmin, string physmax, string warn1min, string warn1max, string warn2min, string warn2max, string pimsStatus, string pimsTagidp, string datapoint, string freq, char periodoffset, string initpimstTagId, char initDataPoint, char initLoadFrequency, char initperiodoffset, string day0result, string retention, string audituser, string dcfoption, string minup, string pimssource)
{
    try
    {
        DBResults objDBResult = new DBResults();
        WEIS.RIPimsUpload objRI = new WEIS.RIPimsUpload();
        objDBResult = objRI.SaveItemUpdate(reciseq, shortname, name, eiscprocess2, period, media, euseq, eqmtseq, eiscuom, pollseq, dcfmseq, rounding, formula, physmin, physmax, warn1min, warn1max, warn2min, warn2max, pimsStatus, pimsTagidp, datapoint, freq, periodoffset, initpimstTagId, initDataPoint, initLoadFrequency, initperiodoffset, day0result, retention, audituser, dcfoption, minup, pimssource);

        if (objDBResult.oraErrMsg.Trim().ToString().Length > 1)
        {
            Exception ex = new Exception(objDBResult.oraErrMsg.ToString());
            throw ex;
        }

=============================

    protected void btnSave_Click(object sender, EventArgs e)
{
    try
    {
        lblUserMsgText.Text = "";
        bool dcfm = ddlvbcfmseq.Enabled;
        string minup, dcfoption="";

        minup = txtminup.Text;

        if (rdbNone.Checked == true)
        {
            dcfoption = "NONE";
        }
        else if (rdbProcess.Checked == true)
        {
            dcfoption = "P";
        }
        else if (rdbData.Checked == true)
        {
            dcfoption = "D";
        }

        Index = Convert.ToInt32(rdbListradios.SelectedIndex);

        SaveItem();

        RetainClientControlValues(dcfm, dcfoption, minup);
    }

==============================

    protected void btnExcMod_Click(object sender, EventArgs e)
{
    try
    {
        lblUserMsgText.Text = "";
        bool dcfm = ddlvbcfmseq.Enabled;
        string minup, dcfoption = "";
        Index = Convert.ToInt32(rdbListradios.SelectedIndex);
        minup = txtminup.Text;

        if (rdbNone.Checked == true)
        {
            dcfoption = "NONE";
        }
        else if (rdbProcess.Checked == true)
        {
            dcfoption = "P";
        }
        else if (rdbData.Checked == true)
        {
            dcfoption = "D";
        }

        Button btn = (Button)sender;
        int evntseq = Convert.ToInt32(btn.CommandArgument.ToString());

        RetainClientControlValues(dcfm, dcfoption, minup);
        //Response.Write("you clicked on button");
    }

1 个答案:

答案 0 :(得分:0)

@Umamaheswaran感谢提示。

    int n;
    if (int.TryParse(string.IsNullOrEmpty(txtminup.Text) ? "0" : txtminup.Text, out n))

以上是初始代码,我将其更改为

     double n;
    if (double.TryParse(string.IsNullOrEmpty(txtminup.Text) ? "0" : txtminup.Text, out n))

以及它转换为

的时候
   Convert.ToInt32

我把它改成了

    Convert.ToDouble 

我不知道是什么问题,因为我对asp.net和c#不是很熟悉,但改变上面的代码解决了这个问题。现在每当我输入一个数字时,它将变为百分比并将其保存为正确的格式。

谢谢大家的帮助和关注。我有几个不同的问题。我会尝试解决它,如果不是我会在这里发布,并试图简明扼要。