How do I manually add extra textview without adding it in axml - xamarin.android

i am trying to extract one data at a time from the sqlite database from the application and for every data return from the sqlite table,i will need to output the data into the GUI with every textview created for every return result else will throw message not found. i am using xamarin native android.
How do i achieve that,i am new to xamarin?
e.g i have a textedit for user to input values database table values(1,2,3,4) if user puts 1,there will be a textview below the textedit with value 1 created And if user continue to put 2,another textview below (the textview with value 1) will be created with value 2
E.G Below:
1)Edittext for user input
2)When user input values 1 in the editbox,it matches the values in the database and return the value 1 as below:
3)When user input another value 2 in the editbox,it matches the values in the database and return value 2 as below:
Cuurently,my code is as follows:
DB.cs(to create the sqlite database in a folder in android that i can access instead of the default application folder)
namespace TestApp
{
public static class Db
{
public static string DBFile = testPath.Combine(Android.OS.Environment.DirectoryDownloads, "test.db"); //for tmp use
public static List<Model.Test> TestList = new List<Model.Test>();
public static void InitializeLocalDB()
{
if (!File.Exists(Db.DBFile))
{
using (var connection = new SQLiteConnection(Db.DBFile))
{
connection.DropTable<Model.Test>();
connection.CreateTable<Model.Test>();
}
}
}
}
}
MainActivity.cs
namespace TestApp
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
Db.InitializeLocalDB();
}
Once i am able to create the database in the download folder,i will extract the db file and manually add in data with compactview to test the app.

Related

how to inflate different layouts in Firebase Recycler Adapter

I have a chat activity and trying to inflate different layouts for the sender and receiver. so far I can retrieve data for the firebase realtime database but sender and receiver have the same layout, I have created layout second layout and tried with viewType but can't figure out how to assign the current user to a cretin layout, please help :(
chat activity
if (!employee)
{
FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder<ChatMessageModel>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("client_emp_messages")
.child(formattedDate+uid), ChatMessageModel.class)
.build();
}
else
{
// employee
Bundle bundle = getIntent().getExtras();
String d = bundle.getString("path_to_client_realtime_db");
options = new FirebaseRecyclerOptions.Builder<ChatMessageModel>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("client_emp_messages")
.child(d), ChatMessageModel.class)
.build();
}
adapter = new ChatAdapter(options);
nMessageList.setAdapter(adapter);
chat adapter
public class ChatAdapter extends FirebaseRecyclerAdapter<ChatMessageModel, ChatAdapter.ChatViewHolder>
{
public ChatAdapter(#NonNull FirebaseRecyclerOptions<ChatMessageModel> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull ChatViewHolder holder, int i, #NonNull ChatMessageModel model) {
holder.nMessage_text_view.setText(model.getMessage());
}
#NonNull
#Override
public ChatViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.message_single_layout, parent, false);
return new ChatViewHolder(view);
}
class ChatViewHolder extends RecyclerView.ViewHolder
{
TextView nMessage_text_view;
public ChatViewHolder(#NonNull View itemView) {
super(itemView);
nMessage_text_view = itemView.findViewById(R.id.message_text_view);
}
}
}
What I suggest you is to make one layout. like the sender on the right side and receiver on the left side. you can use it with the help of a linear layout or relative layout. and set their visibility Invisible.
So download the message data from the database and check it by user id token. If it data matches with the current user token then display it in the right column and set visibility Visible and vice versa.
For that, you just need to store the user token with the message in the database.
Hope you understand it. Thanks

Change invoice pdf file name dynamics d365

can someone help me how to change the file name of a invoice ?
WHen I export a pdf file from screen it always saves as 'show invoice' and in pdf its psaprojinvoice.myprecisiondesign. But I want that there is Invoice num.
Where might be the problem here?
class ProjInvoiceControllerSZM extends PSAProjAndContractInvoiceController
{
public static ProjInvoiceControllerSZM construct()
{
return new ProjInvoiceControllerSZM();
}
public static void main(Args _args)
{
SrsReportRunController formLetterController = ProjInvoiceControllerSZM::construct();
ProjInvoiceControllerSZM controller = formLetterController;
srsPrintDestinationSettings srsPrintDestinationSettings;
controller.initArgs(_args);
Controller.parmReportName(ssrsReportStr(PSAProjInvoiceSZM, PrecisionDesign1));
PSAProjInvoiceContract rdpContract = new PSAProjInvoiceContract();
SRSPrintDestinationSettings settings;
// Define report and report design to use
controller.parmReportName(ssrsReportStr(PSAProjInvoiceSZM, PrecisionDesign1));
// Use execution mode appropriate to your situation
controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
// Suppress report dialog
controller.parmShowDialog(false);
// Explicitly provide all required parameters
// rdpContract.parmReportStateDate(systemDateGet());
controller.parmReportContract().parmRdpContract(rdpContract);
// Change print settings as needed
settings = controller.parmReportContract().parmPrintSettings();
settings.printMediumType(SRSPrintMediumType::File);
settings.fileFormat(SRSReportFileFormat::PDF);
settings.fileName('Invoice.pdf');
// Execute the report
// controller.startOperation();
formLetterController.startOperation();
}
protected void outputReport()
{
SRSCatalogItemName reportDesign;
reportDesign = ssrsReportStr(PSAProjInvoiceSZM,PrecisionDesign1);
this.parmReportName(reportDesign);
this.parmReportContract().parmReportName(reportDesign);
formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
super();
}
}

Grid inline editor - unable to get the edited column values in addCommitHandler method of grid

When I'm trying to click save after the edited the column cell with new user name, I'm not able to get the new cell value, instead I'm getting the old value.
grid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler()
{
#Override
public void preCommit(FieldGroup.CommitEvent commitEvent) throws
FieldGroup.CommitException {
BeanItem item = (BeanItem)
commitEvent.getFieldBinder().getItemDataSource();
User user= (User) item.getBean();
user.getName();//getting the old value instead the new column value
}
}
I have used the BeanItemContainer like below:
BeanItemContainer<User> container = new BeanItemContainer<User>(User.class);
grid.setContainerDataSource(container);
preCommit(FieldGroup.CommitEvent commitEvent) is called before the commit. So the BeanItem's bean (User) contains the old values (the new values were not yet committed into the bean). Therefore getName() returns the old value.
If you want to access the new value you have to use postCommit(FieldGroup.CommitEvent commitEvent) which is called after the commit.
grid.getEditorFieldGroup().addCommitHandler(new FieldGroup.CommitHandler() {
#Override
public void preCommit(FieldGroup.CommitEvent commitEvent) {
BeanItem item = (BeanItem)
commitEvent.getFieldBinder().getItemDataSource();
User user = (User) item.getBean();
String name = user.getName(); // old value
System.out.println(name);
}
#Override
public void postCommit(FieldGroup.CommitEvent commitEvent) {
BeanItem item = (BeanItem)
commitEvent.getFieldBinder().getItemDataSource();
User user = (User) item.getBean();
String name = user.getName(); // new value
System.out.println(name);
}
});
We can able to fetch the new value in the preCommit() method itself by the following code,
TextField nameField = (TextField) grid.getColumn("name").getEditorField();
nameField .getValue(); // new name

how to execute SQL code separatly in SqlServerMigrationSqlGenerator Generates method?

I want to run an SQL script after each new table created through Entity Framework.
I created an override for 'CreateTableOperation' like this:
protected override void Generate(CreateTableOperation createTableOperation)
{
string tenantID = "tenantID";
base.Generate(createTableOperation);
//If the table contain the column "tenantID",
if ((from x in createTableOperation.Columns
where x.Name == tenantID
select x).Any()
)
{
//Add the Security Policies for this table
using (var writer = Writer())
{
writer.WriteLine("ALTER SECURITY POLICY rls.tenantAccessPolicy ");
//Note: dbo. is already part of the .Name, don't add it manually before .Name
writer.WriteLine($"ADD FILTER PREDICATE rls.fn_tenantAccessPredicateWithSuperUser([{tenantID}]) ON [{createTableOperation.Name}], ");
writer.WriteLine($"ADD BLOCK PREDICATE rls.fn_tenantAccessPredicateWithSuperUser([{tenantID}]) ON [{createTableOperation.Name}] ");
Statement(writer);
}
}
}
Let's say I create a new class 'TEST'.
The problem is when I run my Update-Database in the Package Manager Console, the SQL is executed in one big block and create an error because the table is not yet created and I'm trying to get the table.name Package Manager result after Update-Database:
CREATE TABLE [dbo].[TEST] (
[ID] [int] NOT NULL IDENTITY,
[NameTEST] [nvarchar](max),
[TenantID] [int] NOT NULL,
CONSTRAINT [PK_dbo.TEST] PRIMARY KEY ([ID])
)
ALTER SECURITY POLICY rls.tenantAccessPolicy
ADD FILTER PREDICATE rls.fn_tenantAccessPredicateWithSuperUser([tenantID]) ON [dbo.TEST],
ADD BLOCK PREDICATE rls.fn_tenantAccessPredicateWithSuperUser([tenantID]) ON [dbo.TEST]
Cannot find the object "dbo.TEST" because it does not exist or you do not have permissions.
Is there a way to break between the base.Generate(createTableOperation); and my Statement(writer);? (I already tried multiple things with 'GO' without much success). Or is it that I'm not supposed to put code in that method?
I couldn't find a solution/documentation to separate the code/batch SQL in Generate(CreateTableOperation createTableOperation).
What I did instead was to
generate dynamic SQL scripts in the Generate(CreateTableOperation createTableOperation) method
/// <summary>
/// Generate dynamically named .sql file for CREATE and DROP Security Policies (Row-Level Security (Company can't see/insert data of another company))
/// </summary>
/// <param name="createTableOperation">Default parameter that comes with the override method.</param>
protected override void Generate(CreateTableOperation createTableOperation)
{
base.Generate(createTableOperation);
string fullFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\Migrations\\SQLscripts\\SecurityPolicies");
//Remove the schema for the dynamic creation of the .sql filename else it throw an exception:
int indexOfDot = createTableOperation.Name.IndexOf(".");
indexOfDot++; //Because it's 0 base, add 1 char
string tableNameWithoutSchema = (indexOfDot < 0) ? createTableOperation.Name : createTableOperation.Name.Remove(0, indexOfDot);
string filePathCreate = Path.Combine(fullFolderPath, $"CreateSecurityPolicies_{tableNameWithoutSchema}.sql");
string filePathDrop = Path.Combine(fullFolderPath, $"DropSecurityPolicies_{tableNameWithoutSchema}.sql");
//If .sql files doesn't exists, create them
if (!File.Exists(filePathCreate))
{
using (StreamWriter sw = new StreamWriter(filePathCreate, true))
{
sw.WriteLine("ALTER SECURITY POLICY rls.tenantAccessPolicy");
//Note: Don't concatenate 'dbo.{}' because 'createTableOperation.Name' already include 'dbo'
sw.WriteLine($" ADD FILTER PREDICATE rls.fn_tenantAccessPredicateWithSuperUser(CompanyID) ON {createTableOperation.Name},");
sw.WriteLine($" ADD BLOCK PREDICATE rls.fn_tenantAccessPredicateWithSuperUser(CompanyID) ON {createTableOperation.Name}");
sw.WriteLine("GO");
sw.Close();
}
}
if (!File.Exists(filePathDrop))
{
using (StreamWriter sw = new StreamWriter(filePathDrop, true))
{
sw.WriteLine("ALTER SECURITY POLICY rls.tenantAccessPolicy");
sw.WriteLine($" DROP FILTER PREDICATE ON {createTableOperation.Name},");
sw.WriteLine($" DROP BLOCK PREDICATE ON {createTableOperation.Name}");
sw.WriteLine("GO");
sw.Close();
}
}
}
Then, with my SQL scripts in a folder, add it manually to my solution.
Add-Migration just to run my SQL script by adding code into the empty (up-to-date) migration class.
public override void Up()
{
string sqlFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\Migrations\\SQLscripts\\CreateSecurityPolicies_Client.sql");
string sqlText = System.IO.File.ReadAllText(sqlFilePath);
Sql(sqlText);
}
public override void Down()
{
string sqlFilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\Migrations\\SQLscripts\\DropSecurityPolicies_Client.sql");
string sqlText = System.IO.File.ReadAllText(sqlFilePath);
Sql(sqlText);
}
This is the best I can come up with for the moment. I hope it can helps other EntityFramework programmers!

Umbraco Document Type Field Default Value

I would like set a default value for a date picker field in a Document Type in Umbraco.
How can I do this?
This can be easily done using Events, on Document.New
http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events
Just create a new class (eg. UmbracoEvents.cs)
using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using Examine;
public class UmbracoEvents: ApplicationBase
{
/// <summary>Constructor</summary>
public UmbracoEvents()
{
Document.New += new Document.NewEventHandler(Document_New);
}
private void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
{
if (sender.ContentType.Alias == "News")
{
sender.getProperty("date").Value = DateTime.Today; // Set the date for a new News item to today
}
}
}
You could use the Standard Values or the Default Values for Umbraco package.
That can be achieved with sebastiaans first link. As it says on the page you just put in $date$ as the standard value. Then the package will insert current date when the user creates a document of this type.

Resources