Пример #1
0
        public string PhatSinhMaCTHD(string maHoaDon)
        {
            string maCTHD = maHoaDon;
            List <ChiTietHoaDon> cthds = qlcf.ChiTietHoaDons.Where(ct => ct.MaHoaDon == maHoaDon).Select(ct => ct).ToList();
            ChiTietHoaDon        cthd  = cthds.LastOrDefault();

            if (cthd == null)
            {
                maCTHD += "_1000";
            }
            else
            {
                int k;
                k       = Convert.ToInt32(cthd.MaCTHD.Substring(7, 4));
                k      += 1;
                maCTHD += "_" + k.ToString();
            }
            return(maCTHD);
        }
        public int AddChiTietHoaDons(string MaPN, string MaSP, int soLuong, int tongTien)
        {
            ChiTietHoaDon chitiethoadons = qlhh.ChiTietHoaDons.Where(t => t.MaHoaDon == MaPN && t.MaSanPham == MaPN).FirstOrDefault();

            if (chitiethoadons == null)
            {
                ChiTietHoaDon cthd = new ChiTietHoaDon();
                cthd.MaHoaDon  = MaPN;
                cthd.MaSanPham = MaSP;
                cthd.SoLuong   = soLuong;
                cthd.TongTien  = tongTien;
                qlhh.ChiTietHoaDons.InsertOnSubmit(cthd);
                qlhh.SubmitChanges();
                return(1);
            }
            else
            {
                return(0);
            }
        }
Пример #3
0
        public void InsertChiTietHoaDon(string maHoaDon, string maDoUong)
        {
            ChiTietHoaDon cts = qlcf.ChiTietHoaDons.Where(ct => ct.MaHoaDon == maHoaDon && ct.MaDoUong == maDoUong).FirstOrDefault();

            if (cts == null)
            {
                ChiTietHoaDon cthd = new ChiTietHoaDon();
                cthd.MaCTHD    = PhatSinhMaCTHD(maHoaDon);
                cthd.MaHoaDon  = maHoaDon;
                cthd.MaDoUong  = maDoUong;
                cthd.SoLuong   = 1;
                cthd.ThanhTien = GetDonGiaDoUong(maDoUong);

                qlcf.ChiTietHoaDons.InsertOnSubmit(cthd);
                qlcf.SubmitChanges();
            }
            else
            {
                cts.SoLuong++;
                cts.ThanhTien = cts.SoLuong * GetDonGiaDoUong(maDoUong);
                qlcf.SubmitChanges();
            }
        }