TariqMehmod
Programmer
Dear Experts,
I am using these code to save data from VFP 9 to sqlserver 2008.
The codes work fine on single pc.
When I try run my codes on multiuser system then it does display correct next voucher number.
Please review What I am doing wrong.
[pre]
*--------------------------------------------------------------------------------------------------
*--- PRODUCTS TABLE
*-------------------------------------------------------------------------------------------
LiCountx=0
Select cash_s1
Count For !Deleted() To LiCountx
If LiCountx>0
Repl All cr_amount With Round(cr_amount,0),;
vou_no With Thisform.text1.Value,;
Type With 'P',;
Date With date1,;
vou_type With vou_type1,;
acc_name With partyname,;
code2 With Alltrim(Thisform.text10.Value),;
dr_amount With 0
Insert Into cash_s1 (Date,vou_no,vou_type,acc_code,acc_name,qty,rate,dr_amount,cr_amount,code2,Type) ;
SELECT Date,vou_no,vou_type,'2310001' ,acc_name,qty,rate,cr_amount,dr_amount,acc_code,'C' From cash_s1
*-------------------------------------------------------------------------------------------
*--- DEDUCTION TABLE
*-------------------------------------------------------------------------------------------
*---prepare credit entry
If Thisform.text14.Value>0
Thisform.creat_cash_s2()
Select CASH_S2
Append Blank
Repl All vou_no With Thisform.text1.Value,Type With [D],Date With Thisform.text3.Value,;
acc_code With [3501001], dr_amount With Round(Thisform.text14.Value,0),cr_amount With 0,;
vou_type With [ST], acc_name With [CASH SALE],code2 With Thisform.text10.Value,;
dr_amount With Round(Thisform.text14.Value,0)
Insert Into cash_s2 (Date,vou_no,vou_type,acc_code,acc_name,qty,rate,dr_amount,cr_amount,code2,Type) ;
SELECT Date,vou_no,vou_type,'3501001' ,acc_name,qty,rate,dr_amount,cr_amount,acc_code,'' From cash_s2
*-------------------------------------------------------------------------------------------
* collect data from above 2 cursors into one cursor (cash_s1+cash_s2)
Thisform.all_data() && temporary cursor to hold data
Select all_data
Append From Dbf("cash_s2")For !Deleted()
Append From Dbf("cash_s1")For !Deleted()
*-------------------------------------------------------------------------------------------
*--- begin transaction starts
*-------------------------------------------------------------------------------------------
Begin Transaction
SQLSetprop(m.con, "Transactions",2)
lok=.T. && variable to dectect error
If Thisform.edit_mode
SQLExec(cmd,"delete from cashsalpt where date=?thisform.text3.value and vou_no=?thisform.text1.value")
SQLExec(cmd,"delete from cash_sumt where date=?thisform.text3.value and vou_no=?thisform.text1.value")
Else
*--- get NEW voucher number
cmd="select MAX(vou_no)as max_sno from cash_sumt where date=?thisform.text3.value"
If SQLExec(con,cmd,'table1')<0
Aerror(laerror)
Messagebox(laerror[1,2])
Return.F.
Thisform.text1.Value=1
Else
Select table1
Thisform.text1.Value=Nvl(max_sno,0)+1
Endif
Endif
Select all_data
Replace All vou_no With Thisform.text1.Value
Replace All ed_mode With 1
Replace All ed_event With Datetime()
Select all_data
Go Top
Scan For !Deleted() And vou_no>0
TEXT TO m.cmd NOSHOW
INSERT INTO cashsalpt(vou_no,date,vou_type,acc_code,tittle,qty,dr_amount,cr_amount,
rate,code2,type,acc_name,pur_rate,sal_rate)
values(?all_data.vou_no,?all_data.date,?all_data.vou_type,?all_data.acc_code,
?all_data.tittle,?all_data.qty,?all_data.dr_amount,?all_data.cr_amount,
?all_data.rate,?all_data.code2,?all_data.type,?all_data.acc_name,?all_data.pur_rate,?all_data.sal_rate)
ENDTEXT
If SQLExec(m.con,cmd)<0
Aerror(laerror)
Messagebox(laerror[1,2])
lok=.F.
Endif
Endscan
*-------------------------------------------------------------------------------------------
*--- summary table
*-------------------------------------------------------------------------------------------
TEXT TO m.cmd NOSHOW
INSERT INTO cash_sumt(vou_no,date,ed_cnt,vou_type ,acc_code,acc_name,sales_r,
dr_amount,gate_pass ,code2)
values(?thisform.text1.value,?Thisform.text3.value,
?my_edits,'ST',?Thisform.text10.Value,'CASH SALE',?Thisform.text13.Value,
?thisform.text17.value,?thisform.text15.value,?Thisform.text10.Value)
ENDTEXT
If SQLExec(m.con,cmd)<0
Aerror(laerror)
Messagebox(laerror[1,2])
lok=.F.
Endif
*-------------------------------------------------------------------------------------------
*--- Final decesion to save transaction or reject
*-------------------------------------------------------------------------------------------
If lok=.F.
Sqlrollback(m.con)
Rollback
Messagebox("Invoice Not Saved",0+64,"System",3000)
Else
If Sqlcommit(m.con)<0
Aerror(laerror)
Messagebox(laerror[1,2])
Rollback
Else
End Transaction
Messagebox("Invoice Saved",0+64,"System",3000)
Endif
=SQLSetprop( m.con,"Transactions",1)
Endif
Endif
[/pre]
I am using these code to save data from VFP 9 to sqlserver 2008.
The codes work fine on single pc.
When I try run my codes on multiuser system then it does display correct next voucher number.
Please review What I am doing wrong.
[pre]
*--------------------------------------------------------------------------------------------------
*--- PRODUCTS TABLE
*-------------------------------------------------------------------------------------------
LiCountx=0
Select cash_s1
Count For !Deleted() To LiCountx
If LiCountx>0
Repl All cr_amount With Round(cr_amount,0),;
vou_no With Thisform.text1.Value,;
Type With 'P',;
Date With date1,;
vou_type With vou_type1,;
acc_name With partyname,;
code2 With Alltrim(Thisform.text10.Value),;
dr_amount With 0
Insert Into cash_s1 (Date,vou_no,vou_type,acc_code,acc_name,qty,rate,dr_amount,cr_amount,code2,Type) ;
SELECT Date,vou_no,vou_type,'2310001' ,acc_name,qty,rate,cr_amount,dr_amount,acc_code,'C' From cash_s1
*-------------------------------------------------------------------------------------------
*--- DEDUCTION TABLE
*-------------------------------------------------------------------------------------------
*---prepare credit entry
If Thisform.text14.Value>0
Thisform.creat_cash_s2()
Select CASH_S2
Append Blank
Repl All vou_no With Thisform.text1.Value,Type With [D],Date With Thisform.text3.Value,;
acc_code With [3501001], dr_amount With Round(Thisform.text14.Value,0),cr_amount With 0,;
vou_type With [ST], acc_name With [CASH SALE],code2 With Thisform.text10.Value,;
dr_amount With Round(Thisform.text14.Value,0)
Insert Into cash_s2 (Date,vou_no,vou_type,acc_code,acc_name,qty,rate,dr_amount,cr_amount,code2,Type) ;
SELECT Date,vou_no,vou_type,'3501001' ,acc_name,qty,rate,dr_amount,cr_amount,acc_code,'' From cash_s2
*-------------------------------------------------------------------------------------------
* collect data from above 2 cursors into one cursor (cash_s1+cash_s2)
Thisform.all_data() && temporary cursor to hold data
Select all_data
Append From Dbf("cash_s2")For !Deleted()
Append From Dbf("cash_s1")For !Deleted()
*-------------------------------------------------------------------------------------------
*--- begin transaction starts
*-------------------------------------------------------------------------------------------
Begin Transaction
SQLSetprop(m.con, "Transactions",2)
lok=.T. && variable to dectect error
If Thisform.edit_mode
SQLExec(cmd,"delete from cashsalpt where date=?thisform.text3.value and vou_no=?thisform.text1.value")
SQLExec(cmd,"delete from cash_sumt where date=?thisform.text3.value and vou_no=?thisform.text1.value")
Else
*--- get NEW voucher number
cmd="select MAX(vou_no)as max_sno from cash_sumt where date=?thisform.text3.value"
If SQLExec(con,cmd,'table1')<0
Aerror(laerror)
Messagebox(laerror[1,2])
Return.F.
Thisform.text1.Value=1
Else
Select table1
Thisform.text1.Value=Nvl(max_sno,0)+1
Endif
Endif
Select all_data
Replace All vou_no With Thisform.text1.Value
Replace All ed_mode With 1
Replace All ed_event With Datetime()
Select all_data
Go Top
Scan For !Deleted() And vou_no>0
TEXT TO m.cmd NOSHOW
INSERT INTO cashsalpt(vou_no,date,vou_type,acc_code,tittle,qty,dr_amount,cr_amount,
rate,code2,type,acc_name,pur_rate,sal_rate)
values(?all_data.vou_no,?all_data.date,?all_data.vou_type,?all_data.acc_code,
?all_data.tittle,?all_data.qty,?all_data.dr_amount,?all_data.cr_amount,
?all_data.rate,?all_data.code2,?all_data.type,?all_data.acc_name,?all_data.pur_rate,?all_data.sal_rate)
ENDTEXT
If SQLExec(m.con,cmd)<0
Aerror(laerror)
Messagebox(laerror[1,2])
lok=.F.
Endif
Endscan
*-------------------------------------------------------------------------------------------
*--- summary table
*-------------------------------------------------------------------------------------------
TEXT TO m.cmd NOSHOW
INSERT INTO cash_sumt(vou_no,date,ed_cnt,vou_type ,acc_code,acc_name,sales_r,
dr_amount,gate_pass ,code2)
values(?thisform.text1.value,?Thisform.text3.value,
?my_edits,'ST',?Thisform.text10.Value,'CASH SALE',?Thisform.text13.Value,
?thisform.text17.value,?thisform.text15.value,?Thisform.text10.Value)
ENDTEXT
If SQLExec(m.con,cmd)<0
Aerror(laerror)
Messagebox(laerror[1,2])
lok=.F.
Endif
*-------------------------------------------------------------------------------------------
*--- Final decesion to save transaction or reject
*-------------------------------------------------------------------------------------------
If lok=.F.
Sqlrollback(m.con)
Rollback
Messagebox("Invoice Not Saved",0+64,"System",3000)
Else
If Sqlcommit(m.con)<0
Aerror(laerror)
Messagebox(laerror[1,2])
Rollback
Else
End Transaction
Messagebox("Invoice Saved",0+64,"System",3000)
Endif
=SQLSetprop( m.con,"Transactions",1)
Endif
Endif
[/pre]