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.Data.OleDb;

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

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(); 
            conn.ConnectionString = @"provider=microsoft.jet.oledb.4.0;" + @"data source=db1.mdb"; 
            conn.Open(); 
            OleDbCommand cmd = new OleDbCommand(); 
            cmd.Connection = conn; 
            cmd.CommandText = "select * from phone"; 
            DataTable dt = new DataTable(); 
            OleDbDataAdapter adapter = new OleDbDataAdapter(); 
            adapter.SelectCommand = cmd; 
            adapter.Fill(dt); 
            dataGridView1.DataSource = dt; 
            dataGridView1.Visible = true; 
            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            frmadd frmadd = new frmadd();
            frmadd.ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            DataGridViewPrinter.DGVPrinter printer = new DataGridViewPrinter.DGVPrinter();
            printer.CellAlignment = StringAlignment.Center;
            printer.CellFormatFlags = StringFormatFlags.DirectionRightToLeft;

            printer.HeaderCellAlignment = StringAlignment.Center;
            printer.HeaderCellFormatFlags = StringFormatFlags.DirectionRightToLeft;
            printer.PageNumberAlignment = StringAlignment.Near;
            printer.PageNumberInHeader = true;
            printer.PageNumberOnSeparateLine = true;
            printer.PageNumbers = true;
            printer.PorportionalColumns = true;

            printer.Title = "عنوان صفحه";
            printer.TitleAlignment = StringAlignment.Center;
            printer.TitleColor = Color.Blue;
            printer.TitleFont = new Font("Arial", 14);
            printer.TitleFormatFlags = StringFormatFlags.DirectionRightToLeft;

            printer.SubTitle = " ";
            printer.SubTitleAlignment = StringAlignment.Center;
            printer.SubTitleColor = Color.Blue;
            printer.SubTitleFont = new Font("Arial", 14);
            printer.SubTitleFormatFlags = StringFormatFlags.DirectionRightToLeft;

            //printer.Footer = "Footer";
            //printer.FooterAlignment = StringAlignment.Center;
            //printer.FooterColor = Color.Blue;
            //printer.FooterFont = new Font("Arial", 14);
            //printer.FooterFormatFlags = StringFormatFlags.DirectionRightToLeft;
            //printer.FooterSpacing = 10;

            printer.PrintPreviewDataGridView(dataGridView1);

            this.Cursor = Cursors.Default;
        }

      


    }
}
