protected void btnDelete_Click(object sender, EventArgs e) { if (listBox.SelectedItem != null) { Njit.Program.Controls.ComboBoxExtended.CustomItem obj = ((Njit.Program.Controls.ComboBoxExtended.CustomItem)listBox.SelectedItem); try { (this.DataAccess ?? (Options.SettingInitializer.GetDataAccess())).Execute(CommandType.Text, string.Format("DELETE FROM [{0}] WHERE [{1}]=@p", this.TableName, this.KeyField), "@p", obj.Value); } catch (System.Data.SqlClient.SqlException ex) { if (ex.ErrorCode == -2146232060 && ex.Number == 547) { PersianMessageBox.Show(this, "'" + obj.Caption + "' قابل حذف نیست. از این اطلاعات در جای دیگر استفاده شده است"); } else { PersianMessageBox.Show(this, "خطا در حذف '" + obj.Caption + "'" + Environment.NewLine + Environment.NewLine + ex.Message); } } catch (Exception ex) { PersianMessageBox.Show(this, "خطا در حذف '" + obj.Caption + "'" + Environment.NewLine + Environment.NewLine + ex.Message); return; } RefreshData(); } }
private void btnSetAsDefault_Click(object sender, EventArgs e) { if (listBox.SelectedItem != null) { Njit.Program.Controls.ComboBoxExtended.CustomItem obj = ((Njit.Program.Controls.ComboBoxExtended.CustomItem)listBox.SelectedItem); try { (this.DataAccess ?? (Options.SettingInitializer.GetDataAccess())).Execute(CommandType.Text, string.Format("UPDATE [{0}] SET [{1}]=@p1", this.TableName, this.IsDefaultField), "@p1", false); (this.DataAccess ?? (Options.SettingInitializer.GetDataAccess())).Execute(CommandType.Text, string.Format("UPDATE [{0}] SET [{1}]=@p1 WHERE [{2}]=@p2", this.TableName, this.IsDefaultField, this.KeyField), "@p1", true, "@p2", obj.Value); } catch (Exception ex) { PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } RefreshData(); } }
protected void btnEdit_Click(object sender, EventArgs e) { if (listBox.SelectedItem != null) { Njit.Program.Controls.ComboBoxExtended.CustomItem obj = ((Njit.Program.Controls.ComboBoxExtended.CustomItem)listBox.SelectedItem); using (Forms.ComboBoxEditItemsEdit f = new ComboBoxEditItemsEdit(obj.Caption)) { if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { (this.DataAccess ?? (Options.SettingInitializer.GetDataAccess())).Execute(CommandType.Text, string.Format("UPDATE [{0}] SET [{1}]=@p1 WHERE [{2}]=@p2", this.TableName, this.CaptionField, this.KeyField), "@p1", f.Value, "@p2", obj.Value); } catch (Exception ex) { PersianMessageBox.Show(this, "خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message); return; } RefreshData(); } } } }