1-) C# RMOS - ElasticSearch gibi lookUpEdit doldurma
açıklama : textbox'ı lookupeditin üstüne koy sanki oymuş gibi event olayında diğerini değiştir bu sayede o şekilde gözükecektir
proje linki :
https://drive.google.com/file/d/1hVWFQKv9B0QEQsO9umF7bZYiO357pASd/view?usp=sharing
using System;
using System.Data;
using System.Windows.Forms;
namespace ElastikKompanent
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
lookUpEdit1.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("not_basligi","Konu Başlığı"));
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
{
lookUpEdit1.Focus();
lookUpEdit1_KeyDown(null, e);
}
else
{
araElastik(sender, false);
}
}
public void araElastik(object sender, bool mousemi)
{
TextBox grid = sender as TextBox;
string text = grid.Text;
DataTable dt = RHVeritabani.MyGetDataTable(@"select top 10 not_id,not_basligi,not_icerik,cins_adi from notlar
left join cinsler on cinsler.cins_id=notlar.not_cins_id
where not_basligi like '%"+ text + "%' or not_icerik like '%"+ text + "%' or cins_adi like '%"+ text + "%' order by not_id desc");
lookUpEdit1.Properties.DataSource = dt;
lookUpEdit1.Properties.ValueMember = "not_id";
lookUpEdit1.Properties.DisplayMember = "not_basligi";
if (secildi == true)
{
lookUpEdit1.ClosePopup();
}
else
{
lookUpEdit1.ShowPopup();
}
if (mousemi == false && text.Equals(""))
{
lookUpEdit1.Properties.DataSource = null;
lookUpEdit1.Text = "";
lookUpEdit1.EditValue = "";
}
secildi = false;
}
bool secildi = false;
private void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
secildi = true;
//textBox1.Text = ""; // !! İKİ ÜNLEM KOYDUYSAM BUNLARI YORUM SATIRINDAN KALDIRABİLİRSİN İKİ ÜNLEM OLAN HEPSİNDEN
//textBox1.AppendText(lookUpEdit1.Text);// !! İKİ ÜNLEM KOYDUYSAM BUNLARI YORUM SATIRINDAN KALDIRABİLİRSİN İKİ ÜNLEM OLAN HEPSİNDEN
textBox1.Focus();
textBox2.Text = lookUpEdit1.EditValue.ToString();
}
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
secildi = false;
araElastik(sender, true);
}
private void textBox1_Leave(object sender, EventArgs e)
{
// textBox1.Text = lookUpEdit1.Text;// !! İKİ ÜNLEM KOYDUYSAM BUNLARI YORUM SATIRINDAN KALDIRABİLİRSİN İKİ ÜNLEM OLAN HEPSİNDEN
//if (textBox1.Text.Equals("")) // projedeki iki ünlemleri yorum satırından kaldırırsan bu if ve içini sil
//{
// lookUpEdit1.Properties.DataSource = null;
// lookUpEdit1.Text = "";
//}
}
private void lookUpEdit1_KeyDown(object sender, KeyEventArgs e)
{
}
}
}
2-) ESKİSİ
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
TextBox grid = sender as TextBox;
string text = grid.Text;
DataTable dt = RHVeritabani.MyGetDataTable("select top 10 rec_id,aciklama from arizalar where aciklama like '%" + text + "%'");
lookUpEdit2.Properties.DataSource = dt;
lookUpEdit2.Properties.ValueMember = "rec_id";
lookUpEdit2.Properties.DisplayMember = "aciklama";
lookUpEdit2.ShowPopup();
}
// aşağıyı yapmasan daha iyi olabilir sana kalmış
private void lookUpEdit2_EditValueChanged(object sender, EventArgs e) {
textBox1.Text = lookUpEdit2.Text;
}
3-) EN YENİSİ
using System;
using System.Data;
using System.Windows.Forms;
namespace ElastikKompanent
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
lookUpEdit1.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("not_basligi", "Konu Başlığı"));
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
{
lookUpEdit1.Focus();
lookUpEdit1_KeyDown(null, e);
}
else
{
araElastik(sender, false);
}
}
public string parseGetSql(string arananColumn, string[] arananDeger)
{
string kosul = " and ";
string text = "";
foreach (var item in arananDeger)
{
if (!item.Equals(""))
{
text = text + " "+ arananColumn + " like '%" + item + "%'"+kosul;
}
}
if (text.Contains(kosul))
{
int index = text.LastIndexOf(kosul);
text = text.Substring(0, index);
}
return text;
}
public void araElastik(object sender, bool mousemi)
{
TextBox grid = sender as TextBox;
string text = grid.Text.Trim();
string sorgu = ""; // SEN SORGUNU KISALTABİLİRSİN ONEMLİ DEĞİL
if (text.Equals(""))
{
sorgu = @"select top 10 * from notlar
left join cinsler on cinsler.cins_id=notlar.not_cins_id
where not_basligi like '%" + text + "%' or not_icerik like '%" + text + "%' or cins_adi like '%" + text + "%' order by not_id desc";
}
else if (text.Length > 2 && text.Contains(" ")) // en az üç karakter ise
{
string[] splits = text.Split(' ');
sorgu = @"select * from notlar left join cinsler on cinsler.cins_id=notlar.not_cins_id where ";
sorgu = sorgu + "("+ parseGetSql("not_basligi", splits) + ") or (" + parseGetSql("cins_adi", splits) + ") or (" + parseGetSql("not_icerik", splits) + ")";
}
else
{
sorgu = @"select top 10 * from notlar
left join cinsler on cinsler.cins_id=notlar.not_cins_id
where not_basligi like '%" + text + "%' or not_icerik like '%" + text + "%' or cins_adi like '%" + text + "%' order by not_id desc";
}
DataTable dt = RHVeritabani.MyGetDataTable(sorgu);
lookUpEdit1.Properties.DataSource = dt;
lookUpEdit1.Properties.ValueMember = "not_id";
lookUpEdit1.Properties.DisplayMember = "not_basligi";
if (secildi == true)
{
lookUpEdit1.ClosePopup();
}
else
{
lookUpEdit1.ShowPopup();
}
if (mousemi == false && text.Equals(""))
{
lookUpEdit1.Properties.DataSource = null;
lookUpEdit1.Text = "";
lookUpEdit1.EditValue = "";
}
secildi = false;
}
bool secildi = false;
private void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
{
secildi = true;
//textBox1.Text = ""; // !! İKİ ÜNLEM KOYDUYSAM BUNLARI YORUM SATIRINDAN KALDIRABİLİRSİN İKİ ÜNLEM OLAN HEPSİNDEN
//textBox1.AppendText(lookUpEdit1.Text);// !! İKİ ÜNLEM KOYDUYSAM BUNLARI YORUM SATIRINDAN KALDIRABİLİRSİN İKİ ÜNLEM OLAN HEPSİNDEN
textBox1.Focus();
textBox2.Text = lookUpEdit1.EditValue.ToString();
}
private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
secildi = false;
araElastik(sender, true);
}
private void textBox1_Leave(object sender, EventArgs e)
{
// textBox1.Text = lookUpEdit1.Text;// !! İKİ ÜNLEM KOYDUYSAM BUNLARI YORUM SATIRINDAN KALDIRABİLİRSİN İKİ ÜNLEM OLAN HEPSİNDEN
//if (textBox1.Text.Equals("")) // projedeki iki ünlemleri yorum satırından kaldırırsan bu if ve içini sil
//{
// lookUpEdit1.Properties.DataSource = null;
// lookUpEdit1.Text = "";
//}
}
private void lookUpEdit1_KeyDown(object sender, KeyEventArgs e)
{
}
}
}