我用VB6编写的旧应用程序从Oracle数据库表中检索数据并在Grid中显示。我试图使用C#实现相同但失败了。
基本思路是......网格具有一定的固定行,从前2列中的产品详细信息开始,然后是产品等级。每次填充网格后,我都会检查产品是否已更改..如果没有,则继续填充相同的行,当产品与之前的产品不同时,请转到下一行,依此类推,直到数据完成。
这在VB6中运行得非常好,但是我无法在C#中实现相同的功能。
请帮助我!!
提前致谢
RGDS 谢卡尔
string l_merge = string.Empty;
string l_grade = string.Empty;
string l_pack = string.Empty;
string l_usage = string.Empty;
string l_spool=string.Empty;
string strSQL = string.Empty;
int rowNumber = 1;
double boxes = 0;
double aEven = 0;
double aUnEven = 0;
double bGrade = 0;
double cGrade = 0;
double ap3UnEven = 0;
double ap7UnEven = 0;
double rowTotal = 0;
try
{
if (rbtBoxWise.Checked)
{
using (DataBaseConnection dbConn = new DataBaseConnection(this._dsn, this._username, this._password))
{
strSQL = "Select MERGE, DENIER, GRADECODE, SPOOLCODE, USAGEFLAG, COUNT(BOXNUMBER) As Boxes " +
"From TBL_BOXINHAND Where PRODUCTCODE='D' " +
"Group By MERGE, DENIER, GRADECODE, SPOOLCODE, USAGEFLAG " +
"Order By MERGE, DENIER, GRADECODE, SPOOLCODE, USAGEFLAG";
OracleDataReader orReader = dbConn.ExecuteReader(strSQL);
if (orReader != null && orReader.HasRows)
{
dtyStock.Rows = 1;
while (orReader.Read())
{
dtyStock.Rows = dtyStock.Rows + 1;
dtyStock.Cell(rowNumber, 1).Text = orReader["MERGE"].ToString();
dtyStock.Cell(rowNumber, 2).Text = orReader["DENIER"].ToString();
//dtyStock.Cell(rowNumber, 3).Text = "DTY - " + orReader["ILTYPE"].ToString() + " - " + orReader["LUSTURE"].ToString() + " - " + orReader["HEATER"].ToString();
l_merge = orReader["MERGE"].ToString();
do
{
l_grade = orReader["GRADECODE"].ToString();
l_usage = orReader["USAGEFLAG"].ToString();
l_spool = orReader["SPOOLCODE"].ToString();
if (l_grade.StartsWith("A") && l_usage.StartsWith("E") && l_spool != "P3" && l_spool != "P7")
{
aEven = aEven + double.Parse(orReader["Boxes"].ToString());
dtyStock.Cell(rowNumber, 4).Text = aEven.ToString();
rowTotal = rowTotal + double.Parse(orReader["Boxes"].ToString());
}
else if (l_grade.StartsWith("A") && l_usage.StartsWith("L") && l_spool != "P3" && l_spool != "P7")
{
aUnEven = aUnEven + double.Parse(orReader["Boxes"].ToString());
dtyStock.Cell(rowNumber, 5).Text = aUnEven.ToString();
rowTotal = rowTotal + double.Parse(orReader["Boxes"].ToString());
}
else if (l_grade.StartsWith("A") && l_usage.StartsWith("L") && l_spool == "P3" && l_spool != "P7")
{
ap3UnEven = ap3UnEven + double.Parse(orReader["Boxes"].ToString());
dtyStock.Cell(rowNumber, 6).Text = ap3UnEven.ToString();
rowTotal = rowTotal + double.Parse(orReader["Boxes"].ToString());
}
else if (l_grade.StartsWith("A") && l_usage.StartsWith("L") && l_spool != "P3" && l_spool == "P7")
{
ap7UnEven = ap7UnEven + double.Parse(orReader["Boxes"].ToString());
dtyStock.Cell(rowNumber, 7).Text = ap7UnEven.ToString();
rowTotal = rowTotal + double.Parse(orReader["Boxes"].ToString());
}
else if (l_grade.StartsWith("B"))
{
bGrade = bGrade + double.Parse(orReader["Boxes"].ToString());
dtyStock.Cell(rowNumber, 8).Text = bGrade.ToString();
rowTotal = rowTotal + double.Parse(orReader["Boxes"].ToString());
}
else if (l_grade.StartsWith("C"))
{
cGrade = cGrade + double.Parse(orReader["Boxes"].ToString());
dtyStock.Cell(rowNumber, 9).Text = cGrade.ToString();
rowTotal = rowTotal + double.Parse(orReader["Boxes"].ToString());
}
if (orReader != null && orReader.HasRows)
{
orReader.Read();
if (l_merge != orReader["MERGE"].ToString())
{
dtyStock.Cell(rowNumber, 10).Text = rowTotal.ToString();
rowNumber++;
boxes = 0;
aEven = 0;
aUnEven = 0;
bGrade = 0;
cGrade = 0;
ap3UnEven = 0;
ap7UnEven = 0;
rowTotal = 0;
break;
}
}
}
while (orReader.HasRows);
if (!orReader.HasRows)
{
dtyStock.Cell(rowNumber, 10).Text = rowTotal.ToString();
rowNumber++;
boxes = 0;
aEven = 0;
aUnEven = 0;
bGrade = 0;
cGrade = 0;
ap3UnEven = 0;
ap7UnEven = 0;
rowTotal = 0;
break;
}
}
}
else
{
strSQL = string.Empty;
MessageBox.Show(this, "Nothing is packed between selected period!!", "Empty Records", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
refreshAll(this);
}
orReader.Close();
}
}
else if (rbtNetWt.Checked)
{
using (DataBaseConnection dbConn = new DataBaseConnection(this._dsn, this._username, this._password))
{
strSQL = "Select MERGE, DENIER, TWIST, LUSTURE, ILTYPE, HEATER, GRADECODE, PACKINGTYPECODE,SPOOLCODE, USAGEFLAG, SUM(NETWT) " +
"From TBL_BOXINHAND Where PRODUCTCODE='D' Order By MERGE " +
"Group By MERGE, DENIER, TWIST, LUSTURE, ILTYPE, HEATER, GRADECODE, PACKINGTYPECODE,SPOOLCODE, USAGEFLAG";
OracleDataReader orReader = dbConn.ExecuteReader(strSQL);
if (orReader != null && orReader.HasRows)
{
dtyStock.Rows = 1;
while (orReader.Read())
{
}
}
else
{
strSQL = string.Empty;
MessageBox.Show(this, "Nothing is packed between selected period!!", "Empty Records", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
refreshAll(this);
}
orReader.Close();
}
}
else
{
strSQL = string.Empty;
MessageBox.Show(this, "Please choose either Box Wise or Net Wt Wise to continue!!", "Invalid Choice", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}