Home >Database >Mysql Tutorial >XPO学习一(获取数据库服务器时间)

XPO学习一(获取数据库服务器时间)

WBOY
WBOYOriginal
2016-06-07 15:35:351372browse

在开始学习XPO时,需要连接到数据库且需要获得数据库服务器时间,连接ORACLE Session.DefaultSession.Connection = new OracleConnection(Data Source=dbserver;User ID=system;Password=oracle); Session.DefaultSession.AutoCreateOption = AutoCreateOpti

在开始学习XPO时,需要连接到数据库且需要获得数据库服务器时间,连接ORACLE

 Session.DefaultSession.Connection = new OracleConnection("Data Source=dbserver;User ID=system;Password=oracle");
            Session.DefaultSession.AutoCreateOption = AutoCreateOption.SchemaOnly;
            Session.DefaultSession.Connect();

读取服务器时间:

 public static  class oracleGetsysDate {
        public static  DateTime sysDate()
        {
             System.Data.IDbCommand command;
            //System.Data.IDataReader reader;
            command = DevExpress.Xpo.Session.DefaultSession.Connection.CreateCommand();
          
            command.CommandText = "Select sysdate from dual";
            //reader = command.ExecuteReader();
            string dtm = command.ExecuteScalar().ToString();
            DateTime jtdtm = DateTime.Parse(dtm);
           
            return jtdtm;
       }

调用:

  DateTime dt = oracleGetsysDate.sysDate().Date;

 

XPO的业务类:

 public class TEST : XPLiteObject
    {
        string fDEPT_CODE;
        [Key]
        [Size(10)]
        [DbType("varchar2(30)")][Persistent("Dept_code")][DisplayName("科室代码")]
        public string DEPT_CODE
        {
            get { return fDEPT_CODE; }
            set { SetPropertyValue("DEPT_CODE", ref fDEPT_CODE, value); }
        }
        string fDEPT_NAME;
        [Size(30)]
        public string DEPT_NAME
        {
            get { return fDEPT_NAME; }
            set { SetPropertyValue("DEPT_NAME", ref fDEPT_NAME, value); }
        }
        DateTime fCREATEDATE;
        public DateTime CREATEDATE
        {
            get { return fCREATEDATE; }
            set {
               
                SetPropertyValue("CREATEDATE", ref fCREATEDATE, value); }
        }
        public TEST(Session session) : base(session) { }
        public TEST() : base(Session.DefaultSession) { }
        public override void AfterConstruction() { base.AfterConstruction(); }
        protected override void OnSaving()
        {
            base.OnSaving();
            if (!IsDeleted)
            {
                UnitOfWork uw = new UnitOfWork();
               
                if (fDEPT_CODE == null || fDEPT_CODE == "")
                    throw new Exception("科室代码不能置空值,保存失败!");
           
            }
        }
        protected override void Spoil(bool disposing)
        {
            base.Spoil(disposing);
        }
    }

调用XPO:

  try
            {
                DateTime dt = oracleGetsysDate.sysDate().Date;
                dbserver.TEST test = new TEST();
                test.DEPT_CODE = "123";
                test.DEPT_NAME = "Test2";
                test.CREATEDATE = dt;
               
                test.Save();
               // DateTime dt = oracleGetsysDate.sysDate();
                //this.textBox1.Text = dt.ToString();//得到查询表的第一行第一列
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"提示");
            }

XPO的初步学习比较简单。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn