using Packing.lib.datasource;
using lib.model;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Packing
{
    public partial class WorkerSelectFrm : Form
    {
        bool isChangeWorkerMode = false;

        public WorkerSelectFrm(Boolean isChangeWorkerMode = false)
        {
            InitializeComponent();

            this.isChangeWorkerMode = isChangeWorkerMode;
        }

        private void WorkerSelectFrm_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            List<object[]> users = (new Users()).get((new Users()).__COLUMNS, String.Format("dept_id='{0}'", Form1.ini.Read("GroupID", "DataBase")),null, "CONVERT(int, id)");
            workerNoDsBindingSource.Clear();
            WorkerNoDs.list = new List<WorkerNoDs>();

            foreach (object[] row in users)
            {
                // go to each record of worker
                WorkerNoDs.list.Add(new WorkerNoDs(row[0].ToString(), row[1].ToString()));
            }

            dataGridWorkerList.DataSource = WorkerNoDs.list;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (isChangeWorkerMode)
            {
                this.Close();
            } else
            {
                Application.Exit();
            }
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {

            WorkerNoDs worker = WorkerNoDs.list[dataGridWorkerList.CurrentCell.RowIndex];
            Form1.worker = worker;

            this.Close();
        }
    }
}
