Beispiel #1
0
        private void btnDelOutRec_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;
            //再次确认删除操作
            if (MessageBox.Show(this, "真的要删除支出记录----" + rec.ID.ToString() + "?", "提示",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                //删除记录
                if (OutSQL.DeleteOutRec(this.curUser.Name, rec.ID))
                {
                    //删除成功,从表格移除
                    this.dgvOutRec.Rows.Remove(this.dgvOutRec.SelectedRows[0]);
                }
                else
                {
                    //删除失败,则提示
                    MessageBox.Show(this, "删除支出记录----" + rec.ID.ToString() + ",失败!", "提示",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Beispiel #2
0
        private void LoadOutRecList()
        {
            //清除原界面上的数据
            this.dgvOutRec.Rows.Clear();
            List <OutRecord> recLst;

            //从数据库加载支出记录列表
            recLst = OutSQL.LoadOutRcdList(this.curUser.Name);
            //加载失败,可能是数据库连接不成功,提示
            if (recLst == null)
            {
                MessageBox.Show(this, "加载已有支出记录失败,请确认数据库连接!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //依次显示所有的收入记录到界面
            foreach (OutRecord rec in recLst)
            {
                //添加一行到界面
                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;
            }
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //清除原界面上的数据
            this.dgvOutRec.Rows.Clear();
            List <OutRecord> recList;

            //从数据库加载支出记录列表

            /* SqlDataAdapter da = new SqlDataAdapter();
             * DataSet ds = new DataSet("MyMoney");
             * string connString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""E:\c++练习\MyMoneyAgent - 副本 (2) - 副本\MyMoneyAgent\MyMoney.mdf"";Integrated Security=True";
             * SqlConnection conn = new SqlConnection(connString);//创建链接对象
             *
             *   conn.Open();
             *   //查询数据库中
             *   string cmdTxt = "SELECT [支出编号], [姓名], [支出时间], [记录时间], [支出方式], " +
             *                   "[支出类型], [金额], [银行卡号], [支出说明] FROM [支出记录] ";
             *   SqlCommand comm = new SqlCommand(cmdTxt, conn);
             *   da.SelectCommand = comm;
             *   SqlCommandBuilder builder = new SqlCommandBuilder(da);
             *   da.Fill(ds, "支出记录");
             *   dgvOutRec.DataSource = ds.Tables["支出记录"];
             *   //关闭连接
             *   conn.Close();*/
            recList = OutSQL.LoadOutRcdListSearch(this.curUser.Name, date1.Value.ToString(), date2.Value.ToString());
            //加载失败,可能是数据库连接不成功,提示
            if (recList == null)
            {
                MessageBox.Show(this, "加载已有支出记录失败,请确认数据库连接!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //依次显示所有的支出记录到界面
            foreach (OutRecord rec in recList)
            {
                //添加一行到界面
                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;
            }
        }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
0
        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);
                }
            }
        }