private void btnSaveChanges_Click(object sender, EventArgs e) { if (IsValid()) { if (!_isUpdate) { _publisher = new Publisher(); } _publisher.Name = txtName.Text.Trim(); var nameValuePairs = new Dictionary <string, object>(); nameValuePairs.Add("Name", _publisher.Name); if (_isUpdate) { if (!_database.ExecuteUpdate("Publishers", "PublisherId", _publisher.PublisherId, nameValuePairs)) { MessageBox.Show("در درج/ویرایش اطلاعات مشکلی رخ داده است!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Close(); } } else { if (!_database.ExecuteInsert <Publisher>("Publishers", nameValuePairs.Values.ToArray())) { MessageBox.Show("در درج/ویرایش اطلاعات مشکلی رخ داده است!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Close(); } } } }
private void btnSaveChanges_Click(object sender, EventArgs e) { if (IsValid()) { if (!_isUpdate) { _book = new Book(); } _book.Name = txtName.Text.Trim(); _book.PublisherId = int.Parse(cmbPublishers.SelectedValue.ToString()); _book.Author = txtAuthor.Text.Trim(); _book.PublishedOn = dtPublishedOn.Value; _book.ISBN = txtISBN.Text.Trim(); _book.Description = txtDescription.Text.Trim(); var nameValuePairs = new Dictionary <string, object>(); nameValuePairs.Add("Name", _book.Name); nameValuePairs.Add("PublisherId", _book.PublisherId); nameValuePairs.Add("Author", _book.Author); nameValuePairs.Add("PublishedOn", _book.PublishedOn); nameValuePairs.Add("ISBN", _book.ISBN); nameValuePairs.Add("Description", _book.Description); if (_isUpdate && !_database.ExecuteUpdate("Books", "BookId", _book.BookId, nameValuePairs)) { MessageBox.Show("در درج/ویرایش اطلاعات مشکلی رخ داده است!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (!_isUpdate && !_database.ExecuteInsert <Book>("Books", nameValuePairs.Values.ToArray())) { MessageBox.Show("در درج/ویرایش اطلاعات مشکلی رخ داده است!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Close(); } } }