เปลี่ยน Input Language Programmatically

/// <summary>
/// Changing Current Input Language to a next installed language
/// </summary>
public void ChangeInputLanguage()
{
   // Nothing to do if there is only one Input Language supported:
    if (InputLanguage.InstalledInputLanguages.Count == 1)
       return;
   // Get index of current Input Language
    int currentLang = InputLanguage.InstalledInputLanguages.IndexOf(InputLanguage.CurrentInputLanguage);
   // Calculate next Input Language
    InputLanguage nextLang = ++currentLang == InputLanguage.InstalledInputLanguages.Count ? 
       InputLanguage.InstalledInputLanguages[0] : InputLanguage.InstalledInputLanguages[currentLang];
   // Change current Language to the calculated:
    ChangeInputLanguage(nextLang);
}

/// <summary>
/// Changing current Input Language to a new one passed in the param
/// </summary>
/// <param name="ISOLang">ISO Culture name string code e.g. "en" for English</param>
public void ChangeInputLanguage(string ISOLang)
{
   // Convert ISO Culture name to InputLanguage object. Be aware: if ISO is not supported
    // ArgumentException will be invoked here
    InputLanguage nextLang = InputLanguage.FromCulture(new System.Globalization.CultureInfo(ISOLang));
   ChangeInputLanguage(nextLang);
}

/// <summary>
/// Changing current Input Language to a new one passed in the param
/// </summary>
/// <param name="LangID">Integer Culture code e.g. 1033 for English</param>
public void ChangeInputLanguage(int LangID)
{
   // Convert Integer Culture code to InputLanguage object. Be aware: if Culture code is not supported
    // ArgumentException will be invoked here
    InputLanguage nextLang = InputLanguage.FromCulture(new System.Globalization.CultureInfo(LangID));
   ChangeInputLanguage(nextLang);
}

/// <summary>
/// Changing current Input Language to a new one passed in the param
/// </summary>
/// <param name="InputLang">New Input Language as InputLanguage object</param>
public void ChangeInputLanguage(InputLanguage InputLang)
{
   // Check is this Language really installed. Raise exception to warn if it is not:
    if (InputLanguage.InstalledInputLanguages.IndexOf(InputLang) == -1)
       throw new ArgumentOutOfRangeException();
   // InputLAnguage changes here:
    InputLanguage.CurrentInputLanguage = InputLang;
}
Posted in C#

Fixed phpMyAdmin ใน Ubuntu 18.04 “Warning in ./libraries/plugin_interface.lib.php#551 count()”

ปัญหา

Warning in ./libraries/plugin_interface.lib.php#551
 count(): Parameter must be an array or an object that implements Countable

วิธีแก้

backup ไฟล์ plugin_interface.lib.php ไว้ก่อน

$ sudo cp /usr/share/phpmyadmin/libraries/plugin_interface.lib.php /usr/share/phpmyadmin/libraries/plugin_interface.lib.php.bak

เข้าไปแก้ไขไฟล์ plugin_interface.lib.php

$ sudo nano /usr/share/phpmyadmin/libraries/plugin_interface.lib.php 

กด CTRL + W แล้วค้นหาคำว่า

if ($options != null && count($options) > 0) {

ให้แทนด้วย

if ($options != null && count((array)$options) > 0) {

Link

Fixed phpMyAdmin ใน Ubuntu 18.04 “Warning in ./libraries/sql.lib.php#613 count()”

ปัญหา

Warning in ./libraries/sql.lib.php#613 count(): Parameter must be an array or an object that implements Countable

วิธีแก้

backup ไฟล์ sql.lib.php ไว้ก่อน

$ sudo cp /usr/share/phpmyadmin/libraries/sql.lib.php /usr/share/phpmyadmin/libraries/sql.lib.php.bak

เข้าไปแก้ไขไฟล์ sql.lib.php

$ sudo nano /usr/share/phpmyadmin/libraries/sql.lib.php

กด CTRL + W แล้วค้นหาคำว่า

(count($analyzed_sql_results['select_expr'] == 1)

ให้แทนด้วย

((count($analyzed_sql_results['select_expr']) == 1

Link

โปรเจ็กส์ Web Application เรียกใช้ jQuery

1.อ้างถึง jQuery

ไฟล์ Pages|Shared|_Layout.cshtml

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - WebApp1</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
...

2.ทดลองใช้งาน เมื่อคลิกที่ <P> แล้วจะแสดง alert

ไฟล์ Pages|Index.cshtml

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>

    <p>Click on this paragraph.</p>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        $("p").click(function () {
            alert("The paragraph was clicked.");
        });
    });
</script>

Link

สร้างโปรเจ็กส์ Web API ติดต่อ MySQL

  1. สร้างโปรเจ็กส์ด้วย Visual Studio 2019
  2. ไฟล์ต่างๆในโปรเจ็กส์
  3. เพิ่มคลาส Movie
  4. สร้างคอนโทรลเลอร์ MovieController
  5. ติดตั้ง Pomelo.EntityFrameworkCore.MySql
  6. สร้างตารางที่ MySQL
  7. ทดสอบ API
Continue reading