using DevExpress.XtraBars;
using DevExpress.XtraBars.ToolbarForm;
using DeviceRepair.Models;
using DeviceRepair.Models.Record;
using DeviceRepairAndOptimization.Common;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace DeviceRepairAndOptimization.Pages.Plan
{
    public partial class pageMaintenanceRecord : ToolbarForm
    {
        public List<MaintenanceRecordHistoryModel> Datas;
        public MaintenanceRecordHistoryModel CurrentModel;

        public MaintenanceFilterModel filter { get; set; }

        public pageMaintenanceRecord()
        {
            InitializeComponent();
        }

        private void pageMaintenanceRecord_Load(object sender, EventArgs e)
        {
            try
            {
                APIResponseData apiResponseData = Biz.PreserveManager.Instance.GetRecordHisView(filter);
                if (!apiResponseData.IsSuccess)
                {
                    throw new Exception(apiResponseData.Message);
                }

                Datas = apiResponseData.ToDeserializeObject<List<MaintenanceRecordHistoryModel>>();
                this.cfMaintenanceRecord1.Datas = Datas;
                this.cfMaintenanceRecord1.RefreshGrid();
            }
            catch (Exception ex)
            {
                XtraMessageBoxHelper.Error(ex.Message);
            }
        }

        private void btnEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                CurrentModel = cfMaintenanceRecord1.CurrentModel;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                XtraMessageBoxHelper.Error(ex.Message);
            }
        }
    }
}