using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Core.Metadata.Edm;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DynamicData;
using HZH_Controls.Controls;
using WinformDevFramework.Core.Configuration;
using WinformDevFramework.IServices.System;
using WinformDevFramework.Models;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;

namespace WinformDevFramework
{
    public partial class Form1 : Form
    {
        private Random _rand = new Random();
        private ISysMenuServices _menuServices;
        public Form1( ISysMenuServices sysMenuServices)
        {
            _menuServices = sysMenuServices;
            InitializeComponent();
           
        }
        private void AddRootNode(string nodeText)
        {
      ;
        }

        private void AddChildNodes(int nodeCount)
        {
            
        }
        private void button1_Click(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            TabControl parentTabControl = this.Parent.Parent as TabControl;
            TabPage tabpage = this.Parent as TabPage;
            parentTabControl.TabPages.Remove(tabpage);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            TabControl parentTabControl = this.Parent.Parent as TabControl;
            TabPage tabpage = this.Parent as TabPage;
            parentTabControl.TabPages.Remove(tabpage);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           

        }

        private void button1_Click_2(object sender, EventArgs e)
        {
            string str =
                "[encoded data, 33500 characters]";
            //Image image = Base64ToImage(str);
            //pictureBox1.Image= image;

            // 获取PictureBox控件中的图片
            byte[] imageBytes = Convert.FromBase64String(str);
            // 保存图片到临时文件
            string tempFilePath = Application.StartupPath + "temp.png";
            File.WriteAllBytes(tempFilePath, imageBytes);


            //建立新的系统进程    
            System.Diagnostics.Process process = new System.Diagnostics.Process();

            //设置图片的真实路径和文件名    
            process.StartInfo.FileName = tempFilePath;

            //设置进程运行参数，这里以最大化窗口方法显示图片。    
            process.StartInfo.Arguments = "rundl132.exe C://WINDOWS//system32//shimgvw.dll,ImageView_Fullscreen";

            //此项为是否使用Shell执行程序，因系统默认为true，此项也可不设，但若设置必须为true    
            process.StartInfo.UseShellExecute = true;

            //此处可以更改进程所打开窗体的显示样式，可以不设    
            process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            process.Start();
            process.Close();
            // 删除临时文件
            //File.Delete(tempFilePath);
        }
        private string ImageToBase64(Image image)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                image.Save(memoryStream, image.RawFormat);
                byte[] imageBytes = memoryStream.ToArray();
                return Convert.ToBase64String(imageBytes);
            }
        }
        private Image Base64ToImage(string base64str)
        {
            byte[] imageBytes = Convert.FromBase64String(base64str);
            using (MemoryStream memoryStream = new MemoryStream(imageBytes))
            {
                return Image.FromStream(memoryStream);
            }
        }
    }

    class User
    {
        public int id { get; set; }
        public string name { get; set; }
    }
}
