19 Nisan 2010 Pazartesi

sql komutu ile iki tablodada var olan aynı kayıtları silmek veya listelemek

ben bu şekilde aradım bulamadım belki benim gibi arayanlar da çıkar diye ingilizce anahtar kelimeleri de yazayım.

get or delete same records from two tables with sql query

Ms sql de farklı tablolarda bulunan aynı kayıtları silmemiz gerekebiliyor.

öncelikle her iki tablo için diğer tabloda olmayan kayıtları getirelim.
(get the distinct records each tables)

select ProductName from Product
except
select NewProductName from NewProductTable

ve tam tersi tablo için de sorgulayalım

select NewProductName from NewProductTable
except
select ProductName from Product

her iki sonuçta da listelenen kayıların tabloların birinde olduğu diğerinde olmadığını göreceğiz.

ve şimdi de silme işlemini gerçekleştirelim
(now, delete the same records from first table)


delete from product where product.productname not in (

select * from (
select ProductName from Product
except
select NewProductName from NewProductTable

) as newtable

)

17 Ocak 2010 Pazar

com ve net uzantılı domainlerin whois bilgilerini almak

Aşağıda yazmış olduğum fonksiyon com ve net uzantılı domainlerin whois bilgilerini almaya yarar.

system.io sınıfını eklemeyi unutmayın.


public string DownloadWebPage(string Url)
{
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(Url);

WebRequestObject.UserAgent = ".NET Framework/2.0";
WebRequestObject.Referer = "http://www.example.com/";

WebResponse Response = WebRequestObject.GetResponse();

Stream WebStream = Response.GetResponseStream();

StreamReader Reader = new StreamReader(WebStream);

string PageContent = Reader.ReadToEnd();

Reader.Close();
WebStream.Close();
Response.Close();
return PageContent;
}

private void btnWhois_Click(object sender, EventArgs e)
{
lblCreationDate.Text = "";
lblExpDate.Text = "";
lblNs1.Text = "";
lblNs2.Text = "";
lblRegistrar.Text = "";
lblStatus.Text = "";
lblUpdateDate.Text = "";
lblRegistrant.Text = "";

string strResponse = DownloadWebPage("http://www.networksolutions.com/whois/registry-data.jsp?domain=" + txtAddress.Text.Replace("http://", ""));

string[] arrRegist = strResponse.Split(new string[1] { "\n" }, StringSplitOptions.None);
int i = 0;
for (int z = 0; z < arrRegist.Length; z++)
{
if (arrRegist[z].Trim().ToLower().StartsWith("registrant:") || arrRegist[z].Trim().ToLower().StartsWith("regıstrant:") || arrRegist[z].Contains("Kaydedicinin Iletisim Bilgileri"))
{
i = z + 1;
}

}

string[] arrStr = new string[2];
string[] b;
arrStr[0] = "Whois Server Version 2.0\n\nDomain names in the .com and .net domains can now be registered\nwith many different competing registrars. Go to http://www.internic.net\nfor detailed information.\n\n ";
arrStr[1] = ">>> Last update of whois database:";

b = strResponse.ToString().Split(arrStr, StringSplitOptions.None);
txtWhoisFullInfo.Text = b[1].Trim().Replace(" ", Environment.NewLine); // strResponse;

strResponse = b[1].Trim();



string[] domainName = strResponse.Split(new string[2] { " Domain Name: ", "\n " }, StringSplitOptions.None);
char c = 'a';

foreach (string _str in domainName)
{
// c = 'a';
if(_str.StartsWith("Registrar:"))
lblRegistrar.Text = _str;
if (_str.StartsWith("Name Server:") && c=='a')
{
lblNs1.Text = _str;
c = 'b';
}
if (_str.StartsWith("Name Server:") && c == 'b')
{ lblNs2.Text = _str; c = 'x'; }
if (_str.StartsWith("Status:")&&lblStatus.Text=="")
lblStatus.Text = _str;
if (_str.StartsWith("Updated Date:"))
lblUpdateDate.Text = _str;
if (_str.StartsWith("Creation Date:"))
lblCreationDate.Text = _str;
if (_str.StartsWith("Expiration Date:"))
{
string[] ExpDate = _str.Split(new string[1] { "\n" }, StringSplitOptions.None);
lblExpDate.Text = ExpDate[0]; c = 'a'; }
}
}

11 Ocak 2010 Pazartesi

csharp ile url adresi verilen bir sayfayı kaydetmek.

Aşağıdaki fonksiyon url adresi verilen bir web sayfasının içeriğini string olarak döndürür.
Örnek kullanım : DownloadWebPageUsingWebRequest("http://generalengels.blogspot.com");


public static string DownloadWebPageUsingWebRequest(string url)
{
WebRequest myWebRequest = WebRequest.Create(url);

WebResponse myWebResponse = myWebRequest.GetResponse();

Stream ReceiveStream = myWebResponse.GetResponseStream();

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

StreamReader readStream = new StreamReader(ReceiveStream, encode);

string strResponse = readStream.ReadToEnd();
readStream.Close();

myWebResponse.Close();
return strResponse;
}

asp.net csharp ile excel okuma

Asp.Net ve Csharp kullanarak exceldeki kayıtları kullanmak için aşağıda oluşturduğum class ı kullanabiliriniz.

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace _General
{
public class ExcelProccess
{
private string _excelFileName;
public string ExcelFileName
{
get { return _excelFileName; }
set { _excelFileName = value; }
}

private string _excelSheetName;
public string ExcelSheetName
{
get { return _excelSheetName; }
set { _excelSheetName = value; }
}
public OleDbConnection _Connection()
{
OleDbConnection _con = new OleDbConnection("Data Source=" + ExcelFileName + ";Provider=Microsoft.jet.OLEDB.4.0;Extended Properties=Excel 8.0");
return _con;
}
OleDbCommand _command;
public DataTable GetDataTableFromExcelSheet()
{
_command = new OleDbCommand("select * from [" + ExcelSheetName + "$]", _Connection());

// _command = new OleDbCommand("select * from [apple$]", _Connection());
//apple vinegar
if (_Connection().State == ConnectionState.Closed)
_Connection().Open();
OleDbDataAdapter _da = new OleDbDataAdapter(_command);
DataTable _dt = new DataTable();

_da.Fill(_dt);
_Connection().Close();
return _dt;
}

public DataRowCollection GetDataRowCollection()
{
_command = new OleDbCommand("select * from [" + ExcelSheetName + "$]", _Connection());
if (_Connection().State == ConnectionState.Closed)
_Connection().Open();
OleDbDataAdapter _da = new OleDbDataAdapter(_command);
DataTable _dt = new DataTable();
_da.Fill(_dt);
_Connection().Close();
return _dt.Rows;
}
}
}

Kullanımı şu şekilde olmalı :

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
if (FileUpload1.FileName.Substring(FileUpload1.FileName.LastIndexOf("."), 4).ToLower() == ".xls")
{
FileUpload1.SaveAs(Server.MapPath("excel/fiyat.xls"));

_General.ExcelProccess _exproc = new Emre_General.ExcelProccess();
_exproc.ExcelFileName = Server.MapPath("excel/" + "fiyat.xls");
_exproc.ExcelSheetName = "fiyat";

foreach (DataRow dr in _exproc.GetDataRowCollection())
{
decimal Price =decimal.Parse(dr[1].ToString().Replace(".",","));
urun.FiyatGuncelle(Price, dr[0].ToString());
}
_Common.hataScripti("Başarıyla Güncellendi", Button1);
}
else
_Common.hataScripti("Lütfen .xls uzantılı bir dosya seçiniz", Button1);

}
}

Butonun click olayında öcne dosyanın xls uzantılı olup olmadığı yani excel dosyası olup olmadığını kontrol ediyorum. sonra onu excel isimli klasörüme fiyat.xls olarak kaydediyorum. burada dikkat edilmesi gereken excel deki sheet adının belirlenmiş olmasıdır.
_exproc.ExcelSheetName = "fiyat";
gibi. Yani benim excel kullanacağım excel dosyamın sheet adı "fiyat" dır. Burayı istediğiniz şekilde değiştirebilirsiniz ama bu değişikliği excel dosyasında da yapmanız gerekir.

Ben burada urun isimli class ımın fiyatgüncelle fonksiyonunu kullanarak exceldeki her satır okundukça urunlerin fiyatlarını güncelledim. Benim kullandığım excel tablosunda iki kolon var. birincisinde ürünün kodu ikincisinde güncel fiyatı. Yani ben yukarıdaki class ımı kullanarak excel üzerinden ürünlerin kodlarına göre fiyat güncellemesi yapıyorum.

Kullandığım excel örneği aşağıda bulunan resimdeki gibidir.

10 Ocak 2010 Pazar

asp.net c# ile kelimelerin ilk karakterlerini büyük yapma

Code behind tarafında metinlerin sadece ilk harflerini büyük hale getirme ihitiyaçlarınız olabilir. Eğer böyle bir ihtiyacınız olursa aşağıda yazmış olduğum fonksiyonu kullanabilirsiniz.

public string StringToUpperFirstChars(string text)
{
string result = "";
string[] MyText = text.Split(' ');
foreach (string word in MyText)
{
for (int i = 0; i < word.Length; i++)
{
if (i == 0)
result += word[i].ToString().ToUpper();
else
result += word[i].ToString().ToLower();
}
result += " ";
}
return result;
}

Kullanımı şu şekilde olmalıdır.
Response.Write("friedrich engels");

Ekranda "Friedrich Engels" yazdığı yani ilk harflerinin büyük olduğu görülecektir.

18 Aralık 2009 Cuma

Uefa Avrupa Ligi Eşleşmeleri



Uefa Avrupa liginin 2. tur eleme eşleşmelerindeki takımlar:

1. (RUSYA) FC Rubin Kazan & Hapoel Tel-Aviv FC (ISRRAİL)
2. (İSPANYA) Athletic Club & RSC Anderlecht (BELÇİKA)
3. (DANİMARKA) FC København & Olympique de Marseille (FRANSA)
4. (YUNANİSTAN) Panathinaikos FC & AS Roma (ITALYA)
5. (İSPANYA) Club Atlético de Madrid & Galatasaray AŞ (TÜRKİYE)
6. (HOLLANDA) AFC Ajax & Juventus (ITALYA)
7. (BELÇİKA) Club Brugge KV & Valencia CF (İSPANYA)
8. (İNGİLTERE) Fulham FC & FC Shakhtar Donetsk (UKRAYNA)
9. (İNGİLTERE) Liverpool FC & FC Unirea Urziceni (ROMANYA)
10. (ALMANYA) Hamburger SV & PSV Eindhoven (HOLLANDA)
11. (İSPANYA) Villarreal CF & VfL Wolfsburg (ALMANYA)
12. (BELÇİKA)R. Standard de Liège & FC Salzburg (AVUSTURYA)
13. (HOLLANDA) FC Twente & Werder Bremen (ALMANYA)
14. (FRANSA) LOSC Lille Métropole & Fenerbahçe SK (TÜRKİYE)
15. (İNGİLTERE) Everton & Sporting Clube de Portugal (PORTEKİZ)
16. (ALMANYA) Hertha BSC Berlin & SL Benfica (PORTEKİZ)

17 Aralık 2009 Perşembe

Mail Class Asp Net C# - Mail Gönderimi

Mail Class Asp.Net C#

Aşağıdaki class ı kullanarak mail gönderebilirsiniz. Bu class localhostta da çalışır.
public static class mail

{

// <summary>

// HTML Formatında Mail Gönderir

// </summary>

// <param name="alici"></param>

//<param name="gonderici"></param>

// <param name="konu"></param>

// <param name="mesaj"></param>

// <param name="Password"></param>
public static void MailGonder(string alici, string gonderici, string konu, string mesaj, string Password)

{
string smtpServer = "mail.domain.com";

string userName = gonderici;
string password = Password;

int cdoBasic = 1;
int cdoSendUsingPort = 2;

MailMessage msg = new MailMessage();
if (userName.Length > 0)

{
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusing", cdoSendUsingPort);

msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", cdoBasic);msg.Fields.Add(
"http://schemas.microsoft.com/cdo/configuration/sendusername", userName);msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);

}

msg.To = alici;

msg.From = gonderici;

msg.Subject = konu;

msg.Body = mesaj;

msg.BodyFormat = MailFormat.Html;

SmtpMail.SmtpServer = smtpServer;

SmtpMail.Send(msg);

}

}

// Class ı şu şekilde kullanabilirsiniz:

string mesaj = "Deneme Test Maili";
string alici= "isim@domain.com";

mail.MailGonder(alici, isim@domain.com, "Paralel Yazılım Test Maili", mesaj, "xxxx");