public static void initPaymentMethod(ComboBox comboBox) { Metode_PembayaranModel mpm = new Metode_PembayaranModel(); comboBox.Items.Clear(); foreach (DataRow row in mpm.Table.Select("STATUS ='1'")) { ComboBoxItem cbi = new ComboBoxItem(); cbi.Content = row["NAMA"].ToString(); cbi.Tag = row["ID"].ToString(); comboBox.Items.Add(cbi); } cbPayment = comboBox; }
public static void proceedToCheckout() { //Validasi Promo + Validasi Ada checked + kurir + payment //Validasi Ada barang, string message = validateProceedCheckout(); if (message == "Success") { App.openConnection(out _); using (OracleTransaction Transaction = App.connection.BeginTransaction()) { try { Dictionary <string, int> updateStok = new Dictionary <string, int>(); List <string> id_items = new List <string>(); H_Trans_ItemModel hti = new H_Trans_ItemModel(); DataRow rowHTI = hti.Table.NewRow(); ComboBoxItem cbiPembayaran = (ComboBoxItem)ViewComponent.cbPaymentMethod.SelectedItem; Metode_PembayaranModel mpm = new Metode_PembayaranModel(); DataRow dr = mpm.Table.Select($"NAMA = '{cbiPembayaran.Content}'").First(); rowHTI["ID"] = 0; rowHTI["ID_CUSTOMER"] = Session.User["ID"].ToString(); rowHTI["TANGGAL_TRANSAKSI"] = DateTime.Now; if (checkPromotion(promo, false)) { rowHTI["ID_PROMO"] = promo.ID; if (promo.JENIS_POTONGAN == "P") { diskon = Convert.ToInt32((Convert.ToDouble(promo.POTONGAN) * Convert.ToDouble(hargaSebelumOngkir)) / 100.0); diskon = Math.Min(promo.POTONGAN_MAX, diskon); } else { diskon = promo.POTONGAN; } } else { diskon = 0; } //grandtotal = hargasebelumongkir + ongkir - diskon rowHTI["GRANDTOTAL"] = grandTotal - diskon; rowHTI["SUBTOTAL"] = hargaSebelumOngkir; rowHTI["ONGKOS_KIRIM"] = ongkos_kirim; rowHTI["DISKON"] = diskon; rowHTI["ID_METODE_PEMBAYARAN"] = dr["ID"].ToString(); rowHTI["STATUS"] = "W"; hti.insert(rowHTI); D_Trans_ItemModel dti = new D_Trans_ItemModel(); int id_hti = generateID_H_Trans(); foreach (ShopCartComponent scc in list_shopcart) { foreach (CartComponent cc in scc.getCarts()) { DataRow rowDTI = dti.Table.NewRow(); rowDTI["ID"] = 0; rowDTI["ID_H_TRANS_ITEM"] = id_hti; rowDTI["ID_ITEM"] = cc.getItemID(); id_items.Add(cc.getItemID()); rowDTI["JUMLAH"] = cc.getQuantity(); rowDTI["ID_KURIR"] = scc.getIDKurir(); rowDTI["STATUS"] = "W"; if (updateStok.ContainsKey(cc.getItemID())) { updateStok[cc.getItemID()] += Convert.ToInt32(cc.getQuantity()); } else { updateStok.Add(cc.getItemID(), Convert.ToInt32(cc.getQuantity())); } dti.insert(rowDTI); } } Transaction.Commit(); //Update Stok foreach (var val in updateStok) { string id_item = val.Key; int qty = val.Value; // MessageBox.Show(id_item + " - " + qty); ItemModel im = new ItemModel(); DataRow item = im.Table.Select($"ID ='{id_item}'").FirstOrDefault(); if (item != null) { item["STOK"] = Convert.ToInt32(item["STOK"]) - qty; } im.update(); } //TODO tambah ke history trans :) foreach (string id_item in id_items) { deleteItemFromCart(Convert.ToInt32(id_item), false); } loadCartItem(); updateGrandTotal(); TransactionViewModel.initH_Trans(); CustomerViewModel.loadItems(); } catch (OracleException e) { Transaction.Rollback(); MessageBox.Show(e.Message); } }; App.closeConnection(out _); } else { MessageBox.Show(message); } }
public JenisPembayaranViewModel() { cm = new Metode_PembayaranModel(); forid = new Metode_PembayaranModel(); reload(); }