Advertisement
Guest User

Main7Activity

a guest
Jun 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.33 KB | None | 0 0
  1. package com.example.tabita.myapplication;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.AsyncTask;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.app.DatePickerDialog;
  10. import android.view.LayoutInflater;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import android.widget.AdapterView;
  14. import android.widget.BaseAdapter;
  15. import android.widget.Button;
  16. import android.widget.DatePicker;
  17. import android.widget.EditText;
  18. import android.widget.ListView;
  19. import android.widget.TextView;
  20. import android.widget.Toast;
  21.  
  22. import java.io.PrintWriter;
  23. import java.io.StringWriter;
  24. import java.io.Writer;
  25. import java.sql.Connection;
  26. import java.sql.DriverManager;
  27. import java.sql.ResultSet;
  28. import java.sql.Statement;
  29. import java.text.SimpleDateFormat;
  30. import java.util.ArrayList;
  31. import java.util.Calendar;
  32. import java.util.Date;
  33. import java.util.List;
  34. import java.util.Locale;
  35.  
  36.  
  37. public class Main7Activity extends AppCompatActivity implements View.OnClickListener {
  38.  
  39.  
  40. Button bfecha,bhoy,bbuscar;
  41. EditText efecha;
  42. private int dia,mes,anio;
  43.  
  44. private ArrayList<ClassListItems2> itemArrayList2;
  45. private Main7Activity.MyAppAdapter2 myAppAdapter2;
  46. private ListView listView;
  47. private boolean success = false;
  48.  
  49. private String ip;
  50. private String base;
  51. private String user;
  52. private String pass;
  53. private String fecha;
  54. private String profe;
  55. private String todoeldia;
  56.  
  57. @Override
  58. protected void onCreate(Bundle savedInstanceState) {
  59. super.onCreate(savedInstanceState);
  60. setContentView(R.layout.activity_main7);
  61.  
  62. bfecha=(Button)findViewById(R.id.bfecha);
  63. efecha=(EditText)findViewById(R.id.efecha);
  64. bfecha.setOnClickListener(this);
  65.  
  66. bhoy=(Button)findViewById(R.id.bhoy);
  67. bhoy.setOnClickListener(this);
  68.  
  69. bbuscar=(Button)findViewById(R.id.bbuscar);
  70. bbuscar.setOnClickListener(this);
  71.  
  72.  
  73. listView = (ListView) findViewById(R.id.listView_profesor_todoeldia);
  74. itemArrayList2 = new ArrayList<ClassListItems2>();
  75.  
  76.  
  77. Bundle bundle2 = getIntent().getExtras();
  78. ip = bundle2.getString("IP");
  79. base = bundle2.getString("BASE");
  80. user = bundle2.getString("USER");
  81. pass = bundle2.getString("PASS");
  82.  
  83. Main7Activity.SyncData2 orderData = new Main7Activity.SyncData2();
  84. orderData.execute("");
  85.  
  86.  
  87. }
  88.  
  89.  
  90. @Override
  91. public void onClick(View v) {
  92. if(v==bfecha){
  93. final Calendar c= Calendar.getInstance();
  94. dia=c.get(Calendar.DAY_OF_MONTH);
  95. mes=c.get(Calendar.MONTH);
  96. anio=c.get(Calendar.YEAR);
  97.  
  98. DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
  99. @Override
  100. public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
  101. final String selectedDate = year+"-"+twoDigits(monthOfYear+1)+"-"+twoDigits(dayOfMonth);
  102. efecha.setText(selectedDate);
  103. }
  104. }
  105. ,anio,mes,dia);
  106. datePickerDialog.show();
  107.  
  108. }
  109. if(v==bhoy){
  110. SimpleDateFormat formatoFecha = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
  111. Date date = new Date();
  112. efecha.setText(formatoFecha.format(date));
  113. }
  114.  
  115. if(v==bbuscar){
  116.  
  117.  
  118.  
  119. }
  120.  
  121. }
  122.  
  123. private String twoDigits(int n) {
  124. return (n<=9) ? ("0"+n) : String.valueOf(n);
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. private class SyncData2 extends AsyncTask<String, String, String> {
  133. String msg = "¡¡¡Internet/DB_Credentials/Windows_Firewall_TurnOn Error, Compruebe mensaje de error para más detalles!!!";
  134. ProgressDialog progress;
  135.  
  136. @Override
  137. protected void onPreExecute() {
  138. progress = ProgressDialog.show(Main7Activity.this, "Sincronizando",
  139. "Cargando ausencias. Por favor, espere....",true);
  140. }
  141.  
  142. @Override
  143. protected String doInBackground(String... strings) {
  144. try{
  145. Class.forName("com.mysql.jdbc.Driver");
  146. Connection conexion_a_mysql = DriverManager.getConnection("jdbc:mysql://"+ip+":3306/"+base,user,pass);
  147. if(conexion_a_mysql == null){
  148. success = false;
  149. }else{
  150. String query = "SELECT id,idprofesor,todoeldia FROM ausencias WHERE '"+efecha+"' BETWEEN inicio AND fin";
  151. Statement stmt = conexion_a_mysql.createStatement();
  152. ResultSet rs = stmt.executeQuery(query);
  153. if(rs != null){
  154. while(rs.next()) {
  155. try{
  156. itemArrayList2.add(new ClassListItems2(rs.getInt("id"), rs.getString("idprofesor"), rs.getString("todoeldia")));
  157. } catch (Exception ex){
  158. ex.printStackTrace();
  159. }
  160. }
  161. msg = "Ejecutado correctamente";
  162. success = true;
  163. } else{
  164. msg = "ERROR en la ejecución";
  165. success = false;
  166. }
  167. }
  168. } catch (Exception ex){
  169. ex.printStackTrace();
  170. Writer writer = new StringWriter();
  171. ex.printStackTrace(new PrintWriter(writer));
  172. msg = writer.toString();
  173. success = false;
  174. }
  175. return msg;
  176. }
  177.  
  178. @Override
  179. protected void onPostExecute(String msg) {
  180. progress.dismiss();
  181. Toast.makeText(Main7Activity.this, msg + "", Toast.LENGTH_LONG).show();
  182. if(success == false){
  183. }else{
  184. try{
  185. myAppAdapter2 = new Main7Activity.MyAppAdapter2(itemArrayList2, Main7Activity.this);
  186. listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  187. listView.setAdapter(myAppAdapter2);
  188. } catch (Exception ex){
  189.  
  190. }
  191. }
  192. }
  193. }
  194.  
  195. public class MyAppAdapter2 extends BaseAdapter{
  196. public class ViewHolder{
  197. public TextView txtTodoeldia;
  198. public TextView txtProfe;
  199. public TextView textID;
  200. }
  201.  
  202. public List<ClassListItems2> ausencias_list;
  203.  
  204. public Context context;
  205. ArrayList<ClassListItems2> arrayList2;
  206.  
  207. private MyAppAdapter2(List<ClassListItems2> apps, Context context) {
  208. this.ausencias_list = apps;
  209. this.context = context;
  210. arrayList2 = new ArrayList<ClassListItems2>();
  211. arrayList2.addAll(ausencias_list);
  212. }
  213.  
  214. @Override
  215. public int getCount() { return ausencias_list.size(); }
  216.  
  217. @Override
  218. public Object getItem(int position) { return position; }
  219.  
  220. @Override
  221. public long getItemId(int position) { return position; }
  222.  
  223. @Override
  224. public View getView(final int position, View convertView, ViewGroup parent){
  225. View rowView = convertView;
  226. Main7Activity.MyAppAdapter2.ViewHolder viewHolder = null;
  227. if(rowView == null){
  228. LayoutInflater inflater = getLayoutInflater();
  229. rowView = inflater.inflate(R.layout.list_content2, parent, false);
  230. viewHolder = new Main7Activity.MyAppAdapter2.ViewHolder();
  231. viewHolder.textID = (TextView) rowView.findViewById(R.id.textID);
  232. viewHolder.txtProfe = (TextView) rowView.findViewById(R.id.textProfe);
  233. viewHolder.txtTodoeldia = (TextView) rowView.findViewById(R.id.textTodoeldia);
  234. rowView.setTag(viewHolder);
  235. } else{
  236. viewHolder = (Main7Activity.MyAppAdapter2.ViewHolder) convertView.getTag();
  237. }
  238.  
  239. profe = (ausencias_list.get(position).getIdprofesor() + "");
  240. if (profe.equals("1")){
  241. viewHolder.txtProfe.setText("Administrador");
  242. }
  243. if (profe.equals("20186")){
  244. viewHolder.txtProfe.setText("Fernández Odero, José Luis");
  245. }
  246. if (profe.equals("88455")){
  247. viewHolder.txtProfe.setText("Urbano Montero, José Antonio");
  248. }
  249. if (profe.equals("112706")){
  250. viewHolder.txtProfe.setText("Sarmiento Molina, Manuela");
  251. }
  252. if (profe.equals("127354")){
  253. viewHolder.txtProfe.setText("Rodríguez Fernández, Eva");
  254. }
  255. if (profe.equals("132178")){
  256. viewHolder.txtProfe.setText("Rodríguez Macías, Víctor Miguel");
  257. }
  258.  
  259. viewHolder.textID.setText(ausencias_list.get(position).getId() + "");
  260.  
  261. viewHolder.txtTodoeldia.setText(ausencias_list.get(position).getTodoeldia() + "");
  262. todoeldia = (ausencias_list.get(position).getTodoeldia() + "");
  263. if (todoeldia.equals("1")){
  264. viewHolder.txtTodoeldia.setText("Sí" + "");
  265. }
  266. if (todoeldia.equals("0")){
  267. viewHolder.txtTodoeldia.setText("No" + "");
  268. }
  269.  
  270.  
  271. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  272. int ID = 0;
  273. @Override
  274. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  275. ID = ausencias_list.get(position).getId();
  276. Bundle bundle2 = new Bundle();
  277. Intent desieteacinco = new Intent(Main7Activity.this,Main5Activity.class);
  278. bundle2.putString("IP",ip);
  279. bundle2.putString("BASE",base);
  280. bundle2.putString("USER",user);
  281. bundle2.putString("PASS",pass);
  282. bundle2.putInt("ID",ID);
  283.  
  284.  
  285. desieteacinco.putExtras(bundle2);
  286. startActivity(desieteacinco);
  287. }
  288. });
  289.  
  290. return rowView;
  291.  
  292. }
  293. }
  294.  
  295.  
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement