//Сохранить 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(); }
//поиск по имени или референсу private void txtSearch_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!string.IsNullOrEmpty(txtSearch.Text)) { var source = (IEnumerable <Component>)componentBindingSource.DataSource; SharedMethods.Search(componentBindingSource, source, (list) => (c) => { return(c.Name.ToUpper().Contains(txtSearch.Text.ToUpper()) || c.Reference.ToUpper().Contains(txtSearch.Text.ToUpper())); }); } else { componentBindingSource.DataSource = db.GetComponents(); } } }
//Поиск по наименованию заказчика или номеру заказа private void txtSearch_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (!string.IsNullOrEmpty(txtSearch.Text)) { var source = (IEnumerable <Order>)orderBindingSource.DataSource; SharedMethods.Search(orderBindingSource, source, (list) => (o) => { return(o.Customer.ToUpper().Contains(txtSearch.Text.ToUpper()) || o.Number.ToUpper().Contains(txtSearch.Text.ToUpper())); }); } else { ResetBindingSource(); } } }
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"); } }
private void ResetBindingSource() { orderBindingSource.DataSource = db.GetOrders().OrderBy(o => o.ModifiedDate); SharedMethods.GetOrderStatus(StatusDgvColumn); }