private void btn_simpan_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var customer = cbo_kd_customer.EditValue; if (customer == null) { Helpers.Generic.MsgEx("Data customer tidak boleh kosong"); return; } else if (gridView1.RowCount == 0) { Helpers.Generic.MsgEx("Detail barang tidak boleh kosong"); return; } var data = new Models.po() { no_po = txt_no_po.EditValue.ToString(), kd_customer = cbo_kd_customer.EditValue.ToString(), tgl = Convert.ToDateTime(dtp_tgl.EditValue), term = txt_term.EditValue.ToString(), project = txt_project.EditValue.ToString(), sub_total = Convert.ToInt32(txt_sub_total.EditValue), ppn = Convert.ToInt32(txt_ppn.EditValue), total = Convert.ToInt32(txt_total.EditValue) }; for (int i = 0; i < gridView1.RowCount; i++) { if (Convert.ToInt32(gridView1.GetRowCellValue(i, "qty")) > 0) { var detail = new Models.detailpo() { no_po = txt_no_po.EditValue.ToString(), kd_barang = gridView1.GetRowCellValue(i, "kd_barang").ToString(), qty = Convert.ToInt32(gridView1.GetRowCellValue(i, "qty")), liter = Convert.ToInt32(gridView1.GetRowCellValue(i, "liter")), harga = Convert.ToInt32(gridView1.GetRowCellValue(i, "harga")), total = Convert.ToInt32(gridView1.GetRowCellValue(i, "total")) }; data.detailpos.Add(detail); } } if (Controllers.PO.CPO.insert(data)) { Helpers.Generic.MsgInfo("Data PO berhasil disimpan"); this.init(); } }
public static bool insert(Models.po data) { bool result = false; try { using (var db = new Models.jotunContext()) { db.Entry(data).State = EntityState.Added; db.SaveChanges(); result = true; } } catch (Exception ex) { Helpers.Generic.MsgError(ex.Message); } return(result); }