176

(2 replies, posted in General)

thezimguy,
If I may put my little tidbit of information here as my understanding of the two items you mentioned.


1) The ShowForm, as Dimitry said, only shows the form. It is not meant to be a data entry type form UNLESS you manually populate the fields and do your own saves and clearing of the fields. If you enter data into the fields and don't clear them, they will remain present for the duration of the program. So every time you show the form the fields will remain populated unless you clear them through script.


2) Typically SqlValue is used inside SQL (SqlExecute) statements. At least that's all I ever used it for. For text type fields it places the quotes around the string for you otherwise if you use the TEXT attribute of a field (Form1.edit1.Text) inside the SQL statement, then you need to place the quotes around yourself. Also, this works the same whether you are on ShowForm or ShowRecord.


Hope this helps.

177

(22 replies, posted in General)

Anakin,
See attached.  I added Payment and Change fields in the database definitions for the Sales table, placed the new fields in the AllSales tablegrid, changed the NewSale form Object Inspector for each field to point to the corresponding table field, included the new fields in the Save action, and put in script to colorize table rows with no payments to red.

178

(22 replies, posted in General)

Anakin,
See attached for the revised fixed project. Classification and Variant are correctly defined as a relationship to Product, so you really should not have it related to Sales. But in order to bring in those two fields into the Sales tablegrid I created calculated fields to retrieve the respective names. Keep in mind that calculated fields are not real fields so it is not duplicating data in the Sales table.  Also, the controls for these two fields in the NewSale form are defined as ReadOnly.  You cannot change them in this form because they belong to Product, not Sales. Hope this helps.


I just noticed that you asked about placing the Payment and Change in the tablegrid. All you have to do is define them in the Sales table, then put the definitions in the object Inspector of the Sales form. Don't forget to include them in the Save action.

179

(13 replies, posted in Database applications)

kees.krause,
See my earlier post which includes a revised project (Dup Check Revised.zip)

180

(22 replies, posted in General)

Very good point Derek. I did overlook that aspect. I made an assumption that everybody who comes to this software has a database design background. You're absolutely correct. The proper database design is the main foundation for all database applications. It is essential for a successful project. Thanks for your input.

181

(22 replies, posted in General)

Anakin,
Thank you for your kind words. When I came to MVD I knew nothing about the development system and I knew nothing about Pascal except that it is essentially an old development language, meaning it's been around for awhile. However, I've had experience with other development systems and programming languages so my learning curve was very small. I just adapted the same techniques to MVD. For me I learned MVD by going through the videos and online help documents developed by Dimitry http://myvisualdatabase.com/help_en/. I relied on the forum heavily in the beginning and still do. I have also used Delphi Basics website. http://www.delphibasics.co.uk/    I have used SQL reference websites sometimes for assistance with complex SQL statements. For SQL websites you need to make sure the syntax is for either SQLite or MySQL, whichever you are using. There are subtle differences among databases.

The forum is an invaluable resource especially when you are stuck on something. Don't hesitate to ask. There are a lot of people on here who can help. One is Derek who is a very active member on here and he has helped me. I call him the "Master of Non-script Solutions". :-)  I say this out of respect for his knowledge. Obviously, most projects cannot go without some scripting and he has provided significant help with that as well. Dimitry who is the author of MVD is invaluable on here. He can help where other people are not able to. There are a lot more people on here and I don't want to start naming names because I don't want to leave anyone out. As I said before, don't hesitate to ask for help.

I would highly recommend building a code snippet database as soon as you can. Doing so will help you tremendously as you are learning. It can become a very useful resource as a reference tool. Most of the snippets I have came from the forum as new versions come out and from things people have posted that may not be in the help system.

One final thing, I really do not feel that I am an expert on MVD, but I try to help people whenever I can with what I know.

182

(13 replies, posted in Database applications)

kees.krause,
If you want to use my solution I updated the project and added address and then checked for a duplicate after making changes to a record. So if the user updates the fields and the result of the changes will produce a duplicate then present the duplicate error message otherwise it will save the changed data. If you do not want to use the address as part of the duplicate check, then remove it from the SQLEXECUTE statements and the Hold_Flds and FLD_Concat variables.

183

(6 replies, posted in Script)

Try this

frmArticoleAdd.grdBOM.dbSQL:='SELECT tblBom.id,BOMName,ArticleNo, ArticleName,Quantity,UmNo, '
   + 'Case Active when 1 then "Yes" when 0 then "No" End,'
   + 'Case Fixed when 1 then "Yes" when 0 then "No" End '  + 
   'from tblBOM ' +
   'left join tblArticol on tblBom.id_tblArticol1=tblArticol.id ' +
   'left join tblBomType on tblBom.id_tblBomType=tblBomType.id ' +
   'left join tblUm on tblBom.id_tblUM=tblUm.id ' +
   'where id_tblArticol= '+ frmArticoleAdd.txtArticolID.text ;

   frmArticoleAdd.grdBOM.dbListFieldsNames:='ID,Tip BOM, Nr. Articol, Nume Articol, Cantitate,UM, Activ? ,Fix?';
   frmArticoleAdd.grdBOM.dbSQLExecute;

184

(22 replies, posted in General)

It sounds like you may have inserted another column in front of the product name in the tablegrid. If you did then you need to change the FOR LOOP to point to UNITS column in the tablegrid.


Whatever the column number is for UNITS beginning with Column 0 then replace the digit 1 below in Cells[1,i] and Cell[1,i] with the appropriate number. In other words, if the UNITS column is now the third column in the tablegrid, then you want to replace the 1 with 2.

If StrToInt(Inventory.TableGrid1.Cells[1,i]) < 1 then
           Begin
              Inventory.TableGrid1.Cell[1,i].TextColor := clRed;
              Inventory.TableGrid1.Cell[1,i].FontStyle := fsBold;
           End;

185

(6 replies, posted in Script)

Place this inside your SELECT

Case Bool_Field When 1 then 'Yes' When 0 then 'No' End

186

(16 replies, posted in Script)

I would recommend doing what I did, especially if one is new to MVD, and that is create a database (in MVD of course) of code snippets and examples. I use it as a kind of help system for MVD. I refer to mine almost daily. When I first came to MVD I was using the forum for most of my assistance, but I found out early on that it can be laborious trying to find what you are looking for, even when using the search tool. Many times there are solutions in topics where the topic title has nothing to do with the solution itself or somebody may post another subject under a topic in question. Don't get me wrong, the forum is an invaluable tool for assistance. I have learned most everything from the forum and it provides the basis for updating my code snippet database. I download most every project attachment and if there is something in the project that is new or something I did not know, then I insert the code snippet in my database for future referencing. That way I don't have to go back to the forum to try and find it a year later or whenever.

187

(16 replies, posted in Script)

I know the feeling. But don't stress yourself out for hours. Just ask here and someone will get you an answer. There's a lot of good resources on this forum. Happy developing!

188

(13 replies, posted in Database applications)

denzkie1191,
Attached is another option. As you can see, MVD is very flexible in doing things in various ways. Not one is really any better than the other.

189

(3 replies, posted in General)

It worked ok for me. What steps are you doing in creating a new project and database?

Also, the way I understand when the rich text editor was introduced into MVD, this expanded the exe size dramatically even if you did not use this control in your project.

190

(16 replies, posted in Script)

You need to place your IF statement inside the OnChange event of the combobox. See attached revision.

191

(22 replies, posted in General)

Check the attached and see if that is what you want.

192

(22 replies, posted in General)

Anakin,
I made some guesses and assumptions in what you are wanting to do. I revised your project and hopefully my changes gets you closer to what you are looking for. I didn't do anything with CLASSIFICATION or VARIANT in your project. I assumed that the table Product represents inventory whereby UNITS would be the same as qty on hand. The calculated field in Product represents the value of the inventory items. If these assumptions are correct then when you make sales, the UNITS (qty on hand) in Product table gets updated based on the sales transaction units. The NewSale form can be used for adding and editing sales. The PAYMENT and CHANGE fields are only used to calculate the change amount back to the customer. I don't think it is necessary to actually store those amounts so I removed them. But you can add them back if you need to. I put code in to retrieve the product price from the PRODUCT table when a product is selected from the combobox in NewSale form. Most of the code in the project is for the maintaining of the UNITS (qty on hand) in Product table. That code is at the bottom of the script. If you don't need it then you can remove it.


I also added code to change the UNITs cell in the Products tablegrid to RED if the UNITS qty is zero or below.


I'm not sure why you have UNITS as a search item in the Inventory form. I left it alone.

193

(4 replies, posted in Database applications)

manos,
Maybe try installing XAMPP which includes MySQL. It's a much easier install and you can even setup a webserver if you want. It comes with a control panel to start and stop the service and run phpMyAdmin. Here is the link to download:
https://www.apachefriends.org/index.html

CDB,
In the ForeignKey field property, do not select anything from the dropdown. Just type in the table name Supplier, then you can select the Sup_Name from the FieldName dropdown.


EDIT - I am updating my post to support Derek's approach. I was wondering where he got your project and then I saw you had it in another post. After looking at your original project, in my opinion, it would better serve you to use Derek's approach. It is easier, more straightforward and less scripting. It appears you are trying to use tabs rather than forms for various updates and it can become cumbersome with scripting to try to do a lot of things on one form. Not that you can't do it, but it can be complex. In Derek's project, you could almost simulate tabs by placing the buttons above the tablegrid on the first form.  Just a footnote, I typically only use tabs if I have a lot of fields in a record and there are too many to fit on a form. I can spread them in a logical way on separate tabs, but on the same form. Obviously it is not the only use for the tabs, but I just wanted to show you one way for its use.


Hope this helps with your development.

They will not correlate because they are two completely different properties with two distinct values used for different purposes. dbitemID is the actual id in the record whereas listindex is the number of the selection in the combobox. ListIndex has nothing to do with the record id (dbItemID) in the database.


So in your first example you should be using dbItemId and not ListIndex as follows:

procedure frmMain_btnEditSupplier_OnClick (Sender: TObject; var Cancel: boolean);
var
    RecordID:integer;
begin

    RecordID := frmMain.combobox2.dbItemID; //this gets the actual record id from the selected item in the combobox and needed for your ShowRecord.

// check item ID for debugging
    showMessage('item no ' + intToStr(RecordID));

   //ShowRecord(frmEdit.,'supplier',frmMain.ComboBox2.ItemIndex );
   ShowRecord(frmEdit,'supplier',RecordID ); // Open edtForm with item selected ready to be edited and saved back into database.
end;

But you really do not need this code at all  because you can do it without any script whatsoever.

196

(2 replies, posted in General)

blackpearl8534,
Even if your code would work I hate to say this but it is very inefficient. You are spinning through the tablegrid every time you click on it just to get the info from the selected row. You do not need to do this. As soon as the user clicks on a row it is selected so you can get the cell info from the row immediately. See below.

procedure Form1_TableGrid1_OnCellClick (Sender: TObject; ACol, ARow: Integer);
begin
   Form3.Edit3.Text := Form1.TableGrid1.Cells[2,ARow];
   Form3.Edit4.Text := Form1.TableGrid1.Cells[3,ARow];
   Form3.Edit5.Text := Form1.TableGrid1.Cells[5,ARow];
   Form3.Edit6.Text := Form1.TableGrid1.Cells[6,ARow];
   Form3.ShowModal;   // or whatever you want to do at this point
end;

Let me know if you still get the error.

CDB,
You are actually making it more complicated than it needs to be. You can do it without any script. See attached.  Also, you may be getting dbItemID and ItemIndex mixed up. dbItemID is the actual id in the table record. itemIndex is the sequential number of the selected item in the combobox starting with 0.

198

(2 replies, posted in General)

Dimitry created an example

http://myvisualdatabase.com/forum/viewt … 652#p21652

199

(5 replies, posted in General)

Good suggestion Derek. Actually using your method does provide the record's id through retrieving dbItemID in script.


I should have clarified a little more in my answer. It really depends on how the combobox is to be used. If it's being used as a type of lookup as normally done in MVD then placing the id in the SELECT statement should be present. However, I have done the same thing as Jean mentioned with using DISTINCT in the SELECT in situations where I did not need the id. In fact you can't put the id in the SELECT statement when using DISTINCT because it actually defeats the purpose of distinct.

200

(5 replies, posted in General)

jean. blackpearl8534,
You should also include "id" in the SELECT so you know what the id is for the specific selection in the combobox.