Tuesday, June 16, 2015

Grid Checkbox checked values passing to controller



 $("#btnSubmitRetation").on("click", function (e) {      
        var datatype = [];
      //  console.log($(".row-checkbox").length);
      //  console.log($(".row-checkbox:checked").length);
        $(".row-checkbox").each(function (i) {

            var id = $(this).attr("id");
            var defaultValue = "false";
            if ($(this).is(":checked")) {
                defaultValue = "true";
            }          
            dataSet = {
                "key": id,
                "value": defaultValue
            }
            datatype.push(dataSet);

        });


        $.ajax({
            url: '@Url.Action("SaveRecordsRetention", "RecordsRetention")',          
            type: 'POST',
            data: "jsonOfLog=" + JSON.stringify(datatype),
            dataType: 'text',
            success: function (result) {            
            }
        });

Controller:

 [HttpPost]
        public ActionResult SaveRecordsRetention(string jsonOfLog)
        {
            //  var convertedvalue = Newtonsoft.Json.JsonConvert.DeserializeObject>(data);
            try
            {
                if (jsonOfLog != null)
                {
                    List> values = JsonConvert.DeserializeObject>>(jsonOfLog);

                   


                }

Tuesday, September 23, 2014

jQuery selectors select 2nd cell of 2nd row of 2nd table


 

     
       
         X
         **some text that changes**
         **ssss**
     
 

Jquery:

$(function(){
   var text = $("table:eq(1) tr:eq(1) td:eq(2)").text();
   alert(text);
});

Monday, August 25, 2014

Save Error Log or Exception Log in text file in C#

Add a class file name it as ErrorLog
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Text;
using System.IO;

namespace Save_Error_Log_or_Exception
{
    public class ErrorLog
    {
        public bool WriteErrorLog(string LogMessage)
        {
            bool Status = false;
            string LogDirectory = ConfigurationManager.AppSettings["LogDirectory"].ToString();

            DateTime CurrentDateTime = DateTime.Now;
            string CurrentDateTimeString = CurrentDateTime.ToString();
            CheckCreateLogDirectory(LogDirectory);
            string logLine = BuildLogLine(CurrentDateTime, LogMessage);
            LogDirectory = (LogDirectory + "Log_" + LogFileName(DateTime.Now) + ".txt");

            lock (typeof(ErrorLog))
            {
                StreamWriter oStreamWriter = null;
               try
               {
                   oStreamWriter = new StreamWriter(LogDirectory, true);
                    oStreamWriter.WriteLine(logLine);
                    Status = true;
                }
               catch
              {

               }
                finally
                {
                    if (oStreamWriter != null)
                    {
                        oStreamWriter.Close();
                    }
                }
            }
            return Status;
        }

        private bool CheckCreateLogDirectory(string LogPath)
        {
            bool loggingDirectoryExists = false;
            DirectoryInfo oDirectoryInfo = new DirectoryInfo(LogPath);
            if (oDirectoryInfo.Exists)
            {
                loggingDirectoryExists = true;
            }
            else
            {
                try
                {
                    Directory.CreateDirectory(LogPath);
                    loggingDirectoryExists = true;
                }
                catch
                {
                    // Logging failure
                }
            }
            return loggingDirectoryExists;
        }

        private string BuildLogLine(DateTime CurrentDateTime, string LogMessage)
        {
            StringBuilder loglineStringBuilder = new StringBuilder();
            loglineStringBuilder.Append(LogFileEntryDateTime(CurrentDateTime));
            loglineStringBuilder.Append(" \t");
            loglineStringBuilder.Append(LogMessage);
            return loglineStringBuilder.ToString();
        }


        public string LogFileEntryDateTime(DateTime CurrentDateTime)
        {
            return CurrentDateTime.ToString("dd-MM-yyyy HH:mm:ss");
        }


        private string LogFileName(DateTime CurrentDateTime)
        {
            return CurrentDateTime.ToString("dd_MM_yyyy HH:mm:ss");
        }
    }
}
------------
Page_Load:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Save_Error_Log_or_Exception
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            ErrorLog oErrorLog = new ErrorLog();
            try
            {
                int i,j,k;

                i = 100;
                j = 0;
                k =i/j;

               

            }
            catch (Exception ex)
            {
                oErrorLog.WriteErrorLog(ex.ToString());
               
               
            }
        }
    }
}

Thursday, July 10, 2014

How to Find Grid Rows Length In Jquery





var rowCount = $('#grdpayments').find('tr').length;

Wednesday, February 12, 2014

reverse of a string in c#.net

senario: 1


string res = "";
            string sa = "";
            string s = "hyd is good";

            for (int i = s.Length - 1; i = 0; i--)
            {

                res = res + s[i];
            }

Output:  "doog si dyh"







senario: 2







            string[] arr = s.Split(' ');

            for (int i = arr.Length - 1; i >= 0; i--)
            {
                sa += arr[i] + " ";
            }

Output:  "good ishyd"





senario: 3

  string[] arr = s.Split(' ');

            for (int i = arr.Length - 1; i >= 0; i--)
            {
                sa += arr[i] + " ";
            }

            for (int i = 0; i < arr.Length; i++)
            {
                string ss = arr[i];

                for (int j = ss.Length - 1; j >= 0; j--)
                {
                    res += ss[j];
                }
                res += " ";
            }

Output:  "dyh si doog"


 senario: 4


  public static string RecursivelyReverseString(string s)
        {
            if (s.Length > 0)
                return s[s.Length - 1] + RecursivelyReverseString(s.Substring(0, s.Length - 1));
            else
                return s;
        }

Output:  "doog si dyh"

Thursday, January 23, 2014

Action Filters in MVC

 1)OutputCache  Filters in MVC:

Controler:

[OutputCache(Duration = 10)]
        public ActionResult test()
        {
            ViewBag.Date = DateTime.Now.ToString("T");
           
            return View();
        }

View:
@{
    ViewBag.Title = "test";
    @ViewBag.Date;
}

test