Chan
|
|
Group: Forum Members
Posts: 533,
Visits: 2K
|
Hi, I created purchase invoice data entry form for stock in. I want to allow user to able to transfer item by selecting item records in purchase invoice line items. My design is that, user can select line item record, click on "Transfer" button. Customized Transfer form will be shown as below: Location Cost Qty ----------------------------------- The fields above is in un-normalized form. However, my tables are designed in normalized form. How to have temporary table like VFP cursor for temporary editing? Thank you
|
|
|
Keith Chisarik
|
|
Group: StrataFrame Users
Posts: 939,
Visits: 40K
|
This was like the second thing I wanted to know when I started .NET, I LOVED cursors. I use datatables or data views now for lightweight temporary data manipulation.
Keith Chisarik
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
As Keith mentioned, you can create a temp cursor by using a BOs GetDataTable method or just manually creating a DataTable and populating as you like. Dim loTable As New DataTable("MyCursor") DIm loRow As DataRow '-- Create your columns loTable.COlumns.Add("MyFirstColumn",GetType(System.STring)) '-- Add new rows loRow = loTable.NewRow() loRow.Item("MyFirstColumn") = "Your value" loTable.Rows.Add(loRow)
|
|
|
Hugo R. Figueroa
|
|
Group: StrataFrame Users
Posts: 81,
Visits: 3.1K
|
well how can achieve this code (VFP) in C# SELECT date as xdate,cdesc as Service,SUM(num_pax) FROM tempo1 GROUP BY xdate,Service INTO CURSOR tempo2 SELECT CAST(CDOW(xdate)as character(10)) as xday,xdate,Service,sum_num_pax as pax FROM tempo2 INTO CURSOR tempo3 browse I need to use several "cursors" to get the data in the way I want and then use the last one as a source of a datagrid.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Well, you can take several approaches. Approach #1 - Standard Query The first approach would just be to execute the query and bring it into a BO. Remember, you are dealing with disconnected data so you really don't have to add this to a temp cursor as BO (or DataTable within the BO) is your temp cursor. A query doesn't have to match the structure of the BO...you can bring back any query you want. So it would look something like this: MyBO.FillDataTable("SELECT date as xdate,cdesc as Service,SUM(num_pax) FROM tempo1 GROUP BY xdate,Service") You can then access the populated table via the strong-typed properties...or custom properties...or just by accessing the MyBo.CurrentRow.Item("MyField") Approach #2 - Multiple Result Sets Remember that there is a new method on the BusinessLayer that allows you to bring back as many result sets as you need...this is very nice when you need to execute multiple queries:
Dim cmd As New SqlCommand("SELECT date as xdate,cdesc as Service,SUM(num_pax) FROM tempo1 GROUP BY xdate,Service;" & _ "SELECT CAST(CDOW(xdate)as character(10)) as xday,xdate,Service,sum_num_pax as pax FROM tempo2;") MicroFour.StrataFrame.Business.BusinessLayer.FillMultipleDataTables(cmd, _ MyBO1, _ MyBO2) Approach #3 - True Temp Cursors in SQL Server If you really need to create a temp cursor, then this would be done within a stored procedure but ultimately you would be bringing back a result set like above. The only difference would be that you have done all of the query work on the SQL Sproc side prior to coming back over to the client. There are a lot of articles on creating temp tables in SQL Server. The quick and dirty version is that when you create a table with a # it is a local cursor and when you create a table with a ## it is a global cursor. But I really don't think that this is the approach that you need so I will not expand much on this.
|
|
|
Hugo R. Figueroa
|
|
Group: StrataFrame Users
Posts: 81,
Visits: 3.1K
|
Thank you Trent for your answer (It is very helpfull to have code examples besides the explanations :cool . Really. The thing that I don't know how to accomplish is after selecting into a BO the data , how can I "select" from that BO (to group the data or change the field names) into another BO ? I feel dumb asking this questions, but if I don't ask , how can I learn?
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Hugo, I understand that you want to do do 2 SELECTs and the 2nd one will be against the result of the first one. I think that for what you need, you will be better off using a SP, this way you run all the SQL you need and the last one will be returned to the BO. Or maybe you could use LINQ to query the data in the 1st BO, but I think that may be more hard to do if you are not familiar with LINQ. The StrataFlix sample application have some SP sample that may help you get started.
Edhy Rijo
|
|
|
Hugo R. Figueroa
|
|
Group: StrataFrame Users
Posts: 81,
Visits: 3.1K
|
Hi, Edhy The problem is I am providing web access of an application working with DBFs, not SQL server. I know I would be better using SQL server, but that will be the second step, ahead in the future. For now I have to work with VFP tables. I was thinking of Linq, but it seems hard for now .
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
First of all, thanks for your comments Edhy...all good stuff. But I would really caution you from using LINQ...it is a nice concept, but the larger your database gets and your codebase becomes things can become very sluggish. Even on an empty database, LINQ is significantly slower than straight T-SQL. The problem is that when playing around with LINQ and creating a couple of queries, you don't notice it all that much...but the more code built with LINQ and the more complex queries become, then it really starts to show it's poor performance. But to each his own, I just thought I would caution you against using LINQ. At present, it is totally impossible for LINQ to perform as fast as straight T-SQL. OK...so now back to the question. You can either apply a filter on the BO that you bring in or call the Select() on the CurrentDataTable then pass the filtered BO into another BO via the CopyDataFrom method. MyBO.CurrentDataTable.Select("MyField = 1234") OR MyBo.Filter = "MyField = 1234" MySecondBO.CopyDataFrom(MyBO, ClearAndFillFromDefaultView)
|
|
|
Edhy Rijo
|
|
Group: StrataFrame Users
Posts: 2.4K,
Visits: 23K
|
Hi Trent, Thanks for your comments about LINQ, and mostly thanks for the "How to" in getting the data from another BO with the filter trick. The more I work with SF and try to understand the power in their BO logic, the more I get amazed of how simple the solution to a task is with SF, still the ListView is still my favorite control .
Edhy Rijo
|
|
|