Example #1
0
        public List <CTPHIEUNHAP> dsPhieuNhapById(int maphieu)
        {
            List <CTPHIEUNHAP> listCT = new List <CTPHIEUNHAP>();

            using (ContextEntites con = new ContextEntites())
            {
                try
                {
                    var lct = con.CTPHIEUNHAPs.Where(x => x.MAPHIEU == maphieu);
                    foreach (var ct in lct)
                    {
                        CTPHIEUNHAP ctph = new CTPHIEUNHAP();
                        ctph.MAPHIEU = ct.MAPHIEU;
                        ctph.MADC    = ct.MADC;
                        ctph.SL      = ct.SL;
                        ctph.GIANHAP = ct.GIANHAP;
                        listCT.Add(ctph);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            return(listCT);
        }
Example #2
0
        public ActionResult Chonhang(FormCollection collection)
        {
            Phieunhap   ddh = new Phieunhap();
            Nhanvien    nv  = (Nhanvien)Session["Taikhoan"];
            List <Nhap> gh  = Layds();

            ddh.NhanVien = nv.MaNV;
            ddh.Ngaylap  = DateTime.Now;

            kho.Phieunhaps.InsertOnSubmit(ddh);
            kho.SubmitChanges();
            foreach (var item in gh)
            {
                CTPHIEUNHAP ctpx = new CTPHIEUNHAP();
                ctpx.Manhap      = ddh.MaNhap;
                ctpx.MaMH        = item.iMaMH;
                ctpx.SoluongNhap = item.iSoluong;
                ctpx.Gianhap     = item.dDonggia;
                ctpx.Tongtien    = item.dThanhtien;
                kho.CTPHIEUNHAPs.InsertOnSubmit(ctpx);
                //ctdh.Masach = item.iMasach;
                //ctdh.Soluong = item.iSoluong;
                //ctdh.Dongia = (decimal)item.dDonggia;
                //data.CTDATHANGs.InsertOnSubmit(ctdh);
            }
            kho.SubmitChanges();
            Session["Nhap"] = null;
            return(RedirectToAction("Xacnhan", "Nhap"));
        }
Example #3
0
        private void btn_nhap_Click(object sender, EventArgs e)
        {
            if (locked)
            {
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(tb_masp.Text) ||
                    string.IsNullOrEmpty(tb_tenDC.Text) ||
                    int.Parse(tb_SL.Text) == 0 ||
                    string.IsNullOrEmpty(tb_SL.Text))
                {
                    MessageBox.Show("Thiếu Dữ Liệu!");
                    return;
                }
                CTPHIEUNHAP ct = new CTPHIEUNHAP();
                if (!masp_avail)
                {
                    DoChoiBus dcBus = new DoChoiBus();
                    DOCHOI    dc    = new DOCHOI();

                    dc.MADC = int.Parse(tb_masp.Text);
                    dc.SL   = int.Parse(tb_SL.Text);//edit dc.SL=0;
                    dc.GIA  = double.Parse(tb_GiaBan.Text);
                    //listNewDC.Add(dc);
                }

                ///<summary>
                ///hậu
                ///</summary>
                CTPHIEUNHAP ctph = new CTPHIEUNHAP();
                ctph.MAPHIEU = phieu.MAPHIEU;
                ctph.MADC    = int.Parse(tb_masp.Text);
                ctph.SL      = int.Parse(tb_SL.Text);
                ctph.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ctph.SL;

                tong_giatri += (double)ctph.GIANHAP;
                tong_sl     += (int)ctph.SL;

                var li = listCTPN.Where(i => i.MADC == ctph.MADC);
                if (li.Count() > 0)
                {
                    li.First().SL      += ctph.SL;
                    li.First().GIANHAP += ctph.GIANHAP;
                }
                else
                {
                    listCTPN.Add(ctph);
                }

                refreshDataGrid();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Example #4
0
        public bool deleteCTPhieuNhap(CTPHIEUNHAP item)
        {
            bool      ck    = false;
            DoChoiDao dcDao = new DoChoiDao();

            ck = dcDao.addSLDC(item.MADC, -1 * item.SL);
            ck = ck && ctDao.deleteCTPhieuNhap(item.MAPHIEU);
            return(ck);
        }
Example #5
0
        public CTPHIEUNHAP CTPHIEUNHAPbyID(int maphieu, int madc)
        {
            CTPHIEUNHAP ct = new CTPHIEUNHAP();

            using (ContextEntites context = new ContextEntites())
            {
                var a = context.CTPHIEUNHAPs.SingleOrDefault(x => x.MAPHIEU == maphieu && x.MADC == madc);
                ct = a;
            }
            return(ct);//
        }
Example #6
0
        public bool editCTPhieuNhap(CTPHIEUNHAP item)
        {
            bool ck = false;

            int       delta = item.SL - ctDao.CTPHIEUNHAPbyID(item.MAPHIEU, item.MADC).SL;
            DoChoiDao dcDao = new DoChoiDao();

            ck = dcDao.addSLDC(item.MADC, delta);
            ck = ck && ctDao.editCTPhieuNhap(item);
            return(ck);
        }
Example #7
0
        private void tbl_CtPhieuNhap_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (!(tbl_CtPhieuNhap.SelectedRows.Count > 0))
            {
                return;
            }
            CTPHIEUNHAP ct = new CTPHIEUNHAP();

            ct.GIANHAP = (double)tbl_CtPhieuNhap.SelectedRows[0].Cells["GIANHAP"].Value;
            ct.MADC    = (int)tbl_CtPhieuNhap.SelectedRows[0].Cells["MADC"].Value;
            ct.MAPHIEU = (int)tbl_CtPhieuNhap.SelectedRows[0].Cells["MAPHIEU"].Value;
            ct.SL      = (int)tbl_CtPhieuNhap.SelectedRows[0].Cells["SL"].Value;

            changed_item.Add(ct);
            data_change = true;
        }
Example #8
0
        private void bt_XoaNhieu_Click(object sender, EventArgs e)
        {
            if (!(tbl_CtPhieuNhap.SelectedRows.Count > 0))
            {
                return;
            }
            CTPHIEUNHAP ct = new CTPHIEUNHAP();

            ct.GIANHAP = (double)tbl_CtPhieuNhap.SelectedRows[0].Cells["GIANHAP"].Value;
            ct.MADC    = (int)tbl_CtPhieuNhap.SelectedRows[0].Cells["MADC"].Value;
            ct.MAPHIEU = (int)tbl_CtPhieuNhap.SelectedRows[0].Cells["MAPHIEU"].Value;
            ct.SL      = (int)tbl_CtPhieuNhap.SelectedRows[0].Cells["SL"].Value;

            deleted_item.Add(ct);
            listCT.Remove(ct);
            tbl_CtPhieuNhap.Refresh();
            data_change = true;
        }
Example #9
0
        public int AddCTPhieuNhap(CTPHIEUNHAP ct)
        {
            int s;

            using (ContextEntites cn = new ContextEntites())
            {
                try
                {
                    cn.CTPHIEUNHAPs.Add(ct);
                    s = cn.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    s = 0;
                }
            }
            return(s);
        }
        public void ThemChiTietNhap(CTPhieuNhap_DTO a)
        {
            CTPHIEUNHAP b = new CTPHIEUNHAP();

            b.ThanhTien   = a.ThanhTien;
            b.SoPhieuNhap = a.SoPhieuNhap;
            b.SLNhap      = a.SLNhap;
            b.MaSP        = a.MaSP;
            b.DonGia      = a.DonGia;
            DB.CTPHIEUNHAPs.InsertOnSubmit(b);
            var obj = DB.PHIEUNHAPs.Single(x => x.SoPhieuNhap == a.SoPhieuNhap);

            obj.TongTien += a.ThanhTien;
            var c = DB.SANPHAMs.Single(x => x.MaSP == a.MaSP);

            c.SoLuongTon += a.SLNhap;
            //obj.NgayLap = DateTime.Parse(a.NgayLap);
            //DB.SubmitChanges();
            DB.SubmitChanges();
        }
Example #11
0
        public bool editCTPhieuNhap(CTPHIEUNHAP ct)
        {
            bool chek = false;

            using (ContextEntites context = new ContextEntites())
            {
                try
                {
                    var s = context.CTPHIEUNHAPs.Single(x => (x.MADC == ct.MADC && x.MAPHIEU == ct.MAPHIEU));
                    s.SL = ct.SL;

                    if (context.SaveChanges() >= 0)
                    {
                        chek = true;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            return(chek);
            //change
        }
Example #12
0
        public BookImportViewVM()
        {
            ButtonName         = "Thêm sách";
            IsEnabledListView2 = true;
            isSaved            = true;
            AddCommand         = new RelayCommand <Button>((p) => { return(isSaved ? true : false); }, (p) =>
            {
                IsEnabledTextBox  = true;
                IsEnabledCBBox    = true;
                IsEnabledListView = true;
                IsAdding          = true;
                isSaved           = false;
                var receiptNote   = new PHIEUNHAPSACH()
                {
                    NGAYNHAP = DateTime.Now, TONGCHI = 0
                };
                Current      = receiptNote;
                SelectedItem = Current;
                DataProvider.Ins.DB.PHIEUNHAPSACHes.Add(receiptNote);
                DataProvider.Ins.DB.SaveChanges();

                ListReceiptNote.Add(receiptNote);
            });
            AddBookCmd = new RelayCommand <Button>((p) =>
            {
                if (SelectedBook == null || NumOfBook < 1 || SelectedItem == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }, (p) =>
            {
                if (!IsAdding)
                {
                    var book = DataProvider.Ins.DB.CTPHIEUNHAPs.Where(x => x.MASACH == SelectedReceiptNoteDetail.MASACH && x.MAPHIEUNHAP == SelectedReceiptNoteDetail.MAPHIEUNHAP).SingleOrDefault();
                    if (book == null)
                    {
                        MessageBoxWindow mess2 = new MessageBoxWindow();
                        mess2.Tag = "Không tìm thấy cuôn sách này";
                        mess2.ShowDialog();

                        // MessageBox.Show("Không tìm thấy cuôn sách này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    book.SOLUONG = NumOfBook;
                    book.DONGIA  = ImportPrice;
                    DataProvider.Ins.DB.SaveChanges();
                    IsAdding   = true;
                    ButtonName = "Thêm sách";
                }
                else
                {
                    var book = new CTPHIEUNHAP()
                    {
                        MAPHIEUNHAP = SelectedItem.MAPHIEUNHAP, MASACH = SelectedBook.MASACH, SOLUONG = NumOfBook, DONGIA = ImportPrice, THANHTIEN = 0
                    };
                    if (DataProvider.Ins.DB.CTPHIEUNHAPs.Where(x => x.MASACH == book.MASACH && x.MAPHIEUNHAP == book.MAPHIEUNHAP).Count() > 0)
                    {
                        MessageBoxWindow mess2 = new MessageBoxWindow();
                        mess2.Tag = "Đã thêm sách này";
                        mess2.ShowDialog();

                        // MessageBox.Show("Đã thêm sách này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        DataProvider.Ins.DB.CTPHIEUNHAPs.Add(book);
                        DataProvider.Ins.DB.SaveChanges();
                        ListReceiptNoteDetail.Add(book);

                        ListReceiptNoteDetail = new ObservableCollection <CTPHIEUNHAP>(DataProvider.Ins.DB.Database.SqlQuery <CTPHIEUNHAP>("SELECT * FROM CTPHIEUNHAP WHERE MAPHIEUNHAP = (SELECT MAX(MAPHIEUNHAP) FROM PHIEUNHAPSACH)"));
                    }
                }
                IsEnabledListView = true;
                IsEnabledCBBox    = true;
            });
            EditCommand = new RelayCommand <Button>((p) => { return(SelectedReceiptNoteDetail == null?false:true); }, (p) =>
            {
                IsAdding          = false;
                IsEnabledListView = false;
                IsEnabledTextBox  = true;
                IsEnabledCBBox    = false;
                ButtonName        = "Sửa dữ liệu";
            });
            SaveCommand = new RelayCommand <Button>((p) =>
            {
                if (IsEnabledListView)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }, (p) =>
            {
                DataProvider.Ins.DB.PHIEUNHAPSACHes.Where(x => x.MAPHIEUNHAP == SelectedItem.MAPHIEUNHAP).SingleOrDefault().TONGCHI = UpdateTotalPrice();
                DataProvider.Ins.DB.SaveChanges();
                UpdateNumOfBook();
                IsEnabledListView = false;
                Current           = null;
                isSaved           = true;
                ListReceiptNote   = new ObservableCollection <PHIEUNHAPSACH>(DataProvider.Ins.DB.Database.SqlQuery <PHIEUNHAPSACH>("SELECT * FROM PHIEUNHAPSACH WHERE MAPHIEUNHAP = (SELECT MAX(MAPHIEUNHAP) FROM PHIEUNHAPSACH)"));
            });
            DeleteReceiptNoteCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                var receiptNote = DataProvider.Ins.DB.PHIEUNHAPSACHes.Where(x => x.MAPHIEUNHAP == SelectedItem.MAPHIEUNHAP).SingleOrDefault();
                if (DataProvider.Ins.DB.CTPHIEUNHAPs.Where(x => x.MAPHIEUNHAP == SelectedItem.MAPHIEUNHAP).Count() > 0)
                {
                    DataProvider.Ins.DB.CTPHIEUNHAPs.RemoveRange(DataProvider.Ins.DB.CTPHIEUNHAPs.Where(x => x.MAPHIEUNHAP == SelectedItem.MAPHIEUNHAP));
                    DataProvider.Ins.DB.SaveChanges();
                    ListReceiptNoteDetail.Clear();
                }
                DataProvider.Ins.DB.PHIEUNHAPSACHes.Remove(receiptNote);
                DataProvider.Ins.DB.SaveChanges();

                ListReceiptNote.Remove(SelectedItem);
            });
            DeleteReceiptNoteDetailCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                var receiptNoteDetail = DataProvider.Ins.DB.CTPHIEUNHAPs.Where(x => x.MAPHIEUNHAP == SelectedReceiptNoteDetail.MAPHIEUNHAP && x.MASACH == SelectedReceiptNoteDetail.MASACH).SingleOrDefault();

                DataProvider.Ins.DB.CTPHIEUNHAPs.Remove(receiptNoteDetail);
                DataProvider.Ins.DB.SaveChanges();

                ListReceiptNoteDetail.Remove(SelectedReceiptNoteDetail);
            });
            ListBook        = new ObservableCollection <SACH>(DataProvider.Ins.DB.SACHes);
            ListReceiptNote = new ObservableCollection <PHIEUNHAPSACH>(DataProvider.Ins.DB.PHIEUNHAPSACHes);
        }
Example #13
0
        private void btn_nhap_Click(object sender, EventArgs e)
        {
            if (locked)
            {
                return;
            }
            try
            {
                if (string.IsNullOrEmpty(tb_masp.Text) ||
                    string.IsNullOrEmpty(tb_tenDC.Text) ||
                    int.Parse(tb_SL.Text) == 0 ||
                    string.IsNullOrEmpty(tb_SL.Text))
                {
                    MessageBox.Show("Thiếu Dữ Liệu!");
                    return;
                }
                CTPHIEUNHAP ct = new CTPHIEUNHAP();
                if (masp_avail == false)
                {
                    DoChoiBus dcBus = new DoChoiBus();
                    DOCHOI    dc    = new DOCHOI();

                    dc.MADC   = int.Parse(tb_masp.Text);
                    dc.SL     = int.Parse(tb_SL.Text);//edit dc.SL=0;
                    dc.GIA    = double.Parse(tb_GiaBan.Text);
                    dc.LOAI   = tb_loai.Text;
                    dc.NUOCSX = tb_ncsx.Text;
                    dc.TENDC  = tb_tenDC.Text;
                    // dcBus.AddDoChoi(dc);

                    listDc.Add(dc);

                    ct.MADC    = dc.MADC;
                    ct.MAPHIEU = phieu.MAPHIEU;
                    ct.SL      = (int)dc.SL;
                    ct.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ct.SL;
                    listCTPN.Add(ct);
                }

                else
                {
                    masp_avail = true;
                    var li = listCTPN.Where(i => i.MADC == ct.MADC);
                    if (li.Count() > 0)
                    {
                        li.First().SL      += ct.SL;
                        li.First().GIANHAP += ct.GIANHAP;
                    }
                    ct.MADC    = int.Parse(tb_masp.Text);
                    ct.MAPHIEU = phieu.MAPHIEU;
                    ct.SL      = int.Parse(tb_SL.Text);
                    ct.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ct.SL;


                    listCTPN.Add(ct);
                }

                ///<summary>
                ///hậu
                ///</summary>
                //CTPHIEUNHAP ctph = new CTPHIEUNHAP();
                //ctph.MAPHIEU = phieu.MAPHIEU;
                //ctph.MADC = int.Parse(tb_masp.Text);
                //ctph.SL = int.Parse(tb_SL.Text);
                //ctph.GIANHAP = double.Parse(tb_GiaNhap.Text) * (double)ctph.SL;

                //tong_giatri += (double)ctph.GIANHAP;
                //tong_sl += (int)ctph.SL;

                //var li = listCTPN.Where(i => i.MADC == ctph.MADC);
                //if (li.Count() > 0)
                //{
                //    li.First().SL += ctph.SL;
                //    li.First().GIANHAP += ctph.GIANHAP;
                //}
                //else
                //    listCTPN.Add(ctph);
                tong_giatri += (double)ct.GIANHAP;
                tong_sl     += (int)ct.SL;
                refresh();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }