private void dgvOutRec_CellContentClick(object sender, DataGridViewCellEventArgs e) { //如果双击的记录,则显示详细信息 if (e.RowIndex >= 0) { //获取要显示详细信息的记录 OutRecord rec; rec = (OutRecord)this.dgvOutRec.Rows[e.RowIndex].Tag; //创建只读的记录查看对话框 OutReForm dlg; dlg = new OutReForm(this.curUser.Name, rec, true); //显示对话框 dlg.ShowDialog(this); } }
private void btnAddNewOutRec_Click(object sender, EventArgs e) { //创建用来保存新记录的对象 int newId = OutSQL.GetUsableOutID(this.curUser.Name); if (newId == 0) { MessageBox.Show(this, "无法获取可用的支出记录编号,请确保数据库连接正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } OutRecord rec = new OutRecord(); rec.ID = newId; rec.OutTime = DateTime.Now; rec.RecordTime = DateTime.Now; //创建支出记录编辑对话框 OutReForm dlg = new OutReForm(this.curUser.Name, rec, false); if (dlg.ShowDialog(this) == DialogResult.OK) { //添加记录成功,则添加到界面 if (OutSQL.AddOutRec(this.curUser.Name, rec)) { //添加一行到界面 int newRowIndex = this.dgvOutRec.Rows.Add(); this.dgvOutRec.Rows[newRowIndex].Tag = rec; //显示信息到新添加的行 this.dgvOutRec.Rows[newRowIndex].Cells["colOutID"].Value = rec.ID; this.dgvOutRec.Rows[newRowIndex].Cells["colOutTime"].Value = rec.OutTime; this.dgvOutRec.Rows[newRowIndex].Cells["colOutType"].Value = rec.OutType; this.dgvOutRec.Rows[newRowIndex].Cells["colOutUsage"].Value = rec.OutUsage; this.dgvOutRec.Rows[newRowIndex].Cells["colOutRecTime"].Value = rec.RecordTime; this.dgvOutRec.Rows[newRowIndex].Cells["colOutDes"].Value = rec.Description; this.dgvOutRec.Rows[newRowIndex].Cells["colOutBank"].Value = rec.BankCard; this.dgvOutRec.Rows[newRowIndex].Cells["colOutAmount"].Value = rec.Amount; } else { MessageBox.Show(this, "添加记录失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void btnModifyOutRec_Click(object sender, EventArgs e) { //判断是否有选中的记录 if (this.dgvOutRec.SelectedRows.Count == 0) { MessageBox.Show(this, "没有选中任何记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //获取支出记录的数据 OutRecord rec; rec = (OutRecord)this.dgvOutRec.SelectedRows[0].Tag; //创建可修改对话框 OutReForm orf = new OutReForm(this.curUser.Name, rec, false); //显示对话框,进行编辑操作 if (orf.ShowDialog(this) == DialogResult.OK) { //修改记录成功,则更新指定记录 if (OutSQL.ModifyOutRec(this.curUser.Name, rec)) { this.dgvOutRec.SelectedRows[0].Cells["colOutID"].Value = rec.ID; this.dgvOutRec.SelectedRows[0].Cells["colOutTime"].Value = rec.OutTime; this.dgvOutRec.SelectedRows[0].Cells["colOutType"].Value = rec.OutType; this.dgvOutRec.SelectedRows[0].Cells["colOutUsage"].Value = rec.OutUsage; this.dgvOutRec.SelectedRows[0].Cells["colOutRecTime"].Value = rec.RecordTime; this.dgvOutRec.SelectedRows[0].Cells["colOutDes"].Value = rec.Description; this.dgvOutRec.SelectedRows[0].Cells["colOutBank"].Value = rec.BankCard; this.dgvOutRec.SelectedRows[0].Cells["colOutAmount"].Value = rec.Amount; } else { MessageBox.Show(this, "修改记录失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }