Exemple #1
0
 public DBReport(DBReport obj)
 {
     PropertyInfo[] p = obj.GetType().GetProperties();                               // get entity properties
     for (int i = 0; i < (p.Length); i++)
     {
         if (!p[i].PropertyType.Name.Contains("list") && !p[i].Name.Contains("arg"))
             p[i].SetValue(this, p[i].GetValue(obj, null), null);                    // set entity's property values to obj properties
     }
 }
        // fetches list of reports given a report type
        // if rpt_type = "ALL" then fetches all reports
        public static object FetchReportList(string rpt_type)
        {
            ArrayList list = new ArrayList();
            DBReport item = new DBReport();
            string qryString;
            PropertyInfo[] p = item.GetType().GetProperties();

            if (rpt_type == "ALL")
                qryString = "SELECT * FROM REPORTLIST WHERE RPT IS NOT NULL ORDER BY RPT_ID";
            else
                qryString = "SELECT * FROM REPORTLIST WHERE RPT_TYPE LIKE @rpt_type ORDER BY RPT_ID";

            // create database connection
            User user = (User)System.Web.HttpContext.Current.Session[Constant.session.User];
            IDBManager dbmgr = new DBManager(user.plantDBStr);
            dbmgr.ConnectionString = user.plantDBStr;

            try
            {
                dbmgr.Open();
                dbmgr.CreateParameters(1);
                dbmgr.AddParameters(0, "@rpt_type", rpt_type);
                dbmgr.ExecuteReader(System.Data.CommandType.Text, qryString);

                while (dbmgr.DataReader.Read())
                {
                    item = new DBReport();
                    item = (DBReport)TotalManager.FetchObject(item, p, dbmgr);
                    list.Add(item);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbmgr.Dispose();
            }

            return list;
        }
        // fetches report infomration for a given report id
        public static DBReport FetchReport(int id)
        {
            DBReport report = new DBReport();
            string qryString;

            qryString = "SELECT * FROM REPORTLIST WHERE RPT_ID = @rpt_id";

            // create database connection
            User user = (User)System.Web.HttpContext.Current.Session[Constant.session.User];
            IDBManager dbmgr = new DBManager(user.plantDBStr);
            dbmgr.ConnectionString = user.plantDBStr;

            try
            {
                dbmgr.Open();
                dbmgr.CreateParameters(1);
                dbmgr.AddParameters(0, "@rpt_id", id);
                dbmgr.ExecuteReader(System.Data.CommandType.Text, qryString);

                if (dbmgr.DataReader.Read())
                {
                    // get properties of object and fetch object
                    PropertyInfo[] p = report.GetType().GetProperties();
                    report = (DBReport)TotalManager.FetchObject(report, p, dbmgr);
                }

            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbmgr.Dispose();
            }

            return report;
        }