//AB/ Project Editer record //AB/ Object oIDE_Project is a Dialog_Project //AB/ Set Size to 318 466 //AB/ Set ProjectName to "Editer record" //AB/ Set ProjectFileName to "Editer_record.DG" //AB/ Set GenerateFileName to "NONAME26" // Project Object Structure // Editer_record_dg is a ModalPanel // Container3d1 is a Container3d // Datagrid is a Grid // oClose is a Button // Register all objects Register_Object Container3d1 Register_Object Datagrid Register_Object Editer_record_dg Register_Object oClose //AB-IgnoreStart Use Windows.pkg //AB-IgnoreEnd Object Editer_record_dg is a ModalPanel //AB-StoreTopStart Property Integer LeaveNoAsk public 1 // Exit window without any questions Property Integer pModifiedField public 0 // Has the record been changed? Property RowID prwCurrentRecord // Current record Function FetchFromField Integer ActField Returns String Local String sOutTxt Get value of (Datagrid(Container3d1(Self))) Item ((ActField * 2) -1) to sOutTxt Function_Return sOutTxt End_Function //AB-StoreTopEnd Set Border_Style to Border_Thick Set Label to "Edit record" Set Location to 14 45 Set Size to 266 379 Set piMinSize to 100 379 //AB-DDOStart //AB-DDOEnd Object Container3d1 is a Container3d Set Size to 229 369 Set Location to 2 2 Set peAnchors to anAll Object Datagrid is a Grid Set Size to 218 359 Set Location to 4 3 Set peAnchors to anAll Set Line_Width to 2 0 Set Form_Width Item 0 to 150 Set Header_Label Item 0 to "Fieldname and fieldtypes" Set Form_Width Item 1 to 200 Set Header_Label Item 1 to "Contents" //AB-StoreStart Set Line_Width to 2 0 Set select_mode to no_select On_Key Key_F2 Send DoSaveRecord Function DescribeFieldtype Integer iFieldType Returns String Local String sMessage If (iFieldType = DF_ASCII) Move "ASC" to sMessage If (iFieldType = DF_BCD) Move "NUM" to sMessage If (iFieldType = DF_DATE) Move "DATE" to sMessage If (iFieldType = DF_TEXT) Move "TEXT" to sMessage If (iFieldType = DF_BINARY) Move "BIN" to sMessage If (iFieldType = DF_OVERLAP) Move "OVLP" to sMessage Function_Return sMessage End_Function Procedure Fill_the_List Local Integer itms iNoOfFields iActPos lcif rcif iSysfil Local Integer iFilenum oFildef iFieldType iFieldLng iFieldComma Local Integer iSpecFile Local String strTemp sDescribe sLogicalname Send cursor_wait to (cursor_control(current_object)) Move (afildef(Self)) to oFildef Send delete_data Get pDataNumFields to iNoOfFields Get pSystemfile to iSysfil For iActPos From 1 to iNoOfFields Get String_value of oFildef Item (iActPos * 4) to sDescribe Get integer_value of oFildef Item ((iActPos * 4) + 1) to iFieldType Move (DescribeFieldtype(Self, iFieldType)) to strtemp Append sDescribe ", " strtemp Get integer_value of oFildef Item ((iActPos * 4) + 2) to iFieldLng Append sDescribe ", " iFieldLng If (iFieldType = DF_BCD) Begin Get integer_value of (afildef(Self)) Item ((iActPos * 4) + 3) to iFieldComma calc (iFieldLng - iFieldComma) to lcif Move iFieldComma to rcif Append sDescribe " (" lcif "," rcif ")" End Send Add_Item 0 sDescribe Send Add_Item 0 "" Get Item_Count to Itms Set entry_state Item (itms -2) to False Set item_color Item (itms-2) to clLtgray If ((iFieldType = DF_BINARY) or (iFieldType = DF_OVERLAP) or (iFieldType = DF_TEXT)) Begin Set shadow_state Item (itms-1) to True Set item_color Item (itms-1) to clRed Set item_color Item (itms-2) to clRed End Loop Send DoUpdateRecstatus Set current_item to 1 //Top of datacolumn Send cursor_ready to (cursor_control(current_object)) End_Procedure Procedure Set Current_Item Integer Itm local Integer oldst lcif rcif Local Integer iFieldLng iActPos iFieldType iFieldComma Get dynamic_update_state to oldst Set Dynamic_Update_State to False calc (itm / 2) to iActPos Increment iActPos Forward Set Current_Item to (Itm -1) // Make sure that column 0 is shown Forward Set Current_Item to Itm If (Mod(itm, 2)) Begin // Only column 2 (every second item ie. 1, 3, 5...) // Initialize, so that a change to ie. a date-field does not erase the current field Get integer_value of (aFildef(Self)) Item ((iActPos * 4) + 1) to iFieldType Get integer_value of (aFildef(Self)) Item ((iActPos * 4) + 2) to iFieldLng If (iFieldType = DF_DATE) Begin Move 10 to iFieldLng Set form_datatype Item 1 to date_window Set form_margin Item 1 to iFieldLng End If (iFieldType = DF_ASCII) Begin Set form_datatype Item 1 to ascii_window Set form_margin Item 1 to iFieldLng End If (iFieldType = DF_BCD) Begin Get integer_value of (aFildef(Self)) Item ((iActPos * 4) + 3) to iFieldComma If iFieldComma Increment iFieldLng // Room for comma Set Form_datatype Item 1 to ascii_window Set form_margin Item 1 to iFieldLng End If (iFieldType = DF_TEXT) Begin Set form_datatype Item 1 to ascii_window Set form_margin Item 1 to iFieldLng End If (iFieldType = DF_BINARY) Begin Set form_datatype Item 1 to ascii_window Set form_margin Item 1 to 1 // Is normally locked End If (iFieldType = DF_OVERLAP) Begin Set form_datatype Item 1 to ascii_window Set form_margin Item 1 to 1 // Is normally locked End End Set dynamic_update_State to OldSt End_Procedure Procedure item_change Integer fromi Integer toi Returns Integer local Integer rval iError Local Integer iActPos iFieldType Local String strTemp Local Number nTest Local Date dTest calc (fromi / 2) to iActPos Increment iActPos If (Mod(fromi, 2)) Begin // Only column 2 (every second item ie. 1, 3, 5...) Get integer_value of (aFildef(Self)) Item ((iActPos * 4) + 1) to iFieldType If (iFieldType = DF_DATE) Begin Get FetchFromField iActPos to strTemp indicate err False Move strTemp to dTest // Will generate error 16 if this is not a valid date. [err] Procedure_Return fromi Send DoSaveInField iActPos dTest End // If (iFieldType = DF_ASCII) begin // end If (iFieldType = DF_BCD) Begin // Make sure that this is a valid numer (without any letters and so forth.) Get FetchFromField iActPos to strTemp indicate err False Move strTemp to nTest // Will generate error 51, 52 or 54 if this is not a valid number. [err] Procedure_Return fromi Send DoSaveInField iActPos nTest End // If (iFieldType = DF_TEXT) begin // end // If (iFieldType = DF_BINARY) begin // end // If (iFieldType = DF_OVERLAP) begin // end End Forward Get msg_item_change fromi toi to rval Procedure_Return rval End_Procedure Procedure Next Send Key kDownarrow End_Procedure Procedure Previous Send Key kUparrow End_Procedure Procedure DoSaveRecord Integer iAktFelt iMaxFelt iFieldType Integer iFile String strTemp Number nTest Date dTest RowID rwRecord Boolean bFound Get prwCurrentRecord to rwRecord Get piFileNumber to iFile Clear iFile Move (FindByRowId(iFile, rwRecord)) to bFound If (bFound) Begin Reread iFile Get pDataNumFields to iMaxFelt For iAktFelt From 1 to iMaxFelt Get integer_value of (aFildef(Self)) Item ((iAktFelt * 4) + 1) to iFieldType If (iFieldType = DF_DATE) Begin Get FetchFromField iAktFelt to strTemp indicate err False Move strTemp to dTest // Will generate error 16 if this is not a valid date. [err] Begin Clear iFile Unlock Procedure_Return End Set_Field_Value iFile iAktFelt to dTest End If (iFieldType = DF_ASCII) Begin Get FetchFromField iAktFelt to strTemp Set_Field_Value iFile iAktFelt to strTemp End If (iFieldType = DF_BCD) Begin // Make sure that this is a valid numer (without any letters and so forth.) Get FetchFromField iAktFelt to strTemp indicate err False Move strTemp to nTest // Will generate error 51, 52 or 54 if this is not a valid number. [err] Begin Clear iFile Unlock Procedure_Return End Set_Field_Value iFile iAktFelt to strTemp End // If (iFieldType = DF_TEXT) begin // end // If (iFieldType = DF_BINARY) begin // end // If (iFieldType = DF_OVERLAP) begin // end Loop Saverecord iFile Unlock Send DoPageRefresh of tilpas_vw Send Close_panel End End_Procedure //AB-StoreEnd End_Object // Datagrid End_Object // Container3d1 Object oClose is a Button Set Label to "Close" Set Location to 234 321 Set peAnchors to anBottomRight //AB-StoreStart Procedure OnClick Send Close_panel End_Procedure // OnClick //AB-StoreEnd End_Object // oClose //AB-StoreStart On_Key kCancel Send close_panel Procedure DoSaveInField Integer ActField Integer strTemp Set value of (Datagrid(Container3d1(Self))) Item ((ActField * 2) -1) to strTemp Set pModifiedField to True End_Procedure Procedure DoUpdateRecstatus Local String strTemp sLogicalname Local Integer iMaxRecord ActField iNoOfFields Local Integer oData iOffset iSysfil iForceInit oForceInit Integer iFile RowID rwRecord Move (aRecData(Self)) to oData Get prwCurrentRecord to rwRecord Get piFileNumber to iFile Get pDataNumFields to iNoOfFields Get pSystemfile to iSysfil Move 0 to iOffset If (not(IsNullRowId(rwRecord))) Begin For ActField From 1 to iNoOfFields Get string_Value of oData Item (ActField + iOffset -1) to strTemp Send DoSaveInField ActField strTemp Loop End Else Begin //Show an empty record. For ActField From 1 to iNoOfFields Send DoSaveInField ActField "" Loop End End_Procedure Procedure Fill_the_list Send fill_the_list to (Datagrid(Container3d1(Self))) End_Procedure Procedure Close_panel Local Integer iNo iLeaveNoAsk Get LeaveNoAsk to iLeaveNoAsk If not iLeaveNoAsk Begin If (pModifiedField(Self)) Begin Get confirm "Abandon all changes?" to iNo If not iNo Forward Send close_panel End Else Forward Send close_panel End Else Forward Send close_panel End_Procedure //AB-StoreEnd End_Object // Editer_record_dg //AB/ End_Object // oIDE_Project