﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LJH.Inventory.BusinessModel;
using LJH.Inventory.BusinessModel.SearchCondition;
using LJH.Inventory.BLL;
using LJH.GeneralLibrary;
using LJH.GeneralLibrary.Core.UI;
using LJH.GeneralLibrary.Core.DAL;

namespace LJH.Inventory.UI.Forms.Inventory.View
{
    public partial class FrmSteelRollCheckRecordView : FrmMasterBase
    {
        public FrmSteelRollCheckRecordView()
        {
            InitializeComponent();
        }

        #region 重写基类方法
        protected override List<object> GetDataSource()
        {
            List<InventoryCheckSheet> records = null;
            if (SearchCondition == null)
            {
                records = (new APIClient(AppSettings.Current.ConnStr)).GetList<string, InventoryCheckSheet>(null).QueryObjects;
            }
            else
            {
                records = (new APIClient(AppSettings.Current.ConnStr)).GetList<string, InventoryCheckSheet>(SearchCondition).QueryObjects;
            }
            return (from item in records
                    orderby item.SheetDate descending
                    select (object)item).ToList();
        }

        protected override void ShowItemInGridViewRow(DataGridViewRow row, object item)
        {
            var sheet = item as InventoryCheckSheet;
            row.Tag = sheet;
            row.Cells["colCheckDate"].Value = sheet.SheetDate.ToString("yyyy年MM月dd日");
            row.Cells["colSheetID"].Value = sheet.ID;
            row.Cells["colBeforeWeight"].Value = sheet.Inventory;
            row.Cells["colWeight"].Value = sheet.CheckCount;
            row.Cells["colChecker"].Value = sheet.Checker;
            row.Cells["colMemo"].Value = sheet.Memo;
            if (sheet.State == SheetState.已作废)
            {
                row.DefaultCellStyle.ForeColor = Color.Red;
                row.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Strikeout, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            }
        }
        #endregion

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0) return;
            var sheet = dataGridView1.Rows[e.RowIndex].Tag as InventoryCheckSheet;
            if (dataGridView1.Columns[e.ColumnIndex].Name == "colSheetID")
            {
                var frm = FrmSheetDetailFactoryBase.Current.CreateByInventoryCheckSheetID(sheet.ID);
                if (frm != null) frm.ShowDialog();
            }
        }
    }
}
