*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="importdata.vcx" CPID="1250" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS frm_import AS _frmbase OF "_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="Pixels" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="clb_tx_fisier" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cmd_cauta1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdOriginal" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdOriginal.cColumn.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdOriginal.cColumn.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdImport" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdImport.cColumn.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdImport.cColumn.Text1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdImport.cColumnImport.Header1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdImport.cColumnImport._cbbase1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_precedent1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_urmator1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cmd_executa1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_renunt1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="grdTabel" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*p: cfile
	*</DefinedPropArrayMethod>

	*<PropValue>
		cfile = 
		DoCreate = .T.
		Height = 455
		Name = "frm_import"
		Width = 626
		WindowState = 2
		_SHAPE1.Anchor = 10
		_SHAPE1.Height = 29
		_SHAPE1.Left = 0
		_SHAPE1.Name = "_SHAPE1"
		_SHAPE1.Top = 0
		_SHAPE1.Width = 630
		_SHAPE2.Left = 276
		_SHAPE2.Name = "_SHAPE2"
		_SHAPE2.Top = 0
		_SHAPE2.Visible = .F.
		LB_TITLU_ALB_B121.Caption = "Import"
		LB_TITLU_ALB_B121.Name = "LB_TITLU_ALB_B121"
		LB_TITLU_ALB_B121.TabIndex = 10
		BUT_TERMIN1.Anchor = 8
		BUT_TERMIN1.Left = 596
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 8
		BUT_TERMIN1.Top = 1
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'But_precedent1' AS but_precedent WITH ;
		Left = 232, ;
		Name = "But_precedent1", ;
		Picture = ..\grafice\precedent1.bmp, ;
		TabIndex = 6, ;
		Top = 180
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_renunt1' AS but_renunt WITH ;
		Anchor = 8, ;
		Left = 566, ;
		Name = "But_renunt1", ;
		TabIndex = 9, ;
		Top = 1
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'But_urmator1' AS but_urmator WITH ;
		Left = 232, ;
		Name = "But_urmator1", ;
		TabIndex = 5, ;
		Top = 150
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'clb_tx_fisier' AS clb_tx_simplu WITH ;
		Height = 29, ;
		Left = 12, ;
		Name = "clb_tx_fisier", ;
		TabIndex = 1, ;
		Top = 48, ;
		Width = 395, ;
		TEXT_SIMPLU1.ControlSource = "thisform.cFile", ;
		TEXT_SIMPLU1.Height = 23, ;
		TEXT_SIMPLU1.Left = 50, ;
		TEXT_SIMPLU1.Name = "TEXT_SIMPLU1", ;
		TEXT_SIMPLU1.Top = 3, ;
		TEXT_SIMPLU1.Width = 340, ;
		LB_SIMPLU1.Caption = "Fisier", ;
		LB_SIMPLU1.Name = "LB_SIMPLU1"
		*< END OBJECT: ClassLib="lb_tx.vcx" BaseClass="container" />

	ADD OBJECT 'Cmd_cauta1' AS cmd_cauta WITH ;
		Caption = "...", ;
		Height = 27, ;
		Left = 413, ;
		Name = "Cmd_cauta1", ;
		TabIndex = 2, ;
		Top = 48, ;
		Width = 39
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Cmd_executa1' AS cmd_executa WITH ;
		Left = 468, ;
		Name = "Cmd_executa1", ;
		TabIndex = 3, ;
		Top = 48
		*< END OBJECT: ClassLib="cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'grdImport' AS _grdrow WITH ;
		ColumnCount = 2, ;
		DeleteMark = .F., ;
		Height = 201, ;
		Left = 264, ;
		Name = "grdImport", ;
		Panel = 1, ;
		RecordSource = "crsTabelaImport", ;
		TabIndex = 7, ;
		Top = 87, ;
		Width = 354, ;
		Column1.ControlSource = "column_name", ;
		Column1.Name = "cColumn", ;
		Column1.Width = 187, ;
		Column2.ControlSource = "column_import", ;
		Column2.Name = "cColumnImport", ;
		Column2.Sparse = .F., ;
		Column2.Width = 134
		*< END OBJECT: ClassLib="_grd_base.vcx" BaseClass="grid" />

	ADD OBJECT 'grdImport.cColumn.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Coloana", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'grdImport.cColumn.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'grdImport.cColumnImport._cbbase1' AS _cbbase WITH ;
		BorderStyle = 0, ;
		ControlSource = "column_import", ;
		Left = 41, ;
		Name = "_cbbase1", ;
		RowSource = "crsCols.Column_Name", ;
		RowSourceType = 2, ;
		Top = 23
		*< END OBJECT: ClassLib="_cb_base.vcx" BaseClass="combobox" />

	ADD OBJECT 'grdImport.cColumnImport.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Coloana Import", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'grdOriginal' AS _grdrow WITH ;
		ColumnCount = 1, ;
		DeleteMark = .F., ;
		Height = 201, ;
		Left = 12, ;
		Name = "grdOriginal", ;
		Panel = 1, ;
		RecordSource = "crsTabelaOriginala", ;
		TabIndex = 4, ;
		Top = 87, ;
		Width = 219, ;
		Column1.ControlSource = "column_name", ;
		Column1.Name = "cColumn", ;
		Column1.Width = 187
		*< END OBJECT: ClassLib="_grd_base.vcx" BaseClass="grid" />

	ADD OBJECT 'grdOriginal.cColumn.Header1' AS header WITH ;
		Alignment = 2, ;
		Caption = "Coloana", ;
		Name = "Header1"
		*< END OBJECT: BaseClass="header" />

	ADD OBJECT 'grdOriginal.cColumn.Text1' AS textbox WITH ;
		BackColor = 255,255,255, ;
		BorderStyle = 0, ;
		ForeColor = 0,0,0, ;
		Margin = 0, ;
		Name = "Text1"
		*< END OBJECT: BaseClass="textbox" />

	ADD OBJECT 'grdTabel' AS _grdrow WITH ;
		Anchor = 15, ;
		Height = 144, ;
		Left = 17, ;
		Name = "grdTabel", ;
		Panel = 1, ;
		ReadOnly = .F., ;
		RecordSource = "", ;
		TabIndex = 7, ;
		Top = 303, ;
		Width = 602
		*< END OBJECT: ClassLib="_grd_base.vcx" BaseClass="grid" />
	
	PROCEDURE Destroy
		
		IF USED('crsTabelaOriginala')
			USE IN crsTabelaOriginala
		ENDIF 
		IF USED('crsTabelaImport')
			USE IN crsTabelaImport
		ENDIF 
		IF USED('crsCols')
			USE IN crsCols
		ENDIF 
		
		IF USED('fisImport')
			USE IN fisImport
		ENDIF 
	ENDPROC

	PROCEDURE do_cauta
		CD c:\
		this.cFile = GETFILE('dbf','Selectati','Fisier',0,'Selectati fisierul de import')
		this.clb_tx_fisier.Refresh()
	ENDPROC

	PROCEDURE do_executa
		LOCAL lcFile
		lcFile = ALLTRIM(this.cFile)
		IF EMPTY(lcFile)
			RETURN
		ENDIF 
		IF !FILE(lcFile)
			aMESSAGEBOX('Nu exista fisierul ' +_lcFile,0+48,_screen.Caption)
			RETURN 
		ENDIF 
		IF USED('fisImport')
			USE IN fisImport
		ENDIF 
		USE (lcFile) IN 0 SHARED ALIAS fisImport
		
		DELETE FROM crsTabelaImport
		DELETE FROM crsTabelaOriginala
		SELECT fisImport
		lnColumns = FCOUNT('fisImport')
		FOR i = 1 TO lnColumns
			lcColumn = FIELD(i)
			INSERT INTO crsTabelaOriginala (column_name) VALUES (lcColumn)
		ENDFOR 
		
		
		SELECT crsTabelaOriginala
		GO TOP 
		
		this.LockScreen = .T.
		this.grdTabel.RecordSource=""
		this.grdTabel.ColumnCount = -1
		this.grdTabel.RecordSource="fisimport"
		this.LockScreen = .F.
		this.grdTabel.Refresh()
		this.grdImport.Refresh()
		this.grdOriginal.Refresh()
		
		this.grdOriginal.SetFocus()
	ENDPROC

	PROCEDURE do_precedent
		llSucces = .T.
		lcColumn = UPPER(ALLTRIM(crsTabelaImport.column_name))
		IF EMPTY(lcColumn)
			llSucces = .F.
		ENDIF
		DELETE FROM crsTabelaImport WHERE UPPER(ALLTRIM(column_name)) = lcColumn
		this.grdImport.SetFocus()
	ENDPROC

	PROCEDURE do_urmator
		llSucces = .T.
		lcColumn = UPPER(ALLTRIM(crsTabelaOriginala.column_name))
		IF EMPTY(lcColumn)
			llSucces = .F.
		ENDIF
		IF llSucces
			SELECT column_name FROM crsTabelaImport WHERE UPPER(ALLTRIM(column_name)) = lcColumn INTO CURSOR crsTemp
			IF _tally = 1
				llSucces = .F.
			ENDIF  
			IF USED('crsTemp')
				USE IN crsTemp
			ENDIF 
		ENDIF 
		IF llSucces
			INSERT INTO crsTabelaImport (column_name) VALUES (lcColumn)
		ENDIF 
		this.grdImport.SetFocus()
		
		 
		
		
		
	ENDPROC

	PROCEDURE inainte_de_do_termin
		LOCAL llSucces
		llSucces = .F.
		SELECT column_import, COUNT(*) as nr FROM crsTabelaImport GROUP BY column_import HAVING nr > 1 INTO CURSOR crsTemp
		IF _tally > 0
			SELECT crsTemp
			GO TOP 
			lcColoana = ALLTRIM(column_import)	
			aMESSAGEBOX('Alegeti alta coloana de import pentru ' + lcColoana)
		ELSE
			llSucces = .T.
		ENDIF 
		USE IN crsTemp
		
		
		
		
		*!*	lcCreateCursor = [SELECT ]
		lcSelect = []
		SELECT crsTabelaImport
		SCAN
			lcColumn = UPPER(ALLTRIM(column_name))
		*!*		SELECT crsCols
		*!*		LOCATE FOR UPPER(ALLTRIM(column_name)) = lcColumn
		*!*		IF !FOUND()
		*!*			LOOP
		*!*		ENDIF 
			lcColumnName = UPPER(ALLTRIM(column_IMPORT))
		*!*		lcColumnType = UPPER(ALLTRIM(column_type))
		*!*		lnColumnSize1 = column_size1	
		*!*		lnColumnSize2 = column_size2	
			
		*!*		lcCreateCursor = lcCreateCursor + lcColum + [ ] + lcColumnType + ;
		*!*			IIF(!EMPTY(lnColumnSize1),[(] + ALLTRIM(STR(lnColumnSize1)) + IIF(!EMPTY(lnColumnSize2),[,]+ALLTRIM(STR(lnColumnSize2))+[)],[]) + [)],[])  + [,]
			lcSelect = lcSelect + lcColumn + [ as ] + lcColumnName + [,]
		ENDSCAN 
		IF RIGHT(lcSelect,1) = [,]
			lcSelect = LEFT(lcSelect, LEN(lcSelect) - 1)
		ENDIF 	
		
		llUsed = .T.
		IF !USED('fisImport')
			llUsed = .F.
			lcFile = ALLTRIM(this.cFile) 
			USE (lcFile) IN 0 SHARED ALIAS fisImport 
		ENDIF 
		IF EMPTY(lcSelect)
			lcSelect = [ * ]
		ENDIF 
		lcSelect = [SELECT ] + lcSelect + [ from fisImport into cursor crsReturn]
		&lcSelect
		
		IF !llUsed
			IF USED('fisImport')
				USE IN fisImport
			ENDIF 
		ENDIF 
		
		RETURN llSucces
		
	ENDPROC

	PROCEDURE Load
		CREATE CURSOR crsTabelaOriginala (column_name c(100))
		SELECT column_name,SPACE(100) as column_import FROM crsTabelaOriginala INTO CURSOR crsTabelaImport READWRITE 
		
		
		CREATE CURSOR crsCols (column_name c(100), column_type c(1), column_size1 n(10), column_size2 n(10))
		INSERT INTO crsCols (column_name, column_type, column_size1, column_size2) VALUES ('SCD', 'C', 4, 0)
		INSERT INTO crsCols (column_name, column_type, column_size1, column_size2) VALUES ('ASCD', 'C', 4, 0)
		INSERT INTO crsCols (column_name, column_type, column_size1, column_size2) VALUES ('SCC', 'C', 4, 0)
		INSERT INTO crsCols (column_name, column_type, column_size1, column_size2) VALUES ('ASCC', 'C', 4, 0)
		INSERT INTO crsCols (column_name, column_type, column_size1, column_size2) VALUES ('SUMA', 'N', 20, 4)
		INSERT INTO crsCols (column_name, column_type, column_size1, column_size2) VALUES ('EXPLICATIA', 'C', 30, 0)
		
	ENDPROC

ENDDEFINE
