t-sql with ties kullanımı

      Yorum yok t-sql with ties kullanımı
select 
  top 5 ProductName,UnitPrice,UnitsInStock 
from 
  Products 
where 
  UnitsInStock > 10 
order by 
  UnitsInStock

select
   ProductName,UnitPrice,UnitsInStock
from 
   Products 
where 
   UnitsInStock > 10 
order by 
   UnitsInStock

select 
  top 5 with ties ProductName,UnitPrice,UnitsInStock 
from 
  Products 
where 
  UnitsInStock > 10 
order by 
   UnitsInStock

metot geri dönüşleri üzerine bir kaç örnek

örnek 1

class Program
{
   static void Main(string[] args)
   {
     //1. yöntemin kullanımı
     int a, b;
     a = Yontem1(out b);
     // sonuc
     //a -> 20 ve b -> 10 olur.
   }

   //1. yöntem -> out kullanımı
   static int Yontem1(out int par)
   {
     par = 10;
     return 20;
   }
 }

örnek 2

class Program
{
  static void Main(string[] args)
  {
     //2. yöntemin kullanımı
     DonenTip tip = Yontem2();
     //sonuc
     //tip.a -> 20 ve tip.b -> 10 olur.
  }

  //2. yöntem -> sınıf(class) kullanmak
  class DonenTip
  {
    public int a, b;
  }

  static DonenTip Yontem2()
  {
     DonenTip tip = new DonenTip();
     tip.a = 20;
     tip.b = 10;
     return tip;
  }
}

örnek 3

class Program
{
  static void Main(string[] args)
  {
    //3. yöntemin kullanımı
    var sonuc = Yontem3();
    //sonuc.Item1 -> 20 ve sonuc.Item2 -> 10 olur.
  }

  //3. yöntem Tuples kullanımı
  static Tuple<int, int> Yontem3()
  {
    return Tuple.Create(20, 10);
  }
}

 

mvc webgrip ve excel export

      Yorum yok mvc webgrip ve excel export
[HttpPost]
public ActionResult Export(string module)
{
    SiteEntities db = new SiteEntities();

    WebGrid grid = null;
    if(module == "Tercümeler")
        grid = new WebGrid(db.Tercume,,columnNames:new []{"Id", "Kod", "Tr", "En"}, canPage: false, canSort: false);
    else if (module == "Listeler")
        grid = new WebGrid(db.Liste, canPage: false, canSort: false);
    else if (module == "Lokasyonlar")
        grid = new WebGrid(db.Lokasyon, canPage: false, canSort: false);

    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1254");
    Response.Charset = "windows-1254";

    Response.Buffer = true;
    Response.ContentType = "application/vnd.xls";
    string fileName = string.Format("{0}.xls", module);
    Response.AddHeader("content-disposition", string.Concat("attachment;filename=", fileName));
    string html = string.Format("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1254\" /></head><body>{0}</body></html>", grid.GetHtml());

    Response.Write(html);
    Response.End();

    return View();
}
<div class="panel panel-default">
    <div class="panel-heading">Export List</div>
    <div class="panel-body">
        <div class="row">
            @foreach (var module in Model)
            {
                <div class="col-md-4">
                    <form action="/Home/Export" method="post">
                        <input type="hidden" name="module" value="@module.Name" />
                        <button class="btn btn-primary" type="submit">
                            @module.Name <span class="badge">@module.Count</span>
                        </button>
                    </form>
                </div>
            }
        </div>
    </div>
</div>

 

ExceptionHelper

      Yorum yok ExceptionHelper
public static class ExceptionHelper
{
    public static string GetMessage(this Exception ex)
    {
        StringBuilder expS = new StringBuilder();
        expS.Append(ex.Message);
        Exception inner = ex.InnerException;
        while (inner != null)
        {
            expS.AppendFormat("{0}-{1}", Environment.NewLine, inner.Message);
            inner = inner.InnerException;
        }
        return expS.ToString();
    }
}

 

javascript image cycle

      Yorum yok javascript image cycle
<body>
    <img id='img_' src='#' width='100' height='100' />
    <input type='button' name='name' value='sonraki resim' onclick='next();' />
    <script>
        var index = -1;
        var pictures = new Array(
                    'Images/0004574.jpg',
                    'Images/0004604.jpg',
                    'Images/0004611.jpg',
                    'Images/0004613.jpg',
                    'Images/0004592.jpg');
        window.onload = function () {
            next();
        }
        function next() {
            index = (index + 1) % pictures.length;
            document.getElementById('img_').src = pictures[index];
            console.log(index);
        }
    </script>
</body>

 

LINQPad – group by ile pivot

      Yorum yok LINQPad – group by ile pivot

yakınen bildiğimiz t-sql groupby sorgu örneği

select 
  C.CategoryName,Count(EC.CategoryId) Adet
from EntryCategories EC
join Categories C on EC.CategpryID = C.Id
group by
  C.CategoryName

bunu linq ile uyarlayıp alıp biraz değiştirince çok da güzel pivot oluyor

from p in db.EntryCategories
where p.Entry.EntryTime.Year == 2010
group p by p.Category.CategoryName into g
select new
{
  Kategori = g.Key,
  Ocak = g.Where(t => t.Entry.EntryTime.Month == 1).Count(),
  Subat = g.Where(t => t.Entry.EntryTime.Month == 2).Count(),
  Mart = g.Where(t => t.Entry.EntryTime.Month == 3).Count(),
  Nisan = g.Where(t => t.Entry.EntryTime.Month == 4).Count(),
  Mayis = g.Where(t => t.Entry.EntryTime.Month == 5).Count(),
  Haziran = g.Where(t => t.Entry.EntryTime.Month == 6).Count(),
  Temmuz = g.Where(t => t.Entry.EntryTime.Month == 7).Count(),
  Agustos = g.Where(t => t.Entry.EntryTime.Month == 8).Count(),
  Eylul = g.Where(t => t.Entry.EntryTime.Month == 9).Count(),
  Ekim = g.Where(t => t.Entry.EntryTime.Month == 10).Count(),
  Kasim = g.Where(t => t.Entry.EntryTime.Month == 11).Count(),
  Aralik = g.Where(t => t.Entry.EntryTime.Month == 12).Count(),
}.Dump();