anilguleryuz Posted April 25, 2016 Share Posted April 25, 2016 Arkadaşlar merhaba, vs 2010 kullanıyorum. Proje ödevim için hasta kayıt otomasyonu yapmaktayım. Sizlere şu sorum olacaktı, adı, soyadı bilgilerinde 2 harf girip kayıt yaptığım zaman kaydı yapıyor. Benim yapmak istediğim, 3 harften daha kısa harf girildiği zaman kayıt yapmamasını istiyorum. Neredeyse çoğu kişi MaxLength olayından bahsetmiş, ama ben bu şekilde olmasını istemiyorum. If-Else yapısı kullanarak yapmak istiyorum bu işlemi nasıl yapabilirim, yada başka şekilde nasıl yapabilirim. Yardımcı olabilecek arkadaşlar var mı? Quote Link to comment Share on other sites More sharing options...
Editor mephistooo2 Posted April 25, 2016 Editor Share Posted April 25, 2016 Aşağıdaki kodları TextBox’un KeyPress event ine (olayına) yazman gerek. //textBoxa girilecek karakter sayısı 3 olsun if (textBox1.TextLength == 3) { e.Handled = true; } umarım işini görür... 1 Quote Link to comment Share on other sites More sharing options...
KintaRo Posted April 25, 2016 Share Posted April 25, 2016 Bu işi kaydet buttonu ile yapmaya çalışıyorsanız if (textBox1.Text.Length > 2) { MessageBox.Show("Hatalı giriş"); } else { // kayıt kodları } şeklinde olur. 1 Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted April 25, 2016 Author Share Posted April 25, 2016 Yine olmadı, sizin verdiğiniz kodda sadece 3 karaktere kadar sınırlıyor. 3 karakterden sonrasına izin vermiyor. Benim yapmak istediğim bu şekilde değil, textbox karakter sayısı sınırsız fakat kayıt yaparken 2 karakter veya daha az karakter girilince hata versin. Mesela şu şekilde yapmak istiyorum. Spoiler Bu kod doğru bir şekilde çalışıyor Bu kod ise yanlış bir şekilde çalışıyor burada 2 karakter girildiği için hata vermesi gerekiyordu, fakat yine de kayıt yapıyor. Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted April 25, 2016 Editor Share Posted April 25, 2016 Ozaman Kintaronun kodlarını şu şekilde düzenlemen lazım. if (textBox1.Text.Length < 2) { MessageBox.Show("Hatalı giriş"); } else { // kayıt kodları } 1 Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted April 25, 2016 Author Share Posted April 25, 2016 Tamamdır, hallettim. Çok teşekkür ederim. Diğer textboxlar için de yapmak istiyorum onu nasıl yapacağım. && "" komutlarını kullandım hata verdi. Quote Link to comment Share on other sites More sharing options...
SimpsoN_Bart Posted April 25, 2016 Share Posted April 25, 2016 if ((textBox1.TextLength & textBox2.TextLength) < 2) { MessageBox.Show("Hata!"); } else { MessageBox.Show("OK"); } Quote Link to comment Share on other sites More sharing options...
cumman Posted April 25, 2016 Share Posted April 25, 2016 Eger programinin genelinde bir kural tanimlayacaksan bunu else ve iflerle heryerde tek tek sormak yerine extension methodlarla halletmen gerek. Oncelikle bir extenstions sinifi olustur. Bu sinif icinde boolean olarak bir method olustur. public static bool KarakterSinirinaUyuyormu(this string s) { if(s.Length < 2) return false; else return true; } Ardindan bunu nerede kullanacaksan oraya eklersen global olarak bir extensionun olmus olur. Programin her yerinde bu kurali kullanabilirsin: if(TextBox1.Text.KarakterSinirinaUyuyormu()) 3 Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted April 26, 2016 Author Share Posted April 26, 2016 Hocam, sorunu @SimpsoN_Bart arkadaşın verdiği kodla hallettim. Şuan başka bir sorun baş göstermekte her zaman olduğu gibi Textbox'da keypress olayına takıldım. q,w,x harflerin girişini engelleyemiyorum. Sayı sorununu hallettim ama buna bir türlü çözüm bulamadım. Bu konuda da bir yardımcı olursan o kadar çok mutlu olurum ki anlatamam. Artık projeyi tamamlayıp hocama teslim etmek istiyorum Quote Link to comment Share on other sites More sharing options...
KintaRo Posted April 26, 2016 Share Posted April 26, 2016 private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == char.Parse("q") || e.KeyChar == char.Parse("w") || e.KeyChar == char.Parse("x")) { e.Handled = true; } } 2 Quote Link to comment Share on other sites More sharing options...
Editor mephistooo2 Posted April 26, 2016 Editor Share Posted April 26, 2016 (edited) Kintora üstadın kod önerisine aynen katılıyorum anilguleryuz, ancak neden q, x, w harflerini engelliyorsun, hasta yabancı birisiyse ve isminde de bu üç harften birisi var ise hastaneye nasıl kayıt olacak? Geniş düşünmek lazım Edited April 26, 2016 by mephistooo2 Quote Link to comment Share on other sites More sharing options...
SimpsoN_Bart Posted April 26, 2016 Share Posted April 26, 2016 KintaRo'nun yazdığı çalışıyor fakat case sensitive olayı yok yani büyük harfle yazdığı zaman istediğin gerçekleşmez. Hasta otomasyonu yazıyorsan sadece qwx harfleri değil diğer karakterlerde olmaması gerekir senin için ufak bişey yazdım kendine göre düzenlersin; Sadece Karaktere izin verir; private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { const string NotAllowed = "qxwQXW1234567890~`@#$%^&*()_-+={[}]:;',!.><?/|\\"; if (NotAllowed.IndexOf(e.KeyChar) == -1 == false) { e.Handled = true; } } 1 Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted April 26, 2016 Author Share Posted April 26, 2016 (edited) 12 saat önce, mephistooo2 yazdı: Kintora üstadın kod önerisine aynen katılıyorum anilguleryuz, ancak neden q, x, w harflerini engelliyorsun, hasta yabancı birisiyse ve isminde de bu üç harften birisi var ise hastaneye nasıl kayıt olacak? Geniş düşünmek lazım Hocam, ben ilk başta öyle yaptım. Okuldaki hocamın kıllığı yüzünden kodları tekrar düzenliyorum. Projeyi her gösterdiğimde yeni bir şeyler istiyor. Proje her kontrole giderken bu sefer de q,w,x harfleri girilmesin istendi. O yüzden bende mecburiyetten böyle yapmak zorunda kaldım Edited April 26, 2016 by anilguleryuz İmla Hatası Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted May 1, 2016 Author Share Posted May 1, 2016 Arkadaşlar, tekrar merhaba son bir sorum daha olacaktı datagridview içeriğini nasıl yazdırabilirim, ve nasıl baskı önizlemesini sağlayabilirim bilen var mı acaba? Bütün her şey tamam, bir tek o kaldı. Ne yaptıysam hata verdi ya Dipnot: Datagridview'de access veritabanı var On 26.04.2016 at 12:49, SimpsoN_Bart yazdı: KintaRo'nun yazdığı çalışıyor fakat case sensitive olayı yok yani büyük harfle yazdığı zaman istediğin gerçekleşmez. Hasta otomasyonu yazıyorsan sadece qwx harfleri değil diğer karakterlerde olmaması gerekir senin için ufak bişey yazdım kendine göre düzenlersin; Sadece Karaktere izin verir; private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { const string NotAllowed = "qxwQXW1234567890~`@#$%^&*()_-+={[}]:;',!.><?/|\\"; if (NotAllowed.IndexOf(e.KeyChar) == -1 == false) { e.Handled = true; } } Dostum bu arada yanıtlayamadım, verdiğin kod sorunsuzca çalıştı. Teşekkür ederim Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 2, 2016 Share Posted May 2, 2016 şurada yazdırma ile ilgili güzel bir örnek var: Please register to see this content. Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted May 11, 2016 Author Share Posted May 11, 2016 On 02.05.2016 at 15:34, KintaRo yazdı: şurada yazdırma ile ilgili güzel bir örnek var: Please register to see this content. Teşekkür ederim dostum ilginden dolayı, yazdırma işlemi için crystal reports kullandım. Sorunum ortadan kalktı Quote Link to comment Share on other sites More sharing options...
SimpsoN_Bart Posted May 11, 2016 Share Posted May 11, 2016 Madem report programı kullanacaktın keşke FastReport yada DevExpress kullansaydın CR biraz eskidi arttık Quote Link to comment Share on other sites More sharing options...
anilguleryuz Posted May 11, 2016 Author Share Posted May 11, 2016 (edited) 18 dakika önce, SimpsoN_Bart yazdı: Madem report programı kullanacaktın keşke FastReport yada DevExpress kullansaydın CR biraz eskidi arttık Ben report olayını bilmiyordum bile haliyle acemiyiz daha okuldaki hoca.m bana crystal reportu önerdi biraz araştırınca sorunu çözdüm Edited May 11, 2016 by anilguleryuz Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.