using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Dish_Project;

namespace Publishmentation
{
    
    public partial class Request : Form
    {
        public Request() 
        {
            InitializeComponent();
        }
        Connector connector = new Connector();
        PersionCelender celender = new PersionCelender();
        DataSet dataset = new DataSet();
        FormCollection frm = new FormCollection();
        private void button1_Click(object sender, EventArgs e)
        {
            if(dataset!=null)
                dataset.Clear();
            connector.connect();
            dataset= connector.selecte("select * from request where requestid="+textBox1.Text);
            connector.disConnect();
            textBox5.Text = textBox1.Text;
            if (Convert.ToInt32(dataset.Tables[0].Rows[0]["recipt"])==1)
                textBox7.Text="تمام شده";
            else
                textBox7.Text="ناتمام";
            celender.ConvertToPersia( Convert.ToDateTime(dataset.Tables[0].Rows[0]["request_date"]));
            textBox3.Text = celender.Date;
            celender.ConvertToPersia(Convert.ToDateTime(dataset.Tables[0].Rows[0]["receipt_date"]));
            textBox4.Text = celender.Date;
            int p1 = Convert.ToInt32(dataset.Tables[0].Rows[0]["customer_id"]);
            switch (Convert.ToInt32(dataset.Tables[0].Rows[0]["publishtype"]))
            {
                case 1:
                    bookSelect(Convert.ToInt32(dataset.Tables[0].Rows[0]["PublishId"]));
                    textBox6.Text = "کتاب";
                    break;
                case 2:
                    magazineSelect(Convert.ToInt32(dataset.Tables[0].Rows[0]["PublishId"]));
                    textBox6.Text = "مجله";
                    break;
                case 3:
                    advertizmentSelect(Convert.ToInt32(dataset.Tables[0].Rows[0]["PublishId"]));
                    textBox6.Text = "آگهی";
                    break;
            }
            dataset.Clear();
            connector.connect();
            dataset = connector.selecte("select (customername+' '+customerFamily)as name from customer where customerId=" 
                + p1.ToString());
            connector.disConnect();
            textBox2.Text = dataset.Tables[0].Rows[0]["name"].ToString();

            }

        private void advertizmentSelect(int p)
        {

        }

        private void magazineSelect(int p)
        {
            dataset.Clear();
            connector.connect();
            dataset = connector.selecte("select subject from magazine where magazine_id=" + p.ToString());
            connector.disConnect();
            textBox8.Text = dataset.Tables[0].Rows[0]["subject"].ToString();
        }

        private void bookSelect(int p)
        {
            dataset.Clear();
            connector.connect();
            dataset=connector.selecte("select book_subject from bookTable where book_id="+p.ToString());
            connector.disConnect();
            textBox8.Text = dataset.Tables[0].Rows[0]["book_subject"].ToString();
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void Request_Load(object sender, EventArgs e)
        {
            frm = Application.OpenForms;

        }

        private void Request_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm["Form1"].Enabled = true;
            frm["Form1"].Show();
            frm["Form1"].Focus();
        }
        }
}