Automatically inserting value from another table in lightswitch - c#

I am creating a desktop, C# application in Lightswitch. I have a DB file with a table called Reports and another table called StatusList. There are going to be 3 options in StatusList table - Unresolved, In Progress and Resolved. The Report table has a couple of not important fields and a field "Status", which is supposed to hold one of the three values from StatusList table
Now, when the user will create a new Report, I need the application to automatically insert the "Unresolved" value as the "Status" without user being able to change it.
I have tried using this method
partial void Reports_Created()
{
this.Status = "Unresolved";
}
but it is not working. I guess it is because I am trying to assign a String value to the field which is populated from another table.
I am using Visual Studio 2013 and this is my first Lightswitch app as well.
Thank you in advance for any help.

It sounds like your trying to pass parameters between screens. Beth Massi does a good job explaining how to achieve that in this video. And here is another MSDN link to a similar question

Shouldn't your code before like:
This.report.status = "Unresolved"
I.e. The report entity is not referenced by "this" (that refers to the screen).

Related

How to design ASP.NET Core - SQL application where user should be able to create forms of different input items and store values in database

I've started working on a web application project, where a feature is: the admin user can create/update few custom forms choosing different input types from the database and the end users can update the form data in a repetitive fashion/sometimes daily and the data stores in the database for further use cases. To elaborate, the admin user can choose any of "checkbox", "textbox", "textarea", "datetime", "temperature" etc. input types and create a form. The end user then can read the form and input the values that is to be saved in the database for reporting to admin.
I need to use ASP.NET Core MVC, SQL, EF, code first migration at the back-end of the project.
I am thinking maybe (as an example) a Form model with Id and Name properties, TextBox model with Id, Name, FormId, DateTime model with Id, Name, FormId etc. for creating the forms and then when user inputs values that can be updated using other models/tables in the database like TextBoxRecord model with Id, TextBoxId, Value, UserId, DateEntered etc. But then it will be too many tables to update and read every time when entering values and displaying reports to the admin.
I appreciate any help with a good design idea of the data model or how to attain this kind of logic. Also feel free ask, if you have any questions. Thanks.
Some time ago, I was working on some simular project. We don't store each of our form field in DB, because we don't want to update DB each time we need to add some new-kind-of-form-field. We believe it's up to HTML+JS to decide what kind of input to use with particular object property.
We create a serializer, that serialize form structure in xml and store it in DB. In this xml we keep a TableName (EF DataSet<> name) and ColumnName (name of model property) for each FormField.
When we need to show a form to user, we deserialize it from DB, pack in ViewModel (because we don't want to show to user real names of our DB tables) and send it to JavaScript code as JSON. JS then constructs the form element and show it to user. When user submits the data, we again deserialize corresponding form from DB and update actual models in db with data from user input.
Hope this will help.
To all the, eurhm, people, who find this an interesting question and "would like to know the answer too", there's an interesting article to read at
https://www.red-gate.com/simple-talk/opinion/opinion-pieces/bad-carma/
That story started with (at least as good as) exactly the same kind of user requirement as the OP's here.
(And to those who want to downvote this because "not an answer" : it is MORE of an answer because it shows in intimate detail WHY you NEVER want to even start going down that alley.)

Run User Compare with ERPConnect (Theobald)

I would like to know if anyone knows if it is possible to run a SAP User Compare from c# using ERPConnect 4 from Theobald? If so, how?
I can open a connection to SAP and run functions - just don't know how to do User Compare.
EDIT:
It seems like we have to run the report PFCG_TIME_DEPENDENCY.
If anyone knows how to run a report with ERPConnect, or if there exists a functional module in SAP that can run a report, that will also help.
I am not exactly sure what your comparison has to include, but I assume, that you want to compare attributes of the users. If that is the case, you could download the users data from the SAP tables. Here is a starting point for what tables you probably need: http://www.tcodesearch.com/sap-tables/detail?id=USR01
USER01 is the user master record, containing all user with it's main attributes. You can find other interesting related user table through the link above.
To read a table using Erpconnect, look at this link: https://my.theobald-software.com/index.php?/Knowledgebase/Article/View/21/23/reading-sap-tables-directly
You need to create an instance of the ReadTable class. Then you add the fields you are interested in using the AddField method (e.g. MANDT and BNAME for the USR01 table). You could but don't have to enter filter criteria using the AddCriteria method. If you do add multiple creteria, be sure to add boolean operators like "and" or "or":
table.AddCriteria("LANGU = 'D'");
table.AddCriteria("AND MANDT = '007'");
Finally set the table name of the table you want to download and execute the Run-Method. After that you can loop through the results stored in <your RunTable-Instance>.Result.Rows
Sascha

How to retrieve one record from SQL Server database in MVC Model

I am working on Visual C# MVC project. I am using databse first approach in my model.My project is about developing an appmarket where users can buy apps. I used partial view in home page which will conatin details of different apps in different partial views.Like App1 in 1st partial view, App2 in 2nd partial view, so on. For this I used foreach loop.
In each partial view there is link called MoreInfo, so when user clicks on that they will go inside MoreInfo page. In database I have fields such as app info, app cost, description etc which will be displayed inside MoreInfo page. All these fields are in one table called Apps table.
My problem here is if i use forach loop inside MoreInfo page, then I am getting information of each record from database. To be more clear, in Database I have two records for Description field called "Description 1" and "Description 2". If i use foreach loop, then it is displaying two views, one for Description 1 and another for description 2 in same page.
What I want is Desription of 1st app in first MoreInfo page and second description in 2nd MoreInfo view and so on.
can someone help me in this?
Thanks..
Assuming you are using Entity Framework:
Enumerable.FirstOrDefault will do this for you. You can load it into the TSource type.
Here is a link: http://msdn.microsoft.com/en-us/library/bb340482.aspx
var someobj = db.someEnumerable.FirstOrDefault(x => // Condition);
If you're using LINQ to SQL or EF you can tack FirstOrDefault() onto your call which will return the first value or in most cases null (default value for reference types). If you're using something like SQLConnection or invoking a sproc just change your SELECT ... FROM to SELECT TOP 1 .... FROM
You should be using Linq to get one record as per your condition. try something like this (this is only code to show you the logic as we are not sure what variables you have used).
var result=(from x in dbContext.TableName where column==variable select x).FirstOrDefault()
I hope it will help.

C# LINQ-to-SQL - not updating table with stored procedure

SOLVED
I have problems with Linq to SQL inserting/updating/deleting dataset from table with stored procedures.
I have checked data connections, points on the same table that has been created when adding connection
I'm using Linq-to-Sql classes designer for managing behavior of sprocs for my tables (insert, update, delete)
I have same app created with different code style and everything works just fine but i can't include location change (when someone else installs app) in my .cs files, so I want to do it on "right way" and make it work for everyone.
using sql server 2012 and vs2010
Here is my problem.
this is included in form as reference for DataContext
private ZavrsniradDataContext poziv = new ZavrsniradDataContext();
//I've tried without private, and including this into methods where I'm using it and nothing.
after I declare some variables for sending it to sproc I call sproc for altering the table..
poziv.p_IzmjenaMjesta(#ID, #Naziv, #PP, #IDZupanije);
poziv.SubmitChanges();
note: I'm sending ID number of the dataset I want to change, for comparison..
Alter proc [dbo].[p_IzmjenaMjesta]
#ID int,
#Naziv varchar(30),
#PP int,
#IDZupanije int
.
.
.
Update Mjesto
SET Naziv= #Naziv, PostanskiPretinac = #PP, IDZupanije = #IDZupanije
WHERE ID = #ID;
After I call the sproc, my table is being refreshed, and all changes are visible. But after a while, all changes dissapear. I believe all my sprocs and functions are working properly, with my table, but somehow I'm doing something wrong. everything works perfecrly when I run sprocs in Management studio.
My other app contains this definition in beggining of the form, and everything works perfectly. updateing, inserting, deleting! But i don't want that solution because then I have to create fixed location for my database on every PC. I just want to install it and run it :)
public partial class Mjesta : Form
{
ZavrsniRad poziv;
public Mjesta()
{
InitializeComponent();
poziv = new ZavrsniRad(#"c:\zavrsni_rad\Zavrsni rad.mdf");
}
NOTE:
I'm using exact copy of both databases on different locations with same sprocs/functions/dataset for different apps, and one is working, the other one is not working.
and that grinds my gears :(
I have solved it.
app is running and working properly...
I forgot on that little thing :(
Problem solver, add all rights on modifying your database to every account you have.
That also includes rights to log file.
(i dont have rep points for posting pics)
http://www.pohrani.com/f/v/AQ/2bPLiVcP/slika.jpg

UPDATE a Table when another has been modified

I have 2 tables in an Access Database. (SQL examples are fine).
The first table is a table called Reports.
The fields are :-
ID
ReportName
ReportType
The second table is a Template, where a user will store a host of reports. The user modifies this template table each week. Below are the fields :-
ID
UserID
ReportName
ReportType
ScheduledDate
Completed
AssignedBy
I have everything in my code working, but I overlooked something vital.
I need to reflect the changes a user may make to the Report Table, I.E, EDIT a reports name, into the Template Table, so that any instance of the edited report, now shows the new name.
I'm struggling to work out how I can do this?
Any help would be appreciated, it doesn't have to be exact code, more so the method.
Only works for .adp project, you should be able to do this using a trigger.
something like
create <trigger_name>
ON Report
....

Categories

Resources