using Stimulsoft.Report;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls.UI;

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

        private void Form1_Load(object sender, EventArgs e)
        {
          //  radGridView1.Columns.Add(new GridViewCheckBoxColumn() { Name = "Col1", HeaderText = "انتخاب" });
            radGridView1.Columns.Add(new GridViewTextBoxColumn() { Name = "Col2", HeaderText = "کد", FieldName = "Code" });
            radGridView1.Columns.Add(new GridViewTextBoxColumn() { Name = "Col3", HeaderText = "نام", FieldName = "FirstName" });
            radGridView1.Columns.Add(new GridViewTextBoxColumn() { Name = "Col4", HeaderText = "نام خانوادگی", FieldName = "LastName" });
            radGridView1.Columns.Add(new GridViewTextBoxColumn() { Name = "Col5", HeaderText = "موبایل", FieldName = "Mobile" });

            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=.;Initial Catalog=dbTest;Integrated Security=True";
            SqlCommand cmd = new SqlCommand("select * from tblPerson", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);

            radGridView1.DataSource = dt;
 
        }

        private void button1_Click(object sender, EventArgs e)
        {
 


        }

        private void radButton5_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("Code", typeof(string)));
            dt.Columns.Add(new DataColumn("FirstName", typeof(string)));
            dt.Columns.Add(new DataColumn("LastName", typeof(string)));
            dt.Columns.Add(new DataColumn("Mobile", typeof(string)));

            int dtRow = 0;
            for(int i=0;i<=radGridView1.RowCount-1;i++)
            {
                if(radGridView1.Rows[i].IsSelected)
                {
                    dt.Rows.Add();
                    dt.Rows[dtRow][0] = radGridView1.Rows[i].Cells[0].Value;
                    dt.Rows[dtRow][1] = radGridView1.Rows[i].Cells[1].Value;
                    dt.Rows[dtRow][2] = radGridView1.Rows[i].Cells[2].Value;
                    dt.Rows[dtRow][3] = radGridView1.Rows[i].Cells[3].Value;
                    dtRow += 1;
                }
            }

            if(dt.Rows.Count>0)
            {
                StiReport stiReport = new StiReport();
                stiReport.Load(Application.StartupPath + "\\Report.mrt");
                stiReport.RegBusinessObject("Person", dt);
                stiReport.Show();
            }
        }
    }
}
