private void btedit_Click(object sender, EventArgs e) { if (gvcategories.SelectedRows.Count == 0) { MessageBox.Show("Tidak ada kategori yang akan diubah"); } else { var selectedRowId = (int)gvcategories.SelectedRows[0].Cells["id"].Value; var cats = ListCategories.FirstOrDefault(x => x.catid == selectedRowId); if (selectedRowId == 1) { MessageBox.Show("Anda tidak dibenarkan mengubah kategori Lain-Lain"); } else if (cats != null) { var form = new ManageCategories(); form.userdata = userdata; form.Editmode = true; form.CategoryData = cats; form.ShowDialog(); LoadData(); foreach (DataGridViewRow row in gvcategories.Rows) { if (((int)row.Cells["id"].Value) == selectedRowId) { gvcategories.Rows[row.Index].Selected = true; break; } } } } }
private void LoadData() { //if (userdata.user_role == "kasir") //{ // btadditem.Visible = false; // btedititem.Visible = false; // btdeleteitem.Visible = false; // btunitmanage.Visible = false; // btmanagebrand.Visible = false; //} try { ListBrands = brandRepository.GetAll().ToList(); ListProducts = productRepository.GetAll().ToList(); ListCategories = categoryRepository.GetAll().ToList(); ListUnits = unitRepository.GetAll().ToList(); var tempproductlist = new List <TempProdColumns>(); if (ListProducts != null) { foreach (var item in ListProducts) { var prodbrand = ListBrands.FirstOrDefault(x => x.brandid == item.brandid); var prodcat = ListCategories.FirstOrDefault(x => x.catid == item.prodcat); var produnit = ListUnits.FirstOrDefault(x => x.unitid == item.produnit); var itemDetail = new TempProdColumns(); itemDetail.prodid = item.prodid; itemDetail.brandid = item.brandid; itemDetail.brand_name = prodbrand != null ? prodbrand.name : " - "; itemDetail.name = item.name; itemDetail.prodcat = item.prodcat; itemDetail.prodcat_name = prodcat != null ? prodcat.name : " - "; itemDetail.prodcode = item.prodcode; itemDetail.produnit = item.produnit; itemDetail.produnit_code = produnit != null ? produnit.unitcode : " - "; itemDetail.purchaseprice = item.purchaseprice; itemDetail.stocks = item.stocks; itemDetail.barcodeno = item.barcodeno; tempproductlist.Add(itemDetail); } gvproducts.Rows.Clear(); foreach (var item in tempproductlist.OrderBy(x => x.prodcat_name).ThenBy(x => x.brand_name).ThenBy(x => x.name)) { gvproducts.Rows.Add( item.prodid, item.prodcat_name, item.brand_name, item.prodcode, item.name, item.produnit_code, Utils.ToRupiah(item.purchaseprice), item.barcodeno, item.stocks ); } } var cbData = ListBrands; cbData.Insert(0, new BrandColumns { brandid = -1, name = "--- Pilih Merek ---" }); cbbrand.DataSource = new BindingSource(ListBrands, null); cbbrand.DisplayMember = "name"; cbbrand.ValueMember = "brandid"; var cbcatdata = ListCategories; cbcatdata.Insert(0, new CategoryColumns { catid = -1, name = "--- Pilih Kategori ---" }); cbcategory.DataSource = new BindingSource(ListCategories, null); cbcategory.DisplayMember = "name"; cbcategory.ValueMember = "catid"; } catch (Exception ex) { var errMsg = "Details : " + ex.Message + Environment.NewLine + "Stacktrace : " + ex.StackTrace; MessageBox.Show(errMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } tbprodname.Focus(); }