using HandyControl.Controls;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
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.Shapes;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.StoreInfo;
using WCS.Model.ApiModel.User;
using 智慧物流软件系统.Api;

namespace 智慧物流软件系统
{
    /// <summary>
    /// CalibrationWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CalibrationWindow : System.Windows.Window
    {
        public int BoardId { get; set; }

        public int ModuleId { get; set; }
        public string ModuleCode { get; set; }
        public CalibrationWindow(int boardId, int moduleId, string moduleCode)
        {
            InitializeComponent();
            BoardId = boardId;
            ModuleId = moduleId;
            tagIdTxt.Text = $"板ID：{boardId}";
            ModuleCode = moduleCode;
            moduleCodeTxt.Text = $"库位：{moduleCode}";
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                Button_Click(null, null);
            }
            else if (e.Key == Key.Escape)
            {
                this.Close();
            }
        }


        public string GetDataFromHttp(string data, string url, string httpMethod)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Method = httpMethod;
                request.ContentType = "application/json";
                if (!string.IsNullOrEmpty(data))
                {
                    string strContent = data; //参数data
                    using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream()))
                    {
                        dataStream.Write(strContent);
                        dataStream.Close();
                    }
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string encoding = response.ContentEncoding;
                if (encoding == null || encoding.Length < 1)
                {
                    encoding = "UTF-8"; //默认编码  
                }
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
                string retString = reader.ReadToEnd();
                return retString;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public class RootLogin
        {
            public int code { get; set; }

            public string msg { get; set; }

            public object data { get; set; }
        }
    }
}
