Require CSV Issue - ruby-on-rails-3

I'm running a RAils 3.1,ruby 1.9.2 app and I've a issue with CSV;I must import data from csv file; this is my code:
def bulk_operations
require 'csv'
last_asset = ""
last_serial = ""
if request.path.include? "ingress_transport_document"
transport_document_id = params[:ingress_transport_document_id]
td = IngressTransportDocument.find(transport_document_id)
ingress = true;
elsif request.path.include? "egress_transport_document"
transport_document_id = params[:egress_transport_document_id]
td = EgressTransportDocument.find(transport_document_id)
end
if params[:dump_me]
begin
# #parsed_file=CSV::Reader.parse(params[:dump_me][:file],';',"\n")
CSV.foreach(params[:dump_me][:file]) do |row|
bw=BulkWarehouse.new
bw.serial = row[0]
bw.asset = row[1]
logger.debug "#{bw.serial},#{bw.asset} --> #{bw.serial.strip}"
#
# Cerco la presenza di warehouse se la bolla e di tipo aggiornamento
#
if !bw.serial.strip.empty? && !bw.asset.strip.empty? && update_warehouse
warehouse = Warehouse.find_by_serial_and_asset(bw.serial.strip,bw.asset.strip)
elsif !bw.serial.strip.empty? && update_warehouse
warehouse = Warehouse.find_by_serial(bw.serial.strip)
elsif !bw.asset.strip.empty? && update_warehouse
warehouse = Warehouse.find_by_asset(bw.asset.strip)
end
if warehouse && update_warehouse
bw.warehouse_id = warehouse.id
elsif update_warehouse
#wh_errors[:"bulk_warehouse#{n}"] = "Prodotto non presente"
end
if request.path.include? "ingress_transport_document"
bw.ingress_transport_document_id = transport_document_id
elsif request.path.include? "egress_transport_document"
bw.egress_transport_document_id = transport_document_id
end
if bw.save
n=n+1
GC.start if n%50==0
end
last_serial = row[0]
last_asset = row[1]
end
count = sa_query
flash[:notice]="Il CSV e stato importato con successo: #{n} nuovi record sono stati accodati per essere processati.<br>In totale hai #{count} record in attesa di essere processati."
#rescue CSV::IllegalFormatError
logger.debug("CSV Exception: IllegalFormatError")
count = sa_query
flash[:notice] = "Il CSV NON sembra essere formattato correttamente."
flash[:notice] += "L'ultimo ASSET inserito e stato #{last_asset}." if !last_asset.empty?
flash[:notice] += "L'ultimo SERIALE inserito e stato #{last_serial}." if !last_serial.empty?
flash[:notice] += "#{n} nuovi record sono stati accodati per essere processati."
flash[:notice] += "In totale hai #{count} record in attesa di essere processati."
end
end
# update_warehouse e true solo se la bolla e di tipo da aggiornamento
update_warehouse = td.transport_document_type.code == "AGE" ||
td.transport_document_type.code == "REP" ||
td.transport_document_type.code == "ASS"
if params[:ingress_transport_document_id] || params[:egress_transport_document_id]
self.index
render :index
else
redirect_to :action => "index"
end
and Rails give me the following errors: can't convert ActionDispatch::Http::UploadedFile into String
Any suggestion

In Ruby 1.9 it's just CSV.parse. See: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html#method-c-parse

Related

Undefined variable error in optimization program using Julia, JuMP, DataFrames

Trying to update this optimization program that worked fine with julia 1.6.2, but now
returns the following error using julia 1.7.2.
The error occurs in line 24.
#constraint(m, sum(pitchers_lineup[i], i=1:num_pitchers) == 1)
using DataFrames
using GLPK
using JuMP
using CSV
num_lineups = 25
num_overlap = 3
path_hitters = "Hitters.csv"
path_pitchers = "Pitchers.csv"
path_to_output = "output.csv"
# This is a function that creates one lineup using the Type 4 formulation from the paper
function one_lineup_Type_4(hitters, pitchers, lineups, num_overlap, num_hitters, num_pitchers, catcher, first_baseman, second_baseman, third_baseman, shortstop, outfielders, num_teams, hitters_teams, pitchers_opponents)
m = Model(GLPK.Optimizer)
# Variable for Hitters in lineup
#variable(m, hitters_lineup[i=1:num_hitters], Bin)
# Variable for Pitcher in lineup
#variable(m, pitchers_lineup[i=1:num_pitchers], Bin)
# One Pitcher constraint
#constraint(m, sum(pitchers_lineup[i], i=1:num_pitchers) == 1)
# Eight Hitters constraint
#constraint(m, sum(hitters_lineup[i], i=1:num_hitters) == 8)
# between 1 and 2 catchers + first baseman
#constraint(m, sum((catcher)[i]*hitters_lineup[i], i=1:num_hitters) <= 2)
#constraint(m, 1 <= sum(catcher[i]*hitters_lineup[i], i=1:num_hitters))
# between 1 and 2 second basemen
#constraint(m, sum(second_baseman[i]*hitters_lineup[i], i=1:num_hitters) <= 2)
#constraint(m, 1 <= sum(second_baseman[i]*hitters_lineup[i], i=1:num_hitters))
# between 1 and 2 third basemen
#constraint(m, sum(third_baseman[i]*hitters_lineup[i], i=1:num_hitters) <= 2)
#constraint(m, 1 <= sum(third_baseman[i]*hitters_lineup[i], i=1:num_hitters))
# between 1 and 2 shortstops
#constraint(m, sum(shortstop[i]*hitters_lineup[i], i=1:num_hitters) <= 2)
#constraint(m, 1 <= sum(shortstop[i]*hitters_lineup[i], i=1:num_hitters))
# between 3 and 4 outfielders
#constraint(m, 3 <= sum(outfielders[i]*hitters_lineup[i], i=1:num_hitters))
#constraint(m, sum(outfielders[i]*hitters_lineup[i], i=1:num_hitters) <= 4)
# Financial Constraint
#constraint(m, sum(hitters[i,:Salary]*hitters_lineup[i], i=1:num_hitters) + sum(pitchers[i,:Salary]*pitchers_lineup[i], i=1:num_pitchers) <= 35000)
# exactly x different teams for the 8 hitters constraint
#variable(m, used_team[i=1:num_teams], Bin)
constr = #constraint(m, [i=1:num_teams], used_team[i] <= sum(hitters_teams[t, i]*hitters_lineup[t], t=1:num_hitters))
constr = #constraint(m, [i=1:num_teams], sum(hitters_teams[t, i]*hitters_lineup[t], t=1:num_hitters) == 4*used_team[i])
#constraint(m, sum(used_team[i], i=1:num_teams) == 2)
# No pitchers going against hitters
constr = #constraint(m, [i=1:num_pitchers], 6*pitchers_lineup[i] + sum(pitchers_opponents[k, i]*hitters_lineup[k], k=1:num_hitters)<=6)
# Overlap Constraint
constr = #constraint(m, [i=1:size(lineups)[2]], sum(lineups[j,i]*hitters_lineup[j], j=1:num_hitters) + sum(lineups[num_hitters+j,i]*pitchers_lineup[j], j=1:num_pitchers) <= num_overlap)
# Objective
#objective(m, Max, sum(hitters[i,:FPPG]*hitters_lineup[i], i=1:num_hitters) + sum(pitchers[i,:FPPG]*pitchers_lineup[i], i=1:num_pitchers) )
# Solve the integer programming problem
println("Solving Problem...")
print("\n")
status = solve(m);
# Puts the output of one lineup into a format that will be used later
if status==:Optimal
hitters_lineup_copy = Array(Int64)(0)
for i=1:num_hitters
if getvalue(hitters_lineup[i]) >= 0.9 && getvalue(hitters_lineup[i]) <= 1.1
hitters_lineup_copy = vcat(hitters_lineup_copy, fill(1,1))
else
hitters_lineup_copy = vcat(hitters_lineup_copy, fill(0,1))
end
end
for i=1:num_pitchers
if getvalue(pitchers_lineup[i]) >= 0.9 && getvalue(pitchers_lineup[i]) <= 1.1
hitters_lineup_copy = vcat(hitters_lineup_copy, fill(1,1))
else
hitters_lineup_copy = vcat(hitters_lineup_copy, fill(0,1))
end
end
return(hitters_lineup_copy)
end
end
#=
formulation is the type of formulation that you would like to use. Feel free to customize the formulations. In our paper we considered
the Type 4 formulation in great detail, but we have included the code for all of the formulations dicussed in the paper here. For instance,
if you would like to create lineups without stacking, change one_lineup_Type_4 below to one_lineup_no_stacking
=#
formulation = one_lineup_Type_4
function create_lineups(num_lineups, num_overlap, path_hitters, path_pitchers, formulation, path_to_output)
#=
num_lineups is an integer that is the number of lineups
num_overlap is an integer that gives the overlap between each lineup
path_hitters is a string that gives the path to the hitters csv file
path_pitchers is a string that gives the path to the pitchers csv file
formulation is the type of formulation you would like to use (for instance one_lineup_Type_1, one_lineup_Type_2, etc.)
path_to_output is a string where the final csv file with your lineups will be
=#
# Load information for hitters table
hitters = CSV.read(path_hitters, DataFrames.DataFrame)
# Load information for pitchers table
pitchers = CSV.read(path_pitchers, DataFrames.DataFrame)
# Number of hitters
num_hitters = size(hitters)[1]
# Number of pitchers
num_pitchers = size(pitchers)[1]
# catchers stores the information on which players are catchers
catcher = Int64[]
# first baseman stores the information on which players are first baseman
first_baseman = Int64[]
# second baseman stores the information on which players are second baseman
second_baseman = Int64[]
# third baseman stores the information on which players are third baseman
third_baseman = Int64[]
# shortstop stores the information on which players are shortsops
shortstop = Int64[]
# outfielders stores the information on which players are outfielders
outfielders = Int64[]
#=
Process the position information in the hitters file to populate C, 1B, 2B, 3B, SS & OF's with the
corresponding correct information
=#
for i =1:num_hitters
if hitters[i,:Position] == "C"
catcher=vcat(catcher,fill(1,1))
first_baseman=vcat(first_baseman,fill(0,1))
second_baseman=vcat(second_baseman,fill(0,1))
third_baseman=vcat(third_baseman,fill(0,1))
shortstop=vcat(shortstop,fill(0,1))
outfielders=vcat(outfielders,fill(0,1))
elseif hitters[i,:Position] == "1B"
catcher=vcat(catcher,fill(1,1))
first_baseman=vcat(first_baseman,fill(0,1))
second_baseman=vcat(second_baseman,fill(0,1))
third_baseman=vcat(third_baseman,fill(0,1))
shortstop=vcat(shortstop,fill(0,1))
outfielders=vcat(outfielders,fill(0,1))
elseif hitters[i,:Position] == "2B"
catcher=vcat(catcher,fill(0,1))
first_baseman=vcat(first_baseman,fill(0,1))
second_baseman=vcat(second_baseman,fill(1,1))
third_baseman=vcat(third_baseman,fill(0,1))
shortstop=vcat(shortstop,fill(0,1))
outfielders=vcat(outfielders,fill(0,1))
elseif hitters[i,:Position] == "3B"
catcher=vcat(catcher,fill(0,1))
first_baseman=vcat(first_baseman,fill(0,1))
second_baseman=vcat(second_baseman,fill(0,1))
third_baseman=vcat(third_baseman,fill(1,1))
shortstop=vcat(shortstop,fill(0,1))
outfielders=vcat(outfielders,fill(0,1))
elseif hitters[i,:Position] == "SS"
catcher=vcat(catcher,fill(0,1))
first_baseman=vcat(first_baseman,fill(0,1))
second_baseman=vcat(second_baseman,fill(0,1))
third_baseman=vcat(third_baseman,fill(0,1))
shortstop=vcat(shortstop,fill(1,1))
outfielders=vcat(outfielders,fill(0,1))
else
catcher=vcat(catcher,fill(0,1))
first_baseman=vcat(first_baseman,fill(0,1))
second_baseman=vcat(second_baseman,fill(0,1))
third_baseman=vcat(third_baseman,fill(0,1))
shortstop=vcat(shortstop,fill(0,1))
outfielders=vcat(outfielders,fill(1,1))
end
end
catcher = catcher+first_baseman
# Create team indicators from the information in the hitters file
teams = unique(hitters[!, :Team])
# Total number of teams
num_teams = size(teams)[1]
# player_info stores information on which team each player is on
player_info = zeros(Int, size(teams)[1])
# Populate player_info with the corresponding information
for j=1:size(teams)[1]
if hitters[1, :Team] == teams[j]
player_info[j] =1
end
end
hitters_teams = player_info'
for i=2:num_hitters
player_info = zeros(Int, size(teams)[1])
for j=1:size(teams)[1]
if hitters[i, :Team] == teams[j]
player_info[j] =1
end
end
hitters_teams = vcat(hitters_teams, player_info')
end
# Create pitcher identifiers so you know who they are playing
opponents = pitchers[!, :Opponent]
pitchers_teams = pitchers[!, :Team]
pitchers_opponents=[]
for num = 1:size(teams)[1]
if opponents[1] == teams[num]
pitchers_opponents = hitters_teams[:, num]
end
end
for num = 2:size(opponents)[1]
for num_2 = 1:size(teams)[1]
if opponents[num] == teams[num_2]
pitchers_opponents = hcat(pitchers_opponents, hitters_teams[:,num_2])
end
end
end
# Lineups using formulation as the stacking type
the_lineup= formulation(hitters, pitchers, hcat(zeros(Int, num_hitters + num_pitchers), zeros(Int, num_hitters + num_pitchers)), num_overlap, num_hitters, num_pitchers, catcher, first_baseman, second_baseman, third_baseman, shortstop, outfielders, num_teams, hitters_teams, pitchers_opponents)
the_lineup2 = formulation(hitters, pitchers, hcat(the_lineup, zeros(Int, num_hitters + num_pitchers)), num_overlap, num_hitters, num_pitchers, catcher, first_baseman, second_baseman, third_baseman, shortstop, outfielders, num_teams, hitters_teams, pitchers_opponents)
tracer = hcat(the_lineup, the_lineup2)
for i=1:(num_lineups-2)
try
thelineup=formulation(hitters, pitchers, tracer, num_overlap, num_hitters, num_pitchers, catcher, first_baseman, second_baseman, third_baseman, shortstop, outfielders, num_teams, hitters_teams, pitchers_opponents)
tracer = hcat(tracer,thelineup)
catch
break
end
end
# Create the output csv file
lineup2 = ""
for j = 1:size(tracer)[2]
lineup = ["" "" "" "" "" "" "" "" ""]
for i =1:num_hitters
if tracer[i,j] == 1
if catcher[i]==1
if lineup[2]==""
lineup[2] = string(hitters[i,1])
elseif lineup[9] ==""
lineup[9] = string(hitters[i,1])
end
elseif first_baseman[i] == 1
if lineup[2] == ""
lineup[2] = string(hitters[i,1])
elseif lineup[9] == ""
lineup[9] = string(hitters[i,1])
end
elseif second_baseman[i] == 1
if lineup[3] == ""
lineup[3] = string(hitters[i,1])
elseif lineup[9] == ""
lineup[9] = string(hitters[i,1])
end
elseif third_baseman[i] == 1
if lineup[4] == ""
lineup[4] = string(hitters[i,1])
elseif lineup[9] == ""
lineup[9] = string(hitters[i,1])
end
elseif shortstop[i] == 1
if lineup[5] == ""
lineup[5] = string(hitters[i,1])
elseif lineup[9] == ""
lineup[9] = string(hitters[i,1])
end
elseif outfielders[i] == 1
if lineup[6] == ""
lineup[6] = string(hitters[i,1])
elseif lineup[7] == ""
lineup[7] = string(hitters[i,1])
elseif lineup[8] == ""
lineup[8] = string(hitters[i,1])
elseif lineup[9] == ""
lineup[9] = string(hitters[i,1])
end
end
end
end
for i =1:num_pitchers
if tracer[num_hitters+i,j] == 1
lineup[1] = string(pitchers[i,1])
end
end
for name in lineup
lineup2 = string(lineup2, name, ",")
end
lineup2 = chop(lineup2)
lineup2 = string(lineup2, """
""")
end
outfile = open(path_to_output, "w")
write(outfile, lineup2)
close(outfile)
end
# Running the code
create_lineups(num_lineups, num_overlap, path_hitters, path_pitchers, formulation, path_to_output)
UndefVarError: i not defined
Stacktrace:
[1] macro expansion
# ~/.julia/packages/MutableArithmetics/0Y9ZS/src/rewrite.jl:279 [inlined]
[2] macro expansion
# ~/.julia/packages/JuMP/klrjG/src/macros.jl:676 [inlined]
[3] one_lineup_Type_4(hitters::DataFrame, pitchers::DataFrame, lineups::Matrix{Int64}, num_overlap::Int64, num_hitters::Int64, num_pitchers::Int64, catcher::Vector{Int64}, first_baseman::Vector{Int64}, second_baseman::Vector{Int64}, third_baseman::Vector{Int64}, shortstop::Vector{Int64}, outfielders::Vector{Int64}, num_teams::Int64, hitters_teams::Matrix{Int64}, pitchers_opponents::Matrix{Int64})
# Main ./In[30]:24
[4] create_lineups(num_lineups::Int64, num_overlap::Int64, path_hitters::String, path_pitchers::String, formulation::typeof(one_lineup_Type_4), path_to_output::String)
# Main ./In[30]:265
[5] top-level scope
# In[30]:348
[6] eval
# ./boot.jl:373 [inlined]
[7] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
# Base ./loading.jl:1196
The correct syntax is
sum(pitchers_lineup[i] for i=1:num_pitchers)
Note the for, not a comma.

Compute sum Odoo

I have made a custom module budget with the field Value. I would like to sum all the values for the budgets I've made today
def value_budget_day(self):
for budget in self:
# Encontrar si hoy es el mismo dia que se creo un presupuesto
c_date = datetime.strftime(budget.create_date, "%Y-%m-%d %H:%M:%S")
t_date = datetime.strftime(budget.today, "%Y-%m-%d %H:%M:%S")
create_day = c_date[:10]
today_day = t_date[:10]
if create_day == today_day:
# Sumar todos los valores de los presupuestos de ese día
total = 0.0
for val in budget:
total += val.value
budget.today_value = total
else:
budget.today_value = 35
In my code the values are not sum
def value_budget_day(self):
total = 0
for budget in self:
# Encontrar si hoy es el mismo dia que se creo un presupuesto
c_date = datetime.strftime(budget.create_date, "%Y-%m-%d %H:%M:%S")
t_date = datetime.strftime(budget.today, "%Y-%m-%d %H:%M:%S")
create_day = c_date[:10]
today_day = t_date[:10]
if create_day == today_day:
# Sumar todos los valores de los presupuestos de ese día
total += budget.value
budget.today_value = total
else:
budget.today_value = 0
today_value = fields.Float(compute='value_budget_day')

No rows modified when updating records

I have 5 tab pages, with a Datagridview in each pages. Each tab represents a table in my database. The problem is, when updating, only the first table is being updated. Here's my code:
Private Sub update_Click(sender As Object, e As EventArgs) Handles updateBtn.Click
'/// UPDATING TABLE - employee
Try
Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn.Open()
Dim command As New OleDbCommand("UPDATE employee SET [Last_Name] = #lname, [First_Name]= #fname, MI = #mi, Bday = #bday, Age = #age, [Nationality] = #natio, [Contact_Number] = #contact, Sex = #gender, Address = #address, Department = #department, [Position] = #position, TIN = #tin, SSS = #sss, Pagibig = #pagibig, PhilHealth = #phh, Termi_Resi = #termiresi, [Date_hired] = #datehired, [Rate_Month] = #rm, [Date_End] = #dateTermiResi, Status = #status, [Father_Name] = #father, [Mother_Name] = #mother, Civil = #civil, Spouse = #spouse, [Number_of_Children] = #numberchild, Child1 = #child1, Child2 = #child2, Child3 = #child3, Child4 = #child4, Child5 = #child5, Child6 = #child6, Child7 = #child7, Child8 = #child8, Child9 = #child9 WHERE [EmployID] = #numberemp", conn)
With command.Parameters
.AddWithValue("#lname", lname.Text)
.AddWithValue("#fname", fname.Text)
.AddWithValue("#mi", mi.Text)
.AddWithValue("#bday", bday.Value)
.AddWithValue("#age", age.Text)
.AddWithValue("#natio", natio.Text)
.AddWithValue("#contact", contact.Text)
.AddWithValue("#gender", gender.Text)
.AddWithValue("#address", address.Text)
.AddWithValue("#department", department.Text)
.AddWithValue("#position", position.Text)
.AddWithValue("#tim", tin.Text)
.AddWithValue("#sss", sss.Text)
.AddWithValue("#pagibig", pagibig.Text)
.AddWithValue("#phh", phh.Text)
.AddWithValue("#termiresi", termiresi.Text)
.AddWithValue("#datehired", datehired.Value)
.AddWithValue("#rm", rm.Text)
.AddWithValue("#dateTermiResi", dateTermiResi.Value)
.AddWithValue("#status", status.Text)
.AddWithValue("#father", father.Text)
.AddWithValue("#mother", mother.Text)
.AddWithValue("#civil", civil.Text)
.AddWithValue("#spouse", spouse.Text)
.AddWithValue("#numberchild", numberchild.Text)
.AddWithValue("#child1", child1.Text)
.AddWithValue("#child2", child2.Text)
.AddWithValue("#child3", child3.Text)
.AddWithValue("#child4", child4.Text)
.AddWithValue("#child5", child5.Text)
.AddWithValue("#child6", child6.Text)
.AddWithValue("#child7", child7.Text)
.AddWithValue("#child8", child8.Text)
.AddWithValue("#child9", child9.Text)
.AddWithValue("#numberemp", numberemp.Text)
End With
command.ExecuteNonQuery()
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
command.Dispose()
conn.Close()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - education
Try
Using conn2 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn2.Open()
Dim command2 As New OleDbCommand("UPDATE education SET Level_Educ = #hlevelEduc, Degree = #degree, Post_Degree = #postdegree, Elem = #elem, Year_one = #year1, Highschool = #highschool, Year_two = #year2, College = #college, Year_three = #year3, Training_School = #trainingS, Year_four = #year4, Other_Educ = #otherEduc WHERE [EmployID] = #numberemp1", conn2)
numberemp1.Text = numberemp.Text
With command2.Parameters
.AddWithValue("#hlevelEduc", hlevelEduc.Text)
.AddWithValue("#elem", elem.Text)
.AddWithValue("#year1", year1.Text)
.AddWithValue("#highschool", highschool.Text)
.AddWithValue("#year2", year2.Text)
.AddWithValue("#college", college.Text)
.AddWithValue("#year3", year3.Text)
.AddWithValue("#degree", degree.Text)
.AddWithValue("#postdegree", postdegree.Text)
.AddWithValue("#trainingS", trainingS.Text)
.AddWithValue("#year4", year4.Text)
.AddWithValue("#otherEduc", otherEduc.Text)
.AddWithValue("#numberemp1", numberemp1.Text)
End With
Dim rows = command2.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
command2.Dispose()
conn2.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - employment
Try
Using conn3 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn3.Open()
Dim command3 As New OleDbCommand("UPDATE employment SET Cname1 = #cname1, Posi1 = #posi1, Dept1 = #dept1, Tm1 = #tm1, Reason1 = #reason1, Cname2 = #cname2, Posi2 = #posi2, Dept2 = #dept2, Tm2 = #tm2, Reason2 = #reason2, Cname3 = #cname3, Posi3 = #posi3, Dept3 = #dept3, Tm3 = #tm3, Reason3 = #reason3, Cname4 = #cname4, Posi4 = #posi4, Dept4 = #dept4, Tm4 = #tm4, Reason4 = #reason4, Cname5 = #cname5, Posi5 = #posi5, Dept5 = #dept5, Tm5 = #tm5, Reason5 = #reason5, Cname6 = #cname6, Posi6 = #posi6, Dept6 = #dept6, Tm6 = #tm6, Reason6 = #reason6 WHERE [EmployID] = #numberemp2", conn3)
numberemp2.Text = numberemp.Text
With command3.Parameters
.AddWithValue("#cname1", cname1.Text)
.AddWithValue("#posi1", posi1.Text)
.AddWithValue("#dept1", dept1.Text)
.AddWithValue("#tm1", tm1.Text)
.AddWithValue("#reason1", reason1.Text)
.AddWithValue("#cname2", cname2.Text)
.AddWithValue("#posi2", posi2.Text)
.AddWithValue("#dept2", dept2.Text)
.AddWithValue("#tm2", tm2.Text)
.AddWithValue("#reason2", reason2.Text)
.AddWithValue("#cname3", cname3.Text)
.AddWithValue("#posi3", posi3.Text)
.AddWithValue("#dept3", dept3.Text)
.AddWithValue("#tm3", tm3.Text)
.AddWithValue("#reason3", reason3.Text)
.AddWithValue("#cname4", cname4.Text)
.AddWithValue("#posi4", posi4.Text)
.AddWithValue("#dept4", dept4.Text)
.AddWithValue("#tm4", tm4.Text)
.AddWithValue("#reason4", reason4.Text)
.AddWithValue("#cname5", cname5.Text)
.AddWithValue("#posi5", posi5.Text)
.AddWithValue("#dept5", dept5.Text)
.AddWithValue("#tm5", tm5.Text)
.AddWithValue("#reason5", reason5.Text)
.AddWithValue("#cname6", cname6.Text)
.AddWithValue("#posi6", posi6.Text)
.AddWithValue("#dept6", dept6.Text)
.AddWithValue("#tm6", tm6.Text)
.AddWithValue("#reason6", reason6.Text)
.AddWithValue("#numberemp2", numberemp2.Text)
End With
Dim rows = command3.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
command3.Dispose()
conn3.Close()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - disciplinary
Try
Using conn4 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn4.Open()
Dim command4 As New OleDbCommand("UPDATE disciplinary SET Offense1 = #o1, Action1 = #ao1, Dateoff1 = #do1, Offense2 = #o2, Action2 = #ao2, Dateoff2 = #do2, Offense3 = #o3, Action3 = #ao3, Dateoff3 = #do3, Offense4 = #o4, Action4 = #ao4, Dateoff4 = #do4, Offense5 = #o5, Action5 = #ao5, Dateoff5 = #do5, Offense6 = #o6, Action6 = #ao6, Dateoff6 = #do6, Offense7 = #o7, Action7 = #ao7, Dateoff7 = #do7, Offense8 = #o8, Action8 = #ao8, Dateoff8 = #do8, Offense9 = #o9, Action9 = #ao9, Dateoff9 = #do9, Offense10 = #10, Action10 = #ao10, Dateoff10 = #do10 WHERE [EmployID] = #numberemp3 ", conn4)
numberemp3.Text = numberemp.Text
With command4.Parameters
.AddWithValue("#o1", o1.Text)
.AddWithValue("#ao1", ao1.Text)
.AddWithValue("#do1", do1.Value)
.AddWithValue("#o2", o2.Text)
.AddWithValue("#ao2", ao2.Text)
.AddWithValue("#do2", do2.Value)
.AddWithValue("#o3", o3.Text)
.AddWithValue("ao3", ao3.Text)
.AddWithValue("#do3", do3.Value)
.AddWithValue("#o4", o4.Text)
.AddWithValue("#ao4", ao4.Text)
.AddWithValue("#do4", do4.Value)
.AddWithValue("#o5", o5.Text)
.AddWithValue("#ao5", ao5.Text)
.AddWithValue("#do5", do5.Value)
.AddWithValue("#o6", o6.Text)
.AddWithValue("#ao6", ao6.Text)
.AddWithValue("#do6", do6.Value)
.AddWithValue("#o7", o7.Text)
.AddWithValue("#ao7", ao7.Text)
.AddWithValue("#do7", do7.Value)
.AddWithValue("#o8", o8.Text)
.AddWithValue("#ao8", ao8.Text)
.AddWithValue("#do8", do8.Value)
.AddWithValue("#o9", o9.Text)
.AddWithValue("#ao9", ao9.Text)
.AddWithValue("#do9", do9.Value)
.AddWithValue("#o10", o10.Text)
.AddWithValue("#ao10", ao10.Text)
.AddWithValue("#do10", do10.Value)
.AddWithValue("#numberemp3", numberemp3.Text)
End With
Dim rows = command4.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
conn4.Close()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
'/// UPDATING TABLE - trainings
Try
Using conn5 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Employee.mdb;")
conn5.Open()
Dim command5 As New OleDbCommand("UPDATE trainings SET ts1 = #ts1, dts1 = #dts1, ts2 = #ts2, dts2 = #dts2, ts3 = #ts3, dts3 = #dts3, ts4 = #ts4, dts4 = #dts4, ts5 = #ts5, dts5 = #dts5, ts6 = #ts6, dts6 = #dts6, ts7 = #ts7, dts7 = #dts7, ts8 = #ts8, dts8 = #dts8, ts9 = #ts9, dts9 = #dts9, ts10 = #ts10, dts10 = #dts10, ts11 = #ts11, dts11 = #dts11, ts12 = #ts12, dts12 = #dts12, ts13 = #ts13, dts13 = #dts13, ts14 = #ts14, dts14 = #dts14, ts15 = #ts15, dts15 = #dts15, ts16 = #ts16, dts16 = #dts16, ts17 = #ts17, dts17 = #dts17, ts18 = #ts18, dts18 = #dts18, ts19 = #ts19, dts19 = #dts19, ts20 = #ts20, dts20 = #dts20, ts21 = #ts21, dts21 = #dts21, ts22 = #ts22, dts22 = #dts22, ts23 = #ts23, dts23 = #dts23, ts24 = #ts24, dts24 = #dts24 WHERE [EmployID] = #numberemp4 ", conn5)
numberemp4.Text = numberemp.Text
With command5.Parameters
.AddWithValue("#ts1", ts1.Text)
.AddWithValue("#dts1", dts1.Value)
.AddWithValue("#ts2", ts2.Text)
.AddWithValue("#dts2", dts2.Value)
.AddWithValue("#ts3", ts3.Text)
.AddWithValue("#dts3", dts3.Value)
.AddWithValue("#ts4", ts4.Text)
.AddWithValue("#dts4", dts4.Value)
.AddWithValue("#ts5", ts5.Text)
.AddWithValue("#dts5", dts5.Value)
.AddWithValue("#ts6", ts6.Text)
.AddWithValue("#dts6", dts6.Value)
.AddWithValue("#ts7", ts7.Text)
.AddWithValue("#dts7", dts7.Value)
.AddWithValue("#ts8", ts8.Text)
.AddWithValue("#dts8", dts8.Value)
.AddWithValue("#ts9", ts9.Text)
.AddWithValue("#dts9", dts9.Value)
.AddWithValue("#ts10", ts10.Text)
.AddWithValue("#dts10", dts10.Value)
.AddWithValue("#ts11", ts11.Text)
.AddWithValue("#dts11", dts11.Value)
.AddWithValue("#ts12", ts12.Text)
.AddWithValue("#dts12", dts12.Value)
.AddWithValue("#ts13", ts13.Text)
.AddWithValue("#dts13", dts13.Value)
.AddWithValue("#ts14", ts14.Text)
.AddWithValue("#dts14", dts14.Value)
.AddWithValue("#ts15", ts15.Text)
.AddWithValue("#dts15", dts15.Value)
.AddWithValue("#ts16", ts16.Text)
.AddWithValue("#dts16", dts16.Value)
.AddWithValue("#ts17", ts17.Text)
.AddWithValue("#dts17", dts17.Value)
.AddWithValue("#ts18", ts18.Text)
.AddWithValue("#dts18", dts18.Value)
.AddWithValue("#ts19", ts19.Text)
.AddWithValue("#dts19", dts19.Value)
.AddWithValue("#ts20", ts20.Text)
.AddWithValue("#dts20", dts20.Value)
.AddWithValue("#ts21", ts21.Text)
.AddWithValue("#dts21", dts21.Value)
.AddWithValue("#ts22", ts22.Text)
.AddWithValue("#dts22", dts22.Value)
.AddWithValue("#ts23", ts23.Text)
.AddWithValue("#dts23", dts23.Value)
.AddWithValue("#ts24", ts24.Text)
.AddWithValue("#dts24", dts24.Value)
.AddWithValue("#numberemp4", numberemp4.Text)
End With
Dim rows = command5.ExecuteNonQuery()
If rows = 0 Then
MessageBox.Show("No rows modified")
Else
MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
command5.Dispose()
conn5.Close()
disableall()
clearall()
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Add1.Visible = True
btnReg.Visible = True
updateBtn.Visible = False
RefreshDGV()
End Sub
I always get
No rows modified
when updating the second up to the fifth table.
Here's my form to make it clear if it is too confusing..
Assuming that you want to load data to tab pages when needed:
Use the Load event to load data for Tap Page 1
hook up to event Selecting of TabControl to load data for the other pages
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) {
if (e.TabPage.Name == "TabPage1") {
//Load Data for Tab page 1
DataTable dt = new DataTable();
dt.Load(reader);
grid2.DataSource = dt;
}
}

Lua problems with variables

I wrote a Lua code to arrange a list but when I enter any number with 2 decimals as 10, 20, etc. in the list, the variable 'ordenado' always takes the value 1 although whether it fulfills the conditions or not.
valor = {}
ordenado = 0
function inicializar ()
for i = 1,10 do
print ("Introduzca el valor "..i..":")
valor[i] = io.read()
end
end
function verificar ()
for i = 2, #valor do
if valor[i]>valor[i-1] then
ordenado = ordenado + 0
else
ordenado = ordenado + 1
end
print ("actual: "..valor[i].." \nanterior: "..valor[i-1].."\nordenado:"..ordenado.."\n")
end
end
function imprimir()
if ordenado == 0 then
print "La lista esta ordenada"
else
print "La lista no esta ordenada"
end
end
a = inicializar()
a = verificar()
a = imprimir()
The Lua version is 5.2.
The line valor[i] = io.read() stores a string in valor[i]. As strings, "2" > "10".

Variables not being replaced

I've been experimenting with the Lua Language and it seems as if all the variables are interacting with the conditions except for this one variable. Could take a look at it?
function Medicial()
local varName = "Marcy"
local varCondition = "Well"
local varSCondition = "1" -- 5 = Uncurable, 10 = Well, 15 = Unknown, 20 = Surgery, 25 = Post Surgery, 29 = Bar Surgery
local varDoctors = "DefultValue"
local varExStatus = "DefultValue"
local payment = "You can afford this."
local total = 400
if varCondition == "Well" then
varDoctors = "Dr. Pope, Dr.Roadmiller"
varStatus = "Yes"
end
if varCondition == "Sick" then
varDoctors = "Dr. Pope, Dr.Rosenhour, Surgeon Rossford"
varStatus = "No"
end
if total > 1000 then
payment = "You can not afford this."
elseif total >= 1000 then
payment = "You can affort this, but you will be broke."
end
if varSCondition == 1 then
varExStatus = "Well"
end
if varSCondition == 5 then
varExStatus = "Uncurable"
end
if varSCondition == 15 then
varExStatus = "Unknown"
end
if varSCondition == "20" then
varExStatus = "Surgery"
end
if varSCondition == "25" then
varExStatus = "Post Surgery"
end
if varSCondition == "29" then
varExStatus = "Bar Surgery"
end
print("-=Subject Reports=-\n");
print("Subject: "..varName.."\nCurrent Condition: "..varCondition.." ("..varExStatus..")\nCurrent Doctors: "..varDoctors.."\nCurrently Recovering? "..varStatus);
print(">> "..payment);
end
It prints:
-=Subject Reports=-
Subject: Marcy
Current Condition: Well (DefultValue)
Current Doctors: Dr. Pope, Dr.Roadmiller
Currently Recovering? Yes
You can afford this.
This part is broken
if total > 1000 then
payment = "You can not afford this."
elseif total >= 1000 then
payment = "You can affort this, but you will be broke."
end
I bet you meant to do this:
if total < 1000 then
payment = "You can not afford this."
elseif total == 1000 then
payment = "You can affort this, but you will be broke."
end
regarding varSCondition: Your varSCondition is a String ("1"), but you're sometimes comparing it to integers (without the "-signs), for example here:
if varSCondition == 1 then
and sometimes to Strings , for example here:
if varSCondition == "20" then
All of them should be either a string, or an integer, but dont mix them. try this:
local varSCondition = 1 -- 5 = Uncurable, 10 = Well, 15 = Unknown, 20 = Surgery, 25 = Post Surgery, 29 = Bar Surgery
...
if varSCondition == 1 then
varExStatus = "Well"
end
if varSCondition == 5 then
varExStatus = "Uncurable"
end
if varSCondition == 15 then
varExStatus = "Unknown"
end
if varSCondition == 20 then
varExStatus = "Surgery"
end
if varSCondition == 25 then
varExStatus = "Post Surgery"
end
if varSCondition == 29 then
varExStatus = "Bar Surgery"
end