Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            HOADONDAL cmd  = new HOADONDAL();
            hoadon    data = new hoadon();

            data.mahd     = txtma.Text;
            data.makh     = cbmakh.Text;
            data.manv     = cbmanv.Text;
            data.ngaylap  = dtngay.Text;
            data.tongtien = txttt.Text;


            bool kt = cmd.hoadon_insert(data);

            if (kt == false)
            {
                MessageBox.Show("Loi");
            }
            else
            {
                MessageBox.Show("Them thành công");
            }
            Load_Data("select * from HOADON");
            ComboHD();
        }
Ejemplo n.º 2
0
        public ActionResult DatHang(FormCollection collection)
        {
            List <GioHang> gh = (List <GioHang>)Session[cartname];
            hoadon         dh = (hoadon)Session["dathang"];

            DB.hoadons.Add(dh);
            DB.SaveChanges();

            int mahdMax = DB.hoadons.Max(u => u.mahd);

            foreach (var item in gh)
            {
                cthd chitiet = new cthd();
                chitiet.tensp     = item.sanpham.tensp;
                chitiet.mahd      = mahdMax;
                chitiet.masp      = item.sanpham.masp;
                chitiet.soluong   = Convert.ToInt32(item.SoLuong);
                chitiet.thanhtien = Convert.ToInt32(item.SoLuong) * Convert.ToInt32(item.sanpham.gia);
                DB.cthds.Add(chitiet);
                DB.SaveChanges();
            }

            Session.Remove("giohang");
            return(RedirectToAction("ThongBao"));
        }
Ejemplo n.º 3
0
        private void timHoaDon(object sender, EventArgs e)
        {
            hoadon h = hd.layThongTinHoaDon(txtMaHoaDon.Text.ToUpper().Trim());

            if (h != null)
            {
                txtMaHD.Text          = h.mahoadon.Trim();
                txtMaPhieuThue.Text   = h.maphieuthue.Trim();
                txtNgayThanhToan.Text = h.ngaythanhtoan.Trim();
                txtNVThanhToan.Text   = h.manv.Trim();

                txtCMND.Text      = h.phieuthue.khachhang.cmnd.Trim();
                txtHoTen.Text     = h.phieuthue.khachhang.hoten;
                txtDienThoai.Text = h.phieuthue.khachhang.dienthoai.Trim();

                txtPhong.Text        = h.phieuthue.sophong.Trim();
                txtLoaiPhong.Text    = h.phieuthue.phong.loaiphong.Trim();
                txtNgayThue.Text     = h.phieuthue.ngaythue.Trim();
                txtTongNgayThue.Text = h.tongngaythue.Trim();
                txtTienPhong.Text    = h.tongtienphong.Trim() + " VNĐ";

                tblDichVu.DataSource   = dv.danhSachDaThem(h.phieuthue.maphieuthue);
                lblTongTienDichVu.Text = h.tongtiendichvu.Trim() + " VNĐ";
                lblTongCong.Text       = (double.Parse(h.tongtienphong) + double.Parse(h.tongtiendichvu)) + ".00 VNĐ";
            }
            else
            {
                MessageBox.Show("Hóa đơn này không tồn tại.", "Thông báo");
            }
        }
Ejemplo n.º 4
0
        public Boolean Insert(hoadon entity)
        {
            db.hoadons.Add(entity);
            db.SaveChanges();

            return(true);
        }
Ejemplo n.º 5
0
        private void dataGridViewHistory_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            myWebBrowser.DocumentCompleted += myWebBrowser_DocumentCompleted;
            string s = Properties.Resources.invoice;
            //string html = System.IO.File.ReadAllText(s);

            DataGridViewRow row = this.dataGridViewHistory.Rows[e.RowIndex];


            string mahd = row.Cells["mahd"].Value.ToString();

            Console.WriteLine(mahd);
            DBContextSV db = new DBContextSV(Program.connectionString);

            hoadon hd = db.hoadons.Find(mahd);

            s = s.Replace("{{customerName}}", hd.hoten);
            s = s.Replace("{{customerPhone}}", hd.sdt);
            s = s.Replace("{{tong}}", hd.tong.ToString());
            s = s.Replace("{{mahd}}", hd.mahd);
            s = s.Replace("{{ngay}}", hd.ngaylap.ToString());

            chitiethoadon[] cthd = hd.chitiethoadons.ToArray();

            string list = "";

            foreach (chitiethoadon chitiethoadon in cthd)
            {
                string template = $"<tr><td>{chitiethoadon.sanpham.tensp}</td><td>{chitiethoadon.sanpham.giaban} vnd</td><td>{chitiethoadon.soluong}</td></tr> ";
                list += template;
            }
            s = s.Replace("{{list}}", list);
            myWebBrowser.DocumentText = s;
        }
Ejemplo n.º 6
0
        public void xoahd(string id)
        {
            hoadon hd = (from c in db.hoadons select c).Single(x => x.id == id);

            db.hoadons.DeleteOnSubmit(hd);
            db.SubmitChanges();
        }
Ejemplo n.º 7
0
 public void thanhtoanien()
 {
     try
     {
         giatien = 0;
         Dsmonans       mn      = new Dsmonans();
         int            x       = int.Parse(txt_idhoadon_hoadon.Text);
         List <DataRow> list_ma = mn.tinhtien(x).AsEnumerable().ToList();
         foreach (var item in list_ma)
         {
             giatien = giatien + int.Parse(item[0].ToString());
         }
         hoadon         hd       = new hoadon();
         List <DataRow> dt       = hd.search_khuyenmai(int.Parse(cb_tenkhuyenmai_hoadon.SelectedValue.ToString())).AsEnumerable().ToList();
         int            discount = 0;
         foreach (DataRow item in dt)
         {
             discount = int.Parse(item[2].ToString());
         }
         giatien = giatien - giatien * discount / 100;
         txt_thanhtien_hoadon.Text = giatien.ToString() + "  VNĐ";
     }
     catch (Exception)
     {
     }
 }
Ejemplo n.º 8
0
        private void tbs_edit_Click(object sender, EventArgs e)
        {
            if (txt_mahoadon.Text == "")
            {
                MessageBox.Show("Dữ liệu chưa nhập!");
                return;
            }
            hoadon h = new hoadon();

            h.mahoadon      = txt_mahoadon.Text;
            h.makhachhang   = cmb_makhachhang.Text;
            h.manhanvien    = cmb_manhanvien.Text;
            h.maphieu       = cmb_maphieu.Text;
            h.giaphong      = int.Parse(txt_giaphong.Text.ToString());
            h.giadichvu     = int.Parse(txt_giadichvu.Text.ToString());
            h.tongtien      = int.Parse(txt_tongtien.Text.ToString());
            h.ngaythanhtoan = date_ngaythanhtoan.Value;
            if (MessageBox.Show(string.Format("Bạn có muốn sửa hóa đơn?"), "", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                if (Bus.UpdateProfile(h) > 0)
                {
                    MessageBox.Show("Sửa thành công!");
                    Hoadon_Load(sender, e);
                }
                else
                {
                    MessageBox.Show("Error");
                }
            }
        }
Ejemplo n.º 9
0
 private void ProceedPayment()
 {
     if (txtTotalMoney.Text != "0")
     {
         StaffDAO1 staff = new StaffDAO1();
         BillDAO1  bill  = new BillDAO1();
         hoadon    h     = new hoadon();
         h.mahd    = bill.getnewID();
         h.hoten   = txtCustomerName.Text;
         h.sdt     = txtCustomerPhoneNumber.Text;
         h.ngaylap = DateTime.Now;
         h.macn    = Program.station;
         h.tong    = TotalValue;
         h.manv    = staff.getIDbyUsername(Program.idLoged);
         if (bill.create(h) == 1)
         {
             //MessageBox.Show("Thêm thành công");
             ProceedPayment_Detail(h.mahd);
         }
         else
         {
             MessageBox.Show("Thêm thất bại");
         }
         //int totalValue = TotalValue;
         //int DiscountMoney = totalValue - Pay;
         //string CustomerName = txtCustomerName.Text;
         //string CustomerPhone = txtCustomerPhoneNumber.Text;
         //int IDCustomer = BillDAO.Instance.AddCustomerInfor(CustomerName, CustomerPhone);
         //int IDBill = BillDAO.Instance.AddBillInfor(IDCustomer, StaffID, totalValue, DiscountMoney,Pay);
     }
 }
Ejemplo n.º 10
0
        public void load_hoadon()
        {
            hoadon hd = new hoadon();

            data_hoadon.DataSource = hd.showhoadon();
            enable_control_hoadon(false);
            data_hoadon.RowHeadersVisible = false;
        }
Ejemplo n.º 11
0
 public static int DeleteProfile(hoadon hd)
 {
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@mahoadon", hd.mahoadon)
     };
     return(DataProvider.ExecuteNonQuery("xoahoadon", para));
 }
Ejemplo n.º 12
0
 public static int Xemphieu(hoadon h)
 {
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@maphieu", h.maphieu)
     };
     return(DataProvider.ExecuteNonQuery("xemphieudk", para));
 }
        public ActionResult Paid(hoadon hd)
        {
            int     nv_id = (int)((UserLogin)System.Web.HttpContext.Current.Session[QuanLyCapNuoc.common.CommonConstants.NV_SESSION]).nv_id;
            BillDao db    = new BillDao();

            db.Paid(hd.hd_id, nv_id);
            return(RedirectToAction("Show", "Bill", new { hd.hd_id }));
        }
Ejemplo n.º 14
0
        public hoadon HoaDonGanNhatCuaKH(int makh)
        {
            hoadon list = new hoadon();

            list = (from hd in context.hoadons
                    where hd.MAKH == makh
                    orderby hd.SOHD descending
                    select hd).ToList().FirstOrDefault();
            return(list);
        }
Ejemplo n.º 15
0
 public static int Tinhsongay(hoadon h, phieudangki p)
 {
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@maphieu", h.maphieu),
         new SqlParameter("@mahoadon", h.mahoadon),
         new SqlParameter("@maphieu", p.maphieu)
     };
     return(DataProvider.ExecuteNonQuery("tinhsongay", para));
 }
Ejemplo n.º 16
0
 public hoadondto(hoadon entity)
 {
     mahoadon = entity.mahoadon;
     ngayban  = entity.ngayban;
     tongcong = 0;
     foreach (chitiethoadon cthd in entity.chitiethoadons)
     {
         tongcong += cthd.soluongmua * cthd.sanpham.giaban;
     }
     tienkhachdua = entity.tienkhachdua;
 }
Ejemplo n.º 17
0
 public static int UpdateProfile(hoadon hd)
 {
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@mahoadon", hd.mahoadon),
         new SqlParameter("@giaphong", hd.giaphong),
         new SqlParameter("@giadv", hd.giadichvu),
         new SqlParameter("@tongtien", hd.tongtien)
     };
     return(DataProvider.ExecuteNonQuery("suahoadon", para));
 }
Ejemplo n.º 18
0
        public int create(hoadon h)
        {
            var result = db.hoadons.Where(x => x.mahd.Equals(h.mahd)).SingleOrDefault();

            if (result == null)
            {
                db.hoadons.Add(h);
                db.SaveChanges();
                return(1);
            }
            return(0);
        }
Ejemplo n.º 19
0
        public List <hoadon> SearchHd2(string makhachhang)
        {
            List <hoadon> list  = new List <hoadon>();
            string        query = string.Format("select * from hoadon hd inner join khachhang kh on hd.makhachhang=kh.ma where kh.ma like N'%{0}%' ", makhachhang);
            DataTable     data  = DataProvider.Instance.ExecuteQuery(query);

            foreach (DataRow i in data.Rows)
            {
                hoadon ct = new hoadon(i);
                list.Add(ct);
            }
            return(list);
        }
Ejemplo n.º 20
0
        public List <hoadon> XemHoaDon()
        {
            List <hoadon> list  = new List <hoadon>();
            string        query = "select ma,manhanvien,ngaylap,tonggiatri,thanhtien,makhachhang from hoadon";
            DataTable     data  = DataProvider.Instance.ExecuteQuery(query);

            foreach (DataRow item in data.Rows)
            {
                hoadon hd = new hoadon(item);
                list.Add(hd);
            }
            return(list);
        }
Ejemplo n.º 21
0
        public bool add(hoadon entity)
        {
            sanphamcontroller spcontroller = new sanphamcontroller();

            foreach (chitiethoadon cthd in entity.chitiethoadons)
            {
                if (!spcontroller.capnhatsoluong(cthd.id, cthd.soluongmua))
                {
                    return(false);
                }
            }
            return(hdrp.Add(entity));
        }
Ejemplo n.º 22
0
 public bool updateHoaDon(string mhd, DateTime ngay)
 {
     try
     {
         hoadon h = db.hoadons.Single(m => m.mahd == mhd);
         h.ngaymua = ngay;
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 23
0
 public bool deleteActiveHoaDon(string mhd)
 {
     try
     {
         hoadon h = db.hoadons.Single(m => m.mahd == mhd);
         h.Active = false;
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 24
0
 public bool updateTrangThaiHoaDon(string mhd)
 {
     try
     {
         hoadon h = db.hoadons.Single(m => m.mahd == mhd);
         h.hoanthanh = true;
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 25
0
        public void suahd(string id, DateTime ngaylap, string iddt, string ghichu, int so, string loaixuat, string tiente, double tygia, string vat)
        {
            hoadon hd = (from c in db.hoadons select c).Single(x => x.id == id);

            hd.ngayhd   = ngaylap;
            hd.iddt     = iddt;
            hd.ghichu   = ghichu;
            hd.so       = so;
            hd.tiente   = tiente;
            hd.tygia    = tygia;
            hd.loaixuat = loaixuat;
            hd.soVAT    = vat;
            db.SubmitChanges();
        }
Ejemplo n.º 26
0
 //HÓA ĐƠN
 #region
 public static int InsertProfile(hoadon hd)
 {
     SqlParameter[] para = new SqlParameter[]
     {
         new SqlParameter("@mahd", hd.mahoadon),
         new SqlParameter("@manv", hd.manhanvien),
         new SqlParameter("@makh", hd.makhachhang),
         new SqlParameter("@maphieu", hd.maphieu),
         new SqlParameter("@giaphong", hd.giaphong),
         new SqlParameter("@giadv", hd.giadichvu),
         new SqlParameter("@ngaythanhtoan", hd.ngaythanhtoan),
         new SqlParameter("@tongtien", hd.tongtien),
     };
     return(DataProvider.ExecuteNonQuery("themhoadon", para));
 }
Ejemplo n.º 27
0
        private void tooltrp_search_hoadon_Click(object sender, EventArgs e)
        {
            hoadon hd = new hoadon();

            if (hd.search_hoadon(tooltrp_textseach_hoadon.Text).Rows.Count > 0)
            {
                MessageBox.Show("Tìm thấy " + hd.search_hoadon(tooltrp_textseach_hoadon.Text).Rows.Count + " kết quả  !");
                data_hoadon.DataSource = hd.search_hoadon(tooltrp_textseach_hoadon.Text);
            }
            else
            {
                MessageBox.Show("không tìm thấy kết quả nào ");
                load_hoadon();
            }
        }
Ejemplo n.º 28
0
 public hoadon getby_hoadon(string _mahodon, ref string errMsg)
 {
     try
     {
         string      sqlstr = "select * from hoadon where  mahoadon like  N'" + _mahodon + "'";
         IDataReader dr     = SQLExecute.getIDataReader(sqlstr, ref errMsg);
         hoadon      obj    = new hoadon();
         obj = (hoadon)CBO.FillObject(dr, typeof(hoadon));
         return(obj);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 29
0
        public ActionResult XemDonHang()
        {
            HoadonDao   dao      = new HoadonDao();
            List <cthd> listcthd = new List <cthd>();

            hoadon hd = new hoadon();

            if (Session["dangnhap"] != null || !string.IsNullOrEmpty(Session["dangnhap"].ToString()))
            {
                hd       = dao.HoaDonGanNhatCuaKH((int)Session["dangnhap"]);
                listcthd = dao.LayCTHD((int)Session["dangnhap"]);
            }

            ViewData["hoadon"]    = hd;
            ViewData["listorder"] = listcthd;
            return(View());
        }
Ejemplo n.º 30
0
        public ActionResult Diachi(FormCollection collection, hoadon hd)
        {
            hd = new hoadon();
            string stendangnhap = (string)Session["tendangnhap"];
            double stongtien    = Convert.ToDouble(Session["tongtien"]);
            string ssdt         = collection["sodt"];
            string sdiachi      = collection["diachi"];
            string shoten       = collection["name"];

            //gan du lieu vao model
            hd.tendangnhap     = stendangnhap;
            hd.tien            = stongtien;
            hd.sdt             = ssdt;
            hd.diachi          = sdiachi;
            hd.hoten           = shoten;
            Session["dathang"] = hd;
            return(RedirectToAction("DatHang"));
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            QlSachDbDataContext db = new QlSachDbDataContext();
            if ((string)Session["dn"] == "")
            {

                if (!(db.DangNhaps.Where(p => p.TenDangNhap == tbTenDangNhap.Text)).Any())
                {
                    DangNhap dn = new DangNhap();
                    dn.TenDangNhap = tbTenDangNhap.Text;
                    dn.MatKhau = Encoding.MaHoa(Encoding.key, tbMK.Text);
                    dn.Quyen = false;
                    dn.hoten = tbHoten.Text;
                    db.DangNhaps.InsertOnSubmit(dn);
                    db.SubmitChanges();
                }
                else
                {
                    //Type cstype = this.GetType();

                    //// Get a ClientScriptManager reference from the Page class.
                    //ClientScriptManager cs = Page.ClientScript;

                    //// Check to see if the startup script is already registered.
                    //if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                    //{
                    //    String cstext = "alert('Tên đăng nhập này đã tồn tại!');";
                    //    cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
                    //}
                    Response.Write("<script>alert(\"Tên đăng nhập này đã tồn tại!\")</script>");
                    
                    return;
                }
                long makh;
                if (db.KhachHangs.Count() == 0)
                    makh = 0;
                else
                    makh = db.KhachHangs.Max(p => p.Makh);
                KhachHang kh = new KhachHang();
                kh.Makh = makh + 1;
                kh.hoten = tbHoten.Text;
                kh.SoDT = tbSdt.Text;
                kh.email = tbEmail.Text;
                kh.diachi = tbDiachi.Text;
                kh.TenDangNhap = tbTenDangNhap.Text;
                db.KhachHangs.InsertOnSubmit(kh);
                db.SubmitChanges();

                if (Session["gh"] == null)
                {
                    Response.Write("<script>alert(\"Giỏ hàng trống!\");window.location='default.aspx';</script>");
                    //Response.Redirect("default.aspx");
                    return;
                }

                long mahd = 0;
                if (db.hoadons.Count() == 0)
                    mahd = 0;
                else
                    mahd = db.hoadons.Max(p => p.MaHoaDon);
                hoadon hd = new hoadon();
                hd.MaHoaDon = mahd + 1;
                hd.makh = kh.Makh;
                hd.damua = false;
                hd.NgayMua = DateTime.Now;
                db.hoadons.InsertOnSubmit(hd);
                db.SubmitChanges();
                DataTable dt = new DataTable();
                Gio gh = new Gio();
                gh = (Gio)Session["gh"];
                dt = gh.dt;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ChiTietHoaDon cthd = new ChiTietHoaDon();
                    long macthd;
                    if (db.ChiTietHoaDons.Count() == 0)
                        macthd = 0;
                    else
                        macthd = db.ChiTietHoaDons.Max(p => p.MaChiTietHD);
                    cthd.MaChiTietHD = macthd + 1;
                    cthd.MaHoaDon = mahd + 1;
                    cthd.MaSach = dt.Rows[i]["masach"].ToString();
                    cthd.SoLuongMua = int.Parse(dt.Rows[i]["soluong"].ToString());
                    
                    //Trừ số lượng sách mua
                    sach s = db.saches.Single(p => p.masach == cthd.MaSach);
                    s.soluong -= cthd.SoLuongMua;
                    db.ChiTietHoaDons.InsertOnSubmit(cthd);
                    db.SubmitChanges();
                    //Type cstype = this.GetType();

                    //// Get a ClientScriptManager reference from the Page class.
                    //ClientScriptManager cs = Page.ClientScript;

                    //// Check to see if the startup script is already registered.
                    //if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
                    //{
                    //    String cstext = "alert('Đặt mua thành công!');";
                    //    cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
                    //}
                    

                }

                Response.Write("<script>alert(\"Đăng kí thành công!\")</script>");
                Response.Write("<script>window.location='xoagiohang.aspx';</script>");
            }
            else
            {
                string sdn = (string)Session["dn"];
                DangNhap dn = db.DangNhaps.Single(p => p.TenDangNhap == sdn);
                KhachHang kh = db.KhachHangs.Single(p => p.TenDangNhap == sdn);
                dn.MatKhau = Encoding.MaHoa(Encoding.key, tbMK.Text);
                db.SubmitChanges();
                kh.hoten = tbHoten.Text;
                kh.diachi = tbDiachi.Text;
                kh.SoDT = tbSdt.Text;
                kh.email = tbEmail.Text;
                db.SubmitChanges();
               
                Response.Write("<script>alert(\"Thay đổi thông tin thành công!\");window.location ='default.aspx';</script>");
                //Response.Redirect("~/default.aspx");
            }
        }
Ejemplo n.º 32
0
 public int insertHoaDon(HoaDonDTO hdDTO)
 {
     try
     {
         hoadon hd = new hoadon();
         hd.mahoadon = hdDTO.Mahoadon;
         hd.ngaythanhtoan = (DateTime)hdDTO.Ngaythanhtoan;
         hd.tongtien = (decimal)hdDTO.Tongtien;
         hd.maphieuthue = hdDTO.Maphieuthue;
         hd.makhachhang = hdDTO.Makhachhang;
         hd.username = hdDTO.Username;
         htDataContext.hoadons.InsertOnSubmit(hd);
         htDataContext.SubmitChanges();
         return 1;
     }
     catch
     {
         return 0;
     }
 }