private static void CreateItemOnDMTreeGroup(DMTreeGroup control)
        {
            string TableName = "";
            DataTable dt = control.TreeList_1.DataSource as DataTable;
            if (dt != null)
            {
                TableName = dt.TableName;

            }
            else return;
            IPermissionData perRes = FrameworkParams.iPermissionData;
            DataPermission[] tainguyenLst = perRes.getObjectResources();
            if (tainguyenLst == null) return;
            bool Is_Group = false;
            DataPermission DataPer = null;
            foreach (DataPermission data in tainguyenLst)
            {
                if (data.DMTableName_Res == TableName)
                {
                    DataPer = data;
                    Is_Group = false;
                }
                else if (data.DMTableName_ResGroup == TableName)
                {
                    DataPer = data;
                    Is_Group = true;
                    break;
                }
            }
            if (DataPer == null) return;
            DataPer.Init();
            ToolStripButton btnPhanQuyen = new ToolStripButton("Phân quyền", HelpImage.getImage2020("mnbPhieuPhanHoiKH.png"));
            int index = control.btnAdd.Owner.Items.IndexOf(control.btnKhongLuu);
            control.btnAdd.Owner.Items.Insert(index + 2, btnPhanQuyen);
            control.btnAdd.Owner.Items.Insert(index + 3, (new ToolStripSeparator()));
            btnPhanQuyen.Click += delegate(object sender, EventArgs e)
            {
                TreeListNode focusNode = control.TreeList_1.FocusedNode;
                if (focusNode == null && control.TreeList_1.Selection.Count > 0)
                {
                    focusNode = control.TreeList_1.Selection[0];
                }
                if (focusNode == null)
                {
                    HelpMsgBox.ShowNotificationMessage("Bạn chưa chọn dữ liệu. Vui lòng chọn dữ liệu để phân quyền!");
                    return;
                }
                DOResource resource = null;
                if (Is_Group)
                {
                    resource = new DOResource(-1, HelpNumber.ParseInt64(focusNode[control.TreeList_1.KeyFieldName]), -1, null);

                }
                else
                {
                    resource = new DOResource(
                        HelpNumber.ParseInt64(focusNode[control.TreeList_1.KeyFieldName]),
                      dt.Columns.Contains(DataPer.RefFieldNameDM_Res_ResGroup) ?
                       HelpNumber.ParseInt64(focusNode[DataPer.RefFieldNameDM_Res_ResGroup]) : -1,
                       -1, null);
                }

                frmPermissionDataPopUp frm = new frmPermissionDataPopUp(DataPer, resource);
                HelpProtocolForm.ShowModalDialog(ProtocolVN.Framework.Win.FrameworkParams.MainForm, frm);

            };
            if (DataPer.IsPermission == false) return;
            bool AddPermis = control.btnAdd.Visible;
            bool UpdatePermis = control.btnUpdate.Visible;
            bool DeletePermis = control.btnDel.Visible;
            TreeListNode n = control.TreeList_1.FocusedNode;
            if (n != null)
            {
                ApplyPermissionOnDMTreeGroup(control,
                                   Is_Group, AddPermis,
                                   UpdatePermis, DeletePermis,
                                   DataPer, HelpNumber.ParseInt64(n[control.TreeList_1.KeyFieldName]),
                                   HelpNumber.ParseInt64(n[control.TreeList_1.ParentFieldName]));
            }

            control.TreeList_1.FocusedNodeChanged += delegate(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
            {
                TreeListNode node = e.Node;
                if (node == null) return;
                long ID = HelpNumber.ParseInt64(node[control.TreeList_1.KeyFieldName]);
                long ParentID = HelpNumber.ParseInt64(node[control.TreeList_1.ParentFieldName]);
                ApplyPermissionOnDMTreeGroup(control,
                    Is_Group, AddPermis,
                    UpdatePermis, DeletePermis,
                    DataPer, ID, ParentID);
            };
            control._AfterSaveSuccEvent += delegate(DMTreeGroup sender)
            {
                TreeListNode fNode = sender.TreeList_1.FocusedNode;
                if (fNode == null) return;
                DataPer.InsertPermis(HelpNumber.ParseInt64(fNode["ID"]), Is_Group, -1,
                     ProtocolVN.Framework.Win.FrameworkParams.currentUser.employee_id, true, Is_Group || DataPer.Is_ResUseCreate, true, true);

            };
            long deleteID = -1;
            control._BeforeDelEvent += delegate(DMTreeGroup sender)
            {

                if (sender.TreeList_1.FocusedNode!=null)
                {
                    deleteID = HelpNumber.ParseInt64(sender.TreeList_1.FocusedNode["ID"]);
                }

            };
            control._AfterDelSuccEvent += delegate(DMTreeGroup sender)
            {
                if (deleteID != -1)
                {
                    DataPer.DeletePermis(deleteID, Is_Group);
                    deleteID = -1;
                }
            };
        }
        private static void CreateItemOnDMTreeGroupElement(DMTreeGroupElement control)
        {
            string TableName = "";
            DataTable dt = control.gridView_1.GridControl.DataSource as DataTable;
            if (dt != null)
            {
                TableName = dt.TableName;

            }
            else return;
            IPermissionData perRes = FrameworkParams.iPermissionData;
            DataPermission[] tainguyenLst = perRes.getObjectResources();
            if (tainguyenLst == null) return;
            bool Is_Group = false;
            DataPermission DataPer = null;
            foreach (DataPermission data in tainguyenLst)
            {
                if (data.DMTableName_Res == TableName)
                {
                    DataPer = data;
                    Is_Group = false;
                }
                else if (data.DMTableName_ResGroup == TableName)
                {
                    DataPer = data;
                    Is_Group = true;
                    break;
                }
            }
            if (DataPer == null) return;
            DataPer.Init();

            ToolStripButton btnPhanQuyen = new ToolStripButton("Phân quyền", HelpImage.getImage2020("mnbPhieuPhanHoiKH.png"));
            control.btnAdd.Owner.Items.Add(btnPhanQuyen);
            control.btnAdd.Owner.Items.Add(new ToolStripSeparator());
            btnPhanQuyen.Click += delegate(object sender, EventArgs e)
            {
                int rowHandle = control.gridView_1.FocusedRowHandle;
                if (rowHandle < 0 && control.gridView_1.SelectedRowsCount > 0)
                {
                    rowHandle = control.gridView_1.GetSelectedRows()[0];
                }

                DataRow focusRow = control.gridView_1.GetDataRow(rowHandle);
                if (control.gridView_1.IsDataRow(rowHandle) == false || focusRow == null)
                {
                    HelpMsgBox.ShowNotificationMessage("Bạn chưa chọn dữ liệu. Vui lòng chọn dữ liệu để phân quyền!");
                    return;
                }
                DOResource resource = null;
                if (Is_Group)
                {
                    resource = new DOResource(-1, HelpNumber.ParseInt64(focusRow["ID"]), -1, null);
                }
                else
                {
                    resource = new DOResource(
                        HelpNumber.ParseInt64(focusRow["ID"]),
                      dt.Columns.Contains(DataPer.RefFieldNameDM_Res_ResGroup) ?
                       HelpNumber.ParseInt64(focusRow[DataPer.RefFieldNameDM_Res_ResGroup]) : -1,
                       -1, null);
                }

                frmPermissionDataPopUp frm = new frmPermissionDataPopUp(DataPer, resource);
                HelpProtocolForm.ShowModalDialog(ProtocolVN.Framework.Win.FrameworkParams.MainForm, frm);

            };
            if (DataPer.IsPermission == false) return;

            bool AddPermis = control.btnAdd.Visible;
            bool UpdatePermis = control.btnUpdate.Visible;
            bool DeletePermis = control.btnDel.Visible;

            TreeListNode n = control.TreeList_1.FocusedNode;
            long fParentID = -2;

            if (n != null)
            {
                fParentID = HelpNumber.ParseInt64(n["ID"]);
            }

            DataRow r = control.gridView_1.GetFocusedDataRow();
            long fID = -2;
            if (r != null)
            {
                fID = HelpNumber.ParseInt64(r["ID"]);
            }
            ApplyPermissionOnDMTreeGroupElement(control, Is_Group, AddPermis, UpdatePermis, DeletePermis, DataPer, fID, fParentID, false);

            control.gridView_1.FocusedRowChanged += delegate(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
            {
                DataRow row = control.gridView_1.GetDataRow(e.FocusedRowHandle);
                if (row == null) return;
                long ID = HelpNumber.ParseInt64(row["ID"]);
                TreeListNode node = control.TreeList_1.FocusedNode;
                long ParentID = -2;
                if (node != null)
                {
                    ParentID = HelpNumber.ParseInt64(node["ID"]);
                }
                ApplyPermissionOnDMTreeGroupElement(control, Is_Group, AddPermis, UpdatePermis, DeletePermis, DataPer, ID, ParentID, true);
            };
            control.TreeList_1.FocusedNodeChanged += delegate(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
            {
                TreeListNode node = e.Node;
                if (node == null) return;
                long ParentID = HelpNumber.ParseInt64(node["ID"]);

                DataRow row = control.gridView_1.GetFocusedDataRow();
                long ID = -2;
                if (row != null)
                {
                    ID = HelpNumber.ParseInt64(row["ID"]);
                }
                ApplyPermissionOnDMTreeGroupElement(control, Is_Group, AddPermis, UpdatePermis, DeletePermis, DataPer, ID, ParentID, false);
            };

            control.gridView_1.RowUpdated += delegate(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
            {
                if (e.Row == null) return;
                DataRow dr = ((DataRowView)e.Row).Row;
                DataPer.InsertPermis(HelpNumber.ParseInt64(dr["ID"]), Is_Group, -1,
                     ProtocolVN.Framework.Win.FrameworkParams.currentUser.employee_id, true, true, true, true);

            };
            long deleteID = -1;
            control._BeforeDelEvent += delegate(DMTreeGroupElement sender)
            {
                int[] selectedRows = sender.gridView_1.GetSelectedRows();
                if (selectedRows != null && selectedRows.Length > 0)
                {
                    DataRow dlr = sender.gridView_1.GetDataRow(selectedRows[0]);
                    if (dlr != null) deleteID = HelpNumber.ParseInt64(dlr["ID"]);
                }

            };
            control._AfterDelSuccEvent += delegate(DMTreeGroupElement sender)
            {
                if (deleteID != -1)
                {
                    DataPer.DeletePermis(deleteID, Is_Group);
                    deleteID = -1;
                }
            };
        }
        private static void CreateItemOnDMGrid(DMGrid control)
        {
            string TableName = "";
            DataTable dt = control.Grid.GridControl.DataSource as DataTable;
            if (dt != null) TableName = dt.TableName;
            else return;
            IPermissionData perRes = FrameworkParams.iPermissionData;
            DataPermission[] tainguyenLst = perRes.getObjectResources();
            if (tainguyenLst == null) return;
            bool Is_Group = false;
            DataPermission DataPer = null;
            foreach (DataPermission data in tainguyenLst)
            {
                if (data.DMTableName_Res == TableName)
                {
                    DataPer = data;
                    Is_Group = false;
                }
                else if (data.DMTableName_ResGroup == TableName)
                {
                    DataPer = data;
                    Is_Group = true;
                    break;
                }
            }
            if (DataPer == null) return;
            DataPer.Init();
            ToolStripButton btnPhanQuyen = new ToolStripButton("Phân quyền", HelpImage.getImage2020("mnbPhieuPhanHoiKH.png"));
            control.btnAdd.Owner.Items.Add(btnPhanQuyen);
            control.btnAdd.Owner.Items.Add(new ToolStripSeparator());
            btnPhanQuyen.Click += delegate(object sender, EventArgs e)
            {
                int rowHandle = control.Grid.FocusedRowHandle;
                if (rowHandle < 0 && control.Grid.SelectedRowsCount > 0)
                {
                    rowHandle = control.Grid.GetSelectedRows()[0];
                }

                DataRow focusRow = control.Grid.GetDataRow(rowHandle);
                if (control.Grid.IsDataRow(rowHandle) == false || focusRow == null)
                {
                    HelpMsgBox.ShowNotificationMessage("Bạn chưa chọn dữ liệu. Vui lòng chọn dữ liệu để phân quyền!");
                    return;
                }
                DOResource resource = null;
                if (Is_Group)
                {
                    resource = new DOResource(-1, HelpNumber.ParseInt64(focusRow["ID"]), -1, null);

                }
                else
                {
                    resource = new DOResource(
                        HelpNumber.ParseInt64(focusRow["ID"]),
                      dt.Columns.Contains(DataPer.RefFieldNameDM_Res_ResGroup) ?
                       HelpNumber.ParseInt64(focusRow[DataPer.RefFieldNameDM_Res_ResGroup]) : -1,
                       -1, null);
                }

                frmPermissionDataPopUp frm = new frmPermissionDataPopUp(DataPer, resource);
                HelpProtocolForm.ShowModalDialog(ProtocolVN.Framework.Win.FrameworkParams.MainForm, frm);

            };
            if (DataPer.IsPermission == false) return;

            bool UpdatePermis = control.btnUpdate.Visible;
            bool DeletePermis = control.btnDel.Visible;

            DataRow r = control.Grid.GetFocusedDataRow();
            if (r != null)
            {
                ApplyPermissionOnDMGrid(control, Is_Group,
                        UpdatePermis, DeletePermis, DataPer, HelpNumber.ParseInt64(r["ID"]));
            }
            control.Grid.FocusedRowChanged += delegate(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
            {
                DevExpress.XtraGrid.Views.Grid.GridView grid = sender as DevExpress.XtraGrid.Views.Grid.GridView;
                DataRow row = grid.GetDataRow(e.FocusedRowHandle);
                if (row != null)
                {
                    ApplyPermissionOnDMGrid(control, Is_Group,
                        UpdatePermis, DeletePermis, DataPer, HelpNumber.ParseInt64(row["ID"]));
                }

            };
            control._DMCore._AfterSaveSuccEvent += delegate(DMBasicGrid sender)
            {
                DataTable dtSource = sender.Grid.GridControl.DataSource as DataTable;
                DataRow[] rows = dtSource.Select("", "", DataViewRowState.Added);
                if (rows.Length > 0)
                {
                    DataRow rr = rows[0];
                    DataPer.InsertPermis(HelpNumber.ParseInt64(rr["ID"]), Is_Group, -1,
                         ProtocolVN.Framework.Win.FrameworkParams.currentUser.employee_id, true, true, true, true);

                    rr.AcceptChanges();
                }
            };
            long deleteID = -1;
            control._DMCore._BeforeDelEvent += delegate(DMBasicGrid sender)
            {

                DataRow dlr = sender.Grid.GetFocusedDataRow();
                if (dlr != null) deleteID = HelpNumber.ParseInt64(dlr["ID"]);

            };
            control._DMCore._AfterDelSuccEvent += delegate(DMBasicGrid sender)
            {
                if (deleteID != -1)
                {
                    DataPer.DeletePermis(deleteID, Is_Group);
                    deleteID = -1;
                }
            };
        }