private void btnAdd_Click(object sender, EventArgs e) { if (!valName.Validate()) { return; } if (!valPrice.Validate()) { return; } try { EDM.Category c = new EDM.Category() { CategoryName = txtName.Text, Price = txtPrice.Text, Type = radioGroup1.Text, }; db.Categories.Add(c); db.SaveChanges(); XtraMessageBox.Show("تم إضافة العرض", "إضافة", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Text = ""; txtPrice.Text = ""; txtName.Focus(); } catch { return; } }
private void btnSave_Click(object sender, EventArgs e) { if (!valName.Validate()) { return; } if (!edit) { string name = txtName.Text; var category = (from c in db.Categories where c.CategoryName == name select c).ToList(); if (category.Count > 0) { XtraMessageBox.Show("يوجد قسم بهذا الإسم", "تنبيه", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } EDM.Category Category = new EDM.Category() { CategoryName = name, Type = type, }; db.Categories.Add(Category); db.SaveChanges(); XtraMessageBox.Show("تم إضافة القسم", "إضافة", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { var cat = db.Categories.Find(catID); cat.CategoryName = txtName.Text; db.SaveChanges(); XtraMessageBox.Show("تم التعديل بنجاح", "إضافة", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Text = ""; } edit = false; frmAddCategory_Load(sender, e); cmbJobs.EditValue = -1; txtName.Text = ""; }