コード例 #1
0
        private ChiTieu getChiTieuByForm()
        {
            ChiTieu ans = new ChiTieu();

            ans.LoaiChiTieu = cbxLoaiChiTieu.SelectedIndex;
            ans.SoTien      = Int32.Parse(txtSoTien.Text);
            ans.NoiDung     = txtNoiDung.Text;

            return(ans);
        }
コード例 #2
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            if (!CheckLuaChon())
            {
                return;
            }

            if (btnSua.Text == "Sửa")
            {
                btnSua.Text     = "Lưu";
                btnXoa.Text     = "Hủy";
                btnThem.Enabled = false;

                UnlockControl();

                return;
            }

            if (btnSua.Text == "Lưu")
            {
                if (Check())
                {
                    btnSua.Text = "Sửa";
                    btnXoa.Text = "Xóa";

                    LockControl();

                    ChiTieu cu  = getChiTieuByID();
                    ChiTieu moi = getChiTieuByForm();
                    CapNhat(ref cu, moi);

                    try
                    {
                        MessageBox.Show("Sưa thông tin chi tiêu thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Sửa thông tin chi tiêu thất bại\n" + ex.Message,
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvChiTieu();
                }

                return;
            }
        }
コード例 #3
0
        private bool CheckLuaChon()
        {
            ChiTieu k = getChiTieuByID();

            if (k.NoiDung == "" && k.SoTien == 0)
            {
                MessageBox.Show("Chưa có thông tin chi tiêu nào được chọn",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
コード例 #4
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (btnXoa.Text == "Xóa")
            {
                if (!CheckLuaChon())
                {
                    return;
                }

                ChiTieu      cu = getChiTieuByID();
                DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa thông tin chi tiêu này không?",
                                                  "Thông báo",
                                                  MessageBoxButtons.OKCancel,
                                                  MessageBoxIcon.Warning);

                if (rs == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    Helper.ChiTieus.Remove(cu);
                    MessageBox.Show("Xóa thông tin chi tiêu thành công",
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Xóa thông tin chi tiêu thất bại\n" + ex.Message,
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                LoadDgvChiTieu();

                return;
            }
            if (btnXoa.Text == "Hủy")
            {
                btnSua.Text  = "Sửa";
                btnThem.Text = "Thêm";
                btnXoa.Text  = "Xóa";

                LockControl();
                UpdateDetail();
                return;
            }
        }
コード例 #5
0
        private void UpdateDetail()
        {
            ChiTieu z = getChiTieuByID();

            try
            {
                cbxLoaiChiTieu.SelectedIndex = z.LoaiChiTieu;
                txtSoTien.Text  = z.SoTien.ToString();
                txtNoiDung.Text = z.NoiDung.ToString();

                index1 = index;
                index  = dgvChiTieu.SelectedRows[0].Index;
            }
            catch
            {
            }
        }
コード例 #6
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (btnThem.Text == "Thêm")
            {
                btnSua.Enabled = false;
                btnThem.Text   = "Lưu";
                btnXoa.Text    = "Hủy";

                ClearControl();
                UnlockControl();

                return;
            }

            if (btnThem.Text == "Lưu")
            {
                if (Check())
                {
                    btnThem.Text = "Thêm";
                    btnXoa.Text  = "Xóa";
                    LockControl();

                    ChiTieu moi = getChiTieuByForm();
                    Helper.ChiTieus.Add(moi);


                    try
                    {
                        MessageBox.Show("Thêm thông tin chi tiêu thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Thêm thông tin chi tiêu thất bại\n" + ex.Message,
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvChiTieu();
                }
                return;
            }
        }
コード例 #7
0
        public static void LoadDanhSach(string FileName)
        {
            ChiTieus = new List <ChiTieu>();
            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader(FileName))
                {
                    int n;
                    n = Int32.Parse(sr.ReadLine());

                    for (int i = 0; i < n; i++)
                    {
                        ChiTieu item = new ChiTieu();
                        item.LoaiChiTieu = Int32.Parse(sr.ReadLine());
                        item.SoTien      = Int32.Parse(sr.ReadLine());
                        item.NoiDung     = sr.ReadLine();
                        ChiTieus.Add(item);
                    }
                }
            }
            catch
            {
            }
        }
コード例 #8
0
 private void CapNhat(ref ChiTieu cu, ChiTieu moi)
 {
     cu.LoaiChiTieu = moi.LoaiChiTieu;
     cu.SoTien      = moi.SoTien;
     cu.NoiDung     = moi.NoiDung;
 }