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 fromdatagridveiw
{
    public partial class factor : Form
    {
        public factor()
        {
            InitializeComponent();
        }

        public void GetCustomerName(string name)
        {
            radLabel8.Text = name;
        }

        public void GetKalaInfo(string name,string price)
        {
            lblname.Text = name;
            lblprice.Text = price;
        }

 
        private void radButton1_Click_1(object sender, EventArgs e)
        {
            kala k = new kala();
            k.Show();
        }

        private void radButton7_Click(object sender, EventArgs e)
        {
            customer c = new customer();
            c.Show();
        }

        DataTable dt = new DataTable();

        private void radButton3_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\shoping.mdf;Integrated Security=True;User Instance=True");

            for (int i = 0; i < dgvfactor.Rows.Count; i++)
            {
                DataRow dr = dt.NewRow();
                dr["CustomerName"] = dgvfactor.Rows[i].Cells[1].Value.ToString();
                dr["KalaName"] = dgvfactor.Rows[i].Cells[2].Value.ToString();
                dr["KalaCount"] = dgvfactor.Rows[i].Cells[3].Value.ToString();
                dr["KalaPrice"] = dgvfactor.Rows[i].Cells[4].Value.ToString();
                dr["KalaTotalPrice"] = dgvfactor.Rows[i].Cells[5].Value.ToString();
                dt.Rows.Add(dr);
            }

            SqlBulkCopy bulk = new SqlBulkCopy(con);
            bulk.DestinationTableName = "tblFactor";
            con.Open();
            bulk.WriteToServer(dt);
            con.Close();
            dgvfactor.Rows.Clear();
            dt.Rows.Clear();
        }

        int _count = 0;
        private void radButton2_Click(object sender, EventArgs e)
        {
            dgvfactor.Rows.Add(++_count, radLabel8.Text, lblname.Text, txt_tedad.Text, lblprice.Text, radLabel5.Text);

        }

        private void factor_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("CustomerName");
            dt.Columns.Add("KalaName");
            dt.Columns.Add("KalaCount");
            dt.Columns.Add("KalaPrice");
            dt.Columns.Add("KalaTotalPrice");
    
        }

        private void txt_tedad_TextChanged(object sender, EventArgs e)
        {
            if(!string.IsNullOrEmpty(txt_tedad.Text ))
                radLabel5.Text=(Int32.Parse(txt_tedad.Text )*Int32.Parse(lblprice.Text) ).ToString();
        }

        private void radButton5_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void radButton4_Click(object sender, EventArgs e)
        {
            dgvfactor.Rows.Clear();
        }

        private void radButton6_Click(object sender, EventArgs e)
        {
           dgvfactor.CurrentRow.Cells[1].Value = radLabel8.Text;
           dgvfactor.CurrentRow.Cells[2].Value=lblname.Text;
           dgvfactor.CurrentRow.Cells[3].Value=txt_tedad.Text;
           dgvfactor.CurrentRow.Cells[4].Value=lblprice.Text;
           dgvfactor.CurrentRow.Cells[5].Value = radLabel5.Text;
        }

        private void dgvfactor_MouseClick(object sender, MouseEventArgs e)
        {
            if (dgvfactor.SelectedRows.Count > 0)
            {
                radLabel8.Text = dgvfactor.CurrentRow.Cells[1].Value.ToString();
                lblname.Text = dgvfactor.CurrentRow.Cells[2].Value.ToString();
                txt_tedad.Text = dgvfactor.CurrentRow.Cells[3].Value.ToString();
                lblprice.Text = dgvfactor.CurrentRow.Cells[4].Value.ToString();
                radLabel5.Text = dgvfactor.CurrentRow.Cells[5].Value.ToString();
            }
        }

     
    }
}
