6 Ocak 2025 Pazartesi

Javascript DropDown Option ; tanımlanan attr'dan deger çekmek

   var value2send = document.querySelector(`#cmbKisiTipi option[alt='${document.getElementById('cmbKisiTipi').value}']`).dataset.alt; 



 <label for="cmbKisiTipi">Kişi Tipi <span class="text-danger">*</span></label>

 <select class="form-control form-control-focused form-control-pointer" id="cmbKisiTipi">

     <option value="" alt="">Seçiniz</option>

     <option value="1" alt="GERCEK">Gerçek Kişi</option>

     <option value="2" alt="TUZEL">Tüzel Kişi</option>

     <option value="3" alt="DIGER">Diğer</option>

 </select>



13 Ocak 2023 Cuma

Get selected values in a multi-select drop-down with JavaScript

 var hexvalues = [];

var labelvalues = [];

$('#myMultiSelect :selected').each(function(i, selectedElement) {
 hexvalues[i] = $(selectedElement).val();
 labelvalues[i] = $(selectedElement).text();
});

Get selected get customer attribute drop-down with JavaScript

 

<select id="location">
    <option value="a" myTag="123">My option</option>
    <option value="b" myTag="456">My other option</option>
</select>

alert($('#location').find('option:selected').attr('myTag'));


2 Şubat 2022 Çarşamba

c# Number Decimal Separator

     

Tutar işlemlerinde sistem ondalık ayracı farklılıklarından kaynaklanan sorunların önüne geçmek için 

Uygulamanın çalıştığı sunucu/pc üzerinde tanımlı ayracı bilgisini dönen; "CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator" kullanarak daha kısa kod yazabilirsiniz.

Örnek;

string transactionAmount = "1,20"; 

string uiSep = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;

 string Amount = string.Empty;

var x = transactionAmount.Split(uiSep);

 if (x.Length == 2) {

    Amount = x[0] + x[1].PadRight(2,'0');

 } else {

    Amount = x[0] + "00";

}

30 Ocak 2022 Pazar

Javascript Ayın son günü

ayın son günü bulmak için kullanılabilecek bir metot


 function daysInMonth(m, y){

  return m===2?y&3||!(y%25)&&y&15?28:29:30+(m+(m>>3)&1);
}
<!-- example -->
<input type="text" placeholder="enter year" onblur="
  for( var r='', i=0, y=+this.value
     ; 12>i++
     ; r+= 'Month: ' + i + ' has ' + daysInMonth(i, y) + ' days<br>'
     );
  this.nextSibling.innerHTML=r;
" /><div></div>

İşlem tarihinden bir gün sonrasını set ededen metot içinde kullanımı
function formatDate() {
    var d = new Date(),
        month = '' + (d.getMonth() + 1),
        day = '' + (d.getDate() + 1),
        year = d.getFullYear();

    if (month.length < 2)
        month = '0' + month;
    if (day.length < 2)
        day = '0' + day;

// ayın son gününden büyük ise gün set eder
    if (day > daysInMonth(d.getMonth(), year)) 
        day = d.getDate();
    

    return [day, month, year].join('.');
}

19 Ağustos 2021 Perşembe

Windows Servis Projesi Oluşturma

 Consol Projesi oluşturarak aşağıdaki kodlar ile windows servis üzerinden çalışan consol uygulaması geliştirebilirsiniz.

static void Main(string[] args)

        {

            try

            {

                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("tr");

                if (!Environment.UserInteractive)

                    Directory.SetCurrentDirectory(Program.GetServicePath());

                else

                    Directory.SetCurrentDirectory(Program.GetProcessPath());

                if (!Environment.UserInteractive)

                {

                    // running as service

                    using (var service = new Service())

                        ServiceBase.Run(service);

                }

                else

                {

                    // running as console app

                    Start(args);

                    Console.WriteLine("Press any key to stop...");

                    Console.ReadKey(true);

                    Stop();

                }

            }

            catch (Exception ex)

            {

                log.Error(MethodBase.GetCurrentMethod().Name + " - " + ex.Message);

            }

        }

 public static void Start(string[] args)

        {

            try

            {

                var config = new HttpSelfHostConfiguration("http://localhost:8082");

                config.MapHttpAttributeRoutes();

                config.MessageHandlers.Add(new CustomHeaderHandler());

                var server = new HttpSelfHostServer(config);

                server.OpenAsync().Wait();

                log.Info("Server started....");

                ServisHelpers.getSetting();

            }

            catch (Exception ex)

            {

                log.Error(MethodBase.GetCurrentMethod().Name + " - " + ex.Message);

            }

        }


        public static void Stop()

        {


            // onstop code here

        } 

CSS ile INPUT Focuslandığında border renk degişimi

 

CSS ile Input Focus border bilgilerinin degiştirilmesi

.no-focusborder:focus {

    outline-style: none;

    box-shadow: none;

    border-color: deepskyblue;

}

18 Mayıs 2021 Salı

Bilgisayarda Kayıtlı Wifi Şifrelerini Görme

Başlat menüsünü açıp arama kısmına ” cmd ”  yazıyoruz. Ve ” Komut İstemi ” ‘ne tıklıyoruz.

konsola ” netsh wlan show profile” komutu yazarak bilgisayarda kayıtlı wifi listesine erişim sağlanabilmektedir.


 ” netsh wlan show profile name=Bursaspor key=clear ” komutu ile name=Bursaspor  profili için detaylı bilgiye erişim saglanabilmektedir. burada yer alan "Securiyt settings" bölümünde yer alan "Key Content" etiketi karşısında wifi şifresi görüntünecektir.


31 Mayıs 2020 Pazar

.NET Core 3.1 MVC İle Kullanıcının IP Adresini Alma


public string GetClientIp() { 
 var ipAddress = string.Empty; 

if (_accessor.HttpContext.Request.Headers.ContainsKey("X-Forwarded-For") == true)

 ipAddress = _accessor.HttpContext.Request.Headers["X-Forwarded-For"].ToString(); 

 else if (_accessor.HttpContext.Request.Headers.ContainsKey("HTTP_CLIENT_IP") == true && _accessor.HttpContext.Request.Headers["HTTP_CLIENT_IP"].Count != 0) 

 ipAddress = _accessor.HttpContext.Request.Headers["HTTP_CLIENT_IP"]; 

 else if (_accessor?.HttpContext?.Connection?.RemoteIpAddress?.ToString().Length != 0)

 ipAddress = _accessor?.HttpContext?.Connection?.RemoteIpAddress?.ToString(); 

 return ipAddress; 

 }

19 Eylül 2019 Perşembe

JavaScript or JQuery redirect to URL on select


JavaScript:

<select onChange="window.document.location.href=this.options[this.selectedIndex].value;">
<option vlaue="http://deneme.com/">Option 1</option>
<option vlaue="http://deneme.net/">Option 2</option>
<option vlaue="http://deneme.org/">Option 3</o

jQuery:

jQuery(function($) {
$('select').on('change', function() {
var url = $(this).val();
if (url) {
window.location = url;
}
return false;
});
});

18 Eylül 2019 Çarşamba

Web sayfasında geri tuşunu pasif etmek ...

        history.pushState(null, null, location.href);
     
 window.addEventListener('popstate', function (event) {
         
 // The popstate event is fired each time when the current history entry changes.

            var r = false;// confirm("Geri butonu çalışmayacak..?!");

            if (r == true) {
                // Call Back button programmatically as per user confirmation.
                history.back();
                // Uncomment below line to redirect to the previous page instead.
                // window.location = document.referrer // Note: IE11 is not supporting this.
            } else {
                // Stay on the current page.
                history.pushState(null, null, window.location.pathname);
            }

            history.pushState(null, null, window.location.pathname);

        }, false);

6 Ağustos 2019 Salı

c# Web Sayfasının URL bulunması (Get IIS Url)

Farklı sunucularda local dosya erişimde parametrik yapıdan ziyade  IIS üzerindeki url ile dosya erişim yapmak için ;

var url = HttpContext.Request.Url.GetLeftPart(UriPartial.Authority);

response = "http://localhost:59386/"

12 Nisan 2019 Cuma

C# DLL P/Invoke CallbackOnCollectedDelegate Error


Mevcut C++ ile yazılmış bir dll projenize eklemek için ara dll oluşturarak yapacağınız Callback uygulamalarında GC callback metodunu kaldırması sorunucu çalışma aralığında CallbackOnCollectedDelegate  Exception alıp uygulama kapanmasına neden olmaktadır.

Sorun:

        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void ApplicationMessageCallback(Int32 applicationId, IntPtr data, Int32 size);

        [DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl)]
        static extern void inposext_set_application_message_callback(ApplicationMessageCallback cb);

        public static void SetApplicationMessageCallback(ApplicationMessageCallback callbackFunction)
        {

            inposext_set_application_message_callback(callbackFunction);
        }

Çözüm :

        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void ApplicationMessageCallback(Int32 applicationId, IntPtr data, Int32 size);

        [DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl)]
        static extern void inposext_set_application_message_callback(ApplicationMessageCallback cb);

        private static ApplicationMessageCallback callback;   // Keeps it referenced
        public static void SetApplicationMessageCallback(ApplicationMessageCallback callbackFunction)
        {
            callback = callbackFunction;
            inposext_set_application_message_callback(callback);
        }

17 Şubat 2019 Pazar

C# SeriPort Ad okuma

using (var searcher = new System.Management.ManagementObjectSearcher
                ("SELECT * FROM WIN32_SerialPort"))
            {
                string[] portnames = System.IO.Ports.SerialPort.GetPortNames();
                var ports = searcher.Get().Cast<System.Management.ManagementBaseObject>().ToList();
                var tList = (from n in portnames
                             join p in ports on n equals p["DeviceID"].ToString()
                             select n + " - " + p["Caption"] ).ToList();

                   tList.ForEach(Console.WriteLine);
            }

16 Ocak 2019 Çarşamba

system diagnostics process start administrator


system diagnostics process start administrator:

    Process proc = new Process();
    proc.StartInfo.FileName = fileName;
    proc.StartInfo.UseShellExecute = true;
    proc.StartInfo.Verb = "runas";
    proc.Start();

19 Kasım 2018 Pazartesi

Visual Studio- Hata : the underlying connection was closed an unexpected error occurred on a send and (407) Proxy Authentication Required.

Güvenli bir ağ üzerinden proxy yetkilendirmeli bir ağdan dış servise bağlanma sırasında alınan hata cözümü :

app.config eklen

<system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
</system.net>

Clinet Kullanmadan önce aşağıdaki kodu uygun bir yere yerleştirin . TLS 1.2 için 
            System.Net.ServicePointManager.SecurityProtocol = (System.Net.SecurityProtocolType)3072;

If you are stuck with .Net 4.0 and the target site is using TLS 1.2, you need the following line instead. ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

1 Ekim 2018 Pazartesi

javascript ile dropdown secimine göre alan gösterimi


@Html.DropDownList("optionId", new SelectList(SelectListData), "Select an option")

@Html.TextBox("controlId")
<script>
  $("#optionId").on("change", function () {
    if ($("#optionId option:selected").index() == 0) {
      $("#controlId").hide();
    } else {
      $("#controlId").show();
    }
  });
</script>

25 Temmuz 2018 Çarşamba

Devexpress WPF : loading decorator change content

<dx:LoadingDecorator Name="ld" SplashScreenDataContext="{Binding}">
    <dx:LoadingDecorator.SplashScreenTemplate>
        <DataTemplate>
            <dx:WaitIndicator DeferedVisibility="True" Content="{Binding SomeProperty}"/>
        </DataTemplate>
    </dx:LoadingDecorator.SplashScreenTemplate>
...

28 Mayıs 2018 Pazartesi

Işlem başka bir işlem tarafından kullanıldığından dosyasına erişemiyor Hatası ve Çözümü


using (System.IO.FileStream file = new System.IO.FileStream(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite))
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(file))
                    {
                        // Read the stream to a string, and write the string to the console.
                        string not = sr.ReadToEnd();
                    }