当前位置:Gxlcms > mysql > XPO学习一(获取数据库服务器时间)

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

时间:2021-07-01 10:21:17 帮助过:42人阅读

在开始学习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的初步学习比较简单。

人气教程排行