using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Xml;
using System.IO;
using ABC.DanhMuc.NhanVien;
using System.Data;
namespace ABC.NhanVien
{
    
    public partial class NhanVien_PhanQuyen_Forms : DevExpress.XtraEditors.XtraUserControl {
        public NhanVien_PhanQuyen_Forms()
        {           
            InitializeComponent();
           // this.Text = "Danh mục nhân viên";
           // event_click();
            data();
            gv.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gv_CellValueChanged);
            repositoryItemHyperLinkEdit_xem.Click += new EventHandler(repositoryItemHyperLinkEdit_xem_Click);
        }

        #region xem click
        DataRow dtr_nv;
        void repositoryItemHyperLinkEdit_xem_Click(object sender, EventArgs e)
        {
            dtr_nv = gv1.GetDataRow(gv1.FocusedRowHandle);
            Load_list(dtr_nv["ID"].ToString());

        }
        Class_PhanQuyen _Class_PhanQuyen = new Class_PhanQuyen();
        public void Load_list(string id)
        {

            _Class_PhanQuyen.load_data(id);
            gc.DataSource = Class_PhanQuyen.List.Tables[0];

        }
        #endregion

        #region gv_value_changed
        void gv_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DataRow dtr = gv.GetDataRow(gv.FocusedRowHandle);
            string col = e.Column.FieldName.ToString();
            switch (col)
            {
                case "Them":
                    {
                        if (bool.Parse(dtr[col].ToString()) == true)
                        {
                            string sql = "Insert Tbl_pow (ID,Ten_Form,Ten_Fun) values('" + dtr_nv["ID"].ToString() + "','" + dtr["Ten"].ToString() + "','Them')";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        else
                        {
                            string sql = "delete from Tbl_pow where ID = '" + dtr_nv["ID"].ToString() + "' AND Ten_Form ='" + dtr["Ten"].ToString() + "' and Ten_Fun = 'Them'";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        break;
                    }
                case "Sua":
                    {
                        if (bool.Parse(dtr[col].ToString()) == true)
                        {
                            string sql = "Insert Tbl_pow (ID,Ten_Form,Ten_Fun) values('" + dtr_nv["ID"].ToString() + "','" + dtr["Ten"].ToString() + "','Sua')";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        else
                        {
                            string sql = "delete from Tbl_pow where ID = '" + dtr_nv["ID"].ToString() + "' AND Ten_Form ='" + dtr["Ten"].ToString() + "' and Ten_Fun = 'Sua'";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        break;
                    }
                case "Xoa":
                    {
                        if (bool.Parse(dtr[col].ToString()) == true)
                        {
                            string sql = "Insert Tbl_pow (ID,Ten_Form,Ten_Fun) values('" + dtr_nv["ID"].ToString() + "','" + dtr["Ten"].ToString() + "','Xoa')";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        else
                        {
                            string sql = "delete from Tbl_pow where ID = '" + dtr_nv["ID"].ToString() + "' AND Ten_Form ='" + dtr["Ten"].ToString() + "' and Ten_Fun = 'Xoa'";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        break;
                    }
                case "Xem":
                    {
                        if (bool.Parse(dtr[col].ToString()) == true)
                        {
                            string sql = "Insert Tbl_pow (ID,Ten_Form,Ten_Fun) values('" + dtr_nv["ID"].ToString() + "','" + dtr["Ten"].ToString() + "','Xem')";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        else
                        {
                            string sql = "delete from Tbl_pow where ID = '" + dtr_nv["ID"].ToString() + "' AND Ten_Form ='" + dtr["Ten"].ToString() + "' and Ten_Fun = 'Xem'";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        break;
                    }
                case "Inan":
                    {
                        if (bool.Parse(dtr[col].ToString()) == true)
                        {
                            string sql = "Insert Tbl_pow (ID,Ten_Form,Ten_Fun) values('" + dtr_nv["ID"].ToString() + "','" + dtr["Ten"].ToString() + "','Inan')";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        else
                        {
                            string sql = "delete from Tbl_pow where ID = '" + dtr_nv["ID"].ToString() + "' AND Ten_Form ='" + dtr["Ten"].ToString() + "' and Ten_Fun = 'Inan'";
                            _Class_PhanQuyen.Insert(sql);
                        }
                        break;
                    }
            }

        }
        public void save()
        {
            #region
        
                //string sql = "Tbl_NhanVien_insert ";
                //sql += "N'" + Guid.NewGuid().ToString().ToUpper() + "',";
                //sql += "N'" + txtName.Text + "',";
                //sql += "N'" + Note.Text + "',";

                //sql += "N'" + Get_CauHinh.Ngay_DN + "',";
                //sql += "N'" + Get_CauHinh.Dt_Login.Rows[0]["ID"].ToString().ToUpper() + "',";
                //sql += "N'1',";

                //sql += "N'" + _Text1.Text + "',";
                //sql += "N'" + _Text2.Text + "',";
                //sql += "N'',";
                //sql += "N'',";
                //sql += "N'',";
                //sql += "N'',";
                //sql += "N'',";
                //sql += "N'" + _Text8.Text + "',";
                //sql += "N'" + T_IO.mahoachuoi(_Text9.Text) + "',";

                //sql += "NULL,";
                //sql += "NULL,";
                //sql += "NULL,";

                //sql += "NULL,";
                //sql += "NULL,";
                //sql += "NULL";

                //_NhanVien_Class.set(sql);
           



           
            #endregion
        }
        #endregion

        #region lệnh dùng chung
        //NhanVien_Form _NhanVien_Form;
        public void them()
        {
            //_NhanVien_Form = new NhanVien_Form();
            //_NhanVien_Form.TextChanged += new EventHandler(_NhanVien_Form_TextChanged);
            //_NhanVien_Form.ShowDialog();
        } 
        void _NhanVien_Form_TextChanged(object sender, EventArgs e)
        {
            data();
            gv.RefreshData();

        }
        public void excel()
        {
        }
        public void xoa()
        {
            //if (msgbox.dialog_yes_no("Xóa dòng chọn?") == DialogResult.Yes)
            //{
            //    DataRow []dr = NhanVien_Class.List.Tables[0].Select("Select = "+true+"");
            //    for(int i=0;i<dr.Length;i++)
            //    {
            //            string sql = "Delete from Tbl_NhanVien where ID = '"+dr[i]["ID"].ToString().ToUpper()+"'";
            //            _NhanVien_Class.set(sql);

            //    }
            //    data();

            //}
        }
        public void sua()
        {
        }       
        public void chon()
        {
        }
        public void bochon()
        {
        }
        public void chep()
        {
        }
        #endregion

        #region menu click
        public void event_click()
        {
            btn_new.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btn_new_ItemClick);
            btn_excel.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btn_excel_ItemClick);
            btn_del.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btn_del_ItemClick);
            btn_all.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btn_all_ItemClick);
            btn_none.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btn_none_ItemClick);
            btn_copy.ItemClick += new DevExpress.XtraBars.ItemClickEventHandler(btn_copy_ItemClick);
        }

        void btn_copy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            chep();
        }

        void btn_none_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            bochon();
        }

        void btn_all_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            chon();
        }

        void btn_del_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xoa();
        }

        void btn_excel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            excel();
        }

        void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            them();
        }





  

     


  

        #endregion

        #region data
        NhanVien_Class _NhanVien_Class = new NhanVien_Class();
        public void data()
        {
           // _NhanVien_Class.get("Select * from Tbl_NhanVien where ID <> '03E6200D-5CC8-4329-97A1-35A9B2E25863'");
            gc1.DataSource = DuLieu.List_NhanVien.Tables[0];
            gv1.ExpandAllGroups();
        }
        #endregion

        private void NhanVien_Forms_Load(object sender, EventArgs e)
        {
            //if (this.FormBorderStyle != FormBorderStyle.None)
            //{
            //    bar4.Visible = true;
                
            //}
            //else
            //{
            //    bar4.Visible = false;
            //}
        }

     

    }
}
