当我在调试模式下运行代码时,我得到了正确的结果,但是当我在没有调试的情况下运行它时,我得到了意想不到的结果。
有两个文件 MAIN 和 class 文件,从 MAIN 文件我调用
MatrixIncome
函数,它写在如下所示的类文件中。
我试过在有调试和没有调试的两种模式下运行代码,每次在调试模式下运行我都会得到正确的输出,但是在没有调试的情况下运行时我得到了意想不到的结果。
我不知道我错过了什么。
MAIN文件:
_sCon.Open();
_sCmd = new SqlCommand();
_sTr = _sCon.BeginTransaction();
_sCmd.Transaction = _sTr;
try
{
string userId = "00001";
double amount = 160;
pln.MatrixIncome(userId, amount, _sCon, _sTr);
_sTr.Commit();
AlertMessage("Activation successfully submitted!");
}
catch (Exception ex)
{
AlertMessage(ex.ToString());
_sTr.Rollback();
return;
}
finally
{
_sCon.Close();
}
班级文件:
public void MatrixIncome(string id, double amount, SqlConnection _sCon, SqlTransaction _sTr)
{
if (id == "")
{
return;
}
string type = amount.ToString("F0");
string mainId = "";
string fetchSponsorPool = "select * from MatrixInfo" + type + " where _userId='" + id + "'";
_sCmd = new SqlCommand(fetchSponsorPool, _sCon, _sTr);
SqlDataReader sRdr = _sCmd.ExecuteReader();
if (sRdr.HasRows)
{
sRdr.Read();
mainId = sRdr["_mainId"].ToString().ToUpper();
}
else
{
mainId = id;
}
sRdr.Close();
_sCmd = null;
DateTime requestDate = DateTime.UtcNow.AddHours(2);
double amountPercent = amount * 6.25 / 100;
string parent = "";
string sponsorMainId = "";
string joiningType = "";
string matrixId = "";
id = id.ToUpper();
fetchSponsorPool = "select * from MatrixInfo" + type + " where _directCount < 2 order by _id ASC";
_sCmd = new SqlCommand(fetchSponsorPool, _sCon, _sTr);
sRdr = _sCmd.ExecuteReader();
sRdr.Read();
matrixId = sRdr["_tableId"].ToString().ToUpper();
parent = sRdr["_userId"].ToString().ToUpper();
sponsorMainId = sRdr["_mainId"].ToString().ToUpper();
string aId = sRdr["_aId"].ToString().ToUpper();
string bId = sRdr["_bId"].ToString().ToUpper();
sRdr.Close();
if (aId == "")
{
joiningType = "A";
}
else if (bId == "")
{
joiningType = "B";
}
if (parent != "")
{
string updateLeftChildQuery = "";
string updateParentQuery = "";
string insertMatrix = "";
string desc = "";
string insertWalletInfo = "";
string head = "matrix" + type;
string mainIdId = "";
switch (joiningType)
{
case "A":
id = GenerateIdMatrix(type, _sCon, _sTr);
mainIdId = GetMainId(mainId, _sCon, _sTr);
insertMatrix = "insert into MatrixInfo" + type + " values("
+ "'" + type + "',"
+ "'" + id + "',"
+ "'" + parent + "',"
+ "'',"
+ "'',"
+ "'False',"
+ "0, '" + mainIdId + "','" + matrixId + "')";
_sCmd = new SqlCommand(insertMatrix, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
string mainIdPay = GetMainId(sponsorMainId, _sCon, _sTr);
desc = "Matrix Income credited";
insertWalletInfo = "insert into WalletInfo values("
+ "'" + mainIdPay + "',"
+ "'" + requestDate + "',"
+ "'CREDIT',"
+ "'" + amountPercent + "',"
+ "'working',"
+ "'" + desc + "',"
+ "'" + head + "',"
+ "'True',"
+ "'" + requestDate + "','" + amountPercent + "','" + amountPercent + "')";
_sCmd = new SqlCommand(insertWalletInfo, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
updateLeftChildQuery = "update MatrixInfo" + type + " set _aId='" + id + "', _directCount=_directCount+1 where _userId='" + parent + "'";
_sCmd = new SqlCommand(updateLeftChildQuery, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
updateParentQuery = "update MatrixInfo" + type + " set _upline='" + parent + "' where _userId='" + id + "'";
_sCmd = new SqlCommand(updateParentQuery, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
break;
case "B":
id = GenerateIdMatrix(type, _sCon, _sTr);
mainIdId = GetMainId(mainId, _sCon, _sTr);
insertMatrix = "insert into MatrixInfo" + type + " values("
+ "'" + type + "',"
+ "'" + id + "',"
+ "'" + parent + "',"
+ "'',"
+ "'',"
+ "'False',"
+ "0, '" + mainIdId + "','" + matrixId + "')";
_sCmd = new SqlCommand(insertMatrix, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
updateLeftChildQuery = "update MatrixInfo" + type + " set _bId='" + id + "', _directCount=_directCount+1 where _userId='" + parent + "'";
_sCmd = new SqlCommand(updateLeftChildQuery, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
updateParentQuery = "update MatrixInfo" + type + " set _upline='" + parent + "' where _userId='" + id + "'";
_sCmd = new SqlCommand(updateParentQuery, _sCon, _sTr);
_sCmd.ExecuteNonQuery();
_sCmd = null;
if (parent != "")
{
MatrixIncome(parent, amount, _sCon, _sTr);
}
break;
}
}
}
MatrixInfo160
CREATE TABLE [dbo].[MatrixInfo160]
(
[_id] [bigint] IDENTITY(1,1) NOT NULL,
[_matrixName] [varchar](50) NULL,
[_userId] [varchar](250) NULL,
[_upline] [varchar](250) NULL,
[_aId] [varchar](250) NULL,
[_bId] [varchar](250) NULL,
[_upgraded] [bit] NULL,
[_directCount] [int] NULL,
[_mainId] [varchar](250) NULL,
[_tableId] [int] NULL,
CONSTRAINT [PK_MatrixInfo160] PRIMARY KEY CLUSTERED
(
[_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO