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;

namespace ABC.BanLe
{
    public partial class CaSetup : Form
    {
        public string thuonglai_id,ThuongLai_name;
        public CaSetup()
        {
            InitializeComponent();
            //load combo
            load_combo();
            //load list ncc da co 
            this.Load += new EventHandler(Setup_Load);
            simpleButton1.Click += new EventHandler(simpleButton1_Click);
            link_xoalai.Click += new EventHandler(link_xoalai_Click);
            gv_thuonglai.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gv_thuonglai_CellValueChanged);
        }

        

        void gv_thuonglai_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (e.Column.FieldName == "Note")
            {
                DataRow dr = gv_thuonglai.GetDataRow(gv_thuonglai.FocusedRowHandle);
                _NhapLe_Class.set_stt(dr["NCC_ID"].ToString(), dr["Hang_ID"].ToString(), e.Value.ToString());
            }
        }

        void link_xoalai_Click(object sender, EventArgs e)
        {
            if (msgbox.dialog_yes_no("Xóa ?") == DialogResult.Yes)
            {
                DataRow dtr = gv_thuonglai.GetDataRow(gv_thuonglai.FocusedRowHandle);
                _NhapLe_Class.set("delete from BanLe where NCC_ID = '" + thuonglai_id.ToUpper() + "' and Hang_ID = '" + dtr["Hang_ID"].ToString().ToUpper() + "'");
                _NhapLe_Class.get_ca_store("sp_NhapLe_Ca_Load");
                //
                string ndCu = "Xoá BanLe NCC="+ thuonglai_id.ToUpper()+"- Hang_ID = " + dtr["Hang_ID"].ToString().ToUpper();
                DuLieu.LuuLuocSu(Main_Form._tk, this.Name, ndCu, "", "Xoá");
                filter_theonhom();
            }
        }

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

        void Setup_Load(object sender, EventArgs e)
        {
            this.Text = ThuongLai_name;
            filter_theonhom();
        }

        #region load-add ncc
        public void load_combo()
        {
            txtthuonglai.Properties.DataSource = DuLieu.List_Hang.Tables[0];
            txtthuonglai.KeyPress += new KeyPressEventHandler(txtthuonglai_KeyPress);
            txtthuonglai.Enter += new EventHandler(txtthuonglai_Enter);
            txtthuonglai.Leave += new EventHandler(txtthuonglai_Leave);
        }

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

        void txtthuonglai_Enter(object sender, EventArgs e)
        {
            txtthuonglai.BackColor = Color.NavajoWhite;
        }

        void txtthuonglai_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                add_ncc();
            }
            else
            {
            }
        }
        NhapLe_Class _NhapLe_Class = new NhapLe_Class();
        public void add_ncc()
        {
            if (txtthuonglai.EditValue != null && txtthuonglai.EditValue != "")
            {
                if (_NhapLe_Class.them_ca(txtthuonglai.EditValue.ToString().ToUpper(),thuonglai_id,ThuongLai_name) == true)
                {
                    _NhapLe_Class.get_ca_store("sp_NhapLe_Ca_Load");
                    filter_theonhom();
                }

            }
            
            
        }
        #endregion

        #region load grid
        DataView dtv_loaica;
        public void filter_theonhom()
        {
            dtv_loaica = new DataView(DuLieu.NhapLe_List_Ca.Tables[0]);
            dtv_loaica.RowFilter = "NCC_ID = '" + thuonglai_id + "'";
            gc_thuonglai.DataSource = dtv_loaica;
           
           // clum_tenca.Caption = "Cá của Lái :" + select_thuonglai_name;
         
        }
        #endregion
    }
}
// thử nhap code trên casetup