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 FrmPaziresh : Form
    {
        public FrmPaziresh()
        {
            InitializeComponent();
        }

         SqlConnection con;
         string Roomtype = "";

        private void BtnAdd_Click(object sender, EventArgs e)
        {
            TxtHamrah.Enabled = true;
            TxtName.Enabled = true;
         //  TxtRoomNum.Enabled = false;
            TxtMadrak.Enabled = true;
            TxtPish.Enabled = true;
            MskBdate.Enabled = true;
            BtnAdd.Enabled = false;
            BtnCancel.Enabled = true;
            BtnSave.Enabled = true;
            BtnRoom.Enabled = true;
            BtnDate.Enabled = true;
            TxtHamrah.Text = "";
            TxtName.Text = "";
            TxtMadrak.Text = "بدون مدرک";
            TxtPish.Text = "0";
            TxtRoomNum.Text = "";
            MskBdate.Text = "";


        }

        private void FrmPaziresh_Load(object sender, EventArgs e)
        {

        }

        private void BtnSave_Click(object sender, EventArgs e)
        {

            if (String.IsNullOrWhiteSpace(TxtName.Text))
            {
                errorProvider1.Clear();
                errorProvider1.SetError(TxtName, "نام مشتری را وارد کنید");
            }
            else if (String.IsNullOrWhiteSpace(TxtHamrah.Text))
            {
                errorProvider1.Clear();
                errorProvider1.SetError(TxtHamrah, "تعداد همراه را وارد کنید");
            }
            else if (String.IsNullOrWhiteSpace(TxtMadrak.Text))
            {
                errorProvider1.Clear();
                errorProvider1.SetError(TxtMadrak, "مدرک را وارد کنید");
            }

                else if (String.IsNullOrWhiteSpace(TxtPish.Text))
            {
                errorProvider1.Clear();
                errorProvider1.SetError(TxtPish, "مبلغ پیش پرداخت را وارد کنید");
            }
            else if (String.IsNullOrWhiteSpace(TxtRoomNum.Text))
            {
                errorProvider1.Clear();
                errorProvider1.SetError(TxtRoomNum, "شماره اتاق را وارد کنید");
            }
                
                 else if (MskBdate.MaskFull.ToString() == "False")
            {
                errorProvider1.Clear();
                errorProvider1.SetError(MskBdate, "تاریخ را کامل وارد کنید");
            }
         

            else
            {
                errorProvider1.Clear();
                 con = new SqlConnection("Server = .\\SQLEXPRESS ; DataBase = DbHotel ; Integrated Security = True");
           
                SqlCommand cmd = new SqlCommand("NewPaziresh", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Name", TxtName.Text);
                cmd.Parameters.AddWithValue("@TedadHamrah", TxtHamrah.Text);
                cmd.Parameters.AddWithValue("@RoomNum", TxtRoomNum.Text);
                cmd.Parameters.AddWithValue("@RoomType",Roomtype);
                cmd.Parameters.AddWithValue("@BDate", MskBdate.Text);
                cmd.Parameters.AddWithValue("@EDate", "");
                cmd.Parameters.AddWithValue("@Madrak", TxtMadrak.Text);
                cmd.Parameters.AddWithValue("@PishPardakht", TxtPish.Text);
                cmd.Parameters.AddWithValue("@MajmuHazine","0");




                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();



                cmd = new SqlCommand("UpdateRoomState", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@RoomNumber", TxtRoomNum.Text);
                cmd.Parameters.AddWithValue("@State","پر");

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();


             

                FrmMessage Fm = new FrmMessage();
                Fm.LblText.Text = "پذیرش با موفقیت انجام شد";
                Fm.PicClose.Visible = true;
                Fm.PicNO.Visible = false;
                Fm.PicYes.Visible = false;
                Fm.ShowDialog();

            TxtHamrah.Enabled = false;
            TxtName.Enabled = false;
         //  TxtRoomNum.Enabled = false;
            TxtMadrak.Enabled = false;
            TxtPish.Enabled = false;
            MskBdate.Enabled = false;
            BtnAdd.Enabled = true;
            BtnCancel.Enabled = false;
            BtnSave.Enabled = false;
            BtnRoom.Enabled = false;
            BtnDate.Enabled = false;
            //TxtHamrah.Text = "";
           // TxtName.Text = "";
           // TxtMadrak.Text = "بدون مدرک";
           // TxtPish.Text = "0";
           // TxtRoomNum.Text = "";
           // MskBdate.Text = "";
            }
        }

        private void BtnDate_Click(object sender, EventArgs e)
        {
            DateTime today = DateTime.Now;
            PersianCalendar pc = new PersianCalendar();
            String StrDate = pc.GetYear(today).ToString("0000") + pc.GetMonth(today).ToString("00") + pc.GetDayOfMonth(today).ToString("00");
            MskBdate.Text = StrDate;

        }

        private void BtnRoom_Click(object sender, EventArgs e)
        {
            FrmRooms fr = new FrmRooms();
            fr.ShowDialog();
            TxtRoomNum.Text = fr.RoomNumber;
            Roomtype = fr.RoomType;

        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            TxtHamrah.Enabled = false;
            TxtName.Enabled = false;
            //  TxtRoomNum.Enabled = false;
            TxtMadrak.Enabled = false;
            TxtPish.Enabled = false;
            MskBdate.Enabled = false;
            BtnAdd.Enabled = true;
            BtnCancel.Enabled = false;
            BtnSave.Enabled = false;
            BtnRoom.Enabled = false;
            BtnDate.Enabled = false;
            TxtHamrah.Text = "";
            TxtName.Text = "";
            TxtMadrak.Text = "";
            TxtPish.Text = "";
            TxtRoomNum.Text = "";
            MskBdate.Text = "";
        }

        private void TxtHamrah_TextChanged(object sender, EventArgs e)
        {
            NumCorrection.DoCorrection(TxtHamrah);
            System.Globalization.CultureInfo language = new System.Globalization.CultureInfo("en-us");
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(language);
        }

        private void TxtPish_TextChanged(object sender, EventArgs e)
        {

        }
        
    }
}
