private void btn_edit_click(object sender, RoutedEventArgs e) { try { int idCat = Id_category; if (cbCategory.Text != "") { idCat = int.Parse(cbCategory.SelectedValue.ToString()); } else { idCat = Id_category; } medicine updateMed = (from m in _db.medicines where m.Id_medicine == Id_medicine select m).Single(); updateMed.fk_id_category = idCat; updateMed.name_medicine = txtName.Text; updateMed.price = int.Parse(txtPrice.Text); updateMed.stok = int.Parse(txtStock.Text); _db.SaveChanges(); dgridMedicines.ItemsSource = _db.medicines.ToList(); loadCategory(idCat); txtCategory.Text = cbCategory.Text.Trim(); MessageBox.Show("Edit data " + txtName.Text + " suceess !"); } catch { MessageBox.Show("Edit data Fail !"); } }
private void btn_buy(object sender, RoutedEventArgs e) { try { if (getStock(this.Id_medicine, int.Parse(txtAmounts.Text.ToString())) >= 0) { DateTime timestamp = DateTime.Now.ToLocalTime(); transaction t = new transaction() { fk_id_employee = this.Id_employee, fk_id_medicine = this.Id_medicine, qty_medicine = int.Parse(txtAmounts.Text.ToString()), amount = int.Parse(txtTotal.Text.ToString()), time = timestamp }; _db.transactions.Add(t); _db.SaveChanges(); medicine med = (from m in _db.medicines where m.Id_medicine == this.Id_medicine select m).Single(); med.stok = getStock(this.Id_medicine, int.Parse(txtAmounts.Text.ToString())); _db.SaveChanges(); MessageBox.Show("Buy Medicine Success !"); this.Close(); MainWindow.g.Children.Clear(); MainWindow.g.Children.Add(new Transactions()); } else { MessageBox.Show("Minimum Stock !"); } } catch { MessageBox.Show("Buy Medicine Failed !"); } }
private void btn_add_employee(object sender, RoutedEventArgs e) { try { medicine m = new medicine() { name_medicine = txtName.Text.Trim(), price = int.Parse(txtPrice.Text), stok = int.Parse(txtStock.Text), fk_id_category = int.Parse(cbCategory.SelectedValue.ToString()) }; _db.medicines.Add(m); _db.SaveChanges(); Medicine.dgrid.ItemsSource = _db.medicines.ToList(); MessageBox.Show("Add data " + txtName.Text.Trim() + " success !"); this.Close(); } catch { MessageBox.Show("Add data fail !"); } }