viernes, 23 de diciembre de 2022

Embedding QR Code Scanner In Xamarin.Forms

 https://www.c-sharpcorner.com/article/embedding-qr-code-scanner-in-xamarin-forms/Dropdown in Xamarin.Forms

ZXing.Net.Mobile plugin is a useful plugin to facilitate scanning barcodes as effortlessly and painlessly as possible in our own applications works Xamarin.iOS, Xamarin.Android, Tizen, and UWP.

Library Link: https://github.com/Redth/ZXing.Net.Mobile

Without much introduction, we will skip into the coding part of this article.

Coding Part

Here, I will explain the steps to create Dropdown in Xamarin.Forms.

  • Step 1: Creating a new Xamarin.Forms Projects.
  • Step 2: Setting up the scanner in Xamarin.Forms .Net Standard Project
  • Step 3: Implementation of QR Code Scanner inside the screen/page

Step 1 - Creating new Xamarin.Forms Projects

Create New Project by Selecting New -> Project -> Select Xamarin Cross Platform App and Click OK.

Note
Xamarin.Forms version should be greater than 4.5.

Embedding QR Code Scanner in Xamarin.Forms

Then select Android and iOS Platforms as shown below with Code Sharing Strategy as PCL or .Net Standard and click OK.

Embedding QR Code Scanner in Xamarin.Forms

Step 2 - Setting up the scanner in Xamarin.Forms .Net Standard Project

In this step, we will see how to setup the plugin.

Open the Nuget Manager in the Visual Studio Solution by right clicking the solution and select “Manage Nuget Packages”.

Then “ZXing.Net.Mobile” and check all the projects in the solution, install the plugin

Embedding QR Code Scanner in Xamarin.Forms

After the installation, we need to do some additional setup in the platform wise projects.

In Android, update the below code blocks in the MainActivity to initialize the plugin.

// In OnCreate method
Xamarin.Essentials.Platform.Init(Application);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
// In Activity to handle the camera permission from the plugin it self.
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) {
    Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
C#

Step 3 - Implementation of QR Code Scanner inside the screen/page

In this step, we will see how to use the view in Xamarin.Forms.

Open your designer file and in my case MainPage.xaml and add the ZxingSannerView as shown below.

<zxing:ZXingScannerView x:Name="zxing" VerticalOptions="FillAndExpand"/>
Markup

Add Label below the ZxingSannerView to see the results when the bar/QR code is scanned.

Then add the below event to know the successful scan from the control.

zxing.OnScanResult += (result) => Device.BeginInvokeOnMainThread(() => {
    lblResult.Text = result.Text;
});
C#

Full Code implementation of ZXing Scanner View in MainPage

Here, we will see the full code for Main Page.

public partial class MainPage: ContentPage {
    public MainPage() {
        InitializeComponent();
        zxing.OnScanResult += (result) => Device.BeginInvokeOnMainThread(() => {
            lblResult.Text = result.Text;
        });
    }
    protected override void OnAppearing() {
        base.OnAppearing();
        zxing.IsScanning = true;
    }
    protected override void OnDisappearing() {
        zxing.IsScanning = false;
        base.OnDisappearing();
    }
}
C#

Demo

The following screens show the output of this tutorial and it is awesome to have this dropdown in Xamarin.Forms

viernes, 16 de diciembre de 2022

datetime Sqlite

 select datetime(columnDate/10000000 - 62135596800, 'unixepoch') from tabla ;

lunes, 12 de diciembre de 2022

DATEPART sql server

   select  DATEPART(YY, getdate() ) AS Year, 

   DATEPART(QQ, getdate() ) AS Quarter, 

   DATEPART(WK, getdate() ) AS Week, 

   DATEPART(DY, getdate() ) AS dayofYear, 

   DATEPART(MM, getdate() ) AS Month, 

   DATEPART(DD, getdate() ) AS Date, 

   DATEPART(hour, getdate() ) AS Hour, 

   DATEPART(minute, getdate() ) AS Minute, 

   DATEPART(second, getdate() ) AS Second, 

   DATEPART(millisecond, getdate() ) AS Millsecond, 

   DATEPART(microsecond, getdate() ) AS Microsecond, 

   DATEPART(nanosecond, getdate() ) AS Nanosecond


Year Quarter Week dayofYear Month Date Hour Minute Second Millsecond

2022 4 51 346 12 12 12 15 2 677

How to Pass Command Line Arguments using Visual Studio ?

https://dailydotnettips.com/how-to-pass-command-line-arguments-using-visual-studio/

 

You are writing one application in Visual Studio which accepts some command line parameter to do some operation. You pass command-line arguments to the program when it’s been invoked from the command line. But how did you do it from Visual Studio?  You want to test your application, and do you really want to open the command prompt every time to pass the command line values. Really not. Here is a quick tip for all of you.

   Visual Studio enables nice features where you can do this on the Debug tab. Here are the steps to achieve this

1. Right Click on Project from Solution Explorer and Select Properties.

2. In the Project Properties Windows, Navigate to “Debug Tab”

3. You will find the text box “Command Line”

Well, here you can type the command line separated by Space.

image

Just write a simple console application to print the command line argument, and put a breakpoint to check the arguments,

image

So, each value separated by space has taken has a command-line argument. This will produce below output.

image

3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works

 https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9

3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works

The Cors Error

Fix one: install the Allow-Control-Allow-Origin plugin

But the plugin fix is deceiving

Why was the CORS error there in the first place?

How does the same-origin policy work under the hood?

Origin: http://localhost:3000
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Origin: *

Did the plugin “fix” it?

Fix two: send your request to a proxy

Fix three: build your own proxy

If you want to see this in action, head to the source code for the above, along with relevant steps in the README: https://github.com/15Dkatz/beat-cors-server

Conclusion

Connect with David