i have 4 autocomplete text box for job, emboss, cylinder and die
The product and category are working well but i noticed the cylinder uses the embid value instead of id value of jobs so it displays false result.
Lastly i also want to use the dieno from job table to display die no from die table.
Please note
emboss.id = embid.job
jcylin.pid = job.id
jdie.id = job.dieno
CREATE TABLE [dbo].[job_emboss](
[id] [int] NULL,
[embid] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[job_cylinder](
[id] [int] NULL,
[pid] [nvarchar](50) NULL,
[posino] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[job_die](
[id] [int] NULL,
[dieno] [nvarchar](50) NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[job](
[id] [int] NULL,
[pid] [nvarchar](50) NULL,
[embid] [nvarchar](50) NULL,
[diereferneceno] [nvarchar](50) NULL,
[gietzdieref] [nvarchar](50) NULL
) ON [PRIMARY]
GO
INSERT [dbo].[job] ([id], [pid], [embid], [diereferneceno],[gietzdieref]) VALUES (1, N'Test33', N'453', N'570', N'Git1')
INSERT [dbo].[job_emboss] ([id], [embid]) VALUES (453, N'filmno1')
INSERT [dbo].[job_die] ([id], [embid]) VALUES (570, N'die33')
INSERT [dbo].[job_cylinder] ([id], [pid], [posino]) VALUES (236, N'1', N'23a')
INSERT [dbo].[job_cylinder] ([id], [pid], [posino]) VALUES (237, N'1', N'23b')
INSERT [dbo].[job_cylinder] ([id], [pid], [posino]) VALUES (238, N'1', N'23c')
INSERT [dbo].[job_cylinder] ([id], [pid], [posino]) VALUES (239, N'1', N'23d')
INSERT [dbo].[job_cylinder] ([id], [pid], [posino]) VALUES (240, N'1', N'23e')
INSERT [dbo].[job_cylinder] ([id], [pid], [posino]) VALUES (240, N'1', N'23f')
From the Datase structure
Job j
job_emboss e
job_die d
job_cylinder c
j.embid =e.id
j.diereferneceno = d.id
j.id= c.pid
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData",
data: "{ 'searchTerm': '" + request.term + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1 }]);
}
},
error: function (result) {
alert(result.responseText);
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
$('[id*=hfjob2]').val(ui.item.val.split(',')[0]);
$('[id*=hfDieNo]').val(ui.item.val.split(',')[1]);
$('[id*=hfidd]').val(ui.item.val.split(',')[2]);
}
});
}
function SearchText3() {
$(".autosuggest3").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData3",
data: "{ 'searchTerm': '" + request.term + "', pid: '" + $('[id*=hfidd]').val() + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1 }]);
}
},
error: function (result) {
alert(result.responseText);
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
$('[id*=hfjcylin]').val(ui.item.val);
}
});
}
[WebMethod]
public static List<string> GetAutoCompleteData(string searchTerm)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd = new SqlCommand("SELECT id,embid,pid,diereferneceno FROM job WHERE pid LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", searchTerm);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1},{2},{3}", dr["pid"], dr["embid"], dr["diereferneceno"], dr["id"]));
}
return result;
}
}
}
[WebMethod]
public static List<string> GetAutoCompleteData3(string searchTerm, string id)
{
List<string> result = new List<string>();
using (SqlConnection con1 = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd1 = new SqlCommand("select pid,posino from job_cylinder where posino LIKE '%'+@SearchText+'%' AND pid=@id order by id asc", con1))
{
con1.Open();
cmd1.Parameters.AddWithValue("@SearchText", searchTerm);
cmd1.Parameters.AddWithValue("@pid", id);
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["posino"], dr["id"]));
}
return result;
}
}
}
pid:
<asp:TextBox ID="txtSearch1" class="autosuggest" runat="server" Width="29%"></asp:TextBox>
<asp:HiddenField ID="hfjob2" runat="server" />
<asp:HiddenField ID="hfDieNo" runat="server" />
<asp:HiddenField ID="Hfidd" runat="server" />
posino :<asp:TextBox ID="TextBox24" class="autosuggest3" runat="server" Width="244px"></asp:TextBox>
<asp:HiddenField ID="hfjcylin" runat="server" />
i am confused,i dont know what to do again.