/// <summary> /// initialization of the whole log /// </summary> public void Init() { Cursor oldCursor = Cursor; try { Cursor = Cursors.WaitCursor; m_InitialTopOfGrid = dgvCommandersLog.Top; m_InitialTopOfEditGroupBox = gbCL_LogEdit.Top; m_CL_State = enCLAction.None; cbLogSystemName.SelectedIndexChanged += cbLogSystemName_SelectedIndexChanged; //preparing the combo boxes m_DataSource.prepareCmb_EventTypes(ref cbLogEventType); m_DataSource.prepareCmb_EventTypes(ref cbLogSystemName); m_DataSource.prepareCmb_EventTypes(ref cbLogStationName, cbLogSystemName); m_DataSource.prepareCmb_EventTypes(ref cbLogCargoName); m_DataSource.prepareCmb_EventTypes(ref cbLogCargoAction); dtpLogEventDate.CustomFormat = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern + " " + System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.LongTimePattern; dtpLogEventDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom; setCLFieldsEditable(false); // preparing the datagridview dgvCommandersLog.VirtualMode = true; dgvCommandersLog.ReadOnly = true; dgvCommandersLog.AllowUserToAddRows = false; dgvCommandersLog.AllowUserToOrderColumns = false; dgvCommandersLog.RowCount = m_DataSource.InitRetriever(); ((DataGridViewAutoFilterMultiColumnHeaderCell)dgvCommandersLog.Columns["eventtype"].HeaderCell).Retriever = m_DataSource.Retriever; ((DataGridViewAutoFilterMultiColumnHeaderCell)dgvCommandersLog.Columns["eventtype"].HeaderCell).RetrieverSQLSelect = "select distinct E.eventtype"; ((DataGridViewAutoFilterFullColumnHeaderCell)dgvCommandersLog.Columns["systemname"].HeaderCell).Retriever = m_DataSource.Retriever; ((DataGridViewAutoFilterFullColumnHeaderCell)dgvCommandersLog.Columns["systemname"].HeaderCell).RetrieverSQLSelect = "select distinct E.systemname"; ((DataGridViewAutoFilterFullColumnHeaderCell)dgvCommandersLog.Columns["stationname"].HeaderCell).Retriever = m_DataSource.Retriever; ((DataGridViewAutoFilterFullColumnHeaderCell)dgvCommandersLog.Columns["stationname"].HeaderCell).RetrieverSQLSelect = "select distinct E.stationname"; dgvCommandersLog.RowEnter += dgvCommandersLog_RowEnter; dgvCommandersLog.RowPrePaint += dgvCommandersLog_RowPrePaint; dgvCommandersLog.Paint += dgvCommandersLog_Paint; m_GUIInterface = new DBGuiInterface(DB_GROUPNAME, new DBConnector(Program.DBCon.ConfigData, true)); m_GUIInterface.loadAllSettings(this); Cursor = oldCursor; } catch (Exception ex) { Cursor = oldCursor; throw new Exception("Error during initialization the commanders log tab", ex); } }
private void cmdCL_Cancel_Click(object sender, EventArgs e) { try { showRowInFields(new DataGridViewCellEventArgs(dgvCommandersLog.CurrentCellAddress.X, dgvCommandersLog.CurrentCellAddress.Y)); setCLFieldsEditable(false); m_CL_State = enCLAction.None; } catch (Exception ex) { CErr.processError(ex, "Error while cancel editing entry"); } }
/// <summary> /// initiates the save procedure /// (copying data to the datacache (trough DataGridView) and writing changes to DB) /// </summary> private void saveLogEntry() { Double Distance; DataGridViewRow currentRow; try { setCLFieldsEditable(false); dgvCommandersLog.ReadOnly = false; if (dgvCommandersLog.CurrentRow == null) { dgvCommandersLog.Rows.Add(); currentRow = dgvCommandersLog.Rows[dgvCommandersLog.RowCount-1]; } else currentRow = dgvCommandersLog.Rows[dgvCommandersLog.CurrentRow.Index]; //dgvCommandersLog.Rows.Add() // put the changed data into the DataGridView (this will fire the "CellValuePushed"-event) currentRow.Cells["eventtype"].Value = cbLogEventType.Text; currentRow.Cells["time"].Value = dtpLogEventDate.Value; currentRow.Cells["systemname"].Value = cbLogSystemName.Text; currentRow.Cells["stationname"].Value = cbLogStationName.Text; currentRow.Cells["credits_transaction"].Value = nbTransactionAmount.Value; currentRow.Cells["credits_total"].Value = nbCurrentCredits.Value; currentRow.Cells["loccommodity"].Value = cbLogCargoName.Text; currentRow.Cells["action"].Value = cbLogCargoAction.Text; currentRow.Cells["cargovolume"].Value = nbLogQuantity.Value; currentRow.Cells["notes"].Value = tbLogNotes.Text; currentRow.Cells["distance"].Value = txtLogDistance.Value.ToString().ToNString(); dgvCommandersLog.ReadOnly = true; // save changed data (from data cache through "CellValuePushed"-event) to database m_DataSource.SaveEvent((dsEliteDB.vilogRow)m_DataSource.Retriever.MemoryCache.RetrieveDataColumn(dgvCommandersLog.CurrentRow.Index)); m_CL_State = enCLAction.None; } catch (Exception ex) { CErr.processError(ex, "Error while saving entry"); } }
/// <summary> /// prepares a new lof event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdCL_PrepareNew_Click(object sender, EventArgs e) { try { m_CL_State = enCLAction.Add; setCLFieldsEditable(true, true); cbLogEventType.SelectedValue = (Int32)12; dtpLogEventDate.Value = (DateTime)DateTime.UtcNow; cbLogSystemName.Text = Program.actualCondition.System; cbLogStationName.Text = Program.actualCondition.Station; nbTransactionAmount.Text = "0"; nbCurrentCredits.Text = Program.CompanionIO.SGetCreditsTotal().ToString(); cbLogCargoName.Text = ""; cbLogCargoAction.Text = ""; nbLogQuantity.Text = "0"; tbLogNotes.Text = ""; txtLogDistance.Text = ""; } catch (Exception ex) { CErr.processError(ex, "Error while preparing new entry"); } }
/// <summary> /// initates editing of the editable fields /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdCL_EditEntry_Click(object sender, EventArgs e) { try { RefreshSystemComboBoxData(); RefreshStationComboBoxData(); m_CL_State = enCLAction.Edit; setCLFieldsEditable(true); } catch (Exception ex) { CErr.processError(ex, "Error while start editing entry"); } }
/// <summary> /// initates editing of the editable fields /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdCL_EditEntry_Click(object sender, EventArgs e) { try { m_CL_State = enCLAction.Edit; setCLFieldsEditable(true); } catch (Exception ex) { cErr.showError(ex, "Error while start editing entry"); } }