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.Windows.Forms;

namespace Reservtion
{
    public partial class AddCustomerServiceingSummary : Form
    {
        string customerCode, serviceCode, employeeCode, price, priceExpl, expl, servicePrice;
        int tPrice;
        DateTime date;
        RConection r;
        public AddCustomerServiceingSummary(RConection r1, string cc, string sc, string ec,string sp, string f, string p, string pe, string e,DateTime d)
        {
            InitializeComponent();
            int i=0;
            while (sp[i] != '.')
                i++;
            tPrice = (int.Parse(p) + int.Parse(sp.Substring(0, i)));
            richTextBox1.Text = f;
            richTextBox1.Text += "هزینه مازاد: " + p + "\n" + pe + "\n" + "هزینه کل: " + tPrice.ToString() + "\n\n" + "توضیحات:\n" + e;
            customerCode = cc;
            serviceCode = sc;
            employeeCode = ec;
            servicePrice = sp;
            price = p;
            priceExpl = pe;
            expl = e;
            date = d;
            r = r1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            object o;
            int m;
            try
            {
                r.cmd.CommandText = "SELECT MAX(Code) FROM RequestService";
                r.conn.Open();
                o = r.cmd.ExecuteScalar();
                if (o == DBNull.Value)
                    m = 1;
                else
                    m = Convert.ToInt32(o) + 1;
                r.cmd.CommandText = "INSERT INTO RequestService (Code, CustomerCode, ServiceCode, EmployeeCode, TotalCost, Expl, Date) VALUES(" + m.ToString() + "," + customerCode + "," + serviceCode + "," + employeeCode + "," + tPrice.ToString() + ",N'" + expl + "\n" + priceExpl + "',N'" + date.ToShortDateString() + "')";
                r.cmd.ExecuteNonQuery();
                r.conn.Close();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد.", "ثبت خدمات برای مشتری", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                r.a = true;
                this.Close();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ErrorCode);
            }
            finally
            {
                r.conn.Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            r.a = false;
            this.Close();
        }
    }
}