//добавление коэффициента или ставки НДС private void txtFactAndTax_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { double cost = double.Parse(SharedMethods.Convert(txtCost.Text)); double factor = double.Parse(SharedMethods.Convert(txtFactor.Text)); double tax = double.Parse(SharedMethods.Convert(txtTaxRate.Text)); //расчёт Итого double price = (cost * factor) + ((tax / 100) * cost); txtPrice.Text = price.ToString(); } }
//Сохранить private void btnSave_Click(object sender, EventArgs e) { int result = 0; foreach (Control ctr in this.Controls) { if (ctr.GetType() == typeof(TextBox)) { if (string.IsNullOrEmpty(ctr.Text)) { ctr.Focus(); ctr.BackColor = Color.MistyRose; SystemSounds.Beep.Play(); return; } } } //запоминаем заказ if (LastOrder == null) { LastOrder = new Order(); LastOrder.OrderGuid = Guid.NewGuid(); } LastOrder.Customer = txtCustomer.Text; LastOrder.Number = txtNumber.Text; LastOrder.Cost = decimal.Parse(SharedMethods.Convert(txtPrice.Text)); LastOrder.Factor = decimal.Parse(SharedMethods.Convert(txtFactor.Text)); LastOrder.TaxRate = int.Parse(txtTaxRate.Text); LastOrder.Price = decimal.Parse(SharedMethods.Convert(txtPrice.Text)); LastOrder.Status = (int)cmbStatus.SelectedValue; LastOrder.ModifiedDate = DateTime.Now; DbService db = new DbService(); db.Save(LastOrder, (ord) => (i) => i.OrderGuid == ord.OrderGuid); if (result > 0) { MessageBox.Show($"Успешно сохранено в базе данных", "Сохранение в БД", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.DialogResult = DialogResult.OK; Close(); }
public OrderForm(Order order) { InitializeComponent(); LastOrder = order; if (LastOrder != null) { txtNumber.Text = LastOrder.Number; txtCustomer.Text = LastOrder.Customer; txtCost.Text = LastOrder.Cost.ToString(); txtFactor.Text = LastOrder.Factor.ToString(); txtTaxRate.Text = LastOrder.TaxRate.ToString(); txtPrice.Text = LastOrder.Price.ToString(); } else { txtCost.Text = txtPrice.Text = SharedMethods.Convert("0.00"); } }