TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
narasiman rao
NA
519
769k
i get this error when i run The Process cannot access the file because it is used by another process.
Jul 20 2012 5:20 AM
i send design screen of 2 page as follows in attach file please see the attachments file
i send my code below as follows. i run two screen as follows.
In the first screen when i click the payslip button it goes to second page screen.
this is the first screen code as follows,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Pay_Roll_Applications
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("Server=(local);initial catalog=Payroll;Trusted_Connection=True");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void cb_name_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd1 = new SqlCommand("select * from salaries where Name=' " + cb_name.Text + "'", con);
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.Read())
{
txt_date.Text = dr[1].ToString().Trim();
txt_gross.Text = dr[2].ToString().Trim();
txt_pf.Text = dr[3].ToString().Trim();
txt_mobilelimit.Text = dr[11].ToString().Trim();
}
con.Close();
con.Open();
SqlCommand cmd2 = new SqlCommand("select * from salaries where Name=' " + cb_name.Text + "'", con);
SqlDataReader dr1 = cmd2.ExecuteReader();
while (dr1.Read())
{
txt_date.Text = dr1[1].ToString().Trim();
txt_gross.Text = dr1[2].ToString().Trim();
txt_pf.Text = dr1[3].ToString().Trim();
txt_mobilelimit.Text = dr1[11].ToString().Trim();
}
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into salaries values(' " + cb_name.Text + "','" + txt_date.Text + "'," + txt_gross.Text + "," + txt_pf.Text + "," + txt_loan.Text + "," + txt_tax.Text + "," + txt_tds.Text + "," + txt_mobileusage.Text + "," + txt_totdeductions.Text + "," + txt_others.Text + "," + txt_totpayable.Text + "," + txt_mobilelimit.Text + ",'" + txt_usage.Text + "'," + txt_leave.Text + ",'" + txt_remarks.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
cb_name.Text = "";
txt_date.Text = "";
txt_gross.Text = "";
txt_pf.Text = "";
txt_loan.Text = "";
txt_tax.Text = "";
txt_tds.Text = "";
txt_mobileusage.Text = "";
txt_totdeductions.Text = "";
txt_others.Text = "";
txt_totpayable.Text = "";
txt_mobilelimit.Text = "";
txt_usage.Text = "";
txt_leave.Text = "";
txt_remarks.Text = "";
}
private void txt_mobileusage_TextChanged(object sender, EventArgs e)
{
int a, b, c, j, tt, z;
if (!int.TryParse(txt_pf.Text, out a) || a < 0)
{
MessageBox.Show("Not a valid number. Please reenter.");
txt_pf.Focus();
return;
}
if (!int.TryParse(txt_loan.Text, out b) || b < 0)
{
MessageBox.Show("Not a valid number. Please reenter.");
txt_loan.Focus();
return;
}
if (!int.TryParse(txt_tax.Text, out c) || c < 0)
{
MessageBox.Show("Not a valid number. Please reenter.");
txt_tax.Focus();
return;
}
if (!int.TryParse(txt_tds.Text, out j) || j < 0)
{
MessageBox.Show("Not a valid number. Please reenter.");
txt_tds.Focus();
return;
}
if (!int.TryParse(txt_mobileusage.Text, out tt) || tt < 0)
{
MessageBox.Show("Not a valid number. Please reenter and Enter only Numbers.");
txt_mobileusage.Focus();
return;
}
z = a + b + c + j + tt;
txt_totdeductions.Text = z.ToString();
}
private void txt_others_TextChanged(object sender, EventArgs e)
{
int a, b, c, d;
if (!int.TryParse(txt_gross.Text, out a) || a < 0)
{
MessageBox.Show("Not a valid number. Please reenter.");
txt_gross.Focus();
return;
}
if (!int.TryParse(txt_totdeductions.Text, out b) || b < 0)
{
MessageBox.Show("Not a valid number. Please reenter.");
txt_totdeductions.Focus();
return;
}
if (!int.TryParse(txt_others.Text, out c) || c < 0)
{
MessageBox.Show("Not a valid number. Please reenter and Enter only Numbers.");
txt_others.Focus();
return;
}
d = a - b + c;
txt_totpayable.Text = d.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
this.Hide();
}
}
}
Second Screen Code as follows,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Pay_Roll_Applications
{
public partial class Form2 : Form
{
SqlConnection con = new SqlConnection("Server=(local);initial catalog=Payroll;Trusted_Connection=True");
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
int i;
for (i = 1; i <= 31; i++)
{
comboBox1.Items.Add(i);
}
txt_basicscale.Text = "0";
txt_hrascale.Text = "0";
txt_dascale.Text = "0";
txt_variablescale.Text = "0";
txt_working.Text = "31";
txt_basicamount.Text = "0";
txt_hraamt.Text = "0";
txt_daamt.Text = "0";
txt_variableamt.Text = "0";
}
private void button3_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into pay values('" + cb_id.Text + "'," + txt_working.Text + ",' " + txt_Name.Text + "','" + txt_fathers.Text + "','" + txt_pan.Text + "','" + txt_date.Text + "'," + txt_days.Text + ",'" + txt_branch.Text + "',' " + txt_designation.Text + "','" + txt_department.Text + "',' " + txt_pay.Text + "','" + txt_bankname.Text + "'," + txt_accno.Text + "," + txt_basicamount.Text + "," + txt_hraamt.Text + "," + txt_daamt.Text + ", " + txt_variableamt.Text + "," + txt_percentagebasic.Text + "," + txt_excessmobile.Text + "," + txt_tds.Text + "," + txt_loan.Text + "," + txt_netpay.Text + ")", con);
cmd.ExecuteNonQuery();
}
private void cb_id_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd1 = new SqlCommand("select * from pay where Employeeid = '" + cb_id.Text + "'", con);
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.Read())
{
txt_Name.Text = dr[2].ToString().Trim();
txt_fathers.Text = dr[3].ToString().Trim();
txt_pan.Text = dr[4].ToString().Trim();
txt_date.Text = dr[5].ToString().Trim();
txt_branch.Text = dr[7].ToString().Trim();
txt_designation.Text = dr[8].ToString().Trim();
txt_department.Text = dr[9].ToString().Trim();
txt_pay.Text = dr[10].ToString().Trim();
txt_bankname.Text = dr[11].ToString().Trim();
txt_accno.Text = dr[12].ToString().Trim();
txt_basicscale.Text = dr[13].ToString().Trim();
txt_hrascale.Text = dr[14].ToString().Trim();
txt_dascale.Text = dr[15].ToString().Trim();
txt_variablescale.Text = dr[16].ToString().Trim();
txt_excessmobile.Text = dr[18].ToString().Trim();
txt_tds.Text = dr[19].ToString().Trim();
txt_loan.Text = dr[20].ToString().Trim();
txt_basicamount.Text = "";
txt_hraamt.Text = "";
txt_daamt.Text = "";
txt_variableamt.Text = "";
txt_scaletot.Text = "";
txt_amttot.Text = "";
textBox1.Text = "";
txt_netpay.Text = "";
txt_days.Text = "";
txt_percentagebasic.Text = "";
}
con.Close();
con.Open();
SqlCommand cmd2 = new SqlCommand("select * from pay where Employeeid='" + cb_id.Text + "'", con);
SqlDataReader dr1 = cmd2.ExecuteReader();
while (dr1.Read())
{
txt_percentagebasic.Text = dr1[17].ToString().Trim();
}
con.Close();
//con.Open();
//SqlCommand cmd3 = new SqlCommand("select * from vt where id='" + cb_id.Text + "'", con);
//SqlDataReader dr2 = cmd3.ExecuteReader();
//while (dr2.Read())
//{
// txt_excessmobile.Text = dr2[6].ToString().Trim();
// txt_tds.Text = dr2[5].ToString().Trim();
// txt_loan.Text = dr2[4].ToString().Trim();
//}
//con.Close();
}
private void button5_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.Show();
this.Hide();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime dt = dateTimePicker1.Value;
int days = DateTime.DaysInMonth(dt.Year, dt.Month);
txt_working.Text = days.ToString();
//int r, d1;
//r = Convert.ToInt32(txt_variablescale.Text);
//d1 = Convert.ToInt32(1 * r);
//txt_variableamt.Text = d1.ToString();
//txt_variableamt.Text = "0";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
txt_days.Text = comboBox1.Text;
int r, d1;
r = Convert.ToInt32(txt_variablescale.Text);
d1 = Convert.ToInt32(1 * r);
txt_variableamt.Text = d1.ToString();
int c, d;
c = Convert.ToInt32(txt_basicscale.Text);
d = Convert.ToInt32(0.12 * c);
txt_percentagebasic.Text = d.ToString();
double working_days = Convert.ToDouble(txt_working.Text);
double payable_days = Convert.ToDouble(txt_days.Text);
double a = Convert.ToDouble(txt_basicscale.Text);
txt_basicamount.Text = Math.Floor(a / working_days * payable_days).ToString();
double working_days1 = Convert.ToDouble(txt_working.Text);
double payable_days1 = Convert.ToDouble(txt_days.Text);
double a1 = Convert.ToDouble(txt_hrascale.Text);
txt_hraamt.Text = Math.Floor(a1 / working_days1 * payable_days1).ToString();
double working_days2 = Convert.ToDouble(txt_working.Text);
double payable_days2 = Convert.ToDouble(txt_days.Text);
double a2 = Convert.ToDouble(txt_dascale.Text);
txt_daamt.Text = Math.Floor(a2 / working_days2 * payable_days2).ToString();
double working_days3 = Convert.ToDouble(txt_working.Text);
double payable_days3 = Convert.ToDouble(txt_days.Text);
double a3 = Convert.ToDouble(txt_variablescale.Text);
txt_variableamt.Text = Math.Floor(a3 / working_days3 * payable_days3).ToString();
txt_amttot.Text = "";
textBox1.Text = "";
txt_netpay.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
double BasicScale, HraScale, DaScale, VpiScale, BasicAmt, Hraamt, daAmt, VpiAmt, PercentBasic, Excess, Tds, Loan, total, total1, total2, total3, total4;
BasicScale = Convert.ToDouble(txt_basicscale.Text);
HraScale = Convert.ToDouble(txt_hrascale.Text);
DaScale = Convert.ToDouble(txt_dascale.Text);
VpiScale = Convert.ToDouble(txt_variablescale.Text);
BasicAmt = Convert.ToDouble(txt_basicamount.Text);
Hraamt = Convert.ToDouble(txt_hraamt.Text);
daAmt = Convert.ToDouble(txt_daamt.Text);
VpiAmt = Convert.ToDouble(txt_variableamt.Text);
PercentBasic = Convert.ToDouble(txt_percentagebasic.Text);
Excess = Convert.ToDouble(txt_excessmobile.Text);
Tds = Convert.ToDouble(txt_tds.Text);
Loan = Convert.ToDouble(txt_loan.Text);
total = BasicScale + HraScale + DaScale + VpiScale;
txt_scaletot.Text = total.ToString();
total1 = BasicAmt + Hraamt + daAmt + VpiAmt;
txt_amttot.Text = total1.ToString();
total2 = PercentBasic + Excess + Tds + Loan;
textBox1.Text = total2.ToString();
int a, b, c;
if (!int.TryParse(txt_amttot.Text, out a) || a < 0)
{
txt_amttot.Focus();
return;
}
if (!int.TryParse(textBox1.Text, out b) || b < 0)
{
textBox1.Focus();
return;
}
c = a - b;
txt_netpay.Text = c.ToString();
}
}
}
Reply
Answers (
2
)
Triger one cell in Data grid trigers other same or other Data Grid
How to use the Drawing namespace in c#?