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.SqlClient;
using System.Globalization;


namespace HotelProject
{
    public partial class FrmReportKhoruji : Form
    {
        DateTime today = DateTime.Now;
        PersianCalendar pc = new PersianCalendar();
        SqlConnection con;

        public FrmReportKhoruji()
        {
            InitializeComponent();
        }

        private void FrmReportKhoruji_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("Server = . ; DataBase = DbHotel ; Integrated Security = True");
            rdbSpecialDay_CheckedChanged(null, null);

        }

        private void rdbSpecialDay_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbSpecialDay.Checked == true)
            {
                MskOneDate.Enabled = true;
                MskDate1.Enabled = false;
                MskDate2.Enabled = false;


                String StrDate = pc.GetYear(today).ToString("0000") + pc.GetMonth(today).ToString("00") + pc.GetDayOfMonth(today).ToString("00");
                MskOneDate.Text = StrDate;

            }
        }

        private void RbdBetween_CheckedChanged(object sender, EventArgs e)
        {
            if (RbdBetween.Checked == true)
            {
                MskOneDate.Enabled = false;
                MskDate1.Enabled = true;
                MskDate2.Enabled = true;


                String StrDate = pc.GetYear(today).ToString("0000") + pc.GetMonth(today).ToString("00") + pc.GetDayOfMonth(today).ToString("00");
                MskDate2.Text = StrDate;
            }
        }

        private void ImgPrint_Click(object sender, EventArgs e)
        {
            if (rdbSpecialDay.Checked == true)
            {

                if (MskOneDate.MaskFull.ToString() == "False")
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(MskOneDate, "تاریخ را کامل وارد کنید");
                    return;
                }


                SqlDataAdapter da = new SqlDataAdapter("ReportOneDateKhoruji", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.AddWithValue("@Date", MskOneDate.Text);
                DataTable DtResult = new DataTable();
                da.Fill(DtResult);

                stiReport1.Load("stiReportKhoruji.mrt");
                stiReport1.RegData(DtResult);
                stiReport1.Show();




            }
            else
            {

                if (MskDate1.MaskFull.ToString() == "False")
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(MskDate1, "تاریخ را کامل وارد کنید");
                    return;
                }

                if (MskDate2.MaskFull.ToString() == "False")
                {
                    errorProvider1.Clear();
                    errorProvider1.SetError(MskDate2, "تاریخ را کامل وارد کنید");
                    return;
                }

                SqlDataAdapter da = new SqlDataAdapter("ReportBetweenKhoruji", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.AddWithValue("@date1", MskDate1.Text);
                da.SelectCommand.Parameters.AddWithValue("@date2", MskDate2.Text);

                DataTable DtResult = new DataTable();
                da.Fill(DtResult);

                stiReport1.Load("stiReportKhoruji.mrt");
                stiReport1.RegData(DtResult);
                stiReport1.Show();

            }
        }
    }
}
