public DataTable PostVehicleQuery([FromBody] vehiclecls dcls) { string w_clause = ""; if (dcls.plateno != "" && dcls.plateno != "undefined" && dcls.plateno != null) { w_clause = w_clause + " and PlateNo like '%" + dcls.plateno + "%'"; } if (dcls.gsmno != "" && dcls.gsmno != "undefined" && dcls.gsmno != null) { w_clause = w_clause + " and gsmno like '%" + dcls.gsmno + "%'"; } if (dcls.vehclass != "" && dcls.vehclass != "undefined" && dcls.vehclass != null) { w_clause = w_clause + " and Class like '%" + dcls.vehclass + "%'"; } if (dcls.brand != "" && dcls.brand != "undefined" && dcls.brand != null) { w_clause = w_clause + " and brand like '%" + dcls.brand + "%'"; } if (dcls.model != "" && dcls.model != "undefined" && dcls.model != null) { w_clause = w_clause + " and model like '%" + dcls.model + "%'"; } if (dcls.notes != "" && dcls.notes != "undefined" && dcls.notes != null) { w_clause = w_clause + " and notes like '%" + dcls.notes + "%'"; } if (dcls.type != "" && dcls.type != "undefined" && dcls.type != null) { w_clause = w_clause + " and type like '%" + dcls.type + "%'"; } if (w_clause != "") { w_clause = " where " + w_clause.Substring(4); } SqlConnection cont = new SqlConnection(); cont.ConnectionString = constr2; cont.Open(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("select * from Vehicle " + w_clause, cont); da.Fill(dt); cont.Close(); cont.Dispose(); // List <DriverInfo> = new List<DriverInfo>; return(dt); }
public string PostDelVehicle([FromBody] vehiclecls dcls) { SqlConnection cont = new SqlConnection(); cont.ConnectionString = constr2; cont.Open(); DataTable dt = new DataTable(); //SqlDataAdapter da = new SqlDataAdapter("select * from driverinfo " + HttpUtility.HtmlDecode(w_clause), cont); SqlCommand cmd = new SqlCommand(); cmd.Connection = cont; cmd.CommandText = " delete Vehicle where plateno='" + dcls.plateno + "'"; cmd.ExecuteNonQuery(); //da.Fill(dt); cont.Close(); cont.Dispose(); return("Deleted Successfully"); }
public string PostInsVehicle([FromBody] vehiclecls dcls) { try { SqlConnection cont = new SqlConnection(); cont.ConnectionString = constr2; cont.Open(); // DataTable dt = new DataTable(); //SqlDataAdapter da = new SqlDataAdapter("select * from driverinfo " + HttpUtility.HtmlDecode(w_clause), cont); SqlCommand cmd = new SqlCommand(); cmd.Connection = cont; cmd.CommandText = " insert into vehicle(plateno,gsmno,class,brand,type,model,notes,savedby) values('" + dcls.plateno + "','" + dcls.gsmno + "','" + dcls.vehclass + "','" + dcls.brand + "','" + dcls.type + "','" + dcls.model + "','" + dcls.notes + "','" + dcls.userid + "')"; int Records = cmd.ExecuteNonQuery(); //da.Fill(dt); cont.Close(); cont.Dispose(); return(Records + " Saved Successfully"); } catch (Exception e) { return("error" + e.Message); } }