private bool SaveSallery(EmployeeSallery aSallery) { string connectionString = WebConfigurationManager.ConnectionStrings["EmployeeConnectionString"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO EmployeeSallery VALUES(@EmployeeID, @EmployeeName, @Designation, @email,@BasicSallery,@convRate,@houseRent)";; SqlCommand command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@EmployeeID", aSallery.EmployeeId); command.Parameters.AddWithValue("@EmployeeName", aSallery.EmployeeName); command.Parameters.AddWithValue("@Designation", aSallery.Designation); command.Parameters.AddWithValue("@email", aSallery.Email); command.Parameters.AddWithValue("@BasicSallery", aSallery.BasicSallery); command.Parameters.AddWithValue("@convRate", aSallery.ConvRate); command.Parameters.AddWithValue("@houseRent", aSallery.HouseRent); connection.Open(); int rowAffected = command.ExecuteNonQuery(); connection.Close(); return(rowAffected > 0); }
public double GetTotal() { EmployeeSallery aSallery = new EmployeeSallery(); string connectionString = WebConfigurationManager.ConnectionStrings["EmployeeConnectionString"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); string query = "SELECT BasicSallery, convRate, houseRent FROM EmployeeSallery"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader sdr = command.ExecuteReader(); while (sdr.Read()) { string basic = sdr["BasicSallery"].ToString(); string conv = (sdr["convRate"].ToString()); string houserent = (sdr["houseRent"].ToString()); aSallery.BasicSallery = Convert.ToDouble(basic); aSallery.ConvRate = Convert.ToDouble(conv); aSallery.HouseRent = Convert.ToDouble(houserent); aSallery.GetTotalSallery(); aSallery.GetTotalAmount(); } sdr.Close(); connection.Close(); return(aSallery.TotalAmount); }
protected void saveButton_Click(object sender, EventArgs e) { EmployeeSallery aSallery = new EmployeeSallery(); aSallery.EmployeeId = employeeIDTextBox.Text; aSallery.EmployeeName = nameTextBox.Text; aSallery.Designation = designationTextBox.Text; aSallery.Email = emailTextBox.Text; aSallery.BasicSallery = Convert.ToDouble(basicSalleryTextBox.Text); aSallery.ConvRate = Convert.ToDouble(convTextBox.Text); aSallery.HouseRent = Convert.ToDouble(hrTextBox.Text); if (SaveSallery(aSallery)) { messageLabel.CssClass = "label label-success"; messageLabel.Text = "Saved Successfully"; } else { messageLabel.CssClass = "label label-danger"; messageLabel.Text = "Insertion Failed!"; } }