2020年12月9日 星期三

DataGrid and OleDb Connection Test

1. Windows 10 x64 @ ASUS X450J

2. Visual Studio 2019

3. Install Microsoft Access Database Engine 2010 可轉散發套件

https://www.microsoft.com/zh-tw/download/details.aspx?id=13255

4. Northwind.xls (Customer Sheet)

Ex1 Console (.NET Framework)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace oledbEx1

{

    using System.Data;

    using System.Data.OleDb;

    class Program

    {

        static void Main(string[] args)

        {

            DataTable DT = OleDbGetTable("SELECT * FROM [Customers$]", "Northwind.xlsx");

            Console.WriteLine(DT.Rows.Count);

            Console.ReadLine();

        }

        static public DataTable OleDbGetTable(string SQL, string path1)

        {

            DataSet DS = new DataSet();

            OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path1 + ";Extended Properties='Excel 12.0 Xml; HDR = YES';");

            conn.Open();

            OleDbDataAdapter apt = new OleDbDataAdapter(SQL, conn);

            apt.Fill(DS);

            conn.Close();

            return DS.Tables[0];

        }

    }

}

 Ex2 Form (.NET Framework)

namespace FormEx1

{

    using System.Data.OleDb;

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            DataGridView dataGridView1 = new DataGridView();

            this.Controls.Add(dataGridView1);

            dataGridView1.Dock = DockStyle.Fill;

            DataTable DT = OleDbGetTable("SELECT * FROM [Customers$]", "Northwind.xlsx");

            dataGridView1.DataSource = DT.DefaultView;

        }

        public DataTable OleDbGetTable(string SQL, string path1)

        { ...}

  }

}

Ex3 Form (.NET Core 3.x)

nuget Add System.Data.OleD

Ex4 WPF (.NET Framework)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

namespace WPFEx1

{

    using System.Data.OleDb;

    using System.Data;

    /// <summary>

    /// MainWindow.xaml 的互動邏輯

    /// </summary>

    public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

            DataGrid dataGridView1 = new DataGrid();

            Grid G1 = new Grid();

            this.Content = G1;

            G1.Children.Add(dataGridView1);

            DataTable DT = OleDbGetTable("SELECT * FROM [Customers$];", "Northwind.xlsx");

            dataGridView1.ItemsSource = DT.DefaultView;

        }

        public DataTable OleDbGetTable(string SQL, string path1)

        {... }

   

    }

}

Ex5 WPF (.NET Core 3.x)

nuget Add System.Data.OleD

Ex6 Web (.NET Framework)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace WebApp1

{

    using System.Data;

    using System.Data.OleDb;

    public partial class WebForm1 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            DataGrid dataGridView1 = new DataGrid();

            form1.Controls.Add(dataGridView1);

            DataTable DT = OleDbGetTable("SELECT * FROM [Customers$];", Server.MapPath("Northwind.xlsx"));

            dataGridView1.DataSource = DT.DefaultView;

            dataGridView1.DataBind();

       }

        public DataTable OleDbGetTable(string SQL, string path1)

        { ...   }

    }

}



2020年11月3日 星期二

Kinect VideoCAM

1. Ref add Microsoft.Kinect 1.8

2.  xaml

<Window x:Class="WPFCam1.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:WPFCam1"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    <Grid>

        <Rectangle Width="320" Height="240">

            <Rectangle.Fill>

                <ImageBrush x:Name="image1">

                   

                </ImageBrush>

            </Rectangle.Fill>

        </Rectangle>

    </Grid>

</Window>

3. C#

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;


namespace WPFCam1

{

    using Microsoft.Kinect;

    /// <summary>

    /// MainWindow.xaml 的互動邏輯

    /// </summary>

    public partial class MainWindow : Window

    {

        private KinectSensor sensor;

        private WriteableBitmap colorBitmap;

        private byte[] colorPixels;

        public MainWindow()

        {

            InitializeComponent();

            sensor = KinectSensor.KinectSensors[0];

            this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            // Allocate space to put the pixels we'll receive

            this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];

            // This is the bitmap we'll display on-screen

            this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);

            // Set the image we display to point to the bitmap where we'll put the image data

            this.image1.ImageSource = this.colorBitmap;

            this.sensor.ColorFrameReady += this.SensorColorFrameReady;

            // Start the sensor!

            this.sensor.Start();

        }

        private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)

        {

            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())

            {

                if (colorFrame != null)

                {

                    // Copy the pixel data from the image to a temporary array

                    colorFrame.CopyPixelDataTo(this.colorPixels);


                    // Write the pixel data into our bitmap

                    this.colorBitmap.WritePixels(

                        new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),

                        this.colorPixels,

                        this.colorBitmap.PixelWidth * sizeof(int),

                        0);

                }


            }


        }

    }

}



2020年3月16日 星期一

Rotation animation (div)

Ref: https://www.w3schools.com/js/tryit.asp?filename=tryjs_dom_animate_3
<!DOCTYPE html>
<html>
<style>
#myContainer {
  width: 400px;
  height: 400px;
  position: relative;
  background: yellow;
}
/*
center @ 25, 100
*/
#div1 {
  width: 50px;
  height: 200px;
  position: absolute;
  background-color: transpency;

}
/*  25 - w/2 = 50, 100  */
#div2 {
  left: 0px;
  top:100px;
  width: 50px;
  height: 100px;
  position: absolute;
  background-color: blue;
  border-style: solid;
  border-color: green;
}
/*  25 - w/2 = 50, 100  */
#diva {
  width: 50px;
  height: 200px;
  position: absolute;
  background-color: transpency;

}
/*  25 - w/2 = 50, 100  */
#divb {
  left: 0px;
  top:100px;
  width: 50px;
  height: 100px;
  position: absolute;
  background-color: blue;
  border-style: solid;
  border-color: green;
}
</style>
<body>

<p>
<button onclick="myMove()">Click Me</button>
</p>

<div id ="myContainer">

<div id="div1" style="top:0px; left:100px; transform: rotate(-30deg)">
  <div id="div2">
    <div id="diva" style="top:0px; left:0px; transform: rotate(10deg)">
      <div id="divb">

      </div>
    </div>
  </div>
</div>

<script>
function myMove() {

  var pos = -30;
  var dir = 1;
  var c1 = document.getElementById("div1");
  var ca = document.getElementById("diva");
  var id = setInterval(frame, 10);
  function frame() {
    if (pos == 30) {
      clearInterval(id);
    } else {
      redraw();
    }
  }
  function redraw()
  {
    pos++;
    //elem.style.top = pos + 'px';
    //elem.style.left = pos + 'px';
    c1.style.transform = "rotate(" + (pos) + "deg)";
    ca.style.transform = "rotate(" + (pos) + "deg)";
  }
}
</script>

</body>
</html>


2020年1月7日 星期二

git change user error

REF: https://blog.csdn.net/klxh2009/article/details/76019742

git clone xxx
update local files
更新github專案內容
git add .
git config --global user.email "userB@gamil.com"
git config --global user.name "userB"
git commit -m “upload template”
git push -u origin master

-----
check default user
git config --list

D:\Course1081\uTaipei\project\git2\UserB.github.io>git push -u origin master
remote: Permission to userB/userB.github.io.git denied to userA.
fatal: unable to access 'https://github.com/userB/userB.github.io.git/': The requested URL returned error: 403