示例#1
0
 public bool Delete(Entities.HDBanHang hdbh1)
 {
     try
     {
         bool kt = false;
         hdbh = new Constants.HDBanHang();
         Sql  = new Constants.Sql();
         string        sql  = Sql.DeleteHDBangHang;
         Connection    conn = new Connection();
         SqlConnection cn   = conn.openConnection();
         SqlCommand    cmd  = new SqlCommand(sql, cn);
         cmd.Parameters.Add(hdbh.HanhDong, SqlDbType.NVarChar, 20).Value = hdbh1.HanhDong;
         cmd.Parameters.Add(hdbh.HDBanHangID, SqlDbType.Int).Value       = hdbh1.HDBanHangID;
         int i = cmd.ExecuteNonQuery();
         if (i == 1)
         {
             kt = true;
         }
         else
         {
             kt = false;
         }
         cmd.Connection.Dispose();
         cn.Close();
         conn.closeConnection();
         cn   = null;
         conn = null;
         return(kt);
     }
     catch (Exception ex)
     {
         string s = ex.Message;
         return(false);
     }
 }
示例#2
0
        /// <summary>
        /// Select Bảng
        /// </summary>
        /// <returns></returns>
        public Entities.HDBanHang[] Select()
        {
            SelectKH();
            Sql  = new Constants.Sql();
            hdbh = new Constants.HDBanHang();
            string        sql  = Sql.SelectHDBanHang;
            Connection    conn = new Connection();
            SqlConnection cn   = conn.openConnection();
            SqlCommand    cmd  = new SqlCommand(sql, cn);
            SqlDataReader dr   = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Insert Category into ArrayList
            List <Entities.HDBanHang> arr = new List <Entities.HDBanHang>();

            while (dr.Read())
            {
                Entities.HDBanHang hdbanhang = new Entities.HDBanHang();
                hdbanhang.HDBanHangID          = Convert.ToInt32(dr[hdbh.HDBanHangID].ToString());
                hdbanhang.MaHDBanHang          = dr[hdbh.MaHDBanHang].ToString();
                hdbanhang.NgayBan              = DateTime.Parse(dr[hdbh.NgayBan].ToString());
                hdbanhang.MaKhachHang          = dr[hdbh.MaKhachHang].ToString();
                hdbanhang.TenKhachHang         = TimTenKH(dr[hdbh.MaKhachHang].ToString());
                hdbanhang.NoHienThoi           = dr[hdbh.NoHienThoi].ToString();
                hdbanhang.NguoiNhanHang        = dr[hdbh.NguoiNhanHang].ToString();
                hdbanhang.HinhThucThanhToan    = dr[hdbh.HinhThucThanhToan].ToString();
                hdbanhang.MaKho                = dr[hdbh.MaKho].ToString();
                hdbanhang.HanThanhToam         = DateTime.Parse(dr[hdbh.HanThanhToam].ToString());
                hdbanhang.MaDonDatHang         = dr[hdbh.MaDonDatHang].ToString();
                hdbanhang.MaNhanVien           = dr[hdbh.MaNhanVien].ToString();
                hdbanhang.MaTienTe             = dr[hdbh.MaTienTe].ToString();
                hdbanhang.ChietKhau            = dr[hdbh.ChietKhau].ToString();
                hdbanhang.ThanhToanNgay        = dr[hdbh.ThanhToanNgay].ToString();
                hdbanhang.ThanhToanKhiLapPhieu = dr[hdbh.ThanhToanKhiLapPhieu].ToString();
                hdbanhang.ThueGTGT             = dr[hdbh.ThueGTGT].ToString();
                hdbanhang.TongTienThanhToan    = dr[hdbh.TongTienThanhToan].ToString();
                hdbanhang.LoaiHoaDon           = (Boolean)dr[hdbh.LoaiHoaDon];
                hdbanhang.MaThe                = dr[hdbh.MaThe].ToString();
                hdbanhang.GiaTriThe            = dr[hdbh.GiaTriThe].ToString();
                hdbanhang.GhiChu               = dr[hdbh.GhiChu].ToString();
                hdbanhang.Deleted              = (Boolean)dr[hdbh.Deleted];
                hdbanhang.KhachTra             = dr["KhachTra"].ToString();
                hdbanhang.ChietKhauTongHoaDon  = dr["ChietKhauTongHoaDon"].ToString();
                hdbanhang.MaTheGiaTri          = dr[hdbh.MaTheGiaTri].ToString();
                hdbanhang.GiaTriTheGiaTri      = dr[hdbh.GiaTriTheGiaTri].ToString();
                arr.Add(hdbanhang);
            }
            int n = arr.Count;

            if (n == 0)
            {
                return(null);
            }
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn   = null;
            conn = null;
            return(arr.ToArray());
        }
示例#3
0
        /// <summary>
        /// Select Bảng
        /// </summary>
        /// <returns></returns>
        public Entities.HDBanHang[] Select(string Cot, string Kieu, string Giatri, string makh)
        {
            hdbh = new Constants.HDBanHang();
            Sql  = new Constants.Sql();
            string sql = "";

            if (Kieu == "like")
            {
                sql = "select * from HDBanHang where " + Cot + " " + Kieu + " '%" + Giatri + "%' and MaKhachHang ='" + makh + "' and Deleted =0";
            }
            else
            {
                sql = "select * from HDBanHang where " + Cot + " " + Kieu + " '" + Giatri + "' and MaKhachHang ='" + makh + "'  and Deleted =0";
            }
            Connection    conn = new Connection();
            SqlConnection cn   = conn.openConnection();
            SqlCommand    cmd  = new SqlCommand(sql, cn);
            SqlDataReader dr   = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Insert Category into ArrayList
            List <Entities.HDBanHang> arr = new List <Entities.HDBanHang>();

            while (dr.Read())
            {
                Entities.HDBanHang hdbanhang = new Entities.HDBanHang();
                hdbanhang.HDBanHangID       = Convert.ToInt32(dr[hdbh.HDBanHangID].ToString());
                hdbanhang.MaHDBanHang       = dr[hdbh.MaHDBanHang].ToString();
                hdbanhang.NgayBan           = DateTime.Parse(dr[hdbh.NgayBan].ToString());
                hdbanhang.MaKhachHang       = dr[hdbh.MaKhachHang].ToString();
                hdbanhang.NoHienThoi        = dr[hdbh.NoHienThoi].ToString();
                hdbanhang.NguoiNhanHang     = dr[hdbh.NguoiNhanHang].ToString();
                hdbanhang.HinhThucThanhToan = dr[hdbh.HinhThucThanhToan].ToString();
                hdbanhang.MaKho             = dr[hdbh.MaKho].ToString();
                hdbanhang.HanThanhToam      = DateTime.Parse(dr[hdbh.HanThanhToam].ToString());
                hdbanhang.MaDonDatHang      = dr[hdbh.MaDonDatHang].ToString();
                hdbanhang.MaNhanVien        = dr[hdbh.MaNhanVien].ToString();
                hdbanhang.MaTienTe          = dr[hdbh.MaTienTe].ToString();
                hdbanhang.ChietKhau         = dr[hdbh.ChietKhau].ToString();
                hdbanhang.ThanhToanNgay     = dr[hdbh.ThanhToanNgay].ToString();
                hdbanhang.ThueGTGT          = dr[hdbh.ThueGTGT].ToString();
                hdbanhang.TongTienThanhToan = dr[hdbh.TongTienThanhToan].ToString();
                hdbanhang.LoaiHoaDon        = (Boolean)dr[hdbh.LoaiHoaDon];
                hdbanhang.GhiChu            = dr[hdbh.GhiChu].ToString();
                hdbanhang.Deleted           = (Boolean)dr[hdbh.Deleted];
                arr.Add(hdbanhang);
            }
            int n = arr.Count;

            if (n == 0)
            {
                return(null);
            }
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn   = null;
            conn = null;
            return(arr.ToArray());
        }
        public void HienThiHoaDonBanHang()
        {
            Server_Client.Client cl = new Server_Client.Client();
            this.client1 = cl.Connect(Luu.IP, Luu.Ports);

            Entities.HDBanHang nv = new Entities.HDBanHang("Select");
            clientstream = cl.SerializeObj(this.client1, "HDBanHang", nv);
            Entities.HDBanHang[] nv1 = new Entities.HDBanHang[1];
            nv1 = (HDBanHang[])cl.DeserializeHepper(clientstream, nv1);

            int count = 0;

            if (nv1 != null)
            {
                for (int i = 0; i < nv1.Length; i++)
                {
                    if (nv1[i].MaNhanVien == txtmanv.Text)
                    {
                        count++;
                    }
                }
            }
            Entities.HDBanHang [] hdbh = new Entities.HDBanHang [count];

            count = 0;
            if (nv1 != null)
            {
                for (int i = 0; i < nv1.Length; i++)
                {
                    if (nv1[i].MaNhanVien == txtmanv.Text)
                    {
                        hdbh[count] = nv1[i];
                        count++;
                    }
                }
            }
            dataGridView1.DataSource = hdbh;
        }
示例#5
0
        /// <summary>
        /// nút thêm
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsslthem_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            try
            {
                if (KiemTra() == true)
                {
                    //CheckConflictInsert();
                    txtSochungtu.Text = ProID("HDBanHang");
                    kt = true;
                    if (kt == true)
                    {
                        cl = new Server_Client.Client();
                        this.Client1 = cl.Connect(Luu.IP, Luu.Ports);
                        string date = "";
                        try
                        {
                            date = new Common.Utilities().MyDateConversion(mskngaychungtu.Text);
                        }
                        catch
                        {
                            MessageBox.Show("Bạn nhập sai định dạng ngày tháng", "Hệ thống cảnh báo");
                            mskngaychungtu.Focus();
                            return;
                        }
                        string khachtra = "0";
                        if (txtkhachtra.Text == "")
                            khachtra = "0";
                        else
                            khachtra = txtkhachtra.Text;
                        if (Convert.ToDouble(khachtra) < (Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text) - double.Parse(txtGTTheGT.Text)))
                        {
                            lbloi.Text = "Khách trả không thể nhỏ hơn Tổng tiền";
                            return;
                        }
                        Entities.HDBanHang pt = new Entities.HDBanHang();
                        string makho = LayMaKho(cbbkhohang.Text);
                        double ttn = 0;
                        Entities.TheVip tv1 = null;
                        Entities.TheGiamGia tgg1 = null;
                        // The Vip
                        if (Convert.ToDouble(txtTongtien.Text) < Convert.ToDouble(txtGTTheVip.Text))
                        {
                            ttn = Convert.ToDouble(txtGTTheVip.Text) - Convert.ToDouble(txtTongtien.Text);
                            tv1 = new Entities.TheVip("", txtMaTheVip.Text, "", ttn.ToString(), "", "", false);
                        }
                        else
                        {
                            ttn = Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text);
                            tv1 = new Entities.TheVip("", txtMaTheVip.Text, "", "0", "", "", false);
                            // The Gia Tri.
                            if (Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text) < Convert.ToDouble(txtGTTheGT.Text))
                            {
                                ttn = Convert.ToDouble(txtGTTheGT.Text) - (Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text));
                                tgg1 = new Entities.TheGiamGia();
                                tgg1.MaTheGiamGia = txtMaTheGT.Text;
                                tgg1.GiaTriConLai = ttn.ToString();
                            }
                            else
                            {
                                ttn = Convert.ToDouble(txtTongtien.Text) - Convert.ToDouble(txtGTTheVip.Text) - Convert.ToDouble(txtGTTheVip.Text);
                                tgg1 = new TheGiamGia { MaTheGiamGia = txtMaTheGT.Text, GiaTriConLai = "0" };
                            }
                        }

                        chietkhau = (double.Parse(txtGiamgia.Text) + double.Parse(txtChietkhau.Text)).ToString();
                        string ckTongHoaDon = txtPhantramchietkhau.Text;
                        if (string.IsNullOrEmpty(txtPhantramchietkhau.Text))
                            ckTongHoaDon = "0";
                        pt = new HDBanHang("Insert", 0, txtSochungtu.Text, Convert.ToDateTime(date),
                            txtMakhachhang.Text, "0", " ", cbxHinhthucthanhtoan.Text, makho, _datesv, " ",
                            (_currentNhanVien != null) ? _currentNhanVien.MaNhanVien : Common.Utilities.User.NhanVienID, "TT_0001", txtGiamgia.Text, ttn.ToString(), "0",
                            txtGTGT.Text, txtTongtien.Text, true, txtMaTheVip.Text, txtGTTheVip.Text, txtDiengiai.Text, false,
                            Common.Utilities.User.TenDangNhap, txtkhachtra.Text, ckTongHoaDon, txtMaTheGT.Text, txtGTTheGT.Text)
                                 {
                                     ChiTietHDBanHang = CheckDataGridInsert(dtgvsanpham),
                                     ChiTietKhoHangTheoHoaHonNhap = CheckDataGridTruSL(dtgvsanpham),
                                     TheVip = tv1,
                                     TheGiamGia = tgg1
                                 };

                        Clientstrem = cl.SerializeObj(this.Client1, "HDBanHang", pt);

                        bool kt1 = false;
                        kt1 = (bool)cl.DeserializeHepper(Clientstrem, kt1);
                        if (kt1 == true)
                        {
                            //Cập nhật điểm thưởng cho khách hàng
                            if (!string.IsNullOrEmpty(txtMakhachhang.Text))
                            {
                                //Cập nhật điểm thưởng khách hàng thành công
                                bool kq = CapNhatDiemThuongKhachHang(txtMakhachhang.Text, txtTongtien.Text);
                            }
                            else
                            {
                                //Cập nhật điểm thưởng khách hàng thất bại
                            }
                            /////////////////////////////////////
                            khachtra = "0";
                            if (txtkhachtra.Text == "")
                                khachtra = "0";
                            else
                                khachtra = txtkhachtra.Text;

                            if (cbkiemtra.Checked == true)
                            {
                                frmBaoCaorpt bcrpt = new frmBaoCaorpt("HDBanLe", txtSochungtu.Text, double.Parse(txtGiamgia.Text), khachtra, txtdutra.Text, txtKhachPhaiTra.Text, txtGTGT.Text, lbnhanvien.Text, "in", mskngaychungtu.Text, txtGTTheVip.Text, txtGTTheGT.Text, "", txtChietkhau.Text, "", "", "");
                            }

                            GiaVonBanHang(pt.ChiTietHDBanHang);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Thêm thất bại - xin thử lại", "Hệ thống cảnh báo");
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                this.Enabled = true;

            }
        }
示例#6
0
        /// <summary>
        /// nút sửa
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsslsua_Click(object sender, EventArgs e)
        {
            try
            {
                if (KiemTra() == true)
                {
                    CheckConflictUpdate();
                    if (kt == true)
                    {
                        cl = new Server_Client.Client();
                        this.Client1 = cl.Connect(Luu.IP, Luu.Ports);
                        string date = new Common.Utilities().MyDateConversion(mskngaychungtu.Text);
                        Entities.HDBanHang pt = new Entities.HDBanHang();
                        string makho = LayMaKho(cbbkhohang.Text);
                        pt = new Entities.HDBanHang("Insert", 0, txtSochungtu.Text, Convert.ToDateTime(date),
                                                    txtMakhachhang.Text, "0", " ", cbxHinhthucthanhtoan.Text, makho, _datesv, " ",
                                                    Common.Utilities.User.NhanVienID, "TT_0001", txtChietkhau.Text, txtTongtien.Text, "0",
                                                    txtGTGT.Text, txtTongtien.Text, true, txtMaTheVip.Text, txtGTTheVip.Text, txtDiengiai.Text, false,
                                                    Common.Utilities.User.TenDangNhap, txtkhachtra.Text, txtPhantramchietkhau.Text, txtMaTheGT.Text, txtGTTheGT.Text);

                        Clientstrem = cl.SerializeObj(this.Client1, "HDBanHang", pt);
                        bool kt1 = false;
                        kt1 = (bool)cl.DeserializeHepper(Clientstrem, kt1);
                        if (kt1 == true)
                        {
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("thất bại - xin kiểm tra lại dữ liệu", "Hệ thống cảnh báo");
                        }
                    }
                    else
                        MessageBox.Show("Dữ liệu đã bị thay đổi - kiểm tra lại", "Hệ thống cảnh báo");
                }
            }
            catch
            {
            }
            finally
            {

            }
        }
示例#7
0
        public Entities.HDBanHang[] Select_TheoMaKho(string makho)
        {
            hdbh = new Constants.HDBanHang();
            Sql = new Constants.Sql();
            string sql = "";

            sql = "select * from HDBanHang where MaKho ='" + makho + "' and Deleted =0";

            Connection conn = new Connection();
            SqlConnection cn = conn.openConnection();
            SqlCommand cmd = new SqlCommand(sql, cn);
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Insert Category into ArrayList
            List<Entities.HDBanHang> arr = new List<Entities.HDBanHang>();
            while (dr.Read())
            {
                Entities.HDBanHang hdbanhang = new Entities.HDBanHang();
                hdbanhang.HDBanHangID = Convert.ToInt32(dr[hdbh.HDBanHangID].ToString());
                hdbanhang.MaHDBanHang = dr[hdbh.MaHDBanHang].ToString();
                hdbanhang.NgayBan = DateTime.Parse(dr[hdbh.NgayBan].ToString());
                hdbanhang.MaKhachHang = dr[hdbh.MaKhachHang].ToString();
                hdbanhang.NoHienThoi = dr[hdbh.NoHienThoi].ToString();
                hdbanhang.NguoiNhanHang = dr[hdbh.NguoiNhanHang].ToString();
                hdbanhang.HinhThucThanhToan = dr[hdbh.HinhThucThanhToan].ToString();
                hdbanhang.MaKho = dr[hdbh.MaKho].ToString();
                hdbanhang.HanThanhToam = DateTime.Parse(dr[hdbh.HanThanhToam].ToString());
                hdbanhang.MaDonDatHang = dr[hdbh.MaDonDatHang].ToString();
                hdbanhang.MaNhanVien = dr[hdbh.MaNhanVien].ToString();
                hdbanhang.MaTienTe = dr[hdbh.MaTienTe].ToString();
                hdbanhang.ChietKhau = dr[hdbh.ChietKhau].ToString();
                hdbanhang.ThanhToanNgay = dr[hdbh.ThanhToanNgay].ToString();
                hdbanhang.ThueGTGT = dr[hdbh.ThueGTGT].ToString();
                hdbanhang.TongTienThanhToan = dr[hdbh.TongTienThanhToan].ToString();
                hdbanhang.LoaiHoaDon = (Boolean)dr[hdbh.LoaiHoaDon];
                hdbanhang.MaThe = dr[hdbh.MaThe].ToString();
                hdbanhang.GiaTriThe = dr[hdbh.GiaTriThe].ToString();
                hdbanhang.GhiChu = dr[hdbh.GhiChu].ToString();
                hdbanhang.Deleted = (Boolean)dr[hdbh.Deleted];
                arr.Add(hdbanhang);
            }
            int n = arr.Count;
            if (n == 0) return null;
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn = null;
            conn = null;
            return arr.ToArray();
        }
示例#8
0
 public bool Delete()
 {
     try
     {
         cl = new Server_Client.Client();
         this.client1 = cl.Connect(Luu.IP, Luu.Ports);
         Entities.HDBanHang a = new Entities.HDBanHang("DeleteTheoMa", txtSochungtu.Text, "");
         clientstrem = cl.SerializeObj(this.client1, "HDBanHang", a);
         bool kt = false;
         kt = (bool)cl.DeserializeHepper(clientstrem, kt);
         return kt;
     }
     catch
     {
         return false;
     }
 }
示例#9
0
        /// <summary>
        /// kiểm tra trước khi insert
        /// </summary>
        public void CheckConflictInsert()
        {
            try
            {
                kt = true;
                cl = new Server_Client.Client();
                // gán TCPclient
                this.client1 = cl.Connect(Luu.IP, Luu.Ports);
                // khởi tạo biến truyền vào với hàm khởi tạo
                Entities.HDBanHang pt = new Entities.HDBanHang("Select");
                // khởi tạo mảng đối tượng để hứng giá trị
                Entities.HDBanHang[] pt1 = new Entities.HDBanHang[1];
                clientstrem = cl.SerializeObj(this.client1, "HDBanHang", pt);
                // đổ mảng đối tượng vào datagripview
                pt1 = (Entities.HDBanHang[])cl.DeserializeHepper1(clientstrem, pt1);
                if (pt1 != null)
                {
                    for (int j = 0; j < pt1.Length; j++)
                    {
                        if (pt1[j].MaHDBanHang == sochungtu)
                        {
                            //MessageBox.Show("cập nhật mã phiếu - kiểm tra lại để insert");
                            kt = true;
                            sochungtu = txtSochungtu.Text = ProID("HDBanHang");
                            break;
                        }
                        else
                            kt = true;
                    }
                }
            }
            catch (Exception ex)
            {
                kt = false;
            }
            finally
            {

            }
        }
示例#10
0
        private void tsslthem_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            try
            {
                if (KiemTra() == true)
                {
                    //CheckConflictInsert();
                    txtSochungtu.Text = ProID("HDBanHang");
                    kt = true;
                    if (kt == true)
                    {
                        cl = new Server_Client.Client();
                        this.client1 = cl.Connect(Luu.IP, Luu.Ports);
                        string date = "", date2 = "";
                        date = new Common.Utilities().MyDateConversion(makNgaychungtu.Text);
                        try
                        {
                            date2 = new Common.Utilities().MyDateConversion(makHanthanhtoan.Text);
                        }
                        catch
                        {
                            MessageBox.Show("Nhập sai định dạng ngày tháng", "Hệ thông cảnh báo");
                            date2 = "";
                            return;
                        }
                        Entities.HDBanHang pt = new Entities.HDBanHang();
                        string makho = LayMaKho(cbbKhoban.Text);
                        string matt = LayMaTT(cbbtientetygia.Text);

                        if (string.IsNullOrEmpty(txtPhantramchietkhau.Text))
                            txtPhantramchietkhau.Text = "0";
                        if (string.IsNullOrEmpty(txtkhachtra.Text))
                            txtkhachtra.Text = "0";

                        pt = new Entities.HDBanHang("Insert", 0, txtSochungtu.Text, Convert.ToDateTime(date), txtMakhachhang.Text,
                            txtNohienthoi.Text, txtnguoinhanhang.Text, cbbHinhthucthanhtoan.Text, makho, DateTime.Parse(date2),
                            txtDondatbanhang.Text, (_currentNhanVien != null) ? _currentNhanVien.MaNhanVien : Common.Utilities.User.NhanVienID, matt, txtTongchietkhau.Text, "0",
                            txtThanhtoanngay.Text, txtGTGT.Text, txtTongtien.Text, false, " ", "0", txtDiengiai.Text,
                            false, Common.Utilities.User.TenDangNhap, txtkhachtra.Text, txtPhantramchietkhau.Text, string.Empty, "0");
                        pt.ChiTietHDBanHang = CheckDataGridInsert(dtgvsanpham);
                        if (txtDondatbanhang.Text.Length != 0)
                        {
                            pt.DonDatHang = CapNhatTrangThaiDonDatHang("Update", txtDondatbanhang.Text, "Đã thành công");
                        }
                        pt.ChiTietKhoHangTheoHoaHonNhap = CheckDataGridTruSL(dtgvsanpham);
                        double khNo = 0;
                        double tongTienHD = 0;
                        double tongThanhToan = 0;

                        if (!string.IsNullOrEmpty(txtTongtien.Text))
                            tongTienHD = double.Parse(txtTongtien.Text);

                        if (!string.IsNullOrEmpty(txtkhachtra.Text))
                            tongThanhToan = double.Parse(txtkhachtra.Text);

                        if (tongThanhToan > tongTienHD)
                            khNo = 0;
                        else
                            khNo = tongTienHD - tongThanhToan;

                        pt.KhachHang = new Entities.KhachHang("UpdateDuNo", txtMakhachhang.Text, khNo.ToString());
                        clientstrem = cl.SerializeObj(this.client1, "HDBanHang", pt);
                        bool kt1 = false;
                        kt1 = (bool)cl.DeserializeHepper(clientstrem, kt1);
                        if (kt1 == true)
                        {
                            ////Cập nhật điểm thưởng cho khách hàng
                            //if (CapNhatDiemThuongKhachHang(txtMakhachhang.Text, txtTongtien.Text))
                            //{
                            //    //Cập nhật điểm thưởng khách hàng thành công
                            //}
                            //else
                            //{
                            //    //Cập nhật điểm thưởng khách hàng thất bại
                            //}
                            ///////////////////////////////////////

                            string khachtra = "0";
                            if (txtkhachtra.Text == "")
                                khachtra = "0";
                            else
                                khachtra = txtkhachtra.Text;
                            //timerRun.Start();
                            if (cbkiemtra.Checked == true)
                            {
                                Entities.KhachHang kh = GetThongTinKhachHang(txtMakhachhang.Text);
                                frmBaoCaorpt bcrpt = new frmBaoCaorpt("HDBanBuon", txtSochungtu.Text,
                                    Double.Parse(txtTongchietkhau.Text), khachtra, txtdutra.Text, txtTongtien.Text,
                                    txtGTGT.Text, Common.Utilities.User.TenNhanVien, "in", makNgaychungtu.Text, txtgiatrithe.Text, "0", "", txtChietkhau.Text, kh.DiaChi, txtnguoinhanhang.Text, txtDiengiai.Text);
                            }
                            //timerRun.Stop();
                            GiaVonBanHang(pt.ChiTietHDBanHang);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Thêm thất bại - xin hãy thử lại", "Hệ thống cảnh báo");
                        }

                    }
                }
            }
            catch
            {

            }
            finally
            {
                this.Enabled = true;
            }
        }
示例#11
0
        /// <summary>
        /// xử lý khi click vào lập phiếu thanh toán
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tssllapphieuthanhtoan_Click(object sender, EventArgs e)
        {
            try
            {
                string date = new Common.Utilities().MyDateConversion(makNgaychungtu.Text);
                string date2 = new Common.Utilities().MyDateConversion(makHanthanhtoan.Text);
                string makho = LayMaKho(cbbKhoban.Text);
                string matt = LayMaTT(cbbtientetygia.Text);
                Entities.HDBanHang[] pt1 = new Entities.HDBanHang[1];
                pt1[0] = new Entities.HDBanHang("Update", int.Parse(id), txtSochungtu.Text, Convert.ToDateTime(date),
                    txtMakhachhang.Text, txtNohienthoi.Text, txtnguoinhanhang.Text, cbbHinhthucthanhtoan.Text, makho,
                    DateTime.Parse(date2), txtDondatbanhang.Text, Common.Utilities.User.TenNhanVien, matt,
                    txtChietkhau.Text, thanhtoankhilapphieu, thanhtoanngay, txtGTGT.Text, txtTongtien.Text, false, " ", "0",
                    txtDiengiai.Text, false, Common.Utilities.User.TenDangNhap, txtkhachtra.Text, txtPhantramchietkhau.Text, string.Empty, "0");

                frmXuLyPhieuTTCuaKH pt = new frmXuLyPhieuTTCuaKH(pt1);
                pt.ShowDialog();
                this.Close();
            }
            catch
            {
            }
        }
示例#12
0
 /// <summary>
 /// kiểm tra gí trị nhập vào
 /// </summary>
 /// <param name="pxh"></param>
 /// <returns></returns>
 public bool Check(HDBanHang pxh)
 {
     bool gt = true;
     string datetimenew = new Common.Utilities().XuLy(2, (Convert.ToDateTime(pxh.NgayBan).ToShortDateString()));
     string datetimenew2 = new Common.Utilities().XuLy(2, (Convert.ToDateTime(pxh.HanThanhToam).ToShortDateString()));
     if (datetime != datetimenew)
     {
         datetime = makNgaychungtu.Text = datetimenew;
         gt = false;
     }
     if (makh != pxh.MaKhachHang)
     {
         makh = txtMakhachhang.Text = pxh.MaKhachHang;
         gt = false;
     }
     if (nohienthoi != pxh.NoHienThoi)
     {
         nohienthoi = txtNohienthoi.Text = pxh.NoHienThoi;
         gt = false;
     }
     if (nguoinhan != pxh.NguoiNhanHang)
     {
         nguoinhan = txtnguoinhanhang.Text = pxh.NguoiNhanHang;
         gt = false;
     }
     if (hinhthucthanhtoan != pxh.HinhThucThanhToan)
     {
         hinhthucthanhtoan = cbbHinhthucthanhtoan.Text = pxh.HinhThucThanhToan;
         gt = false;
     }
     if (khoban != pxh.MaKho)
     {
         khoban = pxh.MaKho;
         cbbKhoban.Text = LayTenKho(khoban);
         gt = false;
     }
     if (hanthanhtoan != datetimenew2)
     {
         hanthanhtoan = makHanthanhtoan.Text = datetimenew2;
         gt = false;
     }
     if (dondatbanhang != pxh.MaHDBanHang)
     {
         dondatbanhang = txtDondatbanhang.Text = pxh.MaHDBanHang;
         gt = false;
     }
     if (nhanvien != pxh.MaNhanVien)
     {
         nhanvien = lbnhanvien.Text = pxh.MaNhanVien;
         gt = false;
     }
     if (tientetygia != pxh.MaTienTe)
     {
         tientetygia = pxh.MaTienTe;
         cbbtientetygia.Text = LayTenTT(tientetygia);
         txttientetygia.Text = LayDonViTT(tientetygia);
         gt = false;
     }
     if (chietkhau != pxh.ChietKhau)
     {
         chietkhau = txtChietkhau.Text = pxh.ChietKhau;
         gt = false;
     }
     if (thanhtoankhilapphieu != pxh.ThanhToanNgay)
     {
         thanhtoankhilapphieu = txtThanhtoanngay.Text = pxh.ThanhToanNgay;
         gt = false;
     }
     if (gtgt != pxh.ThueGTGT)
     {
         gtgt = txtGTGT.Text = pxh.ThueGTGT;
         gt = false;
     }
     if (tongtien != pxh.TongTienThanhToan)
     {
         tongtien = txtTongtien.Text = pxh.TongTienThanhToan;
         gt = false;
     }
     if (ghichu != pxh.GhiChu)
     {
         ghichu = txtDiengiai.Text = pxh.GhiChu;
         gt = false;
     }
     return gt;
 }
        public void LayHDBanHang()
        {
            try
            {
                cl = new Server_Client.Client();
                this.client1 = cl.Connect(Luu.IP, Luu.Ports);
                Entities.HDBanHang ctxh = new Entities.HDBanHang("Select");
                clientstrem = cl.SerializeObj(this.client1, "HDBanHang", ctxh);
                Entities.HDBanHang[] HDBanHang1 = new Entities.HDBanHang[0];
                HDBanHang1 = (Entities.HDBanHang[])cl.DeserializeHepper1(clientstrem, HDBanHang1);
                if (HDBanHang1 == null)
                {
                    HDBanHang = new Entities.HDBanHang[0];
                    return;
                }

                int count = 0;
                for (int i = 0; i < HDBanHang1.Length; i++)
                {
                    DateTime ngayban = HDBanHang1[i].NgayBan;
                    if (ngayban >= BatDau && ngayban <= KetThuc)
                    {
                        count++;
                    }
                }
                HDBanHang = new Entities.HDBanHang[count];
                count = 0;
                for (int i = 0; i < HDBanHang1.Length; i++)
                {
                    DateTime ngayban = HDBanHang1[i].NgayBan;
                    if (ngayban >= BatDau && ngayban <= KetThuc)
                    {
                        HDBanHang[count] = HDBanHang1[i];
                        count++;
                    }
                }

            }
            catch
            {
            }
        }
示例#14
0
        public bool InsertUpdate(Entities.HDBanHang hdbh1)
        {
            try
            {
                hdbh = new Constants.HDBanHang();
                Sql  = new Constants.Sql();
                string        sql  = Sql.InsertUpdateHDBanHang;
                Connection    conn = new Connection();
                SqlConnection cn   = conn.openConnection();
                SqlCommand    cmd  = new SqlCommand(sql, cn);
                cmd.Parameters.Add(hdbh.HanhDong, SqlDbType.NVarChar, 20).Value           = hdbh1.HanhDong;
                cmd.Parameters.Add(hdbh.HDBanHangID, SqlDbType.Int).Value                 = hdbh1.HDBanHangID;
                cmd.Parameters.Add(hdbh.MaHDBanHang, SqlDbType.VarChar, 20).Value         = hdbh1.MaHDBanHang;
                cmd.Parameters.Add(hdbh.NgayBan, SqlDbType.DateTime).Value                = hdbh1.NgayBan;
                cmd.Parameters.Add(hdbh.MaKhachHang, SqlDbType.NVarChar, 20).Value        = hdbh1.MaKhachHang;
                cmd.Parameters.Add(hdbh.NoHienThoi, SqlDbType.Float).Value                = hdbh1.NoHienThoi;
                cmd.Parameters.Add(hdbh.NguoiNhanHang, SqlDbType.NVarChar, 200).Value     = hdbh1.NguoiNhanHang;
                cmd.Parameters.Add(hdbh.HinhThucThanhToan, SqlDbType.NVarChar, 200).Value = hdbh1.HinhThucThanhToan;
                cmd.Parameters.Add(hdbh.MaKho, SqlDbType.VarChar, 20).Value               = hdbh1.MaKho;
                cmd.Parameters.Add(hdbh.HanThanhToam, SqlDbType.DateTime).Value           = hdbh1.HanThanhToam;
                cmd.Parameters.Add(hdbh.MaDonDatHang, SqlDbType.VarChar, 20).Value        = hdbh1.MaDonDatHang;
                cmd.Parameters.Add(hdbh.MaNhanVien, SqlDbType.VarChar, 20).Value          = hdbh1.MaNhanVien;
                cmd.Parameters.Add(hdbh.MaTienTe, SqlDbType.VarChar, 20).Value            = hdbh1.MaTienTe;
                cmd.Parameters.Add(hdbh.ChietKhau, SqlDbType.Float).Value                 = hdbh1.ChietKhau;
                cmd.Parameters.Add(hdbh.ThanhToanNgay, SqlDbType.Float).Value             = hdbh1.ThanhToanNgay;
                cmd.Parameters.Add(hdbh.ThanhToanKhiLapPhieu, SqlDbType.Float).Value      = hdbh1.ThanhToanKhiLapPhieu;
                cmd.Parameters.Add(hdbh.ThueGTGT, SqlDbType.Float).Value            = hdbh1.ThueGTGT;
                cmd.Parameters.Add(hdbh.TongTienThanhToan, SqlDbType.Float).Value   = hdbh1.TongTienThanhToan;
                cmd.Parameters.Add(hdbh.LoaiHoaDon, SqlDbType.Bit).Value            = hdbh1.LoaiHoaDon;
                cmd.Parameters.Add(hdbh.MaThe, SqlDbType.VarChar).Value             = hdbh1.MaThe;
                cmd.Parameters.Add(hdbh.GiaTriThe, SqlDbType.Float).Value           = hdbh1.GiaTriThe;
                cmd.Parameters.Add(hdbh.GhiChu, SqlDbType.NVarChar, 100).Value      = hdbh1.GhiChu;
                cmd.Parameters.Add(hdbh.Deleted, SqlDbType.Bit).Value               = hdbh1.Deleted;
                cmd.Parameters.Add(hdbh.KhachTra, SqlDbType.Float).Value            = hdbh1.KhachTra;
                cmd.Parameters.Add(hdbh.ChietKhauTongHoaDon, SqlDbType.Float).Value = hdbh1.ChietKhauTongHoaDon;
                cmd.Parameters.Add(hdbh.MaTheGiaTri, SqlDbType.VarChar, 20).Value   = hdbh1.MaTheGiaTri;
                cmd.Parameters.Add(hdbh.GiaTriTheGiaTri, SqlDbType.Float).Value     = hdbh1.GiaTriTheGiaTri;
                int  i  = cmd.ExecuteNonQuery();
                bool kt = false;
                if (i == 1)
                {
                    kt = true;
                }
                else
                {
                    kt = false;
                }

                // trừ số lượng
                new BizLogic.ChiTietKhoHangTheoHoaHonNhap().TruSoLuong(hdbh1.ChiTietKhoHangTheoHoaHonNhap);
                // insert chi tiết hóa đơn
                new BizLogic.ChiTietHDBanHang().InsertUpdate(hdbh1.ChiTietHDBanHang);
                if (!hdbh1.LoaiHoaDon)
                {
                    // cập nhật trạng thái
                    if (hdbh1.DonDatHang != null)
                    {
                        new BizLogic.DonDatHang().CapNhatTrangThaiDonDatHang(hdbh1.DonDatHang);
                    }
                    // update dư nợ
                    if (hdbh1.KhachHang != null)
                    {
                        new BizLogic.KhachHang().Update(hdbh1.KhachHang);
                    }
                }
                else
                {
                    // update thẻ vip
                    if (hdbh1.TheVip != null)
                    {
                        new BizLogic.TheVip().Update(hdbh1.TheVip);
                    }
                    if (hdbh1.TheGiamGia != null)
                    {
                        new BizLogic.TheGiamGia().Update(hdbh1.TheGiamGia);
                    }
                }

                cmd.Connection.Dispose();
                cn.Close();
                conn.closeConnection();
                cn   = null;
                conn = null;
                return(kt);
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(false);
            }
        }
示例#15
0
        /// <summary>
        /// kiểm tra trước khi update
        /// </summary>
        public void CheckConflictUpdate()
        {
            try
            {
                kt = false;
                cl = new Server_Client.Client();
                // gán TCPclient
                this.Client1 = cl.Connect(Luu.IP, Luu.Ports);
                // khởi tạo biến truyền vào với hàm khởi tạo
                Entities.HDBanHang pt = new Entities.HDBanHang("Select");
                // khởi tạo mảng đối tượng để hứng giá trị
                Entities.HDBanHang[] pt1 = new Entities.HDBanHang[1];
                Clientstrem = cl.SerializeObj(this.Client1, "HDBanHang", pt);
                // đổ mảng đối tượng vào datagripview
                pt1 = (Entities.HDBanHang[])cl.DeserializeHepper1(Clientstrem, pt1);
                if (pt1 != null)
                {
                    for (int j = 0; j < pt1.Length; j++)
                    {
                        if (pt1[j].MaHDBanHang == sochungtu)
                        {
                            kt = Check(pt1[j]);
                            break;
                        }
                        else
                            kt = true;
                    }
                }
            }
            catch (Exception ex)
            {
                kt = false;
            }
            finally
            {

            }
        }
示例#16
0
        private void tsslsua_Click(object sender, EventArgs e)
        {
            try
            {
                if (KiemTra() == true)
                {
                    CheckConflictUpdate();
                    if (kt == true)
                    {
                        cl = new Server_Client.Client();
                        this.client1 = cl.Connect(Luu.IP, Luu.Ports);
                        string date = new Common.Utilities().MyDateConversion(makNgaychungtu.Text);
                        string date2 = new Common.Utilities().MyDateConversion(makHanthanhtoan.Text);
                        Entities.HDBanHang pt = new Entities.HDBanHang();
                        string makho = LayMaKho(cbbKhoban.Text);
                        string matt = LayMaTT(cbbtientetygia.Text);
                        pt = new Entities.HDBanHang("Insert", 0, txtSochungtu.Text, Convert.ToDateTime(date), txtMakhachhang.Text,
                                                    txtNohienthoi.Text, txtnguoinhanhang.Text, cbbHinhthucthanhtoan.Text, makho, DateTime.Parse(date2),
                                                    txtDondatbanhang.Text, Common.Utilities.User.NhanVienID, matt, txtTongchietkhau.Text, "0",
                                                    txtThanhtoanngay.Text, txtGTGT.Text, txtTongtien.Text, false, " ", "0", txtDiengiai.Text,
                                                    false, Common.Utilities.User.TenDangNhap, txtkhachtra.Text, txtPhantramchietkhau.Text, string.Empty, "0");

                        clientstrem = cl.SerializeObj(this.client1, "HDBanHang", pt);
                        bool kt1 = false;
                        kt1 = (bool)cl.DeserializeHepper(clientstrem, kt1);
                        if (kt1 == true)
                        {
                            this.Close();
                        }
                        else
                            MessageBox.Show("thất bại - xin kiểm tra lại dữ liệu", "Hệ thống cảnh báo");

                    }
                    else
                        MessageBox.Show("Dữ liệu đã bị thay đổi - Hãy kiểm tra lại", "Hệ thống cảnh báo");
                }
            }
            catch
            {
            }
            finally
            {

            }
        }
 private void LayDuLieuHoaDonBanHang()
 {
     //lấy dữ liệu hóa đơn bán hàng
     HDBanHang inputHdbbh = new HDBanHang { HanhDong = "Select" };
     HDBanHang[] outputHdbh;
     bool kqHdbh = Utils.GetDataFromServer("HDBanHang", inputHdbbh, out outputHdbh);
     if (kqHdbh) _hdBanHangs.AddRange(outputHdbh);
 }
示例#18
0
        public void HienThiHoaDonBanHang()
        {
            Server_Client.Client cl = new Server_Client.Client();
            this.client1 = cl.Connect(Luu.IP, Luu.Ports);

            Entities.HDBanHang nv = new Entities.HDBanHang("Select");
            clientstream = cl.SerializeObj(this.client1, "HDBanHang", nv);
            Entities.HDBanHang[] nv1 = new Entities.HDBanHang[1];
            nv1 = (HDBanHang[])cl.DeserializeHepper(clientstream, nv1);

            int count=0;
            if (nv1!=null)
            {
                for (int i = 0; i < nv1.Length; i++)
                {
                    if (nv1[i].MaNhanVien==txtmanv.Text)
                    {
                        count++;
                    }
                }
            }
            Entities.HDBanHang [] hdbh= new Entities.HDBanHang [count];

            count = 0;
            if (nv1 != null)
            {
                for (int i = 0; i < nv1.Length; i++)
                {
                    if (nv1[i].MaNhanVien == txtmanv.Text)
                    {
                        hdbh[count] = nv1[i];
                        count++;
                    }
                }
            }
            dataGridView1.DataSource = hdbh;
        }