private void gridControl_CurrentCellKeyDown(object sender, KeyEventArgs e) { if (KeyPressHelper.IsEnter(e)) { var grid = (GridControl)sender; var rowIndex = grid.CurrentCell.RowIndex; var colIndex = grid.CurrentCell.ColIndex; IProdukBll bll = new ProdukBll(MainProgram.isUseWebAPI, MainProgram.baseUrl, _log); Produk produk = null; GridCurrentCell cc; switch (colIndex) { case 2: // kode produk _isValidKodeProduk = false; cc = grid.CurrentCell; var kodeProduk = cc.Renderer.ControlValue.ToString(); if (kodeProduk.Length == 0) // kode produk kosong { // fokus ke kolom nama produk GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 1); } else { // pencarian berdasarkan kode produk produk = bll.GetByKode(kodeProduk); if (produk == null) { MsgHelper.MsgWarning("Data produk tidak ditemukan"); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } _isValidKodeProduk = true; SetItemProduk(grid, rowIndex, produk); grid.Refresh(); RefreshTotal(); GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 2); } break; case 3: // pencarian berdasarkan nama produk cc = grid.CurrentCell; var namaProduk = cc.Renderer.ControlValue.ToString(); if (namaProduk.Length == 0) { MsgHelper.MsgWarning("Nama produk tidak boleh kosong"); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } if (!_isValidKodeProduk) { var listOfProduk = bll.GetByName(namaProduk, false); if (listOfProduk.Count == 0) { MsgHelper.MsgWarning("Data produk tidak ditemukan"); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); } else if (listOfProduk.Count == 1) { produk = listOfProduk[0]; SetItemProduk(grid, rowIndex, produk); grid.Refresh(); RefreshTotal(); GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 1); } else // data lebih dari satu { _rowIndex = rowIndex; _colIndex = colIndex; var frmLookup = new FrmLookupReferensi("Data Produk", listOfProduk, true); frmLookup.Listener = this; frmLookup.ShowDialog(); } } else { GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 1); } break; case 4: // jumlah case 5: // diskon GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 1); break; case 6: if (grid.RowCount == rowIndex) { _listOfItemBeli.Add(new ItemBeliProduk()); grid.RowCount = _listOfItemBeli.Count; } GridListControlHelper.SetCurrentCell(grid, rowIndex + 1, 2); // fokus ke kolom kode produk break; default: break; } } }
private void gridControl_CurrentCellKeyDown(object sender, KeyEventArgs e) { if (KeyPressHelper.IsEnter(e)) { var grid = (GridControl)sender; var rowIndex = grid.CurrentCell.RowIndex; var colIndex = grid.CurrentCell.ColIndex; JenisPengeluaran jenisPengeluaran = null; switch (colIndex) { case 2: // pencarian berdasarkan nama jenis pengeluaran GridCurrentCell cc = grid.CurrentCell; var namaProduk = cc.Renderer.ControlValue.ToString(); IJenisPengeluaranBll bll = new JenisPengeluaranBll(_log); var listOfJenisPengeluaran = bll.GetByName(namaProduk); if (listOfJenisPengeluaran.Count == 0) { MsgHelper.MsgWarning("Data jenis pengeluaran tidak ditemukan"); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); } else if (listOfJenisPengeluaran.Count == 1) { jenisPengeluaran = listOfJenisPengeluaran[0]; if (!IsExist(jenisPengeluaran.jenis_pengeluaran_id)) { SetItemJenisPengeluaran(grid, rowIndex, colIndex, jenisPengeluaran); grid.Refresh(); RefreshTotal(); GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 1); } else { MsgHelper.MsgWarning("Data jenis pengeluaran sudah diinputkan"); GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex); } } else // data lebih dari satu, tampilkan form lookup { _rowIndex = rowIndex; _colIndex = colIndex; var frmLookup = new FrmLookupReferensi("Data Jenis Pengeluaran", listOfJenisPengeluaran); frmLookup.Listener = this; frmLookup.ShowDialog(); } break; case 3: GridListControlHelper.SetCurrentCell(grid, rowIndex, colIndex + 1); break; case 4: if (grid.RowCount == rowIndex) { _listOfItemPengeluaran.Add(new ItemPengeluaranBiaya()); grid.RowCount = _listOfItemPengeluaran.Count; } GridListControlHelper.SetCurrentCell(grid, rowIndex + 1, 2); // fokus ke kolom kode produk break; default: break; } } }