using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SinosysHardware.Business;

namespace SinosysHardware.UI
{
    public partial class CustomerService : Form
    {
        private BindingSource Bding =new BindingSource();
        public CustomerService()
        {
            InitializeComponent();
        }

        private void btnSynData_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                statusBar1.Text = "Synchronizing database...";
                Services s = new Services();
                s.SyncWithDataSource();
                this.FillDataGridData();
                statusBar1.Text = "";
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
           
            Cursor.Current = Cursors.Default;
            MessageBox.Show("同步完成！");
        }

        private void btnNewOrder_Click(object sender, EventArgs e)
        {
            NewOrder No = new NewOrder();
            No.ShowDialog();
            FillDataGridData();
            No.Dispose();
        }

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

        private void CustomerService_Load(object sender, EventArgs e)
        {
            this.FillDataGridData();
        }

        private void FillDataGridData()
        {
            OrderDB odb = new OrderDB();
            DataSet Ds = odb.GetOrders(Services.OrderState.All);
            Bding.DataSource = Ds.Tables[0].DefaultView; ;
            this.dataGrid1.DataSource = Bding;
        
        }
    }
}