📄 flowchrt.c
字号:
break;
}
return 0;
}
/*----------------------------------------------------------------------------*/
/* Deactivate Map or SQL button pressed */
/*----------------------------------------------------------------------------*/
int CVICALLBACK DeactivateCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
/* If Button not color active, return */
if (CheckColor(panel, control, ONCOLOR)==0) return 0;
/* Turn off Previous States Choices */
status = SetCtrlAttribute (mainPnl, PANEL_DBFetch, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBCreateRecord, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
/* Issue DeactivateMap */
DBFunc_DeactivateMap (flagMapUsed);
status = SetCtrlAttribute (mainPnl, PANEL_DBDeactivateMap, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
/* Goto Next State in the Flowchart */
status = SetCtrlAttribute (mainPnl, PANEL_DBImmediateSQL, ATTR_CMD_BUTTON_COLOR, ONCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBActivateSQL, ATTR_CMD_BUTTON_COLOR, ONCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBBeginMap, ATTR_CMD_BUTTON_COLOR, ONCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBDisconnect, ATTR_CMD_BUTTON_COLOR, ONCOLOR);
break;
case EVENT_RIGHT_CLICK:
DisplayHelpSection("Deactivate");
break;
}
return 0;
}
/*----------------------------------------------------------------------------*/
/* Disconnect Button button pressed */
/*----------------------------------------------------------------------------*/
int CVICALLBACK DisconnectCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
/* If Button not color active, return */
if (CheckColor(panel, control, ONCOLOR)==0) return 0;
/* Issue Dissconnect */
DBFunc_Disconnect();
status = SetCtrlAttribute (mainPnl, PANEL_DBDisconnect, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBImmediateSQL, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBActivateSQL, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
status = SetCtrlAttribute (mainPnl, PANEL_DBBeginMap, ATTR_CMD_BUTTON_COLOR, OFFCOLOR);
/* Goto Next State in the Flowchart */
status = SetCtrlAttribute (mainPnl, PANEL_DBConnect, ATTR_CMD_BUTTON_COLOR, ONCOLOR);
break;
case EVENT_RIGHT_CLICK:
DisplayHelpSection("Disconnect");
break;
}
return 0;
}
/*----------------------------------------------------------------------------*/
/* Quit Button pressed */
/*----------------------------------------------------------------------------*/
int CVICALLBACK Quit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
case EVENT_RIGHT_CLICK:
break;
}
return 0;
}
/*----------------------------------------------------------------------------*/
/* Help Button pressed */
/*----------------------------------------------------------------------------*/
int CVICALLBACK Help (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
DisplayHelpSection("FLOWCHRT Project Help");
break;
case EVENT_RIGHT_CLICK:
DisplayHelpSection("FLOWCHRT Project Help");
break;
}
return 0;
}
/*----------------------------------------------------------------------------*/
/* Check to see if panel control has the color that was passed */
/*----------------------------------------------------------------------------*/
int CheckColor (int panel, int control, int color)
{
int getcolor;
status = GetCtrlAttribute (panel, control, ATTR_CMD_BUTTON_COLOR, &getcolor);
if (getcolor==color)
return 1;
else {
Beep();
return 0;
}
}
/*----------------------------------------------------------------------------*/
/* Display Panel Help */
/*----------------------------------------------------------------------------*/
int DisplayHelpSection(char *title)
{
int fileHandle, offset, bytes, done, found, total;
char line[128], findString[40];
char *charptr;
size_t charsize = 4000;
fileHandle = OpenFile ("flowchrt.txt", 1, 2, 1);
bytes=1;
done = 0;
found = 0;
Fmt(findString,"BEGINHELP %s", title);
while ((bytes>=0) && (found==0)) {
bytes = ReadLine (fileHandle, line, 127);
if (FindPattern (line, 0, StringLength(findString), findString, 1, 0)>=0)
found = 1;
}
total = 0;
if (found==1) {
charptr = (char *)malloc (charsize);
Fmt(findString,"ENDHELP %s", title);
while ((bytes>=0) && (done==0)) {
bytes = ReadLine (fileHandle, line, 127);
if (FindPattern (line, 0, StringLength(findString), findString, 1, 0)>=0)
done = 1;
else {
CopyString (charptr, total, line, 0, bytes);
total = total + bytes;
charptr[total]='\n';
total++;
charptr[total]='\0';
}
}
if (done==1)
status = MessagePopup (title, charptr);
free(charptr);
}
status = CloseFile (fileHandle);
Error:
return -1;
}
/*---------------------------------------------------------------------------*/
/* See if table exists and issue DROP TABLE SQL if it does */
/*---------------------------------------------------------------------------*/
void EraseIfTableExists(int hdbc, char *tableNamePassed)
{
int hstmt, found, resCode;
char tabQual[130], user[130], table[130], remarks[258], buffer[128];
int tabQualStat, userStat, tableStat, tabTypeStat, remStat, result;
short tabType;
/* Query Data Source for list of all tables */
hstmt = DBTables (hdbc, "*", "*", "*", DB_TBL_TABLE);
if (hstmt <= 0) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Bind data returned (Even though DBTables returns multiple columns, */
/* we only have to bind the column we are interested in, the name.) */
resCode = DBBindColChar(hstmt, 3, 129, table, &tableStat, "");
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Loop through table list to see if table exists */
found = 0;
while ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS) {
result = FindPattern (table, 0, -1, tableNamePassed, 0, 1);
if (result!=-1) found = 1;
}
if ((resCode != DB_SUCCESS) && (resCode != DB_EOF)) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Deactivate Table Query */
resCode = DBDeactivateSQL (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* If table exists, execute DROP TABLE to delete table */
if (found == 1) {
/*Insert values into the database*/
Fmt(buffer,"DROP TABLE %s", tableNamePassed);
resCode = DBImmediateSQL (hdbc, buffer);
if (resCode != 0) {MessagePopup ("SQL ERROR",DBErrorMessage ()); RemovePopup(1);return;}
}
return;
}
/*---------------------------------------------------------------------------*/
/* Open Data Source and generate Misc data */
/*---------------------------------------------------------------------------*/
void InitializeDB (void)
{
char uutNum[11];
double meas1, meas2;
int meas1Stat, meas2Stat, uutStat;
int nativeResCode;
hdbc = DBConnect (FLOW_DSN);
if (hdbc <= 0) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Erase the table if it exists */
EraseIfTableExists(hdbc, FLOW_TABLE);
/* begin map for constructed SQL statement */
hmap = DBBeginMap (hdbc);
if (hmap <= 0) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* specify the columns to be selected and the variables where column */
/* values will be placed. */
resCode = DBMapColumnToChar (hmap, "UUT_NUM", 11, uutNum, &uutStat,"");
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
resCode = DBMapColumnToDouble (hmap, "MEAS1", &meas1, &meas1Stat);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
resCode = DBMapColumnToDouble (hmap, "MEAS2", &meas2, &meas2Stat);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
resCode = DBCreateTableFromMap (hmap, FLOW_TABLE);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Execute the map for table. (construct a SQL Select */
/* statement, execute the statement, bind the selected columns to */
/* the previously specified variables. */
hstmt = DBActivateMap (hmap, FLOW_TABLE);
if (hstmt == 0) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Create the some records */
resCode = DBCreateRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* Put values into the bound variables */
strcpy(uutNum, "2860A123");
meas1 = 0.5;
meas2 = 0.5;
/* Insert the record into the database */
resCode = DBPutRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
/* some more records */
resCode = DBCreateRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
strcpy(uutNum, "2860A124");
meas1 = 0.0;
meas2 = 0.5;
resCode = DBPutRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
resCode = DBCreateRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
meas1 = 0.6;
meas2 = 0.4;
resCode = DBPutRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
resCode = DBCreateRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
strcpy(uutNum, "2860A126");
meas1 = 0.0;
meas2 = 1.1;
resCode = DBPutRecord (hstmt);
if (resCode != DB_SUCCESS) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
resCode = DBDeactivateMap(hmap);
resCode = DBDisconnect (hdbc);
if (resCode < 0) {MessagePopup ("SQL ERROR",DBErrorMessage ()); return;}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -