-
August 2nd, 2010, 06:37 AM
#1
Please help to write common method
I wrote 2 methods to get the list of menu items
the two methods are:
Code:
public List<string> GetListOfFavoriteReports()
{
bool hasFavoriteReports = false;
bool result;
List<string> lstMenuItems = null;
string sql = string.Empty;
if (AccessManager.allowExtensions())
sql = "SELECT seqid, name, description, menuid FROM rptdefn, baserpt WHERE baserpt.rptid=rptdefn.rptid AND favorite='T' AND AppID={0} AND CompanyID={1} ORDER BY name";
else
sql = "SELECT seqid, name, description, menuid FROM rptdefn, baserpt WHERE baserpt.rptid=rptdefn.rptid AND favorite='T' AND AppID={0} AND CompanyID={1} AND SeqID=0 ORDER BY name";
sql = string.Format(sql, CommonFunctions.NewApplicationID,
FASGlobalSystem.GetFASGlobalSystem().DBCompany.CompanyID.ToString());
INetbpDynamicODBCBuffer cursor = FASGlobalSystem.GetFASGlobalSystem().DBCompany.CompanyDB.CreateResultset();
cursor.AllowUpdating = false; // Only need to read
cursor.CursorType = bpDbmsCursorType.dbCursStatic; // Must be static for this to work
cursor.Initialize(FASGlobalSystem.GetFASGlobalSystem().DBCompany.CompanyDB, sql, 30);
cursor.First(); // Move to first row
while (cursor.LastError() == bpDynErrors.bpDynNoError)
{
int seqID = (int)cursor.GetInt(0);
if (lstMenuItems == null)
{
lstMenuItems = new List<string>();
}
lstMenuItems.Add((string)cursor.GetBSTR(1));
hasFavoriteReports = true;
cursor.Next(1);
result = cursor.LastError() == bpDynErrors.bpDynNoError;
}
if (!hasFavoriteReports)
{
if (lstMenuItems == null)
{
lstMenuItems = new List<string>();
}
lstMenuItems.Add("<no favorites>");
}
return lstMenuItems;
}
&
public List<string> GetListOfCustomizedReports()
{
bool hasCustomizedReports = false;
bool result;
List<string> lstMenuItems = null;
string sql = string.Empty;
sql = "SELECT seqid, name, description, menuid FROM rptdefn, baserpt WHERE baserpt.rptid=rptdefn.rptid AND AppID={0} AND CompanyID={1} AND SeqID>0 ORDER BY name";
sql = string.Format(sql, CommonFunctions.NewApplicationID,
FASGlobalSystem.GetFASGlobalSystem().DBCompany.CompanyID.ToString());
INetbpDynamicODBCBuffer cursor = FASGlobalSystem.GetFASGlobalSystem().DBCompany.CompanyDB.CreateResultset();
cursor.AllowUpdating = false; // Only need to read
cursor.CursorType = bpDbmsCursorType.dbCursStatic; // Must be static for this to work
cursor.Initialize(FASGlobalSystem.GetFASGlobalSystem().DBCompany.CompanyDB, sql, 30);
cursor.First(); // Move to first row
while (cursor.LastError() == bpDynErrors.bpDynNoError)
{
int seqID = (int)cursor.GetInt(0);
if (lstMenuItems == null)
{
lstMenuItems = new List<string>();
}
lstMenuItems.Add((string)cursor.GetBSTR(1));
hasCustomizedReports = true;
cursor.Next(1);
result = cursor.LastError() == bpDynErrors.bpDynNoError;
}
if (!hasCustomizedReports)
{
if (lstMenuItems == null)
{
lstMenuItems = new List<string>();
}
lstMenuItems.Add("<empty>");
}
return lstMenuItems;
}
So I want to write a commonmethod for both above methods.
Please specify how t o write it.
Last edited by HanneSThEGreaT; August 2nd, 2010 at 07:46 AM.
-
August 2nd, 2010, 07:45 AM
#2
Re: Please help to write common method
Please use [CODE] tags when posting code. It is explained here :
http://www.codeguru.com/forum/showthread.php?t=401115
-
August 3rd, 2010, 01:10 AM
#3
Re: Please help to write common method
Since the only relevant difference is the sql query string, you can pass this string to a common function.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|