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;


namespace HotelProject
{
    public partial class FrmGetService : Form
    {
        public FrmGetService()
        {
            InitializeComponent();
        }

        SqlConnection con;
        public int CustomerID;
        public string Sum= "";


        private void FrmGetService_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("Server = .\\SQLEXPRESS ; DataBase = DbHotel ; Integrated Security = True");
            SqlDataAdapter da = new SqlDataAdapter("SelectAllServices", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

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

            GrdServices.DataSource = dt;

        }

        private void BtnOk_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(TxtTedad.Text))
                errorProvider1.SetError(TxtTedad, "تعداد را وارد کنید");
            else
            {
                errorProvider1.SetError(TxtTedad, "");
                SqlCommand cmd = new SqlCommand("GiveService", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CustomerID", CustomerID);
                cmd.Parameters.AddWithValue("@Tedad", TxtTedad.Text);
                cmd.Parameters.AddWithValue("@ServiceCost", GrdServices.CurrentRow.Cells[2].Value.ToString());
                cmd.Parameters.AddWithValue("@Sum", Convert.ToInt32(GrdServices.CurrentRow.Cells[2].Value.ToString()) * Convert.ToInt32(TxtTedad.Text));
                cmd.Parameters.AddWithValue("@ServiceName", GrdServices.CurrentRow.Cells[1].Value.ToString());

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

                //''''''''''''''''''


                SqlDataAdapter da = new SqlDataAdapter("GetSum", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.AddWithValue("@CustomerID", CustomerID);
                DataTable dt = new DataTable();
                da.Fill(dt);

                Sum = dt.Rows[0][0].ToString();
                



                
                //'''''''''''''''
                cmd = new SqlCommand("EditSum", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CustomerID", CustomerID);
                cmd.Parameters.AddWithValue("@Sum", Convert.ToInt32(Sum) + Convert.ToInt32(GrdServices.CurrentRow.Cells[2].Value.ToString()) * Convert.ToInt32(TxtTedad.Text));

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


                Sum = Convert.ToString(Convert.ToInt32(Sum) + Convert.ToInt32(GrdServices.CurrentRow.Cells[2].Value.ToString()) * Convert.ToInt32(TxtTedad.Text));
                    
                this.Close();





            }
        }

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