コード例 #1
0
        private void btnDate_Click(object sender, EventArgs e)
        {
            //清除原界面上的数据
            this.dgvInRec.Rows.Clear();
            List <IncomeRecord> recLst;

            //从数据库加载收入记录列表
            recLst = IncomeSQL.LoadIncomRcdListDate(this.curUser.Name, dtpdate1.Value.ToString(), dtpdate2.Value.ToString());
            //加载失败,可能是数据库连接不成功,提示
            if (recLst == null)
            {
                MessageBox.Show(this, "加载已有收入记录失败,请确认数据库连接!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //依次显示所有的收入记录到界面
            foreach (IncomeRecord rec in recLst)
            {
                //添加一行到界面
                int newRowIndex = this.dgvInRec.Rows.Add();
                this.dgvInRec.Rows[newRowIndex].Tag = rec;
                //显示信息到新添加的行
                this.dgvInRec.Rows[newRowIndex].Cells["colInID"].Value      = rec.ID;
                this.dgvInRec.Rows[newRowIndex].Cells["colInInTime"].Value  = rec.IncomeTime;
                this.dgvInRec.Rows[newRowIndex].Cells["colInType"].Value    = rec.IncomeType;
                this.dgvInRec.Rows[newRowIndex].Cells["colInUsage"].Value   = rec.IncomUsage;
                this.dgvInRec.Rows[newRowIndex].Cells["colInRecTime"].Value = rec.RecordTime;
                this.dgvInRec.Rows[newRowIndex].Cells["colInDes"].Value     = rec.Description;
                this.dgvInRec.Rows[newRowIndex].Cells["colInBank"].Value    = rec.BankCard;
                this.dgvInRec.Rows[newRowIndex].Cells["colInAmount"].Value  = rec.Amount;
            }
        }
コード例 #2
0
        private void btnDelIncomRec_Click(object sender, EventArgs e)
        {
            //判断是否有选中的记录
            if (this.dgvInRec.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "没有选中任何记录!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //获取选中记录的数据
            IncomeRecord rec;

            rec = (IncomeRecord)this.dgvInRec.SelectedRows[0].Tag;
            //再次确认删除操作
            if (MessageBox.Show(this, "真的要删除收入记录----" + rec.ID.ToString() + "?", "提示",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //删除记录
                if (IncomeSQL.DeleteIncomRec(this.curUser.Name, rec.ID))
                {
                    //删除成功,从表格移除
                    this.dgvInRec.Rows.Remove(this.dgvInRec.SelectedRows[0]);
                }
                else
                {
                    //删除失败,则提示
                    MessageBox.Show(this, "删除收入记录----" + rec.ID.ToString() + ",失败!", "提示",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
コード例 #3
0
        private void btnAddNewIncomRec_Click(object sender, EventArgs e)
        {
            //创建用来保存新记录的对象
            int newId = IncomeSQL.GetUsableIncomID(this.curUser.Name);

            if (newId == 0)
            {
                MessageBox.Show(this, "无法获取可用的收入记录编号,请确保数据库连接正确!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            IncomeRecord rec = new IncomeRecord();

            rec.ID         = newId;
            rec.IncomeTime = DateTime.Now;
            rec.RecordTime = DateTime.Now;
            //创建收入记录编辑对话框
            IncomeReForm dlg = new IncomeReForm(this.curUser.Name, rec, false);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                //添加记录成功,则添加到界面
                if (IncomeSQL.AddIncomRec(this.curUser.Name, rec))
                {
                    //添加一行到界面
                    int newRowIndex = this.dgvInRec.Rows.Add();
                    this.dgvInRec.Rows[newRowIndex].Tag = rec;
                    //显示信息到新添加的行
                    this.dgvInRec.Rows[newRowIndex].Cells["colInID"].Value      = rec.ID;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInInTime"].Value  = rec.IncomeTime;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInType"].Value    = rec.IncomeType;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInUsage"].Value   = rec.IncomUsage;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInRecTime"].Value = rec.RecordTime;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInDes"].Value     = rec.Description;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInBank"].Value    = rec.BankCard;
                    this.dgvInRec.Rows[newRowIndex].Cells["colInAmount"].Value  = rec.Amount;
                }
                else
                {
                    MessageBox.Show(this, "添加记录失败!", "提示",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
コード例 #4
0
        private void btnModifyIncomRec_Click(object sender, EventArgs e)
        {
            //判断是否有选中的记录
            if (this.dgvInRec.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "没有选中任何记录!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //获取选中记录的数据
            IncomeRecord rec;

            rec = (IncomeRecord)this.dgvInRec.SelectedRows[0].Tag;
            //创建可修改对话框
            IncomeReForm dlg = new IncomeReForm(this.curUser.Name, rec, false);

            //显示对话框,进行编辑操作
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                //修改记录成功,则更新指定记录
                if (IncomeSQL.ModifyIncomrec(this.curUser.Name, rec))
                {
                    this.dgvInRec.SelectedRows[0].Cells["colInID"].Value      = rec.ID;
                    this.dgvInRec.SelectedRows[0].Cells["colInInTime"].Value  = rec.IncomeTime;
                    this.dgvInRec.SelectedRows[0].Cells["colInType"].Value    = rec.IncomeType;
                    this.dgvInRec.SelectedRows[0].Cells["colInUsage"].Value   = rec.IncomUsage;
                    this.dgvInRec.SelectedRows[0].Cells["colInRecTime"].Value = rec.RecordTime;
                    this.dgvInRec.SelectedRows[0].Cells["colInDes"].Value     = rec.Description;
                    this.dgvInRec.SelectedRows[0].Cells["colInBank"].Value    = rec.BankCard;
                    this.dgvInRec.SelectedRows[0].Cells["colInAmount"].Value  = rec.Amount;
                }
                else
                {
                    MessageBox.Show(this, "修改记录失败!", "提示",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }