CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2010
    Posts
    5

    Question 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.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Please help to write common method

    Please use &#091;CODE] tags when posting code. It is explained here :

    http://www.codeguru.com/forum/showthread.php?t=401115

  3. #3
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    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
  •  





Click Here to Expand Forum to Full Width

Featured