예제 #1
0
        private static void SetTsbState(IButton tsb, IControlManager cm)
        {
            // first set enable according state
            string state = cm.State.ToString();

            object entity = cm.DisplayManager.CurrentItem;

            WindowMenuInfo info = tsb.Tag as WindowMenuInfo;

            tsb.Visible = Permission.AuthorizeByRule(info.Visible, entity);
            //if (!tsb.Visible)
            //    continue;

            bool enable = true;

            if (!string.IsNullOrEmpty(info.EnableState))
            {
                enable = info.EnableState.Contains(state);
            }
            if (enable)
            {
                enable = Permission.AuthorizeByRule(info.Enable, entity);
            }
            tsb.Enabled = enable;
        }
        void MasterGrid_CurrentRowChanged(object sender, EventArgs e)
        {
            var    currentRow   = m_parentForm.MasterGrid.CurrentRow;
            string currentLevel = currentRow == null ? null : Feng.Grid.MyGrid.GetGridLevel(currentRow.ParentGrid);

            object entity = currentRow == null ? null : m_parentForm.MasterGrid.CurrentRow.Tag;

            foreach (SmartItem item in m_items1)
            {
                GridRelatedInfo info = item.Tag as GridRelatedInfo;
                if (info.RelatedType == GridRelatedType.ByRows)
                {
                    if (entity == null || (!string.IsNullOrEmpty(info.GridLevel) && info.GridLevel != currentLevel))  // Feng.Utils.ReflectionHelper.GetTypeFromName(info.EntityType) != entity.GetType())
                    {
                        item.Visible = false;
                    }
                    else
                    {
                        item.Visible = Permission.AuthorizeByRule(info.Visible, entity);
                    }
                }
            }
            //foreach (SmartItem item in m_items2)
            //{
            //    GridRelatedInfo info = item.Tag as GridRelatedInfo;
            //    if (entity == null || Feng.Utils.ReflectionHelper.GetTypeFromName(info.EntityType) != entity.GetType())
            //    {
            //        item.Visible = false;
            //    }
            //    else
            //    {
            //        item.Visible = Permission.AuthorizeByRule(info.Visible, entity);
            //    }
            //}
        }
        private bool DeleteByRow(Xceed.Grid.DataRow row)
        {
            GridHelper.EndEditRow(row);

            bool rowAllowDelete = m_grid.AllowInnerDelete &&
                                  m_cm.AllowDelete && Permission.AuthorizeByRule(ADInfoBll.Instance.GetGridRowInfo(m_grid.GridName).AllowDelete, row.Tag);

            if (rowAllowDelete)
            {
                m_cm.DisplayManager.Position = row.Index;
                return(m_cm.DeleteCurrent());
            }
            return(false);
        }
예제 #4
0
        internal static void SetGridRowCellPermissions(this IBoundGrid grid, Xceed.Grid.DataRow row)
        {
            GridRowInfo info   = ADInfoBll.Instance.GetGridRowInfo(grid.GridName);
            object      entity = row.Tag;

            if (grid.ReadOnly)
            {
                return;
            }

            // Only set when readOnly(如果ReadOnly=false,则不设置,继承Parent's ReadOnly)
            bool readOnly = Feng.Permission.AuthorizeByRule(info.ReadOnly, entity);

            if (readOnly)
            {
                row.ReadOnly = readOnly;
            }
            if (row.ReadOnly)
            {
                return;
            }

            foreach (GridCellInfo cellInfo in ADInfoBll.Instance.GetGridCellInfos(grid.GridName))
            {
                Xceed.Grid.Cell cell = row.Cells[cellInfo.GridColumName];
                if (cell == null)
                {
                    continue;
                }

                if (cell.ParentGrid.ReadOnly)
                {
                    continue;
                }
                if (cell.ParentColumn.ReadOnly)
                {
                    continue;
                }
                if (cell.ParentRow.ReadOnly)
                {
                    continue;
                }

                readOnly = Permission.AuthorizeByRule(cellInfo.ReadOnly, entity);
                if (readOnly)
                {
                    cell.ReadOnly = readOnly;
                }
            }
        }
예제 #5
0
        internal static void SetGridRowVisible(this IBoundGrid grid, Xceed.Grid.DataRow row)
        {
            GridRowInfo info   = ADInfoBll.Instance.GetGridRowInfo(grid.GridName);
            object      entity = row.Tag;

            bool visible = Permission.AuthorizeByRule(info.Visible, entity);

            row.Visible = visible;
            if (!row.Visible)
            {
                grid.DataRows.Remove(row);
                return;
            }
        }
예제 #6
0
        void GridGotoDetailFormToolStripItem_DropDownOpened(object sender, EventArgs e)
        {
            IDisplayManagerContainer parentForm = this.Parent.FindForm() as IDisplayManagerContainer;

            if (parentForm != null)
            {
                object entity = parentForm.DisplayManager.Position == -1 ? null : parentForm.DisplayManager.CurrentItem;

                foreach (ToolStripItem item in this.DropDownItems)
                {
                    GridRelatedInfo info = item.Tag as GridRelatedInfo;
                    item.Visible = Permission.AuthorizeByRule(info.Visible, entity);
                }
            }
        }
예제 #7
0
        public static bool DoEditS(IControlManager cm, string gridName)
        {
            var info = ADInfoBll.Instance.GetGridRowInfo(gridName);

            if (info != null && !string.IsNullOrEmpty(info.AllowEdit) &&
                !Permission.AuthorizeByRule(info.AllowEdit, cm.DisplayManager.CurrentItem))
            {
                MessageForm.ShowError("您没有修改此记录的权限!");
                return(false);
            }

            cm.EditCurrent();

            return(true);
        }
예제 #8
0
        public static bool DoDeleteS(IControlManager cm, string gridName)
        {
            var info = ADInfoBll.Instance.GetGridRowInfo(gridName);

            if (info != null && !string.IsNullOrEmpty(info.AllowDelete) &&
                !Permission.AuthorizeByRule(info.AllowDelete, cm.DisplayManager.CurrentItem))
            {
                MessageForm.ShowError("您没有删除此记录的权限!");
                return(false);
            }

            if (MessageForm.ShowYesNo("当前记录将要被删除,是否继续?", "确认", true))
            {
                return(cm.DeleteCurrent());
            }

            return(false);
        }
예제 #9
0
        private static void SetTsbState(IButton tsb, IDisplayManager dm)
        {
            object entity = dm.CurrentItem;

            WindowMenuInfo info = tsb.Tag as WindowMenuInfo;

            tsb.Visible = Permission.AuthorizeByRule(info.Visible, entity);
            //if (!tsb.Visible)
            //    continue;

            bool enable = true;

            if (enable)
            {
                enable = Permission.AuthorizeByRule(info.Enable, entity);
            }
            tsb.Enabled = enable;
        }
예제 #10
0
        internal static void AddDateItemToUnBoundGrid(this IBoundGrid grid, object dataItem)
        {
            GridInfo gridInfo = ADInfoBll.Instance.GetGridInfo(grid.GridName);

            if (!Authority.AuthorizeByRule(gridInfo.Visible))
            {
                return;
            }

            GridRowInfo gridRowInfo = ADInfoBll.Instance.GetGridRowInfo(grid.GridName);

            if (!Permission.AuthorizeByRule(gridRowInfo.Visible, dataItem))
            {
                return;
            }
            Xceed.Grid.DataRow row = grid.DataRows.AddNew();
            grid.SetDataRowsIListData(dataItem, row);
            row.EndEdit();
        }
예제 #11
0
        internal static void SetUnBoundGridDataBinding(this IBoundGrid grid)
        {
            try
            {
                grid.BeginInit();

                grid.DataRows.Clear();

                GridInfo gridInfo = ADInfoBll.Instance.GetGridInfo(grid.GridName);
                if (!Authority.AuthorizeByRule(gridInfo.Visible))
                {
                    return;
                }
                if (!string.IsNullOrEmpty(gridInfo.ReadOnly))
                {
                    grid.ReadOnly = Authority.AuthorizeByRule(gridInfo.ReadOnly);
                }

                GridRowInfo gridRowInfo = ADInfoBll.Instance.GetGridRowInfo(grid.GridName);

                foreach (object entity in grid.DisplayManager.Items)
                {
                    if (!Permission.AuthorizeByRule(gridRowInfo.Visible, entity))
                    {
                        continue;
                    }
                    Xceed.Grid.DataRow row = grid.DataRows.AddNew();
                    grid.SetDataRowsIListData(entity, row);
                    row.EndEdit();
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithNotify(ex);
            }
            finally
            {
                grid.EndInit();
            }

            grid.AfterLoadData();
        }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="gridName"></param>
        /// <returns></returns>
        public Dictionary <string, object> Process(object entity, string gridName)
        {
            Dictionary <string, object> r = new Dictionary <string, object>();

            // grid
            if (!Authority.AuthorizeByRule(ADInfoBll.Instance.GetGridInfo(gridName).Visible))
            {
                return(r);
            }

            // row
            if (!Permission.AuthorizeByRule(ADInfoBll.Instance.GetGridRowInfo(gridName).Visible, entity))
            {
                return(r);
            }

            // column
            foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(gridName))
            {
                object v = null;
                if ((m_useColumnVisible && !Authority.AuthorizeByRule(info.ColumnVisible)) ||
                    (!m_useColumnVisible && !Authority.AuthorizeByRule(info.DataControlVisible)))
                {
                    continue;
                }
                else
                {
                    if (info.GridColumnType != GridColumnType.Normal &&
                        info.GridColumnType != GridColumnType.ExpressionColumn)
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(info.PropertyName))
                    {
                        v = null;
                    }
                    else if (info.GridColumnType == GridColumnType.Normal)
                    {
                        v = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName);
                    }
                    else if (info.GridColumnType == GridColumnType.ExpressionColumn)
                    {
                        if (info.PropertyName.Contains("%"))
                        {
                            v = EntityScript.CalculateExpression(info.PropertyName, entity);
                        }
                        else
                        {
                            v = ProcessInfoHelper.TryExecutePython(info.PropertyName,
                                                                   new Dictionary <string, object>()
                            {
                                { "entity", entity }
                            });
                        }
                    }
                    else
                    {
                        continue;
                    }
                }

                if (v == System.DBNull.Value)
                {
                    v = null;
                }
                if (v == null)
                {
                    r[info.GridColumnName] = null;
                    continue;
                }

                string vs = null;
                if (GridColumnInfoHelper.CreateType(info).IsEnum)
                {
                    vs = v.ToString();
                }

                switch (info.CellViewerManager)
                {
                case "Combo":
                case "MultiCombo":
                    vs = GetViewerText(v, info);
                    break;

                case "Object":
                    vs = EntityHelper.ReplaceEntity(info.CellViewerManagerParam, v, null);
                    break;

                case "Numeric":
                case "Integer":
                case "Long":
                case "Currency":
                    vs = Convert.ToDouble(v).ToString(GetFormatString(info));
                    break;

                case "Date":
                case "DateTime":
                    vs = Convert.ToDateTime(v).ToString(GetFormatString(info));
                    break;

                default:
                    vs = v.ToString();
                    break;
                }

                r[info.GridColumnName] = vs;

                //// cell
                //foreach (GridCellInfo info in GridSettingInfoCollection.Instance[gridName].GridCellInfos)
                //{
                //}
            }

            return(r);
        }
        private static void detailGrid_CollapsedChanged(object sender, EventArgs e)
        {
            DataBoundDetailGrid detailGrid = sender as DataBoundDetailGrid;

            if (detailGrid == null)
            {
                return;
            }

            if (!detailGrid.Collapsed)
            {
                // Buffer
                if (detailGrid.DataRows.Count > 0)
                {
                    return;
                }

                //detailGrid.GridControl.CurrentRow = detailGrid.ParentDataRow;

                // detailGrid.ParentGrid is Xceed.Grid.MasterGrid
                // detailGrid.GridControl is IboundGrid 当时不适用于多层情况
                //IBoundGrid parentGrid = detailGrid.ParentGrid as IBoundGrid;
                //if (parentGrid == null)
                //{
                //    throw new ArgumentException("Parent Grid should be IBoundGrid!");
                //}

                ISearchManagerWithParent smp = detailGrid.DisplayManager.SearchManager as ISearchManagerWithParent;
                if (smp == null)
                {
                    throw new ArgumentException("detailGrid.DisplayManager.SearchManager should be ISearchManagerWithParent!");
                }
                IDisplayManager dmParent = smp.ParentDisplayManager;
                try
                {
                    dmParent.BeginBatchOperation();

                    int oldPos = dmParent.Position;
                    if (oldPos != detailGrid.ParentDataRow.Index)
                    {
                        dmParent.Position = detailGrid.ParentDataRow.Index;
                    }
                    if (detailGrid is ArchiveUnboundDetailGrid)
                    {
                        ((ArchiveUnboundDetailGrid)detailGrid).ArchiveGridHelper.Initialize();
                    }

                    GridInfo gridInfo = ADInfoBll.Instance.GetGridInfo(detailGrid.GridName);

                    bool gridVisible = true;
                    if (!string.IsNullOrEmpty(gridInfo.VisibleAsDetail))
                    {
                        gridVisible = Permission.AuthorizeByRule(gridInfo.VisibleAsDetail, dmParent.CurrentItem);
                    }
                    if (!gridVisible)
                    {
                        detailGrid.Visible = false;
                    }
                    else
                    {
                        detailGrid.Visible = true;

                        // 可能有多个DetailGrid,只处理第一个
                        if (m_detailGridsState.Count == 0)
                        {
                            m_detailGridsState = new ArrayList {
                                detailGrid, detailGrid.GridControl.Enabled, oldPos
                            };

                            detailGrid.GridControl.Enabled = false;
                            detailGrid.DisplayManager.SearchManager.DataLoaded -= new EventHandler <DataLoadedEventArgs>(SearchManager_DataLoaded);
                            detailGrid.DisplayManager.SearchManager.DataLoaded += new EventHandler <DataLoadedEventArgs>(SearchManager_DataLoaded);
                        }

                        detailGrid.DisplayManager.SearchManager.LoadDataAccordSearchControls();
                    }

                    // 不能直接设置,需要在查找完成后设置
                    //dmParent.Position = oldPos;
                }
                finally
                {
                    dmParent.EndBatchOperation();
                    //detailGrid.Visible = (detailGrid.DataRows.Count != 0);
                }
            }
        }