private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) return; //edit if (e.ColumnIndex == 0) { var dataGridViewRow = dataGridView1.Rows[e.RowIndex]; var dataBoundItem = (Bond)dataGridViewRow.DataBoundItem; var addBond = new AddBond(); addBond.SetUiMode(); addBond.SetData(dataBoundItem); addBond.ShowDialog(this); LoadBonds(); } //delete if (e.ColumnIndex == 1) { var dataGridViewRow = dataGridView1.Rows[e.RowIndex]; var dataBoundItem = (Bond)dataGridViewRow.DataBoundItem; var result = MessageBox.Show(@"Are you sure,you want to delete?", @"Delete Bond", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { var dal = new DAL(); dal.DeleteBond(dataBoundItem.Id); LoadBonds(); } } }
public void SaveRule() { var dal = new DAL(); var bonds = dal.GetList(); if (bonds.Count == 0) { const string message = @"You do not have any bonds to Save, thus I am unable " + @" to save any bonds. Please add some bonds before Saving"; MessageBox.Show(message); return; } var dlg = new SaveFileDialog { FileName = "Prize Bond Manager", DefaultExt = ".pbm", Filter = @"Prize Bond Manager Files (.pbm)|*.pbm" }; // Show save file dialog box var result = dlg.ShowDialog(); // Process save file dialog box results if (result == DialogResult.OK) { // Save document string filename = dlg.FileName; var serializer = new Serializer(); var objectToSerialize = new ObjectToSerialize { Bonds = bonds }; serializer.SerializeObject(filename, objectToSerialize); } }
private void AddNewBond() { var bond = new Bond { Serial = Convert.ToInt64(txtSerial.Text), Owner = txtOwner.Text, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; var dal = new DAL(); dal.AddBond(bond); this.Close(); }
private void btnMatchBond_Click(object sender, EventArgs e) { if (ValidData()) { var dal = new DAL(); var bonds = dal.GetBondBySerial(Convert.ToInt64(txtSerial.Text)); if (bonds == null) { lblMessage.Text = @"No match found!"; lblMessage.ForeColor = System.Drawing.Color.Red; } else { lblMessage.Text = @"Success! match found! You are a winner!"; lblMessage.ForeColor = System.Drawing.Color.Green; } } }
public void LoadRule() { // Configure open file dialog box var dlg = new OpenFileDialog { FileName = "Prize Bond Manager", DefaultExt = ".pbm", Filter = @"Prize Bond Manager Files (.pbm)|*.pbm" }; // Show open file dialog box var result = dlg.ShowDialog(); // Process open file dialog box results if (result == DialogResult.OK) { // Open document var filename = dlg.FileName; var serializer = new Serializer(); var deSerializeObject = serializer.DeSerializeObject(filename); var bonds = deSerializeObject.Bonds; var dal = new DAL(); foreach (var bond in bonds) { dal.AddBond(bond); } } }
private void LoadBonds() { var dal = new DAL(); List<Bond> bonds = dal.GetList(); dataGridView1.DataSource = bonds; }
private void UpdateBond() { _updateBondCandidate.Owner = txtOwner.Text; _updateBondCandidate.Serial = Convert.ToInt64(txtSerial.Text); _updateBondCandidate.ModifiedDate = DateTime.Now; var dal = new DAL(); dal.UpdateBond(_updateBondCandidate); this.Close(); }