線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1710
推到 Plurk!
推到 Facebook!

Some Delphi solution help about ADO database

答題得分者是:Justmade
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-04-02 08:19:39 IP:217.36.xxx.xxx 未訂閱
My problem is really kinda hard explain. there are many points to expalin. First, let me describe what I am trying to do. (Sorry, I can't type chinese, so I can only use english) First I am writing a food ordering program I am using ADO component with Access, set up a database. In Access, I have set up 3 tables Food Menu Table (Holding all the information of each food item) Temp Order Item Table Sale Revenue Table I set up a ADOConnection to the database. ADODataset link to Food Menu Table ADOTable link to Temp Order Item Table ADOTable2 link to Sale Revenue Table I use Tedit to search 'Food Item' from 'Food Menu Table', then the item information will be transfer to the 'Temp Order Item Table' After the order is finish, all the Items Information will be transferred to 'Sale Revenue Table' And everything in the 'Temp Order Item' Table will be deleted. Then a New Order starts again. My problem is really hard to explain, if anyone is kind enough to help me. plz :) If sum1 is really really kind to help me plz my ICQ: 67774170 MSN: Franklin_uk@hotmail.com Also, if there anything I described above is not clear, plz tell me Thanks a lot..
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-04-02 10:32:06 IP:218.16.xxx.xxx 未訂閱
I'd say if you can't explain here, it is also hard to explain well in ICQ. Even if you managed to explain to one in ICQ and unluckily find that he cannot help, you have to explain again to other. Then why not just review your problem and summarize them here ? Also, doing the review can help to solve some of the problems yourself in many cases.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-04-02 17:51:26 IP:195.195.xxx.xxx 未訂閱
Absolutely correct!. OK. I try to explain as much as possible As I mentioned before it is a food ordering program, will be used in a food takeaway shop. I set Tedit1 as a auto search, link to the Food Menu Table of the DBase. Say '001' = 'Chips' When I type 001 in the Tedit1 and press enter, The information of 'Chips' such as Price, ID, Types will be copied to the 'Temp Order Table' (ADOTable1). that's what happens as follow: procedure TForm1.Edit1Exit(Sender: TObject); begin ADOTable1.Insert; ADOTable1.FieldValues['DishID']:=ADODataset1.FieldValues['ID']; ADOTable1.FieldValues['Price']:=ADODataset1.FieldValues['Price']; My first question is, can use a Tlisting components instead of set up a Temp Order Table. because this table must be empty, every time the program starts, and will be empty as well after a single order is finished.? Thanks, I am really new in Delphi. and I know what I need to do, what I not sure about the method :(
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-04-02 18:04:43 IP:195.195.xxx.xxx 未訂閱
A summarise is: Enter Food item Code into Tedit1. Then Press Enter. Then Dbedit1.SetFocus; (Dbedit1 is linked to the temp order table, field 'Quantity') Enter quantity of that Item Then Press Enter Then Tedit1.SetFocus; Then Enter the 2nd item When everything is finish, Press Button noted ('Check out') This action will leads to: Print all items information, such as subtotal, total, food name All the item information, will be save in another table of dbase, called 'Sales Revenue' All the item in Temp order table is deleted. Then Tedit1.SetFocus, (New Order can start)
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-04-02 18:11:56 IP:195.195.xxx.xxx 未訂閱
So my problem is, I know all the algorithm of my program. I know what I need to do but I don't know how to type the syntex or 'command'  to applied into Delphi.    I know it sounds like asking u guys design the whole program for me, but this is really really urgrent, this program need to be done by 2 days :(    plz help me. 
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-04-02 19:16:47 IP:195.195.xxx.xxx 未訂閱
AlsoThe method I tried doesn't work. It always crash when I try to insert more than 2 items in the 'Temp Order Table' The crash message says: Project XXX.exe is raised exception class EOleException with message 'The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or ralationship. Change the data in the field or fields that contain duplicate datam remove the index, or redefine the index to permit duplicate entries and try again' Process stopped........
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-04-02 19:25:47 IP:218.16.xxx.xxx 未訂閱
Nope it didn't appear that you ask other to do all the design as you have at least design the whole process of your program.  However, I would sorry to say that it is far from a good design.  Though, it is a workable design.    The code segments you put up also make sense.  The thing I do not understand is that why dont you just put all those together to try making the program and fix those errors one by one ?    For the temp table, you can use array or such to replace it but 1. You better stick to those you at least know a bit then to involve more then your limited time to learn. 2, It is easier to print when the data is in tables.    Actually there is no need of the temp table but for the same reason above, just stick to your own design.    If you need sample, the Demo\DB folder under your Delphi installed folder provide many good ones.  The MastApp is especially good for learning business like database application.    When you encounter some more soid problems, you are most welcomed to ask here.    Some quick hints : 1. after inserting and copying the data to temp table, remember to post (ADOTable1.Post;) 2. you can use quick report for printing, set the QuickRpt1.DataSet to ADOTable1, Put a QRBand to the report and set the bandtype to detail, and put qrdbtexts in the detail band for different fields 3. when copying data from temp table to revenue table, you can use a while loop such as :
While not ADOTable1.eof do
begin
  ADOTable2.Insert;
  ADOTable2..... := ADOTable1.....
  ......
  ADOTable2.Post;
  ADOTable1.Delete // Delete the copied record
end;
After the loop the data in temp table will be copied and cleared.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-04-02 20:29:08 IP:195.195.xxx.xxx 未訂閱
Please point out the part u thing that is a bad design. Can u tell me how to use array to replace the temp table? It is very difficult, I got a Mastering Delphi 7 myself, but there are just too much information to read. Also, do u understand what the error message means? because I kept delete all the field from the temp table, but the same problem still occurs
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-04-02 20:40:41 IP:218.16.xxx.xxx 未訂閱
It is becasue you have defined a primary key or unique secondary key which need unique data but your 2nd record has same key value to your first one. For such temp table, try not using any key. Using array will casue you more trouble in printing. Regarding bad design, it is a large topic. It is basically about normalization. Maybe you can have a quick serch for "database normalization" in Google. However, I dont think you have time to digest that in your time frame.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-04-02 21:36:30 IP:217.36.xxx.xxx 未訂閱
thanx a lot man.. u r from hong kong right? your english sounds pretty good I will try to get the form and interface finish first, then I will build the function in, one by one thnx again :)
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-04-02 21:39:09 IP:218.16.xxx.xxx 未訂閱
you are welcomed. Just feel free to post more question if you encounter further problems.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-04-02 22:36:49 IP:217.36.xxx.xxx 未訂閱
Justmade do u have ICQ or MSN? so I can ask u question more quickly?
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#13 引用回覆 回覆 發表時間:2003-04-02 22:58:03 IP:217.36.xxx.xxx 未訂閱
I put the ADOTable.Delete in 'FormShow': procedure TMain.FormShow(Sender: TObject); begin ADOTable1.Delete; end; That is too make sure everytime the program starts, this temp table is clean. It that the right way to do it? Also, the 'Delete' command only delete one record at a time, how can I delete everything at the same time?
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#14 引用回覆 回覆 發表時間:2003-04-02 23:09:30 IP:218.16.xxx.xxx 未訂閱
Yes, I have ICQ but I seldem use it. Also, I perfer to discuss here. To delete all records at once, it is easier with SQL statement ADOQuery1.SQL.Text := 'delete from tablename'; ADOQuery1.ExecSQL;
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#15 引用回覆 回覆 發表時間:2003-04-02 23:26:11 IP:217.36.xxx.xxx 未訂閱
do I need to add a ADOQuery component for this? also, how should I put it? there are two place I like to put it: 1. The 'Check Out' Button Click 2. Everytime the program starts
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#16 引用回覆 回覆 發表時間:2003-04-02 23:40:48 IP:218.16.xxx.xxx 未訂閱
Yes, You have to add a ADOQuery. It is fine to put the suggested code in the onShow event of your form. For the Check Out button, you dont need to add this if you used my former suggested code becasue it delete each record after it is movied to your revenue table. You are encouraged to sperate different questions (closely related ones should grouped together though) so that other can be more likely to see your added questions. You are also urged to give marks to the one who give satisfactory answer to you so that people will have more motivation to help you. I have to sleep now and hope other will continue to help you. 發表人 - Justmade 於 2003/04/02 23:42:07
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#17 引用回覆 回覆 發表時間:2003-04-02 23:45:24 IP:217.36.xxx.xxx 未訂閱
oh. what time I can see u again? cux u are the only one helping me there. 
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#18 引用回覆 回覆 發表時間:2003-04-03 08:59:33 IP:218.16.xxx.xxx 未訂閱
There is a combo box before the first post and after the last post. You can choose from all who responsed to your question or 缺席 (absent, for none of the answer help) and then press the button beside.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#19 引用回覆 回覆 發表時間:2003-04-03 18:04:28 IP:195.195.xxx.xxx 未訂閱
i set 'ADOTable.Delete' in the button click and OnShow, however, when there is no record in the table, it crash. how can I fix this problem?
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#20 引用回覆 回覆 發表時間:2003-04-03 18:36:30 IP:218.16.xxx.xxx 未訂閱
The solution is already in above posts and I dont think it is necessary to repeat.
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#21 引用回覆 回覆 發表時間:2003-04-03 18:50:24 IP:195.195.xxx.xxx 未訂閱
yeah, i know but I am not very sure. so I create a ADOQuery then on Form Show: ADOQuery1.SQL.Text := 'delete from tablename'; ADOQuery1.ExecSQL; ^That? I am just making sure
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#22 引用回覆 回覆 發表時間:2003-04-03 19:07:30 IP:218.16.xxx.xxx 未訂閱
of casue you have to replace 'tablename' with your real table name
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#23 引用回覆 回覆 發表時間:2003-04-03 19:16:58 IP:195.195.xxx.xxx 未訂閱
Refering back: While not ADOTable1.eof do begin ADOTable2.Insert; ADOTable2..... := ADOTable1..... . ..... ADOTable2.Post; ADOTable1.Delete // Delete the copied recordend; what is 'eof' mean in the first line? Also, I am not really understand what is Tablename.Post for I placed it in my program, it makes no affect at all, and even make the program crash sometimes
Vashee
初階會員


發表:38
回覆:87
積分:25
註冊:2003-03-31

發送簡訊給我
#24 引用回覆 回覆 發表時間:2003-04-03 20:08:59 IP:195.195.xxx.xxx 未訂閱
may be i am still not familiar with ADOquery. do I have to make a new ADOquery everytime if I want to perform different action on different table say: (Menu Table: Price) X (Temp Order Table : Quantity) = (Temp Order Table: Subtotal) another: (Temp Order Table: Subtotal Whole Column) Also, about putting that on OnShow ADOQuery1.SQL.Text := 'delete from tablename'; ADOQuery1.ExecSQL; Can those use the same ADOQuery at the same time? That's why I am confused. Also, I don't know what do put as default in the SQL code in the ADOQuery1,
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#25 引用回覆 回覆 發表時間:2003-04-04 10:22:47 IP:218.16.xxx.xxx 未訂閱
Eof mean End Of File, that statment mean repeat the loop until end of the file. Post is to save the change to the database. However, if you did not edit or insert record and issue post, it will casue error. One ADOQuery can do many different things in DIFFERENT time. It can not do the 2nd thing before the first is finished. Whenever you are not sure, using another do no harm.
系統時間:2024-04-19 19:51:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!