0
\$\begingroup\$

I want to design a flexible dynamic system for a client with standard data-entry screens and CRUD UserControls

I dont know whether UserControls or ServerControls are better for this purpose. For now I have used UserControl for fast drag and drop then making screens work.

My solution contains 3 projects

DataAccessLayer.dll
BusinessLayer.dll    Contains CRUDControl as user control 
MainProject  -> contains Controllers, Models, Views folders

Controllers contain client validation, which is without SQL.
Models contain SQL validation

Solution enter image description here Here's my C# CRUDControl UserControl:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
using DevExpress.XtraEditors;
using Appointment.DataAccessLayer;
using DevExpress.XtraBars;
using System.Collections.ObjectModel;
using CrystalDecisions.CrystalReports.Engine;
using DevExpress.XtraGrid.Views.Grid;

namespace Appointment.BusinessLogicLayer
{
    public partial class CRUDControl : UserControl
    {
        public CRUDControl()
        {
            InitializeComponent();
        }

        #region Internal Members
        internal void RefreshRecordStatus()
        {
            // Refresh current and total record status
            txtCurrentRecord.EditValue = (crud.Pointer + 1).ToString();
            txtCountRecord.EditValue = crud.RecordCount.ToString();
        }
        internal void ClearRecordStatus()
        {
            // Clear current and total record status except in Add, Search state will named
            txtCurrentRecord.EditValue = (this.CRUDState != CRUDState.Default ? (CRUDState == CRUDState.Add ? "Add" : "Search") : string.Empty);
            txtCountRecord.EditValue = (this.CRUDState != CRUDState.Default ? (CRUDState == CRUDState.Add ? "إضافة" : "بحث") : string.Empty);
        }
        internal void SerializeBuffer()
        {
            // Convert text editors to buffer of CRUD.DataBuffer from AttachedForm
            crud.DataBuffer.Clear();
            foreach (Control control in AttachedForm.Controls)
            {
                if (control is TextEdit)
                {
                    if (control is DateEdit)
                        crud.DataBuffer.Add(control.Name.ToLower(), (Utility.IsEmpty(control.Text) ? control.Text : (control as DateEdit).DateTime.ToString("dd/MM/yyyy")));
                    else
                        crud.DataBuffer.Add(control.Name.ToLower(), control.Text.ToString().Trim());
                }
            }
        }
        internal void DeserializeBuffer()
        {
            // Convert buffer from CRUD.DataBuffer to text editors inside AttachedForm
            foreach (KeyValuePair<string, string> buffer in crud.DataBuffer)
            {
                foreach (Control control in AttachedForm.Controls)
                {
                    if (control is TextEdit)
                    {
                        if (control.Name.ToLower() == buffer.Key.ToLower())
                        {
                            if (control is DateEdit)
                                (control as DateEdit).DateTime = DateTime.ParseExact(buffer.Value.Trim(), "dd/MM/yyyy", null);
                            else
                                control.Text = buffer.Value.Trim();
                        }
                    }
                }
            }

            // Get Master-Details record if exist
            if (crudMasterDetails.GridView != null)
                crudMasterDetails.Select();
        }
        internal void InitializeCRUDToolbox()
        {
            switch (CRUDState)
            {
                case CRUDState.Default:
                    btnFirst.Enabled = false;
                    btnPrevious.Enabled = false;
                    btnNext.Enabled = true;
                    btnLast.Enabled = true;

                    btnCancel.Enabled = false;
                    btnSave.Enabled = false;
                    break;
                case CRUDState.Add:
                    btnFirst.Enabled = false;
                    btnPrevious.Enabled = false;
                    btnNext.Enabled = false;
                    btnLast.Enabled = false;

                    btnAdd.Enabled = false;
                    btnSearch.Enabled = false;
                    btnEdit.Enabled = false;
                    btnDelete.Enabled = false;
                    btnPrint.Enabled = false;
                    btnSend.Enabled = false;

                    btnCancel.Enabled = true;
                    btnSave.Enabled = true;
                    break;
                case CRUDState.Search:
                case CRUDState.Delete:
                    btnFirst.Enabled = (crud.RecordCount > 0 ? true : false);
                    btnPrevious.Enabled = (crud.RecordCount > 0 ? true : false);
                    btnNext.Enabled = (crud.RecordCount > 0 ? true : false);
                    btnLast.Enabled = (crud.RecordCount > 0 ? true : false);

                    btnAdd.Enabled = false;
                    btnSearch.Enabled = false;

                    btnEdit.Enabled = (crud.RecordCount > 0 ? ((Privilages.Edit) ? true : false) : false);
                    btnDelete.Enabled = (crud.RecordCount > 0 ? ((Privilages.Edit) ? true : false) : false);
                    btnPrint.Enabled = (crud.RecordCount > 0 ? ((Privilages.Edit) ? true : false) : false);
                    btnSend.Enabled = (crud.RecordCount > 0 ? ((Privilages.Edit) ? true : false) : false);

                    btnCancel.Enabled = true;

                    if (this.CRUDState == CRUDState.Search)
                        btnSave.Enabled = (crud.RecordCount == 0 ? true : false);
                    else
                        btnSave.Enabled = false;

                    break;
            }
        }
        internal void InitializeFirstCRUD(bool creteria = false)
        {

            crud.Select(creteria);
            if (crud.RecordCount > 0)
            {
                RefreshRecordStatus();  // Refresh current record and total records status
                InitializeCRUDToolbox();
                DeserializeBuffer();        // Deserialize injected CRUD DataBuffer to text edits
            }
            else
            {
                // If "Search Mode" and no data then "Default mode"
                if (CRUDState == CRUDState.Search)
                {
                    InitializeCRUDToolbox();
                    XtraMessageBox.Show("لا يوجد نتائج بحث", "نتائج البحث", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    // If "Default Mode" and no data then "Add Mode"
                    btnAdd_ItemClick(null, null);
                }
            }
            InitializeComboBoxElement();
        }
        internal void InitializePrivilages()
        {
            Privilages.Initialize(AttachedForm.Name.Trim());
            btnAdd.Enabled = (crud.RecordCount == 0 && CRUDState == CRUDState.Add ? false : Privilages.Add);
            btnEdit.Enabled = (crud.RecordCount == 0 && CRUDState == CRUDState.Add ? false : Privilages.Edit);
            btnDelete.Enabled = (crud.RecordCount == 0 && CRUDState == CRUDState.Add ? false : Privilages.Delete);
            btnSearch.Enabled = (crud.RecordCount == 0 && CRUDState == CRUDState.Add ? false : Privilages.Search);
            btnPrint.Enabled = (crud.RecordCount == 0 && CRUDState == CRUDState.Add ? false : Privilages.Print);
            btnSend.Enabled = (crud.RecordCount == 0 && CRUDState == CRUDState.Add ? false : Privilages.Send);
        }
        internal void EmptyFields()
        {
            foreach (Control control in AttachedForm.Controls)
            {
                if (control is TextEdit)
                {
                    control.Text = string.Empty;
                    if (control is DateEdit)
                    {
                        (control as DateEdit).Properties.NullText = string.Empty;
                        (control as DateEdit).Properties.NullDate = string.Empty;
                    }
                }
            }
        }
        internal void DefaultFields()
        {
            foreach (Control control in AttachedForm.Controls)
            {
                if (control is DateEdit)
                    (control as DateEdit).DateTime = DateTime.Now;
            }
        }
        #endregion

        #region Public Properties 
        /// <summary>
        /// Main CRUD object for each CRUDControl
        /// </summary>
        public CRUD crud = new CRUD();

        /// <summary>
        /// Attached table with CRUDControl
        /// </summary>
        public string Table
        {
            get; set;
        }

        /// <summary>
        /// Attached primary key with CRUDControl
        /// </summary>
        public string PrimaryKey
        {
            get; set;
        }

        /// <summary>
        /// Attached form with CRUDControl
        /// </summary>
        public Form AttachedForm
        {
            get { return this.Parent as Form; }
        }

        /// <summary>
        /// State of CRUDControl [ Default = 0, Add = 1, Search = 2 ]
        /// </summary>
        public CRUDState CRUDState
        {
            get; private set;
        }

        /// <summary>
        /// Crystal Report .rpt class
        /// </summary>
        public ReportClass ReportClass { get; set; }

        /// <summary>
        /// Returns true if any validations errors and stop executing add, edit mode
        /// </summary>
        public event EventHandler ControllerEvent;

        // Events during CRUDOperations
        public event EventHandler AfterAdd;
        public event EventHandler AfterEdit;
        public event EventHandler AfterDelete;
        public event EventHandler AfterSearch;

        public event EventHandler BeforeAdd;
        public event EventHandler BeforeEdit;
        public event EventHandler BeforeDelete;
        public event EventHandler BeforeSearch;

        /// <summary>
        /// Focus in btnAccept, btnEdit depended on CRUDState
        /// </summary>
        public new void Focus()
        {
            if (CRUDState > 0)
                barManager1.Bars[0].ItemLinks[6].Focus();
            else
                barManager1.Bars[0].ItemLinks[11].Focus();
        }

        private Collection<ComboBoxElement> _comboBoxElement = new Collection<ComboBoxElement>();

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Collection<ComboBoxElement> ComboBoxElement
        {
            get { return _comboBoxElement; }
        }

        // Initialize ComboBoxEdit search controls
        public void InitializeComboBoxElement()
        {
            if (_comboBoxElement.Count == 0) return;

            SQLQuery sQLQuery = new SQLQuery();
            foreach (var obj in _comboBoxElement)
            {
                ((ComboBoxEdit)AttachedForm.Controls.Find(obj.ControlID, true)[0]).Properties.Items.Clear();
                ((ComboBoxEdit)AttachedForm.Controls.Find(obj.ControlID, true)[0]).Properties.Items.AddRange(sQLQuery.GetRows(obj.Table, obj.Field));
            }
        }

        private CRUDMasterDetails crudMasterDetails = new CRUDMasterDetails();
        public CRUDMasterDetails CRUDMasterDetails
        {
            get
            {
                if (crudMasterDetails == null)
                    crudMasterDetails = new CRUDMasterDetails();
                return crudMasterDetails;
            }
        }

        #endregion

        #region Hidden Properties
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override bool AllowDrop { get => base.AllowDrop; set => base.AllowDrop = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override AnchorStyles Anchor { get => base.Anchor; set => base.Anchor = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override bool AutoScroll { get => base.AutoScroll; set => base.AutoScroll = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override bool AutoSize { get => base.AutoSize; set => base.AutoSize = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Color BackColor { get => base.BackColor; set => base.BackColor = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override AutoValidate AutoValidate { get => base.AutoValidate; set => base.AutoValidate = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Point AutoScrollOffset { get => base.AutoScrollOffset; set => base.AutoScrollOffset = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Image BackgroundImage { get => base.BackgroundImage; set => base.BackgroundImage = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override ImageLayout BackgroundImageLayout { get => base.BackgroundImageLayout; set => base.BackgroundImageLayout = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override BindingContext BindingContext { get => base.BindingContext; set => base.BindingContext = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        protected override bool CanEnableIme => base.CanEnableIme;

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        protected override bool CanRaiseEvents => base.CanRaiseEvents;

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override ContextMenu ContextMenu { get => base.ContextMenu; set => base.ContextMenu = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override ContextMenuStrip ContextMenuStrip { get => base.ContextMenuStrip; set => base.ContextMenuStrip = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Cursor Cursor { get => base.Cursor; set => base.Cursor = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Color ForeColor { get => base.ForeColor; set => base.ForeColor = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Font Font { get => base.Font; set => base.Font = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override bool Focused => base.Focused;

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Rectangle DisplayRectangle => base.DisplayRectangle;

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override LayoutEngine LayoutEngine => base.LayoutEngine;

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override string Text { get => base.Text; set => base.Text = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override ISite Site { get => base.Site; set => base.Site = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Size MaximumSize { get => base.MaximumSize; set => base.MaximumSize = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override Size MinimumSize { get => base.MinimumSize; set => base.MinimumSize = value; }

        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft { get => base.RightToLeft; set => base.RightToLeft = value; }
        #endregion

        private void CRUDControl_Load(object sender, EventArgs e)
        {
            if (this.DesignMode) return;    // Prevent design-time issues

            // Initialize crud members [ DataAccessLayer from BusinessLogicLayer ]
            crud.Table = this.Table;
            crud.PrimaryKey = this.PrimaryKey;

            // Initialize Master-Details class
            if (crudMasterDetails.GridView != null)
                crudMasterDetails.CRUDControl = this;

            // Intiailize data-entry screen for first usage
            InitializeFirstCRUD();

            // Initialize security if there's records else add mode if privilage exist
            InitializePrivilages();

            AttachedForm.Controls.Find(this.PrimaryKey, true)[0].Focus();    // Focus on first input
        }

        // Add
        private void btnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Add Mode
            this.CRUDState = CRUDState.Add;
            EmptyFields();      // Clear fields
            crud.Clear();       // Clear dataset, pointer, recordcount and data buffer to be fresh for use

            // Clear details grid
            if (crudMasterDetails.GridView != null)
                crudMasterDetails.Clear();

            DefaultFields();    // Load default values

            InitializeCRUDToolbox();    // Initialize CRUD toolbox for add-mode
            ClearRecordStatus();        // Clear record status

            AttachedForm.Controls.Find(this.PrimaryKey, true)[0].Focus();    // Focus on first input
        }

        // Print
        private void btnPrint_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Print Current Record
            SQLQuery sQLQuery = new SQLQuery();
            if (crudMasterDetails.GridView == null)
                this.ReportClass.SetDataSource(sQLQuery.GetDataTable(Table, $"{PrimaryKey} = '{crud.DataBuffer[PrimaryKey.ToLower()].Replace("'", "''")}'"));
            else
            {

                ReportClass.Database.Tables[0].SetDataSource(sQLQuery.GetDataTable(Table, $"{PrimaryKey} = '{crud.DataBuffer[PrimaryKey.ToLower()].Replace("'", "''")}'"));
                ReportClass.Database.Tables[1].SetDataSource(sQLQuery.GetDataTable(crudMasterDetails.MasterDetailsTable, $"{PrimaryKey} = '{crud.DataBuffer[PrimaryKey.ToLower()].Replace("'", "''")}'"));
            }

            new CrystalReportEngine()
            {
                ReportClass = this.ReportClass,
                Text = this.AttachedForm.Text
            }.ShowDialog();

        }

        // Cancel
        private void btnCancel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Cancel Operation [ Add, Search ]

            // Back to default mode
            CRUDState = CRUDState.Default;
            InitializeFirstCRUD();

            if (crud.RecordCount > 0)
                InitializePrivilages();
        }

        // Search
        private void btnSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Search Mode
            this.CRUDState = CRUDState.Search;

            EmptyFields();  // clear fields
            crud.Clear();   // Clear dataset to be fresh for use

            // Clear details grid
            if (crudMasterDetails.GridView != null)
                crudMasterDetails.Clear();

            InitializeCRUDToolbox();   // Initialize CRUD tollbox for search-mode
            ClearRecordStatus();       // Clear record status

            AttachedForm.Controls.Find(this.PrimaryKey, true)[0].Focus();    // Focus on first input
        }

        // Edit
        private void btnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show("هل أنت متأكد من التعديل ؟", "تعديل السجل الحالى", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                // Controller event
                EventHandler eventHandlerController = ControllerEvent;
                if (eventHandlerController != null)
                    ControllerEvent(sender, EventArgs.Empty);

                // BeforeEdit event
                EventHandler eventHandlerBeforeEdit = BeforeEdit;
                if (eventHandlerBeforeEdit != null)
                    BeforeEdit(sender, EventArgs.Empty);

                if (CRUDError.HasError)
                {
                    CRUDError.HasError = false; // Reset error state
                    return;
                }

                // Edit operation
                SerializeBuffer();
                crud.Update(crud.DataBuffer);

                if (crudMasterDetails.GridView != null)
                    crudMasterDetails.Post();

                // AfterEdit event
                EventHandler eventHandlerAfterEdit = AfterEdit;
                if (eventHandlerAfterEdit != null)
                    AfterEdit(sender, EventArgs.Empty);
            }

        }

        // Delete
        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show("هل أنت متأكد من الحذف ؟", "حذف السجل الحالى", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
            {
                // BeforeDelete event
                EventHandler eventHandlerBeforeDelete = BeforeDelete;
                if (eventHandlerBeforeDelete != null)
                    BeforeDelete(sender, EventArgs.Empty);

                if (CRUDError.HasError)
                {
                    CRUDError.HasError = false; // Reset error state
                    return;
                }

                // Delete operation
                if (crudMasterDetails.GridView != null)
                    crudMasterDetails.Delete(); // Delete master-details first to fetch current pointer of primary key

                // Delete master file then assign pointer of primary key
                crud.Delete();

                // AfterDelete event
                EventHandler eventHandlerAfterDelete = AfterDelete;
                if (eventHandlerAfterDelete != null)
                    AfterDelete(sender, EventArgs.Empty);

                if (crud.RecordCount > 0)
                {
                    DeserializeBuffer();    // Deserialize injected CRUD DataBuffer to text edits
                    RefreshRecordStatus();  // Refresh current record and total records status
                }
                else
                {
                    if (this.CRUDState == CRUDState.Search)
                    {
                        this.CRUDState = CRUDState.Delete;  // Force delete state inside a search
                        EmptyFields();  // clear fields
                        InitializeCRUDToolbox();   // Switch to delete in a search mode
                        ClearRecordStatus();
                    }
                    else
                    {
                        if (Privilages.Add)
                            btnAdd_ItemClick(sender, e);
                    }
                }
            }
        }

        // Save
        private void btn_Save_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Save Operation [ Add or Search ]
            if (CRUDState == CRUDState.Add)
            {
                // Case add mode

                // Check for first transactions usage and if add mode privilage exist
                if (crud.RecordCount == 0 && !Privilages.Add)
                {
                    XtraMessageBox.Show("لا يوجد سجلات ، والمستخدم ليس له صلاحية الإضافة", "السجلات فارغة - صلاحية الإضافة", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Validate controller & corresponding model event
                EventHandler eventHandler = ControllerEvent;
                if (eventHandler != null)
                    ControllerEvent(null, null);

                // BeforeAdd event
                EventHandler eventHandlerBeforeAdd = BeforeAdd;
                if (eventHandlerBeforeAdd != null)
                    BeforeAdd(sender, EventArgs.Empty);

                if (CRUDError.HasError)
                {
                    CRUDError.HasError = false; // Reset error state
                    return;
                }

                SerializeBuffer();
                crud.Insert(crud.DataBuffer);
                if (crudMasterDetails.GridView != null)
                    crudMasterDetails.Post();

                // AfterAdd event
                EventHandler eventHandlerAfterAdd = AfterAdd;
                if (eventHandlerAfterAdd != null)
                    AfterAdd(sender, EventArgs.Empty);

                EmptyFields();      // Clear fields
                crud.Clear();       // Clear dataset, pointer, recordcount and data buffer to be fresh for use

                // Clear details grid
                if (crudMasterDetails.GridView != null)
                    crudMasterDetails.Clear();

                DefaultFields();    // Load default values

                AttachedForm.Controls.Find(this.PrimaryKey, true)[0].Focus();    // Focus on first input
            }
            else
            {
                // Case search mode

                SerializeBuffer();
                crud.FlushBuffer(); // Remove empty values from buffer
                if (crud.DataBuffer.Count > 0)  // If there`s data in buffer then creteria buffer
                {
                    // BeforeSearch event
                    EventHandler eventHandlerBeforeSearch = BeforeSearch;
                    if (eventHandlerBeforeSearch != null)
                        BeforeSearch(sender, EventArgs.Empty);

                    InitializeFirstCRUD(true); // Initialize first data-entry with creteria of search

                    // AfterSearch event
                    EventHandler eventHandlerAfterSearch = AfterSearch;
                    if (eventHandlerAfterSearch != null)
                        AfterSearch(sender, EventArgs.Empty);
                }
                else
                {
                    // Search Mode & TextEdits is null then default buffer, No AfterSearcg evebt gere
                    CRUDState = CRUDState.Default;
                    InitializeFirstCRUD();
                    InitializePrivilages();
                    AttachedForm.Controls.Find(this.PrimaryKey, true)[0].Focus();    // Focus on first input
                }

            }

        }

        // Help
        private void btnHelp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            XtraMessageBox.Show("نظام المعاملات - مساعدة", "Help - مساعدة");
        }

        // First
        private void btnFirst_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Move First
            crud.MoveFirst();
            txtCurrentRecord.EditValue = (crud.Pointer + 1).ToString();
            btnFirst.Enabled = false;
            btnPrevious.Enabled = false;
            btnNext.Enabled = true;
            btnLast.Enabled = true;
            DeserializeBuffer();        // Deserialize injected CRUD DataBuffer to text edits

        }

        // Previous
        private void btnPrevious_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Move Previous
            crud.MovePrevious();
            txtCurrentRecord.EditValue = (crud.Pointer + 1).ToString();
            if (crud.Pointer == 0)
            {
                btnFirst.Enabled = false;
                btnPrevious.Enabled = false;
            }
            btnNext.Enabled = true;
            btnLast.Enabled = true;
            DeserializeBuffer();        // Deserialize injected CRUD DataBuffer to text edit

        }

        // Next
        private void btnNext_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Move Next
            crud.MoveNext();
            txtCurrentRecord.EditValue = (crud.Pointer + 1).ToString();
            if (crud.Pointer == crud.RecordCount - 1)
            {
                btnNext.Enabled = false;
                btnLast.Enabled = false;
            }
            btnFirst.Enabled = true;
            btnPrevious.Enabled = true;
            DeserializeBuffer();        // Deserialize injected CRUD DataBuffer to text edits
        }

        // Last
        private void btnLast_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            // Move Last
            crud.MoveLast();
            txtCurrentRecord.EditValue = (crud.Pointer + 1).ToString();
            btnFirst.Enabled = true;
            btnPrevious.Enabled = true;
            btnNext.Enabled = false;
            btnLast.Enabled = false;
            DeserializeBuffer();        // Deserialize injected CRUD DataBuffer to text edits

        }

    }
}
\$\endgroup\$
  • \$\begingroup\$ What i mean by flexible is adding any data-entry screens later will be extremely easy that what i want to do. \$\endgroup\$ – Software KAMAL Jan 26 at 22:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.