private void AccessoryBindingSource_CurrentChanged(object sender, EventArgs e) { if (AccessoryBindingSource.Count <= 0) { id.Text = ""; kode_accessory.Text = ""; nama_accessory.Text = ""; Edit.Enabled = false; Hapus.Enabled = false; return; } var current = AccessoryBindingSource.IndexOf(AccessoryBindingSource.Current); UnitAccessoryModel accessoryModel = ((UnitAccessoryModel)AccessoryXpCollection[current]); id.Text = accessoryModel.id.ToString(); kode_accessory.Text = accessoryModel.kode_accessory; nama_accessory.Text = accessoryModel.nama_accessory; Edit.Enabled = true; Hapus.Enabled = true; kode_accessory.Enabled = false; nama_accessory.Enabled = false; }
private void Hapus_Click(object sender, EventArgs e) { var current = AccessoryBindingSource.IndexOf(AccessoryBindingSource.Current); UnitAccessoryModel accessoryModel = ((UnitAccessoryModel)AccessoryXpCollection[current]); AccessoryXpCollection.Remove(accessoryModel); AccessoryUnitOfWork.CommitChanges(); if (AccessoryBindingSource.Count <= 0) { Tambah.PerformClick(); } }
private void Simpan_Click(object sender, EventArgs e) { if (!Validator.Validate()) { return; } UnitAccessoryModel accessoryModel; if (id.Text == "") { accessoryModel = new UnitAccessoryModel(AccessoryUnitOfWork) { kode_accessory = kode_accessory.Text, nama_accessory = nama_accessory.Text }; AccessoryXpCollection.Add(accessoryModel); AccessoryUnitOfWork.CommitChanges(); } else { XPQuery <UnitAccessoryModel> acc_coll = AccessoryUnitOfWork.Query <UnitAccessoryModel>(); accessoryModel = acc_coll.FirstOrDefault(a => a.id == Convert.ToInt64(id.Text)); accessoryModel.kode_accessory = kode_accessory.Text; accessoryModel.nama_accessory = nama_accessory.Text; accessoryModel.Save(); AccessoryUnitOfWork.CommitChanges(); } id.Text = accessoryModel.id.ToString(); AccessoryBindingSource.Position = AccessoryXpCollection.IndexOf(accessoryModel); kode_accessory.Enabled = false; nama_accessory.Enabled = false; Edit.Enabled = true; Hapus.Enabled = true; }