SIGN UP MEMBER LOGIN:    
Blog

inventory manegmant system

Posted by Sudhakar Chaudhary Blogs | .NET 4.5 Jan 17, 2012
sale and purchase inventory management system on windows application
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;
using System.Collections;
using Org.Vesic.WinForms;
using System.Drawing.Drawing2D;
using System.IO;
namespace WindowsFormsApplication1
{
    public partial class purchase : Form
    {
        //variable for update fat

        string ofbillno, ofdate, ovno, ofcomp, ofbdate;
        ////////////////
        int saveORmodify = 0;

        double realvalue1;
        double textbfill;
        string cacr;
        double final;
        double totamt;
        char STTYP;
        FormState ft = new FormState();
        string ProductCode;
        string fvat;
        string PackingForFill;
        string Fmrp, Fpdeal, Fsdeal, Fptax, Fpdiscount, Fprate, Ftrade, Forrmfd, Fmfd, Frackno, Frecno;
        string fdcd;
        int total;
        SqlConnection con = ConMgr.GetConnection();
        public purchase()
        {
            InitializeComponent();
            //this.dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;

        }

        public void PartyBalance()
        {

            SqlDataAdapter adp = new SqlDataAdapter("select sum (amount) as balance from fat where a_code='" + fdcd.ToString() + "'", con);
            SqlCommandBuilder cd = new SqlCommandBuilder(adp);
            DataSet ds = new DataSet("s");
            adp.Fill(ds, "s");
            foreach (DataRow dr in ds.Tables["s"].Rows)
            {
                string balen = dr["balance"].ToString();
                if (balen == "")
                {
                    labelGradient9.Text = "000.000";
                }
                else
                {
                    labelGradient9.Text = balen.ToString();
                }
            }

        }
        #region datagridview first column
        public void columnDataGridView()
        {
            dataGridView1.Columns.Add("A_NAME ", "N/R/F");
            dataGridView1.Columns.Add("DEBIT", "Product Name");
            dataGridView1.Columns.Add("CREADIT", "Packing");
            dataGridView1.Columns.Add("F_FALLON", "MRP");
            dataGridView1.Columns.Add("F_RESCHE", "Quantity");
            dataGridView1.Columns.Add("F_HEADS", "P.Deal");
            dataGridView1.Columns.Add("A_CODE", "S.Deal");
            dataGridView1.Columns.Add("", "VAT");
            dataGridView1.Columns.Add("P.Discount", "P.Discount");
            dataGridView1.Columns.Add("", "P.Rate");
            dataGridView1.Columns.Add("", "Trade");
            dataGridView1.Columns.Add("ORRMFG", "ORR MFG");
            dataGridView1.Columns.Add("batch", "Batch No.");
            dataGridView1.Columns.Add("Expiry", "Expiry");
            dataGridView1.Columns.Add("MFD", "MFD");
            dataGridView1.Columns.Add("RACK", "Rack No.");
            dataGridView1.Columns.Add("", "Amount");
            dataGridView1.Columns.Add("", "Trade Val");
            dataGridView1.Columns.Add("F_RECNO", "Sr.No.");
            dataGridView1.Columns.Add("productcode", "P_Code");
            dataGridView1.Columns.Add("purequantity", "purequantity");
            dataGridView1.Columns.Add("SAT", "SAT");
            dataGridView1.Columns.Add("Exc.", "Exc.");
            dataGridView1.Columns.Add("Dis.SaleRate", "Dis.Sale Rate");
            dataGridView1.Columns.Add("v4", "v4");
            dataGridView1.Columns.Add("4v1sat", "4v1sat");
            dataGridView1.Columns.Add("v12", "v12");
            dataGridView1.Columns.Add("12v1sat", "12v1sat");
            dataGridView1.Columns.Add("amt", "amt");
        }
        #endregion
        #region datagrid first design
        private void DesignDataGridView()
        {
            this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 10);
            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Calibri", 11f, FontStyle.Bold);
            DataGridViewCellStyle fooCellStyle = new DataGridViewCellStyle();
            DataGridViewHeaderCell f = new DataGridViewHeaderCell();
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.BurlyWood;
            dataGridView1.EnableHeadersVisualStyles = false;
            this.dataGridView1.Columns[2].ReadOnly = true;
            this.dataGridView1.Columns[16].ReadOnly = true;
            this.dataGridView1.Columns[17].ReadOnly = true;
            this.dataGridView1.Columns[18].ReadOnly = true;
            DataGridViewColumn column0 = dataGridView1.Columns[0];
            column0.Width = 50;
            DataGridViewColumn column1 = dataGridView1.Columns[1];
            column1.MinimumWidth = 305;
            DataGridViewColumn column2 = dataGridView1.Columns[2];
            column2.Width = 80;
            DataGridViewColumn column3 = dataGridView1.Columns[3];
            column3.Width = 80;
            DataGridViewColumn column4 = dataGridView1.Columns[4];
            column4.Width = 70;
            DataGridViewColumn column5 = dataGridView1.Columns[5];
            column5.Width = 70;
            DataGridViewColumn column6 = dataGridView1.Columns[6];
            column6.Width = 70;
            DataGridViewColumn column7 = dataGridView1.Columns[7];
            column7.Width = 50;
            DataGridViewColumn column21 = dataGridView1.Columns[21];
            column21.Width = 50;
            DataGridViewColumn column8 = dataGridView1.Columns[8];
            column8.Width = 75;
            DataGridViewColumn column23 = dataGridView1.Columns[23];
            column23.MinimumWidth = 150;
            DataGridViewColumn column24 = dataGridView1.Columns[24];
            column24.MinimumWidth = 150;
            dataGridView1.BackgroundColor = System.Drawing.Color.CadetBlue;
        }
        #endregion
        #region method for filling combobox accourding to debitor creditor and all
        public void BindCreaditorOnly()
        {
            comboBox3.Text = "";
            comboBox3.BackColor = System.Drawing.Color.Wheat;
            comboBox3.Items.Clear();
            string CreaditorOnly = "1009";
            SqlDataAdapter adp = new SqlDataAdapter("SELECT a_name,d_address1,d_city,a_code from ams where f_resche='" + CreaditorOnly.ToString() + "'  ", con);
            SqlCommandBuilder cd = new SqlCommandBuilder(adp);
            DataSet ds = new DataSet("s");
            adp.Fill(ds, "s");
            foreach (DataRow dr in ds.Tables["s"].Rows)
            {
                string aName = dr["a_name"].ToString();
                string dAddress = dr["d_address1"].ToString();
                string dCity = dr["d_city"].ToString();
                string fdcdinner = dr["a_code"].ToString();
                comboBox3.Items.Add(aName + "  " + dAddress + "  " + dCity + "                               " + fdcdinner);
            }

        }
        public void BindCreaditorAndDebitor()
        {
            comboBox3.Text = "";
            comboBox3.BackColor = System.Drawing.Color.Wheat;
            comboBox3.Items.Clear();
            string CreaditorOnly = "1009";
            string DebitorOnly = "1012";
            SqlDataAdapter adp = new SqlDataAdapter("SELECT a_name,d_address1,d_city,a_code from ams where f_resche='" + CreaditorOnly.ToString() + "' or f_resche='" + DebitorOnly.ToString() + "' ", con);
            SqlCommandBuilder cd = new SqlCommandBuilder(adp);
            DataSet ds = new DataSet("s");
            adp.Fill(ds, "s");
            foreach (DataRow dr in ds.Tables["s"].Rows)
            {
                string aName = dr["a_name"].ToString();
                string dAddress = dr["d_address1"].ToString();
                string dCity = dr["d_city"].ToString();
                string fdcdinner = dr["a_code"].ToString();
                comboBox3.Items.Add(aName + "  " + dAddress + "  " + dCity + "                              " + fdcdinner);
            }

        }
        public void BindAll()
        {
            comboBox3.Text = "";
            comboBox3.BackColor = System.Drawing.Color.Wheat;
            comboBox3.Items.Clear();
            SqlDataAdapter adp = new SqlDataAdapter("SELECT a_name,d_address1,d_city,a_code from ams ", con);
            SqlCommandBuilder cd = new SqlCommandBuilder(adp);
            DataSet ds = new DataSet("s");
            adp.Fill(ds, "s");
            foreach (DataRow dr in ds.Tables["s"].Rows)
            {
                string aName = dr["a_name"].ToString();
                string dAddress = dr["d_address1"].ToString();
                string dCity = dr["d_city"].ToString();
                string fdcdinner = dr["a_code"].ToString();
                comboBox3.Items.Add(aName + "  " + dAddress + "  " + dCity + "                               " + fdcdinner);
            }

        }
        #endregion

        public void listviewFill()
        {

            SqlDataAdapter adp = new SqlDataAdapter("select p_name ,p_packing,p_code from pms ", con);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                ListViewItem listitem = new ListViewItem(dr[0].ToString());
                listitem.SubItems.Add(dr[1].ToString());
                listitem.SubItems.Add(dr[2].ToString());
                listView1.Items.Add(listitem);

            }

        }
        public void FillPTax()
        {

            SqlDataAdapter adp = new SqlDataAdapter("SELECT top 1 f_vat  as vat FROM taxst WHERE P_CODE='" + ProductCode + "' ORDER BY f_stdate DESC", con);
            SqlCommandBuilder cd = new SqlCommandBuilder(adp);
            DataSet ds = new DataSet("s");
            adp.Fill(ds, "s");
            foreach (DataRow dr in ds.Tables["s"].Rows)
            {
                fvat = dr["vat"].ToString();
            }
        }
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }
        public void read()
        {
            try
            {
                using (StreamReader reader = new StreamReader("c:\\sam.txt"))
                {
                    string m = reader.ReadLine();
                    STTYP = Convert.ToChar(m);
                }
            }
            catch (Exception ms) { }
        }
        #region form load
        private void purchase_Load(object sender, EventArgs e)
        {
            read();
           
            comboBox3.DropDownHeight = 100;
            listView1.Hide();
            listviewFill();
            columnDataGridView();
            DesignDataGridView();

            try
            {

                dataGridView1.Columns["productcode"].Visible = false;
                dataGridView1.Columns["purequantity"].Visible = false;
                dataGridView1.Columns["v4"].Visible = false;
                dataGridView1.Columns["4v1sat"].Visible = false;
                dataGridView1.Columns["v12"].Visible = false;
                dataGridView1.Columns["12v1sat"].Visible = false;
                dataGridView1.Columns["amt"].Visible = false;
                dataGridView1.Columns["F_RECNO"].Visible = false;
            }
            catch (Exception es) { }


            dataGridView1.Columns["SAT"].DisplayIndex = 8;
            dataGridView1.Columns["Exc."].DisplayIndex = 9;
            dataGridView1.Columns["Dis.SaleRate"].DisplayIndex = 12;
            listView1.Hide();
            this.dataGridView1.DefaultCellStyle.ForeColor = Color.Black;


        }
        #endregion

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.SelectedIndex == 0)
            {
                BindCreaditorOnly();
            }
            if (comboBox2.SelectedIndex == 1)
            {
                BindCreaditorAndDebitor();
            }
            if (comboBox2.SelectedIndex == 2)
            {
                BindAll();
            }
        }
        #region method to save discout textboxs
        public void savediscount()
        {
            try
            {
                SqlDataAdapter adp = new SqlDataAdapter("select * from fat", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet();
                adp.Fill(ds, "s");
                DataRow dr;
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                dr = ds.Tables["s"].NewRow();
                dr["f_date"] = DT2.ToLongDateString();
                dr["v_no"] = fdcd.ToString();//party code    
                if (comboBox1.SelectedIndex == 1)
                {
                    dr["entry"] = "RP";//COMBOBOX1 SLECTION
                }
                if (comboBox1.SelectedIndex == 0)
                {
                    dr["entry"] = "CP";//COMBOBOX1 SELECTION
                }
                dr["particular"] = textBox1.Text.Trim() + "     discount % is:" + textBox8.Text;//INVOICE NO
                dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                dr["A_CODE"] = "60019";////code for 0%
                dr["amount"] = "-" + textBox17.Text;//TEXTBOX3 FOR 0% AMOUNT
                dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                dr["f_bdate"] = DT1.ToLongDateString();
                dr["f_billno"] = textBox1.Text.Trim();//invoice no
                ds.Tables["s"].Rows.Add(dr);
                adp.Update(ds, "s");
                con.Close();
            }
            catch (Exception ess) { }

        }
        #endregion
        #region roundoff saveing
        public void roundoff()
        {
            try
            {
                double roundoffvariable = Convert.ToDouble(textBox9.Text);
                SqlDataAdapter adp = new SqlDataAdapter("select * from fat", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet();
                adp.Fill(ds, "s");
                DataRow dr;
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                dr = ds.Tables["s"].NewRow();
                dr["f_date"] = DT2.ToLongDateString();
                dr["v_no"] = fdcd.ToString();//party code     
                if (comboBox1.SelectedIndex == 1)
                {
                    dr["entry"] = "RP";//COMBOBOX1 SLECTION
                }
                if (comboBox1.SelectedIndex == 0)
                {
                    dr["entry"] = "CP";//COMBOBOX1 SELECTION
                }
                dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                if (roundoffvariable > 0)
                {
                    dr["dbt_cdt"] = "C";//NEGATIVE VLAUE OF AMOUT
                }
                else
                {
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                }
                dr["A_CODE"] = "60018";////code for 0%
                dr["amount"] = textBox9.Text;//TEXTBOX3 FOR 0% AMOUNT
                dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                dr["f_bdate"] = DT1.ToLongDateString();
                dr["f_billno"] = textBox1.Text.Trim();//invoice no
                ds.Tables["s"].Rows.Add(dr);
                adp.Update(ds, "s");
                con.Close();
            }
            catch (Exception msmms) { }
        }
        #endregion
        #region grand totoal textbox save
        public void grandTotal()
        {
            try
            {
                double roundoffvariable = Convert.ToDouble(textBox9.Text);
                SqlDataAdapter adp = new SqlDataAdapter("select * from fat", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet();
                adp.Fill(ds, "s");
                DataRow dr;
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                dr = ds.Tables["s"].NewRow();
                dr["f_date"] = DT2.ToLongDateString();
                dr["v_no"] = fdcd.ToString();//party code  
                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                dr["particular"] = textBox1.Text.Trim();//INVOICE NO            
                dr["dbt_cdt"] = "C";//NEGATIVE VLAUE OF AMOUT            
                dr["A_CODE"] = fdcd.ToString();//party code     
                dr["amount"] = textBox10.Text;//TEXTBOX3 FOR 0% AMOUNT
                dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                dr["f_bdate"] = DT1.ToLongDateString();
                dr["f_billno"] = textBox1.Text.Trim();//invoice no
                ds.Tables["s"].Rows.Add(dr);
                adp.Update(ds, "s");
                con.Close();
            }
            catch (Exception mms) { }
        }
        #endregion
        #region saving textbox value to fat
        public void saveallvatandsatvalue()
        {
            try
            {
                SqlDataAdapter adp = new SqlDataAdapter("select * from fat", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet();
                adp.Fill(ds, "s");
                DataRow dr;
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                for (int i = 1; i <= 7; i++)
                {


                    if (i == 1)
                    {
                        if (textBox3.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["amount"] = "-" + textBox3.Text;//TEXTBOX3 FOR 0% AMOUNT
                            dr["A_CODE"] = "60001";////code for amout4%
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }
                    }
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////0000000000000/////////////////////           


                    if (i == 2)
                    {
                        if (textBox2.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["A_CODE"] = "60002";////code for amout4%
                            dr["amount"] = "-" + textBox2.Text;//TEXTBOX3 FOR 0% AMOUNT
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }
                    }
                    if (i == 3)
                    {
                        if (textBox4.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["A_CODE"] = "60007";////code for vat 4%
                            dr["amount"] = "-" + textBox4.Text;//TEXTBOX3 FOR 0% AMOUNT
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }
                    }
                    if (i == 4)
                    {
                        if (textBox13.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["A_CODE"] = "60009";////code for vat 4 and adtition 1%
                            dr["amount"] = "-" + textBox13.Text;//TEXTBOX3 FOR 0% AMOUNT
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }

                    }

                    //////////////////////////////////////////////////////////////////////////////////////// vat12.5////////////////////////////

                    if (i == 5)
                    {
                        if (textBox5.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE                 
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no                 
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["A_CODE"] = "60003";////code for 0%
                            dr["amount"] = "-" + textBox5.Text;//TEXTBOX3 FOR 0% AMOUNT
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }
                    }
                    if (i == 6)
                    {
                        if (textBox6.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["A_CODE"] = "60008";////code for 0%
                            dr["amount"] = "-" + textBox6.Text;//TEXTBOX3 FOR 0% AMOUNT
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }
                    }
                    if (i == 7)
                    {
                        if (textBox7.Text != "0")
                        {
                            dr = ds.Tables["s"].NewRow();
                            dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                            dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                            dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                            dr["f_bdate"] = DT1.ToLongDateString();
                            dr["f_billno"] = textBox1.Text.Trim();//invoice no
                            dr["f_date"] = DT2.ToLongDateString();
                            dr["v_no"] = fdcd.ToString();//party code
                            dr["A_CODE"] = "60010";////code for 0%
                            dr["amount"] = "-" + textBox7.Text;//TEXTBOX3 FOR 0% AMOUNT
                            if (comboBox1.SelectedIndex == 1)
                            {
                                dr["entry"] = "RP";//COMBOBOX1 SLECTION
                            }
                            if (comboBox1.SelectedIndex == 0)
                            {
                                dr["entry"] = "CP";//COMBOBOX1 SELECTION
                            }
                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }

                    }
                    con.Close();

                }
                if (textBox8.Text != "0")
                {
                    savediscount();
                }
                if (textBox9.Text != "0")
                {
                    roundoff();
                }
                if (comboBox1.SelectedIndex == 1)
                {
                    grandTotal();
                }

                
            }
            catch (Exception msmms) { }

        }
        #endregion

        private void button1_Click_1(object sender, EventArgs e)
        {


        }
        #region fill datagrid searching second grid
        public void FillDataGridCell()
        {
            SqlDataAdapter adp = new SqlDataAdapter("SELECT Top 1 F_RECNO,F_RECDT ,F_MRP, F_PDEAL, F_SDEAL, F_VATPER, F_DISC_BEF, F_STRATE, F_TRADE, F_ORMFD, F_MFD, F_RACKNO,F_RECNO FROM PPT WHERE P_CODE='" + ProductCode + "' ORDER BY F_RECDT  DESC", con);
            SqlCommandBuilder cd = new SqlCommandBuilder(adp);
            DataSet ds = new DataSet("s");
            adp.Fill(ds, "s");
            foreach (DataRow dr in ds.Tables["s"].Rows)
            {
                Fmrp = dr["F_MRP"].ToString();
                Fpdeal = dr["F_PDEAL"].ToString();
                Fsdeal = dr["F_SDEAL"].ToString();
                Fptax = dr["F_VATPER"].ToString();
                Fpdiscount = dr["F_DISC_BEF"].ToString();
                Fprate = dr["F_STRATE"].ToString();
                Ftrade = dr["F_TRADE"].ToString();
                Forrmfd = dr["F_ORMFD"].ToString();
                Fmfd = dr["F_MFD"].ToString();
                Frackno = dr["F_RACKNO"].ToString();
                Frecno = dr["F_RECNO"].ToString();
            }
        }
        #endregion
        private void button2_Click(object sender, EventArgs e)
        {
            this.Refresh();
            saveORmodify = 0;          
            ClearTextBoxes(this);
            dataGridView1.Rows.Clear();
            
            
        }
        public void ClearTextBoxes(Control control)
        {
            foreach (Control c in control.Controls)
            {
                if (c is TextBox)
                {
                    ((TextBox)c).Clear();
                    
                }               
                if (c.HasChildren)
                {
                    ClearTextBoxes(c);
                }

            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            master m = new master();
            m.Show();
            this.Hide();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            pmaster p = new pmaster();
            p.Show();

        }



        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (dataGridView1.CurrentCell.ColumnIndex == 1)
            {

                listView1.TabIndex = 0;
                TextBox tb = (TextBox)e.Control;
                tb.BackColor = System.Drawing.Color.LightBlue;
                tb.TextChanged += new EventHandler(tb_TextChanged);

            }
            e.CellStyle.BackColor = Color.LightGreen;
        }


        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        #region listview item seclection
        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            try
            {
                FillDataGridCell();
                FillPTax();
                dataGridView1.CurrentRow.Cells[1].Value = listView1.Items[e.ItemIndex].SubItems[0].Text;
                dataGridView1.CurrentRow.Cells[2].Value = listView1.Items[e.ItemIndex].SubItems[1].Text;
                ProductCode = listView1.Items[e.ItemIndex].SubItems[2].Text; ;
                dataGridView1.CurrentRow.Cells[3].Value = Fmrp;
                dataGridView1.CurrentRow.Cells[5].Value = Fpdeal;
                dataGridView1.CurrentRow.Cells[6].Value = Fsdeal;
                dataGridView1.CurrentRow.Cells[7].Value = fvat;
                dataGridView1.CurrentRow.Cells[8].Value = Fpdiscount;
                dataGridView1.CurrentRow.Cells[9].Value = Fprate;
                dataGridView1.CurrentRow.Cells[10].Value = Ftrade;
                dataGridView1.CurrentRow.Cells[11].Value = Forrmfd;
                dataGridView1.CurrentRow.Cells[14].Value = Fmfd;
                dataGridView1.CurrentRow.Cells[15].Value = Frackno;

                dataGridView1.Columns["productcode"].Visible = false;
                dataGridView1.CurrentRow.Cells[19].Value = ProductCode.ToString();

            }
            catch (Exception mss)
            {
                MessageBox.Show(mss.ToString());
            }
        }
        #endregion

        void tb_TextChanged(object sender, EventArgs e)
        {

            string productName = dataGridView1.CurrentRow.Cells[1].EditedFormattedValue.ToString();
            listView1.TabIndex = 1;
            ListViewItem foundItem = listView1.FindItemWithText(productName.ToString(), false, 0, true);
            if (foundItem != null)
            {
                listView1.TopItem = foundItem;

                string m = foundItem.Index.ToString();
                textBox1.TabIndex = 0;
                listView1.TabIndex = 1;

            }
            else
            {

            }
        }

        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            dataGridView1.CurrentCell.Style.BackColor = System.Drawing.Color.Aqua;

        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            string shows = dataGridView1.CurrentCell.ColumnIndex.ToString();
            if (shows == "1")
            {
                int x = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location.X;
                int y = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location.Y;
                this.listView1.Location = new System.Drawing.Point(x, y + 100);
                listView1.Show();
            }

        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void purchase_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.Handled = true;
            }
            if (e.KeyCode == Keys.Down)
            {
                e.Handled = true;
            }
            if (e.KeyCode == Keys.Tab)
            {
                e.Handled = true;
            }

        }
        #region datagrid calculation vat sat first
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (dataGridView1.CurrentRow.Cells[5].Selected == true)
                {
                    if (e.KeyCode == Keys.Enter)
                    {
                        double quantity = double.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
                        double mrptake = double.Parse(dataGridView1.CurrentRow.Cells[9].Value.ToString());
                        double TradeVal = quantity * mrptake;
                        dataGridView1.CurrentRow.Cells[17].Value = TradeVal.ToString("0.00");

                    }
                }
                if ((dataGridView1.CurrentRow.Cells[4].Selected == true) || (dataGridView1.CurrentRow.Cells[5].Selected == true) || (dataGridView1.CurrentRow.Cells[6].Selected == true) || (dataGridView1.CurrentRow.Cells[7].Selected == true) || (dataGridView1.CurrentRow.Cells[8].Selected == true) || (dataGridView1.CurrentRow.Cells[9].Selected == true) || (dataGridView1.CurrentRow.Cells[10].Selected == true) || (dataGridView1.CurrentRow.Cells[21].Selected == true) || (dataGridView1.CurrentRow.Cells[22].Selected == true))
                {
                    if (e.KeyCode == Keys.Enter)
                    {
                        try
                        {
                            dataGridView1.CurrentRow.Cells[16].Value = "0";
                            dataGridView1.CurrentRow.Cells[24].Value = "0";
                            dataGridView1.CurrentRow.Cells[25].Value = "0";
                            dataGridView1.CurrentRow.Cells[26].Value = "0";
                            dataGridView1.CurrentRow.Cells[27].Value = "0";
                            //////////////////////////////////////////////////////////////////////////////////
                            ///for postive sign////
                            string pedalstringvalue = dataGridView1.CurrentRow.Cells[5].Value.ToString();
                            string sign = "+";
                            bool answer = pedalstringvalue.Contains(sign);
                            if (answer == true)
                            {

                                string[] cutthevalue = pedalstringvalue.Split('+');
                                double beforesigndeal = double.Parse(cutthevalue[0].ToString());
                                double aftersigndeal = double.Parse(cutthevalue[1].ToString());
                                double quantitydeal = double.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
                                double purequantity = double.Parse(pdealmethodforposstive(beforesigndeal, aftersigndeal, quantitydeal).ToString());/////the value of final quantiy
                                dataGridView1.CurrentRow.Cells[20].Value = purequantity.ToString("0.00");
                            }

                            ////without sign
                            if (answer == false)
                            {

                                double quantitydeal = double.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
                                dataGridView1.CurrentRow.Cells[20].Value = quantitydeal.ToString("0.00"); ;
                                double pd = double.Parse(dataGridView1.CurrentRow.Cells[5].Value.ToString());
                                double finalquantiy = quantitydeal + pd;
                                dataGridView1.CurrentRow.Cells[4].Value = finalquantiy.ToString("0.00"); ;
                            }
                            //////////////////////////////////////////////////////////////////////////////////
                            double quantity = double.Parse(dataGridView1.CurrentRow.Cells[20].Value.ToString());
                            double mrptake = double.Parse(dataGridView1.CurrentRow.Cells[9].Value.ToString());
                            double TradeVal = quantity * mrptake;
                            dataGridView1.CurrentRow.Cells[17].Value = TradeVal.ToString("0.00");
                            /////////////////////////////////////////////////////////////////////////////////
                            string amoutinstring = dataGridView1.CurrentRow.Cells[17].Value.ToString();
                            double amt = Convert.ToDouble(amoutinstring);
                            double dis = double.Parse(dataGridView1.CurrentRow.Cells[8].Value.ToString());
                            double vat = double.Parse(dataGridView1.CurrentRow.Cells[7].Value.ToString()) + double.Parse(dataGridView1.CurrentRow.Cells[21].Value.ToString());


                            double tdisc = amt * dis * 0.01;
                            amt = amt - tdisc;
                            double tvat = amt * vat * 0.01;

                            double tamt = amt + tvat;
                            dataGridView1.CurrentRow.Cells[16].Value = tamt.ToString("0.00");

                            //  totamt = totamt + tamt;
                            //labelGradient14.Text = totamt.ToString();

                            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            //{

                            //    double tot = double.Parse(dataGridView1.Rows[i].Cells[16].Value.ToString());
                            //    t1 =t1+tot;
                            //    labelGradient14.Text = t1.ToString();
                            //}
                            /////////////////////////////////////////0v/////////////////////////////////////////////////////////////////////////

                            double condition0 = Convert.ToDouble(dataGridView1.CurrentRow.Cells[7].Value.ToString());
                            if (condition0 <= 0)
                            {

                                double tradval4 = double.Parse(dataGridView1.CurrentRow.Cells[17].Value.ToString());
                                double discout4 = double.Parse(dataGridView1.CurrentRow.Cells[8].Value.ToString());
                                double discoutamoutvat4 = tradval4 * discout4 * 0.01;
                                double amout4 = tradval4 - discoutamoutvat4;
                                dataGridView1.CurrentRow.Cells[28].Value = amout4.ToString("0.00");
                                double vat4 = amout4 * condition0 * 0.01;
                                dataGridView1.CurrentRow.Cells[24].Value = vat4.ToString("0.00");

                                double sat4 = double.Parse(dataGridView1.CurrentRow.Cells[21].Value.ToString());
                                double sat4amout = amout4 * sat4 * 0.01;
                                dataGridView1.CurrentRow.Cells[25].Value = sat4amout.ToString("0.00");

                            }
                            /////////////////////////////////////////////4v///////////////////////////////////////////////////////////////////
                            double condition4 = Convert.ToDouble(dataGridView1.CurrentRow.Cells[7].Value.ToString());
                            if (condition4 > 0 && condition4 < 12.5)
                            {

                                double tradval4 = double.Parse(dataGridView1.CurrentRow.Cells[17].Value.ToString());
                                double discout4 = double.Parse(dataGridView1.CurrentRow.Cells[8].Value.ToString());
                                double discoutamoutvat4 = tradval4 * discout4 * 0.01;
                                double amout4 = tradval4 - discoutamoutvat4;
                                dataGridView1.CurrentRow.Cells[28].Value = amout4.ToString("0.00");
                                double vat4 = amout4 * condition4 * 0.01;
                                dataGridView1.CurrentRow.Cells[24].Value = vat4.ToString("0.00");

                                double sat4 = double.Parse(dataGridView1.CurrentRow.Cells[21].Value.ToString());
                                double sat4amout = amout4 * sat4 * 0.01;
                                dataGridView1.CurrentRow.Cells[25].Value = sat4amout.ToString("0.00");

                            }
                            //////////////////////////////12 vat//////////////////////////////////////////////////////
                            double condition12 = Convert.ToDouble(dataGridView1.CurrentRow.Cells[7].Value.ToString());
                            if (condition12 >= 12.5)
                            {

                                double tradval4 = double.Parse(dataGridView1.CurrentRow.Cells[17].Value.ToString());
                                double discout4 = double.Parse(dataGridView1.CurrentRow.Cells[8].Value.ToString());
                                double discoutamoutvat4 = tradval4 * discout4 * 0.01;
                                double amout4 = tradval4 - discoutamoutvat4;
                                dataGridView1.CurrentRow.Cells[28].Value = amout4.ToString("0.00");
                                double vat12 = amout4 * condition12 * 0.01;
                                // double findalamout = double.Parse(dataGridView1.CurrentRow.Cells[16].Value.ToString()) - amout4;
                                dataGridView1.CurrentRow.Cells[26].Value = vat12.ToString("0.00");

                                double sat4 = double.Parse(dataGridView1.CurrentRow.Cells[21].Value.ToString());
                                double sat4amout = amout4 * sat4 * 0.01;
                                dataGridView1.CurrentRow.Cells[27].Value = sat4amout.ToString("0.00");

                            }

                        }
                        catch (Exception ms) { }
                        textBox2.Text = "0";
                        textBox3.Text = "0";
                        textBox5.Text = "0";
                        ////////////////////////////below of form......................................vat0,4,12....
                        try
                        {
                            double tot1 = 0;
                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            {
                                double condition000 = double.Parse(dataGridView1.Rows[i].Cells[7].Value.ToString());
                                if (condition000 <= 0)
                                {
                                    tot1 += double.Parse(dataGridView1.Rows[i].Cells[16].Value.ToString());
                                    textBox3.Text = tot1.ToString();
                                }
                            }
                        }
                        catch (Exception msp) { }

                        ////    amount 4  ////////////////////////////////////////////////////////////////////////////
                        try
                        {
                            double tot2 = 0;
                            double vat4total = 0;
                            double sat4totoal = 0;
                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            {
                                double condition = double.Parse(dataGridView1.Rows[i].Cells[7].Value.ToString());
                                if (condition > 0 && condition < 12.5)
                                {
                                    tot2 += double.Parse(dataGridView1.Rows[i].Cells[28].Value.ToString());
                                    textBox2.Text = tot2.ToString();
                                }
                                vat4total += double.Parse(dataGridView1.Rows[i].Cells[24].Value.ToString());
                                textBox4.Text = vat4total.ToString();

                                sat4totoal += double.Parse(dataGridView1.Rows[i].Cells[25].Value.ToString());
                                textBox13.Text = sat4totoal.ToString();
                            }

                        }
                        catch (Exception vats) { }
                        //// amount 12.5 /////////////////////////////////////////////////////////////////////////////
                        try
                        {

                            double vat12total = 0;
                            double sat12totoal = 0;
                            double tot3 = 0;
                            for (int j = 0; j < dataGridView1.Rows.Count; j++)
                            {
                                double condition = double.Parse(dataGridView1.Rows[j].Cells[7].Value.ToString());
                                if (condition >= 12.5)
                                {
                                    tot3 += double.Parse(dataGridView1.Rows[j].Cells[28].Value.ToString());
                                    textBox5.Text = tot3.ToString();
                                }

                                vat12total += double.Parse(dataGridView1.Rows[j].Cells[26].Value.ToString());
                                textBox6.Text = vat12total.ToString();

                                sat12totoal += double.Parse(dataGridView1.Rows[j].Cells[27].Value.ToString());
                                textBox7.Text = sat12totoal.ToString();
                            }


                        }
                        catch (Exception ms2) { }
                        //////////////////////////////////////////////////////////////////////////////////////////////////
                        try
                        {
                            decimal tot = 0;
                            foreach (DataGridViewRow row in dataGridView1.Rows)
                            {
                                tot += Convert.ToDecimal(row.Cells[16].Value.ToString());
                                labelGradient14.Text = tot.ToString();
                            }

                        }
                        catch (Exception ex) { }
                        try
                        {
                            textchage();
                        }
                        catch (Exception exs) { }
                    }

                }
                if (dataGridView1.CurrentRow.Cells[1].Selected == true)
                {
                    if (e.KeyCode == Keys.Down)
                    {
                        listView1.TabIndex = 0;
                        listView1.Focus();
                    }
                }
            }
            catch (Exception ms) { }
        }
        #endregion

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            dataGridView1.CurrentCell.Style.BackColor = System.Drawing.Color.White;
            try
            {
                string upercase = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                dataGridView1.CurrentRow.Cells[0].Value = upercase.ToUpper();
            }
            catch (Exception mss)
            {

            }
        }

        #region datagrid cell enter validation first
        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {

            try
            {
                labelGradient12.Text = dataGridView1.CurrentRow.Cells[16].Value.ToString();
                textBox14.Text = dataGridView1.CurrentRow.Cells[28].Value.ToString();
                double Currentcondition = double.Parse(dataGridView1.CurrentRow.Cells[7].Value.ToString());
                if (Currentcondition == 0)
                {
                    textBox15.Text = "0";
                    textBox16.Text = "0";
                }
                if (Currentcondition > 0 && Currentcondition < 12.5)
                {
                    textBox15.Text = dataGridView1.CurrentRow.Cells[24].Value.ToString();
                    textBox16.Text = dataGridView1.CurrentRow.Cells[25].Value.ToString();
                }
                if (Currentcondition >= 12.5)
                {
                    textBox15.Text = dataGridView1.CurrentRow.Cells[26].Value.ToString();
                    textBox16.Text = dataGridView1.CurrentRow.Cells[27].Value.ToString();
                }


            }
            catch (Exception ms) { }


            DataGridViewTextBoxCell cell = dataGridView1[3, e.RowIndex] as DataGridViewTextBoxCell;
            if (e.ColumnIndex == 3)
            {
                if (dataGridView1.CurrentRow.Cells[2].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[2].Value = 0;
                }
            }


            if (e.ColumnIndex == 0)
            {
                if (dataGridView1.CurrentRow.Cells[2].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[2].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[3].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[3].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[5].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[5].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[6].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[6].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[7].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[7].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[8].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[8].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[9].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[9].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[10].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[10].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[11].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[11].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[12].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[12].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[13].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[13].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[14].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[14].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[15].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[15].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[16].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[16].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[17].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[17].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[21].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[21].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[22].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[22].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[23].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[23].Value = 0;
                }
            }

            if (e.ColumnIndex == 17)
            {
                if (dataGridView1.CurrentRow.Cells[2].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[2].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[3].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[3].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[5].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[5].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[6].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[6].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[7].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[7].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[8].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[8].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[9].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[9].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[10].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[10].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[11].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[11].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[12].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[12].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[13].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[13].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[14].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[14].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[15].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[15].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[16].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[16].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[17].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[17].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[21].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[21].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[22].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[22].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[23].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[23].Value = 0;
                }
            }


            if (e.ColumnIndex == 11)
            {
                if (dataGridView1.CurrentRow.Cells[2].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[2].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[3].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[3].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[5].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[5].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[6].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[6].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[7].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[7].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[8].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[8].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[9].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[9].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[10].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[10].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[11].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[11].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[12].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[12].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[13].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[13].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[14].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[14].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[15].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[15].Value = " ";
                }
                if (dataGridView1.CurrentRow.Cells[16].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[16].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[17].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[17].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[21].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[21].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[22].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[22].Value = 0;
                }
                if (dataGridView1.CurrentRow.Cells[23].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[23].Value = 0;
                }
            }







            if (e.ColumnIndex == 5)
            {
                if (dataGridView1.CurrentRow.Cells[3].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[3].Value = 0;
                }
            }
            if (e.ColumnIndex == 6)
            {
                if (dataGridView1.CurrentRow.Cells[5].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[5].Value = 0;
                }
            }
            if (e.ColumnIndex == 7)
            {
                if (dataGridView1.CurrentRow.Cells[6].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[6].Value = 0;
                }
            }
            if (e.ColumnIndex == 8)
            {
                if (dataGridView1.CurrentRow.Cells[7].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[7].Value = 0;
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[8].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[8].Value = 0;
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[10].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[10].Value = 0;
                }
            }

            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[11].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[11].Value = " ";
                }
            }

            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[12].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[12].Value = " ";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[13].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[13].Value = "  /  ";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[14].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[14].Value = " ";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[15].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[15].Value = " ";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[11].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[11].Value = " ";
                }
            }
            if (e.ColumnIndex == 1)
            {
                if (dataGridView1.CurrentRow.Cells[0].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[0].Value = "N";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[21].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[21].Value = "0";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[22].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[22].Value = "0";
                }
            }
            if (e.ColumnIndex == 9)
            {
                if (dataGridView1.CurrentRow.Cells[23].Value == null)
                {
                    dataGridView1.CurrentRow.Cells[23].Value = "0";
                }
            }



            string shows = dataGridView1.CurrentCell.ColumnIndex.ToString();
            if (shows == "1")
            {
                int x = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location.X;
                int y = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location.Y;
                this.listView1.Location = new System.Drawing.Point(x, y + 100);
                listView1.Show();
                listView1.TabIndex = 1;
            }
            else
            {
                listView1.Hide();
            }


        }
        #endregion
        private void listView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                listView1.Hide();
                dataGridView1.Focus();
                dataGridView1.CurrentCell.Selected = true;

            }
        }

        private void comboBox3_TextChanged(object sender, EventArgs e)
        {

            int index = comboBox3.FindStringExact(comboBox3.Text);
            if (index < 0)
            {

                comboBox3.TabIndex = 1;
            }
            else
            {
                comboBox3.SelectedIndex = index;
                comboBox3.TabIndex = 1;

            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            string fullname = comboBox3.Text;
            string lastWord = fullname.Split(' ').Last();
            fdcd = lastWord.ToString();
            PartyBalance();

        }



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



        private void button8_Click(object sender, EventArgs e)
        {
            ft.Restore(this);
        }


        #region second grid column search
        public void fillcolumnDataGridView()
        {
            dataGridView1.Columns.Add("A_NAME ", "N/R/F");
            dataGridView1.Columns.Add("DEBIT", "Product Name");
            dataGridView1.Columns.Add("CREADIT", "Packing");
            dataGridView1.Columns.Add("F_FALLON", "MRP");
            dataGridView1.Columns.Add("F_RESCHE", "Quantity");
            dataGridView1.Columns.Add("F_HEADS", "P.Deal");
            dataGridView1.Columns.Add("A_CODE", "S.Deal");
            dataGridView1.Columns.Add("", "VAT");
            dataGridView1.Columns.Add("P.Discount", "P.Discount");
            dataGridView1.Columns.Add("", "P.Rate");
            dataGridView1.Columns.Add("", "Trade");
            dataGridView1.Columns.Add("ORRMFG", "ORR MFG");
            dataGridView1.Columns.Add("batch", "Batch No.");
            dataGridView1.Columns.Add("Expiry", "Expiry");
            dataGridView1.Columns.Add("MFD", "MFD");
            dataGridView1.Columns.Add("RACK", "Rack No.");
            dataGridView1.Columns.Add("", "Amount");
            dataGridView1.Columns.Add("", "Trade Val");
            dataGridView1.Columns.Add("F_RECNO", "Sr.No.");
            dataGridView1.Columns.Add("productcode", "P_Code");
            dataGridView1.Columns.Add("purequantity", "purequantity");
            dataGridView1.Columns.Add("SAT", "SAT");
            dataGridView1.Columns.Add("Exc.", "Exc.");
            dataGridView1.Columns.Add("Dis.SaleRate", "Dis.Sale Rate");
            dataGridView1.Columns.Add("v4", "v4");
            dataGridView1.Columns.Add("4v1sat", "4v1sat");
            dataGridView1.Columns.Add("v12", "v12");
            dataGridView1.Columns.Add("12v1sat", "12v1sat");
            dataGridView1.Columns.Add("amt", "amt");
        }
        #endregion
        #region datagridview  desing search
        private void fillDesignDataGridView()
        {
            this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 10);
            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Calibri", 11f, FontStyle.Bold);
            DataGridViewCellStyle fooCellStyle = new DataGridViewCellStyle();
            DataGridViewHeaderCell f = new DataGridViewHeaderCell();
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.BurlyWood;
            dataGridView1.EnableHeadersVisualStyles = false;
            this.dataGridView1.Columns[2].ReadOnly = true;
            this.dataGridView1.Columns[16].ReadOnly = true;
            this.dataGridView1.Columns[17].ReadOnly = true;
            this.dataGridView1.Columns[18].ReadOnly = true;
            DataGridViewColumn column0 = dataGridView1.Columns[0];
            column0.Width = 50;
            DataGridViewColumn column1 = dataGridView1.Columns[1];
            column1.MinimumWidth = 305;
            DataGridViewColumn column2 = dataGridView1.Columns[2];
            column2.Width = 80;
            DataGridViewColumn column3 = dataGridView1.Columns[3];
            column3.Width = 80;
            DataGridViewColumn column4 = dataGridView1.Columns[4];
            column4.Width = 70;
            DataGridViewColumn column5 = dataGridView1.Columns[5];
            column5.Width = 70;
            DataGridViewColumn column6 = dataGridView1.Columns[6];
            column6.Width = 70;
            DataGridViewColumn column7 = dataGridView1.Columns[7];
            column7.Width = 50;
            DataGridViewColumn column21 = dataGridView1.Columns[21];
            column21.Width = 50;
            DataGridViewColumn column8 = dataGridView1.Columns[8];
            column8.Width = 75;
            DataGridViewColumn column23 = dataGridView1.Columns[23];
            column23.MinimumWidth = 150;
            DataGridViewColumn column24 = dataGridView1.Columns[24];
            column24.MinimumWidth = 150;
            dataGridView1.BackgroundColor = System.Drawing.Color.CadetBlue;

            try
            {
                dataGridView1.Columns["productcode"].Visible = false;
                dataGridView1.Columns["purequantity"].Visible = false;
                dataGridView1.Columns["v4"].Visible = false;
                dataGridView1.Columns["4v1sat"].Visible = false;
                dataGridView1.Columns["v12"].Visible = false;
                dataGridView1.Columns["12v1sat"].Visible = false;
                dataGridView1.Columns["amt"].Visible = false;
                dataGridView1.Columns["F_RECNO"].Visible = false;
            }
            catch (Exception es) { }


            dataGridView1.Columns["SAT"].DisplayIndex = 8;
            dataGridView1.Columns["Exc."].DisplayIndex = 9;
            dataGridView1.Columns["Dis.SaleRate"].DisplayIndex = 12;
        }
        #endregion
        #region fill gridiviewa ccordingto search
        public void FILL()
        {
            try
            {
                DateTime DT = Convert.ToDateTime(dateTimePicker1.Text);
                con.Open();
                string quryString = "SELECT  F_NORMAL, P_NAME, P_PACKING, F_MRP, P_QNT, F_PDEAL, F_SDEAL, F_VATPER, F_ADTPER, F_EXDPER, F_DISC_BEF, F_STRATE, F_CTRADE, F_TRADE, F_ORMFD, BAT_NO, F_EXPDT, F_MFD, F_RACKNO, AMOUNT, F_RECNO,P_CODE FROM PPT WHERE  INVOICE_NO='" + textBox1.Text + "' AND F_DATE='" + DT.ToLongDateString() + "'  ORDER BY F_RECNO asc";
                SqlDataAdapter da = new SqlDataAdapter(quryString, con);
                DataSet ds = new DataSet();
                da.Fill(ds, "Emp");
                int row = ds.Tables["Emp"].Rows.Count - 1;
                for (int r = 0; r <= row; r++)
                {
                    dataGridView1.Rows.Add();
                    dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0];
                    dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1];
                    dataGridView1.Rows[r].Cells[2].Value = ds.Tables["Emp"].Rows[r].ItemArray[2];
                    dataGridView1.Rows[r].Cells[3].Value = ds.Tables["Emp"].Rows[r].ItemArray[3];
                    dataGridView1.Rows[r].Cells[4].Value = ds.Tables["Emp"].Rows[r].ItemArray[4];
                    dataGridView1.Rows[r].Cells[5].Value = ds.Tables["Emp"].Rows[r].ItemArray[5];
                    dataGridView1.Rows[r].Cells[6].Value = ds.Tables["Emp"].Rows[r].ItemArray[6];
                    dataGridView1.Rows[r].Cells[7].Value = ds.Tables["Emp"].Rows[r].ItemArray[7];
                    dataGridView1.Rows[r].Cells[21].Value = ds.Tables["Emp"].Rows[r].ItemArray[8];
                    dataGridView1.Rows[r].Cells[8].Value = ds.Tables["Emp"].Rows[r].ItemArray[10];
                    dataGridView1.Rows[r].Cells[9].Value = ds.Tables["Emp"].Rows[r].ItemArray[11];
                    dataGridView1.Rows[r].Cells[10].Value = ds.Tables["Emp"].Rows[r].ItemArray[13];
                    dataGridView1.Rows[r].Cells[11].Value = ds.Tables["Emp"].Rows[r].ItemArray[14];
                    dataGridView1.Rows[r].Cells[12].Value = ds.Tables["Emp"].Rows[r].ItemArray[15];
                    dataGridView1.Rows[r].Cells[13].Value = ds.Tables["Emp"].Rows[r].ItemArray[16];
                    dataGridView1.Rows[r].Cells[14].Value = ds.Tables["Emp"].Rows[r].ItemArray[17];
                    dataGridView1.Rows[r].Cells[15].Value = ds.Tables["Emp"].Rows[r].ItemArray[18];
                    dataGridView1.Rows[r].Cells[16].Value = ds.Tables["Emp"].Rows[r].ItemArray[19];
                    dataGridView1.Rows[r].Cells[18].Value = ds.Tables["Emp"].Rows[r].ItemArray[20];
                    dataGridView1.Rows[r].Cells[19].Value = ds.Tables["Emp"].Rows[r].ItemArray[21];

                }
                con.Close();
                tax0();
            }
            catch (Exception ess) { }
        }
        #endregion

        #region method fill textbox search second grid
        public void tax0()
        {
            try
            {

                con.Close();
                con.Open();
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                SqlDataAdapter adp = new SqlDataAdapter("select amount,a_code ,particular FROM fat WHERE  f_date='" + DT2.ToLongDateString() + "' and f_bdate='" + DT1.ToLongDateString() + "' and  v_no='" + fdcd + "' and f_billno='" + textBox1.Text + "' ", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet("s");
                adp.Fill(ds, "s");
                foreach (DataRow dr in ds.Tables["s"].Rows)
                {
                    if (dr["a_code"].ToString() == "60001")//o %
                    {
                        string amountg = dr["amount"].ToString();
                        textBox3.Text = amountg.Remove(0, 1);
                    }
                    if (dr["a_code"].ToString() == "60002")//purchase 5%
                    {
                        string amountg = dr["amount"].ToString();
                        textBox2.Text = amountg.Remove(0, 1);
                    }
                    if (dr["a_code"].ToString() == "60007")//%vat 4
                    {
                        string amountg = dr["amount"].ToString();
                        textBox4.Text = amountg.Remove(0, 1);
                    }
                    if (dr["a_code"].ToString() == "60009")//4 vat and adition 1%
                    {
                        string amountg = dr["amount"].ToString();
                        textBox13.Text = amountg.Remove(0, 1);
                    }

                    if (dr["a_code"].ToString() == "60003")//12 vat purchase
                    {
                        string amountg = dr["amount"].ToString();
                        textBox5.Text = amountg.Remove(0, 1);
                    }

                    if (dr["a_code"].ToString() == "60008")//vat 12%
                    {
                        string amountg = dr["amount"].ToString();
                        textBox6.Text = amountg.Remove(0, 1);
                    }

                    if (dr["a_code"].ToString() == "60010")//vat 12% aditional 1
                    {
                        string amountg = dr["amount"].ToString();
                        textBox7.Text = amountg.Remove(0, 1);
                    }
                    if (dr["a_code"].ToString() == "60018")//roundoff
                    {
                        textBox9.Text = dr["amount"].ToString();

                    }
                    if (dr["a_code"].ToString() == "60019")//discount
                    {
                        string dis = dr["amount"].ToString();
                        textBox17.Text = dis.Remove(0, 1);
                    }
                    if (dr["a_code"].ToString() == "60019")//o %
                    {
                        string amountg = dr["particular"].ToString();
                        string result = amountg.Replace(":", "+");
                        string[] cutthevalue = result.Split('+');
                        double beforesigndeal = double.Parse(cutthevalue[1].ToString());
                        textBox8.Text = beforesigndeal.ToString();
                    }

                }
                con.Close();
            }
            catch (Exception sss) { }
        }
        #endregion



        private void purchase_Paint(object sender, PaintEventArgs e)
        {

            Graphics mGraphics = e.Graphics;
            Pen pen1 = new Pen(Color.FromArgb(96, 155, 173), 1);
            Rectangle Area1 = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
            LinearGradientBrush LGB = new LinearGradientBrush(Area1, Color.FromArgb(96, 155, 20), Color.FromArgb(200, 251, 200), LinearGradientMode.Vertical);
            mGraphics.FillRectangle(LGB, Area1);
            mGraphics.DrawRectangle(pen1, Area1);
        }

        #region save button click

        private void button9_Click(object sender, EventArgs e)
        {

            if (textBox1.Text == DBNull.Value.ToString())
            {
                MessageBox.Show("Please Fill Invoice No.");
            }
            else
            {

                if (comboBox1.Text == DBNull.Value.ToString())
                {
                    MessageBox.Show("Please Select Invoice Type.");
                }
                else
                {
                    if (comboBox2.Text == DBNull.Value.ToString())
                    {
                        MessageBox.Show("Please Select Party.");
                    }
                    else
                    {
                        if (comboBox3.Text == DBNull.Value.ToString())
                        {
                            MessageBox.Show("Please Party Name.");
                        }
                        else
                        {
                            if (saveORmodify == 0)
                            {
                                savegrid();
                                saveallvatandsatvalue();
                            }
                            if (saveORmodify == 1)
                            {
                                GRIDVIEWUPDATEFIRST();
                                ModifyTextINfatamount0();
                                ModifyTextINfatamount4();
                                ModifyTextINfatvat4();
                                ModifyTextINfatvat4andSAT1();
                                ModifyTextINfatamount12();
                                ModifyTextINfatvat12();
                                ModifyTextINfatvat12SAT1();
                                ModifyTextINfatdicount();
                                ModifyTextINfatRoundOff();
                                ModifyTextINfatGrandTotoal();

                            }

                        }
                    }
                }
            }



        }
        #endregion
        #region method savegrid to ppt
        public void savegrid()
        {
            try
            {
                con.Close();
                con.Open();
                SqlDataAdapter adp = new SqlDataAdapter("select * from ppt", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet();
                adp.Fill(ds, "s");
                DataRow dr;
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                DateTime DT3 = Convert.ToDateTime(dateTimePicker3.Text);

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Rows[i].Cells[17].Value == null)
                    {
                    }
                    else
                    {
                        decimal amt = Convert.ToDecimal(dataGridView1.Rows[i].Cells[16].Value.ToString());
                        decimal qnt = Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value.ToString());
                        decimal fqnt = amt / qnt;
                        dr = ds.Tables["s"].NewRow();
                        dr["INVOICE_NO"] = textBox1.Text.Trim();
                        dr["F_CACR"] = cacr.ToString();
                        dr["F_DATE"] = DT1.ToLongDateString();
                        dr["F_RECDT"] = DT2.ToLongDateString();
                        dr["F_DUEDT"] = DT3.ToLongDateString();
                        dr["P_CODE"] = dataGridView1.Rows[i].Cells[19].Value.ToString();
                        dr["F_STTYPE"] = STTYP.ToString();
                        dr["F_PCODE"] = fdcd.ToString();
                        dr["F_QNT"] = fqnt.ToString();
                        dr["PUR_QNT"] = dataGridView1.Rows[i].Cells[4].Value.ToString();
                        dr["F_NORMAL"] = dataGridView1.Rows[i].Cells[0].Value.ToString();
                        dr["P_NAME"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
                        dr["P_PACKING"] = dataGridView1.Rows[i].Cells[2].Value.ToString();
                        dr["F_ADTPER"] = dataGridView1.Rows[i].Cells[21].Value.ToString();
                        dr["F_MRP"] = dataGridView1.Rows[i].Cells[3].Value.ToString();
                        dr["P_QNT"] = dataGridView1.Rows[i].Cells[4].Value.ToString();
                        dr["F_PDEAL"] = dataGridView1.Rows[i].Cells[5].Value.ToString();
                        dr["F_SDEAL"] = dataGridView1.Rows[i].Cells[6].Value.ToString();
                        dr["F_VATPER"] = dataGridView1.Rows[i].Cells[7].Value.ToString();
                        dr["F_DISC_BEF"] = dataGridView1.Rows[i].Cells[8].Value.ToString();
                        dr["F_STRATE"] = dataGridView1.Rows[i].Cells[9].Value.ToString();
                        dr["F_TRADE"] = dataGridView1.Rows[i].Cells[10].Value.ToString();
                        dr["F_ORMFD"] = dataGridView1.Rows[i].Cells[11].Value.ToString();
                        dr["BAT_NO"] = dataGridView1.Rows[i].Cells[12].Value.ToString();
                        dr["F_EXPDT"] = dataGridView1.Rows[i].Cells[13].Value.ToString();
                        dr["F_MFD"] = dataGridView1.Rows[i].Cells[14].Value.ToString();
                        dr["F_RACKNO"] = dataGridView1.Rows[i].Cells[15].Value.ToString();
                        dr["AMOUNT"] = dataGridView1.Rows[i].Cells[16].Value.ToString();
                        if (dataGridView1.Rows[i].Cells[23].Value == null)
                        {
                            dr["F_CTRADE"] = "0";
                        }
                        else
                        {
                            dr["F_CTRADE"] = dataGridView1.Rows[i].Cells[23].Value.ToString();
                        }
                        ds.Tables["s"].Rows.Add(dr);
                        adp.Update(ds, "s");
                    }
                }
                con.Close();
               
            }
            catch (Exception EXS) { }
            RecordSaved rs = new RecordSaved();
            rs.Show();
        }
        #endregion
        #region combobox3 validation for search and fill
        private void comboBox3_Validating(object sender, CancelEventArgs e)
        {
            DateTime DT = Convert.ToDateTime(dateTimePicker1.Text);
            SqlCommand cmd = new SqlCommand("SELECT  F_NORMAL,P_NAME,P_CODE,P_PACKING,F_MRP,P_QNT, F_PDEAL, F_SDEAL , F_DISC_BEF, F_TRADE, F_STRATE, F_ORMFD, F_MFD, F_RACKNO, F_RECNO,BAT_NO,F_EXPDT FROM PPT WHERE  INVOICE_NO='" + textBox1.Text + "' AND F_DATE='" + DT.ToLongDateString() + "'  ORDER BY F_RECNO asc", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count > 0)
            {
                string result = purchaseMessageBox.ShowBox("Do you Want To Exit", "Exit");
                if (result.Equals("2"))
                {
                    saveORmodify = 1;
                    dataGridView1.Columns.Clear();
                    dataGridView1.Rows.Clear();
                    dataGridView1.Refresh();
                    fillcolumnDataGridView();
                    fillDesignDataGridView();
                    FILL();
                    ValueForConditionUpdate();
                    SecondGridFillMethod();
                    //W01
                }

                if (result.Equals("1"))
                {                   
                    MessageBox.Show("Delete Record..");
                }
                if (result.Equals("3"))
                {
                    purchaseMessageBox p = new purchaseMessageBox();
                    p.Close();
                }

            }
            else
            {

            }
        }
        #endregion


        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {

            string indexs = comboBox1.SelectedIndex.ToString();

            if (indexs == "0")
            {
                cacr = "C";
            }
            if (indexs == "1")
            {
                cacr = "R";
            }
        }
        static double pdealmethodforposstive(double a, double b, double c)
        {
            double addsign = a + b;
            double devide = a / addsign;
            double result = c * devide;
            return result;
        }
        static double pdealfornormal()
        {
            double result = 0;
            return result;
        }

        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {

            if (dataGridView1.Columns[e.ColumnIndex].Name == "DEBIT")
            {
                if (String.IsNullOrEmpty(e.FormattedValue.ToString()) && dataGridView1[e.ColumnIndex, e.RowIndex].IsInEditMode)
                {
                    this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Error";
                    e.Cancel = true;
                }
            }


        }
        public void selectionChange()
        {
            double qnt = double.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
            double rate = double.Parse(dataGridView1.CurrentRow.Cells[9].Value.ToString());
            double discout = double.Parse(dataGridView1.CurrentRow.Cells[8].Value.ToString());
            double amt = qnt * rate;
            double dis = amt * discout * 0.01;
            double currentamout = amt - dis;
            // double vatamout=
        }

        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            contextMenuStrip1.Hide();


        }



        #region toolstripmenu locking option

        private void toolStripMenuItem1_CheckedChanged(object sender, EventArgs e)
        {

            if (toolStripMenuItem1.Checked == true)
            {
                dataGridView1.Columns["F_HEADS"].Visible = false;

            }
            if (toolStripMenuItem1.Checked == false)
            {
                dataGridView1.Columns["F_HEADS"].Visible = true;
            }


        }

        private void toolStripMenuItem2_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem2.Checked == true)
            {
                dataGridView1.Columns["A_CODE"].Visible = false;

            }
            if (toolStripMenuItem2.Checked == false)
            {
                dataGridView1.Columns["A_CODE"].Visible = true;
            }

        }

        private void toolStripMenuItem3_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem3.Checked == true)
            {
                dataGridView1.Columns["P.Discount"].Visible = false;

            }
            if (toolStripMenuItem3.Checked == false)
            {
                dataGridView1.Columns["P.Discount"].Visible = true;
            }
        }

        private void toolStripMenuItem4_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem4.Checked == true)
            {
                dataGridView1.Columns["ORRMFG"].Visible = false;

            }
            if (toolStripMenuItem4.Checked == false)
            {
                dataGridView1.Columns["ORRMFG"].Visible = true;
            }
        }

        private void toolStripMenuItem5_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem5.Checked == true)
            {
                dataGridView1.Columns["batch"].Visible = false;

            }
            if (toolStripMenuItem5.Checked == false)
            {
                dataGridView1.Columns["batch"].Visible = true;
            }
        }

        private void toolStripMenuItem6_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem6.Checked == true)
            {
                dataGridView1.Columns["Expiry"].Visible = false;

            }
            if (toolStripMenuItem6.Checked == false)
            {
                dataGridView1.Columns["Expiry"].Visible = true;
            }
        }

        private void toolStripMenuItem7_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem7.Checked == true)
            {
                dataGridView1.Columns["MFD"].Visible = false;

            }
            if (toolStripMenuItem7.Checked == false)
            {
                dataGridView1.Columns["MFD"].Visible = true;
            }
        }

        private void toolStripMenuItem8_CheckStateChanged(object sender, EventArgs e)
        {
            if (toolStripMenuItem8.Checked == true)
            {
                dataGridView1.Columns["RACK"].Visible = false;

            }
            if (toolStripMenuItem8.Checked == false)
            {
                dataGridView1.Columns["RACK"].Visible = true;
            }
        }
        #endregion
        public void amount0()
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {
            try
            {
                double discoutper = double.Parse(textBox8.Text);
                double discoutamout = textbfill * discoutper * 0.01;
                textBox17.Text = discoutamout.ToString();
                double newtextbfill = textbfill - discoutamout;
                textBox10.Text = newtextbfill.ToString();
                realvalue1 = newtextbfill;
                textBox9_TextChanged(sender, e);
            }
            catch (Exception sa) { }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }
        public void textchage()
        {
            try
            {
                double t7, t13, t3, t2, t5, t4, t6;
                t7 = Convert.ToDouble(textBox7.Text);
                t13 = Convert.ToDouble(textBox13.Text);
                t3 = Convert.ToDouble(textBox3.Text);
                t2 = Convert.ToDouble(textBox2.Text);
                t5 = Convert.ToDouble(textBox5.Text);
                t4 = Convert.ToDouble(textBox4.Text);
                t6 = Convert.ToDouble(textBox6.Text);
                textbfill = t7 + t13 + t3 + t2 + t5 + t4 + t6;
                textBox10.Text = textbfill.ToString();
            }
            catch (Exception es) { }
        }
        #region calculation on textchange all textbox effect
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }

        private void textBox13_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {
            textchage();
            textBox8_TextChanged(sender, e);
            textBox9_TextChanged(sender, e);
        }
        private void textBox8_Validated(object sender, EventArgs e)
        {
            if (textBox8.Text == "")
            {
                textBox8.Text = "0";
            }
        }
        #endregion
        private void textBox9_TextChanged(object sender, EventArgs e)
        {
            try
            {

                double discoutper = double.Parse(textBox9.Text);
                if (discoutper > 0)
                {
                    double realvalue = realvalue1;
                    double discoutamout = realvalue + discoutper;
                    textBox10.Text = discoutamout.ToString();

                }

                else
                {

                    double realvalue = realvalue1;
                    double discoutamout = realvalue + discoutper;
                    textBox10.Text = discoutamout.ToString();

                }

            }
            catch (Exception sa) { }
        }
        #region datagridview enter key press move to next cell
        private void dataGridView1_KeyUp(object sender, KeyEventArgs e)
        {

            try
            {

                if (e.KeyCode == Keys.Enter)
                {

                    DataGridView vm = (DataGridView)sender;

                    if (vm.CurrentCell.RowIndex == vm.Rows.Count - 1)
                    {

                        //if it's not the last cell, move to the next one
                        if (vm.CurrentCell.ColumnIndex != 17)
                        {
                            //if (vm.CurrentCell.ColumnIndex == 7)
                            //{
                            //    vm.CurrentCell = vm.Rows[vm.CurrentCell.RowIndex].Cells[vm.CurrentCell.ColumnIndex + 15];
                            //}
                            //if (vm.CurrentCell.ColumnIndex == 8)
                            //{
                            //    vm.CurrentCell = vm.Rows[vm.CurrentCell.RowIndex].Cells[vm.CurrentCell.ColumnIndex + 13];
                            //}
                           
                            vm.CurrentCell = vm.Rows[vm.CurrentCell.RowIndex].Cells[vm.CurrentCell.ColumnIndex + 1];
                        }
                        else
                        {
                            if (dataGridView1.CurrentRow.Cells[1].Value == null)
                            {
                                MessageBox.Show("Please Select Item Name..");
                                SendKeys.Send("{Home}");
                            }
                            else
                            {
                                if (dataGridView1.CurrentRow.Cells[4].Value == null)
                                {
                                    MessageBox.Show("Quantity Must be Grater Than 0.");
                                    SendKeys.Send("{Home}");
                                    SendKeys.Send("{Right}");
                                    SendKeys.Send("{Right}");
                                    SendKeys.Send("{Right}");
                                }
                                else
                                {
                                    if (dataGridView1.CurrentRow.Cells[9].Value == null)
                                    {
                                        MessageBox.Show("Rate Must Be Grater Than 0");
                                        SendKeys.Send("{Home}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                        SendKeys.Send("{Right}");
                                    }
                                    else
                                    {
                                        vm.EndEdit();
                                        vm.Rows.Add();
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{left}");
                                        SendKeys.Send("{down}");
                                    }
                                }
                            }

                        }
                    }
                    else
                    {

                        if (vm.CurrentCell.ColumnIndex == 17)
                        {

                            vm.CurrentCell = vm.Rows[vm.CurrentCell.RowIndex + 1].Cells[0];
                        }
                        else
                        {

                            vm.CurrentCell = vm.Rows[vm.CurrentCell.RowIndex].Cells[vm.CurrentCell.ColumnIndex + 1];
                        }
                    }

                    e.Handled = true;
                }
            }
            catch (Exception ms) { }

        }
        #endregion
        private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {
            if (dataGridView1.IsCurrentCellInEditMode == true)
            {
                dataGridView1.AllowUserToAddRows = false;
            }
        }


        public void ValueForConditionUpdate()
        {
            try
            {
                //sud
                DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                SqlDataAdapter adp = new SqlDataAdapter("SELECT TOP 1 F_BILLNO,F_DATE,V_NO,F_COMP,F_BDATE FROM FAT WHERE F_BILLNO='" + textBox1.Text + "' and F_DATE='" + DT2.ToLongDateString() + "' AND V_NO='" + fdcd.ToString() + "' AND F_BDATE='" + DT1.ToLongDateString() + "'", con);
                SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                DataSet ds = new DataSet("s");
                adp.Fill(ds, "s");
                foreach (DataRow dr in ds.Tables["s"].Rows)
                {
                    ofbillno = dr["F_BILLNO"].ToString();
                    ofdate = dr["F_DATE"].ToString();
                    ovno = dr["V_NO"].ToString();
                    ofcomp = dr["F_COMP"].ToString();
                    ofbdate = dr["F_BDATE"].ToString();

                }
            }
            catch (Exception mss) { }
        }


        public void SecondGridFillMethod()
        {

            try
            {

                for (int y = 0; y <= dataGridView1.Rows.Count; y++)
                {

                    double condition0 = Convert.ToDouble(dataGridView1.Rows[y].Cells[7].Value.ToString());
                    if (condition0 <= 0)
                    {
                        double quantity1 = double.Parse(dataGridView1.Rows[y].Cells[4].Value.ToString());
                        double prate1 = double.Parse(dataGridView1.Rows[y].Cells[9].Value.ToString());
                        dataGridView1.Rows[y].Cells[17].Value = quantity1 * prate1;

                        double tradval4 = double.Parse(dataGridView1.Rows[y].Cells[17].Value.ToString());
                        double discout4 = double.Parse(dataGridView1.Rows[y].Cells[8].Value.ToString());
                        double discoutamoutvat4 = tradval4 * discout4 * 0.01;
                        double amout4 = tradval4 - discoutamoutvat4;
                        dataGridView1.Rows[y].Cells[28].Value = amout4.ToString("0.00");
                        double vat4 = amout4 * condition0 * 0.01;
                        dataGridView1.Rows[y].Cells[24].Value = vat4.ToString("0.00");
                        double sat4 = double.Parse(dataGridView1.Rows[y].Cells[21].Value.ToString());
                        double sat4amout = amout4 * sat4 * 0.01;
                        dataGridView1.Rows[y].Cells[25].Value = sat4amout.ToString("0.00");

                    }
                    /////////////////////////////////////////////4v///////////////////////////////////////////////////////////////////
                    double condition4 = Convert.ToDouble(dataGridView1.Rows[y].Cells[7].Value.ToString());
                    if (condition4 > 0 && condition4 < 12.5)
                    {
                        double quantity1 = double.Parse(dataGridView1.Rows[y].Cells[4].Value.ToString());
                        double prate1 = double.Parse(dataGridView1.Rows[y].Cells[9].Value.ToString());
                        dataGridView1.Rows[y].Cells[17].Value = quantity1 * prate1;

                        double tradval4 = double.Parse(dataGridView1.Rows[y].Cells[17].Value.ToString());
                        double discout4 = double.Parse(dataGridView1.Rows[y].Cells[8].Value.ToString());
                        double discoutamoutvat4 = tradval4 * discout4 * 0.01;
                        double amout4 = tradval4 - discoutamoutvat4;
                        dataGridView1.Rows[y].Cells[28].Value = amout4.ToString("0.00");
                        double vat4 = amout4 * condition4 * 0.01;
                        dataGridView1.Rows[y].Cells[24].Value = vat4.ToString("0.00");
                        double sat4 = double.Parse(dataGridView1.Rows[y].Cells[21].Value.ToString());
                        double sat4amout = amout4 * sat4 * 0.01;
                        dataGridView1.Rows[y].Cells[25].Value = sat4amout.ToString("0.00");

                    }
                    //////////////////////////////12 vat//////////////////////////////////////////////////////
                    double condition12 = Convert.ToDouble(dataGridView1.Rows[y].Cells[7].Value.ToString());
                    if (condition12 >= 12.5)
                    {
                        double quantity1 = double.Parse(dataGridView1.Rows[y].Cells[4].Value.ToString());
                        double prate1 = double.Parse(dataGridView1.Rows[y].Cells[9].Value.ToString());
                        dataGridView1.Rows[y].Cells[17].Value = quantity1 * prate1;

                        double tradval4 = double.Parse(dataGridView1.Rows[y].Cells[17].Value.ToString());
                        double discout4 = double.Parse(dataGridView1.Rows[y].Cells[8].Value.ToString());
                        double discoutamoutvat4 = tradval4 * discout4 * 0.01;
                        double amout4 = tradval4 - discoutamoutvat4;
                        dataGridView1.Rows[y].Cells[28].Value = amout4.ToString("0.00");
                        double vat12 = amout4 * condition12 * 0.01;
                        dataGridView1.Rows[y].Cells[26].Value = vat12.ToString("0.00");
                        double sat4 = double.Parse(dataGridView1.Rows[y].Cells[21].Value.ToString());
                        double sat4amout = amout4 * sat4 * 0.01;
                        dataGridView1.Rows[y].Cells[27].Value = sat4amout.ToString("0.00");

                    }
                }
            }
            catch (Exception ms) { }

        }
        #region m1
        public void ModifyTextINfatamount0()
        {

            double TEXT3 = Convert.ToDouble(textBox3.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat  WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60001' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)/////update
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox3.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60001' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        DateTime cofdate = Convert.ToDateTime(ofbdate);
                        DateTime cofdate1 = Convert.ToDateTime(ofdate);
                        string amountu = "-" + textBox3.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + cofdate1.ToLongDateString() + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60001' AND F_COMP='" + ofcomp + "' and F_BDATE='" + cofdate.ToLongDateString() + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60001' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                double condition = Convert.ToDouble(textBox3.Text.ToString());
                if (condition > 0)
                {
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code
                    dr["amount"] = "-" + textBox3.Text;//TEXTBOX3 FOR 0% AMOUNT
                    dr["A_CODE"] = "60001";////code for amout4%
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                }
            }
            MessageBox.Show("Update");

        }
        #endregion
        #region m2
        public void ModifyTextINfatamount4()
        {
            double TEXT3 = Convert.ToDouble(textBox2.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60002' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)/////update
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox2.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60002' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        string amountu = "-" + textBox2.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60002' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60002' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {

                if (TEXT3 > 0)
                {
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code
                    dr["A_CODE"] = "60002";////code for amout4%
                    dr["amount"] = "-" + textBox2.Text;//TEXTBOX3 FOR 0% AMOUNT
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                }
            }
           
        }
        #endregion
        #region m3
        public void ModifyTextINfatvat4()
        {
            double TEXT3 = Convert.ToDouble(textBox4.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat  WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60007' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox4.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60007' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        string amountu = "-" + textBox4.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60007' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60007' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {

                if (TEXT3 > 0)
                {
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code
                    dr["A_CODE"] = "60007";////code for vat 4%
                    dr["amount"] = "-" + textBox4.Text;//TEXTBOX3 FOR 0% AMOUNT
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                }
            }
            
        }
        #endregion
        #region m4
        public void ModifyTextINfatvat4andSAT1()
        {
            double TEXT3 = Convert.ToDouble(textBox13.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat  WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60009' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox13.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60009' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        string amountu = "-" + textBox13.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60009' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60009' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                if (TEXT3 > 0)
                {
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code
                    dr["A_CODE"] = "60009";////code for vat 4 and adtition 1%
                    dr["amount"] = "-" + textBox13.Text;//TEXTBOX3 FOR 0% AMOUNT
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                }
            }

        }
        #endregion
        #region m5
        public void ModifyTextINfatamount12()
        {
            try
            {
                double TEXT3 = Convert.ToDouble(textBox5.Text.ToString());
                SqlCommand cmd = new SqlCommand("select A_CODE from fat  WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60003' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adp.Fill(ds, "s");
                if (ds.Tables["s"].Rows.Count == 1)
                {
                    if (TEXT3 > 0)
                    {
                        DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                        DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                        if (comboBox1.SelectedIndex == 1)
                        {
                            con.Open();
                            string amountu = "-" + textBox5.Text;
                            SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60003' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                            cd.ExecuteNonQuery();
                            con.Close();

                        }
                        if (comboBox1.SelectedIndex == 0)
                        {
                            con.Open();
                            string amountu = "-" + textBox5.Text;
                            SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60003' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                            cd.ExecuteNonQuery();
                            con.Close();
                        }
                    }
                    if (TEXT3 == 0)//////delete
                    {
                        con.Open();
                        SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60003' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                else
                {
                    if (TEXT3 > 0)
                    {
                        SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                        SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                        DataSet ds1 = new DataSet();
                        adp1.Fill(ds1, "s");
                        DataRow dr;
                        DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                        DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                        dr = ds1.Tables["s"].NewRow();
                        dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                        dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                        dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE                 
                        dr["f_billno"] = textBox1.Text.Trim();//invoice no                 
                        dr["f_bdate"] = DT1.ToLongDateString();
                        dr["f_date"] = DT2.ToLongDateString();
                        dr["v_no"] = fdcd.ToString();//party code
                        dr["A_CODE"] = "60003";////code for 0%
                        dr["amount"] = "-" + textBox5.Text;//TEXTBOX3 FOR 0% AMOUNT
                        if (comboBox1.SelectedIndex == 1)
                        {
                            dr["entry"] = "RP";//COMBOBOX1 SLECTION
                        }
                        if (comboBox1.SelectedIndex == 0)
                        {
                            dr["entry"] = "CP";//COMBOBOX1 SELECTION
                        }
                        ds1.Tables["s"].Rows.Add(dr);
                        adp1.Update(ds1, "s");
                    }
                }
            }
            catch (Exception ess) { }

        }
        #endregion
        #region m6
        public void ModifyTextINfatvat12()
        {
            double TEXT3 = Convert.ToDouble(textBox6.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60008' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox6.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60008' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        string amountu = "-" + textBox6.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60008' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60008' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                if (TEXT3 > 0)
                {
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code
                    dr["A_CODE"] = "60008";////code for 0%
                    dr["amount"] = "-" + textBox6.Text;//TEXTBOX3 FOR 0% AMOUNT
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                }
            }

        }
        #endregion
        #region m7
        public void ModifyTextINfatvat12SAT1()
        {
            double TEXT3 = Convert.ToDouble(textBox7.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60010' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)/////update
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox7.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60010' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        string amountu = "-" + textBox7.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60010' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60010' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                if (TEXT3 > 0)
                {
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["particular"] = textBox1.Text.Trim();//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code
                    dr["A_CODE"] = "60010";////code for 0%
                    dr["amount"] = "-" + textBox7.Text;//TEXTBOX3 FOR 0% AMOUNT
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                }
            }

        }
        #endregion
        #region m8
        public void ModifyTextINfatdicount()
        {
            double TEXT3 = Convert.ToDouble(textBox8.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60019' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
              
                if (TEXT3 > 0)/////update
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = "-" + textBox17.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "     discount % is:" + textBox8.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60019' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        con.Open();
                        string amountu = "-" + textBox17.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP' ,F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text + "     discount % is:" + textBox8.Text + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60019' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60019' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                if (TEXT3 > 0)
                {
                  
                    SqlDataAdapter adp1 = new SqlDataAdapter("select * from fat", con);
                    SqlCommandBuilder cd1 = new SqlCommandBuilder(adp1);
                    DataSet ds1 = new DataSet();
                    adp1.Fill(ds1, "s");
                    DataRow dr;
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    dr = ds1.Tables["s"].NewRow();
                    dr["f_date"] = DT2.ToLongDateString();
                    dr["v_no"] = fdcd.ToString();//party code    
                    if (comboBox1.SelectedIndex == 1)
                    {
                        dr["entry"] = "RP";//COMBOBOX1 SLECTION
                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        dr["entry"] = "CP";//COMBOBOX1 SELECTION
                    }
                    dr["particular"] = textBox1.Text.Trim() + "     discount % is:" + textBox8.Text;//INVOICE NO
                    dr["dbt_cdt"] = "D";//NEGATIVE VLAUE OF AMOUT
                    dr["A_CODE"] = "60019";////code for 0%
                    dr["amount"] = "-" + textBox17.Text;//TEXTBOX3 FOR 0% AMOUNT
                    dr["f_comp"] = STTYP.ToString();//PASS LOGIN TIME TEXT READ ACCODING OT COMPANY SE
                    dr["f_bdate"] = DT1.ToLongDateString();
                    dr["f_billno"] = textBox1.Text.Trim();//invoice no
                    ds1.Tables["s"].Rows.Add(dr);
                    adp1.Update(ds1, "s");
                    con.Close();
                }
            }

        }
        #endregion
        #region m9
        public void ModifyTextINfatRoundOff()
        {
            double roundoffvariable = Convert.ToDouble(textBox9.Text);
            double TEXT3 = Convert.ToDouble(textBox9.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60018' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)/////update
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        if (roundoffvariable > 0)
                        {
                            con.Open();
                            string amountu = textBox9.Text;
                            SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text.Trim() + "' , DBT_CDT='C' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60018' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                            cd.ExecuteNonQuery();
                            con.Close();

                        }
                        else
                        {
                            con.Open();
                            string amountu = textBox9.Text;
                            SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text.Trim() + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60018' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                            cd.ExecuteNonQuery();
                            con.Close();

                        }

                    }
                    if (comboBox1.SelectedIndex == 0)
                    {
                        if (roundoffvariable > 0)
                        {
                            con.Open();
                            string amountu = textBox9.Text;
                            SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text.Trim() + "' , DBT_CDT='C' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60018' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                            cd.ExecuteNonQuery();
                            con.Close();

                        }
                        else
                        {
                            con.Open();
                            string amountu = textBox9.Text;
                            SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='CP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text.Trim() + "' , DBT_CDT='D' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60018' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                            cd.ExecuteNonQuery();
                            con.Close();

                        }
                    }
                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='60018' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                if (TEXT3 > 0)
                {
                    roundoff();
                }
            }

        }
        #endregion
        #region m10
        public void ModifyTextINfatGrandTotoal()
        {
            double roundoffvariable = Convert.ToDouble(textBox10.Text);
            double TEXT3 = Convert.ToDouble(textBox9.Text.ToString());
            SqlCommand cmd = new SqlCommand("select A_CODE from fat WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='" + fdcd + "' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds, "s");
            if (ds.Tables["s"].Rows.Count == 1)
            {
                if (TEXT3 > 0)/////update
                {
                    DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                    DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                    if (comboBox1.SelectedIndex == 1)
                    {
                        con.Open();
                        string amountu = textBox9.Text;
                        SqlCommand cd = new SqlCommand("UPDATE FAT SET ENTRY='RP', F_DATE='" + DT2.ToLongDateString() + "' , V_NO='" + fdcd.ToString() + "' , PARTICULAR='" + textBox1.Text.Trim() + "' , DBT_CDT='C' , AMOUNT='" + amountu.ToString() + "' , F_COMP='" + STTYP.ToString() + "' , F_BDATE='" + DT1.ToLongDateString() + "', F_BILLNO='" + textBox1.Text + "' WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='" + fdcd + "' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }

                }
                if (TEXT3 == 0)//////delete
                {
                    con.Open();
                    SqlCommand cd = new SqlCommand("DELETE FAT WHERE F_DATE='" + ofdate + "' AND V_NO='" + ovno + "' AND F_BILLNO='" + ofbillno + "' AND A_CODE='" + fdcd + "' AND F_COMP='" + ofcomp + "' and F_BDATE='" + ofbdate + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();
                }
            }
            else
            {
                if (TEXT3 > 0)
                {
                    if (comboBox1.SelectedIndex == 1)
                    {
                        grandTotal();
                    }
                }
            }

        }
        #endregion

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        public void GRIDVIEWUPDATEFIRST()
        {
            
            try
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    double quntitydel = double.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString());
                    if (quntitydel <= 0)
                    {
                        con.Open();
                        SqlCommand cd = new SqlCommand("delete ppt where f_recno='" + dataGridView1.Rows[i].Cells[18].Value.ToString() + "'", con);
                        cd.ExecuteNonQuery();
                        con.Close();
                    }
                    if (dataGridView1.Rows[i].Cells[18].Value != null)
                    {
                        GRIDVIEWUPDATEFIRST1();
                    }
                    else
                    {
                        con.Close();
                        con.Open();
                        SqlDataAdapter adp = new SqlDataAdapter("select * from ppt", con);
                        SqlCommandBuilder cd = new SqlCommandBuilder(adp);
                        DataSet ds = new DataSet();
                        adp.Fill(ds, "s");
                        DataRow dr;
                        DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
                        DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
                        DateTime DT3 = Convert.ToDateTime(dateTimePicker3.Text);
                        if (dataGridView1.Rows[i].Cells[17].Value == null)
                        {
                        }
                        else
                        {
                            decimal amt = Convert.ToDecimal(dataGridView1.Rows[i].Cells[16].Value.ToString());
                            decimal qnt = Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value.ToString());
                            decimal fqnt = amt / qnt;
                            dr = ds.Tables["s"].NewRow();
                            dr["INVOICE_NO"] = textBox1.Text.Trim();
                            dr["F_CACR"] = cacr.ToString();
                            dr["F_DATE"] = DT1.ToLongDateString();
                            dr["F_RECDT"] = DT2.ToLongDateString();
                            dr["F_DUEDT"] = DT3.ToLongDateString();
                            dr["P_CODE"] = dataGridView1.Rows[i].Cells[19].Value.ToString();
                            dr["F_STTYPE"] = STTYP.ToString();
                            dr["F_PCODE"] = fdcd.ToString();
                            dr["F_QNT"] = fqnt.ToString();
                            dr["PUR_QNT"] = dataGridView1.Rows[i].Cells[4].Value.ToString();
                            dr["F_NORMAL"] = dataGridView1.Rows[i].Cells[0].Value.ToString();
                            dr["P_NAME"] = dataGridView1.Rows[i].Cells[1].Value.ToString();
                            dr["P_PACKING"] = dataGridView1.Rows[i].Cells[2].Value.ToString();
                            dr["F_ADTPER"] = dataGridView1.Rows[i].Cells[21].Value.ToString();
                            dr["F_MRP"] = dataGridView1.Rows[i].Cells[3].Value.ToString();
                            dr["P_QNT"] = dataGridView1.Rows[i].Cells[4].Value.ToString();
                            dr["F_PDEAL"] = dataGridView1.Rows[i].Cells[5].Value.ToString();
                            dr["F_SDEAL"] = dataGridView1.Rows[i].Cells[6].Value.ToString();
                            dr["F_VATPER"] = dataGridView1.Rows[i].Cells[7].Value.ToString();
                            dr["F_DISC_BEF"] = dataGridView1.Rows[i].Cells[8].Value.ToString();
                            dr["F_STRATE"] = dataGridView1.Rows[i].Cells[9].Value.ToString();
                            dr["F_TRADE"] = dataGridView1.Rows[i].Cells[10].Value.ToString();
                            dr["F_ORMFD"] = dataGridView1.Rows[i].Cells[11].Value.ToString();
                            dr["BAT_NO"] = dataGridView1.Rows[i].Cells[12].Value.ToString();
                            dr["F_EXPDT"] = dataGridView1.Rows[i].Cells[13].Value.ToString();
                            dr["F_MFD"] = dataGridView1.Rows[i].Cells[14].Value.ToString();
                            dr["F_RACKNO"] = dataGridView1.Rows[i].Cells[15].Value.ToString();
                            dr["AMOUNT"] = dataGridView1.Rows[i].Cells[16].Value.ToString();
                            dr["F_CTRADE"] = dataGridView1.Rows[i].Cells[23].Value.ToString();

                            ds.Tables["s"].Rows.Add(dr);
                            adp.Update(ds, "s");
                        }

                        con.Close();
                    }
                }
              
            }
            catch (Exception es) { }
        }
        public void GRIDVIEWUPDATEFIRST1()
        {
            //UPS
            DateTime DT1 = Convert.ToDateTime(dateTimePicker1.Text);
            DateTime DT2 = Convert.ToDateTime(dateTimePicker2.Text);
            DateTime DT3 = Convert.ToDateTime(dateTimePicker3.Text);
          
            try
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {

                    if (dataGridView1.Rows[i].Cells[5].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[5].Value = "0";
                    }
                    if (dataGridView1.Rows[i].Cells[6].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[6].Value = "0";
                    }
                    if (dataGridView1.Rows[i].Cells[7].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[7].Value = "0";
                    }
                    if (dataGridView1.Rows[i].Cells[8].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[8].Value = "0";
                    }
                    if (dataGridView1.Rows[i].Cells[9].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[9].Value = "0";
                    }
                    if (dataGridView1.Rows[i].Cells[10].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[10].Value = " ";
                    }
                    if (dataGridView1.Rows[i].Cells[11].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[11].Value = " ";
                    }
                    if (dataGridView1.Rows[i].Cells[12].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[12].Value = " ";
                    }
                    if (dataGridView1.Rows[i].Cells[13].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[13].Value = "/";
                    }
                    if (dataGridView1.Rows[i].Cells[14].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[14].Value = " ";
                    }
                    if (dataGridView1.Rows[i].Cells[15].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[15].Value = " ";
                    }
                    if (dataGridView1.Rows[i].Cells[23].Value == null)
                    {
                        dataGridView1.Rows[i].Cells[23].Value = "0";
                    }

                    decimal amt = Convert.ToDecimal(dataGridView1.Rows[i].Cells[16].Value.ToString());
                    decimal qnt = Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value.ToString());
                    decimal fqnt = amt / qnt;
                    con.Open();
                    SqlCommand cd = new SqlCommand("UPDATE PPT SET INVOICE_NO ='" + textBox1.Text.Trim() + "',F_CACR = '" + cacr.ToString() + "',F_DATE = '" + DT1.ToLongDateString() + "',F_RECDT = '" + DT1.ToLongDateString() + "',F_DUEDT = '" + DT1.ToLongDateString() + "',P_NAME = '" + dataGridView1.Rows[i].Cells[1].Value.ToString() + "' ,P_CODE = '" + dataGridView1.Rows[i].Cells[19].Value.ToString() + "',PUR_QNT = '" + dataGridView1.Rows[i].Cells[4].Value.ToString() + "',F_NORMAL = '" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "',P_PACKING = '" + dataGridView1.Rows[i].Cells[2].Value.ToString() + "',F_ADTPER = '" + dataGridView1.Rows[i].Cells[21].Value.ToString() + "',F_MRP = '" + dataGridView1.Rows[i].Cells[3].Value.ToString() + "',P_QNT = '" + dataGridView1.Rows[i].Cells[4].Value.ToString() + "',F_PDEAL = '" + dataGridView1.Rows[i].Cells[5].Value.ToString() + "',F_SDEAL = '" + dataGridView1.Rows[i].Cells[6].Value.ToString() + "',F_VATPER = '" + dataGridView1.Rows[i].Cells[7].Value.ToString() + "',F_DISC_BEF = '" + dataGridView1.Rows[i].Cells[8].Value.ToString() + "',F_STRATE = '" + dataGridView1.Rows[i].Cells[9].Value.ToString() + "',F_TRADE = '" + dataGridView1.Rows[i].Cells[10].Value.ToString() + "',F_ORMFD = '" + dataGridView1.Rows[i].Cells[11].Value.ToString() + "',BAT_NO = '" + dataGridView1.Rows[i].Cells[12].Value.ToString() + "',F_EXPDT = '" + dataGridView1.Rows[i].Cells[13].Value.ToString() + "',F_MFD = '" + dataGridView1.Rows[i].Cells[14].Value.ToString() + "',F_RACKNO = '" + dataGridView1.Rows[i].Cells[15].Value.ToString() + "',AMOUNT = '" + dataGridView1.Rows[i].Cells[16].Value.ToString() + "',F_CTRADE='" + dataGridView1.Rows[i].Cells[23].Value.ToString() + "',F_STTYPE = '" + STTYP.ToString() + "',F_PCODE = '" + fdcd.ToString() + "',F_QNT = '" + fqnt.ToString() + "' WHERE F_RECNO='" + dataGridView1.Rows[i].Cells[18].Value.ToString() + "'", con);
                    cd.ExecuteNonQuery();
                    con.Close();

                }
            }
            catch (Exception ess) { }

        }

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

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

        private void mediamToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ft.Restore(this);
        }

        private void fullToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ft.Maximize(this);
        }

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


    }
}

share this blog :
post comment