using System;
using System.Data;

namespace DeviceRepairAndOptimization.Pages
{
    public partial class page_totalWarn : FormBase
    {
        Action ParentClose;
        public page_totalWarn(Action exitForm)
        {
            InitializeComponent();
            ParentClose = exitForm;
        }

        DataTable CreateDatas()
        {
            DataTable Datas = new DataTable();
            Datas.Columns.AddRange(new DataColumn[] {
                new DataColumn { ColumnName = "Number"          },
                new DataColumn { ColumnName = "Remark"          },
                new DataColumn { ColumnName = "LastDate"        },
                new DataColumn { ColumnName = "WarmDate"        },
                new DataColumn { ColumnName = "RemainingDays"   },
                new DataColumn { ColumnName = "Cycle"           }
            });


            int[] numbers = new int[] { 32, 55, 61, 63, 78 };
            string[] remarks = new string[] { "这是一段不重要的说明。", "这是一段很重要很重要的说明。" };
            int[] remainingDays = new int[] { 15, 10, 7, 5, 3 };
            int[] cycles = new int[] { 183, 365, 92 };

            DataRow row = Datas.NewRow();
            row["Number"] = numbers[0];
            row["Remark"] = remarks[0];
            row["LastDate"] = DateTime.Today.AddDays((remainingDays[0] - cycles[0]));
            row["WarmDate"] = DateTime.Today.AddDays(-remainingDays[0]);
            row["RemainingDays"] = remainingDays[0];
            row["Cycle"] = cycles[0];
            Datas.Rows.Add(row);

            DataRow row1 = Datas.NewRow();
            row1["Number"] = numbers[1];
            row1["Remark"] = remarks[1];
            row1["LastDate"] = DateTime.Today.AddDays((remainingDays[1] - cycles[1]));
            row1["WarmDate"] = DateTime.Today.AddDays(-remainingDays[1]);
            row1["RemainingDays"] = remainingDays[1];
            row1["Cycle"] = cycles[1];
            Datas.Rows.Add(row1);

            DataRow row2 = Datas.NewRow();
            row2["Number"] = numbers[2];
            row2["Remark"] = remarks[1];
            row2["LastDate"] = DateTime.Today.AddDays((remainingDays[2] - cycles[2]));
            row2["WarmDate"] = DateTime.Today.AddDays(-remainingDays[2]);
            row2["RemainingDays"] = remainingDays[2];
            row2["Cycle"] = cycles[2];
            Datas.Rows.Add(row2);

            DataRow row3 = Datas.NewRow();
            row3["Number"] = numbers[3];
            row3["Remark"] = remarks[1];
            row3["LastDate"] = DateTime.Today.AddDays((remainingDays[3] - cycles[2]));
            row3["WarmDate"] = DateTime.Today.AddDays(-remainingDays[3]);
            row3["RemainingDays"] = remainingDays[3];
            row3["Cycle"] = cycles[2];
            Datas.Rows.Add(row3);

            DataRow row4 = Datas.NewRow();
            row4["Number"] = numbers[4];
            row4["Remark"] = remarks[0];
            row4["LastDate"] = DateTime.Today.AddDays((remainingDays[4] - cycles[2]));
            row4["WarmDate"] = DateTime.Today.AddDays(-remainingDays[4]);
            row4["RemainingDays"] = remainingDays[4];
            row4["Cycle"] = cycles[2];
            Datas.Rows.Add(row4);

            return Datas;
        }

        private void page_totalWarn_Load(object sender, EventArgs e)
        {
            DataTable Datas = CreateDatas();
            gridControl1.DataSource = Datas;
        }

        /// <summary>
        /// 窗体大小改变时事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void Page_Resize(object sender, EventArgs e)
        {

        }

        private void tileView1_ContextButtonClick(object sender, DevExpress.Utils.ContextItemClickEventArgs e)
        {
            int RowHandle = ((DevExpress.XtraGrid.Views.Tile.TileViewItem)e.DataItem).RowHandle;
            DataRow data = tileView1.GetDataRow(RowHandle);
            int key = int.Parse(data["Number"] + "");
            switch (e.Item.Name)
            {
                //本次忽略
                case "contextButton1":
                    tileView1.DeleteRow(RowHandle);
                    break;
                case "contextButton2":
                    //using (DialogWindow dw = new DialogWindow(data["Number"] + "", typeof(page_DriveMaintenance), data))
                    //{
                    //    if (dw.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    //    {
                    //        tileView1.DeleteRow(RowHandle);
                    //    }
                    //}

                    break;
                default:
                    break;
            }

            if (tileView1.RowCount == 0)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                Invoke(new Action(() => { ParentClose(); }));
            }
        }
    }
}
