private void gridControl_CurrentCellKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F4) { Shortcut(sender, e); return; } if (KeyPressHelper.IsEnter(e)) { if (lblKembalian.Text.Length > 0) { lblKembalian.Text = ""; } var grid = (GridControl)sender; var rowIndex = grid.CurrentCell.RowIndex; var colIndex = grid.CurrentCell.ColIndex; IProdukBll bll = new ProdukBll(_log); Produk produk = null; GridCurrentCell cc; switch (colIndex) { case 2: // kode produk 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) { ShowMessage("Data produk tidak ditemukan", true); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } if (!_pengaturanUmum.is_stok_produk_boleh_minus) { if (produk.is_stok_minus) { ShowMessage("Maaf stok produk tidak boleh minus", true); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } } ShowMessage(""); double diskon = 0; if (_customer != null) { diskon = _customer.diskon; } if (!(diskon > 0)) { var diskonProduk = GetDiskonJualFix(produk, 1, produk.diskon); diskon = diskonProduk > 0 ? diskonProduk : produk.Golongan.diskon; } ItemJualProduk itemJual = null; // cek item produk sudah diinputkan atau belum ? var itemProduk = GetExistItemProduk(produk.produk_id); if (itemProduk != null) // sudah ada, tinggal update jumlah { var index = _listOfItemJual.IndexOf(itemProduk); UpdateItemProduk(grid, index); cc.Renderer.ControlText = string.Empty; itemJual = _listOfItemJual[index]; } else { SetItemProduk(grid, rowIndex, produk, diskon: diskon); itemJual = _listOfItemJual[rowIndex - 1]; if (grid.RowCount == rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); grid.RowCount = _listOfItemJual.Count; } } grid.Refresh(); RefreshTotal(); DisplayItemProduct(itemJual); if (_pengaturanUmum.is_tampilkan_keterangan_tambahan_item_jual) { // fokus ke kolom keterangan GridListControlHelper.SetCurrentCell(grid, rowIndex, 4); } else { if (_pengaturanUmum.is_fokus_input_kolom_jumlah) { GridListControlHelper.SetCurrentCell(grid, rowIndex, 5); // fokus ke kolom jumlah } else { GridListControlHelper.SetCurrentCell(grid, _listOfItemJual.Count, 2); // pindah kebaris berikutnya } } } break; case 3: // pencarian berdasarkan nama produk cc = grid.CurrentCell; var namaProduk = cc.Renderer.ControlValue.ToString(); if (namaProduk.Length == 0) { ShowMessage("Nama produk tidak boleh kosong", true); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } var listOfProduk = bll.GetByName(namaProduk, false); if (listOfProduk.Count == 0) { ShowMessage("Data produk tidak ditemukan", true); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); } else if (listOfProduk.Count == 1) { ShowMessage(""); produk = listOfProduk[0]; IHargaGrosirBll hargaGrosirBll = new HargaGrosirBll(_log); produk.list_of_harga_grosir = hargaGrosirBll.GetListHargaGrosir(produk.produk_id).ToList(); if (!_pengaturanUmum.is_stok_produk_boleh_minus) { if (produk.is_stok_minus) { ShowMessage("Maaf stok produk tidak boleh minus", true); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } } double diskon = 0; if (_customer != null) { diskon = _customer.diskon; } if (!(diskon > 0)) { var diskonProduk = GetDiskonJualFix(produk, 1, produk.diskon); diskon = diskonProduk > 0 ? diskonProduk : produk.Golongan.diskon; } ItemJualProduk itemJual = null; // cek item produk sudah diinputkan atau belum ? var itemProduk = GetExistItemProduk(produk.produk_id); if (itemProduk != null) // sudah ada, tinggal update jumlah { var index = _listOfItemJual.IndexOf(itemProduk); UpdateItemProduk(grid, index); cc.Renderer.ControlText = string.Empty; itemJual = _listOfItemJual[index]; } else { SetItemProduk(grid, rowIndex, produk, diskon: diskon); itemJual = _listOfItemJual[rowIndex - 1]; if (grid.RowCount == rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); grid.RowCount = _listOfItemJual.Count; } } grid.Refresh(); RefreshTotal(); DisplayItemProduct(itemJual); if (_pengaturanUmum.is_tampilkan_keterangan_tambahan_item_jual) { // fokus ke kolom keterangan GridListControlHelper.SetCurrentCell(grid, rowIndex, 4); } else { if (_pengaturanUmum.is_fokus_input_kolom_jumlah) { GridListControlHelper.SetCurrentCell(grid, rowIndex, 5); // fokus ke kolom jumlah } else { GridListControlHelper.SetCurrentCell(grid, _listOfItemJual.Count, 2); // pindah kebaris berikutnya } } } else // data lebih dari satu { ShowMessage(""); _rowIndex = rowIndex; _colIndex = colIndex; var frmLookup = new FrmLookupReferensi("Data Produk", listOfProduk); frmLookup.Listener = this; frmLookup.ShowDialog(); } break; case 4: // keterangan if (grid.RowCount == rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); grid.RowCount = _listOfItemJual.Count; } if (_pengaturanUmum.is_fokus_input_kolom_jumlah) { GridListControlHelper.SetCurrentCell(grid, rowIndex, 5); // fokus ke kolom jumlah } else { GridListControlHelper.SetCurrentCell(grid, _listOfItemJual.Count, 2); // pindah kebaris berikutnya } break; case 5: // jumlah if (!_pengaturanUmum.is_stok_produk_boleh_minus) { gridControl_CurrentCellValidated(sender, new EventArgs()); var itemJual = _listOfItemJual[rowIndex - 1]; produk = itemJual.Produk; var isValidStok = (produk.sisa_stok - itemJual.jumlah) >= 0; if (!isValidStok) { ShowMessage("Maaf stok produk tidak boleh minus", true); GridListControlHelper.SelectCellText(grid, rowIndex, colIndex); return; } } if (grid.RowCount == rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); grid.RowCount = _listOfItemJual.Count; } GridListControlHelper.SetCurrentCell(grid, _listOfItemJual.Count, 2); // pindah kebaris berikutnya break; case 6: // diskon if (grid.RowCount == rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); grid.RowCount = _listOfItemJual.Count; } GridListControlHelper.SetCurrentCell(grid, _listOfItemJual.Count, 2); break; case 7: if (grid.RowCount == rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); grid.RowCount = _listOfItemJual.Count; } GridListControlHelper.SetCurrentCell(grid, _listOfItemJual.Count, 2); // fokus ke kolom kode produk break; default: break; } } }
public void Ok(object sender, object data) { // filter berdasarkan data if (data is Produk) // pencarian produk baku { var produk = (Produk)data; IHargaGrosirBll hargaGrosirBll = new HargaGrosirBll(_log); produk.list_of_harga_grosir = hargaGrosirBll.GetListHargaGrosir(produk.produk_id).ToList(); if (!_pengaturanUmum.is_stok_produk_boleh_minus) { if (produk.is_stok_minus) { ShowMessage("Maaf stok produk tidak boleh minus", true); GridListControlHelper.SelectCellText(this.gridControl, _rowIndex, 3); return; } } double diskon = 0; if (_customer != null) { diskon = _customer.diskon; } if (!(diskon > 0)) { var diskonProduk = GetDiskonJualFix(produk, 1, produk.diskon); diskon = diskonProduk > 0 ? diskonProduk : produk.Golongan.diskon; } ItemJualProduk itemJual = null; // cek item produk sudah diinputkan atau belum ? var itemProduk = GetExistItemProduk(produk.produk_id); if (itemProduk != null) // sudah ada, tinggal update jumlah { var index = _listOfItemJual.IndexOf(itemProduk); UpdateItemProduk(this.gridControl, index); this.gridControl.GetCellRenderer(_rowIndex, _colIndex).ControlText = string.Empty; itemJual = _listOfItemJual[index]; } else { SetItemProduk(this.gridControl, _rowIndex, produk, diskon: diskon); itemJual = _listOfItemJual[_rowIndex - 1]; if (this.gridControl.RowCount == _rowIndex) { _listOfItemJual.Add(new ItemJualProduk()); this.gridControl.RowCount = _listOfItemJual.Count; } } this.gridControl.Refresh(); RefreshTotal(); DisplayItemProduct(itemJual); if (_pengaturanUmum.is_tampilkan_keterangan_tambahan_item_jual) { // fokus ke kolom keterangan GridListControlHelper.SetCurrentCell(this.gridControl, _rowIndex, 4); } else { if (_pengaturanUmum.is_fokus_input_kolom_jumlah) { GridListControlHelper.SetCurrentCell(this.gridControl, _rowIndex, 5); // fokus ke kolom jumlah } else { if (itemProduk != null) { GridListControlHelper.SetCurrentCell(this.gridControl, _rowIndex, 2); // fokus ke kolom kode } else { GridListControlHelper.SetCurrentCell(this.gridControl, _rowIndex + 1, 2); // fokus kebaris berikutnya } } } } else if (data is Customer) // pencarian customer { this._customer = (Customer)data; txtCustomer.Text = this._customer.nama_customer; ShowMessage(""); lblStatusBar.Text = lblStatusBar.Text.Replace("Cari Pelanggan", "Reset Pelanggan"); KeyPressHelper.NextFocus(); } else if (data is JualProduk) // pembayaran { var jual = (JualProduk)data; if (_pengaturanUmum.is_auto_print) { if (_isCetakStruk) { switch (_pengaturanUmum.jenis_printer) { case JenisPrinter.DotMatrix: CetakNotaDotMatrix(_jual); break; case JenisPrinter.MiniPOS: CetakNotaMiniPOS(_jual); break; default: // do nothing break; } } } var kembalian = Math.Abs(jual.jumlah_bayar - jual.grand_total); DisplayKembalian(NumberHelper.NumberToString(kembalian)); tmrDisplayKalimatPenutup.Enabled = true; lblKembalian.Text = string.Format("Kembalian: {0}", NumberHelper.NumberToString(kembalian)); ResetTransaksi(false); } else // filter bardasarkan nama form { var frmName = sender.GetType().Name; switch (frmName) { case "FrmHapusItemTransaksi": var noTransaksi = (int)((dynamic)data).noTransaksi; var itemJual = _listOfItemJual[noTransaksi - 1]; itemJual.entity_state = EntityState.Deleted; _listOfItemJual.Remove(itemJual); gridControl.RowCount = _listOfItemJual.Count(); gridControl.Refresh(); RefreshTotal(); GridListControlHelper.SetCurrentCell(gridControl, _listOfItemJual.Count, 2); break; default: break; } } }