using ETC2019.Models;
using Newtonsoft.Json;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ETCConsoleTesting
{
    class Program
    {
        static string[] AllowExtension { get; set; } = new string[] { ".jpg", ".jpeg", ".gif" };

        static void Main(string[] args)
        {
            Bitmap image = new Bitmap(@"C:\Users\ECOM\Desktop\44098165_2094594700585147_1068071517981507584_o.jpg");

            double r = 0, g = 0, b = 0;

            for (int x = 0; x < image.HorizontalResolution; x++)
                for (int y = 0; y < image.VerticalResolution; y++)
                {
                    r = r + image.GetPixel(x, y).R;
                    g = g + image.GetPixel(x, y).G;
                    b = b + image.GetPixel(x, y).B;
                }

            r = r / image.HorizontalResolution * image.VerticalResolution;

            g = g / image.HorizontalResolution * image.VerticalResolution;

            b = b / image.HorizontalResolution * image.VerticalResolution;


        }
        // Config 檔案製作
        //static void Main(string[] args)
        //{
        //    Configuration config = new Configuration() { CreateDT = DateTime.Now, ModifyDT = DateTime.Now };

        //    config.AllowExtension = new string[] { ".jpg", ".jpeg", ".bmp", ".gif" };

        //    config.Return = new ReturnModel();

        //    config.ROI = new ROIModel();

        //    config.SQL = new SQLModel();

        //    config.SQL.Items = new SQL[]
        //    {
        //        new SQL()
        //        {
        //            DataSource = "192.168.6.233",
        //            InitialCatalog = "nhpb",
        //            UserID = "sa",
        //            Password = "jack",
        //            Table = "[nhpb].[dbo].[return]",
        //            Columns = "[code],[name]",
        //        },
        //        new SQL()
        //        {
        //            DataSource = "192.168.6.233",
        //            InitialCatalog = "nhpb",
        //            UserID = "sa",
        //            Password = "jack",
        //            Table = "[nhpb].[dbo].[etcMetered]",
        //            Columns = "*",
        //        },
        //    };

        //    DataRowCollection rows = config.SQL.Items[0].Select();

        //    List<Return> items = new List<Return>();

        //    for (int i = 0; i < rows.Count; i++)
        //        items.Add(new Return() { ID = rows[i][0] as string, Text = rows[i][1] as string });

        //    items.Sort();

        //    config.Return.Items = items.ToArray();

        //    StreamWriter sw = new StreamWriter("config.json");

        //    sw.Write(JsonConvert.SerializeObject(config, Formatting.Indented));

        //    sw.Flush();

        //    sw.Close();

        //    Console.ReadKey();
        //}
    }
}
