void add_element() { using (var faeg = new Form_AddEditGoalElement("Новая выплата по цели")) { faeg.ShowDialog(); if (faeg.DialogResult == DialogResult.OK) { var newGoalRow = dataSet1.Tables["GoalHistory"].NewRow(); newGoalRow["HistoryID"] = Convert.ToInt32(_HistoryID); newGoalRow["DateTime"] = faeg.dtp_DateTimeGoalElement.Value; newGoalRow["Sum"] = (faeg.txb_GoalElementAllSum.Text == "") ? "0" : faeg.txb_GoalElementAllSum.Text; newGoalRow["Comment"] = faeg.txb_GoalElementComment.Text; dataSet1.Tables["GoalHistory"].Rows.Add(newGoalRow); } } }
private void повторитьToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.CurrentRow == null) return; using (var addEdit = new Form_AddEditGoalElement("Редактирование выплаты по цели")) { addEdit.dtp_DateTimeGoalElement.Value = DateTime.ParseExact(dataGridView1.CurrentRow.Cells[1].Value.ToString(), "dd.MM.yyyy H:mm:ss", CultureInfo.CreateSpecificCulture("ru-RU")); addEdit.txb_GoalElementAllSum.Text = Convert.ToDouble(dataGridView1.CurrentRow.Cells[2].Value).ToString(); addEdit.txb_GoalElementComment.Text = Class_element.Comment = dataGridView1.CurrentRow.Cells[3].Value.ToString(); addEdit.ShowDialog(); if (addEdit.DialogResult == DialogResult.OK) { var newRow = dataSet1.Tables["GoalHistory"].NewRow(); newRow["HistoryID"] = Convert.ToInt32(_HistoryID); newRow["DateTime"] = addEdit.dtp_DateTimeGoalElement.Value; newRow["Sum"] = (addEdit.txb_GoalElementAllSum.Text == "") ? "0" : addEdit.txb_GoalElementAllSum.Text; newRow["Comment"] = addEdit.txb_GoalElementComment.Text; dataSet1.Tables["GoalHistory"].Rows.Add(newRow); } } }
void edit_element() { if (dataGridView1.CurrentRow == null) return; using (var addEdit = new Form_AddEditGoalElement("Редактирование выплаты по цели")) { addEdit.dtp_DateTimeGoalElement.Value = DateTime.ParseExact(dataGridView1.CurrentRow.Cells[1].Value.ToString(), "dd.MM.yyyy H:mm:ss", CultureInfo.CreateSpecificCulture("ru-RU")); addEdit.txb_GoalElementAllSum.Text = Convert.ToDouble(dataGridView1.CurrentRow.Cells[2].Value).ToString(); addEdit.txb_GoalElementComment.Text = Class_element.Comment = dataGridView1.CurrentRow.Cells[3].Value.ToString(); addEdit.ShowDialog(); if (addEdit.DialogResult == DialogResult.OK) { var editRow = ((DataRowView)dataGridView1.CurrentRow.DataBoundItem).Row; editRow["HistoryID"] = Convert.ToInt32(_HistoryID); editRow["DateTime"] = addEdit.dtp_DateTimeGoalElement.Value; editRow["Sum"] = (addEdit.txb_GoalElementAllSum.Text == "") ? "0" : addEdit.txb_GoalElementAllSum.Text; editRow["Comment"] = addEdit.txb_GoalElementComment.Text; } } }