|
I have used Thread Thr = new Thread();
I do not SetFocus gridview1.FocusedRowHandle = i; it will warning: "Cross-thread operation not valid: Control 'gridControl1' accessed from a thread other than the thread it was created on."
you do not know how to fix this ?
|
|
|
|
|
because the grid is active on another thread so you will need to use a delegate to access the grid.
have a read of this Fill datagridview Column from different thread[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
, 1, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static INT sIsLastArrValid = 0;
#define RRINTERVAL_NUM 12
static INT16 sHeartRate;
static INT16 sRrIntervals[RRINTERVAL_NUM];
static INT sHrOfOneSecond;
static INT sInnerHeartRate, sInnerLastHeartRate;
static INT sPreviousMatched;
static INT sOutHR;
typedef struct{ UCHAR type; INT position; INT isSaved;} ARRSELECTED;
static ARRSELECTED sLastArrSelected;
static UINT32 sBlankLength = 0;
static INT sNotUpdatedTime = 0;
void ArrhythmiaAnalysis( void )
{
PaceStatistic();
arr_anal( );
if( 0 < gArrAnalysisInfo.ignoreResult )
{
gArrAnalysisInfo.arrCode = NML;
gStates.current = MAX_STATE;
gRGlobals.counter = 0;
}
}
void arr_anal( void )
{
INT i, ptr;
Frame pack;
if ( gEcgStatus.ecg1Exist
&& gEcgStatus.ecg2Exist )
{
i = ChannelAutoSelect(mod( gEcgBuffer.pos - ARR_SAMPLE_RATE , ECG_BUF_LENGTH));
}
else
{
if ( gEcgStatus.ecg1Exist )
i = ECG_CHANNEL_1;
else
i = ECG_CHANNEL_2;
}
if ( i != gArrConfig.arrChannel )
{
gArrConfig.arrChannel = i;
pack.id = ECGCHANNEL;
pack.data[0] = gArrConfig.arrChannel;
gProtocol.SendPack( pack );
}
gRDetEcgBuf = gEcgBuffer.channel[gArrConfig.arrChannel];
if( IsRelearnNeeded() == TRUE )
{
gArrAnalysisInfo.ignoreResult = 4;
EcgVarInit();
gQrsAnaInfo.inLearning = TRUE;
ResetSTAnalysis( );
sBlankLength = 0;
}
if(TRUE == gArrConfig.arrSelfLearn)
{
gQrsAnaInfo.inLearning = TRUE;
gArrConfig.arrSelfLearn = FALSE;
}
gTemplateSet.maxTemplate = MAX_TEMPLATE;
gRDetEcgBufPtr = gEcgBuffer.pos;
ECGProcess( ARR_SAMPLE_RATE );
#ifdef ENABLE_EXTRA_VFIB_DETECTION
CopyDiffData( ARR_SAMPLE_RATE );
#endif
gRGlobals.qrsDetected = 0;
if( IsNoise( ARR_SAMPLE_RATE ) )
{
gArrAnalysisInfo.arrCode = NOS;
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_NOISE;
gQrsAnaInfo.delay = 2;
gRGlobals.validRRi = 0;
gRGlobals.resetPeakDetect = 1;
gRGlobals.timePast = 0;
gStates.current = MAX_STATE;
gRGlobals.counter = 0;
if( gRGlobals.initialized == 0 )
EcgVarInit();
}
else
if( gQrsAnaInfo.delay > 0 )
{
gQrsAnaInfo.delay --;
gArrAnalysisInfo.arrCode = NML;
}
else
{
if( IsECGLost( ARR_SAMPLE_RATE ) )
{
gArrAnalysisInfo.arrCode = ASY;
gRGlobals.timePast = 0;
gQrsAnaInfo.isEcgLost = TRUE;
gRGlobals.validRRi = 0;
gRGlobals.resetPeakDetect = 1;
gStates.current = MAX_STATE;
gRGlobals.counter = 0;
if( gRGlobals.initialized == 0 )
EcgVarInit();
}
else
{
gQrsAnaInfo.isEcgLost = FALSE;
}
if( gRGlobals.initialized == 0 )
{
if( TRUE == gQrsAnaInfo.isEcgLost )
{
gRGlobals.initLength = 0;
gRGlobals.initialized = 0;
gRGlobals.qrsPtr = 0;
}
else
{
InitDetect( );
if( gRGlobals.initialized == 1 )
{
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_ARR_LRN;
}
else
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_QRS_LEARN;
}
}
else
{
if( gQrsAnaInfo.inLearning == TRUE && gTemplateSet.ready == 1 )
{
TemplateVarInit();
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_ARR_LRN;
}
if( FALSE == gQrsAnaInfo.isEcgLost)
QRSDetector( ARR_SAMPLE_RATE );
else
gRGlobals.qrsDetected = 0;
i = gRGlobals.qrsDetected - 1;
while( i >= 0 )
{
ptr = mod( gRGlobals.qrsPtr - i, MAX_QRS_NUM);
if( gQrsComplex[ptr].coef != INVALID_CORRCOEF )
{
break;
}
i --;
}
ArrhythmiaProcess( i+1 );
if( gQrsAnaInfo.inLearning == TRUE && gArrAnalysisInfo.arrCode != ASY )
{
gArrAnalysisInfo.arrCode = ARRLRN;
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_ARR_LRN;
}
}
if ( ( gQrsAnaInfo.isEcgLost
||( gRGlobals.timePast > _4SECONDS + _200MS) )
&& ASY != gArrAnalysisInfo.arrCode )
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_SIGNAL_TOO_SMALL;
}
gQrsAnaInfo.heartRate = InnerGetHeartRate();
gQrsAnaInfo.hrOfCurrSec = sHrOfOneSecond;
}
UCHAR ChannelAutoSelect( INT16 beginPos )
{
INT i;
for( i = 0; i < ECG_CHANNEL_MAX; i++ )
{
__Ddf1(gEcgBuffer.channel[i], gChannelAutoSelInfo.lpDifEcg[i], beginPos,
ARR_SAMPLE_RATE, ECG_BUF_LENGTH, ECG_BUF_LENGTH);
PulNum( gChannelAutoSelInfo.lpDifEcg[i], i );
}
ChSelectNum( ECG_CHANNEL_MAX );
return gChannelAutoSelInfo.byCurChNum;
}
void ChSelectNum( INT16 iChNum )
{
INT16 i;
INT16 pulseNum = 0;
if( iChNum == 1 )
return;
if( gChannelAutoSelInfo.byTimeDelay > 1 )
gChannelAutoSelInfo.byTimeDelay--;
else
gChannelAutoSelInfo.byTimeDelay = 0;
for( i = 0; i < iChNum; i++ )
{
if( i != gChannelAutoSelInfo.byCurChNum )
{
if( gChannelAutoSelInfo.byPulNum[gChannelAutoSelInfo.byCurChNum] != 0 )
{
if( gChannelAutoSelInfo.byPulNum[i] != 0 )
pulseNum = 1;
else
pulseNum = 0;
}
if( ( ( gChannelAutoSelInfo.byPulNum[i] < gChannelAutoSelInfo.byPulNum[gChannelAutoSelInfo.byCurChNum] ) && ( pulseNum == 1 ) )
|| ( ( gChannelAutoSelInfo.byPulNum[i] <= gChannelAutoSelInfo.byPulNum[gChannelAutoSelInfo.byCurChNum] )
&&( gChannelAutoSelInfo.iMaxDiff[i] > gChannelAutoSelInfo.iMaxDiff[gChannelAutoSelInfo.byCurChNum] ) )
|| ( gChannelAutoSelInfo.iMaxDiff[gChannelAutoSelInfo.byCurChNum] == 10 ) )
{
gChannelAutoSelInfo.byChgCount[i]++;
if( ( gChannelAutoSelInfo.byChgCount[i] > 10 ) && ( gChannelAutoSelInfo.byTimeDelay == 0 ) )
{
gChannelAutoSelInfo.byCurChNum = i;
gChannelAutoSelInfo.byChgCount[i] = 0;
}
}
else
gChannelAutoSelInfo.byChgCount[i] = 0;
}
}
return;
}
void PulNum( INT16 *lpDifEcg, INT16 iChNo)
{
INT16 i;
INT16 iCutLine;
gChannelAutoSelInfo.iMaxDiff[iChNo] = *lpDifEcg;
gChannelAutoSelInfo.byPulNum[iChNo] = 0;
for( i = 1; i < ARR_SAMPLE_RATE; i++)
{
if( *( lpDifEcg + i ) > gChannelAutoSelInfo.iMaxDiff[iChNo] )
gChannelAutoSelInfo.iMaxDiff[iChNo] = *( lpDifEcg + i );
}
iCutLine = gChannelAutoSelInfo.iMaxDiff[iChNo] / 3;
if( iCutLine < 10 )
iCutLine = 10;
for( i = 0; i < ARR_SAMPLE_RATE; i++ )
{
if( ( *( lpDifEcg + i ) > iCutLine ) && ( gChannelAutoSelInfo.byPassThdFlag[iChNo]== 0 ) )
{
gChannelAutoSelInfo.byPulNum[iChNo] ++;
gChannelAutoSelInfo.byPassThdFlag[iChNo] = 1;
}
else
{
if( *( lpDifEcg + i ) <= iCutLine )
gChannelAutoSelInfo.byPassThdFlag[iChNo] = 0;
}
}
if( gChannelAutoSelInfo.iMaxDiff[iChNo] < 10 )
gChannelAutoSelInfo.iMaxDiff[iChNo] = 10;
return;
}
INT IsRelearnNeeded( void )
{
return FALSE;
}
void ArrhythmiaProcess( INT qrsProcessed )
{
UCHAR arrCode;
INT i, ptr, position, isArrSelectedValid;
INT tmp, firstSaved;
ARRSELECTED arrSelected;
gRGlobals.qrsClassified = 0;
for( i = qrsProcessed - 1; i >= 0; i -- )
{
ptr = mod( gRGlobals.qrsPtr - i, MAX_QRS_NUM);
tmp = MorphClassify(
ptr,
gSysSetting.pace || (0 < gArrAnalysisInfo.ignoreResult)
);
if( tmp > 0 )
{
gRGlobals.qrsClassified += tmp;
gRGlobals.classifiedQrsPtr = ptr;
}
}
if( gSysSetting.pace || (0 < gArrAnalysisInfo.ignoreResult) )
{
for( i = gRGlobals.qrsClassified - 1; i >= 0; i -- )
{
ptr = mod( gRGlobals.classifiedQrsPtr - i, MAX_QRS_NUM);
gQrsComplex[ptr].type = QT_DOMINANT;
}
}
arrSelected.type = gArrAnalysisInfo.lastArrCode;
arrSelected.isSaved = 1;
isArrSelectedValid = 0;
firstSaved = 0;
for( i = gRGlobals.qrsClassified - 1; i >= 0; i -- )
{
ptr = mod( gRGlobals.classifiedQrsPtr - i, MAX_QRS_NUM);
if( gQrsComplex[ptr].type == QT_ABNORMAL )
gArrAnalysisInfo.pvcOfCurrentSecond ++;
arrCode = ArrhythmiaClassify( &gStates, ptr, &position );
if( arrCode != NON && position >= 0 )
{
if( gArrAnalysisInfo.lastArrCode == arrCode && sContinueAllowed[arrCode] )
{
if( sIsLastArrValid )
{
arrSelected.type = sLastArrSelected.type ;
arrSelected.position = sLastArrSelected.position ;
arrSelected.isSaved = 0;
firstSaved = 1;
sIsLastArrValid = 0;
isArrSelectedValid = 1;
}
else
if( !firstSaved )
{
arrSelected.type = arrCode ;
arrSelected.position = gQrsComplex[position].peakPos;
isArrSelectedValid = 1;
}
continue;
}
else
gArrAnalysisInfo.lastArrCode = arrCode;
if( sArrInfo[arrCode].warningLevel >= sArrInfo[arrSelected.type].warningLevel )
{
arrSelected.type = arrCode;
arrSelected.position = gQrsComplex[position].peakPos;
arrSelected.isSaved = 0;
firstSaved = 1;
isArrSelectedValid = 1;
}
else
if( arrCode != NML )
{
sLastArrSelected.type = arrCode;
sLastArrSelected.position = gQrsComplex[position].peakPos;
sIsLastArrValid = 1;
}
}
}
arrCode = NON;
if( ASYSTOLEDetect() == 1 )
{
arrCode = ASY;
}
else
if( (gArrAnalysisInfo.arrCode == ASY) && (arrSelected.type != ASY) )
{
arrSelected.type = NML;
isArrSelectedValid = 1;
}
#ifdef ENABLE_EXTRA_VFIB_DETECTION
if( VFIBDetect( ) == 1 )
{
arrCode = FIB;
}
#endif
#ifdef ENABLE_EXTRA_VFIB_DETECTION
if( arrCode == ASY || arrCode == FIB )
#else
if( arrCode == ASY )
#endif
{
arrSelected.type = arrCode;
arrSelected.position = mod( gEcgBuffer.pos - 4 * ARR_SAMPLE_RATE, ECG_BUF_LENGTH);
isArrSelectedValid = 1;
if( gArrAnalysisInfo.arrCode != arrCode )
{
arrSelected.isSaved = 0;
}
}
if( isArrSelectedValid )
{
gArrAnalysisInfo.arrCode = arrSelected.type;
gArrAnalysisInfo.position = arrSelected.position;
if( arrSelected.isSaved == 0 )
gArrAnalysisInfo.isSaved = 0;
}
if( gArrAnalysisInfo.arrCode <= 19 && gArrAnalysisInfo.isSaved == 0 )
{
i = mod( gArrAnalysisInfo.position - ARR_RECORD_SECONDS * ARR_SAMPLE_RATE, ECG_BUF_LENGTH);
i = mod( gEcgBuffer.pos - i , ECG_BUF_LENGTH );
if( i < ARR_RECORD_SECONDS * ARR_SAMPLE_RATE )
{
gArrAnalysisInfo.arrCode = NML;
}
}
}
CHAR IsECGLost( INT sample )
{
INT i, ptr;
ptr = mod(gRDetEcgBufPtr - sample, ECG_BUF_LENGTH);
for( i = 0; i < sample; i ++)
{
if( MWI_THRESHOLD >= *(gMWIBuf + ptr) )
{
sBlankLength ++;
}
else
{
sBlankLength = 0;
}
ptr = mod(ptr + 1, ECG_BUF_LENGTH);
}
if( ECGLOST_THRESHOLD < sBlankLength )
return TRUE;
else
return FALSE;
}
UCHAR ArrhythmiaClassify( STATES* states, INT qrsPtr, INT* eventQrsIndex )
{
INT arrCode, qrsIndex;
INT i, tmp, qrsNumber, ptr0, ptr1;
UCHAR type;
states->last = states->current;
if( gQrsComplex[qrsPtr].type == QT_ABNORMAL )
type = 1;
else
type = 0;
if( states->current <= MAX_STATE && states->current >= 0 )
{
states->current = sStateTransfer[states->current][type];
}
else
{
states->current = MAX_STATE;
}
states->ptr = mod( states->ptr + 1, QRS_SAVED );
states->rri[states->ptr] = gQrsComplex[qrsPtr].rri;
states->matched[states->ptr] = gQrsComplex[qrsPtr].matched;
states->qrsPtrs[states->ptr] = qrsPtr;
arrCode = sStateToArrType[states->current][0];
qrsIndex = sStateToArrType[states->current][1];
switch( arrCode )
{
case VPB:
if( states->averageRRi > _600MS )
{
i = mod( states->ptr - qrsIndex , QRS_SAVED );
if( ( (states->rri[i] * 10) <= (states->averageRRi * 5 ) )
&&(states->rri[mod(i+1,QRS_SAVED)] >= states->averageRRi* 5 / 4 ) )
{
arrCode = ROT;
}
}
break;
case NML:
if( states->current == 24 )
{
arrCode = TachBradyDetect( states );
}
break;
default:
break;
}
if( states->current >= 22 )
{
if( states->last == 8 )
qrsNumber = 2;
else
qrsNumber = 1;
ptr0 = mod( states->ptr - qrsNumber , QRS_SAVED );
ptr1 = mod( ptr0 + 1, QRS_SAVED );
for( i = 0; i < qrsNumber ; i ++ )
{
if( (states->rri[ptr0] < _4SECONDS )
&&(states->rri[ptr1] < states->averageRRi * 3 / 2 )
&&( (states->averageRRi > _600MS && states->rri[ptr0] > states->averageRRi * 7 / 4 )
|| (states->averageRRi < _600MS && states->rri[ptr0] > ( _1000MS - 4 ) )) )
{
arrCode = MIS;
ptr0 = mod( ptr0 - 1, QRS_SAVED );
*eventQrsIndex = states->qrsPtrs[ptr0];
if( TRUE == gSysSetting.pace )
{
tmp = mod( gEcgBuffer.pos - gQrsComplex[*eventQrsIndex].peakPos, ECG_BUF_LENGTH);
arrCode = PaceAnalysis( tmp, states->averageRRi );
}
break;
}
ptr0 = mod( ptr0 + 1, QRS_SAVED );
}
}
qrsNumber = sStateToArrType[states->current][2];
tmp = mod( states->ptr - qrsIndex, QRS_SAVED );
if( arrCode != MIS && arrCode != PNC && arrCode != PNP )
{
if( qrsNumber > 0 )
{
if( arrCode == TAC || arrCode == BRD )
*eventQrsIndex = states->qrsPtrs[mod(tmp - 5, QRS_SAVED)];
else
*eventQrsIndex = states->qrsPtrs[tmp];
}
else
*eventQrsIndex = -1;
}
for( i = 0; i < qrsNumber; i++)
{
if( states->matched[tmp] && states->matched[mod( tmp - 1, QRS_SAVED)] )
states->averageRRi = UpdateAveRRi( states->rri[tmp], states->averageRRi );
tmp = mod( tmp + 1, QRS_SAVED);
}
return arrCode;
}
UCHAR TachBradyDetect( STATES* states )
{
INT i, tmp, tmp1, ptr;
UCHAR arrCode;
static INT TACHY_LIMIT[3] = { ARR_SAMPLE_RATE/2+2, ARR_SAMPLE_RATE*3/8+2, ARR_SAMPLE_RATE*3/8+2 };
tmp = tmp1 = 0;
for(i = 0 ; i < 5; i ++)
{
ptr = mod( states->ptr - i , QRS_SAVED );
if( states->rri[ ptr ] <= TACHY_LIMIT[gSysSetting.patientType] )
{
tmp ++;
}
else
if( states->rri[ ptr ] >= (_1500MS - 2) )
{
tmp1 ++;
}
}
arrCode = NML;
if( tmp >= 5 )
arrCode = TAC;
else
if( tmp1 >= 5 )
arrCode = BRD;
return arrCode;
}
INT UpdateAveRRi( INT currentRRi, INT averageRRi )
{
if( ( (abs( currentRRi - averageRRi ) < averageRRi / 5)
&&(currentRRi > ARR_SAMPLE_RATE/2)
&&(currentRRi < ARR_SAMPLE_RATE*3/2) )
||( sNotUpdatedTime >= 3 ) )
{
averageRRi = (averageRRi * 7 + currentRRi) / 8;
sNotUpdatedTime = 0;
}
else
{
sNotUpdatedTime ++;
}
return averageRRi;
}
UCHAR ASYSTOLEDetect( void )
{
return gQrsAnaInfo.isEcgLost || (gRGlobals.timePast > _4SECONDS + _200MS) ;
}
INT16 __Ddf1( UCHAR *Ecg_buf, INT16* dif_buf, UINT Proc_begin,
UINT Proc_len, UINT Ecgbuf_len, UINT Ddfbuf_len )
{
INT16 i, n0;
INT16 ecgPos;
INT16 x0, x1, x2, x3;
INT16 fib;
if( (Proc_len > Ecgbuf_len) || (Proc_len > Ddfbuf_len) )
{
return(-1);
}
n0 = 0;
ecgPos = (Proc_begin - 4 + Ecgbuf_len)%Ecgbuf_len;
for( i = n0; i < (int)Proc_len; i++ )
{
x0 = ecgPos;
x1 = ( ecgPos + 1 ) ;
if( x1 >= (int)Ecgbuf_len ) x1 = x1 - Ecgbuf_len;
x2 = ( ecgPos + 3 );
if( x2 >= (int)Ecgbuf_len ) x2 = x2 - Ecgbuf_len;
x3 = ( ecgPos + 4 );
if( x3 >= (int)Ecgbuf_len ) x3 = x3 - Ecgbuf_len;
fib = ( *(Ecg_buf+x2) - *(Ecg_buf+x1)
+ 2 * (*(Ecg_buf+x3) - *(Ecg_buf+x0) ) ) >> 1;
if( Proc_len <= ARR_SAMPLE_RATE )
{
*( dif_buf + i ) = fib;
}
ecgPos = ( ecgPos + 1 );
if(ecgPos>=(int)Ecgbuf_len) ecgPos = 0 ;
}
return 1;
}
INT16 PVCStatistic( UCHAR* list, INT listSize, INT pvcNumber )
{
INT16 i, total;
total = pvcNumber;
for( i = listSize - 1; i > 0 ; i -- )
{
*( list + i ) = *( list + i - 1);
total += *( list + i );
}
*( list ) = pvcNumber;
return total;
}
#define _1200MS (ARR_SAMPLE_RATE+ARR_SAMPLE_RATE/5)
INT16 CalculateHeartRate( INT16 rrInterval )
{
INT i, max, min, total, rri, validRRI;
for( i = RRINTERVAL_NUM - 1; i > 0; i --)
{
sRrIntervals[i] = sRrIntervals[i-1];
}
sRrIntervals[0] = rrInterval;
if( (_1200MS <= sRrIntervals[0])
&& (_1200MS <= sRrIntervals[1])
&& (_1200MS <= sRrIntervals[2]) )
{
rri = 4;
}
else
rri = RRINTERVAL_NUM;
validRRI = 0;
for( i = 0; i < RRINTERVAL_NUM; i ++)
{
if ( 0 < sRrIntervals[i] )
validRRI ++;
}
if ( 5 > validRRI )
return sHeartRate;
total = 0;
max = 0;
min = 5120;
if (RRINTERVAL_NUM == rri)
rri = validRRI;
for( i = 0; i < rri; i ++)
{
if( sRrIntervals[i] > max )
max = sRrIntervals[i];
if( sRrIntervals[i] < min )
min = sRrIntervals[i];
total += sRrIntervals[i];
}
if( rri > 4 )
{
total -= min + max;
rri -= 2;
}
if( total != 0 )
{
sHeartRate = 600 * (INT32)rri * ARR_SAMPLE_RATE / total;
sHeartRate = ( sHeartRate + 4 ) / 10;
} else {
sHeartRate = -100;
}
return sHeartRate;
}
INT16 InnerGetHeartRate( void )
{
INT i, ptr;
INT sum_for_b2b_hr;
BOOL tmpCondition = FALSE;
tmpCondition = ( gRGlobals.timePast > _4SECONDS + _200MS );
if( TRUE == gQrsAnaInfo.isEcgLost
|| tmpCondition
|| gRGlobals.initialized == 0
|| gQrsAnaInfo.delay > 0 )
{
sInnerHeartRate = -100;
sHrOfOneSecond = -100;
}
else
{
sum_for_b2b_hr = 0;
for( i = gRGlobals.qrsDetected - 1 ; i >= 0; i -- )
{
ptr = mod(gRGlobals.qrsPtr - i, MAX_QRS_NUM);
if( sPreviousMatched && gQrsComplex[ptr].matched && gRGlobals.validRRi )
{
sInnerHeartRate = CalculateHeartRate( gQrsComplex[ptr].rri);
sum_for_b2b_hr += gQrsComplex[ptr].rri;
}
else
gRGlobals.validRRi = 1;
sPreviousMatched = gQrsComplex[ptr].matched;
}
if (0 < sum_for_b2b_hr)
{
sHrOfOneSecond = 600 * (INT32)gRGlobals.qrsDetected * ARR_SAMPLE_RATE / sum_for_b2b_hr;
sHrOfOneSecond = ( sHrOfOneSecond + 4 ) / 10;
}
}
if( sOutHR == 1 || sInnerLastHeartRate == -100 )
{
sInnerLastHeartRate = sInnerHeartRate;
sOutHR = 0;
}
else
{
sOutHR = 1;
}
return sInnerLastHeartRate;
}
#ifdef ENABLE_EXTRA_VFIB_DETECTION
void CopyDiffData( INT sample )
{
INT i, ptr, tmp;
ptr = mod( gRDetEcgBufPtr - sample , ECG_BUF_LENGTH );
for( i = 0; i < sample && i < ARR_SAMPLE_RATE; i ++)
{
tmp = *(gDiffBuf + ptr);
*( gVFibInfo.data + i ) = tmp;
if( tmp > 0 )
*( gVFibInfo.noiseDetBuf + i ) = tmp;
else
*( gVFibInfo.noiseDetBuf + i ) = 0;
ptr = mod( ptr + 1, ECG_BUF_LENGTH);
}
}
#endif
void ResetFlag( void )
{
gQrsAnaInfo.inLearning = FALSE;
gArrStatus.ecgAnalysisStatus = ECG_ANA_STATUS_NORMAL;
gArrAnalysisInfo.arrCode = NML;
gArrAnalysisInfo.lastArrCode = NML;
}
#define MINIMAL_CROSSPOINT 20
INT IsNoise( INT sample )
{
INT isNoise,crossPoint, slope;
isNoise = IsSaturation( sample );
isNoise |= ( PacePulseOfTheSecond() > PACE_NUM_ALLOWED );
if( !isNoise )
{
slope = gRGlobals.maxSlope / 4;
if( slope < MIN_NOISESLOPE )
slope = MIN_NOISESLOPE;
crossPoint = CrossPointNum(gLpDiffBuf, mod( gRDetEcgBufPtr - sample, ECG_BUF_LENGTH),
sample/2, slope );
if( crossPoint < MINIMAL_CROSSPOINT )
crossPoint = CrossPointNum(gLpDiffBuf, mod( gRDetEcgBufPtr - sample/2, ECG_BUF_LENGTH),
sample/2, slope );
isNoise = ( crossPoint >= MINIMAL_CROSSPOINT );
}
return isNoise;
}
#define SATURATION_HI 0xfd
#define SATURATION_LO 0x2
#define FASTCHANGE_TIME 5
#define FASTCHANGING 5
INT IsSaturation( INT sample )
{
INT i, ptr, delay, result;
INT numberFF, number00, fastChange;
UCHAR data;
numberFF = number00 = fastChange = 0;
delay = ARR_SAMPLE_RATE;
ptr = mod( gRDetEcgBufPtr - sample, ECG_BUF_LENGTH);
for( i = 0; i < sample; i++ )
{
data = *( gRDetEcgBuf + ptr );
ptr += 1;
if( ptr >= ECG_BUF_LENGTH )
ptr = 0;
if( data > SATURATION_HI )
{
numberFF ++;
if( delay < FASTCHANGING )
{
fastChange ++;
}
}
else
if( data < SATURATION_LO )
{
number00 ++;
delay = 0;
}
delay ++;
}
if( number00 > _200MS
|| numberFF > _200MS
|| fastChange > FASTCHANGE_TIME )
{
result = 1;
}
else
{
result = 0;
}
return result;
}
void InitStatics( void )
{
INT i;
sIsLastArrValid = 0;
sHeartRate = -100;
for (i = 0; i < RRINTERVAL_NUM; i ++)
sRrIntervals[i] = 0;
sHrOfOneSecond = -100;
sInnerHeartRate = -100;
sInnerLastHeartRate = -100;
sPreviousMatched = 1;
sOutHR = 0;
sLastArrSelected.type = NML;
sLastArrSelected.position = 0;
sLastArrSelected.isSaved = 1;
sBlankLength = 0;
sNotUpdatedTime = 0;
InitTompkinsStatic( );
}
INT PacePulseOfTheSecond( void )
{
INT pace_count, i;
pace_count = 0;
for( i = 0; i < MAX_PACE_NUM; i ++ )
{
if( gPaceEcg1Cnt[i] <= ARR_SAMPLE_RATE - 1 )
pace_count ++;
}
return pace_count;
}
|
|
|
|
|
And what precisely is your expectation here. You have just dumped a bunch of code in the forum.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I've GPL'd your code.
What was the question again?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Is this in any way related to the detection of obstructive sleep apnea through ECG signal features?
|
|
|
|
|
How I Can Make My Program With Multiple Language For Forms In C# ?
|
|
|
|
|
Do some research, this is the first entry[^] when I typed your question into Google.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Simply put, what would be more efficient?
If I make a program with lets say 20 images that are just solid colors, but put together to make custom controls, then those custom controls are used several times each, would that be as efficient as just creating panels with a solid BackColor?
Would they yield the same results in terms of RAM/CPU consumption? Would one be better then the other?
|
|
|
|
|
Without actually testing it it difficult to be certain - and you could check with the Stopwatch class by handing the Paint event - but my gut feeling is that the solid background colour will be faster and more ram efficient. It's pretty certain to be more ram efficient because it doesn't need to store the colour bitmaps, and a quick look at the reference source says that Graphics.Clear just calls the native clear method SafeNativeMethods.Gdip.GdipGraphicsClear - it doesn't have to faff about with looking to see if any scaling is needed and so forth which the DrawImage version does. And since it is called for every control in Windows every time it's painted, I'd imagine even Microsoft will have put good effort into ensuring it's as fast as possible!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thanks for this I was trying to prove a point to a friend about avoiding images when your just using a solid color and just wanted to re-assure myself
|
|
|
|
|
How to fill directly the cells of a datagrid linked to a table in a databasis? I tried this code but no data is added to the table. It only works when the data comes from a textbox and then sent to the datagrid cells :
public void BD_Conexao()
{
try
{
OdbcConnection con = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxxxx; database=lic; uid=es; password=1234; option = 3 ");
con.Open();
}
catch (Exception ex)
{
Console.WriteLine("Erro na ligação à base de dados. \n{0}", ex.Message);
return;
}
}
public void Consulta()
{
con = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxx; database=lice; uid=estagio; password=1234; option = 3 ");
con.Open();
OdbcCommand Command = con.CreateCommand();
Command.CommandText = "select lojas.Id, lojas.NIF, lojas.Loja, lojas.Bloqueado, lojas.DataFim, lojas.lastupdate, lojas.Nome";
Command.CommandType = CommandType.Text;
Command.Connection = con;
OdbcDataAdapter adapter = new OdbcDataAdapter();
adapter.SelectCommand = Command;
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
grid_lic.DataSource = dataSet;
grid_lic.DataMember = dataSet.Tables[0].TableName;
}
private void bt_preencher_Click(object sender, EventArgs e)
{
BD_Conexao();
string DataFim = dateTimePicker.Value.ToString("yyyy-MM-dd");
string lastupdate = dateTimePicker2.Value.ToString("yyyy-MM-dd");
Commandtext = "insert into lojas (NIF,Loja,bloqueado, DataFim, lastupdate, Nome) values (@NIF,@Loja,@Bloqueado,@DataFim,@lastupdate,@Nome)";
OdbcCommand Command = new OdbcCommand(Commandtext, con);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
Command.ExecuteNonQuery();
Consulta();
}
modified 9-Dec-15 10:09am.
|
|
|
|
|
Command.CommandText = "select lojas.Id, lojas.NIF, lojas.Loja, lojas.Bloqueado, lojas.DataFim, lojas.lastupdate, lojas.Nome";
That SELECT statment does not look complete, you have not told it which table to extract the data from. You should also add some error checking to your code to test that your commands work as expected.
|
|
|
|
|
The problem is not there, actually I forgot to include here the end of that select ("select lojas.Id, lojas.NIF, lojas.Loja, lojas.Bloqueado, lojas.DataFim, lojas.lastupdate, lojas.Nome from lojas";).
I´ve made exactly the same but using textboxes instead of filling directly the datagrid cell, and the data was added. The code written below works, but data is inserted in texboxes instead of datagrid cells. I don't want to use any buttons, I want to add data directly in the datagrid with no buttons nor texboxes:
string NIF = textBoxNIF.Text;
int loja = int.Parse(textBoxLoja.Text);
int bloqueador = 0;
if (checkBoxBloq.Checked == true)
bloqueador = 1;
else
bloqueador = 0;
string DataFim = dateTimePicker1.Value.ToString("yyyy-MM-dd");
string lastupdate = dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss");
string Nome = textBoxNome.Text;
string Commandtext = "insert into lojas (NIF,loja,Bloqueado,DataFim,lastupdate,Nome) values ('" + NIF + "', " + loja + "," + bloqueador + ",'" + DataFim + "','" + lastupdate + "','" + Nome + "')";
OdbcCommand cm2 = new OdbcCommand(Commandtext, con);
cm2.ExecuteNonQuery();
Consulta();
Why does this code works but the first I put doesn't?
|
|
|
|
|
Why have you taken a perfectly good parameterized query, and replaced it with one that's vulnerable to SQL Injection[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Which query is vulnerable to injection? What do you propose in order to fill de datagrid directly in its cells without texboxes?
Thank you.
|
|
|
|
|
Member 11449447 wrote: Which query is vulnerable to injection?
Take a guess!
Member 11449447 wrote:
string Commandtext = "insert into lojas (NIF,loja,Bloqueado,DataFim,lastupdate,Nome) values ('" + NIF + "', " + loja + "," + bloqueador + ",'" + DataFim + "','" + lastupdate + "','" + Nome + "')";
OdbcCommand cm2 = new OdbcCommand(Commandtext, con);
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
The OdbcCommand uses positional, not named, parameters. You have to use ? as the parameter placeholder in the query, and add the parameters in the same order as they appear in the query.
using (OdbcConnection connection = CreateConnection())
using (OdbcCommand command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection))
{
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("NIF", grid_lic.CurrentRow.Cells[1].Value);
command.Parameters.AddWithValue("Loja", grid_lic.CurrentRow.Cells[2].Value);
command.Parameters.AddWithValue("Bloqueado", checkBox_bloq.Checked);
command.Parameters.AddWithValue("DataFim", grid_lic.CurrentRow.Cells[4].Value);
command.Parameters.AddWithValue("lastupdate", grid_lic.CurrentRow.Cells[5].Value);
command.Parameters.AddWithValue("Nome", grid_lic.CurrentRow.Cells[6].Value);
connection.Open();
command.ExecuteNonQuery();
}
As to your original problem: you're storing the OdbcConnection instance in a field, which is a bad idea. Your BD_Conexao method is creating and opening a new connection, but only stores it in a local variable. The field is never updated, so your bt_preencher_Click method is unable to use that field.
Remove the field, and use a method which creates and returns the connection object instead:
private static OdbcConnection CreateConnection()
{
return new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxxxx; database=lic; uid=es; password=1234; option = 3 ");
}
public void Consulta()
{
using (OdbcConnection connection = CreateConnection())
using (OdbcCommand command = new OdbcCommand("SELECT Id, NIF, Loja, Bloqueado, DataFim, lastupdate, Nome FROM lojas", connection))
{
...
}
}
private void bt_preencher_Click(object sender, EventArgs e)
{
using (OdbcConnection connection = CreateConnection())
using (OdbcCommand command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection))
{
...
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you very much, it seems to be functioning now.
|
|
|
|
|
I design a form which show color scheme on datagridview(alternate rows).it work fine. But when I call it from mdi parent form menu strip tab, Then it does not show color on datagridview(which fill on form load function).When I run only child form it shows like color on gridview3 and datagridview4.But when I call from parent then it does not show color in datagridview3(alternate rows) and datagridview4(alternate rows).
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedItem = "Select Gender";
using (SqlConnection con = new SqlConnection(conn))
{
SqlDataAdapter sda = new SqlDataAdapter("getdata", con);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
ds.Tables[0].TableName = "Product";
ds.Tables[1].TableName = "Category";
dataGridView3.DataSource = ds.Tables["Product"];
dataGridView4.DataSource = ds.Tables["Category"];
}
gridrowcolor();
}
public void gridrowcolor()
{
DataGridViewCellStyle st = new DataGridViewCellStyle();
st.Font = new Font("Arial", 12, FontStyle.Bold);
for (int i = 0; i < dataGridView4.Rows.Count-1; i++)
{
int ii = Convert.ToInt32(dataGridView4.Rows[i].Cells[0].Value.ToString());
if (ii % 2 == 0)
{
dataGridView4.Rows[i].DefaultCellStyle.BackColor = Color.Gray;
dataGridView4.Rows[i].DefaultCellStyle = st;
}
else
dataGridView4.Rows[i].DefaultCellStyle.BackColor = Color.Brown;
}
for (int i = 0; i < dataGridView3.Rows.Count - 1; i++)
{
dataGridView3.CellBorderStyle = DataGridViewCellBorderStyle.None;
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Font = new Font(dataGridView3.Font, FontStyle.Bold);
int ii = Convert.ToInt32(dataGridView3.Rows[i].Cells[0].Value.ToString());
if (ii % 2 == 0)
{
dataGridView3.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
dataGridView3.Rows[i].DefaultCellStyle = style;
dataGridView3.DefaultCellStyle.SelectionForeColor = Color.Chocolate;
}
else
dataGridView3.Rows[i].DefaultCellStyle.BackColor = Color.Orange;
}
}
From Parent MDI Form
private void receiptCancelRequestToolStripMenuItem_Click(object sender, EventArgs e)
{
Form1 frm = new Form1();
frm.MdiParent = this;
frm.Show();
}
modified 9-Dec-15 6:37am.
|
|
|
|
|
You need to show us the code and explain where you think it is going wrong. Please edit your question and add the details. Note: please ensure you add <pre> tags around your code, you can use the code link above the edit window to do it.
|
|
|
|
|
I have a nice idea for the work of the program running on Android platform
A Dictionary Is it possible to help CODE
|
|
|
|
|
OK.... what? Your post doesn't make any sense at all. Are you asking how to write a Dictionary application?
|
|
|
|
|
Same question posted on QA using the name 'eng_aza'
Please do not double-post.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Please make your question understandable.
|
|
|
|
|