using DeviceRepair.Models;
using DeviceRepair.Models.Device;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SqlSugarTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
                {
                    ConnectionString = "Data Source=www.clovejunti.cn,11433;Initial Catalog=DriveMaintenance;Persist Security Info=True;User ID=sa;Password=P@ssw0rd;",
                    DbType = SqlSugar.DbType.SqlServer,
                    IsAutoCloseConnection = true,
                    InitKeyType = InitKeyType.Attribute
                }))
                {
                    // 获取设备计划信息
                    DeviceInformationInfo Dev = db.Queryable<DeviceInformationInfo>().First(x => x.AutoID == 408);
                    List<DriveMaintencePlanInfo> plans = db.Queryable<DriveMaintencePlanInfo>().Where(x => x.EquipmentID == 408 && x.MaintenanceYear == 2024 && SqlFunc.HasValue(x.MaintenanceType)).ToList();
                    int[] pIds = plans.Select(x => x.AutoID).ToArray();

                    List<MaintenanceRecordInfo> records = db.Queryable<MaintenanceRecordInfo>().Where(x => x.EquipmentPrimaryID == 408 && SqlFunc.ContainsArray(pIds, x.AutoID)).ToList();


                    DeviceAnnPlanView devs = new DeviceAnnPlanView
                    {
                        Dev = Dev,
                        Plans = plans,
                        Records = records
                    };


                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
