コード例 #1
0
        public void SetCrudControls(AppModuleCrudState CrudModeSelected)
        {
            try
            {
                _crudMode = CrudModeSelected;

                if (onCrudModeNotification != null)
                {
                    CrudModeNotificationArgs crudNotifyArgs = new CrudModeNotificationArgs();
                    crudNotifyArgs.SelectedCrudMode = _crudMode;

                    onCrudModeNotification(this, crudNotifyArgs);
                }

                switch (CrudMode)
                {
                case AppModuleCrudState.Brows:
                    RefButSave.Visible    = false;
                    RefButCancel.Visible  = false;
                    RefButDelete.Enabled  = true;
                    RefButNew.Enabled     = true;
                    RefButEdit.Enabled    = true;
                    RefButRefresh.Enabled = true;
                    RefDataGrid.Enabled   = true;

                    break;

                case AppModuleCrudState.New:
                    RefButSave.Visible    = true;
                    RefButCancel.Visible  = true;
                    RefButDelete.Enabled  = false;
                    RefButNew.Enabled     = false;
                    RefButEdit.Enabled    = false;
                    RefButRefresh.Enabled = false;
                    RefDataGrid.Enabled   = false;
                    break;

                case AppModuleCrudState.Edit:
                    RefButSave.Visible    = true;
                    RefButCancel.Visible  = true;
                    RefButDelete.Enabled  = false;
                    RefButNew.Enabled     = false;
                    RefButEdit.Enabled    = false;
                    RefButRefresh.Enabled = false;
                    RefDataGrid.Enabled   = false;
                    break;

                case AppModuleCrudState.Delete:
                    break;
                }
            }
            catch (Exception Ex)
            {
                return;
            }
        }
コード例 #2
0
        public void UpdateRowSelectIndex(int RowIndex)
        {
            CurrentSelectedRow = null;

            if (RefDataGrid.DataSource == null)
            {
                return;
            }

            if (RowIndex < 0)
            {
                SetCrudControls(AppModuleCrudState.Brows);
                return;
            }

            if (RowIndex > RefDataGrid.Rows.Count)
            {
                SetCrudControls(AppModuleCrudState.Brows);
                return;
            }

            try
            {
                DataTable table   = RefDataGrid.DataSource as DataTable;
                DataRow   dataRow = table.NewRow();

                try
                {
                    dataRow = ((DataRowView)RefDataGrid.SelectedRows[0].DataBoundItem).Row;
                }catch (Exception Ex)
                { return; }

                dynamic dataRowObj;
                dataRowObj         = DataRowToObject(dataRow);
                CurrentSelectedRow = dataRowObj;

                if (dataRowObj != null)
                {
                    if (onRowDataNotification != null)
                    {
                        CrudModeNotificationArgs crudNotifyArgs = new CrudModeNotificationArgs();
                        crudNotifyArgs.SelectedCrudMode     = _crudMode;
                        crudNotifyArgs.RowData              = dataRowObj;
                        crudNotifyArgs.CurrentSelectedIndex = this.GridSelectedIndex;

                        onRowDataNotification(this, crudNotifyArgs);
                    }
                }
                //string dataRowObjectStr = JsonConvert.SerializeObject((dataRowObj));

                if (dataRowObj == null)
                {
                    SetCrudControls(AppModuleCrudState.Brows);
                    return;
                }
            }catch (Exception Ex)
            {
                SetCrudControls(AppModuleCrudState.Brows);
                CurrentSelectedRow = null;
                return;
            }
        }