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

using ABC.DanhMuc.Hang;
using ABC.DanhMuc.KhachHang;
using ABC.DanhMuc.NCC;
using System.Xml;
using ABC.File;
using ABC.KetNoi;

namespace ABC.GiaoDich
{
    public partial class NhapSi_New1 : DevExpress.XtraEditors.XtraForm
    {
        #region hàm dựng
        public NhapSi_New1()
        {
            InitializeComponent();

            Class_KetNoi db = new Class_KetNoi();
            this.Text = Get_CauHinh.Dt_DAT.Rows[0]["Name_Soft"].ToString();
            enter_lever_keypress();
            string sql_ThuongLai = @"Select Tbl_NCC.*,Tbl_NhomNCC.Name as _ID1_Name from Tbl_NCC
                        INNER JOIN Tbl_NhomNCC on Tbl_NCC._ID1 = Tbl_NhomNCC.ID 
                        where Tbl_NCC.IS_User = 1 order by Tbl_NhomNCC.Name asc, Tbl_NCC.Name ASC";
            txtthuonglai.Properties.DataSource = db.T_opendataset(sql_ThuongLai).Tables[0];
          
            string sql = @"Select Tbl_KhachHang.*,Tbl_NhomKhachHang.Name as _ID1_Name,Tbl_KhachHang.ID as ID_KhachHang ,  
                    Tbl_KhachHang.Name as Tbl_KhachHang_Name  
                    from Tbl_KhachHang 
                    INNER JOIN Tbl_NhomKhachHang on Tbl_KhachHang._ID1 = Tbl_NhomKhachHang.ID 
             where    Tbl_KhachHang.IS_User=1 
                     order by Tbl_NhomKhachHang.Name asc, Tbl_KhachHang.Name ASC";
            DataTable dt = db.T_opendataset(sql).Tables[0];
            txtkhachhang.Properties.DataSource = dt;
            txtloaica.Properties.DataSource = DuLieu.List_Hang.Tables[0];
            btn_themNCC.Click += new EventHandler(btn_themNCC_Click);
            btn_ThemKH.Click += new EventHandler(btn_ThemKH_Click);
            btn_Them_Loaica.Click += new EventHandler(btn_Them_Loaica_Click);
            txtkhachhang.EditValueChanged+=new EventHandler(txtkhachhang_EditValueChanged);
        }
        
        #endregion

        #region them danh muc
        Hang_Class _Hang_Class = new Hang_Class();
        KhachHang_Class _KhachHang_Class = new KhachHang_Class();
        NCC_Class _NCC_Class = new NCC_Class();

        NCC_Forms _NCC_Forms;
        KhachHang_Forms _KhachHang_Forms;
        Hang_Forms _Hang_Forms;
        
        void btn_Them_Loaica_Click(object sender, EventArgs e)
        {
            Hang_Form frm = new Hang_Form();
          frm.ShowDialog();
            _Hang_Class.get_store("sp_Hang_Load");
            txtloaica.Properties.DataSource = DuLieu.List_Hang.Tables[0];
          txtloaica.Focus();
        }

        void _Hang_Forms_FormClosed(object sender, FormClosedEventArgs e)
        {
            _Hang_Class.get_store("sp_Hang_Load");
            txtloaica.Properties.DataSource = DuLieu.List_Hang.Tables[0];
            txtloaica.Focus();
        }

        void btn_ThemKH_Click(object sender, EventArgs e)
        {
            KhachHang_Form1 frm = new KhachHang_Form1();
           frm.ShowDialog();
           _KhachHang_Class.get_store("sp_KhachHang_Load");
           txtkhachhang.Properties.DataSource = DuLieu.List_KhachHang.Tables[0];
           txtkhachhang.Focus();
        }

        void _KhachHang_Forms_FormClosed(object sender, FormClosedEventArgs e)
        {
            _KhachHang_Class.get_store("sp_KhachHang_Load");
            txtkhachhang.Properties.DataSource = DuLieu.List_KhachHang.Tables[0];
            txtkhachhang.Focus();
        }
        
        void btn_themNCC_Click(object sender, EventArgs e)
        {
            NCC_Form frm = new NCC_Form();
            frm.ShowDialog();
            _NCC_Class.get_store("sp_NhaCC1_Load");
            txtthuonglai.Properties.DataSource = DuLieu.List_NCC.Tables[0];
            txtthuonglai.Focus();
        }

        void _NCC_Forms_FormClosed(object sender, FormClosedEventArgs e)
        {
            _NCC_Class.get_store("sp_NhaCC1_Load");
            txtthuonglai.Properties.DataSource = DuLieu.List_NCC.Tables[0];
            txtthuonglai.Focus();
        }
        #endregion

        public DataRow dr; 

        #region ham save
        decimal SL, Gia, Sot, Ket, Lu, Cat, Bom;
        public void save()
        {
            #region
            bool Next = true;
            int thutu=0;
            string ms = "";

            if (txtthuonglai.EditValue == null)
            {
                Next = false;
                thutu = 1;
                ms = "Bạn Chưa nhập thương lái.";
            }
            if (Next == true)
            {
                if (txtkhachhang.EditValue == null)
                {
                    Next = false;
                    thutu = 2;
                    ms = "Bạn chưa nhập khách hàng.";
                }

            }
            if (Next == true)
            {
                if (txtloaica.EditValue == null)
                {
                    Next = false;
                    thutu = 3;
                    ms = "Bạn chưa nhập loại cá.";
                }

            }
            if (Next == true)
            {
                if (txtsl.Text == "")
                {
                    Next = false;
                    thutu = 4;
                    ms = "Bạn chưa nhập số lượng.";
                }

            }
            if (Next == true)
            {
                try
                {
                    SL = decimal.Parse(txtsl.Text);
                    Next = true;
                }
                catch
                {
                    Next = false;
                    thutu = 5;
                    ms = "Bạn nhập sai số lượng.";
                }  
            }
            if (Next == true)
            {
                if (txtgia.Text != "")
                {
                    try
                    {
                        Gia = decimal.Parse(txtgia.Text);
                        Next = true;
                    }
                    catch
                    {
                        Next = false;
                        thutu=6;
                        ms = "Bạn nhập sai giá.";
                    }
                }
                else
                {
                    Gia = 0;
                    Next = true;
                }
            }
            if (Next == true)
            {
                if (txtsot.Text != "")
                {
                    try
                    {
                        Sot = decimal.Parse(txtsot.Text);
                        Next = true;
                    }
                    catch
                    {
                        Sot = 0;
                        Next = false;
                        thutu = 7;
                        ms = "Bạn nhập sai số lượng sọt.";
                    }
                }
                else
                {
                    Sot = 0;
                    Next = true;
                }


            }
            if (Next == true)
            {
                if (txtket.Text != "")
                {
                    try
                    {
                        Ket = decimal.Parse(txtket.Text);
                        Next = true;
                    }
                    catch
                    {
                        Next = false;
                        thutu = 8;
                        Ket = 0;
                        ms = "Bạn nhập sai số lượng két.";
                    }
                }
                else
                {
                    Ket = 0;
                    Next = true;
                }


            }
            if (Next == true)
            {
                if (txtLu.Text != "")
                {
                    try
                    {
                        Lu = decimal.Parse(txtLu.Text);
                        Next = true;
                    }
                    catch
                    {
                        Next = false;
                        thutu = 9;
                        Lu = 0;
                        ms = "Bạn nhập sai số lượng Lu.";
                    }
                }
                else
                {
                    Lu = 0;
                    Next = true;
                }
            }
            if (Next == true)
            {
                if (txtCat.Text != "")
                {
                    try
                    {
                        Cat = decimal.Parse(txtCat.Text);
                        Next = true;
                    }
                    catch
                    {
                        Next = false;
                        thutu = 10;
                        Cat = 0;
                        ms = "Bạn nhập sai số lượng Cắt.";
                    }
                }
                else
                {
                    Cat = 0;
                    Next = true;
                }
            }
            if (Next == true)
            {
                if (txtBom.Text != "")
                {
                    try
                    {
                        Bom = decimal.Parse(txtBom.Text);
                        Next = true;
                    }
                    catch
                    {
                        Next = false;
                        thutu = 11;
                        Bom = 0;
                        ms = "Bạn nhập sai số lượng Bom.";
                    }
                }
                else
                {
                    Bom = 0;
                    Next = true;
                }
            }
          
#endregion
            if (Next == true)
            {
                add_dulieu_chualuu(txtthuonglai.EditValue.ToString().ToUpper(),
                    txtkhachhang.EditValue.ToString().ToUpper(),
                    txtloaica.EditValue.ToString().ToUpper(),
                    SL.ToString(),
                    Gia.ToString(),
                    Sot.ToString(),
                    Ket.ToString(),
                    txtthuonglai.Text,
                    txtkhachhang.Text,
                    txtloaica.Text,
                    Lu.ToString(),
                    Cat.ToString(),
                    Bom.ToString());
                txtkhachhang.Focus();
              
                if (this.Text == "+")
                    this.Text = "-";
                else
                    this.Text = "+";
                

                if (msgbox.dialog_yes_no("Đã lưu. \n \n Bạn muốn tiếp tục không ?") == DialogResult.Yes)
                {
                    txtkhachhang.Focus();                   
                }
                else
                {
                    this.Close();
                }

            }
            else
            {
                #region thong bao
                msgbox.dialog_OK_warning(ms);
                switch (thutu)
                {
                    case 1: txtthuonglai.Focus(); break;
                    case 2: txtkhachhang.Focus(); break;
                    case 3: txtloaica.Focus(); break;
                    case 4: txtsl.Focus(); break;
                    case 5: txtsl.Focus(); break;
                    case 6: txtgia.Focus(); break;
                    case 7: txtsot.Focus(); break;
                    case 8: txtket.Focus(); break;
                    case 9: txtLu.Focus(); break;
                    case 10: txtCat.Focus(); break;
                    case 11: txtBom.Focus(); break;
                }
                #endregion
            }

           
        }
        #endregion

        public void add_dulieu_chualuu(string txtthuonglai, string txtkhachhang, string txtloaica, string txtsl, string txtgia, string _sot, string _ket, string thuonglaiten, string khachhangten, string loaicaten,string _lu,string _cat,string _bom)
        {
            #region
            DataRow dtr = DuLieu.List_NhapSi_ChuaLuu.Tables[0].NewRow();
            dtr["ID"] = Guid.NewGuid().ToString().ToUpper();
            dtr["ID_NCC"] = txtthuonglai;
            dtr["ID_KhachHang"] = txtkhachhang;
            dtr["ID_Hang"] = txtloaica;
            dtr["SL"] = txtsl;
            dtr["Gia_1"] = txtgia;
            decimal thanhtien = decimal.Parse(txtsl) * decimal.Parse(txtgia);
            dtr["ThanhTien"] = thanhtien;
            dtr["Sot"] = _sot;
            dtr["Ket"] = _ket;
            dtr["Lu"] = _lu;
            dtr["Cat"] = _cat;
            dtr["Bom"] = _bom;

            dtr["Tbl_NCC_Name"] = thuonglaiten;
            dtr["Tbl_KhachHang_Name"] = khachhangten;
            dtr["Tbl_Hang_Name"] = loaicaten;
            dtr["STT_Them"] = (DuLieu.List_NhapSi_ChuaLuu.Tables[0].Rows.Count + 1 + DuLieu.List_NhapSi_DaLuu.Tables[0].Rows.Count).ToString();
            DuLieu.List_NhapSi_ChuaLuu.Tables[0].Rows.Add(dtr);
            // add to xml
            XmlDocument doc = new XmlDocument();
            doc.Load(NhapSi_Class._xmlfile);
            XmlNode root = doc.DocumentElement;
            //Create a new node.
            XmlElement elem = doc.CreateElement("Table");
            //add element
            XmlElement ID = doc.CreateElement("ID");
            XmlElement ID_Hang = doc.CreateElement("ID_Hang");
            XmlElement ID_KhachHang = doc.CreateElement("ID_KhachHang");
            XmlElement ID_NCC = doc.CreateElement("ID_NCC");
            XmlElement SL = doc.CreateElement("SL");
            XmlElement Gia_1 = doc.CreateElement("Gia_1");
            XmlElement Sot = doc.CreateElement("Sot");
            XmlElement Ket = doc.CreateElement("Ket");
            XmlElement Lu = doc.CreateElement("Lu");
            XmlElement Cat = doc.CreateElement("Cat");
            XmlElement Bom = doc.CreateElement("Bom");
            XmlElement ThanhTien = doc.CreateElement("ThanhTien");
            XmlElement Tbl_NCC_Name = doc.CreateElement("Tbl_NCC_Name");
            XmlElement Tbl_KhachHang_Name = doc.CreateElement("Tbl_KhachHang_Name");
            XmlElement Tbl_Hang_Name = doc.CreateElement("Tbl_Hang_Name");
            XmlElement STT_Them = doc.CreateElement("STT_Them");

          // add inner text
            ID.InnerText = dtr["ID"].ToString();
            ID_Hang.InnerText = dtr["ID_Hang"].ToString();
            ID_KhachHang.InnerText = dtr["ID_KhachHang"].ToString();
            ID_NCC.InnerText = dtr["ID_NCC"].ToString();
            SL.InnerText = dtr["SL"].ToString();
            Gia_1.InnerText = dtr["Gia_1"].ToString();
            Sot.InnerText = dtr["Sot"].ToString();
            Ket.InnerText = dtr["Ket"].ToString();
            Lu.InnerText = dtr["Lu"].ToString();
            Cat.InnerText = dtr["Cat"].ToString();
            Bom.InnerText = dtr["Bom"].ToString();
            ThanhTien.InnerText = dtr["ThanhTien"].ToString();
            Tbl_NCC_Name.InnerText = dtr["Tbl_NCC_Name"].ToString();
            Tbl_KhachHang_Name.InnerText = dtr["Tbl_KhachHang_Name"].ToString();
            Tbl_Hang_Name.InnerText = dtr["Tbl_Hang_Name"].ToString();
            STT_Them.InnerText = dtr["STT_Them"].ToString();
            // add to element
            elem.AppendChild(ID);
            elem.AppendChild(ID_Hang);
            elem.AppendChild(ID_KhachHang);
            elem.AppendChild(ID_NCC);
            elem.AppendChild(SL);
            elem.AppendChild(Gia_1);
            elem.AppendChild(Sot);
            elem.AppendChild(Ket);
            elem.AppendChild(Lu);
            elem.AppendChild(Cat);
            elem.AppendChild(Bom);
            elem.AppendChild(ThanhTien);
            elem.AppendChild(Tbl_NCC_Name);
            elem.AppendChild(Tbl_KhachHang_Name);
            elem.AppendChild(Tbl_Hang_Name);
            elem.AppendChild(STT_Them);

            root.AppendChild(elem);
            doc.Save(NhapSi_Class._xmlfile);
            #endregion
        }

        #region button event
        void simpleButton_ok_Click(object sender, EventArgs e)
        {
            save();
        }
        #endregion       

        #region phim tat 
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
         
            if (keyData == (Keys.F2))
            {
                save();
            }
           return base.ProcessCmdKey(ref msg, keyData);
        }
     
        #endregion

        #region event enter
        public void enter_lever_keypress()
        {
            txtthuonglai.Enter += new EventHandler(txtthuonglai_Enter);
            txtthuonglai.Leave += new EventHandler(txtthuonglai_Leave);
            txtthuonglai.KeyPress += new KeyPressEventHandler(txtthuonglai_KeyPress);

            txtkhachhang.Enter += new EventHandler(txtkhachhang_Enter);
            txtkhachhang.Leave += new EventHandler(txtkhachhang_Leave);
            txtkhachhang.KeyPress += new KeyPressEventHandler(txtkhachhang_KeyPress);

            txtloaica.Enter += new EventHandler(txtloaica_Enter);
            txtloaica.Leave += new EventHandler(txtloaica_Leave);
            txtloaica.KeyPress += new KeyPressEventHandler(txtloaica_KeyPress);

            txtsl.Enter += new EventHandler(txtsl_Enter);
            txtsl.Leave += new EventHandler(txtsl_Leave);
            txtsl.KeyPress += new KeyPressEventHandler(txtsl_KeyPress);

            txtgia.Enter += new EventHandler(txtgia_Enter);
            txtgia.Leave += new EventHandler(txtgia_Leave);
            txtgia.KeyPress += new KeyPressEventHandler(txtgia_KeyPress);

            txtsot.Enter += new EventHandler(txtsot_Enter);
            txtsot.Leave += new EventHandler(txtsot_Leave);
            txtsot.KeyPress += new KeyPressEventHandler(txtsot_KeyPress);

            txtket.Enter += new EventHandler(txtket_Enter);
            txtket.Leave += new EventHandler(txtket_Leave);
            txtket.KeyPress += new KeyPressEventHandler(txtket_KeyPress);

            txtLu.Enter += new EventHandler(txtLu_Enter);
            txtLu.Leave += new EventHandler(txtLu_Leave);
            txtLu.KeyPress += new KeyPressEventHandler(txtLu_KeyPress);

            txtCat.Enter += new EventHandler(txtCat_Enter);
            txtCat.Leave += new EventHandler(txtCat_Leave);
            txtCat.KeyPress += new KeyPressEventHandler(txtCat_KeyPress);

            txtBom.Enter += new EventHandler(txtBom_Enter);
            txtBom.Leave += new EventHandler(txtBom_Leave);
            txtBom.KeyPress += new KeyPressEventHandler(txtBom_KeyPress);
        }

        void txtket_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (e.KeyChar == 13)
                {
                    txtLu.Text = "";
                    txtLu.Focus();
                }
            }
        }

        void txtket_Leave(object sender, EventArgs e)
        {
            txtket.BackColor = Color.White;
        }

        void txtket_Enter(object sender, EventArgs e)
        {
            txtket.BackColor = Color.NavajoWhite;
        }
        void txtLu_Enter(object sender, EventArgs e)
        {
            txtLu.BackColor = Color.NavajoWhite;
        }
        void txtCat_Enter(object sender, EventArgs e)
        {
            txtCat.BackColor = Color.NavajoWhite;
        }
        void txtBom_Enter(object sender, EventArgs e)
        {
            txtBom.BackColor = Color.NavajoWhite;
        }
        void txtsot_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtket.Text = "";
                txtket.Focus();
            }
        }
        void txtLu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (e.KeyChar == 13)
                {
                    txtCat.Text = "";
                    txtCat.Focus();
                }
            }
        }
        void txtCat_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                if (e.KeyChar == 13)
                {
                    txtBom.Text = "";
                    txtBom.Focus();
                }
            }
        }
        void txtBom_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                save();
            }
        }
        void txtsot_Leave(object sender, EventArgs e)
        {
            txtsot.BackColor = Color.White;
        }
        void txtLu_Leave(object sender, EventArgs e)
        {
            txtLu.BackColor = Color.White;
        }
        void txtCat_Leave(object sender, EventArgs e)
        {
            txtCat.BackColor = Color.White;
        }
        void txtBom_Leave(object sender, EventArgs e)
        {
            txtBom.BackColor = Color.White;
        }
        void txtsot_Enter(object sender, EventArgs e)
        {
            txtsot.BackColor = Color.NavajoWhite;
        }

        void txtgia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtsot.Text = "";
                txtsot.Focus();
            }
        }
        void txtgia_Leave(object sender, EventArgs e)
        {
            txtgia.BackColor = Color.White;
        }
        void txtgia_Enter(object sender, EventArgs e)
        {
            txtgia.BackColor = Color.NavajoWhite;
        }

        void txtsl_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtgia.Text = "";
                txtgia.Focus();
            }
        }
        void txtsl_Leave(object sender, EventArgs e)
        {
            txtsl.BackColor = Color.White;
        }
        void txtsl_Enter(object sender, EventArgs e)
        {
            txtsl.BackColor = Color.NavajoWhite;
        }

        void txtloaica_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtsl.Text = "";
                txtsl.Focus();
            }
        }
        void txtloaica_Leave(object sender, EventArgs e)
        {
            txtloaica.BackColor = Color.White;
        }
        void txtloaica_Enter(object sender, EventArgs e)
        {
            txtloaica.BackColor = Color.NavajoWhite;
        }
        //private void txtkhachhang_EditValueChanged(object sender, EventArgs e)
        //{
        //    DevExpress.XtraEditors.LookUpEdit editor = sender as DevExpress.XtraEditors.LookUpEdit;
        //    object value = editor.GetColumnValue("_Text3");
        //    lblSoDienThoai.Text = value.ToString();
        //}
        private DataTable dtThongTinKetChuyen(string ID_KhachHang)
        {
            Class_KetNoi db = new Class_KetNoi();
            return db.T_opendataset("sp_CongNo_TheoID '" + ID_KhachHang+"'").Tables[0];

        }
        void txtkhachhang_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtloaica.Focus();
                #region hien cong no
                if (e.KeyChar == 13)
                {
                    if (txtkhachhang.EditValue != null && txtkhachhang.EditValue != "")
                    {
                        //DataTable dtKetChuyen = dtThongTinKetChuyen(txtkhachhang.EditValue.ToString().Trim());
                        double soTien = 0;
                      //  if (dtKetChuyen.Rows.Count > 0)
                        //    soTien = double.Parse("0" + dtKetChuyen.Rows[0]["ChotTien"].ToString());
                        //
                        DevExpress.XtraEditors.LookUpEdit editor = sender as DevExpress.XtraEditors.LookUpEdit;
                        object value = editor.GetColumnValue("_Text3");
                        lblSoDienThoai.Text = value.ToString();
                       // txttien.Focus();
                        //load no
                        DataRow[] dr = DuLieu.CongNo_1Ngay.Tables[0].Select("ID_KhachHang = '" + txtkhachhang.EditValue.ToString().ToUpper() + "'");
                        if (dr.Length > 0)
                        {
                            
                            double nocus =(dr[0]["NoCu"].ToString()=="")?0: double.Parse(dr[0]["NoCu"].ToString());
                            nocus += soTien;
                            double nomois =(dr[0]["NoMoi"].ToString()=="")?0: double.Parse(dr[0]["NoMoi"].ToString());
                            double tongnos =(dr[0]["TongNo"].ToString()=="")?0: double.Parse(dr[0]["TongNo"].ToString());
                            tongnos += soTien;
                            lblNoCu.Text = String.Format("{0:#,#}", nocus) + " (vnđ)";

                            lblNoMoi.Text = String.Format("{0:#,#}", nomois) + " (vnđ)";
                            lblTongNo.Text = String.Format("{0:#,#}", tongnos) + " (vnđ)";
                        }
                        else
                        {
                            lblNoCu.Text = String.Format("{0:#,#}", soTien) + " (vnđ)";

                            lblNoMoi.Text = String.Format("{0:#,#}", 0) + " (vnđ)";
                            lblTongNo.Text = String.Format("{0:#,#}", soTien) + " (vnđ)";
                        }
                    }
                    else
                    {
                        msgbox.dialog_OK_warning("Vui lòng chọn khách hàng");
                    }
                }
                else
                {
                    if (e.KeyChar == 27)
                    {
                        //txttien.Focus();
                        txtkhachhang.EditValue = null;
                        txtkhachhang.Text = "";
                        txtkhachhang.ClosePopup();
                        lblSoDienThoai.Text = "";
                    }
                }
                #endregion
            }
        }
        void txtkhachhang_Leave(object sender, EventArgs e)
        {
            txtkhachhang.BackColor = Color.White;
        }
        void txtkhachhang_Enter(object sender, EventArgs e)
        {
            txtkhachhang.BackColor = Color.NavajoWhite;
        }

        void txtthuonglai_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtkhachhang.Focus();
            }
        }
        void txtthuonglai_Leave(object sender, EventArgs e)
        {
            txtthuonglai.BackColor = Color.White;
        }
        void txtthuonglai_Enter(object sender, EventArgs e)
        {
            txtthuonglai.BackColor = Color.NavajoWhite;
        }
        #endregion

        #region load
        private void NhapSi_New_Load(object sender, EventArgs e)
        {
            //dtpNgay.DateTime = DateTime.Now;
        }
        #endregion

        private void txtkhachhang_EditValueChanged(object sender, EventArgs e)
        {
            if (txtkhachhang.EditValue != null && txtkhachhang.EditValue != "")
            {
                DevExpress.XtraEditors.LookUpEdit editor = sender as DevExpress.XtraEditors.LookUpEdit;
                object value = editor.GetColumnValue("_Text3");
                lblSoDienThoai.Text = value.ToString();
                // txttien.Focus();
                //load no
                DataRow[] dr = DuLieu.CongNo_1Ngay.Tables[0].Select("ID_KhachHang = '" + txtkhachhang.EditValue.ToString().ToUpper() + "'");
                if (dr.Length > 0)
                {
                    double nocus =(dr[0]["NoCu"].ToString()=="")?0: double.Parse(dr[0]["NoCu"].ToString());
                    double nomois =(dr[0]["NoMoi"].ToString()=="")?0: double.Parse(dr[0]["NoMoi"].ToString());
                    double tongnos =(dr[0]["TongNo"].ToString()=="")?0: double.Parse(dr[0]["TongNo"].ToString());

                    lblNoCu.Text = String.Format("{0:#,#}", nocus) + " (vnđ)";

                    lblNoMoi.Text = String.Format("{0:#,#}", nomois) + " (vnđ)";
                    lblTongNo.Text = String.Format("{0:#,#}", tongnos) + " (vnđ)";
                }
                else
                {
                    lblNoCu.Text = String.Format("{0:#,#}", 0) + " (vnđ)";

                    lblNoMoi.Text = String.Format("{0:#,#}", 0) + " (vnđ)";
                    lblTongNo.Text = String.Format("{0:#,#}", 0) + " (vnđ)";
                }
            }
            else
            {
                msgbox.dialog_OK_warning("Vui lòng chọn khách hàng");
            }
        }

        private void panelControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void labelControl4_Click(object sender, EventArgs e)
        {

        }
    }
}
