using System;
using System.Data;
using Core.Mes.ServerFrameWork;
using System.IO;
using System.Data.OracleClient;
using System.Collections;
using Core.Mes.IBaseInterface;

namespace Core.Mes.PurviewManager
{
  public class UAM_FUNCTION : IComponent
  {
    public UAM_FUNCTION() { }

    private System.String _FUNCTIONID;
    private System.String _FUNCTIONNAME;
    private System.String _CLASSNAME;
    private System.String _ASSEMBLYNAME;
    private System.String _MEMO;


    public System.String FUNCTIONID
    {
      get { return _FUNCTIONID; }
      set { _FUNCTIONID = value; }
    }

    public System.String FUNCTIONNAME
    {
      get { return _FUNCTIONNAME; }
      set { _FUNCTIONNAME = value; }
    }

    public System.String CLASSNAME
    {
      get { return _CLASSNAME; }
      set { _CLASSNAME = value; }
    }

    public System.String ASSEMBLYNAME
    {
      get { return _ASSEMBLYNAME; }
      set { _ASSEMBLYNAME = value; }
    }

    public System.String MEMO
    {
      get { return _MEMO; }
      set { _MEMO = value; }
    }


    public ReturnObject SelectUAM_FUNCTION(string strWhere)
    {
      string sqlstr = "select FUNCTIONID"
         + ", FUNCTIONNAME"
         + ", CLASSNAME"
         + ", ASSEMBLYNAME"
         + ", IMAGENAME"
         + ", MEMO"
         + " from UAM_FUNCTION " + strWhere;
      string err = "";
      DataSet ds = DBManager.ExecuteQuery(sqlstr, out err);
      if (err == "") err = sqlstr;
      return new ReturnObject(ds, err);
    }

    public ReturnObject SelectAndCopy(string strWhere)
    {
      string sqlstr = "select FUNCTIONID"
         + ", FUNCTIONNAME"
         + ", CLASSNAME"
         + ", ASSEMBLYNAME"
         + ", MEMO"
         + " from UAM_FUNCTION " + strWhere;
      string err = "";
      DataSet ds = DBManager.ExecuteQuery(sqlstr, out err);
      if (err == "" && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
      {
        DataRow dr = ds.Tables[0].Rows[0];
        Type type = this.GetType();
        foreach (System.Reflection.PropertyInfo pro in type.GetProperties())
        {
          if (pro.GetType().ToString() == "System.Single")
          {
            pro.SetValue(this, (Single)dr[pro.Name], null);
            continue;
          }
          pro.SetValue(this, dr[pro.Name], null);
        }
      }
      if (err == "") err = sqlstr;
      return new ReturnObject(ds, err);
    }

    public ReturnObject InsertUAM_FUNCTION(ArrayList ar)
    {
      string sqlstr = "insert into UAM_FUNCTION"
        + " (FUNCTIONID"
        + ", FUNCTIONNAME"
        + ", CLASSNAME"
        + ", ASSEMBLYNAME"
        + ", MEMO"
        + ", IMAGENAME"
        + ") values ('" + ar[0]
        + "', '" + ar[1]
        + "', '" + ar[2]
        + "', '" + ar[3]
        + "', '" + ar[4]
        + "', '" + ar[5] + "')";
      string err = "";
      int i = DBManager.ExecuteNonQuery(sqlstr, out err);
      return new ReturnObject(i, err);
    }

    public ReturnObject UpdateUAM_FUNCTION(ArrayList ar)
    {
      string sqlstr = "update UAM_FUNCTION set "
        + "FUNCTIONID = '" + ar[0]
        + "', FUNCTIONNAME = '" + ar[1]
        + "CLASSNAME = '" + ar[2]
        + "', ASSEMBLYNAME = '" + ar[3]
        + "', MEMO = '" + ar[4]
        + "', IMAGENAME = '" + ar[5]
        + "' where FUNCTIONID = '" + ar[0] + "'";

      string err = "";
      int i = DBManager.ExecuteNonQuery(sqlstr, out err);
      return new ReturnObject(i, err);
    }

    public ReturnObject DeleteUAM_FUNCTION(string strWhere)
    {
      string sqlstr = "delete from UAM_FUNCTION " + strWhere;
      string err = "";
      int i = DBManager.ExecuteNonQuery(sqlstr, out err);
      return new ReturnObject(i, err);
    }

    public ReturnObject UpdateDataSet(DataSet ds, string sqlstr)
    {
      string err = "";
      bool flag = DBManager.UpdateTable(ds.Tables[0], sqlstr, out err);
      return new ReturnObject(flag, err);
    }

    public void Copy(UAM_FUNCTION par)
    {
      FUNCTIONID = par.FUNCTIONID;
      FUNCTIONNAME = par.FUNCTIONNAME;
      CLASSNAME = par.CLASSNAME;
      ASSEMBLYNAME = par.ASSEMBLYNAME;
      MEMO = par.MEMO;
    }
  }
}