Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday 23 December 2014

Commit Pop-Up in JavaScript


 HttpContext context = HttpContext.Current;
                            context.Response.Write("<script type='text/javascript'>alert('Access Denied.This is not your request'); window.frameElement.commitPopup();</script>");
                            context.Response.Flush();
                            context.Response.End();

Get-Set All the Controls in the Form


DataTable dtCtrl = new DataTable();
            dtCtrl.Columns.Add("ctrlID");
            dtCtrl.Columns.Add("ctrlValue");

            ArrayList controlList = new ArrayList();
            GetControls(Page.Controls, controlList);
            foreach (string str in controlList)
            {
                if (this.Page.FindControl(str) != null)
                {
                    Control ctrl = Page.FindControl(str);
                    if (ctrl.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                    {
                        TextBox txtBox = ctrl as TextBox;
                        if (txtBox.ReadOnly == true && txtBox.Visible == true)
                        {
                            DataRow dRow = dtCtrl.NewRow();
                            dRow["ctrlID"] = txtBox.UniqueID;
                            dRow["ctrlValue"] = Request[txtBox.UniqueID];
                            dtCtrl.Rows.Add(dRow);
                        }
                    }
                }
            }
            foreach (DataRow drow in dtCtrl.Rows)
            {
                (Page.FindControl(drow["ctrlID"].ToString()) as TextBox).Text = drow["ctrlValue"].ToString();
            }

PostBackTrigger in ASP.Net


<asp:Panel ID="panel_Buttons" runat="server">
                <div class="btnslist">
                <asp:UpdatePanel ID="UpdatePanel_Buttons" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnSave" runat="server" CssClass="btns" OnClick="btnSave_Click" Text="Save as Draft" Visible="false"/>
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="btnSave" />
                </Triggers>
                </asp:UpdatePanel>
                </div>
            </asp:Panel>



SPSite,SPWeb as Strings


sRootSite = SPContext.Current.Site.Url;
sSiteUrl = SPContext.Current.Web.Url;

Operations On Date Control When they Selected

function CheckDate(sender, args) {

            var selectedDate = new Date();

            selectedDate = sender._selectedDate;

            var todayDate = new Date();

            var one_day = 1000 * 60 * 60 * 24;


            if (selectedDate.getDateOnly() > todayDate.getDateOnly()) {

                sender._selectedDate = todayDate;

                sender._textbox.set_Value(sender._selectedDate.format(sender._format));

                alert("Sorry, Future dates are not allowed");
                sender._textbox.set_Value("");
            }
            else {
                var NoOfDays = Math.ceil((todayDate.getTime() - selectedDate.getTime()) / (one_day));
                if (NoOfDays > 90) {
                    //alert("Sorry, Voucher can not be old than 90 days");
                    //sender._textbox.set_Value("");
                }
            }

        }

Allow Only Numbers in TextBox

<asp:TextBox ID="txtFareAmount_Travel_TEB" runat="server" MaxLength="12" CssClass="inptxt"
                                                            onBlur="CalculateGrandTotal_TEB(this.id)" onKeyup="ValidateDeciPointRevCalc(this.id)" ></asp:TextBox>
                                                            <asp:FilteredTextBoxExtender ID="ftbEx_txtFareAmount_Travel_TEB" runat="server" TargetControlID="txtFareAmount_Travel_TEB"
                                                                            FilterType="Custom, Numbers" ValidChars="."></asp:FilteredTextBoxExtender>
                         

Calculate Amount In Words

function CalculateAmountInWords_ER() {
            var txtAmount_ER = document.getElementById('<%=txtAmount_ER.ClientID%>');
            var txtAmountInWords_ER = document.getElementById('<%=txtAmountInWords_ER.ClientID%>');

            var Round_Amount = Math.round(txtAmount_ER.value * 100) / 100;
            if (trim(txtAmount_ER.value, " ") != "") {
                txtAmount_ER.value = Round_Amount.toFixed(2);
                ConvertToWords(Math.round(txtAmount_ER.value), txtAmount_ER.id, txtAmountInWords_ER.id);
            }
            else {
                txtAmount_ER.value = "";
                txtAmountInWords_ER.value = "";
            }
        }

 function ConvertToWords(s, ClientID_Number, ClientID_words) {
            var num = s;
            num = Math.floor(s);
            var obStr = new String(num);
            numReversed = obStr.split("");
            actnumber = numReversed.reverse();

            if (Number(num) >= 0) {
                //do nothing
            }
          
            else {
                alert('Please enter a valid number!');
                if (ClientID_Number != "") {
                    document.getElementById(ClientID_Number).value = "";
                }
                if (ClientID_words != "") {
                    document.getElementById(ClientID_words).value = "";
                }
                return false;
            }
            if (Number(num) == 0) {
                document.getElementById(ClientID_Number).value = "";
                document.getElementById(ClientID_words).value = "";
                return false;
            }
            if (actnumber.length > 9) {
                alert('the Number is too big to covertes');
                return false;
            }

            var iWords = ["Zero", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine"];
            var ePlace = ['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'];
            var tensPlace = ['dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety'];

            var iWordsLength = numReversed.length;
            var totalWords = "";
            var inWords = new Array();
            var finalWord = "";
            j = 0;
            for (i = 0; i < iWordsLength; i++) {
                switch (i) {
                    case 0:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        inWords[j] = inWords[j] + ' Only';
                        break;
                    case 1:
                        tens_complication(ClientID_words);
                        break;
                    case 2:
                        if (actnumber[i] == 0) {
                            inWords[j] = '';
                        }
                        else if (actnumber[i - 1] != 0 && actnumber[i - 2] != 0) {
                            inWords[j] = iWords[actnumber[i]] + ' Hundred and';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]] + ' Hundred';
                        }
                        break;
                    case 3:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        if (actnumber[i + 1] != 0 || actnumber[i] > 0) {
                            inWords[j] = inWords[j] + " Thousand";
                        }
                        break;
                    case 4:
                        tens_complication(ClientID_words);
                        break;
                    case 5:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        if (iWordsLength <= 7) {
                            inWords[j] = inWords[j] + " Lakh";
                        }
                        else {
                            if (actnumber[i] == 0 && actnumber[i + 1] != 0) {
                                inWords[j] = inWords[j] + " Lakh";
                            }
                            if (actnumber[i] != 0 && actnumber[i + 1] == 0) {
                                inWords[j] = inWords[j] + " Lakh";
                            }
                        }                      
                        break;
                    case 6:
                        tens_complication(ClientID_words);
                        break;
                    case 7:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        inWords[j] = inWords[j] + " Crore";
                        break;
                    case 8:
                        tens_complication(ClientID_words);
                        break;
                    default:
                        break;
                }
                j++;
            }

To Check Decimal Point Validation, calculate Amount in Grid control based on selected DropDown Value

<script language="javascript">
    
        function CalculateTotalsInGrid(id) {
            var txtControl = document.getElementById(id);
                var NumberEntered = txtControl.value;
                var count = 0;
                var LastIndexOfDot = 0;
                for (var i = 0; i < NumberEntered.length; i++) {
                    if (NumberEntered[i] == '.') {
                        count = count + 1;
                        if (count == 2) {
                            LastIndexOfDot = i;
                        }
                    }
                }
                if (LastIndexOfDot > 0) {
                    document.getElementById(id).value = NumberEntered.substring(0, LastIndexOfDot);
                }
                var totalDoll=0;
                var val1=1;
                if(efg != "INR")
                {                  
                    val1 = parseFloat(document.getElementById('<%=txtExchangerate_TEB.ClientID%>').value);
                }
                var gdv = document.getElementById('<%=gdvExpenseSummary_Travel_TEB.ClientID%>');
                for (var i = 1; i < gdv.rows.length; i++) {
                    var Curramnt =parseFloat(gdv.rows[i].cells[8].childNodes.item(0).value);
                    var date = gdv.rows[i].cells[1].childNodes.item(0).value;
                    var ModeOfTransport = gdv.rows[i].cells[4].childNodes.item(0).value;
                    if (trim(date, " ") != "" && trim(ModeOfTransport, " ") != "")
                    {
                        totalDoll+=Curramnt;
                        gdv.rows[i].cells[9].childNodes.item(0).value =parseFloat(val1 * Curramnt);
                        gdv.rows[i].cells[9].childNodes.item(0).focus();
                    }
                    else
                    {
                        if(date == "")
                        {
                        alert('Please Select Date at Sr.No'+i);
                        }
                        else if(ModeOfTransport == "")
                        {
                        alert('Please Select ModeOfTransport at Sr.No'+i);
                        }
                    }
                }

                var efg=document.getElementById('<%=ddlCurr_Travel_TEB.ClientID%>').value;
                if(efg != "INR")
                {
                var gdv2 = document.getElementById('<%=txtConveyExpenseDyn_Travel_TEB.ClientID%>');
                gdv2.value=parseFloat(totalDoll);
                }
        }


Get Correct Element ID based on fired Events

function ValidateIDofControlRevCalc(id) {
               
                var val2 = parseFloat(NumberEntered);
                var ansD;
                if(event.srcElement.id == "<%= txtMiscellaneousAmount_Travel_TEB.ClientID%>")
                {
                    ansD = document.getElementById('<%=txtMiscExpenseDyn_Travel_TEB.ClientID%>');
                }
               
            }

Get Selected row from GridView

function GetSelectedRow(lnk) {
            var row = lnk.parentNode.parentNode;
            var rowIndex = row.rowIndex - 1;

            var start = row.cells[5].getElementsByTagName("input")[0].value;
            var end= row.cells[6].getElementsByTagName("input")[0].value;

            alert(start);
            alert(end);

            var t1=0; var t2=-0;
            var _txt3=0;

            if (start.value != "")
            t1 = start.value;
            alert(t1);
           

            if (end.value != "")
             t2 = end.value;
               alert(t2);
      
           if(t2 >= t1)
            _txt3.value = parseInt(t1) - parseInt(t2);
            alert(_txt3.value)
}

Please provide your feedback in the comments section above. Please don't forget to follow.