在ASP.NET中运行的应用程序没有提供所需的输出
本文关键字:输出 应用程序 NET ASP 运行 | 更新日期: 2023-09-27 18:29:27
我有一个应用程序没有正确计算百分比。假设以百分比计算输入。但有一个错误正在阻止它这样做
例如,如果我输入任何以小数开头的数字,如0.01
、0.001
或0.02
等,它将分别给我输出1
、0.1
和2
。如果我输入任何整数,如1
、2
、3
、10
等,它将始终给出相同的输出,即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");
}
@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#不是很熟悉,但修改上面的代码解决了问题。现在,每当我输入一个数字时,它都会变为百分比,并将其保存为正确的格式。
感谢大家的帮助和关心。我还有一些不同的问题。我会努力解决它,如果不是的话,我会把它贴在这里,尽量简明扼要。