private void Simpan_Click(object sender, EventArgs e) { if (!InputValidator.Validate()) { return; } XPQuery <UnitModelModel> model_coll = ModelUnitOfWork.Query <UnitModelModel>(); UnitModelModel model; if (id.Text == "") { model = new UnitModelModel(ModelUnitOfWork); } else { model = model_coll.FirstOrDefault(m => m.id_model == Convert.ToInt64(id.Text)); } model.merk = merk.Text; model.tipe_model = tipe_model.Text; ModelUnitOfWork.Save(model); ModelUnitOfWork.CommitChanges(); LoadDataGrid(); id.Text = model.id_model.ToString(); merk.Enabled = false; tipe_model.Enabled = false; Edit.Enabled = true; Hapus.Enabled = true; }
private void TambahWarna_Click(object sender, EventArgs e) { if (!WarnaValidator.Validate()) { return; } var SelectedModel = ModelGridView.GetFocusedRowCellValue(colid_model); XPQuery <UnitModelModel> model_coll = ModelUnitOfWork.Query <UnitModelModel>(); UnitModelModel model = model_coll.FirstOrDefault(m => m.id_model == Convert.ToInt64(SelectedModel)); var SelectedVariant = VariantGridView.GetFocusedRowCellValue(colvariant); XPQuery <UnitModelVariantModel> variant_coll = ModelUnitOfWork.Query <UnitModelVariantModel>(); UnitModelVariantModel variantModel = variant_coll.FirstOrDefault(v => v.nama_variant == SelectedVariant.ToString() && v.id_model == model); UnitModelWarnaModel warnaModel = new UnitModelWarnaModel(ModelUnitOfWork) { id_model = model, id_variant = variantModel, nama_warna = nama_warna.Text }; ModelUnitOfWork.CommitChanges(); nama_warna.ResetText(); LoadDataGrid(); }
private void Hapus_Click(object sender, EventArgs e) { if (!InputValidator.Validate()) { return; } DialogResult dialog = MessageBox.Show("Yakin akan menghapus data ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialog != DialogResult.Yes) { return; } XPQuery <UnitModelModel> model_coll = ModelUnitOfWork.Query <UnitModelModel>(); UnitModelModel model = model_coll.FirstOrDefault(m => m.id_model == Convert.ToInt64(id.Text)); if (model.UnitModelVariants.Count > 0) { MessageBox.Show("Model Tidak dapat dihapus karena memiliki data Variant dan transmisi", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ModelUnitOfWork.Delete(model); ModelUnitOfWork.CommitChanges(); LoadDataGrid(); Tambah.PerformClick(); }
private void TambahVariant_Click(object sender, EventArgs e) { if (!VariantValidator.Validate()) { return; } UnitModelVariantModel variantModel = new UnitModelVariantModel(ModelUnitOfWork); var SelectedModel = ModelGridView.GetFocusedRowCellValue(colid_model); XPQuery <UnitModelModel> model_coll = ModelUnitOfWork.Query <UnitModelModel>(); UnitModelModel model = model_coll.FirstOrDefault(m => m.id_model == Convert.ToInt64(SelectedModel)); variantModel.id_model = model; variantModel.created_by = Login.User.username; variantModel.nama_variant = nama_variant.Text; variantModel.Save(); ModelUnitOfWork.CommitChanges(); nama_variant.ResetText(); LoadDataGrid(); }