Пример #1
0
 public bool xoaCTHD(ChiTietHoaDon chiTietHoaDon)
 {
     try
     {
         var ketQua = (from item in ketNoi.ChiTietHoaDons
                       where item.MaChiTietHoaDon == chiTietHoaDon.MaChiTietHoaDon
                       select item).FirstOrDefault();
         ketNoi.ChiTietHoaDons.DeleteOnSubmit(ketQua);
         ketNoi.SubmitChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
Пример #2
0
 public bool themCTHoaDon(ChiTietHoaDon item)
 {
     try
     {
         ketNoi.Connection.Close();
         ketNoi.Connection.Open();
         ketNoi.SubmitChanges();
         ketNoi.ChiTietHoaDons.InsertOnSubmit(item);
         ketNoi.SubmitChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
Пример #3
0
        public bool ThemCTHD(ChiTietHoaDon cthd)
        {
            string       sql     = "insert into ChiTietHoaDon values(@mahd,@tpt,@sl,@madv)";
            SqlParameter parMahd = new SqlParameter("@mahd", System.Data.SqlDbType.VarChar);

            parMahd.Value = cthd.MaHoaDon;
            SqlParameter parTtdv = new SqlParameter("@tpt", System.Data.SqlDbType.Float);

            parTtdv.Value = cthd.TongTienDichVu;
            SqlParameter parSldv = new SqlParameter("@sl", System.Data.SqlDbType.Int);

            parSldv.Value = cthd.SoLuongDichVu;
            SqlParameter parMadv = new SqlParameter("@madv", System.Data.SqlDbType.VarChar);

            parMadv.Value = cthd.MaDichVu;
            bool kq = WriteData(sql, new[] { parMahd, parTtdv, parSldv, parMadv });

            return(kq);
        }
Пример #4
0
 public bool CthoadonInsert(ChiTietHoaDon chitiethoadon)
 {
     try
     {
         openConnect();
         SqlCommand cmd = new SqlCommand("CTHOADON_INSERT", con);
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add(new SqlParameter("MASANPHAM", chitiethoadon.MaSanPham));
         cmd.Parameters.Add(new SqlParameter("DONGIA", Convert.ToDouble(chitiethoadon.DonGia)));
         cmd.Parameters.Add(new SqlParameter("SOLUONG", chitiethoadon.SoLuong));
         cmd.ExecuteNonQuery();
         closeConnect();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #5
0
        public bool SuaCTHD(ChiTietHoaDon cthd)
        {
            string       sql     = "update ChiTietHoaDon set TongTienDichVu = @tpt, SoLuongDichVu = @sldv where MaHoaDon = @mahd and MaDichVu = @madv";
            SqlParameter parMahd = new SqlParameter("@mahd", System.Data.SqlDbType.VarChar);

            parMahd.Value = cthd.MaHoaDon;
            SqlParameter parTtdv = new SqlParameter("@tpt", System.Data.SqlDbType.Float);

            parTtdv.Value = cthd.TongTienDichVu;
            SqlParameter parSoLuong = new SqlParameter("@sldv", System.Data.SqlDbType.Int);

            parSoLuong.Value = cthd.SoLuongDichVu;
            SqlParameter parMadv = new SqlParameter("@madv", System.Data.SqlDbType.VarChar);

            parMadv.Value = cthd.MaDichVu;
            bool kq = WriteData(sql, new[] { parMahd, parTtdv, parSoLuong, parMadv });

            return(kq);
        }
Пример #6
0
        public Boolean ThemChiTietHoaDon(ChiTietHoaDon cthd)
        {
            OpenConn();
            string     sql     = "insert into ChiTietHoaDon values(@maHD,@maSP,@soluong)";
            SqlCommand sqlComm = new SqlCommand(sql, conn);

            sqlComm.Parameters.Add(new SqlParameter("@maHD", SqlDbType.NChar)).Value  = cthd.MaHoaDon;
            sqlComm.Parameters.Add(new SqlParameter("@soluong", SqlDbType.Int)).Value = cthd.SoLuong;
            sqlComm.Parameters.Add(new SqlParameter("@maSP", SqlDbType.NChar)).Value  = cthd.MaSanPham;
            int kq = sqlComm.ExecuteNonQuery();

            CloseConn();
            if (kq != 0)
            {
                return(true);
            }

            return(false);
        }
Пример #7
0
        public List <ChiTietHoaDon> layChiTietHoaDonTheoMa(string maHoaDon)
        {
            List <ChiTietHoaDon> arr = new List <ChiTietHoaDon>();

            Connect.openConnect();
            string     query = "select * from ChiTietHoaDon where maHoaDon=@maHoaDon ";
            SqlCommand cmd   = new SqlCommand(query, Connect.connect);

            cmd.Parameters.AddWithValue("maHoaDon", maHoaDon);

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                ChiTietHoaDon x = new ChiTietHoaDon(int.Parse(dr["maHang"] + ""), int.Parse(dr["maHoaDon"] + ""), int.Parse(dr["soLuong"] + ""), float.Parse(dr["thanhTien"] + ""));
                arr.Add(x);
            }
            Connect.closeConnect();
            return(arr);
        }
Пример #8
0
        public List <ChiTietHoaDon> DSChiTietHoaDon(string mahd)
        {
            SqlDataReader        reader = ReadData("select * from ChiTietHoaDon where MaHoaDon = '" + mahd + "'");
            List <ChiTietHoaDon> dsCTHD = new List <ChiTietHoaDon>();

            while (reader.Read())
            {
                string        mahoadon       = reader.GetString(0);
                double        tongtiendichvu = reader.GetDouble(1);
                int           soluongdichvu  = reader.GetInt32(2);
                string        madichvu       = reader.GetString(3);
                ChiTietHoaDon cthd           = new ChiTietHoaDon();
                cthd.MaHoaDon       = mahoadon;
                cthd.TongTienDichVu = tongtiendichvu;
                cthd.MaDichVu       = madichvu;
                cthd.SoLuongDichVu  = soluongdichvu;
                dsCTHD.Add(cthd);
            }
            reader.Close();
            return(dsCTHD);
        }
Пример #9
0
        public bool SuaCTHD(ChiTietHoaDon cthd)
        {
            string       sql     = "update ChiTietHoaDon set MaHD = @mahd, TienPhaiTra = @tpt, SoLuongDV = @sldv, MaDV = @madv, Thang = @thang";
            SqlParameter parMahd = new SqlParameter("@mahd", System.Data.SqlDbType.VarChar);

            parMahd.Value = cthd.MaHD;
            SqlParameter parTpt = new SqlParameter("@tpt", System.Data.SqlDbType.Float);

            parTpt.Value = cthd.TienPhaiTra;
            SqlParameter parSoLuong = new SqlParameter("@sl", System.Data.SqlDbType.Int);

            parSoLuong.Value = cthd.SoLuongDV;
            SqlParameter parMadv = new SqlParameter("@madv", System.Data.SqlDbType.VarChar);

            parMadv.Value = cthd.MaDV;
            SqlParameter parThang = new SqlParameter("@thang", System.Data.SqlDbType.VarChar);

            parThang.Value = cthd.Thang;
            bool kq = WriteData(sql, new[] { parMahd, parTpt, parSoLuong, parMadv, parThang });

            return(kq);
        }
Пример #10
0
        public List <ChiTietHoaDon> DSChiTietHoaDon()
        {
            SqlDataReader        reader = ReadData("select * from ChiTietHoaDon");
            List <ChiTietHoaDon> dsCTHD = new List <ChiTietHoaDon>();

            while (reader.Read())
            {
                string        mahoadon       = reader.GetString(0);
                float         tongtiendichvu = float.Parse(reader.GetString(1));
                int           soluongdichvu  = int.Parse(reader.GetString(2));
                string        madichvu       = reader.GetString(3);
                int           thang          = int.Parse(reader.GetString(4));
                ChiTietHoaDon cthd           = new ChiTietHoaDon();
                cthd.MaHoaDon       = mahoadon;
                cthd.TongTienDichVu = tongtiendichvu;
                cthd.MaDichVu       = madichvu;
                cthd.SoLuongDichVu  = soluongdichvu;
                dsCTHD.Add(cthd);
            }
            reader.Close();
            return(dsCTHD);
        }
Пример #11
0
        public bool ThemCTHD(ChiTietHoaDon cthd)
        {
            string       sql     = "insert into ChiTietHoaDon values(@mahd,@tpt,@sl,@madv,@thang)";
            SqlParameter parMahd = new SqlParameter("@mahd", System.Data.SqlDbType.VarChar);

            parMahd.Value = cthd.MaHD;
            SqlParameter parTpt = new SqlParameter("@tpt", System.Data.SqlDbType.Float);

            parTpt.Value = cthd.TienPhaiTra;
            SqlParameter parSldv = new SqlParameter("@sl", System.Data.SqlDbType.Int);

            parSldv.Value = cthd.SoLuongDV;
            SqlParameter parMadv = new SqlParameter("@madv", System.Data.SqlDbType.VarChar);

            parMadv.Value = cthd.MaDV;
            SqlParameter parThang = new SqlParameter("@thang", System.Data.SqlDbType.Int);

            parThang.Value = cthd.Thang;
            bool kq = WriteData(sql, new[] { parMahd, parTpt, parSldv, parMadv, parThang });

            return(kq);
        }
Пример #12
0
        public List <ChiTietHoaDon> TimCTHD(string MaHD)
        {
            SqlDataReader        reader = ReadData("select * from ChiTietHoaDon where MaHD = " + MaHD);
            List <ChiTietHoaDon> dsCTHD = new List <ChiTietHoaDon>();

            while (reader.Read())
            {
                string        mahd  = reader.GetString(0);
                float         tpt   = float.Parse(reader.GetString(1));
                int           sldv  = int.Parse(reader.GetString(2));
                string        madv  = reader.GetString(3);
                int           thang = int.Parse(reader.GetString(4));
                ChiTietHoaDon cthd  = new ChiTietHoaDon();
                cthd.MaHD        = mahd;
                cthd.TienPhaiTra = tpt;
                cthd.MaDV        = madv;
                cthd.SoLuongDV   = sldv;
                cthd.Thang       = thang;
                dsCTHD.Add(cthd);
            }
            reader.Close();
            return(dsCTHD);
        }
        public bool capNhat(ChiTietHoaDon chiTietHoaDon)
        {
            try
            {
                var ketQua = (from chitiet in ketNoi.ChiTietHoaDons
                              where chitiet.MaChiTietHoaDon == chiTietHoaDon.MaChiTietHoaDon
                              select chitiet);

                foreach (var tam in ketQua)
                {
                    tam.SoLuong   = chiTietHoaDon.SoLuong;
                    tam.MaHoaDon  = chiTietHoaDon.MaHoaDon;
                    tam.MaSanPham = chiTietHoaDon.MaSanPham;
                }

                ketNoi.SubmitChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Пример #14
0
        public List <ChiTietHoaDon> TimTheoMaHoaDon(int mahd)
        {
            List <ChiTietHoaDon> list = new List <ChiTietHoaDon>();

            OpenConn();
            string     sql     = "select * from ChiTietHoaDon where MaHoaDon=@mahd";
            SqlCommand sqlComm = new SqlCommand(sql, conn);

            sqlComm.Parameters.Add(new SqlParameter("@mahd", SqlDbType.NChar)).Value = mahd;
            SqlDataReader sqlDr = sqlComm.ExecuteReader();

            while (sqlDr.Read())
            {
                ChiTietHoaDon cthd = new ChiTietHoaDon();
                cthd.MaHoaDon  = sqlDr.GetInt32(0);
                cthd.MaSanPham = sqlDr.GetString(1);
                cthd.SoLuong   = sqlDr.GetInt32(2);
                list.Add(cthd);
            }
            sqlDr.Close();
            CloseConn();
            return(list);
        }
 //Thêm loại chi tiết hóa đơn
 public Result InsertCTHD(string MaHD, string MaHang, string SoLuong, string DonGia)
 {
     if (checkPrimaryKeyMaChiTietHoaDon(MaHD, MaHang) == false)
     {
         return(Result.PRIMARY_KEY);
     }
     try
     {
         ChiTietHoaDon hd = new ChiTietHoaDon();
         hd.MaHD      = MaHD;
         hd.MaHang    = MaHang;
         hd.SoLuong   = int.Parse(SoLuong);
         hd.DonGia    = decimal.Parse(DonGia);
         hd.ThanhTien = hd.SoLuong * hd.DonGia;
         qlch.ChiTietHoaDons.InsertOnSubmit(hd);
         qlch.SubmitChanges();
         return(Result.SUCCESS);
     }
     catch
     {
         return(Result.FAILED);
     }
 }
Пример #16
0
 partial void UpdateChiTietHoaDon(ChiTietHoaDon instance);
Пример #17
0
 partial void InsertChiTietHoaDon(ChiTietHoaDon instance);
Пример #18
0
        //Lây số lượng hàng hóa cũ
        public int GetSoLuongCu(string mahd, string mamh)
        {
            ChiTietHoaDon ct = da.ChiTietHoaDons.Where(t => t.maHD == mahd && t.maMH == mamh).SingleOrDefault();

            return((int)ct.SoLuong);
        }
Пример #19
0
 partial void DeleteChiTietHoaDon(ChiTietHoaDon instance);