private void ReadData() { ExpensePerOperation exp = new ExpensePerOperation(""); if (_parentForm.ExpensePerOperation == null) { var result = OperatingExpenses.ReadData(_samplingGUID); exp = result.exp; } else { exp = _parentForm.ExpensePerOperation; } //IsNew = !result.success; txtCostOfFishing.Text = exp.CostOfFishing.ToString(); txtIncomeSales.Text = exp.IncomeFromFishSale.ToString(); txtROI.Text = exp.ReturnOfInvestment.ToString(); txtWeightConsumed.Text = exp.WeightFishConsumed.ToString(); foreach (var item in exp.ExpenseItemsList) { var lvi = lvExpenseItems.Items.Add(item.Key, item.Value.ExpenseItem, null); lvi.SubItems.Add(item.Value.ItemCost.ToString()); lvi.SubItems.Add(item.Value.Unit); lvi.SubItems.Add(item.Value.UnitQuantity.ToString()); } }
public void LoadSpecsAndExpenses() { lblRefNumber.Text = $"Reference No: {RefNumber}"; if (SamplingGuid.Length > 0) { var s = ManageGearSpecsClass.GetSampledSpecsEx(SamplingGuid); if (s.Length == 0) { txtGearSpecs.Text = "Gear specs not found"; } else { txtGearSpecs.Text = s; } var result = OperatingExpenses.ReadData(SamplingGuid, true); if (result.success) { var expenseItem = result.exp; txtExpenses.Text = OperatingExpenses.SamplingExpenses; } else { txtExpenses.Text = "Fishing operation expenses not found"; } } }
private void OnButtonClick(object sender, EventArgs e) { switch (((Button)sender).Name) { case "btnDelete": DialogResult deleteDr = MessageBox.Show("Delete fishing operating costs for this sampling?", "Please confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (deleteDr == DialogResult.Yes && OperatingExpenses.Delete(_samplingGUID)) { lvExpenseItems.Items.Clear(); foreach (Control c in Controls) { if (c.GetType().Name == "TextBox") { c.Text = ""; } } _expensesDeleted = true; _parentForm.SamplingFishingOperatingExpenseDeleted(); Close(); } break; case "btnAdd": ShowEditItemForm(); break; case "btnRemove": if (lvExpenseItems.SelectedItems.Count > 0) { lvExpenseItems.Items.Remove(lvExpenseItems.SelectedItems[0]); } break; case "btnOK": if (ValidateExpenses() && PreSaveExpense(_dataStatus)) { _parentForm.UpdateExpenses(); Close(); } else { MessageBox.Show("Cannot accept blank expense. At least one item must be filled up", "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case "btnCancel": Close(); break; } }
private void OnFieldValidating(object sender, CancelEventArgs e) { string s = ((Control)sender).Text; string controlName = ((Control)sender).Name; string msg = ""; if (s.Length > 0) { switch (controlName) { case "txtCost": case "txtUnitQuantity": if (double.TryParse(s, out double v)) { if (v < 0) { msg = "Expected value is numeric and must not be less than zero"; e.Cancel = true; } } else { msg = "Expected value is numeric and must not be less than zero"; e.Cancel = true; } break; case "cboSelection": case "cboUnit": ComboBox cbo = (ComboBox)sender; if (s.Length < 2) { e.Cancel = true; msg = "Item is too short. Make it at least 3 letters long"; } else { if (!cbo.Items.Contains(s)) { DialogResult dr = MessageBox.Show($"{s} was not found in the selection\r\nDo you want to add {s} to the list?", "Confirmation needed", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.Yes) { switch (controlName) { case "cboSelection": if (OperatingExpenses.AddExpenseItemToSelection(s)) { cboSelection.Items.Add(s); cboSelection.Text = s; } break; case "cboUnit": if (OperatingExpenses.AddExpenseUnitToSelection(s)) { cboUnit.Items.Add(s); cboUnit.Text = s; } break; } } else { msg = "Select an item in the drop-down list"; e.Cancel = true; } } } break; } } if (e.Cancel) { MessageBox.Show(msg, "Validation error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }