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.Globalization;

namespace restooran
{
    public partial class factor : Form
    {
        public factor()
        {
            InitializeComponent();
        }

        private void superTabStrip1_ItemClick(object sender, EventArgs e)
        {

        }
       
        private void factor_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.tbl_info' table. You can move, or remove it, as needed.
            this.tbl_infoTableAdapter.Fill(this.dataSet1.tbl_info);
            // TODO: This line of code loads data into the 'dataSet11.tbl_deser' table. You can move, or remove it, as needed.
            this.tbl_deserTableAdapter.Fill(this.dataSet1.tbl_deser);
            // TODO: This line of code loads data into the 'dataSet1.tbl_subfactor' table. You can move, or remove it, as needed.
            this.tbl_subfactorTableAdapter.Fill(this.dataSet1.tbl_subfactor);
            txtshfactor1.Text = tbl_factorTableAdapter.getmax1().ToString();
            tbl_faTableAdapter.DeleteQuery();
            tbl_fTableAdapter.DeleteQuery();
            PersianCalendar pc = new PersianCalendar();
            string Year, Day, Month;
            Year = pc.GetYear(DateTime.Now).ToString();
            Month = pc.GetMonth(DateTime.Now).ToString();
            Day = pc.GetDayOfMonth(DateTime.Now).ToString();
            if (Day.Length == 1)
            {
                Day = pc.GetDayOfMonth(DateTime.Now).ToString().Insert(0, "0");
            }

            if (Month.Length == 1)
            {
                Month = pc.GetMonth(DateTime.Now).ToString().Insert(0, "0");
            }
            txtdate.Text = Year + '/' + Month + '/' + Day;
            // TODO: This line of code loads data into the 'dataSet1.tbl_ghaza' table. You can move, or remove it, as needed.
            this.tbl_ghazaTableAdapter.Fill(this.dataSet1.tbl_ghaza);
            // TODO: This line of code loads data into the 'dataSet1.tbl_fa' table. You can move, or remove it, as needed.
            this.tbl_faTableAdapter.Fill(this.dataSet1.tbl_fa);
            // TODO: This line of code loads data into the 'dataSet1.tbl_f' table. You can move, or remove it, as needed.
            this.tbl_fTableAdapter.Fill(this.dataSet1.tbl_f);
        }

        private void btninsert1_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_fTableAdapter.myinsert(txtcode1r.Text, txtsharh1r.Text, decimal.Parse(txttedad1.Text), decimal.Parse(tbl_deserTableAdapter.getgheymat(txtcode1r.Text).ToString()), (decimal.Parse(txttedad1.Text) * decimal.Parse(tbl_deserTableAdapter.getgheymat(txtcode1r.Text).ToString())));
                sum = decimal.Parse(txttedad1.Text) * decimal.Parse(tbl_deserTableAdapter.getgheymat(txtcode1r.Text).ToString());
                txtmablagh.Text = (decimal.Parse(txtmablagh.Text) + sum).ToString();
                txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                this.tbl_fTableAdapter.Fill(this.dataSet1.tbl_f);
                txttedad1.Text = txtsharh1r.Text = txtcode1r.Text = "";
                txtcode1r.Focus();
            }
            catch { MessageBox.Show("error"); }
        }

        private void txtcode1_TextChanged(object sender, EventArgs e)
        {
            if (txtcode1r.Text != "")
                tbl_deserTableAdapter.FillBycode(dataSet1.tbl_deser, txtcode1r.Text);
            else

            { }
        }

        

        private void btndelete1_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("اطلاعات حذف شده قابل بازیابی نیست.آیا مطمئن هستید؟", "اخطار حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    tbl_fTableAdapter.mydelete(dataGridViewX2.CurrentRow.Cells[0].Value.ToString());
                    txtmablagh.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(dataGridViewX2.CurrentRow.Cells[4].Value.ToString())).ToString();
                    txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                    this.tbl_fTableAdapter.Fill(this.dataSet1.tbl_f);
                }
                else
                {
                }
            }
            catch { MessageBox.Show("error"); }
            
        }

        

        private void tabControlPanel1_Click(object sender, EventArgs e)
        {

        }
        decimal sum=0; 
        private void btninsert_Click(object sender, EventArgs e)
        {
            try
            {
                if (txttedad.Text == "")
                {
                    MessageBox.Show("لطفا تعداد را وارد کنید");
                }
                else
                {
                    tbl_faTableAdapter.myinsert(txtcode.Text, txtsharh.Text, decimal.Parse(txttedad.Text), decimal.Parse(tbl_ghazaTableAdapter.getgheymat(txtcode.Text).ToString()), (decimal.Parse(txttedad.Text) * decimal.Parse(tbl_ghazaTableAdapter.getgheymat(txtcode.Text).ToString())));
                    sum = decimal.Parse(txttedad.Text) * decimal.Parse(tbl_ghazaTableAdapter.getgheymat(txtcode.Text).ToString());
                    txtmablagh.Text = (decimal.Parse(txtmablagh.Text) + sum).ToString();
                    txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                    this.tbl_faTableAdapter.Fill(this.dataSet1.tbl_fa);
                    txtcode.Text = txtsharh.Text = txttedad.Text = "";
                    txtcode.Focus();
                }
            }
            catch {
                MessageBox.Show("error");
            }


        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_fTableAdapter.UpdateQuery(decimal.Parse(tbl_fTableAdapter.gettedad(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()).ToString()) + 1, decimal.Parse(tbl_deserTableAdapter.getgheymat(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()).ToString()) + decimal.Parse(dataGridViewX2.CurrentRow.Cells[4].Value.ToString()), dataGridViewX2.CurrentRow.Cells[0].Value.ToString());
                qeymat = decimal.Parse(tbl_deserTableAdapter.getgheymat(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()).ToString());
                txtmablagh.Text = (qeymat + decimal.Parse(txtmablagh.Text)).ToString();
                txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                this.tbl_fTableAdapter.Fill(this.dataSet1.tbl_f);
            }
            catch { MessageBox.Show("error"); }
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("اطلاعات حذف شده قابل بازیابی نیست.آیا مطمئن هستید؟", "اخطار حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    tbl_faTableAdapter.mydelete(dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
                    txtmablagh.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(dataGridViewX1.CurrentRow.Cells[4].Value.ToString())).ToString();
                    txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                    this.tbl_faTableAdapter.Fill(this.dataSet1.tbl_fa);
                }
                else
                {
                }
            }
            catch { MessageBox.Show("error"); }
            
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_fTableAdapter.UpdateQuery(decimal.Parse(tbl_fTableAdapter.gettedad(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()).ToString()) - 1, decimal.Parse(dataGridViewX2.CurrentRow.Cells[4].Value.ToString()) - decimal.Parse(tbl_deserTableAdapter.getgheymat(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()).ToString()), dataGridViewX2.CurrentRow.Cells[0].Value.ToString());
                qeymat = decimal.Parse(tbl_deserTableAdapter.getgheymat(dataGridViewX2.CurrentRow.Cells[0].Value.ToString()).ToString());
                txtmablagh.Text = (decimal.Parse(txtmablagh.Text) - qeymat).ToString();
                txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                this.tbl_fTableAdapter.Fill(this.dataSet1.tbl_f);
            }
            catch { MessageBox.Show("error"); }
        }
        decimal qeymat;
        private void buttonX6_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_faTableAdapter.UpdateQuery(decimal.Parse(tbl_faTableAdapter.gettedad(dataGridViewX1.CurrentRow.Cells[0].Value.ToString()).ToString()) + 1, decimal.Parse(tbl_ghazaTableAdapter.getgheymat(dataGridViewX1.CurrentRow.Cells[0].Value.ToString()).ToString()) + decimal.Parse(dataGridViewX1.CurrentRow.Cells[4].Value.ToString()), dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
                qeymat = decimal.Parse(tbl_ghazaTableAdapter.getgheymat(dataGridViewX1.CurrentRow.Cells[0].Value.ToString()).ToString());
                txtmablagh.Text = (qeymat + decimal.Parse(txtmablagh.Text)).ToString();
                txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                this.tbl_faTableAdapter.Fill(this.dataSet1.tbl_fa);
            }
            catch { MessageBox.Show("error"); }
           
        }

        private void buttonX5_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_faTableAdapter.UpdateQuery(decimal.Parse(tbl_faTableAdapter.gettedad(dataGridViewX1.CurrentRow.Cells[0].Value.ToString()).ToString()) - 1, decimal.Parse(dataGridViewX1.CurrentRow.Cells[4].Value.ToString()) - decimal.Parse(tbl_ghazaTableAdapter.getgheymat(dataGridViewX1.CurrentRow.Cells[0].Value.ToString()).ToString()), dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
                qeymat = decimal.Parse(tbl_ghazaTableAdapter.getgheymat(dataGridViewX1.CurrentRow.Cells[0].Value.ToString()).ToString());
                txtmablagh.Text = (decimal.Parse(txtmablagh.Text) - qeymat).ToString();
                txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
                this.tbl_faTableAdapter.Fill(this.dataSet1.tbl_fa);
            }
            catch { MessageBox.Show("error"); }
        }

        private void txttakhfif_TextChanged(object sender, EventArgs e)
        {
            if (txttakhfif.Text != "")
                txtnahayi.Text = (decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
            else {
                txttakhfif.Text = "0";
                txtnahayi.Text=(decimal.Parse(txtmablagh.Text) - decimal.Parse(txttakhfif.Text)).ToString();
            }
        }

        private void textBoxX1_TextChanged(object sender, EventArgs e)
        {
            if (txtcode.Text != "")
                tbl_ghazaTableAdapter.FillBycode(dataSet1.tbl_ghaza, txtcode.Text);
            else
            { }
        }
        int i, j;
        private void buttonX4_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_infoTableAdapter.Fill(dataSet11.tbl_info);
                tbl_factorTableAdapter.myinsert(txtshfactor1 .Text  , txtdate.Text, decimal.Parse(txtmablagh.Text), decimal.Parse(txttakhfif.Text), decimal.Parse(txtnahayi.Text));
                for (i = 0; i < dataGridViewX1.Rows.Count; i++)
                {
                    tbl_subfactorTableAdapter.myinsert(txtshfactor1 .Text , dataGridViewX1.Rows[i].Cells[1].Value.ToString(), decimal.Parse(dataGridViewX1.Rows[i].Cells[2].Value.ToString()), decimal.Parse(dataGridViewX1.Rows[i].Cells[3].Value.ToString()), decimal.Parse(dataGridViewX1.Rows[i].Cells[4].Value.ToString()));
                }
                for (j = 0; j < dataGridViewX2.Rows.Count; j++)
                {
                    tbl_subfactorTableAdapter.myinsert(txtshfactor1 .Text , dataGridViewX2.Rows[j].Cells[1].Value.ToString(), decimal.Parse(dataGridViewX2.Rows[j].Cells[2].Value.ToString()), decimal.Parse(dataGridViewX2.Rows[j].Cells[3].Value.ToString()), decimal.Parse(dataGridViewX2.Rows[j].Cells[4].Value.ToString()));
                }

                tbl_subfactorTableAdapter.FillBysh(dataSet11.tbl_subfactor, txtshfactor1.Text);
                CrystalReport2 cr = new CrystalReport2();
                cr.SetDataSource(dataSet11);
                cr.SetParameterValue("date", txtdate.Text);
                cr.SetParameterValue("shomare", txtshfactor1.Text);
                cr.SetParameterValue("mablagh", txtmablagh.Text);
                cr.SetParameterValue("takhfif", txttakhfif.Text);
                cr.SetParameterValue("total", txtnahayi.Text);
                if (checkBoxX1.Checked == true)
                    cr.SetParameterValue("check", "سالن");
                else
                    cr.SetParameterValue("check", "بیرون");
                viewer f = new viewer();
                f.crystalReportViewer1.ReportSource = cr;
                //f.Show();
                
                f.crystalReportViewer1.PrintReport();
                
                this.Hide();
                if (MessageBox.Show("آیا مایل به چاپ فیش آشپزخانه هستید؟", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    //tbl_subfactorTableAdapter.FillBysh(dataSet11.tbl_subfactor, txtshfactor1.Text);
                    tbl_faTableAdapter.Fill(dataSet11.tbl_fa);
                    ashpaz cr1 = new ashpaz();
                    cr1.SetDataSource(dataSet11);
                    cr1.SetParameterValue("shomare", txtshfactor1.Text);
                    if (checkBoxX1.Checked == true)
                        cr1.SetParameterValue("check", "سالن");
                    else
                        cr1.SetParameterValue("check", "بیرون");
                    viewer f1 = new viewer();
                    f1.crystalReportViewer1.ReportSource = cr1;
                    //f1.Show();
                    f1.crystalReportViewer1.PrintReport();
                }
                else
                {
                }
                //if (MessageBox.Show("آیا مایل به چاپ فیش سالن هستید؟", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                //{
                //    tbl_subfactorTableAdapter.FillBysh(dataSet11.tbl_subfactor, txtshfactor1.Text);
                //    //tbl_fTableAdapter.Fill(dataSet11.tbl_f);
                //    salon  cr2 = new salon ();
                //    cr2.SetDataSource(dataSet11);
                //    cr2.SetParameterValue("shomare", txtshfactor1.Text);
                //    if (checkBoxX1.Checked == true)
                //        cr2.SetParameterValue("check", "سالن");
                //    else
                //        cr2.SetParameterValue("check", "بیرون");
                //    viewer f2 = new viewer();
                //    f2.crystalReportViewer1.ReportSource = cr2;
                //    f2.Show();
                //    f2.crystalReportViewer1.PrintReport();

                //}
                //else
                //{
                //}
                
            }
            catch { MessageBox.Show("error"); }
        }

        private void comboBoxEx1_SelectedValueChanged(object sender, EventArgs e)
        {
           
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            tbl_subfactorTableAdapter.FillBysh(dataSet11.tbl_subfactor, txtshfactor1.Text);
            CrystalReport2 cr = new CrystalReport2();
            cr.SetDataSource(dataSet11);
            cr.SetParameterValue("date", txtdate.Text);
            cr.SetParameterValue("shomare", txtshfactor1.Text);
            cr.SetParameterValue("mablagh", txtmablagh.Text);
            cr.SetParameterValue("takhfif", txttakhfif.Text);
            cr.SetParameterValue("total", txtnahayi.Text);
            viewer f = new viewer();
            f.crystalReportViewer1.ReportSource = cr;
            f.Show();
            //this.Hide();
        }

        private void groupPanel1_Click(object sender, EventArgs e)
        {

        }

        private void buttonX3_Click_1(object sender, EventArgs e)
        {
            try
            {
                tbl_subfactorTableAdapter.FillBysh(dataSet11.tbl_subfactor, txtshfactor1.Text);
                ashpaz cr = new ashpaz();
                cr.SetDataSource(dataSet11);
                cr.SetParameterValue("shomare", txtshfactor1.Text);
                if (checkBoxX1.Checked == true)
                    cr.SetParameterValue("check", "سالن");
                else
                    cr.SetParameterValue("check", "بیرون");
                viewer f = new viewer();
                f.crystalReportViewer1.ReportSource = cr;
                f.Show();
            }
            catch { MessageBox.Show("error"); }
        }

        private void txtshfactor1_TextChanged(object sender, EventArgs e)
        {

        }

        private void txttedad_KeyPress(object sender, KeyPressEventArgs e)
        {
          
        }

       
        

        
    }
}
