Devexpress kullanımında gridview kullanırken setgridvalue kullanmak yerine datatableda gerekli değişiklikleri yaptıktan sonra gridccontrolun datasourceunu datatablea eşitlemek daha sorunsuz olur. Sebebi gridview count kullanırken bazı değerleri setgridvalueda atmamakta ama filtreleyince atmakta.
Tag: visual c#
EXCEPTION WRITE TO LOG
public void WRITELOG(string ERROR, Exception E, int TYPE)
{
try
{
string directory = AppDomain.CurrentDomain.BaseDirectory + "logs\\";
Directory.CreateDirectory(directory);
string EXTENTION = "";
if (TYPE == 0)
EXTENTION = " - ERRORS";
else if (TYPE == 1)
EXTENTION = " - STATUS";
else if (TYPE == 2)
EXTENTION = " - EXPS";
string path = directory + DateTime.Now.ToString("yyyy.MM.dd" + EXTENTION) + ".txt";
if (!File.Exists(path))
File.Create(path).Close();
else
{
if (TYPE > 0 || E == null)
File.AppendAllText(path, Environment.NewLine);
else
File.AppendAllText(path, Environment.NewLine + Environment.NewLine +
Environment.NewLine + Environment.NewLine + Environment.NewLine);
}
File.AppendAllText(path, DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss") + " : " + ERROR +
Environment.NewLine + (E != null ? " ----- HATA : ----- " + E.ToString() : ""));
}
catch { }
}
Aspxgridview selected ve toplu işlemleri
--aşağıdaki kod bütün seçili rowlara işlem yapar
List SelectedUsers = grid.GetSelectedFieldValues(new string[] { "ID", "TUTAR" });
foreach (object user in SelectedUsers)
{
IList items = user as IList;
if (items == null) return;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CarringtonWebConnectionString1"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("update ACIKHESAP set ODEME_DURUMU=1, ODENEN_TUTAR=" + items[1].ToString() + " where ID=" + items[0].ToString(), con);
cmd.ExecuteNonQuery();
}
---aşağıdaki kod seçili seçili deil farketmez hepsine işlem yapar
for (int i = 0; i < grid.VisibleRowCount; i++)
{
var items = grid.GetRowValues(i, new string[] { "ID", "TUTAR" }) as object[];
// ASPxListBox1.Items.Add(rowValues[0].ToString());
//you can add these key in a list here
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CarringtonWebConnectionString1"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("update ACIKHESAP set ODEME_DURUMU=2, ODENEN_TUTAR=" + items[1].ToString() + " where ID=" + items[0].ToString(), con);
cmd.ExecuteNonQuery();
VISUAL C# SQL AYNI KOD VARMI KONTROL
private void button3_Click(object sender, EventArgs e)
{
SqlConnection sqlConnection = new SqlConnection("Server = " + logoserver + "; Database = " + logodb + "; User Id = " + logouser + "; Password = " + logopass);
using (SqlCommand sqlCommand = new SqlCommand("SELECT COUNT(*) from ZV_LOGO_HASTA where KODU = 112", sqlConnection))
{
sqlConnection.Open();
int userCount = (int)sqlCommand.ExecuteScalar();
if (userCount > 0)
{
MessageBox.Show("BU KOD VAR");
}
else MessageBox.Show("BU KOD YOK");
}
sqlConnection.Close();
}
Visual studio c# dlleri projene exeye gömme
projeyi ac solution exlporerda en yukarı sag tıkla manage nuget packetse bas yada
view others package manager consola bunu yaz indirsin Install-Package Costura.Fody
indirdikten sonra dllerin exele gömülü olur
view others package manager consola bunu yaz indirsin Install-Package Costura.Fody
indirdikten sonra dllerin exele gömülü olur
Visual c# ms sql database çifte kontrol
SqlConnection connectionString = new SqlConnection("Server = " + ondegerler.SQLBAGLANTISI_KAYNAK + "; Database = " + ondegerler.SQLBAGLANTISI_VERITABANI + "; User Id = " + ondegerler.SQLBAGLANTISI_KULLANICI + "; Password = " + ondegerler.SQLBAGLANTISI_PAROLA);
connectionString.Open();
{
SqlCommand sqlcom2 = new SqlCommand("select count(malzeme_kodu) from tbl_malzeme where tbl_malzeme.malzeme_kodu = '" + Text_malzeme_kodu.Text + "'", connectionString);
if (sqlcom2.ExecuteScalar() != null)
{
int UserExist = (int)sqlcom2.ExecuteScalar();
if (UserExist > 0)
{
MessageBox.Show("Bu İsimde Malzeme Kodu Daha Önceden Yaratılmıştır!");
}
}
visual c# update ms sql table from query inside txt file
// MessageBox.Show(Text_malzeme_grubu.EditValue.ToString());
// string connectionString = null;
SqlConnection connectionString = new SqlConnection("Server = " + ondegerler.SQLBAGLANTISI_KAYNAK + "; Database = " + ondegerler.SQLBAGLANTISI_VERITABANI + "; User Id = " + ondegerler.SQLBAGLANTISI_KULLANICI + "; Password = " + ondegerler.SQLBAGLANTISI_PAROLA);
connectionString.Open();
FileInfo file = new FileInfo(Application.StartupPath + "\\tbl_cari_kartlari_duzenle_kaydet.txt");
string duzenle = file.OpenText().ReadToEnd();
//MessageBox.Show(silinecekkod.ToString());
SqlCommand sqlcom = new SqlCommand(duzenle, connectionString);
sqlcom.Parameters.AddWithValue("@cari_turu", Text_cari_turu.Text.Trim());
sqlcom.Parameters.AddWithValue("@cari_adi", Text_cari_adi.Text.Trim());
sqlcom.Parameters.AddWithValue("@irtibat", Text_irtibat.Text.Trim());
sqlcom.Parameters.AddWithValue("@adres", Text_adres.Text.Trim());
sqlcom.Parameters.AddWithValue("@paremetre", text_paremetre.Text.Trim());
sqlcom.Parameters.AddWithValue("@cari_kodu", Text_cari_kodu.Text.Trim());
sqlcom.ExecuteNonQuery();
connectionString.Close();
MessageBox.Show("Cari Başarıyla Düzenlendi!", "CARİ KARTI DÜZENLEME", MessageBoxButtons.OK, MessageBoxIcon.Information);
/*txt file =*/
update tbl_cariler
set cari_turu=@cari_turu , cari_adi = @cari_adi ,irtibat=@irtibat , adres = @adres, paremetre = @paremetre
where cari_kodu = @cari_kodu
gridview connect to ms sql with txt file query and get data to gridview with summary
string connectionString = null;
SqlConnection cnn;
connectionString = "Server = " + ondegerler.SQLBAGLANTISI_KAYNAK + "; Database = " + ondegerler.SQLBAGLANTISI_VERITABANI + "; User Id = " + ondegerler.SQLBAGLANTISI_KULLANICI + "; Password = " + ondegerler.SQLBAGLANTISI_PAROLA;
FileInfo file = new FileInfo(Application.StartupPath + "\\tbl_cariler.txt");
string script = file.OpenText().ReadToEnd();
cnn = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(script, cnn);
DataTable dt = new DataTable();
da.Fill(dt);
gridControl1.DataSource = dt;
gridView1.Columns[1].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
gridView1.Columns[1].SummaryItem.DisplayFormat = "Adet = {0}";
gridView1.Columns["Bakiye"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
gridView1.Columns["Bakiye"].SummaryItem.DisplayFormat = "Toplam = {0}";
gridView1.BestFitColumns();
Devexpress grid databar
GridFormatRule gridFormatRule = new GridFormatRule();
FormatConditionRuleDataBar formatConditionRuleDataBar = new FormatConditionRuleDataBar();
gridFormatRule.Column = gridView1.Columns[“Bakiye”];
formatConditionRuleDataBar.PredefinedName = “Blue Gradient”;
gridFormatRule.Rule = formatConditionRuleDataBar;
this.gridView1.FormatRules.Add(gridFormatRule);
FormatConditionRuleDataBar formatConditionRuleDataBar = new FormatConditionRuleDataBar();
gridFormatRule.Column = gridView1.Columns[“Bakiye”];
formatConditionRuleDataBar.PredefinedName = “Blue Gradient”;
gridFormatRule.Rule = formatConditionRuleDataBar;
this.gridView1.FormatRules.Add(gridFormatRule);
Devexpress gridview export to excel with savefiledialog
string filename;
saveFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.ShowDialog();
filename = saveFileDialog1.FileName;
if (filename == "") filename = "";
else
{
gridView1.ExportToXlsx(filename);
System.Diagnostics.Process.Start(filename);
}
