Exemple #1
0
        private void ReloadData()
        {
            ThreadHelper.LoadForm(() =>
            {
                CRUD.DisposeDb();

                if (tabControl.SelectedTabPage == tabNhaCungCap)
                {
                    _khachHangs = CRUD.DbContext.KhachHangs.Where(s => s.IsActived && s.LoaiKhachHang == _loaiKhachHang.ToString()).ToList();
                    gridControlKhachHang.DataSource = _khachHangs;
                }

                if (tabControl.SelectedTabPage == tabNhapKho)
                {
                    var startDate = NhapKho_StartDate.Value;
                    var endDate   = NhapKho_EndDate.Value;
                    _donHangs     =
                        CRUD.DbContext.DonHangs
                        .Where(s => s.IsActived &&
                               s.LoaiDonHang == _loaiDonHang.ToString() &&
                               s.NgayLap >= startDate &&
                               s.NgayLap <= endDate)
                        .ToList();
                    gridControlNhapKho.DataSource = _donHangs;
                }

                if (tabControl.SelectedTabPage == tabCongNo)
                {
                    ucCongNoList1.SetLoaiDonHang(_loaiDonHang, Define.LoaiTienTeEnum.VND);
                }

                if (tabControl.SelectedTabPage == tabCongNoUSD)
                {
                    ucCongNoList2.SetLoaiDonHang(_loaiDonHang, Define.LoaiTienTeEnum.USD);
                }

                if (tabControl.SelectedTabPage == tabThanhToan)
                {
                    var startDate = ThanhToan_StartDate.Value;
                    var endDate   = ThanhToan_EndDate.Value;

                    _thanhToanCongNoes = CRUD.DbContext.ThanhToanCongNoes
                                         .Where(s => s.IsActived &&
                                                s.CongNo.IsActived &&
                                                s.CongNo.LoaiDonHang == _loaiDonHang.ToString() &&
                                                s.NgayThanhToan >= startDate &&
                                                s.NgayThanhToan <= endDate).ToList();
                    gridControlThanhToan.DataSource = _thanhToanCongNoes;
                }
            });
        }
Exemple #2
0
        public UcCongNoCu(Define.LoaiDonHangEnum loaiDonHang, Define.LoaiTienTeEnum loaiTienTe)
        {
            InitializeComponent();

            CongNo_KhachHangId.DisplayMember = "Ten";
            CongNo_KhachHangId.ValueMember   = "Id";
            var lstKhachHang = new List <KhachHang>();

            if (loaiDonHang == Define.LoaiDonHangEnum.XuatKho)
            {
                lstKhachHang        = CRUD.DbContext.KhachHangs.Where(s => s.LoaiKhachHang != Define.LoaiKhachHangEnum.NhaCungCap.ToString()).ToList();
                lblKhachHangId.Text = "Khách Hàng";
            }
            else
            {
                lstKhachHang = CRUD.DbContext.KhachHangs.Where(s => s.LoaiKhachHang == Define.LoaiKhachHangEnum.NhaCungCap.ToString()).ToList();
            }
            CongNo_KhachHangId.DataSource = new BindingSource((lstKhachHang), null);

            CongNo_LoaiTienTe.DisplayMember = "Value";
            CongNo_LoaiTienTe.ValueMember   = "Key";
            CongNo_LoaiTienTe.DataSource    = new BindingSource(Define.LoaiTienTeDict, null);

            _domainData             = new CongNo();
            _domainData.NgayLap     = TimeHelper.CurentDateTime();
            _domainData.LoaiDonHang = loaiDonHang.ToString();
            _domainData.LoaiTienTe  = loaiTienTe.ToString();

            Init(_domainData);
        }
Exemple #3
0
        public override bool SaveData()
        {
            var validateResult = ValidateInput();

            if (!string.IsNullOrEmpty(validateResult))
            {
                MessageBox.Show(validateResult);
                return(false);
            }

            var saveData = CRUD.GetFormObject <CongNo>(FormControls);

            CRUD.DecorateSaveData(saveData);
            saveData.LoaiDonHang = _loaiDonHang.ToString();
            CRUD.DbContext.CongNoes.AddOrUpdate(saveData);
            CRUD.DbContext.SaveChanges();

            return(true);
        }
Exemple #4
0
        public UcDonHang(Define.LoaiDonHangEnum loaiDonHang, DonHang data = null)
        {
            InitializeComponent();

            DonHang_KhachHangId.DisplayMember = "Ten";
            DonHang_KhachHangId.ValueMember   = "Id";
            var lstKhachHang = new List <KhachHang>();

            if (loaiDonHang == Define.LoaiDonHangEnum.XuatKho)
            {
                lstKhachHang        = CRUD.DbContext.KhachHangs.Where(s => s.LoaiKhachHang != Define.LoaiKhachHangEnum.NhaCungCap.ToString()).ToList();
                lblKhachHangId.Text = "Khách Hàng";
            }
            else
            {
                lstKhachHang = CRUD.DbContext.KhachHangs.Where(s => s.LoaiKhachHang == Define.LoaiKhachHangEnum.NhaCungCap.ToString()).ToList();
            }
            DonHang_KhachHangId.DataSource = new BindingSource((lstKhachHang), null);

            DonHang_LoaiTienTe.DisplayMember = "Value";
            DonHang_LoaiTienTe.ValueMember   = "Key";
            DonHang_LoaiTienTe.DataSource    = new BindingSource(Define.LoaiTienTeDict, null);

            _loaiDonHang = loaiDonHang;
            _domainData  = data;
            if (_domainData == null)
            {
                _domainData             = new DonHang();
                _domainData.NgayLap     = TimeHelper.CurentDateTime();
                _domainData.LoaiDonHang = loaiDonHang.ToString();
                _domainData.TrangThai   = Define.TrangThaiDonHang.Moi.ToString();
                _domainData.LoaiTienTe  = Define.LoaiTienTeEnum.VND.ToString();
                _domainData.TyGia       = 1;

                btnDelete.Visible = false;
                btnIn.Visible     = false;
                GenerateMaDH();
            }
            else
            {
                _chiTietDonhang = new BindingList <ChiTietDonHang>(_domainData.ChiTietDonHangs.ToList());
                if (_domainData.KhachHangId == Define.KhachLeId)
                {
                    var khachLe = lstKhachHang.FirstOrDefault(s => s.Id == Define.KhachLeId);
                    if (khachLe != null)
                    {
                        khachLe.Ten = _domainData.Ten;
                    }
                }
                btnDelete.Visible = true;

                _chiTietDonhang.ForEach(s => s.ListChiTietHangHoa = s.ChiTietHangHoas.ToList());

                if (_domainData.TrangThai == Define.TrangThaiDonHang.ThanhToan.ToString())
                {
                    btnSave.Enabled        = false;
                    btnDelete.Visible      = false;
                    _domainData.ThanhToan += _domainData.CongNoes.Where(l => l.IsActived).Sum(l => l.ThanhToan);
                }
            }

            Init(_domainData);

            // Get list hang hoa
            var dataSource = CRUD.DbContext.KhoHangs
                             .Where(s => s.IsActived &&
                                    (loaiDonHang == Define.LoaiDonHangEnum.NhapKho || s.SoLuong > 0))
                             .Select(s => new { s.TenHang, s.Id })
                             .Union(CRUD.DbContext.ChiTietDonHangs
                                    .Where(s => _domainData.Id == s.DonHangId)
                                    .Join(CRUD.DbContext.KhoHangs, ctdh => ctdh.HangHoaId, kh => kh.Id,
                                          (ctdh, kh) => new { kh.TenHang, kh.Id })).ToList();

            FormBehavior.DecoreateLookEdit(listHangHoa, dataSource, "TenHang");
            listHangHoa.EditValueChanged += listHangHoa_EditValueChanged;

            gridControlChiTiet.DataSource      = _chiTietDonhang;
            gridViewChiTiet.ActiveFilterString = string.Format("[IsActived] = '{0}'", true);

            CheckDonHangUSD();

            btnDeleteRow.ButtonClick += btnDeleteRow_ButtonClick;

            UpdateTongTien();
            UpdateNo();
        }
Exemple #5
0
        public override bool SaveData()
        {
            var validateResult = ValidateInput();

            if (!string.IsNullOrEmpty(validateResult))
            {
                MessageBox.Show(validateResult);
                return(false);
            }

            var thanhToan = PrimitiveConvert.StringToInt(ThanhToanCongNo_ThanhToan.Text);
            var no        = PrimitiveConvert.StringToInt(CongNo_No.Text);

            using (var transaction = new TransactionScope())
            {
                if (thanhToan > no)
                {
                    foreach (var congNo in _congNoes)
                    {
                        CRUD.DecorateSaveData(congNo);
                        var tienThanhToan = thanhToan;
                        if (congNo.No >= thanhToan)
                        {
                            thanhToan = 0;
                        }
                        else
                        {
                            tienThanhToan = (long)congNo.No;
                            thanhToan    -= (long)congNo.No;
                        }
                        congNo.No -= tienThanhToan;

                        var thanhToanCongNo = CRUD.GetFormObject <ThanhToanCongNo>(FormControls);
                        thanhToanCongNo.ThanhToan = tienThanhToan;
                        thanhToanCongNo.CongNoId  = congNo.Id;
                        CRUD.DecorateSaveData(thanhToanCongNo);
                        CRUD.DbContext.ThanhToanCongNoes.Add(thanhToanCongNo);


                        if (thanhToan <= 0)
                        {
                            break;
                        }
                    }
                    CRUD.DbContext.SaveChanges();
                }
                else
                {
                    // Update cong no
                    var congNo = CRUD.GetFormObject <CongNo>(FormControls);
                    congNo.DonHangId   = _domainData.DonHangId;
                    congNo.KhachHangId = _domainData.KhachHangId;
                    congNo.NgayLap     = _domainData.NgayLap;
                    congNo.LoaiDonHang = _loaiDonHang.ToString();
                    CRUD.DecorateSaveData(congNo, _domainData);
                    UpdateCongNo(congNo);
                }

                transaction.Complete();
            }

            return(true);
        }