protected virtual void OnSetupData() { //load all lookups foreach (JkLookUpComboBox comboBox in IAppHandler.FindControlByType("JkLookUpComboBox", this)) { comboBox.LoadData(); } //clear all datatables VMasterDataTable.Clear(); foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { DataSet.DataTable.Clear(); } if (CommandText != null && CommandText != "") { VTransactionHandler.LoadData(CommandText, ref VMasterDataTable, this.Parameters); } if (SetupData != null) { SetupData(); } }
private void AssignEventOnButtons() { btnNew.Click += (obj, e) => { if (!btnNew.Visible || !btnNew.Enabled) { return; } try { IAppHandler.StartBusy("Executing New"); FormState = FormStates.fsNew; Run(); VMasterDataTable.Clear(); foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { DataSet.DataTable.Clear(); } } finally { IAppHandler.EndBusy("Executing New"); } }; btnEdit.Click += (obj, e) => { if (!btnEdit.Visible || !btnEdit.Enabled) { return; } try { IAppHandler.StartBusy("Executing Edit"); FormState = FormStates.fsEdit; Run(); } finally { IAppHandler.EndBusy("Executing Edit"); } }; btnSave.Click += (obj, e) => { Control focusedControl = IAppHandler.FindFocusedControl(this); if (!btnSave.Visible || !btnSave.Enabled) { return; } //remove focus on databound controls, so that it will perform its validation or computation this.splitContainer.Panel2.Focus(); //perform Validation first OnValidateSave(); if (ValidationFails) { if (focusedControl != null) { focusedControl.Select(); } return; } if (IMessageHandler.Confirm(ISystemMessages.SavingQuestion) == DialogResult.Yes) { try { IAppHandler.StartBusy("Executing Save"); OnBeforeSave(); //this should be called after before save, so that before save can be used on //performing operations before assigning it to MasterColumns SetColumnsValue(); try { try { //all of the events which interacts with the database //should be just put in one connection, so if in case //error occurs all the processes will be rolled back VTransactionHandler.Connect(); VTransactionHandler.BeginTran(); if (FormState == FormStates.fsEdit) { UnPost(); } if (FormState == FormStates.fsNew) { VTransactionHandler.SaveMaster(CommandText, ref VMasterDataTable, Parameters); SaveDetail(); } else if (FormState == FormStates.fsEdit) { VTransactionHandler.EditMaster(CommandText, Parameters); EditDetail(); } Post(); VTransactionHandler.CommitTran(); } catch (Exception ex) { VTransactionHandler.Rollback(); if (FormState == FormStates.fsNew) { IMessageHandler.ShowError(ISystemMessages.SaveDataError + ex.Message); } else { IMessageHandler.ShowError(ISystemMessages.EditDataError + ex.Message); } return; } } finally { VTransactionHandler.Disconnect(); } if (FormState == FormStates.fsNew) { KeyList.Add(Parameters[0].Value); KeyId = KeyList.Count() - 1; } OnAfterSave(); FormState = FormStates.fsView; Run(); } finally { IAppHandler.EndBusy("Executing Save"); } } }; btnCancel.Click += (obj, e) => { if (!btnCancel.Visible || !btnCancel.Enabled) { return; } if (IMessageHandler.Confirm(ISystemMessages.ClosingOrCancellingQuestion) == DialogResult.Yes) { this.splitContainer.Panel2.Focus(); try { IAppHandler.StartBusy("Executing Cancel"); if (FormState == FormStates.fsNew) { if (ParametersHasValues()) { FormState = FormStates.fsView; Run(); } else { CloseForm(); } } else { FormState = FormStates.fsView; Run(); } } finally { IAppHandler.EndBusy("Executing Cancel"); } } }; btnFirstRecord.Click += (obj, e) => { if (!btnFirstRecord.Visible || !btnFirstRecord.Enabled) { return; } ReQuery(obj, e); }; btnPreviousRecord.Click += (obj, e) => { if (!btnPreviousRecord.Visible || !btnPreviousRecord.Enabled) { return; } ReQuery(obj, e); }; btnNextRecord.Click += (obj, e) => { if (!btnNextRecord.Visible || !btnNextRecord.Enabled) { return; } ReQuery(obj, e); }; btnLastRecord.Click += (obj, e) => { if (!btnLastRecord.Visible || !btnLastRecord.Enabled) { return; } ReQuery(obj, e); }; }