void IReportEntity.GetDataSource(out string DataSource, out string DataSourceOrder, List <FieldParam> Parameters) { GetDataSource(out DataSource, out DataSourceOrder, Parameters); if (DataSource.Length == 0) { Type ObjType; string Condition; GetDataSource(out ObjType, out Condition, out DataSourceOrder, Parameters); if (ObjType == null) { throw new ApplicationException("DataSource Laporan belum ditentukan"); } TableDef td = MetaData.GetTableDef(ObjType); if (td != null) { Dp.ValidateTableDef(td); DataSource = "SELECT * FROM " + td.GetSqlHeaderView(Dp); if (Condition.Length > 0) { DataSource = string.Concat(DataSource, " WHERE ", Condition); } } else { throw new ApplicationException("DataSource Laporan belum ditentukan"); } } DataChanged(); FormChanged(); }
public bool TryFindAvgValue <TEntity>(string FieldName, string Conditions, out object Value, params FieldParam[] Parameters) where TEntity : BaseEntity { TableDef td = MetaData.GetTableDef(typeof(TEntity)); DataPersistance Dp = td.GetDataPersistance(this.Dp); Dp.ValidateTableDef(td); string SqlSelect = string.Concat("SELECT ", Dp.GetSqlAvg(), "(", GetFieldName(td, FieldName), ") FROM ", td.GetSqlHeaderView(Dp)); if (Conditions.Length > 0) { SqlSelect = string.Concat(SqlSelect, " WHERE ", Conditions); } return(Dp.Find.TryFindValue(SqlSelect, out Value, Parameters)); }
// Real Find public bool TryFindFirstValues <TEntity>(string FieldNames, string Conditions, string OrderFields, out object[] Values, params FieldParam[] Parameters) where TEntity : BaseEntity { TableDef td = MetaData.GetTableDef(typeof(TEntity)); DataPersistance Dp = td.GetDataPersistance(this.Dp); Dp.ValidateTableDef(td); string[] FName = FieldNames.Split(','); string SqlSelect = string.Empty; bool IsLSQLExist = false; for (int i = 0; i < FName.Length; i++) { FieldDef fld = td.GetFieldDef(FName[i]); if (fld != null) { if (fld._dtlsa == null) { SqlSelect = string.Concat(SqlSelect, ",", fld._FieldName); } else { SqlSelect = string.Concat(SqlSelect, ",(", fld._dtlsa.GetSqlQuery(), ") AS ", fld._FieldName); IsLSQLExist = true; } } else { SqlSelect = string.Concat(SqlSelect, ",", FName[i].Trim()); } } SqlSelect = string.Concat("SELECT ", SqlSelect.Remove(0, 1), " FROM ", td.GetSqlHeaderView(Dp)); if (IsLSQLExist) { SqlSelect = string.Concat("SELECT * FROM (", SqlSelect, ") AS ", td._TableName); } if (Conditions.Length > 0) { SqlSelect = string.Concat(SqlSelect, " WHERE ", Conditions); } IDbCommand Cmd = Dp.CreateCommand( Dp.GetSqlSelectTopN(SqlSelect, 1, OrderFields), CommandType.Text, Parameters); bool MustClose; if (Dp.Connection.State != ConnectionState.Open) { Dp.Connection.Open(); MustClose = true; } else { MustClose = false; } IDataReader rdr = null; try { Dp.WriteLog(Cmd.CommandText); rdr = Dp._ExecuteReader(Cmd); if (rdr.Read()) { Values = new object[rdr.FieldCount]; for (int i = 0; i < rdr.FieldCount; i++) { Values[i] = NormalizeVarType(rdr[i]); } return(true); } Values = null; return(false); } finally { if (rdr != null) { rdr.Close(); } if (MustClose) { Dp.Connection.Close(); } } }
public bool IsExists(Type EntityType, string Conditions, params FieldParam[] Parameters) { TableDef td = MetaData.GetTableDef(EntityType); DataPersistance Dp = td.GetDataPersistance(this.Dp); Dp.ValidateTableDef(td); string FieldName = string.Empty; foreach (FieldDef fd in td.KeyFields.Values) { FieldName = fd._FieldName; break; } string SqlSelectBld = string.Empty; foreach (FieldDef fd in td.NonKeyFields.Values) { if (fd._dtlsa == null) { if (FieldName.Length == 0) { FieldName = fd._FieldName; } } else { SqlSelectBld = string.Concat(SqlSelectBld, ",(", fd._dtlsa.GetSqlQuery(), ") AS ", fd._FieldName); } } string SqlSelect = SqlSelectBld.Length == 0 ? string.Concat("SELECT ", FieldName, " FROM ", td.GetSqlHeaderView(Dp)) : string.Concat( "SELECT ", FieldName, " FROM (SELECT *", SqlSelectBld, " FROM ", td.GetSqlHeaderView(Dp), ") AS ", td._TableName); if (Conditions.Length > 0) { SqlSelect = string.Concat(SqlSelect, " WHERE ", Conditions); } SqlSelect = Dp.GetSqlSelectTopN(SqlSelect, 1, string.Empty); IDbCommand Cmd = Dp.CreateCommand(SqlSelect, CommandType.Text, Parameters); bool MustClose; if (Dp.Connection.State != ConnectionState.Open) { Dp.Connection.Open(); MustClose = true; } else { MustClose = false; } IDataReader rdr = null; try { Dp.WriteLog(Cmd.CommandText); rdr = Dp._ExecuteReader(Cmd); return(rdr.Read()); } finally { if (rdr != null) { rdr.Close(); } if (MustClose) { Dp.Connection.Close(); } } }