/// <summary> /// Digunakan untuk MovePrev dan MoveNext /// </summary> /// <param name="Op"></param> /// <returns></returns> private string GenKeyCondition(string Op) { string strKey; FieldDef PrevField; if (_CurrentKeyField.Length == 0) { PrevField = _OrderFld; } else { PrevField = _CurrentKeyField[0]; } strKey = string.Concat(PrevField._FieldName, Op, "@XCurrKeyX"); ParamMovePrevNext = (FieldParam[])_ParamCurrentKeyField.Clone(); int NumKeyField = ParamMovePrevNext.Length; Array.Resize <FieldParam>(ref ParamMovePrevNext, NumKeyField + 2); ParamMovePrevNext[NumKeyField] = new FieldParam("XCurrKeyX", PrevField, PrevField.GetValue(_Entity._Original)); string strTemp = string.Empty; if (_CurrentKeyField.Length > 0) { ParamMovePrevNext[0].Value = _CurrentKeyField[0] .GetValue(_Entity._Original); for (int i = 1; i < _CurrentKeyField.Length; i++) { strTemp = string.Concat(strTemp, PrevField._FieldName, "=@", PrevField._FieldName, " AND "); FieldDef TmpFld = _CurrentKeyField[i]; ParamMovePrevNext[i].Value = TmpFld .GetValue(_Entity._Original); strKey = string.Concat(strKey, " OR ", strTemp, TmpFld._FieldName, Op, "@", TmpFld._FieldName); PrevField = TmpFld; } } strKey = string.Concat("(", strKey, ")"); return(strKey); }
private string SqlMovePrevious() { //SELECT TOP 1 KeyField FROM View WHERE // ordField=@CurrField AND KeyField<@CurrKey OR // ordField<@CurrField ORDER BY OrdField DESC, KeyField DESC string strTemp = WhereExist ? " AND (" : " WHERE ("; string strOrderFld = GetOderFieldName(); string RetVal = Dp.GetSqlSelectTopN( string.Concat(strQuery, strTemp, strOrderFld, "=@XCurrFieldX AND ", GenKeyCondition("<"), " OR ", strOrderFld, "<@XCurrFieldX)"), 1, string.Concat(strOrderFld, " DESC", _strOrderDesc)); ParamMovePrevNext[ParamMovePrevNext.Length - 1] = new FieldParam("XCurrFieldX", _OrderFld, _OrderFld.GetValue(_Entity._Original)); return(RetVal); }
/// <summary> /// Returns the supplied Source object without any event hooks. /// </summary> public static object WithoutEventHooks(this object Source) { if (Source == null) { return(null); } var FieldDefs = Source.GetType().GetEventFields(); foreach (FieldInfo FieldDef in FieldDefs) { if (FieldDef.GetValue(Source) != null) { FieldDef.SetValue(Source, null); } } return(Source); }
public void SendEntityChanged(BaseEntity ActionEntity) { if (ActionEntity.GetType().Assembly.FullName .StartsWith("Sentra")) { return; } TableDef td = MetaData.GetTableDef(ActionEntity); if (td.KeyFields.Count == 0) { return; } int Ctr = 0; FieldDef KeyField = null; foreach (FieldDef fld in td.KeyFields.Values) { if (Ctr++ == 0 || fld.FieldName.StartsWith("No", StringComparison.OrdinalIgnoreCase)) { KeyField = fld; } } if (KeyField == null) { return; } if (KeyField.DataType == DataType.VarChar) { string KeyValue = (string)KeyField.GetValue(ActionEntity); syncClientCtl1.Send(new DtPopUpMessageSend("_Warning_", KeyValue, td.TableName, enMessageType.InternalMessage, true)); } }
public bool MoveData(MoveType MovingType) { IDataReader rdr; #region Cek MovingType switch (MovingType) { case MoveType.MoveFirst: rdr = DataPersistance.ExecuteReader(SqlMoveFirst()); break; case MoveType.MovePrevious: if (!IsError) { rdr = DataPersistance.ExecuteReader(SqlMovePrevious( DataPersistance.FormatSqlValue(_OrderFld.GetValue(_Original), _OrderFld.DataType), DataPersistance.FormatSqlValue(_CurrentKeyValue, DataType.VarChar))); } else { rdr = DataPersistance.ExecuteReader(SqlMoveFirst()); } break; case MoveType.MoveNext: if (!IsError) { rdr = DataPersistance.ExecuteReader(SqlMoveNext( DataPersistance.FormatSqlValue(_OrderFld.GetValue(_Original), _OrderFld.DataType), DataPersistance.FormatSqlValue(_CurrentKeyValue, DataType.VarChar))); } else { rdr = DataPersistance.ExecuteReader(SqlMoveLast()); } break; case MoveType.FindCriteria: rdr = DataPersistance.ExecuteReader(SqlFindCriteria()); break; case MoveType.FindFirst: rdr = DataPersistance.ExecuteReader( SqlFindFirst(DataPersistance.FormatSqlValue( FindValue, _OrderFld.DataType))); break; case MoveType.FindLast: rdr = DataPersistance.ExecuteReader( SqlFindLast(DataPersistance.FormatSqlValue( FindValue, _OrderFld.DataType))); break; default: // MoveLast rdr = DataPersistance.ExecuteReader( SqlMoveLast()); break; } #endregion if (rdr.Read()) { _CurrentKeyValue = rdr.GetString(0); string Criteria = string.Concat(DataPersistance .BuildKeyField(td), "=", DataPersistance .FormatSqlValue(_CurrentKeyValue)); DataPersistance.LoadEntity(_Entity, Criteria, true); MetaData.Clone(_Original, _Entity, true); if (e != null) { e._Original = (ParentEntity)_Original; } IsError = false; _SaveType = SaveType.SaveUpdate; if (e != null) { e._SaveType = SaveType.SaveUpdate; } } else { switch (MovingType) { case MoveType.MovePrevious: return(MoveFirst()); case MoveType.MoveNext: return(MoveLast()); } IsError = true; } if (onAfterLoad != null) { onAfterLoad(); } if (onDataMoving != null) { onDataMoving(MovingType, IsError); } return(!IsError); }