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(); } }
//check if all required columns are filled up private void IMasterDetailForm_ValidateSave() { foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { foreach (JkDetailColumn column in DataSet.Columns) { if (column.Required) { foreach (DataRow row in DataSet.DataTable.Rows) { if (row.RowState != DataRowState.Deleted) { if (((row[column.Name] == null || row[column.Name] == DBNull.Value) && String.IsNullOrWhiteSpace(column.ControlName)) || (!String.IsNullOrWhiteSpace(column.ControlName) && int.Parse(row[column.Name].ToString()) == 0)) { IMessageHandler.Inform(ISystemMessages.FillRequiredFieldOnGridMessage(column.Caption)); ValidationFails = true; return; } } } } } } }
private void IMasterForm_SetupData() { foreach (JkLookUpComboBox comboBox in IAppHandler.FindControlByType("JkLookUpComboBox", this)) { if (FormState == FormStates.fsView) { comboBox.RemoveFilterOnDataSource(); } else { comboBox.FilterDataSource(); } } if (FormState == FormStates.fsNew) { AssignControlsDefaultValue(); } else { AssignValuesToControls(); } InitSeriesProviders(); }
private void IMasterDetailForm_BeforeSave() { //remove temporary columns so that it will not cause //malfuction on DataAdapter.Update function foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { DataSet.RemoveTemporaryColumns(); } }
protected override void SaveDetail() { base.SaveDetail(); foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { if (!String.IsNullOrWhiteSpace(DataSet.CommandText) && DataSet.LinkToMaster) { VTransactionHandler.SaveDetail(DataSet.CommandText, DataSet.DataTable, Parameters, DataSet.Parameters); } } }
private void IMasterForm_AfterSave() { if (FormState == FormStates.fsNew) { foreach (JkSeriesProvider series in IAppHandler.FindControlByType("JkSeriesProvider", this)) { series.UpdateSeries(); } } RefreshDataSet(); }
private void IMasterDetailForm_SetupData() { foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { if (!String.IsNullOrWhiteSpace(DataSet.CommandText) && DataSet.LinkToMaster) { DataSet.Parameters.Find(dp => dp.Name == "Id").Value = Parameters.Find(p => p.Name == "Id").Value; if (!String.IsNullOrWhiteSpace(DataSet.CommandText)) { DataSet.DataTable = VTransactionHandler.LoadData(DataSet.CommandText, DataSet.Parameters); DataSet.AddTemporaryColumns(); DataSet.GridView.DataSource = DataSet.DataTable; } //For further update on this code, I'm still not sure if this will fit on all scenarios foreach (DataColumn column in DataSet.DataTable.Columns) { if (!column.AllowDBNull && column.DataType.ToString() == "System.Int32" && !column.AutoIncrement) { if (FormState == FormStates.fsNew) { column.DefaultValue = -1; } else { column.DefaultValue = Parameters.Find(p => p.Name == "Id").Value; } } } } //load data from lookup to grid foreach (DataGridViewColumn column in DataSet.GridView.Columns) { if (column.GetType().ToString().Contains("DataGridViewComboBoxColumn")) { DataGridViewComboBoxColumn comboBox = column as DataGridViewComboBoxColumn; JkLookUpComboBox lookUp = (Controls.Find(DataSet.Columns.Find(dc => dc.Name == column.DataPropertyName).ControlName, true).First() as JkLookUpComboBox); if (lookUp.Items.Count == 0) { lookUp.LoadData(); } comboBox.DataSource = lookUp.DataSource; comboBox.DisplayMember = lookUp.DisplayText; comboBox.ValueMember = lookUp.Key; } } } }
public void CloseForm() { VMasterDataTable.Clear(); foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { DataSet.DataTable.Clear(); } if (IAppHandler.OpenPreviousForm(this) != null) { IAppHandler.OpenPreviousForm(this).Run(); } this.Dispose(); }
protected override void UpdateControls() { base.UpdateControls(); foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { if (FormState == FormStates.fsView) { DataSet.GridView.EditMode = DataGridViewEditMode.EditProgrammatically; } else { DataSet.GridView.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2; } DataSet.GridView.AllowUserToAddRows = FormState != FormStates.fsView; DataSet.GridView.AllowUserToDeleteRows = FormState != FormStates.fsView; } }
private void IMasterDetailForm_SetupControl() { foreach (JkDetailDataSet DataSet in IAppHandler.FindControlByType("JkDetailDataSet", this)) { //workaround to hide columns that are generated automatically by .Net foreach (DataGridViewColumn column in DataSet.GridView.Columns) { if (!String.IsNullOrWhiteSpace(column.DataPropertyName)) { column.Visible = DataSet.Columns.Find(c => c.Name == column.DataPropertyName).Visible; } } //workaround to fix temporary columns that are not recomputing //after cancelling a transaction DataSet.GridView.ComputeFooterValues(); } splitContainerMasterDetail.Panel1.Focus(); }
private void InitSeriesProviders() { if (FormState == FormStates.fsNew) { foreach (Control control in IAppHandler.FindControlByType("JkSeriesProvider", this)) { JkSeriesProvider series = (control as JkSeriesProvider); series.ConnectionString = Properties.Settings.Default.FreeAccountingSoftwareConnectionString; series.CompanyId = ISecurityHandler.CompanyId.ToString(); series.GetSeries(); foreach (JkMasterColumn column in MasterColumns) { if (column.Name == series.TransactionColumn && !String.IsNullOrWhiteSpace(column.ControlName)) { IAppHandler.SetControlsValue(Controls.Find(column.ControlName, true).First(), series.Value); } } } } }
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); }; }