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

namespace shop
{
    public partial class pardakhteagsat : Form
    {
        public pardakhteagsat()
        {
            InitializeComponent();
        }

        private void cls()
        {
            txtfamili.Text = txtnam.Text =
            txtpish.Text = mask1.Text = "";
        }

        void display()
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from pardakht", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "pardakht");
            dataGridView1.DataSource = ds.Tables["pardakht"].DefaultView;
            con1.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "insert into pardakht(tarikh,nam,famili,pul) values ('" + mask1.Text + "','" + txtnam.Text + "','" + txtfamili.Text + "','" + txtpish.Text + "')";
            con.Open();
            com.Connection = con;
            com.ExecuteNonQuery();
            con.Close();
            display();
            cls();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            display();
            decimal sum = 0, s = 0;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                sum += Convert.ToDecimal(dataGridView1.Rows[i].Cells["daramad"].Value);
                dataGridView1.Rows[i].Cells["cod"].Value = i + 1;
                s += Convert.ToDecimal(dataGridView1.Rows[i].Cells["kol"].Value);
                dataGridView1.Rows[i].Cells["cod"].Value = i + 1;
            }
            lblsud.Text = sum.ToString("###,###,###,###");
            lblfrush.Text = s.ToString("###,###,###,###");
        }
    }
}
