Focus offers grid on MG select so qty can be typed immediately.

This commit is contained in:
Magomed 2026-07-20 20:02:58 +03:00
parent 5c439fe780
commit 7f3bc2eb35

View File

@ -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,7 +1554,18 @@ and tempOrder.GoodName = PriceList.GoodName
int RowIndex = -1;
string idPriceListItem = string.Empty;
if (_browseMode == PriceBrowseMode.Offers && dgvPriceList.SelectedRows.Count > 0)
if (_browseMode == PriceBrowseMode.Offers)
{
if (IsOrderQuantityStartKey(e.KeyChar))
{
EnsureOffersRowSelected();
if (!dgvPriceList.Focused)
{
dgvPriceList.Focus();
}
}
if (dgvPriceList.SelectedRows.Count > 0)
{
RowIndex = dgvPriceList.SelectedRows[0].Index;
if (RowIndex >= 0
@ -1491,6 +1575,7 @@ and tempOrder.GoodName = PriceList.GoodName
idPriceListItem = dgvPriceList.Rows[RowIndex].Cells[11].Value?.ToString() ?? string.Empty;
}
}
}
if (e.KeyChar == (Char)Keys.Back)
{
@ -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)