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

namespace LibraryMembers
{
    public partial class frmBazgashteketab : Form
    {
        public frmBazgashteketab()
        {
            InitializeComponent();
        }

        public void dbConnection()
        {
            clsGrideview dbCon1 = new clsGrideview();
            dataGridView1.DataSource = dbCon1.dbConnection(@"SELECT     dbo.Members.MemBerID, dbo.Members.Name + N'  ' + dbo.Members.Sname AS EXPR1, dbo.Books.Title, dbo.BookH.DateDeli, dbo.Subjects.Subject, 
                      dbo.BookH.zemanat, dbo.BookH.Mablagh FROM dbo.BookH INNER JOIN dbo.Books ON dbo.BookH.BookID = dbo.Books.BookID INNER JOIN
                      dbo.Members ON dbo.BookH.PersonelID = dbo.Members.MemBerID INNER JOIN dbo.Subjects ON dbo.Books.TopicID = dbo.Subjects.SubId WHERE     (dbo.BookH.DatBaz IS NULL)");
        }

        public void dbConnection2()
        {
            clsForCombo cmbP2 = new clsForCombo();
            comboBox1.DataSource = cmbP2.dbConnection2(@"SELECT     MemBerID FROM    dbo.Members WHERE     (memberState = 1)");
            comboBox2.DataSource = cmbP2.dbConnection2(@"SELECT     BookID, Title FROM   dbo.Books WHERE     (TahYeNo = 1)");

            comboBox1.ValueMember = "MemBerID";
            comboBox1.DisplayMember = "MemBerID";

            comboBox2.ValueMember = "BookID";
            comboBox2.DisplayMember = "Title";
        }

        public void adish()
        {
            FirstClass dbEx = new FirstClass();
            dbEx.cmd.Parameters.Add("@PersonelID", SqlDbType.NVarChar).Value = comboBox1.SelectedValue.ToString();
            dbEx.cmd.Parameters.Add("@BookID", SqlDbType.NVarChar).Value = comboBox2.SelectedValue.ToString();
            dbEx.cmd.Parameters.Add("@DateDeli", SqlDbType.NVarChar).Value = textBox2.Text.Trim();
            dbEx.cmd.Parameters.Add("@DatBaz", SqlDbType.NVarChar).Value = textBox1.Text.Trim();
            dbEx.exeCommand("sp_BookH_Update");

            FirstClass dbex1 = new FirstClass();
            dbex1.cmd.Parameters.Add("@BookID", SqlDbType.NVarChar).Value = comboBox2.SelectedValue.ToString();
            dbex1.cmd.Parameters.Add("@TahYeNo", SqlDbType.Bit).Value = 0;
            dbex1.exeCommand("sp_Books_Update");

        }

        private void frmBazgashteketab_Load(object sender, EventArgs e)
        {
            dbConnection();
            dbConnection2();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || comboBox1.Text == "" || comboBox2.Text == "")
            {
                MessageBox.Show("مقادیر تمامی فیلدها بایستی وارد شوند");
            }
            else
            {
                adish();
                dbConnection();
                dbConnection2();
            }
        
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}