using SelfHelpClient.BL;
using SelfHelpClient.BO;
using SelfHelpClient.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SelfHelpClient
{
  public partial class SelfHelpForm : Form
  {
    long billID;
    public SelfHelpForm(long id)
    {
      InitializeComponent();
      billID = id;
    }

    private void backBtn_Click(object sender, EventArgs e)
    {
      MainForm.Form.Show();
      this.Close();
    }

    private void washCarBtn_Click(object sender, EventArgs e)
    {
      var standard = WeightBillBL.GetCarStandard(billID);
      if (standard == null)
      {
        DialogForm.ShowDialog("未填写车辆标准", 5);
        return;
      }
      var list = XmlUtil.DeserializeFromFile<List<CarStandardConfig>>("CarStandardConfig.xml");
      var config = list.FirstOrDefault(x => x.Standard == standard.Value);
      if (config == null)
      {
        DialogForm.ShowDialog("未配置车辆费用标准", 5);
        return;
      }
      var printEntity = WeightBillBL.GetWashPrintEntity(billID, config.Fee);

      var dic = new Dictionary<string, string>();
      dic.Add("$Date", printEntity.Date.ToString("yyyy-MM-dd"));
      dic.Add("$Index", printEntity.RowIndex.ToString());
      dic.Add("$CarNumber", printEntity.CarNumber);
      dic.Add("$CarSize",config.ShowName);
      dic.Add("$Fee", config.Fee.ToString("#0.######"));
      dic.Add("$WeightMan", printEntity.WeightMan);

      BwpClientPrint.BwpClientWebPrint.Print("CarPaperPrint.html", dic);

      backBtn_Click(null, EventArgs.Empty);
    }
  }
}
