
using Shop.Context;
using Stimulsoft.Report;
using Stimulsoft.Report.BarCodes;
using Stimulsoft.Report.Components;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shop
{
    public partial class AddOrder : Form
    {
        private readonly ShopContext shopContext;
        public AddOrder(ShopContext shopContext)
        {
            InitializeComponent();
            this.shopContext = shopContext;
        }




        private void BtnNewOrder_Click(object sender, EventArgs e)
        {


        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Email");

       foreach(DataGridViewRow row in dataGridView1.Rows)
            {
                dataTable.Rows.Add
                    (
                    row.Cells[1].Value.ToString(),
                    row.Cells[2].Value.ToString()
                    );
            }

            PersianCalendar persianCalendar = new PersianCalendar();
            string date = persianCalendar.GetYear(DateTime.Now).ToString() + "/" + persianCalendar.GetMonth(DateTime.Now).ToString() + "/" + persianCalendar.GetDayOfMonth(DateTime.Now).ToString();
            StiReport stiReport = new StiReport();
            stiReport.Load(Application.StartupPath + "\\TestReport.mrt");
            stiReport.Compile();

            StiComponentsCollection stiComponentsCollection = stiReport.GetComponents();

            foreach (StiComponent component in stiComponentsCollection)
            {
                if (component.Name == "Text6")
                {
                    StiText stiText = component as StiText;

                    stiText.Text.Value = "مقدار جدید این کامپونتت";
                }

                if (component.Name == "BarCode1")
                {
                    StiBarCode stiBarCode = component as StiBarCode;
                    StiBarCodeExpression stiexp = new StiBarCodeExpression();
                    stiexp.Value = "EFG567";
                    stiBarCode.Code = stiexp;
                }

                if (component.Name == "QrCode1")
                {
                    StiBarCode qrCode = component as StiBarCode;
                    StiBarCodeExpression stiexp2 = new StiBarCodeExpression();
                    stiexp2.Value = "https://shaya-soft.ir/";
                    qrCode.Code = stiexp2;
                }
            }

            stiReport["img"] = Image.FromFile("C:\\Users\\User\\Pictures\\len.jpg");
            stiReport["Title"] = "نرم افزار فروشگاه من";
            stiReport["Date"] = date;
            stiReport["Time"] = DateTime.Now.ToString("HH:mm:ss");
            stiReport.RegData("DataTable", dataTable);

            stiReport.Render();
            stiReport.Show();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void AddOrder_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = shopContext.Users.ToList();

        }
    }
}
