private void btnClose_Click(object sender, EventArgs e) { if (!btnClose.Visible || !btnClose.Enabled) { return; } splitContainer.Panel2.Focus(); if (FormState == FormStates.fsNew || FormState == FormStates.fsEdit) { if (IMessageHandler.Confirm(ISystemMessages.ClosingOrCancellingQuestion) == DialogResult.No) { return; } } CloseForm(); }
private void cmbSubsidiary_SelectedIndexChanged(object sender, EventArgs e) { if (FormState == FormStates.fsView || !EditingReady) { return; } String CommandText = "EXEC uspGetUnpaidInvoice @Id, @SubsidiaryId"; SqlDataAdapter Adapter = new SqlDataAdapter(CommandText, Properties.Settings.Default.FreeAccountingSoftwareConnectionString); DataTable table = new DataTable(); int Id = 0; try { Adapter.SelectCommand.Parameters.AddWithValue("@Id", Id); Adapter.SelectCommand.Parameters.AddWithValue("@SubsidiaryId", cmbSubsidiary.SelectedValue); Adapter.Fill(table); if (table.Rows.Count == 0) { foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Index != dataGridView.NewRowIndex) { dataGridView.Rows.Remove(row); //clear the grid rather than the datatable } } IMessageHandler.Inform(ISystemMessages.NoPendingInvoice); return; } if (FormState == FormStates.fsNew || (FormState == FormStates.fsEdit && IMessageHandler.Confirm(ISystemMessages.RemovePaidInvoice) == DialogResult.Yes)) { foreach (DataGridViewRow row in dataGridView.Rows) { if (row.Index != dataGridView.NewRowIndex) { dataGridView.Rows.Remove(row); } } } foreach (DataRow row in table.Rows) { DataRow newRow = dstDetail.DataTable.NewRow(); foreach (DataColumn column in table.Columns) { newRow[column.ColumnName] = row[column.ColumnName]; } dstDetail.DataTable.Rows.Add(newRow); } } finally { Adapter.Dispose(); table.Dispose(); } }
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); }; }