הדפסות

image

 

[sourcecode language='csharp'  padlinenumbers='true']
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace ErezPrint
{
    public partial class Main : Form
    {
        dbEntities db = new dbEntities();
        public Main()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            var tmp = (from s in db.user select s).ToList();
            dataGridView1.DataSource = tmp;


        }

        private void button1_Click(object sender, EventArgs e)
        {
            user u1 = new user();
            u1.Name = "user" + (char) DateTime.Now.Second;
            u1.value = DateTime.Now.Minute;
            u1.pass = DateTime.Now.Millisecond.ToString();
            db.user.AddObject(u1);
            db.SaveChanges();
            MessageBox.Show("עודכן בהצלחה");
            Main_Load(sender, e);

        }

       

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics G = e.Graphics;
            Font messageFont = new Font("Arial", 18, System.Drawing.GraphicsUnit.Point);
            G.PageUnit = GraphicsUnit.Millimeter;
            String Message = "דוח משתמשים";
            StringFormat format = new StringFormat(StringFormatFlags.DirectionRightToLeft);
            G.DrawString(Message, messageFont, Brushes.Blue, 120, 25, format);
            int row = 40;
            G.DrawString("שם             ערך         סיסמה", messageFont, Brushes.Blue, 160, row, format);
            var tmp = (from s in db.user select s).ToList();
            foreach (user x in tmp)
            {
                row += 10;
                G.DrawString(x.Name, messageFont, Brushes.Blue, 160, row, format);
                G.DrawString(x.value.ToString(), messageFont, Brushes.Blue, 140, row, format);
                G.DrawString(x.pass.ToString(), messageFont, Brushes.Blue, 120, row, format);
            }
            Image newImage = Properties.Resources.Winter;
            Point ul = new Point(5, 5);
            Point ur = new Point(200, 5);
            Point ll = new Point(5, 25);
            Point[] dest = { ul, ur, ll };
            G.DrawImage(newImage, dest);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.ShowDialog();
        }
    }
}
[/sourcecode]