C# ile Raporlama

C# ile prinpreviewdialog ve printdocument nesnesi ile yapılan raporlama örneği…

pri1 pri2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

C# Kodları

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace raporlama
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

SqlConnection conn = new SqlConnection(“Data Source=.\\SQLEXPRESS; Initial Catalog=ogrenci; Integrated Security=true;”);
private void textBox4_TextChanged(object sender, EventArgs e)
{
int vize, final;
double ortalama;
vize = Convert.ToInt16(textBox5.Text);
final = Convert.ToInt16(textBox4.Text);
ortalama=(vize*0.4)+(final*0.6);
textBox6.Text = ortalama.ToString();
if (ortalama > 60)
textBox7.Text = “Başarılı”;
else
textBox7.Text = “Başarısız”;
}

private void button1_Click(object sender, EventArgs e)
{
conn.Open();
string sorgu = “insert into ogrencibilgi (OgrNo, Ad,Soyad,Vize,Final,Ortalama,Durum) values(‘” + textBox1.Text + “‘,'” + textBox2.Text + “‘,'” + textBox3.Text + “‘,” + textBox5.Text + “,” + textBox4.Text + “,” + textBox6.Text + “,'” + textBox7.Text + “‘)”;
SqlCommand cmd = new SqlCommand(sorgu,conn);
cmd.ExecuteNonQuery();
MessageBox.Show(“Ekleme İşlemi Başarılı….”);
conn.Close();
}

private void button2_Click(object sender, EventArgs e)
{
conn.Open();
string sorgu = “select * from ogrencibilgi where OgrNo='”+textBox8.Text+”‘”;
SqlDataAdapter adp = new SqlDataAdapter(sorgu, conn);
DataSet ds = new DataSet();
adp.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}

Font baslik = new Font(“Verdana”, 12, FontStyle.Bold);
Font govde = new Font(“Verdana”, 12);
SolidBrush sb = new SolidBrush(Color.Black);

private void button3_Click(object sender, EventArgs e)
{
printPreviewDialog1.ShowDialog();
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
StringFormat sFormat = new StringFormat();
sFormat.Alignment = StringAlignment.Near;
e.Graphics.DrawString(“CELAL BAYAR ÜNİVERSİTESİ”, baslik, sb, 270, 70);
e.Graphics.DrawString(“AKHİSAR MESLEK YÜKSEKOKULU”, baslik, sb, 250, 90);
e.Graphics.DrawString(“Öğrenci Başarı Bilgi Formu”, baslik, sb, 280, 110);

e.Graphics.DrawString(dataGridView1.Rows[0].Cells[0].Value.ToString(), govde, sb, 70, 180);
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[1].Value.ToString(), govde, sb, 85, 180);
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[2].Value.ToString(), govde, sb, 150, 180);
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[3].Value.ToString(), govde, sb, 250, 180);
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[4].Value.ToString(), govde, sb, 300, 180);
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[5].Value.ToString(), govde, sb, 350, 180);
e.Graphics.DrawString(dataGridView1.Rows[0].Cells[6].Value.ToString(), govde, sb, 400, 180);

}
}
}

 

 

 

admin