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

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

    private System.String _LOGINID;
    private System.String _ROLEID;
    private System.String _USERID;
    private System.String _PASSWORD;
    private System.DateTime _EXPIREDATE;
    private System.DateTime _RECORDTIME;
    private System.String _ACCREDITMAN;
    private System.String _LOCKSTATUS;
    private System.String _VALIDATECODE;


    public System.String LOGINID
    {
      get { return _LOGINID; }
      set { _LOGINID = value; }
    }

    public System.String ROLEID
    {
      get { return _ROLEID; }
      set { _ROLEID = value; }
    }

    public System.String USERID
    {
      get { return _USERID; }
      set { _USERID = value; }
    }

    public System.String PASSWD
    {
      get { return _PASSWORD; }
      set { _PASSWORD = value; }
    }

    public System.DateTime EXPIREDATE
    {
      get { return _EXPIREDATE; }
      set { _EXPIREDATE = value; }
    }

    public System.DateTime RECORDTIME
    {
      get { return _RECORDTIME; }
      set { _RECORDTIME = value; }
    }

    public System.String ACCREDITMAN
    {
      get { return _ACCREDITMAN; }
      set { _ACCREDITMAN = value; }
    }

    public System.String LOCKSTATUS
    {
      get { return _LOCKSTATUS; }
      set { _LOCKSTATUS = value; }
    }

    public System.String VALIDATECODE
    {
      get { return _VALIDATECODE; }
      set { _VALIDATECODE = value; }
    }


    public ReturnObject SelectUAM_AUTHORIZATION(string strWhere)
    {
      string sqlstr = "SELECT LOGINID"
                     + ", ROLEID"
                     + ", USERID"
                     + ", PASSWD"
                     + ", (SELECT DEPARTMENTID FROM CXUSER.UAM_USER WHERE CXUSER.UAM_USER.USERID=CXUSER.UAM_AUTHORIZATION.USERID) DEPARTMENTID "
                     + ", (SELECT WORKPOS FROM CXUSER.UAM_USER WHERE CXUSER.UAM_USER.USERID=CXUSER.UAM_AUTHORIZATION.USERID) WORKPOS "
                     + ", (SELECT MEMO FROM CXUSER.UAM_ROLE WHERE CXUSER.UAM_ROLE.ROLEID=CXUSER.UAM_AUTHORIZATION.ROLEID) ROLEMEMO "
                   //+ ", EXPIREDATE"
                   //+ ", RECORDTIME"
                   // + ", ACCREDITMAN"
                    // + ", LOCKSTATUS"
                    // + ", VALIDATECODE"
                     + " from CXUSER.UAM_AUTHORIZATION " + strWhere;
      string err = "";
      DataSet ds = DBManager.ExecuteQuery(sqlstr, out err);
      if (err == "") err = sqlstr;
      return new ReturnObject(ds, err);
    }
    public ReturnObject GetUAM_AUTHORIZATION(string where)
    {
      string sql = "SELECT A.LOGINID,A.ROLEID,A.USERID,A.PASSWD,B.DEPARTMENTID,B.WORKPOS,"
                  + "(SELECT MEMO FROM CXUSER.UAM_ROLE WHERE ROLEID=A.ROLEID) ROLEMEMO,decode(NVL(lockstatus,'0'),'0','ÒÑÆôÓÃ','ÒÑÍ£ÓÃ') STATUS "
                //+"EXPIREDATE,RECORDTIME,ACCREDITMAN,LOCKSTATUS,VALIDATECODE "
                  + "FROM CXUSER.UAM_AUTHORIZATION A,CXUSER.UAM_USER B WHERE A.USERID=B.USERID "
                  + where
                  + " ORDER BY A.LOGINID ";
      string err = "";
      DataSet rtndst = this.DBManager.ExecuteQuery(sql, out err);
      if (err == "") err = err + "%" + sql;
      return new ReturnObject(rtndst, err);
    }
    public ReturnObject SelectAndCopy(string strWhere)
    {
      string sqlstr = "SELECT LOGINID"
         + ", ROLEID"
         + ", USERID"
         + ", PASSWD"
         + ", EXPIREDATE"
         + ", RECORDTIME"
         + ", ACCREDITMAN"
         + ", LOCKSTATUS"
         + ", VALIDATECODE"
         + " from CXUSER.UAM_AUTHORIZATION " + 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_AUTHORIZATION(ArrayList ar)
    {
      string sqlstr = "INSERT INTO CXUSER.UAM_AUTHORIZATION"
         + " (LOGINID"
         + ", ROLEID"
         + ", USERID"
         + ", PASSWD"
         + ") VALUES ('" + ar[0]
         + "', '" + ar[1]
         + "', '" + ar[2]
         + "', '" + ar[3] + "')";
      string err = "";
      int i = DBManager.ExecuteNonQuery(sqlstr, out err);
      return new ReturnObject(i, err);
    }

    public ReturnObject UpdateUAM_AUTHORIZATION(ArrayList ar)
    {
      string sqlstr = "UPDATE CXUSER.UAM_AUTHORIZATION SET "
         + "  ROLEID = '" + ar[1]
         + "', USERID = '" + ar[2]
         + "', PASSWD = '" + ar[3]
         + "' WHERE LOGINID = '" + ar[0] + "'";
      string err = "";
      int i = DBManager.ExecuteNonQuery(sqlstr, out err);
      return new ReturnObject(i, err);
    }
    public ReturnObject UpdateRollid(ArrayList ar)
    {
      string sqlstr = "UPDATE CXUSER.UAM_AUTHORIZATION SET "
        + "  ROLEID = '" + ar[0]
        + "' WHERE LOGINID = '" + ar[1] + "'";
      string err = "";
      int i = DBManager.ExecuteNonQuery(sqlstr, out err);
      return new ReturnObject(i, err);
    }

    public ReturnObject DeleteUAM_AUTHORIZATION(string strWhere)
    {
      string sqlstr = "DELETE FROM CXUSER.UAM_AUTHORIZATION " + 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_AUTHORIZATION par)
    {
      LOGINID = par.LOGINID;
      ROLEID = par.ROLEID;
      USERID = par.USERID;
      PASSWD = par.PASSWD;
      EXPIREDATE = par.EXPIREDATE;
      RECORDTIME = par.RECORDTIME;
      ACCREDITMAN = par.ACCREDITMAN;
      LOCKSTATUS = par.LOCKSTATUS;
      VALIDATECODE = par.VALIDATECODE;
    }
  }
}