﻿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.WebAPIClient;
using LJH.Inventory.BusinessModel;
using LJH.Inventory.BusinessModel.SearchCondition;
using LJH.GeneralLibrary.Core.UI;
using LJH.GeneralLibrary;

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

        #region 重写基类方法
        protected override void Init()
        {
            base.Init();
        }

        protected override FrmDetailBase GetDetailForm()
        {
            return null;
        }

        protected override List<object> GetDataSource()
        {
            List<PurchaseItemRecord> items = null;
            if (SearchCondition == null)
            {
                items = new PurchaseOrderBLL(AppSettings.Current.ConnStr).GetRecords(null).QueryObjects;
            }
            else
            {
                items = new PurchaseOrderBLL(AppSettings.Current.ConnStr).GetRecords(SearchCondition).QueryObjects;
            }
            return (from item in items
                    orderby item.AddDate ascending, item.SheetNo ascending
                    select (object)item).ToList();
        }

        protected override void ShowItemInGridViewRow(DataGridViewRow row, object item)
        {
            PurchaseItemRecord info = item as PurchaseItemRecord;
            row.Tag = info;
            row.Cells["colSheetID"].Value = info.SheetNo;
            row.Cells["colOrderID"].Value = info.OrderID;
            row.Cells["colCustomer"].Value = info.CustomerName;
            row.Cells["colProject"].Value = info.ProjectID;
            row.Cells["col材料设备名称"].Value = info.Product != null ? info.Product.get_材料设备名称() : null;
            //row.Cells["col规格型号"].Value = info.Product != null ? info.Product.get_规格型号() : null;
            row.Cells["colUnit"].Value = info.Product.Unit;
            row.Cells["colDemandDate"].Value = info.DemandDate;
            row.Cells["col在制"].Value = (info.Count - info.Received > 0) ? (decimal?)(info.Count - info.Received).Trim() : null;
            row.Cells["colMemo"].Value = info.Memo;
            row.DefaultCellStyle.ForeColor = info.Received == info.Count ? Color.Blue : Color.Black;
        }
        #endregion
    }
}

