Пример #1
0
        /// <summary>
        /// 选中所有行
        /// </summary>
        public void SelectAll()
        {
            selection.Clear();
            // fast (won't work if the grid is filtered)
            //if(_view.DataSource is ICollection)
            //	selection.AddRange(((ICollection)_view.DataSource));
            //else
            // slow:
            for (int i = 0; i < _view.DataRowCount; i++)
            {
                selection.Add(_view.GetRow(i));
            }

            Invalidate();
        }
Пример #2
0
        protected void BandedView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            BandedGridView bandedView = (BandedGridView)MainView;

            //Hiển thị lương theo nhóm ca
            int focusedRowHandle = e.RowHandle;

            if (focusedRowHandle >= 0)
            {
                HREmployeePayRollsInfo objEmployeePayRollsInfo = bandedView.GetRow(focusedRowHandle) as HREmployeePayRollsInfo;
                if (objEmployeePayRollsInfo != null)
                {
                    foreach (var item in WorkingShiftGroupsList)
                    {
                        if (item.ADWorkingShiftGroupID > 0)
                        {
                            if (e.Column.FieldName == item.ADWorkingShiftGroupID.ToString())
                            {
                                decimal total = (decimal)objEmployeePayRollsInfo.HREmployeePayrollDetailsList.
                                                Where(o => o.HREmployeeTimeSheetOTDetailName == item.ADWorkingShiftGroupID.ToString() &&
                                                      !o.IsOT).
                                                Sum(o => o.HREmployeePayrollHours);

                                e.DisplayText = total.ToString("n4");
                            }
                            else if (e.Column.FieldName == "L" + item.ADWorkingShiftGroupID.ToString())
                            {
                                decimal total = (decimal)objEmployeePayRollsInfo.HREmployeePayrollDetailsList.
                                                Where(o => o.HREmployeeTimeSheetOTDetailName == item.ADWorkingShiftGroupID.ToString() &&
                                                      !o.IsOT).
                                                Sum(o => o.HREmployeePayrollSalaryFactor);

                                e.DisplayText = total.ToString("n0");
                            }
                        }
                    }

                    foreach (var item in OTFactorlist)
                    {
                        if (e.Column.FieldName == string.Format("TC{0}", item.ADOTFactorID.ToString()))
                        {
                            decimal total = (decimal)objEmployeePayRollsInfo.HREmployeePayrollDetailsList.
                                            Where(o => o.HREmployeeTimeSheetOTDetailName == item.ADOTFactorID.ToString() &&
                                                  o.IsOT).
                                            Sum(o => o.HREmployeePayrollHourFactor);
                            e.DisplayText = total.ToString("n5");
                        }
                        else if (e.Column.FieldName == string.Format("LTC{0}", item.ADOTFactorID.ToString()))
                        {
                            decimal total = (decimal)objEmployeePayRollsInfo.HREmployeePayrollDetailsList.
                                            Where(o => o.HREmployeeTimeSheetOTDetailName == item.ADOTFactorID.ToString() &&
                                                  o.IsOT).
                                            Sum(o => o.HREmployeePayrollSalaryFactor);

                            e.DisplayText = total.ToString("n0");
                        }
                    }
                }
            }
        }
Пример #3
0
        private void bandedGridView1_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
        {
            BandedGridView     bandgv = sender as BandedGridView;
            CHITIETPHIEUTRADTO ct     = bandgv.GetRow(e.RowHandle) as CHITIETPHIEUTRADTO;

            if (ct != null)
            {
                e.ChildList = listpt.Where(p => p.NgayTra == ct.NgayTra && p.MaDocGia == ct.MaDocGia).Select(p => p).ToList();
            }
        }
Пример #4
0
        private void bandedGridView2_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
        {
            BandedGridView      bandgv = sender as BandedGridView;
            CHITIETPHIEUMUONDTO ct     = bandgv.GetRow(e.RowHandle) as CHITIETPHIEUMUONDTO;

            if (ct != null)
            {
                e.ChildList = listpm.Where(p => (p.NgayMuon == ct.NgayMuon && p.MaDocGia == ct.MaDocGia) && (p.TinhTrangMuon == "Còn hạn" || p.TinhTrangMuon == "Quá hạn")).Select(p => p).ToList();
            }
        }
Пример #5
0
        protected void BandedView_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            BandedGridView bandedView = (BandedGridView)MainView;

            if (!bandedView.IsValidRowHandle(e.RowHandle))
            {
                return;
            }
            int focusedRowHandle = e.RowHandle;

            if (focusedRowHandle >= 0)
            {
                HREmployeeTimeSheetsInfo objEmployeeTimeSheetsInfo = bandedView.GetRow(focusedRowHandle) as HREmployeeTimeSheetsInfo;
                if (objEmployeeTimeSheetsInfo != null)
                {
                    if (objEmployeeTimeSheetsInfo.HREmployeeTimeSheetOTDetailsList != null)
                    {
                        foreach (var item in objEmployeeTimeSheetsInfo.HREmployeeTimeSheetOTDetailsList)
                        {
                            if (e.Column.FieldName == item.HREmployeeTimeSheetOTDetailName)
                            {
                                e.DisplayText = item.HREmployeeTimeSheetOTDetailHours.ToString();
                                e.CellValue   = item.HREmployeeTimeSheetOTDetailHours;
                            }
                        }
                    }
                    if (objEmployeeTimeSheetsInfo.HRTimeSheetEntrysList != null)
                    {
                        objEmployeeTimeSheetsInfo.HRTimeSheetEntrysList.ForEach(o =>
                        {
                            if (e.Column.FieldName == "CONG" + o.FK_ADWorkingShiftID.ToString())
                            {
                                decimal total = (decimal)objEmployeeTimeSheetsInfo.HRTimeSheetEntrysList.
                                                Where(x => x.FK_ADWorkingShiftID == o.FK_ADWorkingShiftID &&
                                                      !x.IsCommonParam)
                                                .Sum(x => x.HRTimeSheetEntryWorkingQty);

                                e.DisplayText = total.ToString("n5");
                            }
                        });
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// BandedGridView 拖拽
        /// </summary>
        /// <param name="gvMain"></param>
        public static void DragGridRow <T>(this BandedGridView gvMain)
        {
            // 拖拽遮罩控件
            DragMaster dragMaster = new DragMaster();
            // 当前拖拽行绘画区域
            Rectangle _DragRowRect = Rectangle.Empty;

            GridControl gcMain       = gvMain.GridControl;
            GridHitInfo _DownHitInfo = null;

            //表格属性 允许拖拽
            gcMain.AllowDrop = true;
            gvMain.OptionsDetail.EnableMasterViewMode = false;
            #region 将对象拖至边界时发生 DragOver
            gcMain.DragOver += delegate(object sender, System.Windows.Forms.DragEventArgs e)
            {
                if (e.Data.GetDataPresent(typeof(T)))
                {
                    e.Effect = DragDropEffects.Move;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            };
            #endregion

            #region 拖拽完成时处理数据 DragDrop
            gcMain.DragDrop += delegate(object sender, System.Windows.Forms.DragEventArgs e)
            {
                // 拖过来的新数据
                T newRow = (T)e.Data.GetData(typeof(T));
                // 原来在此坐标的数据
                // e的坐标是相对于屏幕的
                var         clientPoint = gcMain.PointToClient(new Point(e.X, e.Y));
                GridHitInfo hitInfo     = gvMain.CalcHitInfo(new Point(clientPoint.X, clientPoint.Y));
                var         oldRow      = (T)gvMain.GetRow(hitInfo.RowHandle);

                // 如果相等则不处理
                if (oldRow == null || newRow == null)
                {
                    return;
                }

                // 且目标位置不是最后一行的话要将所有序号重排
                // 原来的行号
                var oldIndex = _DownHitInfo.RowHandle;
                // 新的行号
                var newIndex = hitInfo.RowHandle;

                BindingSource bs = (BindingSource)(gcMain.DataSource);
                if (bs == null)
                {
                    return;
                }

                bs.RemoveAt(oldIndex);
                bs.Insert(oldIndex, oldRow);
                bs.RemoveAt(newIndex);
                bs.Insert(newIndex, newRow);

                bs.ResetBindings(false);
            };
            #endregion

            #region  标按下 MouseDown
            gcMain.MouseDown += delegate(object sender, MouseEventArgs e)
            {
                _DownHitInfo = null;
                GridHitInfo hitInfo = gvMain.CalcHitInfo(new Point(e.X, e.Y));
                if (Control.ModifierKeys != Keys.None)
                {
                    return;
                }
                if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)
                {
                    // 禁用的Grid不支持拖拽
                    if (!gvMain.OptionsBehavior.Editable ||
                        gvMain.OptionsBehavior.ReadOnly)
                    {
                        return;
                    }
                    // 只有点击最前面才能拖拽
                    if (hitInfo.InRowCell)
                    {
                        return;
                    }
                    // 缓存
                    _DownHitInfo = hitInfo;
                }
            };
            #endregion

            #region  标移动 MouseMove
            gcMain.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (_DownHitInfo != null)
                    {
                        Size dragSize = SystemInformation.DragSize;
                        // 偏离区域
                        Rectangle dragRect = new Rectangle(new Point(_DownHitInfo.HitPoint.X - dragSize.Width / 2, _DownHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);

                        if (!dragRect.Contains(new Point(e.X, e.Y)))
                        {
                            // 屏幕坐标
                            var p = gcMain.PointToScreen(e.Location);
                            // 刷新是必须要的
                            gcMain.Refresh();
                            // 获取当前行截图
                            var bmp = GetDragRowImage(gcMain, _DownHitInfo, _DragRowRect);

                            Point offSetPoint = new Point(p.X + 1, p.Y - dragMaster.DragSize.Height / 2);
                            // 开始显示拖拽遮罩
                            dragMaster.StartDrag(bmp, offSetPoint, DragDropEffects.Move);
                            // 获取要拖拽的数据
                            object row = gvMain.GetRow(_DownHitInfo.RowHandle);
                            // 开始拖拽
                            gcMain.DoDragDrop(row, DragDropEffects.Move);
                            // 取消事件
                            DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;
                            // 清空缓存
                            _DownHitInfo = null;
                        }
                    }
                }
            };
            #endregion

            #region 在用鼠标拖动某项时发生,是否允许继续拖放 QueryContinueDrag
            gcMain.QueryContinueDrag += delegate(object sender, QueryContinueDragEventArgs e)
            {
                switch (e.Action)
                {
                case DragAction.Continue:
                    // 移动遮罩
                    Point offSetPoint = new Point(Cursor.Position.X + 1, Cursor.Position.Y - dragMaster.DragSize.Height / 2);
                    dragMaster.DoDrag(offSetPoint, DragDropEffects.Move, false);
                    break;

                default:
                    // 清空
                    _DragRowRect = Rectangle.Empty;
                    // 停止拖动
                    dragMaster.EndDrag();
                    break;
                }
            };
            #endregion

            #region 点击行头移动行
            gvMain.CustomDrawRowIndicator += delegate(object sender, RowIndicatorCustomDrawEventArgs e)
            {
                if (_DragRowRect == Rectangle.Empty && _DownHitInfo != null && _DownHitInfo.RowHandle == e.RowHandle)
                {
                    _DragRowRect = e.Bounds;
                }
            };
            #endregion
        }
Пример #7
0
        protected void BandedView_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            PayRollEntities entity     = (PayRollEntities)((BaseModuleERP)Screen.Module).CurrentModuleEntity;
            BandedGridView  bandedView = (BandedGridView)MainView;

            if (bandedView.FocusedRowHandle >= 0)
            {
                HREmployeePayRollsInfo objEmployeePayRollsInfo = (HREmployeePayRollsInfo)bandedView.GetRow(bandedView.FocusedRowHandle);
                ((PayRollModule)Screen.Module).CalculatePayRollTotalAmounts(objEmployeePayRollsInfo);
            }
        }