/// <summary>
        /// SaveRowValues
        /// </summary>
        /// <param name="row"></param>
        /// <param name="grid"></param>
        public static void SaveRowValues(Xceed.Grid.CellRow row, IArchiveGrid grid)
        {
            if (row is InsertionRow)
            {
                grid.ControlManager.AddNew();

                row.Tag = grid.ControlManager.DisplayManager.CurrentItem;
                grid.AddThrowInsertRow = true;
            }
            else
            {
                grid.ControlManager.EditCurrent();
                // when insert, dataRow endingedit event will occur also
                row.Tag = grid.ControlManager.DisplayManager.CurrentItem;
            }

            try
            {
                foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
                {
                    if (row.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                    {
                        if (info.GridColumnType == GridColumnType.Normal)
                        {
                            if (row.Cells[info.GridColumnName].ReadOnly)
                            {
                                continue;
                            }

                            if (info.GridColumnType == GridColumnType.Normal)
                            {
                                EntityScript.SetPropertyValue(grid.ControlManager.DisplayManager.CurrentItem, info.Navigator, info.PropertyName,
                                                              row.Cells[info.GridColumnName].Value);
                            }
                            else if (info.GridColumnType == GridColumnType.ExpressionColumn)
                            {
                                Script.ExecuteStatement(info.Navigator,
                                                        new Dictionary <string, object> {
                                    { "entity", grid.ControlManager.DisplayManager.CurrentItem },
                                    { "cm", grid.ControlManager }
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithNotify(ex);
                throw;
            }

            grid.ControlManager.EndEdit(true);

            grid.AddThrowInsertRow = false;

            grid.ArchiveGridHelper.ClearError(row);
        }
        /// <summary>
        /// row_EditEnded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void row_Saving(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Xceed.Grid.CellRow row = (Xceed.Grid.CellRow)sender;

            SaveRowValues(row, this);

            e.Cancel = (this.ControlManager.State != StateType.View);

            if (e.Cancel)
            {
                this.ControlManager.CancelEdit();
            }
        }
        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="dataSource"></param>
        ///// <param name="dataMember"></param>
        //public override void SetDataBinding(object dataSource, string dataMember)
        //{
        //    base.SetDataBinding(dataSource, dataMember);

        //    ArchiveUnboundGrid.SetGridRowCellProperties(this);
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void row_Saving(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Xceed.Grid.CellRow row = (Xceed.Grid.CellRow)sender;

            ArchiveUnboundGrid.SaveRowValues(row, row.ParentGrid as ArchiveUnboundDetailGrid);

            e.Cancel = (this.ControlManager.State != StateType.View);

            if (e.Cancel)
            {
                this.ControlManager.CancelEdit();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 public static void EndEditRow(Xceed.Grid.CellRow row)
 {
     if (row != null && row.IsBeingEdited)
     {
         try
         {
             row.EndEdit();
         }
         catch (Xceed.Grid.GridValidationException)
         {
             row.CancelEdit();
         }
     }
 }
        ///// <summary>
        ///// CancelEdit
        ///// </summary>
        //private void CancelEdit1()
        //{
        //    for (int i = 0; i < m_grid.DataRows.Count; ++i)
        //    {
        //        if (m_grid.DataRows[i].IsBeingEdited)
        //        {
        //            m_grid.DataRows[i].CancelEdit();
        //        }
        //    }

        //    if (m_insertionRow != null && m_insertionRow.IsBeingEdited)
        //    {
        //        m_insertionRow.CancelEdit();
        //    }

        //    //ClearError();
        //}

        /// <summary>
        /// 清除错误
        /// </summary>
        internal void ClearError(Xceed.Grid.CellRow row)
        {
            foreach (Cell cell in row.Cells)
            {
                cell.ResetErrorDescription();
            }
            row.ResetErrorDescription();

            if (m_insertionRow != null)
            {
                foreach (Cell cell in m_insertionRow.Cells)
                {
                    cell.ResetErrorDescription();
                    cell.ResetReadOnly();
                }
            }
        }
        ///// <summary>
        /////
        ///// </summary>
        ///// <param name="dataSource"></param>
        ///// <param name="dataMember"></param>
        //public override void SetDataBinding(object dataSource, string dataMember)
        //{
        //    base.SetDataBinding(dataSource, dataMember);
        //}

        #region "Same"
        /// <summary>
        /// SaveRowValues
        /// </summary>
        /// <param name="row"></param>
        /// <param name="grid"></param>
        public static void SaveRowValues(Xceed.Grid.CellRow row, IArchiveGrid grid)
        {
            if (row is InsertionRow)
            {
                //grid.ControlManager.AddNew();
                grid.ControlManager.State = StateType.Add;

                row.Tag = grid.ControlManager.DisplayManager.CurrentItem;
                grid.AddThrowInsertRow = true;
            }
            else
            {
                grid.ControlManager.EditCurrent();
                // when insert, dataRow endingedit event will occur also
                row.Tag = grid.ControlManager.DisplayManager.CurrentItem;
            }

            grid.ControlManager.EndEdit(true);

            grid.AddThrowInsertRow = false;

            grid.ArchiveGridHelper.ClearError(row);
        }
        internal bool DoValidateRow(Xceed.Grid.CellRow row, System.ComponentModel.CancelEventArgs e)
        {
            bool allValid = true;

            foreach (Cell cell in row.Cells)
            {
                // cell.Visible (when invisible validate also)
                if (cell.Visible && !cell.ReadOnly)
                {
                    allValid &= this.validationProvider1.Validate(cell, false, true);

                    if (!allValid)
                    {
                        return(false);
                    }
                }
            }

            if (ValidateRow != null)
            {
                ValidateRow(row, e);
                allValid &= !e.Cancel;
            }

            //Validator validator = ValidationFactory.CreateValidator(m_cm.DisplayManager.MainDataManager.EntityInfo.EntityType);
            //ValidationResults results = validator.Validate(m_cm.DisplayManager.CurrentItem);
            //if (!results.IsValid)
            //{
            //    foreach (ValidationResult result in results)
            //    {
            //        row.Cells[result.Key].ErrorDescription = result.Message;
            //    }
            //    return false;
            //}

            return(allValid);
        }