using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ABC.DanhMuc.NhomNCC;
using ABC.NhomNCC;
using System.Xml;
using System.IO;
using ABC.GiaoDich;


namespace ABC.BanLe
{
    
    public partial class ChonNhom_Form_Le : DevExpress.XtraEditors.XtraForm {

        public ChonNhom_Form_Le()
        {           

            InitializeComponent();  
            this.Text = "Cấu hình nhập lẽ";
            _ID1.Properties.DataSource = DuLieu.List_Nhom_NCC.Tables[0];
            simpleButton1.Click += new EventHandler(simpleButton1_Click);
            btn_themNCC.Click += new EventHandler(btn_themNCC_Click);
            simpleButton2.Click += new EventHandler(simpleButton2_Click);
            txtkytu.Text = DuLieu.KyTu;
            lbvidu.Text = "VD : Số Toa lẽ : "+txtkytu.Text+"01";
            txtkytu.TextChanged += new EventHandler(txtkytu_TextChanged);
        }
        NhapLe_Class _NhapLe_Class = new NhapLe_Class();
        void txtkytu_TextChanged(object sender, EventArgs e)
        {
            if (txtkytu.Text != "")
            {
                lbvidu.Text = "VD : Số Toa lẽ : " + txtkytu.Text + "01";

                string _xml_temp_kytu = Path.GetDirectoryName(Application.ExecutablePath) + @"\BanLe\TempDataLe\KyTu.xml";
                    XmlDocument doc = new XmlDocument();
                    doc.Load(_xml_temp_kytu);
                    XmlNodeList aNodes = doc.SelectNodes("/NewDataSet/Table");
                    XmlNode node1 = aNodes[0];
                    foreach (XmlNode node2 in node1.ChildNodes)
                    {
                        if (node2.Name == "ID")
                            node2.InnerText = txtkytu.Text.ToString().ToUpper();

                    }
                    doc.Save(_xml_temp_kytu);
                    _NhapLe_Class.load_xml_kytu();
                
            }
            else
            {
                msgbox.dialog_OK_info("Vui lòng nhập ký tự đầu cho số hóa đơn.");
            }
            
        }
        public string Kytu_hoadon;

        void simpleButton2_Click(object sender, EventArgs e)
        {
            NhapLe_Class._nhom = "All";
            
            this.Close();
        }
        NhomNCC_Forms _NhomNCC_Forms;
        void btn_themNCC_Click(object sender, EventArgs e)
        {
            _NhomNCC_Forms = new NhomNCC_Forms();
            //_NhomNCC_Forms.FormClosed += new FormClosedEventHandler(_NhomNCC_Forms_FormClosed);
            //_NhomNCC_Forms.ShowDialog();
        }
        NhomNCC_Class _NhomNCC_Class = new NhomNCC_Class();
        void _NhomNCC_Forms_FormClosed(object sender, FormClosedEventArgs e)
        {
            _NhomNCC_Class.get_store("sp_NhomNCC1_Load");
            _ID1.Properties.DataSource = DuLieu.List_Nhom_NCC.Tables[0];
        }

        void simpleButton1_Click(object sender, EventArgs e)
        {
            if (_ID1.EditValue != null)
            {
                NhapLe_Class._nhom = _ID1.EditValue.ToString().ToUpper();
                //tennhom = _ID1.EditValue.ToString().ToUpper();
                this.Text = _ID1.EditValue.ToString();
                this.Close();
            }
            else
            {
                msgbox.dialog_OK_info("Bạn chưa chọn nhóm lái.");
            }
            
        }

       

     


     

    }
}
