private void btnSubmit_Click(object sender, EventArgs e) { if (BaseValidator.IsFormValid(this.components)) { BookTB book = new BookTB() { BookName = txtBookName.Text, Code = txtBookCode.Text, Publishare = txtPublishare.Text, Writer = txtWriter.Text }; using (ControlerDB db = new ControlerDB()) { if (BookId == 0) { db.BookRepository.Insert(book); db.Save(); } else { book.BookID = BookId; db.BookRepository.Updatae(book); db.Save(); } } DialogResult = DialogResult.OK; } }
private void btnDeleteBooks_Click(object sender, EventArgs e) { if (dgvBooks.CurrentRow != null) { int bookId = int.Parse(dgvBooks.CurrentRow.Cells[0].Value.ToString()); if (MessageBox.Show("ایا میخواهید این کتاب را حذف کنید؟", "هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (ControlerDB db = new ControlerDB()) { try { var form = db.FromRepository.get(fr => fr.BookID == bookId); foreach (var fromTb in form) { db.FromRepository.Delete(fromTb); } db.BookRepository.Delete(bookId); db.Save(); BooksBind(); FromBimd(); } catch { MessageBox.Show("حذف با خطا مواجه شد"); } db.Save(); BooksBind(); } } } else { MessageBox.Show("لطفا یک نغر را انتخاب کنید", "خطا", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }
private void btnSubmit_Click(object sender, EventArgs e) { using (ControlerDB db = new ControlerDB()) { FromTb from = new FromTb() { BookID = bookId, Date = DateTime.Now, Type = (rdbPay.Checked)? true : false, UserID = userId }; db.FromRepository.Insert(from); db.Save(); } DialogResult = DialogResult.OK; }
private void btnSubmit_Click(object sender, EventArgs e) { using (ControlerDB db = new ControlerDB()) { string path = Application.StartupPath + "/Images/"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string imagename = Guid.NewGuid().ToString() + Path.GetExtension(pcCustomer.ImageLocation); pcCustomer.Image.Save(path + imagename); if (BaseValidator.IsFormValid(this.components)) { CustomerTB customer = new CustomerTB() { FullName = txtFullName.Text, Address = txtAddress.Text, Email = txtEmail.Text, Phone = txtPhone.Text, CustomerIMG = imagename }; if (userId == 0) { db.CustomersRepository.InsertCustomers(customer); } if (userId != 0) { customer.CustomerID = userId; db.CustomersRepository.UpdateCustomer(customer); } db.Save(); } DialogResult = DialogResult.OK; } }
private void btnDeleteCustomer_Click(object sender, EventArgs e) { if (dgvCustomers.CurrentRow != null) { int userid = int.Parse(dgvCustomers.CurrentRow.Cells[0].Value.ToString()); using (ControlerDB db = new ControlerDB()) { if (MessageBox.Show("ایا از حذف اطمینان دارید؟", "هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { var user = db.CustomersRepository.GetCustomerByID(userid); File.Delete(Application.StartupPath + "/Images/" + user.CustomerIMG); db.CustomersRepository.DeleteCustomer(userid); db.Save(); UsersBind(); } } } else { MessageBox.Show("لطفا یک نغر را انتخاب کنید", "خطا", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } }