Sunday, 25 September 2016

How to create multilingual application in C# ?

Firstly defined In global.asax.cs

 protected void Application_BeginRequest()
        {
            CultureInfo info = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString());
            info.DateTimeFormat.ShortDatePattern = "dd.MM.yyyy";
            System.Threading.Thread.CurrentThread.CurrentCulture = info;
        }


        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies["lang"];
            if (cookie != null && cookie.Value != null)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
            }
            else
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
            }
        }

In App_Global_ResourceFile folder


To create a resource file in this folder -:
default.
employee.resx (It's automatic in English language we represent string and value)

Emp  Employee

employee.bn.resx (bn means bengali language we represent string and value)

Emp Employee_bn

We represent View Pages



In LayOut Pages defined-

    <script type="text/javascript">
        function SetLanguage(obj) {
            debugger;
            $.ajax({
                cache: false,
                type: "GET",
                url: '/Home/SetCulture/?lang=' + obj,
                success: function (result) {
                    debugger;
                    window.location.reload();

                },
                error: function (result) {
                    alert("Error");
                }
            });
        }

    </script>

 public ActionResult SetCulture(string lang)
        {
            LanguageModel model = new LanguageModel();
            if (!String.IsNullOrEmpty(lang))
            {
                string culture = lang;
                CultureInfo ci = CultureInfo.GetCultureInfo(culture);
                Thread.CurrentThread.CurrentUICulture = ci;
                model.Culture = lang;
                Response.Cookies["lang"].Value = culture;
                Response.Cookies["lang"].Expires = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE).AddDays(30);
            }
            else
            {
                string culture = "en";
                CultureInfo ci = CultureInfo.GetCultureInfo(culture);
                Thread.CurrentThread.CurrentUICulture = ci;
                model.Culture = culture;
                Response.Cookies["lang"].Value = culture;
            }
            return Json(model, JsonRequestBehavior.AllowGet);

        }

<label>App_GlobalResources.employee.Emp</label>






Sunday, 10 July 2016

How to implementing jquery datepicker in bootstrap modal?

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title" id="myModalLabel">Modal title</h4>

            </div>
            <div class="modal-body">
                <div class="col-md-12">
                    <div class="row">
                        <label for="idTourDateDetails">Tour Start Date:</label>
                        <div class="form-group">
                            <div class="input-group">
                                <input type="text" name="idTourDateDetails" id="idTourDateDetails" readonly="readonly" class="form-control clsDatePicker"> <span class="input-group-addon"><i id="calIconTourDateDetails" class="glyphicon glyphicon-th"></i></span>

                            </div>
                        </div>Alt Field:
                        <input type="text" name="idTourDateDetailsHidden" id="idTourDateDetailsHidden">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

$('#idTourDateDetails').datepicker({
     dateFormat: 'dd-mm-yy',
     minDate: '+5d',
     changeMonth: true,
     changeYear: true,
     altField: "#idTourDateDetailsHidden",
     altFormat: "yy-mm-dd"
 });

// Since confModal is essentially a nested modal it's enforceFocus method
// must be no-op'd or the following error results
// "Uncaught RangeError: Maximum call stack size exceeded"
// But then when the nested modal is hidden we reset modal.enforceFocus
var enforceModalFocusFn = $.fn.modal.Constructor.prototype.enforceFocus;

$.fn.modal.Constructor.prototype.enforceFocus = function() {};

$confModal.on('hidden', function() {
    $.fn.modal.Constructor.prototype.enforceFo

Wednesday, 22 June 2016

How to multiple select list value in mvc without ctrl key?

Multiple select list value in asp.net

Multiple select list value in java script


<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-3.1.1.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-multiselect.css")" rel="stylesheet" />
<script src="@Url.Content("~/Content/MultiCheckbx/js/bootstrap-multiselect.js")"></script>

 <script type="text/javascript">
        $(document).ready(function () {

            $('#ddlLanguage').multiselect({
                includeSelectAllOption: true,
                numberDisplayed: 1,
            });

function Validation() {
    //var language = ListboxChek();
    debugger;
    var languageids = '';
    $('#dvlanguage input[type="checkbox"]:checked').each(function (i, el) {
        languageids += el.value + ',';
        document.getElementById("hdnLanguage").value = languageids;
        var abc = document.getElementById("hdnLanguage").value;
    });
    var abcd = document.getElementById("hdnLanguage").value;
  </script>

When Insert into a table
 @Html.HiddenFor(m => m.hdnLanguage)
 <div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
  @if (Model._listLanguage.Count() > 0)
   {
        foreach (var item in Model._listLanguage)
        {
             <option value="@item.LanguageId"> @item.Name </option>
         }
   }
    </select>
 </div>

  <button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

When Edit after that update
 @Html.HiddenFor(m => m.hdnLanguage)
<div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
    @if (Model._listLanguage.Count() > 0)
       {
           foreach (var item in Model._listLanguage)
           {
               <option value="@item.LanguageId"
                  @if (Model.hdnLanguage != null && (Model.hdnLanguage.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Any(p => (item.LanguageId.ToString().Trim().ToLower() == p.ToString().Trim().ToLower()))))
                                            { <text> selected="selected" </text>  }>
                                                                            @item.Name
                                                                        </option>
             }
        }
    </select>


 </div>
<button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

How to multiple select list value in mvc without ctrl key?

Multiple select list value in asp.net

Multiple select list value in java script


<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-3.1.1.min.css")" rel="stylesheet" />
<link href="@Url.Content("~/Content/MultiCheckbx/css/bootstrap-multiselect.css")" rel="stylesheet" />
<script src="@Url.Content("~/Content/MultiCheckbx/js/bootstrap-multiselect.js")"></script>

 <script type="text/javascript">
        $(document).ready(function () {

            $('#ddlLanguage').multiselect({
                includeSelectAllOption: true,
                numberDisplayed: 1,
            });

function Validation() {
    //var language = ListboxChek();
    debugger;
    var languageids = '';
    $('#dvlanguage input[type="checkbox"]:checked').each(function (i, el) {
        languageids += el.value + ',';
        document.getElementById("hdnLanguage").value = languageids;
        var abc = document.getElementById("hdnLanguage").value;
    });
    var abcd = document.getElementById("hdnLanguage").value;
  </script>

When Insert into a table
 @Html.HiddenFor(m => m.hdnLanguage)
 <div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
  @if (Model._listLanguage.Count() > 0)
   {
        foreach (var item in Model._listLanguage)
        {
             <option value="@item.LanguageId"> @item.Name </option>
         }
   }
    </select>
 </div>

  <button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

When Edit after that update
 @Html.HiddenFor(m => m.hdnLanguage)
<div id="dvlanguage">
 <select id="ddlLanguage" class="form-control" multiple="multiple">
    @if (Model._listLanguage.Count() > 0)
       {
           foreach (var item in Model._listLanguage)
           {
               <option value="@item.LanguageId"
                  @if (Model.hdnLanguage != null && (Model.hdnLanguage.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Any(p => (item.LanguageId.ToString().Trim().ToLower() == p.ToString().Trim().ToLower()))))
                                            { <text> selected="selected" </text>  }>
                                                                            @item.Name
                                                                        </option>
             }
        }
    </select>


 </div>
<button type="submit" class="btn" onclick="javascript:return Validation();">Submit</button>

Tuesday, 21 June 2016

How to a file and text value in javascript and sent data in mvc?

<form enctype="multipart/form-data">
    <div class="col-sm-5">
        <div class="form-group">
            <label>Weekend Date:<span id="errorWeekendDate">*</span></label>
            @Html.TextBoxFor(model => model.WeekendDate, new { @Placeholder = "Weekend Date", @required = "required", @style = "height: 35px;border: 1px solid #ccc;border-radius: 4px;" })
            <div class="clearfix"></div>
        </div>
    </div>
    <div class="col-sm-7">
        <a class="file-input-wrapper btn btn-default" style="margin-bottom: 15px;">
            <input type="file" name="file" id="fileInput" data-filename-placement="inside">
        </a>
        <input type="submit" value="Upload file" style="position: relative;top: -5px;" />
    </div>
    <br />
</form>
<div class="clearfix"></div>
<div id="dvmismatch" style="display :none;">
    @Html.Partial("_MismatchVendorList", Model)
</div>



<script type="text/javascript">
    $(function () {
        // When your form is submitted
        $("form").submit(function (e) {
            debugger;
            var errorWeekendDate = document.getElementById('errorWeekendDate');
            var WeekendDate = document.getElementById('WeekendDate');

            if (WeekendDate.value == '') {
                errorWeekendDate.style.color = "red";
                return false;
            }
            else {
                errorWeekendDate.style.color = "";
            }
            e.preventDefault();
            // Serialize your form
            var formData = new FormData($(this)[0]);
            loader();

            // Make your POST
            $.ajax({
                type: 'POST',
                url: '@Url.Action("FileCsv", "InvoiceProcessing")',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (result) {
                    debugger;
                    $("#popup_ok").click();
                    document.getElementById('dvmismatch').style.display = 'block';
                    $("#dvmismatch").html(result);
                },
                error: function (result) { alert(''); }

            });
        });
    })

function loader() {
        debugger;
        jAlert('<img src="@Url.Content("~/Content/images/ajax-loader-large.gif")" height="60" width="60" />', 'Please wait');
        $("#popup_ok").hide();
    }
</script>

        [HttpPost]
        public ActionResult FileCsv(HttpPostedFileBase file, string WeekendDate)
        {
            try
            {
                int result = 0;
                string List = string.Empty;
                DataSet ds = new DataSet();
                if (Request.Files["file"].ContentLength > 0)
                {
                    string fileExtension =
                                        System.IO.Path.GetExtension(Request.Files["file"].FileName);

                    string ImportCSVFile = Request.Files["file"].FileName;
                    string FileName = Request.Files["file"].FileName;
                    string[] strFileName = FileName.Split('.');
                    FileName = strFileName[0];

                    string fileLocation = Server.MapPath("~/Content/CSVFile/") + Request.Files["file"].FileName;
                    if (System.IO.File.Exists(fileLocation))
                    {
                        System.IO.File.Delete(fileLocation);
                    }
                    Request.Files["file"].SaveAs(fileLocation);

                    DataTable dt = new DataTable();

                    string fileName1 = Request.Files["file"].FileName;
                    string path = Path.Combine(Server.MapPath("~/Content/CSVFile/"), fileLocation);

 

                return PartialView("_MismatchVendorList", model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


Sunday, 19 June 2016

How to bind a partial view in a div?

 <div id="dvMappingList" style="display:none;"> </div>

        public ActionResult ServicetoServiceMapping()
        {
            AModel model = new AModel();
            try
            {
             

                return PartialView("_ServiceMapping", model);
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

function bindServicetoService(serviceId, IsServiceId) {
        debugger;
        $('#dvMappingList').html('');
        loader();
        $.ajax({
            cache: false,
            type: "GET",
            url: '@Url.Action("ServicetoServiceMapping", "Component")',
            data: { serviceId: serviceId, IsServiceId: IsServiceId },
            success: function (result) {
                debugger;
                $("#dvMappingList").html(result);
                $('.tabclass li').removeClass("active");
                $('#litab3').addClass("active");
                $('.tab-content div').removeClass("in active");
                $('#tab3').addClass("in active");
                //document.getElementById("litab3").style.display = "block";
                document.getElementById("dvMappingList").style.display = "block";
                $("#popup_ok").click();
            },
        }
    )
    };

And after that top to message display and reload the page-:

In Partial view page-

 <div id="prefix_108058000000" class="Metronic-alerts alert alert-success fade in" style="display: none;">
            <a type="button" class="close" data-dismiss="alert" aria-hidden="true"></a>
            <span id="spnmessage1"></span>
        </div>
        <div id="prefix_Error" class="Metronic-alerts alert alert-danger fade in" style="display: none;">
            <a type="button" class="close" data-dismiss="alert" aria-hidden="true"></a>
            <span id="spnmessage2"></span>
        </div>


In Main Page

<div class="page-content" id="dvSubComponat">

In a div tab and partial pages...........

<ul class="nav nav-tabs tabclass">
        <li class="active" id="litab1"><a data-toggle="tab" href="#tab1">A Mapping</a></li>
        <li id="litab2" style="display:none;"><a data-toggle="tab" href="#tab2">Add Edit Employee</a></li>
        <li id="litab3" style="display:none;"><a data-toggle="tab" href="#tab3">DepartmentMapping Mapping</a></li>
        <li id="litab4" style="display:none;"><a data-toggle="tab" href="#tab4">Add Edit Deaprtment Mapping</a></li>
    </ul>

<div class="form-body">
 <div id="tab1" class="tab-pane fade in active">
                                                <div id="dvEmployee">
                                                    @Html.HiddenFor(a => a.EmpID)
                                                    <div class="form-group" style="margin-left:-217px;">
                                                        <label class="control-label col-md-3">
                                                            Search EmployeeID :
                                                        </label>
                                                        <div class="col-md-4">
                                                            @Html.TextBoxFor(m => m.SerTextID, new { @class = "form-control", @onkeypress = "return PopulateEmployeeID();" })
                                                        </div>
                                                    </div>
                                                    <div id="dvserAllList">
                                                        @Html.Partial("_EmployeeAllListPartial", Model)
                                                    </div>
                                                </div>

                                                <div id="dvmaplist" style="display:none;">
                                                    @Html.Partial("_ComponentMappingPartial", Model)
                                                </div>

                                                <div id="dvunmaplist" style="display:none;">
                                                    @Html.Partial("_ComponentUnMappingPartial", Model)
                                                </div>

                                            </div>
</div>

<div id="tab2" class="tab-pane fade">
            @Html.Action("AddEditEmployee", "Component", new { ID = 0 })
        </div>
</div>

 function SuccessSubComponent(data) {
        $("#popup_ok").click();
        if (data != null) {
            debugger;
            if (data.indexOf("exist") != -1) {
                $('#prefix_Error').show();
                $('#prefix_Error').removeClass("fade");
                $("#spnmessage2").html(data);
                $("#spnmessage2").focus();
                $('html,body').animate({
                    scrollTop: $("#dvSubComponat").offset().top
                },
       'slow');
                setTimeout("loadSubComponentReload()", 1000);
            }
            else {
                debugger;
                $('#prefix_108058000000').show();
                $('#prefix_108058000000').removeClass("fade");
                $("#spnmessage1").html(data);
                $("#spnmessage1").focus();
                $('html,body').animate({
                    scrollTop: $("#dvSubComponat").offset().top
                },
       'slow');
                setTimeout("loadComponentMapReload()", 1000);
            }
        }
    }

    function loadComponentMapReload() {
        window.location.href = "@Url.Action("ComponentMapping", "Component")";
    }


Wednesday, 15 June 2016

How to display some character in mvc?

@(model.ShortDescription.Length > 130 ? model.ShortDescription.Substring(0, 131)+"..." : model.ShortDescription)