C# w、 单元格[“TDS”]。值=转换为32(TDS); newDataRow.Cells[“Final_Amt”]。Value=NetSalary; } } 私有void advancedDataGridView1\u SortStringChanged(

C# w、 单元格[“TDS”]。值=转换为32(TDS); newDataRow.Cells[“Final_Amt”]。Value=NetSalary; } } 私有void advancedDataGridView1\u SortStringChanged(,c#,winforms,ms-access,datagridview,C#,Winforms,Ms Access,Datagridview,w、 单元格[“TDS”]。值=转换为32(TDS); newDataRow.Cells[“Final_Amt”]。Value=NetSalary; } } 私有void advancedDataGridView1\u SortStringChanged(对象发送方,事件参数e) { this.bs.Sort=this.dataGridView1.SortString; } 私有void advancedDataGridView1\u筛选器字符串已更改(对象发送方,事件参数e) { this.b

w、 单元格[“TDS”]。值=转换为32(TDS); newDataRow.Cells[“Final_Amt”]。Value=NetSalary; } } 私有void advancedDataGridView1\u SortStringChanged(对象发送方,事件参数e) { this.bs.Sort=this.dataGridView1.SortString; } 私有void advancedDataGridView1\u筛选器字符串已更改(对象发送方,事件参数e) { this.bs.Filter=this.dataGridView1.FilterString; } 私有void dataGridView1_CellEndEdit(对象发送方,DataGridViewCellEventArgs e) { } 公共教育 { 初始化组件(); } 专用双TotalTds() { 如果(indexofrow>=0) { foreach(dataGridView1.Rows中的DataGridViewRow行) { if(dataGridView1.Rows!=null) { 尝试 { OpenConnection(); query=“从年度数据中选择TotalTDS,其中员工代码=@a”; scm=新的OleDbCommand(查询、数据库.myConnection); scm.Parameters.AddWithValue(“@a”和“+行.单元格[“员工代码”].Value+”); sdr=scm.ExecuteReader(); while(sdr.Read()) { totaltds=Convert.ToDouble(sdr.GetValue(0)); } CloseConnection(); } 捕获(例外) { 投掷; } } } } 返回总TDS; } 私有无效按钮2\u单击(对象发送者,事件参数e) { sdr=SelectMonthValue(); if(sdr.Read()==false) { foreach(dataGridView1.Rows中的DataGridViewRow行) { 使用(scm=new-OleDbCommand(“插入“+comboBox1.SelectedItem.ToString()+”(员工代码、工作日、EPF、TDS、最终金额)值(@b、@c、@d、@e、@f)”,database.myConnection) { 尝试 { scm.Parameters.AddWithValue(“@b”,行.单元格[“员工代码”].Value); scm.Parameters.AddWithValue(“@c”,行.单元格[“工作日”].Value); scm.Parameters.AddWithValue(“@d”,row.Cells[“EPF”].Value); scm.Parameters.AddWithValue(“@e”,行.单元格[“TDS”].Value); scm.Parameters.AddWithValue(“@f”,行单元格[“最终金额”].Value); scm.ExecuteNonQuery(); } 捕获(例外情况除外) { Show(例如ToString(),“Message”,MessageBoxButtons.OK,MessageBoxIcon.Information); } } } } 其他的 { foreach(dataGridView1.Rows中的DataGridViewRow行) { 使用(scm=new-OleDbCommand(“更新”+comboBox1.SelectedItem.ToString()+“设置工作日=@c,EPF=@d,TDS=@e,最终金额=@f,其中员工代码=@b”,database.myConnection)) { 尝试 { scm.Parameters.AddWithValue(“@c”,行.单元格[“工作日”].Value); scm.Parameters.AddWithValue(“@d”,row.Cells[“EPF”].Value); scm.Parameters.AddWithValue(“@e”,行.单元格[“TDS”].Value); scm.Parameters.AddWithValue(“@f”,行单元格[“最终金额”].Value); scm.Parameters.AddWithValue(“@b”,行.单元格[“员工代码”].Value); scm.ExecuteNonQuery(); } 捕获(例外情况除外) { Show(例如ToString(),“Message”,MessageBoxButtons.OK,MessageBoxIcon.Information); } } } } 如果(comboBox1.SelectedIndex==0) { query=“更新年度数据集[工作日(Apr)]=@a、[EPF(Apr)]=@b、[TDS(Apr)]=@c、[NetPay(Apr)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==1) { query=“更新年度数据集[工作日(五月)]=@a、[EPF(五月)]=@b、[TDS(五月)]=@c、[NetPay(五月)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==2) { query=“更新年度数据集[工作日(六月)]=@a、[EPF(六月)]=@b、[TDS(六月)]=@c、[NetPay(六月)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==3) { query=“更新年度数据集[工作日(7月)]=@a、[EPF(7月)]=@b、[TDS(7月)]=@c、[NetPay(7月)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==4) { query=“更新年度数据集[工作日(8月)]=@a、[EPF(8月)]=@b、[TDS(8月)]=@c、[NetPay(8月)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==5) { query=“更新年度数据集[工作日(九月)]=@a、[EPF(九月)]=@b、[TDS(九月)]=@c、[NetPay(九月)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==6) { query=“更新年度数据集[工作日(十月)]=@a、[EPF(十月)]=@b、[TDS(十月)]=@c、[NetPay(十月)]=@d,其中员工代码=@e”; } else if(comboBox1.SelectedIndex==7) { query=“更新年度
using System;
using System.Data;
using System.Data.OleDb;
using System.Globalization;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class MonthDeduction : Form
    {
    Database database = new Database();
    int indexofrow;
    OleDbDataAdapter sda;
    OleDbDataReader sdr; OleDbCommand scm; BindingSource bs;
    string query;
    double tmp, monthdays, totaltds,NetSalary;

    private OleDbDataReader SelectMonthValue()
        {
        query = "Select Top 1000 * from " + comboBox1.SelectedItem.ToString() + "";
        scm = new OleDbCommand(query,database.myConnection);
        try
            {
            database.OpenConnection();
            sdr = scm.ExecuteReader();
            return sdr;
            }
        catch (Exception)
            {
            throw;
            }
        }

    private void dataGridView1_CellEndEdit_1(object sender,DataGridViewCellEventArgs e)
        {
        indexofrow = e.RowIndex;
        if (comboBox1.SelectedText != null)
            {
            int month = DateTime.ParseExact(Convert.ToString(comboBox1.SelectedItem),"MMMM",CultureInfo.InvariantCulture).Month;
            monthdays = DateTime.DaysInMonth(DateTime.Now.Year,month);
            }
        if (dataGridView1.Rows != null)
            {
            DataGridViewRow newDataRow = dataGridView1.Rows[indexofrow];
            double wd = Convert.ToDouble(newDataRow.Cells["Working_Days"].Value);
            double epf = Convert.ToDouble(newDataRow.Cells["EPF"].Value);
            double tds = Convert.ToDouble(newDataRow.Cells["TDS"].Value);
            double salary = Convert.ToDouble(newDataRow.Cells["Basic_Salary"].Value);
            DateTime dob = Convert.ToDateTime(newDataRow.Cells["DOB"].Value);
            double yearlysalary = salary * 12;
            totaltds = TotalTds();
            double twofifty = 250000 / 12;
            double three = 300000 / 12;
            double five = 500000 / 12;
            double ten = 1000000 / 12;
            double finalsalary = (salary / monthdays) * wd;
            int age = 0;
            age = DateTime.Now.Year - dob.Year;
            if (DateTime.Now.DayOfYear < dob.DayOfYear)
                {
                age = age - 1;
                }
            if (wd > monthdays)
                {
                DialogResult result = MessageBox.Show("Working Days Could Not Be Greater Than MonthDays","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                if (result == System.Windows.Forms.DialogResult.OK)
                    {
                    newDataRow.Cells["Working_Days"].Value = 0;
                    newDataRow.Cells["EPF"].Value = 0;
                    newDataRow.Cells["TDS"].Value = 0;
                    newDataRow.Cells["Final_Amt"].Value = 0;
                    }
                }
            else if (salary <= 15000)
                {
                epf = finalsalary * .12;
                tds = 0;
                NetSalary = Convert.ToInt32(finalsalary - epf);
                }
            else if (salary > 15000 & salary < twofifty)
                {
                tds = 0;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary);
                }
            else if (age < 60 & salary > twofifty & salary < five)
                {
                tmp = (yearlysalary - 250000) * .05;
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            else if (age < 60 & salary > five & salary < ten)
                {
                tmp = 12500 + ((yearlysalary - 500000) * .20);
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            else if (age < 60 & salary > ten)
                {
                tmp = 112500 + ((yearlysalary - 1000000) * .30);
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }

            else if (age > 60 & age < 80 & salary > three & salary < five)
                {
                tmp = yearlysalary * .05;
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            else if (age > 60 & age < 80 & salary > five & salary < ten)
                {
                tmp = 10000 + ((yearlysalary - 500000) * .20);
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            else if (age < 80 & age > 60 & salary > ten)
                {
                tmp = 110000 + ((yearlysalary - 1000000) * .30);
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            else if (age > 80 & salary > five & salary < ten)
                {
                tmp = yearlysalary * .20;
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            else if (age > 80 & salary > ten)
                {
                tmp = 100000 + ((yearlysalary - 1000000) * .30);
                tds = ((tmp + (tmp * .02)) / 12) - totaltds;
                epf = 0;
                NetSalary = Convert.ToInt32(finalsalary - tds);
                }
            newDataRow.Cells["EPF"].Value = Convert.ToInt32(epf);
            newDataRow.Cells["TDS"].Value = Convert.ToInt32(tds);
            newDataRow.Cells["Final_Amt"].Value = NetSalary;
            }
        }

    private void advancedDataGridView1_SortStringChanged(object sender,EventArgs e)
        {
        this.bs.Sort = this.dataGridView1.SortString;
        }

    private void advancedDataGridView1_FilterStringChanged(object sender,EventArgs e)
        {
        this.bs.Filter = this.dataGridView1.FilterString;
        }
    private void dataGridView1_CellEndEdit(object sender,DataGridViewCellEventArgs e)
        {
        }
    public MonthDeduction()
        {
        InitializeComponent();
        }
    private double TotalTds()
        {
        if (indexofrow >= 0)
            {
            foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                if (dataGridView1.Rows != null)
                    {
                    try
                        {
                        database.OpenConnection();
                        query = "SELECT TotalTDS FROM AnnualTDS where Employee_Code=@a";
                        scm = new OleDbCommand(query,database.myConnection);
                        scm.Parameters.AddWithValue("@a","" + row.Cells["Employee_Code"].Value + "");
                        sdr = scm.ExecuteReader();
                        while (sdr.Read())
                            {
                            totaltds = Convert.ToDouble(sdr.GetValue(0));
                            }
                        database.CloseConnection();
                        }
                    catch (Exception)
                        {
                        throw;
                        }
                    }
                }
            }
        return totaltds;
        }

    private void button2_Click(object sender,EventArgs e)
        {
        sdr = SelectMonthValue();
        if (sdr.Read() == false)
            {                           
            foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                using (scm = new OleDbCommand("INSERT INTO " + comboBox1.SelectedItem.ToString() + " (Employee_Code,Working_Days,EPF,TDS,Final_Amt) VALUES(@b,@c,@d,@e,@f)",database.myConnection))
                    {
                    try
                        {                                                                  
                        scm.Parameters.AddWithValue("@b",row.Cells["Employee_Code"].Value);
                        scm.Parameters.AddWithValue("@c",row.Cells["Working_Days"].Value);
                        scm.Parameters.AddWithValue("@d",row.Cells["EPF"].Value);
                        scm.Parameters.AddWithValue("@e",row.Cells["TDS"].Value);
                        scm.Parameters.AddWithValue("@f",row.Cells["Final_Amt"].Value);
                        scm.ExecuteNonQuery();                                             
                        }
                    catch (Exception ex)
                        {
                        MessageBox.Show(ex.ToString(),"Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
                        }
                    }
                }
            }
        else
            {
            foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                using (scm = new OleDbCommand("UPDATE " + comboBox1.SelectedItem.ToString() + " SET Working_Days=@c,EPF=@d,TDS=@e,Final_Amt=@f where Employee_Code=@b",database.myConnection))
                    {
                    try
                        {                                                                  
                        scm.Parameters.AddWithValue("@c",row.Cells["Working_Days"].Value);
                        scm.Parameters.AddWithValue("@d",row.Cells["EPF"].Value);
                        scm.Parameters.AddWithValue("@e",row.Cells["TDS"].Value);
                        scm.Parameters.AddWithValue("@f",row.Cells["Final_Amt"].Value);
                        scm.Parameters.AddWithValue("@b",row.Cells["Employee_Code"].Value);
                        scm.ExecuteNonQuery();                                            
                        }
                    catch (Exception ex)
                        {
                        MessageBox.Show(ex.ToString(),"Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
                        }
                    }
                }
            }
        if (comboBox1.SelectedIndex == 0)
            {
            query = "Update Annual_Data SET [Working_Days(Apr)]=@a,[EPF(Apr)]=@b,[TDS(Apr)]=@c,[NetPay(Apr)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 1)
            {
            query = "Update Annual_Data SET [Working_Days(May)]=@a,[EPF(May)]=@b,[TDS(May)]=@c,[NetPay(May)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 2)
            {
            query = "Update Annual_Data SET [Working_Days(Jun)]=@a,[EPF(Jun)]=@b,[TDS(Jun)]=@c,[NetPay(Jun)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 3)
            {
            query = "Update Annual_Data SET [Working_Days(Jul)]=@a,[EPF(Jul)]=@b,[TDS(Jul)]=@c,[NetPay(Jul)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 4)
            {
            query = "Update Annual_Data SET [Working_Days(Aug)]=@a,[EPF(Aug)]=@b,[TDS(Aug)]=@c,[NetPay(Aug)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 5)
            {
            query = "Update Annual_Data SET [Working_Days(Sep)]=@a,[EPF(Sep)]=@b,[TDS(Sep)]=@c,[NetPay(Sep)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 6)
            {
            query = "Update Annual_Data SET [Working_Days(Oct)]=@a,[EPF(Oct)]=@b,[TDS(Oct)]=@c,[NetPay(Oct)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 7)
            {
            query = "Update Annual_Data SET [Working_Days(Nov)]=@a,[EPF(Nov)]=@b,[TDS(Nov)]=@c,[NetPay(Nov)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 8)
            {
            query = "Update Annual_Data SET [Working_Days(Dec)]=@a,[EPF(Dec)]=@b,[TDS(Dec)]=@c,[NetPay(Dec)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 9)
            {
            query = "Update Annual_Data SET [Working_Days(Jan)]=@a,[EPF(Jan)]=@b,[TDS(Jan)]=@c,[NetPay(Jan)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 10)
            {
            query = "Update Annual_Data SET [Working_Days(Feb)]=@a,[EPF(Feb)]=@b,[TDS(Feb)]=@c,[NetPay(Feb)]=@d where Employee_Code = @e";
            }
        else if (comboBox1.SelectedIndex == 11)
            {
            query = "Update Annual_Data SET [Working_Days(Mar)]=@a,[EPF(Mar)]=@b,[TDS(Mar)]=@c,[NetPay(Mar)]=@d where Employee_Code = @e";
            }
        foreach (DataGridViewRow row in dataGridView1.Rows)
            {
            try
                {
                scm = new OleDbCommand(query,database.myConnection);
                scm.Parameters.AddWithValue("@a",row.Cells["Working_Days"].Value);
                scm.Parameters.AddWithValue("@b",row.Cells["EPF"].Value);
                scm.Parameters.AddWithValue("@c",row.Cells["TDS"].Value);
                scm.Parameters.AddWithValue("@d",row.Cells["Final_Amt"].Value);
                scm.Parameters.AddWithValue("@e",row.Cells["Employee_Code"].Value);
                scm.ExecuteNonQuery();
                }
            catch (Exception ex)
                {
                MessageBox.Show(ex.ToString());
                }
            }
        MessageBox.Show("Data Saved","Done",MessageBoxButtons.OK,MessageBoxIcon.Information);
        database.CloseConnection();
        }
    private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)
        {
        TotalTds();
        if (comboBox1.SelectedItem != null)
            {
            sdr = SelectMonthValue();
            if (sdr.Read() == false)
                {
                query = "Select Top 1000 Employee_Code,Name,Father_Name,DOB,Place_Of_Post,Program_Name,Designation,Date_Hired,Bank_Name,IFSC,Bank_Ac,Basic_Salary,Working_Days,EPF,TDS,Final_Amt from empinfo";
                scm = new OleDbCommand(query,database.myConnection);
                scm.ExecuteNonQuery();
                sda = new OleDbDataAdapter(scm);
                }
            else
                {
                if (comboBox1.SelectedIndex == 0)
                    {
                    query = "select Top 1000 * from Apr";
                    }
                else if (comboBox1.SelectedIndex == 1)
                    {
                    query = "select Top 1000 * from Mai";
                    }
                else if (comboBox1.SelectedIndex == 2)
                    {
                    query = "select Top 1000 * from Jun";
                    }
                else if (comboBox1.SelectedIndex == 3)
                    {
                    query = "select Top 1000 * from Jul";
                    }
                else if (comboBox1.SelectedIndex == 4)
                    {
                    query = "select Top 1000 * from Aug";
                    }
                else if (comboBox1.SelectedIndex == 5)
                    {
                    query = "select Top 1000 * from Sep";
                    }
                else if (comboBox1.SelectedIndex == 6)
                    {
                    query = "select Top 1000 * from Oct";
                    }
                else if (comboBox1.SelectedIndex == 7)
                    {
                    query = "select Top 1000 * from Nov";
                    }
                else if (comboBox1.SelectedIndex == 8)
                    {
                    query = "select Top 1000 * from Dec";
                    }
                else if (comboBox1.SelectedIndex == 9)
                    {
                    query = "select Top 1000 * from Jan";
                    }
                else if (comboBox1.SelectedIndex == 10)
                    {
                    query = "select Top 1000 * from Feb";
                    }
                else if (comboBox1.SelectedIndex == 11)
                    {
                    query = "select Top 1000 * from Mar";
                    }
                scm = new OleDbCommand(query,database.myConnection);
                scm.ExecuteNonQuery();
                sda = new OleDbDataAdapter(scm);
                }
            DataTable dt = new DataTable();
            sda.Fill(dt);
            bs = new BindingSource();
            bs.DataSource = dt.DefaultView;
            dataGridView1.DataSource = bs;
            dataGridView1.AutoResizeColumns();
            dataGridView1.Columns["Employee_Code"].Frozen = true;
            dataGridView1.Sort(dataGridView1.Columns["Employee_Code"],System.ComponentModel.ListSortDirection.Ascending);
            dataGridView1.Columns["Name"].Frozen = true;
            dataGridView1.Columns["Father_Name"].Frozen = true;
            dataGridView1.Columns["Employee_Code"].ReadOnly = true;
            dataGridView1.Columns["Name"].ReadOnly = true;
            dataGridView1.Columns["Father_Name"].ReadOnly = true;
            dataGridView1.Columns["DOB"].ReadOnly = true;
            dataGridView1.Columns["Place_Of_Post"].ReadOnly = true;
            dataGridView1.Columns["Program_Name"].ReadOnly = true;
            dataGridView1.Columns["Designation"].ReadOnly = true;
            dataGridView1.Columns["Date_Hired"].ReadOnly = true;
            dataGridView1.Columns["Bank_Name"].ReadOnly = true;
            dataGridView1.Columns["IFSC"].ReadOnly = true;
            dataGridView1.Columns["Bank_Ac"].ReadOnly = true;
            dataGridView1.Columns["Basic_Salary"].ReadOnly = true;
            dataGridView1.Columns["EPF"].ReadOnly = true;
            dataGridView1.Columns["TDS"].ReadOnly = true;
            dataGridView1.Columns["Final_Amt"].ReadOnly = true;
            label2.Text = string.Format("Total Employee : {0}",dataGridView1.RowCount);
            if (dataGridView1.Rows.Count > 0)
                {
                dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells["Working_Days"];
                dataGridView1.BeginEdit(true);
                }
            sda.Update(dt);
            database.CloseConnection();
            }
        else
            {
            MessageBox.Show("Please Select Month");
            }
        }
    }
}