diff --git a/src/ElectronicPharmacy/UserControls/UCPriceList.cs b/src/ElectronicPharmacy/UserControls/UCPriceList.cs index f833035..8bedd83 100644 --- a/src/ElectronicPharmacy/UserControls/UCPriceList.cs +++ b/src/ElectronicPharmacy/UserControls/UCPriceList.cs @@ -741,6 +741,79 @@ namespace Электронная_Фармация.UserControls AppDebugLog.Error("PriceList", "Не удалось применить фильтр наименование+МГ", ex); bsPriceList.RemoveFilter(); } + + FocusOffersGridForInput(); + } + + private void FocusOffersGridForInput() + { + if (!IsHandleCreated) + { + return; + } + + BeginInvoke(new Action(() => + { + if (_browseMode != PriceBrowseMode.Offers || !dgvPriceList.Visible) + { + return; + } + + EnsureOffersRowSelected(); + dgvPriceList.Focus(); + })); + } + + private bool EnsureOffersRowSelected() + { + if (_browseMode != PriceBrowseMode.Offers || dgvPriceList.Rows.Count == 0) + { + return false; + } + + if (dgvPriceList.SelectedRows.Count > 0) + { + return true; + } + + for (var i = 0; i < dgvPriceList.Rows.Count; i++) + { + var row = dgvPriceList.Rows[i]; + if (row.IsNewRow) + { + continue; + } + + _suppressPriceListSelectionEvents = true; + try + { + row.Selected = true; + var columnIndex = GetPreferredOffersSelectionColumnIndex(); + if (columnIndex >= 0 && columnIndex < row.Cells.Count) + { + dgvPriceList.CurrentCell = row.Cells[columnIndex]; + } + } + finally + { + _suppressPriceListSelectionEvents = false; + } + + ShowMePriceWithMarkupPercentForSelectedGood(); + return true; + } + + return false; + } + + private int GetPreferredOffersSelectionColumnIndex() + { + if (dgvPriceList.Columns.Contains("Наименование")) + { + return dgvPriceList.Columns["Наименование"].Index; + } + + return dgvPriceList.Columns.Count > 3 ? 3 : 0; } private void BindOffersTable() @@ -1481,14 +1554,26 @@ and tempOrder.GoodName = PriceList.GoodName int RowIndex = -1; string idPriceListItem = string.Empty; - if (_browseMode == PriceBrowseMode.Offers && dgvPriceList.SelectedRows.Count > 0) + if (_browseMode == PriceBrowseMode.Offers) { - RowIndex = dgvPriceList.SelectedRows[0].Index; - if (RowIndex >= 0 - && RowIndex < dgvPriceList.Rows.Count - && dgvPriceList.Rows[RowIndex].Cells.Count > 11) + if (IsOrderQuantityStartKey(e.KeyChar)) { - idPriceListItem = dgvPriceList.Rows[RowIndex].Cells[11].Value?.ToString() ?? string.Empty; + EnsureOffersRowSelected(); + if (!dgvPriceList.Focused) + { + dgvPriceList.Focus(); + } + } + + if (dgvPriceList.SelectedRows.Count > 0) + { + RowIndex = dgvPriceList.SelectedRows[0].Index; + if (RowIndex >= 0 + && RowIndex < dgvPriceList.Rows.Count + && dgvPriceList.Rows[RowIndex].Cells.Count > 11) + { + idPriceListItem = dgvPriceList.Rows[RowIndex].Cells[11].Value?.ToString() ?? string.Empty; + } } } @@ -2117,6 +2202,12 @@ and SumOrderedItems = '{SumOrder}'"; return builder.ToString(); } + private static bool IsOrderQuantityStartKey(char keyChar) + { + return (keyChar >= (char)Keys.D1 && keyChar <= (char)Keys.D9) + || (keyChar >= (char)Keys.NumPad1 && keyChar <= (char)Keys.NumPad9); + } + private void dgvPriceList_SelectionChanged(object sender, EventArgs e) { if (_suppressPriceListSelectionEvents)