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

namespace SelfHelpClient
{
  public partial class MainForm : Form
  {
    private static MainForm mForm;
    public static MainForm Form
    {
      get { return mForm; }
    }
    public MainForm()
    {
      if (!File.Exists("AppConfig.cfg"))
      {
        MessageBox.Show("请先配置服务器地址");
        this.Close();
      }
      WeightBillBL.ServerUrl = File.ReadAllText("AppConfig.cfg");
      mForm = this;
      InitializeComponent();
    }

    private void selfBtn_Click(object sender, EventArgs e)
    {
      var entity = ReadCard();
      if (entity == null)
        return;
      if (entity.BillType == 0)
      {
        DialogForm.ShowDialog("没有待办理业务", 5);
        return;
      }
      new SelfHelpForm(entity.ID).ShowDialog();
      //this.Hide();
    }

    private void weightBtn_Click(object sender, EventArgs e)
    {
      var entity = ReadCard();
      if (entity == null)
        return;
      new WeightForm(entity).Show();
      this.Hide();
    }

    ViewEntity ReadCard()
    {
      var reader = new ReadCardForm();
      if (reader.ShowDialog() == DialogResult.OK)
        return reader.VEntity;
      return null; ;
    }

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