﻿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.WebAPIClient;
using LJH.GeneralLibrary.Core.DAL;
using LJH.GeneralLibrary.Core.UI;
using LJH.GeneralLibrary;
using LJH.Inventory.UI.Forms.General;
using LJH.Inventory.UI.Forms.Inventory.View;

namespace LJH.Inventory.UI.Forms.Sale
{
    public partial class Frm折叠门价格计算器 : Form
    {
        public Frm折叠门价格计算器()
        {
            InitializeComponent();
        }

        public List<OrderItem> OrderItems { get; set; }

        private void Frm卷帘门价格计算器_Load(object sender, EventArgs e)
        {
            var temp = OrderItems.Select(it => it.Product.GetPropertyByDecimalOrDefault(ProductNote.洞口面积单价)).Distinct().ToList();
            if (temp.Count == 1) txt洞口面积单价.DecimalValue = temp[0];

            temp = OrderItems.Select(it => it.Product.GetPropertyByDecimalOrDefault(ProductNote.折叠帘布面积单价)).Distinct().ToList();
            if (temp.Count == 1) txt帘布面积单价.DecimalValue = temp[0];

            temp = OrderItems.Select(it => it.Product.GetPropertyByDecimalOrDefault(ProductNote.折叠封堵洞口面积单价)).Distinct().ToList();
            if (temp.Count == 1) txt封堵洞口面积单价.DecimalValue = temp[0];

            temp = OrderItems.Select(it => it.Product.GetPropertyByDecimalOrDefault(ProductNote.折叠封堵帘布面积单价)).Distinct().ToList();
            if (temp.Count == 1) txt封堵帘布面积单价.DecimalValue = temp[0];

            temp = OrderItems.Select(it => it.Product.GetPropertyByDecimalOrDefault(ProductNote.配件价格)).Distinct().ToList();
            if (temp.Count == 1) txt其它.DecimalValue = temp[0];
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            foreach (var oi in OrderItems)
            {
                oi.Product.SetProperty(ProductNote.洞口面积单价, txt洞口面积单价.DecimalValue > 0 ? txt洞口面积单价.DecimalValue.ToString("F2") : null);
                oi.Product.SetProperty(ProductNote.折叠帘布面积单价, txt帘布面积单价.DecimalValue > 0 ? txt帘布面积单价.DecimalValue.ToString("F2") : null);
                oi.Product.SetProperty(ProductNote.折叠封堵洞口面积单价, txt封堵洞口面积单价.DecimalValue > 0 ? txt封堵洞口面积单价.DecimalValue.ToString("F2") : null);
                oi.Product.SetProperty(ProductNote.折叠封堵帘布面积单价, txt封堵帘布面积单价.DecimalValue > 0 ? txt封堵帘布面积单价.DecimalValue.ToString("F2") : null);
                oi.Product.SetProperty(ProductNote.配件价格, txt其它.DecimalValue > 0 ? txt其它.DecimalValue.ToString("F2") : null);
                oi.Price = oi.Product.计算报价();
                oi.CalAmount();
                this.DialogResult = DialogResult.OK;
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
