locked
how only insert the doc_no and leave doc name from autocomplete textbox RRS feed

  • Question

  • User1865404792 posted

    Hi All

    [System.Web.Script.Services.ScriptMethod()]

    [System.Web.Services.WebMethod]

    public static List<string> GetCompletionList(string prefixText, int count)

    {

        using (OracleConnection con = new OracleConnection("data source=localhost:1521/orcl; user id=alhakimy; password=alhakimyyes;"))

        {

            using (OracleCommand com = new OracleCommand())

            {

                com.CommandText = "select doc_no, doc_name from doctors where city_no= Session['city_no'] and doc_name like '%" + prefixText + "%' ";

                com.Parameters.Add("@TextBox1", prefixText);

                com.Connection = con;

                con.Open();

                List<string> summ = new List<string>();

                using (OracleDataReader sdr = com.ExecuteReader())

                {

                    while (sdr.Read())

                    {

                        summ.Add(string.Format("{0}-{1}", sdr["DOC_NAME"], sdr["Doc_NO"]));

                    }

                }

                con.Close();

                return summ;

            }

        }

    }

    In the previous code I have an autocomplete list that shows the (doc_no,doc_name)

    The result is the appearance of the doctor's name and number in the textbox1

    Now I only want to insert the doc_no and leave the doc_name in database

    I used this code

    ("insert into daily_do (MAN_NO,date_ee,DOC_NO,TIME_V,DA_NO,fail_vis) VALUES ('" + lblman_no.Text + "', to_date('" + txtdate.Text + "12:00:00','YYYY-MM-DD HH:MI:ss') ,'" + textbox1.text + "','" + DropDownList1.SelectedValue + "',(select max(DA_NO) from daily_do)+1,'" + DropDownList2.SelectedValue + "')", connect);

    I used this code for solution After adding a hidden field and a button

    <script type="text/javascript">

        $(function () {

            $("[id$=textbox1]").autocomplete({

                source: function (request, response) {

                    $.ajax({

                        url: '<%=ResolveUrl("~/daily.aspx/GetCompletionList") %>',

                        data: "{ 'prefixtext': '" + request.term + "'}",

                        dataType: "json",

                        type: "POST",

                        contentType: "application/json; charset=utf-8",

                        success: function (data) {

                            response($.map(data.d, function (item) {

                                return {

                                    label: item.split('-')[0],

                                    val: item.split('-')[1]

                                }

                            }))

                        },

                        error: function (response) {

                            alert(response.responseText);

                        },

                        failure: function (response) {

                            alert(response.responseText);

                        }

                    });

                },

                select: function (e, i) {

                    $("[id$=hfdoc_no]").val(i.item.val);

                },

                minLength: 1

            });

        }); 

    </script>

    ===============================================

    <asp:TextBox ID="TextBox1" runat="server" Height="30px" style="font-size: large; font-weight: 700" Width="235px" autocomplete="off"></asp:TextBox>

    <asp:Button ID="submit" runat="server" OnClick="Submit" Text="sub" />

    <asp:HiddenField ID="hfdoc_no" runat="server" />

    ===============================================

    protected void Submit(object sender, EventArgs e)

        {

            string doc_name = Request.Form[TextBox1.UniqueID];

            string doc_no = Request.Form[hfdoc_no.UniqueID];

            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Name: " + doc_name + "\\nNO: " + doc_no + "');", true);

        }

    ==============================================

    But the doc_no does not pass to the hidden field and the result is the appearance of message box in which the following is written

    Name:mohammed-2458

    NO:

    While the result is supposed to be as follows

    Name: mohammed

    NO: 2458

    Sunday, June 21, 2020 6:36 AM

All replies

  • User288213138 posted

    Hi alhakimy,

    But the doc_no does not pass to the hidden field and the result is the appearance of message box in which the following is written

    Name:mohammed-2458

    NO:

    While the result is supposed to be as follows

    Name: mohammed

    NO: 2458

    Does the browser alert any error message? 

    You can check whether there are detailed error messages in the console by using F12.

    You can also  try to solve the problem by dubug your code.

    Best regards,

    Sam

    Monday, June 22, 2020 10:07 AM
  • User1865404792 posted

    There are no errors

    But why not take the doc_no (2458) and keep it in the hidden field

    Monday, June 22, 2020 3:52 PM
  • User288213138 posted

    Hi alhakimy,

    There are no errors

    But why not take the doc_no (2458) and keep it in the hidden field

    Please show me your complete code and table structure.

    I tested your code, but it keeps alerting me with error messages.

    Best regards,

    Sam

    Tuesday, June 23, 2020 7:32 AM
  • User1865404792 posted

    When pasting the code here
    Unorganized appeared

    http://www.mediafire.com/file/4zr814i8l991iol/html%2526cs.rar/file

    This link contains a zip file with two files, one for HTML and one for CS

    Tuesday, June 23, 2020 8:50 AM
  • User288213138 posted

    Hi alhakimy,

    http://www.mediafire.com/file/4zr814i8l991iol/html%2526cs.rar/file

    This link contains a zip file with two files, one for HTML and one for CS

    Please post your key code in this thread.

    Best regards,

    Sam

    Wednesday, June 24, 2020 7:40 AM
  • User1865404792 posted

    I am sorry for the link

    html

    <%@ Page Language="C#"  MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="daily.aspx.cs" Inherits="daily" %>
    
    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            .auto-style1 {
                text-align: right;
            }
            .auto-style2 {
                color: #0000CC;
                font-weight: bold;
                font-size: large;
            }
            .auto-style3 {
                text-align: center;
            }
            .auto-style4 {
                font-size: large;
                color: #000000;
            }
            .auto-style5 {
                height: 38px;
            }
            .auto-style7 {
                font-weight: bold;
            }
            .auto-style8 {
                font-size: large;
                font-weight: bold;
            }
            .auto-style9 {
                background-color: #F0F0F0;
            }
            .auto-style10 {
                height: 38px;
                text-align: left;
            }
            .auto-style11 {
                text-align: left;
            }
            .auto-style13 {
                font-size: large;
                color: #0000CC;
            }
            .auto-style14 {
                font-size: large;
            }
            .auto-style15 {
                color: #CC0000;
                font-size: large;
            }
            
            .auto-style16 {
                font-size: large;
                text-decoration: underline;
            }
            .auto-style17 {
                font-size: large;
                color: #CC0066;
            }
            .auto-style19 {
                font-size: x-large;
            }
            
            .auto-style20 {
                color: #CC0066;
                font-size: x-large;
            }
            
        </style>
    </head>
    <body>
    
        <!-- لحفظ رقم الطبيب المختار في صفحة الزيارات في الحقل المخفي من اجل الحفظ في قاع -->
        <script type="text/javascript">
        $(function () {
            $("[id$=TextBox1]").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '<%=ResolveUrl("~/daily.aspx/GetCompletionList") %>',
                        data: "{ 'prefixText': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.split('-')[0],
                                    val: item.split('-')[1]
                                }
                            }))
                        },
                        error: function (response) {
                            alert(response.responseText);
                        },
                        failure: function (response) {
                            alert(response.responseText);
                        }
                    });
                },
                select: function (e, i) {
                    $("[id$=hfdoc_no]").val(i.item.val);
                },
                minLength: 1
            });
        });  
    </script>
            
        <!--ادخال فقط ارقام في تكست كمية العينات -->
        <script type="text/javascript">
            function CheckNumeric(e) {
                if (window.event)
                    // IE             
                {
                    if ((e.keyCode < 48 || e.keyCode > 57) & e.keyCode != 8)
                {
                    event.returnValue = false;
                    return false;
                }
                }
                else {
                    // Fire Fox
                    if ((e.which < 48 || e.which > 57) & e.which != 8)
                    {
                        e.preventDefault();
                        return false;
                    }
                }
            }  
    
        </script>
        
    
    
        <form id="form1" runat="server">
        <div>
        
            <br />
            <table align="center" class="auto-style9">
                <tr>
                    <td colspan="6" class="auto-style3">
                        <asp:ScriptManager ID="ScriptManager1" runat="server">
                        </asp:ScriptManager>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="auto-style3">
                        <asp:Image ID="Image1" runat="server" Height="88px" ImageUrl="~/img/daily-visits.png" Width="353px" />
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style1" colspan="3">
                        <asp:Label ID="Label7" runat="server" CssClass="auto-style13" Height="35px" Width="100%"></asp:Label>
                    </td>
                    <td class="auto-style3">
                        <asp:Label ID="Label8" runat="server" CssClass="auto-style14" Height="35px" Text=":المستخدم"></asp:Label>
                    </td>
                    <td class="auto-style1">&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style11"><strong>
                        <asp:Button ID="btnback" runat="server" CausesValidation="False" CssClass="auto-style2" Height="35px" Text="رجوع للرئيسية" Width="140px" OnClick="Button4_Click" />
                        </strong></td>
                    <td class="auto-style11">&nbsp;</td>
                    <td class="auto-style11" colspan="2"><strong>
                        <asp:Button ID="btnnewvisit" runat="server" CssClass="auto-style2" Height="35px" OnClick="Button5_Click" Text="زياره جديده" Width="140px" CausesValidation="False" />
                        </strong></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style11" colspan="4">
                        <asp:DropDownList ID="DropDownList5" runat="server" Visible="False">
                        </asp:DropDownList>
                        <asp:HiddenField ID="hfdoc_no" runat="server"  />
                        <asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" />
                    </td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style11" colspan="3"><strong>
                        <asp:TextBox ID="txtdate" runat="server" CssClass="auto-style7" Enabled="False" Font-Size="12pt" Height="30px" Width="235px"></asp:TextBox>
                        </strong></td>
                    <td class="auto-style11" colspan="2"><strong>
                        <asp:Label ID="Label1" runat="server" CssClass="auto-style4" Text=":التاريخ"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td>
                        &nbsp;</td>
                    
                    <td class="auto-style11" colspan="3">
                        <asp:TextBox ID="TextBox1" runat="server" Height="30px" style="font-size: large; font-weight: 700" Width="235px" autocomplete="off"></asp:TextBox>
                        <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" CompletionInterval="250"> </cc1:AutoCompleteExtender>
                              </td>
                    <td class="auto-style11" colspan="2"><strong>
                        <asp:Label ID="Label15" runat="server" CssClass="auto-style4" Text=":الطبيب"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="DropDownList4" CssClass="auto-style20" ErrorMessage="ادخل اسم الطبيب">*</asp:RequiredFieldValidator>
                    </td>
                    <td class="auto-style11" colspan="3">
                        <asp:DropDownList ID="DropDownList4" runat="server" Height="35px" Width="240px" CssClass="auto-style14">
                            <asp:ListItem Value="1">محمد</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td class="auto-style11" colspan="2"><strong>
                        <asp:Label ID="Label2" runat="server" CssClass="auto-style4" Text=":الطبيب"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style11" colspan="3"><strong>
                        <asp:DropDownList ID="DropDownList1" runat="server" CssClass="auto-style8" Enabled="False" Height="35px" Width="240px">
                            <asp:ListItem Value="morning">صباحية</asp:ListItem>
                            <asp:ListItem Value="evening">مسائية</asp:ListItem>
                        </asp:DropDownList>
                        </strong></td>
                    <td class="auto-style11" colspan="2"><strong>
                        <asp:Label ID="Label3" runat="server" CssClass="auto-style4" Text=":الفترة"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td class="auto-style5"></td>
                    <td class="auto-style10" colspan="3"><strong>
                        <asp:DropDownList ID="DropDownList2" runat="server" CssClass="auto-style8" Enabled="False" Height="35px" Width="240px">
                            <asp:ListItem Value="ok">تمت الزيارة</asp:ListItem>
                            <asp:ListItem Value="absentee">لم يحضر</asp:ListItem>
                            <asp:ListItem Value="busy">مشغول</asp:ListItem>
                            <asp:ListItem Value="travel">مسافر</asp:ListItem>
                        </asp:DropDownList>
                        </strong></td>
                    <td class="auto-style10" colspan="2"><strong>
                        <asp:Label ID="Label4" runat="server" CssClass="auto-style4" Text=":الحالة"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style11" colspan="3"><strong>
                        <asp:DropDownList ID="DropDownList3" runat="server" CssClass="auto-style8" Enabled="False" Height="35px" Width="240px" AppendDataBoundItems="true">
                            <asp:ListItem Selected="True" Text="" Value=""></asp:ListItem>
                        </asp:DropDownList>
                        </strong></td>
                    <td class="auto-style11" colspan="2"><strong>
                        <asp:Label ID="Label5" runat="server" CssClass="auto-style4" Text=":العينة"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style3" colspan="2"><strong>
                        <asp:Button ID="btnadd" runat="server" CssClass="auto-style8" Height="35px" OnClick="btnadd_Click" Text="اضافة عينة" Width="126px" />
                        &nbsp;&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtqnt" CssClass="auto-style20" ErrorMessage="ادخل الكمية">*</asp:RequiredFieldValidator>
                        </strong></td>
                    <td class="auto-style11">
                        <asp:TextBox ID="txtqnt" onkeypress="CheckNumeric(event);" xmlns:asp="#unknown" runat="server" Enabled="False" Height="30px" Width="60px" CssClass="auto-style19"></asp:TextBox>
                    </td>
                    <td><strong>
                        <asp:Label ID="Label6" runat="server" CssClass="auto-style4" Text=":الكمية"></asp:Label>
                        </strong></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td class="auto-style3" colspan="6">
                        <asp:Label ID="Label10" runat="server" CssClass="auto-style15" Width="100%"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td colspan="6">
                        <asp:GridView ID="GridView1" runat="server" Width="100%" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="GridView1_RowDeleting">
                            <AlternatingRowStyle BackColor="White" />
                            <Columns>
                                <asp:TemplateField HeaderText="حذف" ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="~/img/delete.png" Text="Delete" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#EFF3FB" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#F5F7FB" />
                            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                            <SortedDescendingCellStyle BackColor="#E9EBEF" />
                            <SortedDescendingHeaderStyle BackColor="#4870BE" />
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style3" colspan="6">&nbsp;</td>
                </tr>
                <tr>
                    <td class="auto-style3" colspan="6"><strong>
                        <asp:Label ID="Label11" runat="server" CssClass="auto-style16" Text="الهدايا المقدمة للطبيب" Width="100%"></asp:Label>
                        </strong></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="3">
                        <strong>
                        <asp:TextBox ID="txtgive" runat="server" CssClass="auto-style7" Enabled="False" Font-Size="12pt" Height="30px" Width="235px"></asp:TextBox>
                        </strong></td>
                    <td><strong>
                        <asp:Label ID="Label12" runat="server" CssClass="auto-style14" Text=":الهدية"></asp:Label>
                        </strong></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="2" class="auto-style1">
                        <strong>
                        <asp:Button ID="btnaddgive" runat="server" CssClass="auto-style8" Height="35px" OnClick="btnaddgive_Click" Text="اضافة هديه" Width="120px" Enabled="False" />
                        &nbsp;&nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtqntgive" CssClass="auto-style20" ErrorMessage="ادخل الكمية">*</asp:RequiredFieldValidator>
                        </strong></td>
                    <td class="auto-style11">
                        <asp:TextBox ID="txtqntgive" onkeypress="CheckNumeric(event);" runat="server" Enabled="False" Height="30px" Width="60px" CssClass="auto-style19">0</asp:TextBox>
                    </td>
                    <td><strong>
                        <asp:Label ID="Label13" runat="server" CssClass="auto-style14" Text=":الكمية"></asp:Label>
                        </strong></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td class="auto-style3" colspan="4">
                        <strong>
                        <asp:Label ID="Label14" runat="server" CssClass="auto-style17"></asp:Label>
                        </strong></td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="6">
                        <asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDeleting="GridView2_RowDeleting" Width="100%">
                            <AlternatingRowStyle BackColor="White" />
                            <Columns>
                                <asp:CommandField ButtonType="Image" DeleteImageUrl="~/img/delete.png" HeaderText="حذف" ShowDeleteButton="True" />
                            </Columns>
                            <EditRowStyle BackColor="#2461BF" />
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#EFF3FB" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                            <SortedAscendingCellStyle BackColor="#F5F7FB" />
                            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                            <SortedDescendingCellStyle BackColor="#E9EBEF" />
                            <SortedDescendingHeaderStyle BackColor="#4870BE" />
                        </asp:GridView>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="2">
                        &nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="2">
                        <strong>
                        <asp:Button ID="btnsave" runat="server" OnClick="btnsave_Click" Text="حفظ" Width="120px" CssClass="auto-style8" Height="35px" Enabled="False" />
                        </strong></td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>
                        &nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td colspan="2">
                        &nbsp;</td>
                    <td colspan="2">
                        <asp:Label ID="lblman_no" runat="server" Visible="False"></asp:Label>
                    </td>
                    <td>&nbsp;</td>
                </tr>
            </table>
            <br />
        
        </div>
        </form>
    </body>
    </html>
    

    c#

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;//لاضافة الجدول
    using Oracle.ManagedDataAccess.Client;
    using System.Web.Services;
    using System.Configuration;
    
    public partial class daily : System.Web.UI.Page
    {
        
        OracleConnection connect = new OracleConnection("data source=localhost:1521/orcl; user id=alhakimy; password=alhakimyyes;");
    
        //تعريف تايبل من اجل اضافه العينات للجريد فيو
        DataTable addtogv = new DataTable();
    
        //تعريف تايبل من اجل اضافه العينات للجريد فيو
        DataTable addgive = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            ///////////////////////////////////اذا كان الرابط يذهب على طول لصفحه غير صفحة الدخول فيجب ان يعود لصفحه تسجيل الدخول كيف هذا\
            //سنكتب الكود التالي الذي يقول عند تحميل الصفحه لو كان المتغير الذي ياخر قيمة رقم المستخدم فارغ اي انه لم يقم بادخال رقم المستخدم افتح صفحة تسجيل الدخول كالتالي
            if (!Page.IsPostBack)
            {
                if (Session["user_no"] == null)
                {
                    Response.Redirect("login.aspx");
                }
            }
            /////////////////////////////////////
            // طباعة اسم الستتخدم على ليبل 7 ورقم المستخدم في ليبل الرقم
            if (Session["user_name"] != null)
            {
                Label7.Text = Session["user_name"].ToString();
            }
    
            if (Session["user_no"] != null)
            {
                lblman_no.Text = Session["user_no"].ToString();//طباعة رقم المستخدم في اليبل
            }
            ///////////////////////////////اضهار رقم واسم المدينة التي يعمل بها المندوب الذي سجل الدخول
            try
            { 
                if (connect.State == ConnectionState.Closed)
                {
                    connect.Open();
                }
                //المدينة التي يعمل فيها المندوب الذي سجل الدخول
                OracleDataAdapter adbter_city_no = new OracleDataAdapter("SELECT ALL mandob_up.city_NO, city.city_NAME FROM city, mandob_up WHERE mandob_up.city_NO = city.city_NO and(mandob_up.man_no = '" + lblman_no.Text + "')", connect);
                DataTable tab_city_no = new DataTable();
                connect.Close();
    
                adbter_city_no.Fill(tab_city_no);
                DropDownList5.DataSource = tab_city_no;
                DropDownList5.DataTextField = "CITY_NAME";
                DropDownList5.DataValueField = "CITY_NO";
                DropDownList5.DataBind();
                ///////////////////////اخذ رقم المدينه من اجل استخدامها في الويب ميثود
                Session["city_no"] = DropDownList5.SelectedValue;
            }
    
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            ////////////////////////////////////////////////
            if (!Page.IsPostBack)
            {
                if (ViewState["gives"] == null)//تسمية الاعمدة الخاصة بجريد فيو الهدايا
                {
                    addgive.Columns.Add("give");
                    addgive.Columns.Add("qun_g");
                    ViewState["gives"] = addgive;
                }
            }
    
            /////////////////////////
            //من اجل هل تم تحميل الصفحه مجددا ام لا لاضافه العيانات للجريد فيو
            if (!Page.IsPostBack)
            {
                if (ViewState["records"] == null)
                {
                    addtogv.Columns.Add("item_no");
                    addtogv.Columns.Add("item_name");
                    addtogv.Columns.Add("qun");
                    ViewState["records"] = addtogv;
                }
            }
            
        }
    
        ///////////////////////////////// الطوة الثانية لعمل اوتو كمبليت حيث الاولى هي المفاتيح والتكست بوكس1 وبداخله اوتوكمبليت
        [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
    
        public static List<string> GetCompletionList(string prefixText)
        { 
            using (OracleConnection con = new OracleConnection("data source=localhost:1521/orcl; user id=alhakimy; password=alhakimyyes;"))
            {
                using (OracleCommand com = new OracleCommand())
                {
                    com.CommandText = "select doc_no, doc_name from doctors where city_no= "+ HttpContext.Current.Session["city_no"]+" and doc_name like '%" + prefixText + "%' and doctors.status=0 ";
                    com.Parameters.Add("@TextBox1", prefixText);
                    com.Connection = con;
                    con.Open();
                    List<string> summ = new List<string>();
                    using (OracleDataReader sdr = com.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            summ.Add(string.Format("{0}-{1}", sdr["DOC_NAME"], sdr["Doc_NO"]));//اذا اضفنا عمود جملة السكلته سنضيفه هنا كالبقية
                        }
                    }
                    con.Close();
                    return summ;
                }
            }
        }
        ////////////////////////////////
        //////////الزر الخاص بعضر رساله
        protected void Submit(object sender, EventArgs e)
        {
            string doc_name = Request.Form[TextBox1.UniqueID];
            string doc_no = Request.Form[hfdoc_no.UniqueID];
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Name: " + doc_name + "\\nNO: " + doc_no + "');", true);
    
        }
    
        protected void btnadd_Click(object sender, EventArgs e)
        {
            try
            {
                //GridView1.Columns[2].Visible = false;
                //جملة الشرط التالية تقول لوكان حقل كمية العينات اقل او تساوي صفر اضهر الليبل الذي يقول دخل قيمة اكبر من صفر
                if (int.Parse(txtqnt.Text) < 1)
                {
                    Label10.Text = "ادخل قيمة اكبر من صفر";  //تم استخدام انتجر دوت بارس لانه لانه يقبل فقط سترينج داخل التكست بوكس 
                }
                else
                {
                    Label10.Visible = false;//اخفاء ليبل رساله ادخال قيمة اكبر من صفر
                                            //اضافه للجريد فيو الخاصه بالعينات
                    addtogv = (DataTable)ViewState["records"];
                    addtogv.Rows.Add(DropDownList3.SelectedItem.Value, DropDownList3.SelectedItem.Text, txtqnt.Text);
                    GridView1.DataSource = addtogv;
                    GridView1.DataBind();
                }
            }
            
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
    
    
    
    
    
        }
    
        protected void Button5_Click(object sender, EventArgs e)
        {
         
            try
            {
                txtdate.Text = DateTime.Now.ToString("yyyy/MM/dd");
                //في حالة تشغيل الفورم تكون الادوات غير مفعله
                //وعند ضغط زر اضافه زياره تتم تفعيل هذه الادوات
                DropDownList1.Enabled = true;
                DropDownList2.Enabled = true;
                DropDownList3.Enabled = true;
                txtqnt.Enabled = true;
                btnadd.Enabled = true;
                btnsave.Enabled = true;
                btnaddgive.Enabled = true;
                txtgive.Enabled = true;
                txtqntgive.Enabled = true;
                //RequiredFieldValidator3.Enabled = true; // تشغيل التحقق من ادخال اسم الطبيب لانها مغلقة من الخصائص بسبب
                // انه كان عند الضغط على زياره جديده وتفعيل تكست الطبيب كان يشتغل على طول وتضهر النجمه
    
                //عرض اسماء الاصناف الخاص بالمندوب الذي سجل الدخول
                //OracleConnection connect = new OracleConnection("data source=localhost:1521/orcl; user id=alhakimy; password=alhakimyyes;");
                if (connect.State == ConnectionState.Closed)
                {
                    connect.Open();
                }
    
                OracleDataAdapter adbter_samp = new OracleDataAdapter("SELECT ALL MAN_DO2.ITEMS_NO, ITEMS.ITEMS_NAME FROM ITEMS, MAN_DO2 WHERE MAN_DO2.ITEMS_NO = ITEMS.ITEMS_NO and (man_do2.man_no = '"+lblman_no.Text+"')", connect);
                DataTable tab_samp = new DataTable();
                connect.Close();
    
                adbter_samp.Fill(tab_samp);
                DropDownList3.DataSource = tab_samp;
                DropDownList3.DataTextField = "ITEMS_NAME";
                DropDownList3.DataValueField = "ITEMS_NO";
                DropDownList3.DataBind();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
             
        }
    
    
    
    
    
        protected void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                //القسم الخاص بحفظ اسم الطبيب المزار
                if (connect.State == ConnectionState.Closed)
                {
                    connect.Open();
                }
                OracleCommand cmd = new OracleCommand("insert into daily_do (MAN_NO,date_ee,DOC_NO,TIME_V,DA_NO,fail_vis) VALUES ('" + lblman_no.Text + "', to_date('" + txtdate.Text + "12:00:00','YYYY-MM-DD HH:MI:ss') ,'" + DropDownList4.SelectedValue + "','" + DropDownList1.SelectedValue + "',(select max(DA_NO) from daily_do)+1,'" + DropDownList2.SelectedValue + "')", connect);
                cmd.ExecuteNonQuery();
                connect.Close();
                //القسم الخاص بحفظ العينات
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    cmd = new OracleCommand("insert into samp(sam_NO,DA_NO,ITEM_NO,QUNTITY,datee,status,note_e,doc_no,man_no) VALUES ((select max(sam_no) from SAMP)+1,(select max(DA_NO) from daily_do)," + GridView1.Rows[i].Cells[1].Text + "," + GridView1.Rows[i].Cells[3].Text + ",to_date('" + txtdate.Text + " 12:00:00','YYYY-MM-DD HH:MI:ss'),1,null," + DropDownList4.SelectedValue + ",'" + lblman_no.Text + "')", connect);
                    connect.Open();
                    cmd.ExecuteNonQuery();
                    connect.Close();
                }
                //القسم الخاص بحفظ الهدايا
                for (int i = 0; i < GridView2.Rows.Count; i++)
                {
                    cmd = new OracleCommand("insert into GIVES(GIVES_NO,DA_NO,Gives_NAME,QUN,date_e,status,note_e,doc_no,man_no) VALUES ((select max(GIVES_NO) from GIVES)+1,(select max(DA_NO) from daily_do),'" + GridView2.Rows[i].Cells[1].Text + "','" + GridView2.Rows[i].Cells[2].Text + "',to_date('" + txtdate.Text + " 12:00:00','YYYY-MM-DD HH:MI:ss'),1,null," + DropDownList4.SelectedValue + ",'" + lblman_no.Text + "')", connect);
                    connect.Open();
                    cmd.ExecuteNonQuery();
                    connect.Close();
                }
    
    
                //Label10.Text="تم اضافة الزياره بنجاح";
                Response.Write("<script>alert('تمت عملة الحفظ');</script>");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
    
    
    
        }
    
    
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            addtogv = (DataTable)ViewState["records"];
            addtogv.Rows[e.RowIndex].Delete();
            GridView1.DataSource = addtogv;
            GridView1.DataBind();
        }
    
        protected void btnaddgive_Click(object sender, EventArgs e)
        {
            try
            {
                //جملة الشرط التالية تقول لوكان حقل كمية الهدايا اقل او تساوي صفر اضهر الليبل الذي يقول دخل قيمة اكبر من صفر
                if (int.Parse(txtqntgive.Text) < 1)
                {
                    Label14.Text = "ادخل قيمة اكبر من صفر";  //تم استخدام انتجر دوت بارس لانه لانه يقبل فقط سترينج داخل التكست بوكس 
                }
                else
                {
                    Label14.Visible = false;//اخفاء ليبل رساله ادخال قيمة اكبر من صفر
                                            // اضافه للجريد فيو الخاصة بالهدايا
                    addgive = (DataTable)ViewState["gives"];
                    addgive.Rows.Add(txtgive.Text, txtqntgive.Text);
                    GridView2.DataSource = addgive;
                    GridView2.DataBind();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
    
        }
    
        protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            addgive = (DataTable)ViewState["gives"];
            addgive.Rows[e.RowIndex].Delete();
            GridView2.DataSource = addgive;
            GridView2.DataBind();
        }
    
    
        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Redirect("main.aspx");
        }
      
    }

    Wednesday, June 24, 2020 8:09 AM
  • User288213138 posted

    Hi alhakimy,

     $("[id$=TextBox1]").autocomplete({

    Can you share with me a reference to your autocomplete() method?

    I tested your code, but encountered an autocomplete is not a function error, but when I write the demo test myself, it can work normally.

    Best regards,

    Sam

    Thursday, July 2, 2020 7:43 AM
  • User1865404792 posted
    Thank you
    The problem was solved by transferring the following code
     <script type="text/javascript">
        $(function () {
            $("[id$=TextBox1]").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '<%=ResolveUrl("~/daily.aspx/GetCompletionList") %>',
                        data: "{ 'prefixText': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.split('-')[0],
                                    val: item.split('-')[1]
                                }
                            }))
                        },
                        error: function (response) {
                            alert(response.responseText);
                        },
                        failure: function (response) {
                            alert(response.responseText);
                        }
                    });
                },
                select: function (e, i) {
                    $("[id$=hfdoc_no]").val(i.item.val);
                },
                minLength: 1
            });
        });  
    </script>
    From <body>
    to Down <title></title>

    thank you

    Saturday, July 4, 2020 8:06 AM