<%@ page title="Patient Visit" language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="PatientVIsit, App_Web_fzfkhksa" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:UpdatePanel ID="PagePanel" runat="server" ChildrenAsTriggers="true">
        <ContentTemplate>
            <div class="main-content container-fluid">
                <div class="page-title">
                    <h3>Patient Visit</h3>
                </div>
                <section class="section">
                    <div class="row bspace form-group">
                        <div class="col-md-12">
                            <div class="divider">
                                <div class="divider-text">Patient Details</div>
                            </div>
                            <div class="row bspace form-group">
                                <div class="col-md-2">
                                    <label class="label">Visit Date</label>
                                    <asp:TextBox ID="txtVisitDate" runat="server" CssClass="form-control" TextMode="Date" placeholder="dd/mm/yyyy" required AutoComplete="off"></asp:TextBox>
                                    <asp:Label ID="lblLastVisitDate" runat="server" Visible="false"></asp:Label>
                                </div>
                                <div class="col-md-2">
                                    <label class="label">Visit Time</label>
                                    <asp:TextBox ID="txtTime" runat="server" CssClass="form-control" TextMode="Time" placeholder="HH:MM" required AutoComplete="off"></asp:TextBox>
                                </div>
                                <div class="col-md-2">
                                    <label class="label">Patient Type</label>
                                    <asp:DropDownList ID="ddlPatientType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPatientType_SelectedIndexChanged" CssClass="form-select">
                                        <asp:ListItem Text="Small" Value="1"></asp:ListItem>
                                        <asp:ListItem Text="Large" Value="2"></asp:ListItem>
                                        <asp:ListItem Text="Exotic" Value="3"></asp:ListItem>
                                        <asp:ListItem Text="Poultry/Dairy" Value="4"></asp:ListItem>
                                        <asp:ListItem Text="Equine" Value="5"></asp:ListItem>
                                    </asp:DropDownList>
                                </div>
                                <div class="col-md-3">
                                    <asp:Label ID="lblNew" runat="server" Visible="false"></asp:Label>
                                    <label class="label">Owner Name</label>
                                    <asp:Label ID="lblPatientID" runat="server" Visible="false"></asp:Label>
                                    <asp:TextBox ID="txtOwnerName" runat="server" CssClass="form-control" AutoPostBack="true" OnTextChanged="txtOwnerName_TextChanged" placeholder="Owner Name" required AutoComplete="off"></asp:TextBox>
                                    <cc1:AutoCompleteExtender ID="txtOwnerName_AutoCompleteExtender" runat="server" BehaviorID="txtOwnerName_AutoCompleteExtender" CompletionListCssClass="completionList" CompletionListHighlightedItemCssClass="itemHighlighted" CompletionListItemCssClass="listItem" DelimiterCharacters="" ServicePath="AutoComplete.asmx" ServiceMethod="GetOwnerName" TargetControlID="txtOwnerName">
                                    </cc1:AutoCompleteExtender>
                                </div>
                                <div class="col-md-3">
                                    <asp:Label CssClass="label" ID="lblType" Text="Patient Name" runat="server"></asp:Label>
                                    <asp:TextBox ID="txtPatientName" runat="server" required CssClass="form-select" list="PatientList" AutoPostBack="true" OnTextChanged="txtPatientName_TextChanged" AutoComplete="off" />
                                    <datalist id="PatientList">
                                        <asp:Repeater ID="repeatList" runat="server">
                                            <ItemTemplate>
                                                <option value='<%# Eval("PatientName") %>' itemid='<%# Eval("PatientID") %>'></option>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </datalist>
                                </div>
                            </div>
                            <div class="row">
                                <div class="row bspace form-group">
                                    <div class="col-md-4">
                                        <label class="label">WA No</label>
                                        <asp:TextBox ID="txtWaNo" runat="server" CssClass="form-control" placeholder="WA No"></asp:TextBox>
                                    </div>
                                    <div class="col-md-4">
                                        <label class="label">Alternate No</label>
                                        <asp:TextBox ID="txtAltNo" runat="server" CssClass="form-control" placeholder="Alternate No"></asp:TextBox>
                                    </div>
                                    <div class="col-md-4">
                                        <label class="label">Email ID</label>
                                        <asp:TextBox ID="txtEmailID" runat="server" CssClass="form-control" placeholder="Email ID"></asp:TextBox>
                                    </div>
                                </div>
                                <div class="row bspace form-group">
                                    <div class="col-md-4">
                                        <label class="label">Address</label>
                                        <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" CssClass="form-control" Height="100px" placeholder="Address"></asp:TextBox>
                                    </div>
                                    <div class="col-md-8">
                                        <div class="row bspace form-group">
                                            <div class="col-md-6">
                                                <label class="label">DOB</label>
                                                <asp:TextBox ID="txtDOB" runat="server" TextMode="Date" onchange="DateSelectionChanged()" CssClass="form-control" placeholder="dd/MM/yyyy"></asp:TextBox>
                                                <script type="text/javascript">
                                                    function DateSelectionChanged() {
                                                        var endingDate = new Date();

                                                        var startingDate = new Date(document.getElementById('<%=txtDOB.ClientID%>').value);

                                                        var startDate = new Date(new Date(startingDate).toISOString().substr(0, 10));
                                                        if (!endingDate) {
                                                            endingDate = new Date().toISOString().substr(0, 10); // need date in YYYY-MM-DD format
                                                        }
                                                        var endDate = new Date(endingDate);
                                                        if (startDate > endDate) {
                                                            var swap = startDate;
                                                            startDate = endDate;
                                                            endDate = swap;
                                                        }
                                                        var startYear = startDate.getFullYear();
                                                        var february = (startYear % 4 === 0 && startYear % 100 !== 0) || startYear % 400 === 0 ? 29 : 28;
                                                        var daysInMonth = [31, february, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

                                                        var yearDiff = endDate.getFullYear() - startYear;
                                                        var monthDiff = endDate.getMonth() - startDate.getMonth();
                                                        if (monthDiff < 0) {
                                                            yearDiff--;
                                                            monthDiff += 12;
                                                        }
                                                        var dayDiff = endDate.getDate() - startDate.getDate();
                                                        if (dayDiff < 0) {
                                                            if (monthDiff > 0) {
                                                                monthDiff--;
                                                            } else {
                                                                yearDiff--;
                                                                monthDiff = 11;
                                                            }
                                                            dayDiff += daysInMonth[startDate.getMonth()];
                                                        }
                                                        document.getElementById('<%=txtAge.ClientID%>').value = yearDiff + 'Y ' + monthDiff + 'M ' + dayDiff + 'D';
                                                    }
                                                </script>
                                            </div>
                                            <div class="col-md-6">
                                                <label class="label">Age</label>
                                                <asp:TextBox ID="txtAge" runat="server" CssClass="form-control" placeholder="Age"></asp:TextBox>
                                            </div>

                                        </div>
                                        <div class="row bspace form-group">
                                            <div class="col-md-6">
                                                <label class="label">Gender</label>
                                                <asp:DropDownList ID="ddlGender" runat="server" CssClass="form-select">
                                                    <asp:ListItem Text="Select"></asp:ListItem>
                                                    <asp:ListItem Text="Male"></asp:ListItem>
                                                    <asp:ListItem Text="Female"></asp:ListItem>
                                                    <asp:ListItem Text="Neutered Male"></asp:ListItem>
                                                    <asp:ListItem Text="Neutered Female"></asp:ListItem>
                                                </asp:DropDownList>
                                            </div>
                                            <div class="col-md-6">
                                                <label class="label">Weight</label>
                                                <%--  </div>
                                            <div class="col-md-4">--%>
                                                <asp:TextBox ID="txtWeight" runat="server" CssClass="form-control" placeholder="Weight"></asp:TextBox>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row bspace form-group">
                                        <div class="col-md-2">
                                            <label class="label">Species</label>
                                        </div>
                                        <div class="col-md-2">
                                            <asp:DropDownList ID="ddlSpeciesType" runat="server" CssClass="form-select" AppendDataBoundItems="true" AutoPostBack="true" OnSelectedIndexChanged="ddlSpeciesType_SelectedIndexChanged">
                                                <asp:ListItem Selected="True" Value="0" Text="Select"></asp:ListItem>
                                            </asp:DropDownList>
                                        </div>
                                        <div class="col-md-2">
                                            <label class="label">Breed</label>
                                        </div>
                                        <div class="col-md-2">
                                            <asp:DropDownList ID="ddlBreed" runat="server" CssClass="form-select" AppendDataBoundItems="true">
                                                <asp:ListItem Selected="True" Value="0" Text="Select"></asp:ListItem>
                                            </asp:DropDownList>
                                        </div>
                                        <div class="col-md-1">
                                            <label class="label">Nos.</label>
                                        </div>
                                        <div class="col-md-1">
                                            <asp:TextBox ID="txtNos" runat="server" CssClass="form-control" placeholder="Nos"></asp:TextBox>
                                        </div>
                                        <div class="col-md-2">
                                            <asp:Button ID="btnAdd" runat="server" Visible="false" Text="Add" CausesValidation="false" UseSubmitBehavior="false" CssClass="btn btn-primary btn-block" OnClick="btnAdd_Click" />
                                        </div>
                                    </div>
                                    <div class="row bspace form-group" id="FirmEntry" runat="server" visible="false">
                                        <table class="table table-hover mb-0">
                                            <thead>
                                                <tr>
                                                    <th>SrNo</th>
                                                    <th>Species</th>
                                                    <th>Breed</th>
                                                    <th>CountOfAnimal</th>
                                                    <th>ACTION</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <asp:Repeater ID="RepeaterPatientVisit" runat="server">
                                                    <ItemTemplate>
                                                        <tr>
                                                            <td>
                                                                <asp:Label ID="lblSrNo" Text='<%# Eval("SrNo") %>' runat="server"></asp:Label></td>

                                                            <td><%# Eval("Species") %></td>
                                                            <td class="text-bold-500"><%# Eval("Breed") %></td>
                                                            <td><%# Eval("CountOfAnimal") %></td>
                                                            <td>
                                                                <asp:Label ID="lblPatientEntryID" Text='<%#Eval("PatientEntryID") %>' runat="server" Visible="false"></asp:Label>
                                                                <asp:Label ID="lblSpeciesTypeID" Text='<%#Eval("SpeciesTypeID") %>' runat="server" Visible="false"></asp:Label>
                                                                <asp:Label ID="lblBreedID" Text='<%#Eval("BreedID") %>' runat="server" Visible="false"></asp:Label>
                                                                <asp:Label ID="lblStat" Text='<%#Eval("Stat") %>' runat="server" Visible="false"></asp:Label>
                                                                <div class="dropdown">
                                                                    <a class="btn btn-link font-24 p-0 line-height-1 no-arrow dropdown-toggle" href="#" role="button" data-toggle="dropdown">
                                                                        <i class="dw dw-more"></i>
                                                                    </a>
                                                                    <div class="dropdown-menu dropdown-menu-right dropdown-menu-icon-list">
                                                                        <asp:Button CssClass="dropdown-item" runat="server" Text="View" ID="View" AutoPostBack="true" CommandArgument='<%#Eval("SrNo") %>' OnClick="View_Click"></asp:Button>
                                                                        <asp:Button CssClass="dropdown-item" runat="server" Text="Delete" ID="btnDelete" AutoPostBack="true" CommandArgument='<%#Eval("SrNo") %>' OnClick="btnDelete_Click"></asp:Button>
                                                                    </div>
                                                                </div>
                                                            </td>
                                                        </tr>
                                                    </ItemTemplate>
                                                </asp:Repeater>
                                            </tbody>
                                        </table>
                                        <asp:Label ID="lblPatientEntryID" runat="server" Visible="false"></asp:Label>
                                    </div>
                                </div>
                            </div>
                            <div class="row bspace form-group">
                                <div class="col-md-4">
                                <div class="checkbox-container">
                                    <label class="label">Department </label>
                                    <asp:CheckBoxList ID="ChkDepartment" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ChkDepartment_SelectedIndexChanged" AppendDataBoundItems="true" CssClass="form-group" RepeatColumns="1" Font-Size="Small">
                                    </asp:CheckBoxList>
                                </div>
                                    </div>
                                <div class="col-md-4">
                                    <label class="label">Doctor Name</label>
                                    <asp:CheckBoxList ID="ddlDoctor" runat="server" CssClass="form-group" AppendDataBoundItems="true" RepeatColumns="1" Font-Size="Small">
                                        <%--    <asp:ListItem Text="Select" Value="0" Selected="True"></asp:ListItem>--%>
                                    </asp:CheckBoxList>
                                </div>
                                <div class="col-md-4">
                                    <label class="label">Complaint </label>
                                    <asp:TextBox ID="txtComplaint" runat="server" CssClass="form-control" TextMode="MultiLine" placeholder="Complaint" required AutoComplete="off"></asp:TextBox>
                                </div>
                            </div>
                            <div class="row bspace form-group">
                                <div class="col-md-6">
                                    <label class="label">Remarks </label>
                                    <asp:TextBox ID="txtRemarks" runat="server" CssClass="form-control" TextMode="MultiLine" placeholder="Remarks" AutoComplete="off"></asp:TextBox>
                                </div>
                                <div class="col-md-6">
                                    <label class="label">Notes </label>
                                    <asp:TextBox ID="txtAdminNote" runat="server" CssClass="form-control" TextMode="MultiLine" placeholder="Notes" AutoComplete="off"></asp:TextBox>
                                </div>
                            </div>
                            <div class="row bspace">
                                <div class="col-md-8">
                                    <label class="label">Upload Image</label>
                                    <%--  </div>
                                <div class="col-md-6">--%>
                                    <%--   <div class="form-file">--%>
                                    <asp:FileUpload ID="ImageUpload" runat="server" CssClass="form-control"></asp:FileUpload>

                                </div>
                                <div class="col-md-4">
                                    <asp:Button ID="btnImageUpload" runat="server" Text="Upload" CssClass="btn btn-primary" OnClick="btnImageUpload_Click" CausesValidation="false" UseSubmitBehavior="false" />
                                </div>
                            </div>
                            <div class="row bspace">
                                <asp:GridView ID="GridPatientImages" runat="server" AutoGenerateColumns="False" CssClass="table table-responsive" OnRowDeleting="GridPatientImages_RowDeleting">
                                    <Columns>
                                        <asp:BoundField DataField="SrNo" HeaderText="SrNo" />
                                        <asp:BoundField DataField="ImageID" HeaderText="ImageID" SortExpression="ImageID" HeaderStyle-CssClass="hideGridColumn" ItemStyle-CssClass="hideGridColumn" />
                                        <asp:BoundField DataField="PatientID" HeaderText="PatientID" SortExpression="PatientID" HeaderStyle-CssClass="hideGridColumn" ItemStyle-CssClass="hideGridColumn" />
                                        <asp:BoundField DataField="ImageName" HeaderText="ImageName" SortExpression="ImageName" HeaderStyle-CssClass="hideGridColumn" ItemStyle-CssClass="hideGridColumn" />
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:Image ID="PImage" runat="server" ImageUrl='<%# Eval("ImgPath") %>' Width="80px" Height="80px" CssClass="zoom" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:CommandField ShowDeleteButton="true" />
                                    </Columns>
                                </asp:GridView>
                            </div>
                            <div class="row bspace form-group">
                                <div class="col-md-6">
                                    <label class="label">Charges</label>
                                    <asp:TextBox ID="txtCharges" runat="server" CssClass="form-control" placeholder="Charges" AutoComplete="off"></asp:TextBox>
                                </div>
                                <div class="col-md-6">
                                    <label class="label">Total Bill</label>
                                    <asp:TextBox ID="txtTotalBill" runat="server" CssClass="form-control" placeholder="Total Bill" AutoComplete="off"></asp:TextBox>
                                </div>
                            </div>
                            <div class="row form-group">
                                <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>
                                <asp:Label ID="lblID" runat="server" Visible="false"></asp:Label>
                                <asp:Label ID="lblSrNo" runat="server" Visible="false"></asp:Label>
                                <asp:Label ID="lblUserID" runat="server" Visible="false"></asp:Label>
                                <asp:Label ID="lblOwnerID" runat="server" Visible="false"></asp:Label>
                                <asp:Label ID="lblMsg" runat="server" ForeColor="Green"></asp:Label>
                                <asp:Label runat="server" ID="lblImageID" Visible="false"></asp:Label>
                            </div>
                            <div class="row bspace">
                                <div class="col-md-4">
                                    <asp:Button ID="btnSave" runat="server" Text="Save" CssClass="btn btn-primary btn-block" OnClick="btnSave_Click" />
                                </div>
                                <div class="col-md-4">
                                    <asp:Button ID="btnAddPatient" runat="server" Text="Add Patient" CssClass="btn btn-primary btn-block" CausesValidation="false" UseSubmitBehavior="false" OnClick="btnAddPatient_Click" />
                                </div>
                                <%--   <div class="col-md-4">
                                    <button type="button" class="btn btn-primary btn-block" data-toggle="modal" data-target="#exampleModalCenter">Show</button>
                                </div>--%>
                                <div class="col-md-4">
                                    <asp:Button ID="btnReset" runat="server" Text="Reset" CssClass="btn btn-primary btn-block" OnClick="btnReset_Click" UseSubmitBehavior="false" CausesValidation="false" />
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="btnImageUpload" />
        </Triggers>
    </asp:UpdatePanel>

    <script type="text/javascript">
        function MutExChkList(chk) {
            var chkList = chk.parentNode.parentNode.parentNode;
            var chks = chkList.getElementsByTagName("input");
            for (var i = 0; i < chks.length; i++) {
                if (chks[i] != chk && chk.checked) {
                    chks[i].checked = false;
                }
            }
        }
    </script>

</asp:Content>

