// Tao
        public void Tao()
        {
            fmPopupHoaDon fm = new fmPopupHoaDon("Tạo hoá đơn bán hàng");

            fm.StartPosition = FormStartPosition.CenterParent;
            fm.butIn.Enabled = false;
            fm.ctrlData      = ctrlData;
            HoaDon   hd;
            DonThuoc dt;

            while (true)
            {
                if (fm.ShowDialog() == DialogResult.OK)
                {
                    hd = new HoaDon(fm.txtMa.Text);
                    dt = new DonThuoc(fm.txtDThuocMa.Text, fm.txtDThuocKH.Text, fm.txtDThuocBacSiKe.Text, fm.dtpDThuocNgayKe.Value, fm.txtDThuocGhiChu.Text, hd);

                    hd.Ngay      = fm.dtpNgayTao.Value;
                    hd.NguoiLap  = fm.txtNguoiTao.Text;
                    hd.DThuoc    = dt;
                    hd.TrangThai = fm.rdoChuaThanhToan.Checked ? Const.TrangThai.ChuaThanhToan : Const.TrangThai.DaThanhToan;
                    foreach (DictionaryEntry entry in fm.dsthuoc)
                    {
                        hd.DSChiTiet.Add(new ChiTietHoaDon((int)entry.Value, (Thuoc)entry.Key));
                    }
                    //
                    if (!ctrlData.Them <DonThuoc>(dt))
                    {
                        MessageBox.Show("Mã đơn thuốc đã bị trùng!");
                    }
                    else if (!ctrlData.Them <HoaDon>(hd))
                    {
                        ctrlData.Xoa <DonThuoc>(dt);
                        MessageBox.Show("Mã hoá đơn đã bị trùng!");
                    }
                    else
                    {
                        // Tinh toan so luong con lai
                        foreach (ChiTietHoaDon ct in hd.DSChiTiet)
                        {
                            ct.thuoc.SLConLai -= ct.SoLuong;
                            // Update vào CSDL
                            ctrlData.Sua <Thuoc>(ct.thuoc);
                        }
                        break;
                    }
                }
                else
                {
                    return;
                }
            }
        }
Beispiel #2
0
        // Sua
        public void Sua(string Ma)
        {
            fmPopupThuoc fm = new fmPopupThuoc("Sửa thuốc");

            fm.StartPosition      = FormStartPosition.CenterParent;
            fm.ctrlData           = ctrlData;
            fm.txtMa.ReadOnly     = true;
            fm.nudSoLuong.Enabled = false;

            var th = ctrlData.ListItems <Thuoc>(Ma, "Ma", Const.TextFindOption.Absolute)[0];

            fm.txtMa.Text       = th.Ma;
            fm.txtTen.Text      = th.Ten;
            fm.nudSoLuong.Value = (decimal)th.SLConLai;
            fm.dtpNSX.Value     = th.NSX;
            fm.dtpHSD.Value     = th.HSD;
            fm.txtDonVi.Text    = th.DonVi;
            fm.nudDonGia.Value  = (decimal)th.DonGia;
            fm.txtGhiChu.Text   = th.GhiChu;
            fm.nhasx            = th.NhaSX;
            fm.nhacc            = th.NhaCC;
            fm.nthuoc           = th.NThuoc;
            //
            if (fm.ShowDialog() == DialogResult.OK)
            {
                if (!ctrlData.Sua <Thuoc>(new Thuoc(fm.txtMa.Text, fm.txtTen.Text, (int)fm.nudSoLuong.Value, fm.dtpNSX.Value, fm.dtpHSD.Value, fm.txtDonVi.Text, (int)fm.nudDonGia.Value, fm.txtGhiChu.Text, fm.nhasx, fm.nhacc, fm.nthuoc)))
                {
                    MessageBox.Show("Sửa thất bại!");
                    return;
                }
            }
        }
        // Sua
        public void Sua(string Ma)
        {
            var nsx = ctrlData.ListItems <NhomThuoc>(Ma, "Ma", Const.TextFindOption.Absolute)[0];
            //
            fmPopupNThuoc fm = new fmPopupNThuoc("Sửa nhóm thuốc");

            fm.StartPosition  = FormStartPosition.CenterParent;
            fm.txtMa.ReadOnly = true;
            fm.txtMa.Text     = nsx.Ma;
            fm.txtTen.Text    = nsx.Ten;
            fm.txtGhiChu.Text = nsx.GhiChu;
            //
            if (fm.ShowDialog() == DialogResult.OK)
            {
                if (!ctrlData.Sua <NhomThuoc>(new NhomThuoc(Ma, fm.txtTen.Text, fm.txtGhiChu.Text)))
                {
                    MessageBox.Show("Sửa thất bại!");
                    return;
                }
            }
        }
        // Sua
        public void Sua(string Ma)
        {
            var nsx = ctrlData.ListItems <NhaSanXuat>(Ma, "Ma", Const.TextFindOption.Absolute)[0];
            //
            fmPopupNSX fm = new fmPopupNSX("Sửa nhà sản xuất");

            fm.StartPosition  = FormStartPosition.CenterParent;
            fm.txtMa.ReadOnly = true;
            fm.txtMa.Text     = nsx.Ma;
            fm.txtTen.Text    = nsx.Ten;
            fm.txtSDT.Text    = nsx.SDT;
            fm.txtDiaChi.Text = nsx.DiaChi;
            //
            if (fm.ShowDialog() == DialogResult.OK)
            {
                if (!ctrlData.Sua <NhaSanXuat>(new NhaSanXuat(Ma, fm.txtTen.Text, fm.txtSDT.Text, fm.txtDiaChi.Text)))
                {
                    MessageBox.Show("Sửa thất bại!");
                    return;
                }
            }
        }