using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Data;
using VBNET = Microsoft.VisualBasic;
using gmRTL.Core;
using Microsoft.VisualBasic.CompilerServices;
using System.Linq;
using System.Collections.Generic;

namespace FMSTest
{
   public static class utils
   {
      public const string gLogFile = "FMSTest.log";
      public static string reportRecordSet(gmRTL.DataLib.SqlClient.Recordset rs)
      {
         string reportRecordSet = "";

         if (rs == null)
         {
            reportRecordSet = "RS IS NOTHING";
            return reportRecordSet;
         }
         string rpt = "";
         int r = 0;
         const string rptstr = "%fld%[%r%]=%v%";     // & vbCrLf
         r = 1;

         rs.MoveFirst();
         while (!rs.EOF)
         {
            foreach(gmRTL.DataLib.SqlClient.Field fld in rs.Fields)
            {
               rpt = rpt + rptstr + "\r\n";
               rpt = rpt.ReplaceStr("%fld%",fld.Name,1,-1,StringComparison.CurrentCulture);
               rpt = rpt.ReplaceStr("%r%",r.ToStr(),1,-1,StringComparison.CurrentCulture);
               if (fld.ProviderDbType == System.Data.SqlDbType.Bit)
               {
                  rpt = rpt.ReplaceStr("%v%",(fld.Value.ToBool() ? "True" : "False"),1,-1,StringComparison.CurrentCulture);
               }
               else if (gmRTL.Core.InformationHelper.IsNumeric(fld.Value))
               {
                  rpt = rpt.ReplaceStr("%v%",gmRTL.Core.FormatHelper.Format(fld.Value,"0.00"),1,-1,StringComparison.CurrentCulture);
               }
               else
               {
                  rpt = rpt.ReplaceStr("%v%",fld.Value.ToStr(),1,-1,StringComparison.CurrentCulture);
               }
            }
            r = r + 1;
            rs.MoveNext();
         }
         return rpt;
      }
      [STAThread]
      public static void Main(string[] args)
      {
         if (gmRTL.Core.FileSystemHelper.Dir(utils.gLogFile,gmRTL.Core.FileSystemHelper.FileAttribute.Normal) != "")
         {
            System.IO.File.Delete(utils.gLogFile);
         }

         if (gmRTL.Core.InteractionHelper.Command() == "/batch")
         {
            frmFMSTest.DefInstance.cmdTest_Click(null,new EventArgs());
            Environment.Exit(0);
         }
         else
         {
            System.Windows.Forms.Application.Run(frmFMSTest.DefInstance);
         }

      }
   }
}
