i have a problem to

2 posts, 0 answers
  1. Dhaval
    Dhaval avatar
    17 posts
    Member since:
    Feb 2011

    Posted 08 Jul 2011 Link to this post

    <%@ Page Title="Diagnosis Code Maintanance " Language="C#" MasterPageFile="~/MasterPages/Site.master"
        AutoEventWireup="true" CodeFile="Diagnosis.aspx.cs" Inherits="Codes_Diagnosis"
        EnableTheming="true" Theme="DefaultTheme" %>
     
    <%@ Register TagPrefix="MyCtrl" Namespace="CBR.Business" Assembly="CBR.Business" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
        <script language="javascript" type="text/javascript">
            function clearData() {
                document.getElementById('<%=txtcode.ClientID%>').value = '';
                document.getElementById('<%=txtDescription.ClientID%>').value = '';
                document.getElementById('<%=hdnPK.ClientID%>').value = '';
                document.getElementById('<%=chkUserEntered.ClientID%>').checked = false;
                document.getElementById('<%=chkActive.ClientID%>').checked = false;
                document.getElementById('<%=txtcode.ClientID%>').disabled = false;
                document.getElementById('<%=txtcode.ClientID%>').focus();
                return true;
            }
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Skin="Outlook" runat="server" />
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
            <table width="100%" cellpadding="0px" cellspacing="0px" border="0px">
                <tr>
                    <td width="100%">
                        <!-- Top Pane Start -->
                        <div class="BillReviewContainer">
                            <div class="PanelTitle">
                                <div class="PanelTitleIcon">
                                    Diagnosis</div>
                            </div>
                            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="BillReviewTab">
                                <tr>
                                    <td width="15%" align="right">
                                        <asp:Label ID="lblCode" SkinID="Required" runat="server" Text="Code:"></asp:Label>
                                    </td>
                                    <td width="85%">
                                        <asp:TextBox ID="txtcode" MaxLength="6" SkinID="Small" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvCode" ValidationGroup="Submit" runat="server"
                                            ControlToValidate="txtcode"  SetFocusOnError="true" ErrorMessage="Code is mandatory" Display="None"></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="revCode" ValidationExpression="(^[+]?\w*\.?\d*[1-9]+\d*$)|(^[+]?[1-9]+\d*\.\d*$)"
                                            runat="server" ValidationGroup="Submit" Display="None" ControlToValidate="txtcode"  SetFocusOnError="true"
                                            ErrorMessage="Only numeric or alphabates are allowed.i.e. e1.23,0.12,121"></asp:RegularExpressionValidator>
                                        <asp:HiddenField ID="hdnPK" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" valign="top">
                                        <asp:Label ID="lblDescription" SkinID="Required" runat="server" Text="Description:"></asp:Label>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtDescription" TextMode="MultiLine" SkinID="Multiline" runat="server"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvDesc" ValidationGroup="Submit" runat="server"
                                            ControlToValidate="txtDescription" SetFocusOnError="true" ErrorMessage="Description is mandatory" Display="None"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td valign="middle">
                                        <asp:CheckBox ID="chkUserEntered" runat="server" Text=" User entered" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td valign="middle">
                                        <asp:CheckBox ID="chkActive" runat="server" Text=" Active" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:Button ID="btnSave" OnClick="btnSave_Click" SkinID="InnerSaveButton" ValidationGroup="Submit"
                                            runat="server" />
                                        <asp:Button ID="btnCancel" runat="server" SkinID="InnerClearButton" OnClientClick="return clearData();" />
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <asp:Label ID="lblMsg" ForeColor="Red" runat="server"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <asp:ValidationSummary ID="vs" HeaderText="Please enter following fields" DisplayMode="BulletList"
                                            runat="server" ValidationGroup="Submit" CssClass="msg" ForeColor="Red" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <!-- Top Pane Ends -->
                        <!-- Second Pane Start -->
                        <div class="PrevsBillsContainer">
                            <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Width="100%">
                                <Items>
                                    <telerik:RadPanelItem Text="Diagnosis" CssClass="PrevsBillsHeader" ImageUrl="~/App_Themes/DefaultTheme/img/previous_bill_icon.png">
                                        <ContentTemplate>
                                            <telerik:RadGrid ID="grdDiagnosis" OnInit="grdDiagnosis_Init" OnItemDataBound="grdDiagnosis_DataBound"
                                                runat="server" AllowAutomaticDeletes="false" OnPreRender="grdDiagnosis_PreRender"
                                                SkinID="ContentGrid" OnItemCommand="grdDiagnosis_ItemCommand">
                                                <MasterTableView TableLayout="Fixed" AllowMultiColumnSorting="true" DataKeyNames="di_int_pk">
                                                    <SortExpressions>
                                                        <telerik:GridSortExpression FieldName="di_DiagCode" SortOrder="Ascending" />
                                                    </SortExpressions>
                                                    <Columns>
                                                        <telerik:GridBoundColumn HeaderText="Diagnosis Code" UniqueName="Code" AutoPostBackOnFilter="true"
                                                            ShowFilterIcon="false" CurrentFilterFunction="StartsWith" DataField="di_DiagCode"
                                                            HeaderStyle-Width="14%" ItemStyle-Width="14%">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn HeaderText="Description" AutoPostBackOnFilter="true" ShowFilterIcon="false"
                                                            UniqueName="Description" CurrentFilterFunction="StartsWith" DataField="di_DiagDescription">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridCheckBoxColumn DataField="di_User" FilterListOptions="VaryByDataType"
                                                            HeaderText="User entered" CurrentFilterFunction="NoFilter" UniqueName="Userentered"
                                                            HeaderStyle-Width="10%" ItemStyle-Width="10%">
                                                        </telerik:GridCheckBoxColumn>
                                                        <telerik:GridCheckBoxColumn DataField="di_Active" FilterListOptions="VaryByDataType"
                                                            HeaderText="Active" CurrentFilterFunction="NoFilter" UniqueName="Active" HeaderStyle-Width="6%"
                                                            ItemStyle-Width="6%"  Resizable="false">
                                                        </telerik:GridCheckBoxColumn>
                                                        <telerik:GridTemplateColumn AllowFiltering="false" HeaderStyle-Width="40px" ItemStyle-Width="40px"  Resizable="false">
                                                            <ItemStyle HorizontalAlign="Center" />
                                                            <ItemTemplate>
                                                                <%-- <asp:LinkButton ID="LinkButton1" runat="server" Text="Edit" CommandName="Show"></asp:LinkButton>--%>
                                                                <asp:ImageButton ID="ImgEdit" runat="server" AlternateText="Edit" CommandName="Show"
                                                                    ImageUrl="~/Images/edit_icon.png" />
                                                                <asp:HiddenField ID="hdnID" runat="server" Value='<%# Eval("di_int_pk") %>' />
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                        <telerik:GridButtonColumn ConfirmText="Do you want to delete this entry?" ConfirmDialogType="RadWindow"
                                                            ConfirmTitle="Delete" CommandName="Delete" Text="Delete" ButtonType="ImageButton"
                                                            ImageUrl="~/Images/delete_icon.png" UniqueName="DeleteColumn" HeaderStyle-Width="40px"
                                                            ItemStyle-Width="40px" Resizable="false">
                                                            <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                                                        </telerik:GridButtonColumn>
                                                    </Columns>
                                                </MasterTableView>
                                            </telerik:RadGrid>
                                        </ContentTemplate>
                                    </telerik:RadPanelItem>
                                </Items>
                                <CollapseAnimation Duration="100" Type="None" />
                                <ExpandAnimation Duration="100" Type="None" />
                            </telerik:RadPanelBar>
                        </div>
                        <!-- Second Pane Ends -->
                    </td>
                </tr>
            </table>
        </telerik:RadAjaxPanel>
    </asp:Content>


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Collections;
    using System.Web.UI.WebControls;
    using CBR.Business;
    using CBR.DataModel;
    using System.Data;
    using Telerik.Web.UI;

    public partial class Codes_Diagnosis : System.Web.UI.Page
    {

        #region Page Events

        /// <summary>
        /// Page Load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                txtcode.Focus();
                Bind();
                if (RadPanelBar1.Items.Count > 0)
                    RadPanelBar1.Items[0].Expanded = true;
            }
        }

        #endregion

        #region Functions

        /// <summary>
        /// Bind grid
        /// </summary>
        private void Bind()
        {
            List<Diagnostic> objDiagnostic = CodesManager.GetAllDiagnosis();
            //grdDiagnosis.VirtualItemCount = objServices.Count;
            grdDiagnosis.DataSource = objDiagnostic;
            grdDiagnosis.DataBind();

        }

        /// <summary>
        /// Clear all fields
        /// </summary>
        private void ClearAll()
        {
            txtcode.Text = "";
            txtDescription.Text = "";
            chkUserEntered.Checked = false;
            chkActive.Checked = false;
            txtcode.Enabled = true;
            txtcode.Focus();
        }

        #endregion

        #region Grid events

        /// <summary>
        /// Grid Prerender event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdDiagnosis_PreRender(object sender, System.EventArgs e)
        {
            Bind();
        }

        /// <summary>
        /// Actions to perform for different commands
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void grdDiagnosis_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
            {

            }
            else if (e.CommandName == RadGrid.DeleteCommandName)
            {
                lblMsg.Text = "";
                GridDataItem editedItem = (GridDataItem)e.Item;
                int ID = Convert.ToInt32(((HiddenField)editedItem.FindControl("hdnID")).Value);
                CodesManager.DeleteDiagnosticByID(ID);
                ClearAll();
                Bind();
            }

            else if (e.CommandName == "Show")
            {
                lblMsg.Text = "";
                GridDataItem selectedItem = (GridDataItem)e.Item;
                Hashtable selectedItemValues = new Hashtable();
                selectedItem.ExtractValues(selectedItemValues);
                if (!Convert.ToBoolean(selectedItemValues["di_User"]))
                {
                    txtcode.Enabled = false;
                    txtDescription.Focus();
                }
                else
                {
                    txtcode.Focus();
                }
                txtcode.Text = selectedItemValues["di_DiagCode"].ToString().Trim();
                txtDescription.Text = selectedItemValues["di_DiagDescription"].ToString().Trim();
                chkUserEntered.Checked = Convert.ToBoolean(selectedItemValues["di_User"]);
                chkActive.Checked = Convert.ToBoolean(selectedItemValues["di_Active"]);
                hdnPK.Value = ((HiddenField)selectedItem.FindControl("hdnID")).Value;

            }
        }

        /// <summary>
        /// Hide Top command row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdDiagnosis_DataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridCommandItem)
            {
                GridCommandItem cmditm = (GridCommandItem)e.Item;
                cmditm.FindControl("RefreshButton").Visible = false;//hide the text
                cmditm.FindControl("RebindGridButton").Visible = false;//hide the image
                e.Item.FindControl("InitInsertButton").Visible = false;//hide Add text
                e.Item.FindControl("AddNewRecordButton").Visible = false;//hide add button
                e.Item.Visible = false; // hide Top command row
            }
        }

        /// <summary>
        /// Init event to hide filter options from checkbox field filter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdDiagnosis_Init(object sender, System.EventArgs e)
        {
            GridFilterMenu menu = grdDiagnosis.FilterMenu;
            int i = 0;

            while (i < menu.Items.Count)
            {
                if (menu.Items[i].Text == "NoFilter" || menu.Items[i].Text == "EqualTo")
                {
                    i++;
                }
                else
                {
                    menu.Items.RemoveAt(i);
                }
            }

        }

        #endregion

        # region Events

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Diagnostic objDiagnostic = new Diagnostic();
            objDiagnostic.di_DiagCode = txtcode.Text;
            objDiagnostic.di_DiagDescription = txtDescription.Text;
            objDiagnostic.di_User = chkUserEntered.Checked;
            objDiagnostic.di_Active = chkActive.Checked;
            lblMsg.Text = "";
            if (hdnPK.Value == "")
            { // Insert
                if (CodesManager.GetDiagnosisByCode(txtcode.Text).Count > 0)
                {

                    lblMsg.Text = "Diagnosis Code already exists";
                    return;
                }
                else
                {
                    objDiagnostic.di_Type = "";
                    objDiagnostic.di_MajorDiagGrouping = "";
                    objDiagnostic.di_Catastrophic = false;
                    CodesManager.InsertDiagnostic(objDiagnostic);
                    lblMsg.Text = "Diagnosis Code added successfully";
                    txtcode.Enabled = true;
                }
            }
            else
            // Update
            {
                objDiagnostic.di_int_pk = Convert.ToInt32(hdnPK.Value);
                CodesManager.UpdateDiagnostic(objDiagnostic);
                //btnSave.Text = "Insert";
            }
            hdnPK.Value = "";
            ClearAll();
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            hdnPK.Value = "";
            ClearAll();
            lblMsg.Text = "";

        }

        #endregion

    }


    #region Diagnosis
            public static List<Diagnostic> GetAllDiagnosis()
            {


                List<Diagnostic> objDiagnostic = new List<Diagnostic>();

                try
                {
                    objDiagnostic = CodesData.GetAllDiagnosis();
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("Business-CodesManager-GetAllDiagnosis").Error(ex);
                    throw ex;
                }

                return objDiagnostic;
            }

            public static List<Diagnostic> GetDiagnosisByCode(string Code)
            {
                List<Diagnostic> objDiagnostic = new List<Diagnostic>();

                try
                {
                    objDiagnostic = CodesData.GetDiagnosisByCode(Code);
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("Business-CodesManager-GetDiagnosisByCode").Error(ex);
                    throw ex;
                }

                return objDiagnostic;
            }

            public static void InsertDiagnostic(Diagnostic objDiagnostic)
            {
                try
                {
                    CodesData.AddDiagnosis(objDiagnostic);
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("Business-CodesManager-InsertDiagnostic").Error(ex);
                    throw ex;
                }
            }

            public static void UpdateDiagnostic(Diagnostic objDiagnostic)
            {
                try
                {
                    CodesData.UpdateDiagnosisByID(objDiagnostic);
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("Business-CodesManager-UpdateDiagnostic").Error(ex);
                    throw ex;
                }
            }

            public static void DeleteDiagnosticByID(Int32 ID)
            {
                try
                {
                    CodesData.DeleteDiagnosisByID(ID);
                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("Business-CodesManager-DeleteDiagnosticByID").Error(ex);
                    throw ex;
                }
            }

            #endregion


     public static Diagnostic AddDiagnosis(Diagnostic objDiagnosis)
            {
                using (CBREntities CBRContext = new CBREntities())
                {
                    CBRContext.Connection.Open();
                    DbTransaction objTrans = CBRContext.Connection.BeginTransaction();

                    try
                    {

                        CBRContext.AddToDiagnostics(objDiagnosis);
                        CBRContext.SaveChanges();
                        objTrans.Commit();

                    }
                    catch (Exception ex)
                    {
                        LogManager.GetLogger("DataAccess-CodesDAL-AddDiagnosis").Error(ex);
                        objTrans.Rollback();
                        throw ex;
                    }
                }
                return objDiagnosis;
            }

            public static List<Diagnostic> GetDiagnosisByCode(string Code)
            {
                using (CBREntities CBRContext = new CBREntities())
                {
                    CBRContext.Connection.Open();
                    DbTransaction objTrans = CBRContext.Connection.BeginTransaction();
                    try
                    {
                        List<Diagnostic> resultList =
                        (from ServieList in CBRContext.Diagnostics
                         where ServieList.di_DiagCode == Code
                         select ServieList).ToList();
                        objTrans.Commit();
                        return resultList;

                    }
                    catch (Exception ex)
                    {
                        objTrans.Rollback();
                        LogManager.GetLogger("DataAccess-CodesDAL-GetDiagnosisByCode").Error(ex);
                        throw ex;
                    }

                }
            }

            public static List<Diagnostic> GetAllDiagnosis()
            {
                CBREntities objCBREntities = new CBREntities();
                objCBREntities.Connection.Open();
                List<Diagnostic> objStateInfo = new List<Diagnostic>();
                DbTransaction objTrans = objCBREntities.Connection.BeginTransaction();

                try
                {
                    objStateInfo = objCBREntities.Diagnostics.Select(row => row).ToList();
                    objTrans.Commit();

                }
                catch (Exception ex)
                {
                    LogManager.GetLogger("DataAccess-CodesDAL-GetAllDiagnosis").Error(ex);
                    objTrans.Rollback();
                    throw ex;
                }

                return objStateInfo;
            }

            public static void UpdateDiagnosis(Diagnostic objDiagnosis)
            {
                EntityKey key = null;
                object original = null;

                using (CBREntities CBRContext = new CBREntities())
                {
                    CBRContext.Connection.Open();
                    DbTransaction objTrans = CBRContext.Connection.BeginTransaction();

                    try
                    {
                        key = CBRContext.CreateEntityKey("Diagnostics", objDiagnosis);
                        if (CBRContext.TryGetObjectByKey(key, out original))
                        {
                            CBRContext.ApplyCurrentValues(key.EntitySetName, objDiagnosis);
                        }
                        CBRContext.SaveChanges();
                        objTrans.Commit();

                    }
                    catch (Exception ex)
                    {

                        objTrans.Rollback();
                        LogManager.GetLogger("DataAccess-CodesDAL-UpdateDiagnosis").Error(ex);
                        throw ex;
                    }
                }
            }

            public static void UpdateDiagnosisByID(Diagnostic objDiagnosis)
            {
                using (CBREntities CBRContext = new CBREntities())
                {
                    CBRContext.Connection.Open();
                    DbTransaction objTrans = CBRContext.Connection.BeginTransaction();

                    Diagnostic resultList =
                        (from ServieList in CBRContext.Diagnostics
                         where ServieList.di_int_pk == objDiagnosis.di_int_pk
                         select ServieList).FirstOrDefault();
                    resultList.di_DiagCode = objDiagnosis.di_DiagCode;
                    resultList.di_DiagDescription = objDiagnosis.di_DiagDescription;
                    resultList.di_Active = objDiagnosis.di_Active;
                    resultList.di_User = objDiagnosis.di_User;
                    try
                    {
                        CBRContext.SaveChanges();
                        objTrans.Commit();

                    }
                    catch (Exception ex)
                    {
                        objTrans.Rollback();

                        LogManager.GetLogger("DataAccess-CodesDAL-UpdateDiagnosisByID").Error(ex);
                        throw ex;
                    }
                }

            }

            public static void DeleteDiagnosisByID(Int32 ID)
            {
                using (CBREntities CBRContext = new CBREntities())
                {
                    CBRContext.Connection.Open();
                    DbTransaction objTrans = CBRContext.Connection.BeginTransaction();

                    Diagnostic resultList =
                        (from UserList in CBRContext.Diagnostics
                         where UserList.di_int_pk == ID
                         select UserList).FirstOrDefault();

                    CBRContext.DeleteObject(resultList);

                    try
                    {
                        CBRContext.SaveChanges();
                        objTrans.Commit();

                    }
                    catch (Exception ex)
                    {
                        objTrans.Rollback();

                        LogManager.GetLogger("DataAccess-CodesDAL-DeleteDiagnosisByID").Error(ex);
                        throw ex;
                    }
                }
            }

            #endregion
  2. Bhanu
    Bhanu avatar
    2 posts
    Member since:
    Mar 2011

    Posted 08 Jul 2011 Link to this post

    What exactly the problem you are facing?
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top