Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Modifying Some Code To Comply With My Program

Status
Not open for further replies.

foxprox558

Programmer
Oct 19, 2013
53
0
0
US
Code:
**************************************************
PUBLIC go_Form

go_Form = NEWOBJECT("frmForm")

ADDPROPERTY(go_Form, "la_Customers[1]")

go_Form.Show

Read Events
Close all
Clear All
RETURN


**************************************************
DEFINE CLASS cboCombo AS ComboBox
	Width = 48
	Height = 24
	Style = 2
	RowSourceType = 1
	RowSource = "Open,Card,Cash,Check"
	ControlSource = "curOpenSales.C_PaidBy"
	
	PROCEDURE Click()
		LOCAL li_RecNo, lc_Alias
		LOCAL ARRAY la_Open[1]
		
		lc_Alias = ALIAS()
		li_RecNo = RECNO(lc_Alias)
		
		DODEFAULT()
		
		GOTO li_RecNo IN (lc_Alias)
		
		SELECT SUM(N_Price) FROM &lc_Alias WHERE &lc_Alias..C_PaidBy = "Open" INTO ARRAY la_Open
		
		IF VARTYPE(la_Open[1]) != "N"
			la_Open[1] = 0

		ENDIF 

		WITH go_Form.txtTotalSales
			.Value = la_Open[1]
			.Refresh()

		ENDWITH
	ENDPROC 
ENDDEFINE 
	
DEFINE CLASS frmForm AS Form
	AutoCenter = .T.
	Caption = "Sales"
	ShowTips = .T.
	Height = 480
	Width = 648
	MinHeight = This.Height
	MinWidth = This.Width
	
ADD OBJECT lblLastName AS Label WITH ;
	Caption = "Customer Lastname", ;
	Left = 12, ;
	Top = 6, ;
	Autosize = .T., ;
	Anchor = 3
	
ADD OBJECT cboCustomers AS ComboBox WITH ;
	Top = 6, Left = 150, Height = 30, Width = 246, Style = 2, BoundColumn = 2
		
	PROCEDURE cboCustomers.GotFocus()
		SELECT C_LName, C_CID FROM curCustomer ;
			ORDER BY 1 ;
			INTO ARRAY go_Form.la_Customers
		
		This.RowSourceType = 5
		This.RowSource = "go_Form.la_Customers"

	ENDPROC 
	
	PROCEDURE cboCustomers.Click()
		LOCAL ARRAY la_Open[1]
		
		SELECT * FROM curSales ;
			WHERE curSales.C_CID = ALLTRIM(This.Value) AND ;
				curSales.C_PaidBy = "Open" ;
			INTO CURSOR curOpenSales READWRITE 
		
		IF _Tally > 0
			WITH go_Form.grdOpenSales
				.Visible = .T.
				.RowHeight = 24
				.ColumnCount = -1
				.RecordSource = "curOpenSales"
				.SetAll("DynamicBackColor", "IIF(curOpenSales.C_PaidBy != [Open], RGB(255,255,255), RGB(0,255,0))", "Column")  && Alternate white and green records
				.Column1.ReadOnly = .T.
				.Column2.ReadOnly = .T.
				.Column3.ReadOnly = .T.
				.Column3.Sparse = .F.
				.Column3.Text1.InputMask = "9999.99"
				.Column4.Width = 120
				.Column4.Sparse = .F.
				.Column4.AddObject("cboPaidBy", "cboCombo")
				.Column4.RemoveObject("Text1")
				.Column4.CurrentControl = "cboPaidBy"
				.Column4.cboPaidBy.Visible = .T.


			ENDWITH 
		ELSE 
			go_Form.grdOpenSales.visible = .F.
			
		ENDIF
		
		SELECT * FROM curSales ;
			WHERE curSales.C_CID = ALLTRIM(This.Value) ;
			INTO CURSOR curSalesSelection READWRITE 
						
		IF _Tally > 0
			WITH go_Form.grdSales
				.Visible = .T.
				.RowHeight = 24
				.ColumnCount = -1
				.RecordSource = "curSalesSelection"
				.SetAll("DynamicBackColor", "IIF(curSalesSelection.C_PaidBy != [Open], RGB(255,255,255), RGB(0,255,0))", "Column")  && Alternate white and green records
				.Column1.ReadOnly = .T.
				.Column2.ReadOnly = .T.
				.Column3.ReadOnly = .T.
				.Column3.Sparse = .F.
				.Column3.Text1.InputMask = "9999.99"
				.Column3.Text1.FontBold = .T.
				.Column4.ReadOnly = .T.
				.Column4.Width = 120
				.Column4.Sparse = .F.
				.Column4.FontBold = .T.
				.Column5.ReadOnly = .T.

			ENDWITH 

			SELECT SUM(N_Price) FROM curSalesSelection WHERE curSalesSelection.C_PaidBy = "Open" INTO ARRAY la_Open

			IF VARTYPE(la_Open[1]) != "N"
				la_Open[1] = 0

			ENDIF 
			
			WITH go_Form
				.cmdSave.Visible = .T.
				.txtTotalSales.Visible = .T.
				.txtTotalSales.Value = la_Open[1]
				.lblOpenSales.Visible = .T.

			ENDWITH 
		ELSE 
			WITH go_Form
				.grdSales.Visible =.F.
				.cmdSave.Visible = .F.
				.txtTotalSales.Visible = .F.
				.lblOpenSales.Visible = .F.

			ENDWITH 

			= MESSAGEBOX("No open orders for this customer!",0, "Open Sales")

		ENDIF 
		
		go_Form.Refresh()
		
	ENDPROC
	
ADD OBJECT lblSelection AS Label WITH ;
	Caption = "Open Orders", ;
	FontBold = .T., ;
	Left = 12, ;
	Top = 36, ;
	Autosize = .T., ;
	Anchor = 1 + 2

ADD OBJECT lblOrders AS Label WITH ;
	Caption = "All Orders", ;
	FontBold = .T., ;
	Left = 12, ;
	Top = 192, ;
	Autosize = .T., ;
	Anchor = 2 + 8 + 16 + 64

ADD OBJECT shpLine as Line WITH ;
	Top = 180, ;
	Left = 12, ;
	Height = 0, ;
	Width = 624, ;
	Drawmode = 16, ;
	Anchor = 2 + 8 + 16 + 64

ADD OBJECT grdSales AS Grid WITH ;
	Left = 12, ;
	Top = 214, ;
	Width = 624, ;
	Height = 186, ;
	Anchor = 2 + 4 + 8 + 16, ;
	Visible = .F.

ADD OBJECT grdOpenSales AS Grid WITH ;
	Left = 12, ;
	Top = 54, ;
	Width = 624, ;
	Height = 120, ;
	Anchor = 1 + 2 + 8 + 64, ;
	Visible = .F.
	
ADD OBJECT txtTotalSales AS Textbox WITH ;
	Left = 276, Top = 408, Height = 42, Width = 360, Value = 0, InputMask = "999,999.99", Anchor = 2 + 4 + 8, Visible = .F. , ;
	FontBold = .T., FontSize = 24 
	
ADD OBJECT cmdSave AS CommandButton WITH ;
	Left = 12, Top = 408, Height = 42, Width = 60, Caption = "Save", Anchor = 2 + 4, Visible = .F.

	PROCEDURE cmdSave.Click()
		UPDATE curSales SET curSales.C_PaidBy = curOpenSales.C_PaidBy, curSales.C_CCNumber = curOpenSales.C_CCNumber ;
			WHERE curSales.C_CID = curOpenSales.C_CID AND curSales.N_Price = curOpenSales.N_Price
	
		go_Form.cboCustomers.Click()
		
	ENDPROC 

ADD OBJECT lblOpenSales AS Label WITH ;
	Caption = "Open Orders", ;
	Left = 78, ;
	Top = 408, ;
	Height = 42, ;
	Autosize = .T., ;
	FontBold = .T., ;
	FontSize = 24, ;
	Anchor = 2 + 4, ;
	Visible = .F.
	
	
PROCEDURE Destroy
	CLOSE ALL
	Clear Events

ENDPROC

PROCEDURE Load

	CREATE CURSOR curCustomer (C_CID C(3), C_LName C(20))
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI1", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI2", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI3", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI4", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI5", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI6", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI7", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI8", accounts.last+", "+accounts.first)
	INSERT INTO curCustomer (C_CID, C_LName) VALUES ("CI9", accounts.last+", "+accounts.first)
	LOCATE 

	CREATE CURSOR curSales (C_CID C(3), C_Descri C(20), N_Price N(6,2), C_PaidBy C(5), C_CCNumber C(24)) 
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI1", "Description", 4.25, "Card","4566 5421 5445 6666 5564")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI1", "Description", 114.24, "Check","1234")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI1", "Description", 24.22, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI1", "Description", 324.23, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI2", "Description", 54.29, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI2", "Description", 654.27, "Check","1235")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI2", "Description", 47.28, "Check","1236")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI2", "Description", 468.26, "Card","6542 2451 5896 7458 4711")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI3", "Description", 447.24, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI3", "Description", 426.23, "Card","4712 7896 5412 3657 5411")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI3", "Description", 644.24, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI4", "Description", 954.25, "Check","1237")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI4", "Description", 384.27, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI4", "Description", 274.29, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI8", "Description", 164.25, "Card","5478 6895 5213 4652 7444")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI9", "Description", 104.25, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI3", "Description", 384.27, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI4", "Description", 274.29, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI7", "Description", 164.25, "Card","5478 6895 5213 4652 7444")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI6", "Description", 104.25, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI7", "Description", 384.27, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI9", "Description", 274.29, "Card","5478 6895 5213 4652 7444")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI6", "Description", 164.25, "Card","5478 6895 5213 4652 7444")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI4", "Description", 104.25, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI8", "Description", 384.27, "Check","1235")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI7", "Description", 274.29, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI9", "Description", 164.25, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI9", "Description", 104.25, "Open","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI6", "Description", 384.27, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI7", "Description", 274.29, "Check","1255")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI8", "Description", 164.25, "Cash","")
	INSERT INTO curSales (C_CID, C_Descri, N_Price, C_PaidBy, C_CCNumber ) VALUES ("CI9", "Description", 104.25, "Check","4125")

ENDPROC

ENDDEFINE
*********************************************

This code is a response to a thread that I posted. I am not familiar with hard-coded programming in foxpro (Writing programs from scratch) I always program from forms. I would really appreciate it if somebody could help me with this code, I know it's working right, but It's not using my tables (As it was a demo) but I need it to have an added 'Search' TextBox
and 'Search' Button that when you push the search button it takes the info from textbox and looks in the accounts table (it searches by last name) and put them into the combobox in the format
accounts.custno: accounts.last+", "accounts.first
custno=customer number
last=last name
first=first name
it will then retrieve the customer number from the combobox and begin using the 'orders.dbf' table and search with the customer number with orders marked with order status 'orders.stat="P"' ('P' Being 'pending') and then insert them into the grid with the total, and the date it was initiated (orders.dropoff).

REEAlly need help with this one! last part of the program!!
 
>I am not familiar with hard-coded programming in foxpro (Writing programs from scratch) I always program from forms

Well, this code ome from opening a form in the class browser, using the "viewcode" toolbar button and there you have similar code. Tweak it a little and you have what you show.

You can reverse the process, take an empty form and do as the code says, eg:

Code:
DEFINE CLASS frmForm AS Form
	AutoCenter = .T.
	Caption = "Sales"
	ShowTips = .T.
	Height = 480
	Width = 648
	MinHeight = This.Height
	MinWidth = This.Width

Take your new form, open the properties window and set the properties shown here.

Code:
DEFINE CLASS cboCombo AS ComboBox
	Width = 48
	Height = 24
	Style = 2
	RowSourceType = 1
	RowSource = "Open,Card,Cash,Check"
	ControlSource = "curOpenSales.C_PaidBy"
	
	PROCEDURE Click()
		LOCAL li_RecNo, lc_Alias
		LOCAL ARRAY la_Open[1]
		
		lc_Alias = ALIAS()
		li_RecNo = RECNO(lc_Alias)
		
		DODEFAULT()
		
		GOTO li_RecNo IN (lc_Alias)
		
		SELECT SUM(N_Price) FROM &lc_Alias WHERE &lc_Alias..C_PaidBy = "Open" INTO ARRAY la_Open
		
		IF VARTYPE(la_Open[1]) != "N"
			la_Open[1] = 0

		ENDIF 

		WITH go_Form.txtTotalSales
			.Value = la_Open[1]
			.Refresh()

		ENDWITH
	ENDPROC 
ENDDEFINE

Add a combo, set it's properties as given and copy the code between PROCEDURE Click() and ENDPROC into it's click event.

etc. etc.

Now you can continue and work with the tools you know, remove the Load code, instead use the dataenvironment to add your tables, change all names correspondingly.

Bye, Olaf.
 
I always program from forms.

As Olaf says - you can continue and work with the tools you know

Why try to re-invent the wheel with a methodology that you are unfamiliar with?

If you are familiar with developing VFP Forms, and you see what that form does, why not just create your own form and make it do what that one does?

It would solve 2 problems...
1. You would be working in a method that you are comfortable with.
2. It would use your data tables as you need.

If there is/are one (or mote) specific things which that form does and which you do not know how to do, just ask that single question (or those questions) so that you can incorporate it into your own form - developed in the methodology you are familiar with.

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top