public static KhachHangDTO LayKhachHangTheoMaKhachHang(String mkh)
        {
            KhachHangDTO khachhang = new KhachHangDTO();

            try
            {
                // Making connection with Npgsql provider
                NpgsqlConnection conn = new NpgsqlConnection(SqlDataAccessHelper.ConnectionString());
                try
                {
                    conn.Open();
                }
                catch (Exception)
                {
                    throw;
                }

                // quite complex sql statement
                string sql = "SELECT * FROM khachhang Where makhachhang = '" + mkh + "'";

                NpgsqlCommand    command = new NpgsqlCommand(sql, conn);
                NpgsqlDataReader reader  = command.ExecuteReader();

                while (reader.Read())
                {
                    khachhang.MaKhachHang     = reader[0].ToString();
                    khachhang.HoTen           = reader[1].ToString();
                    khachhang.CMND            = reader[2].ToString();
                    khachhang.NgaySinh        = DateTime.Parse(reader[3].ToString());
                    khachhang.GioiTinh        = reader[4].ToString();
                    khachhang.DiaChi          = reader[5].ToString();
                    khachhang.Sdt             = reader[6].ToString();
                    khachhang.MaLoaiKhachHang = reader[7].ToString();
                }

                conn.Close();
                return(khachhang);
            }
            catch (Exception msg)
            {
                // something went wrong, and you wanna know why

                throw msg;
            }
        }
Exemple #2
0
        public static NpgsqlDataAdapter TimKiemPhieuThue(PhieuThueDTO pt)
        {
            try
            {
                // Making connection with Npgsql provider
                NpgsqlConnection conn = new NpgsqlConnection(SqlDataAccessHelper.ConnectionString());
                conn.Open();
                // quite complex sql statement
                string sql = "select phieuthue.maphieuthue, phieuthue.makhachhang, hoten, manhanvien, ngaylap, soluongphong  from phieuthue, khachhang WHERE phieuthue.makhachhang = khachhang.makhachhang AND maphieuthue LIKE '%" + pt.MaPhieuThue + "%' AND phieuthue.makhachhang LIKE '%" + pt.MaKhachHang + "%' AND hoten LIKE '%" + pt.HoTenKhachHang + "%'";

                // data adapter making request from our connection
                NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);

                conn.Close();
                return(da);
            }
            catch (Exception msg)
            {
                // something went wrong, and you wanna know why
                //MessageBox.Show(msg.ToString());
                throw msg;
            }
        }