public static void RefreshLookupTable(String strTableName) { bool isUpdate = false; lock ( LookupTables ) { LoadLookupTable(strTableName); if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colUpdateTime) && LastUpdateTimes.ContainsKey(strTableName)) { #region Has 'UpdateTime' DateTime lastTimeInDB = TimeProvider.GetTableLastUpdateTime(strTableName); DataTable lookupTable = LookupTables[strTableName]; DateTime lastTimeInApp = LastUpdateTimes[strTableName]; if (DataStructureProvider.IsTableColumn(strTableName, ABCCommon.ABCConstString.colABCStatus)) { #region Has 'ABCStatus' if (lastTimeInDB > lastTimeInApp) { #region Refresh Modified Items String strQuery = String.Format(@"SELECT * FROM {0} WHERE ABCStatus ='Alive' AND {1}", strTableName, TimeProvider.GenCompareDateTime(ABCCommon.ABCConstString.colUpdateTime, ">", lastTimeInApp)); DataSet ds = DataQueryProvider.CompanyDatabaseHelper.RunQuery(strQuery); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { BusinessObjectController controller = BusinessControllerFactory.GetBusinessController(strTableName); String strPK = DataStructureProvider.GetPrimaryKeyColumn(strTableName); foreach (DataRow row in ds.Tables[0].Rows) { #region Row BusinessObject obj = (BusinessObject)controller.GetObjectFromDataRow(row); Guid iID = ABCHelper.DataConverter.ConvertToGuid(ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, strPK)); DataRow[] rows = lookupTable.Select(String.Format("{0}='{1}'", strPK, iID)); if (rows.Length == 0) // new { lookupTable.ImportRow(row); } else { DataRow dr = rows[0]; int index = lookupTable.Rows.IndexOf(dr); if (DataStructureProvider.IsExistABCStatus(obj.AATableName) && ABCBusinessEntities.ABCDynamicInvoker.GetValue(obj, ABCCommon.ABCConstString.colABCStatus).ToString().Equals(ABCCommon.ABCConstString.ABCStatusDeleted)) //delete { lookupTable.Rows.RemoveAt(index); } else //update { object[] lstArr = new object[row.ItemArray.Length]; row.ItemArray.CopyTo(lstArr, 0); lookupTable.Rows[index].ItemArray = lstArr; } } #endregion } isUpdate = true; } #endregion } #endregion } else { #region Without 'ABCStatus' if (lastTimeInDB > lastTimeInApp || TimeProvider.GetRecordCountOfTable(strTableName) != lookupTable.Rows.Count) { DataSet ds = BusinessControllerFactory.GetBusinessController(strTableName).GetDataSetAllObjects(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { lookupTable.Rows.Clear(); foreach (DataRow dr in ds.Tables[0].Rows) { lookupTable.ImportRow(dr); } isUpdate = true; } } #endregion } LastUpdateTimes[strTableName] = lastTimeInDB; #endregion } else { #region Without 'UpdateTime' DataTable lookupTable = LookupTables[strTableName]; if (TimeProvider.GetRecordCountOfTable(strTableName) != lookupTable.Rows.Count) { DataSet ds = BusinessControllerFactory.GetBusinessController(strTableName).GetDataSetAllObjects(); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { lookupTable.Rows.Clear(); foreach (DataRow dr in ds.Tables[0].Rows) { lookupTable.ImportRow(dr); } isUpdate = true; } } #endregion } } if (isUpdate && RefreshTableMethods.ContainsKey(strTableName)) { foreach (MethodInfo method in RefreshTableMethods[strTableName]) { method.Invoke(null, new object[] {}); } } }