Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. package com.nure.dmytro21;
  2. import android.app.*;
  3. import android.content.*;
  4. import android.os.*;
  5. import android.util.*;
  6. import android.view.*;
  7. import android.widget.*;
  8. import android.widget.AdapterView.*;
  9. import com.nure.dmytro21.Adapters.*;
  10. import com.nure.dmytro21.models.*;
  11. import java.util.*;
  12. import org.json.*;
  13.  
  14. public class GoodsActivity extends Activity implements CarryOutQuerry.OnCarryOutListener, OnItemClickListener, OnClickListener
  15. //, GoodsAdapter.OnClickButtonChange
  16. {
  17.  
  18. static Technique t;
  19. CarryOutQuerry carryOutQuerry;
  20. static ArrayList<Photos> photos;
  21. ArrayList<Technique> tech;
  22. String techQuerry = "SELECT t.id_NummTechn, t.description, p.titleOfProd, t.model, t.guaranteec, t.nInStore, t.created, t.cost, ti.title FROM technique as t INNER JOIN Title as ti ON t.id_title = ti.id_title INNER JOIN Producer as p ON t.id_producer = p.id_producer ";
  23. String techQuerryWhere;
  24. GoodsAdapter adapter;
  25. ProgressDialog pd;
  26. ListView list;
  27. EditText etQuerrySearch;
  28. Button btnSendSearch;
  29. Button btnGoToCar;
  30.  
  31.  
  32. @Override
  33. protected void onCreate(Bundle savedInstanceState)
  34. {
  35. super.onCreate(savedInstanceState);
  36. requestWindowFeature(Window.FEATURE_NO_TITLE);
  37. getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
  38. setContentView(R.layout.list_activity_goods);
  39.  
  40. pd = new ProgressDialog(this);
  41. pd.setTitle("Loading");
  42. pd.setCanceledOnTouchOutside(false);
  43. pd.setCancelable(false);
  44.  
  45. list = (ListView) findViewById(R.id.list_activity_goodsListView);
  46. etQuerrySearch = (EditText) findViewById(R.id.list_activity_goodsEtSearch);
  47. btnSendSearch = (Button) findViewById(R.id.list_activity_goodsBtnOK);
  48. btnGoToCar = (Button) findViewById(R.id.listactivitygoodsBtnCar);
  49. list.setOnItemClickListener(this);
  50. btnSendSearch.setOnClickListener(this);
  51. btnGoToCar.setOnClickListener(this);
  52.  
  53. if (photos == null)
  54. photos = new ArrayList<>();
  55. carryOutQuerry = new CarryOutQuerry(this, "SELECT * FROM photos");
  56. carryOutQuerry.execute();
  57. carryOutQuerry.setICarryOut(this);
  58.  
  59. }
  60.  
  61. // @Override
  62. // public void onClickBtnChabge(View v, Technique tech, int requestCode)
  63. // {
  64. // if (requestCode == 1)
  65. // {
  66. // Intent Intent = new Intent(this, TechnActivity.class);
  67. // Intent.putExtra("idT", tech.getId_NummTechn());
  68. // startActivityForResult(Intent, requestCode);
  69. // }
  70. // }
  71.  
  72. @Override
  73. protected void onActivityResult(int requestCode, int resultCode, Intent data)
  74. {
  75. // TODO: Implement this method
  76. super.onActivityResult(requestCode, resultCode, data);
  77. }
  78.  
  79. @Override
  80. public void onClick(View p1)
  81. {
  82. switch (p1.getId())
  83. {
  84. case R.id.list_activity_goodsBtnOK : {
  85. if (etQuerrySearch.getText().toString() != null)
  86. {
  87. pd.setMessage("Поиск...");
  88. pd.show();
  89. CarryOutQuerry coq = new CarryOutQuerry(this, techQuerry + "WHERE Match(t.description) AGAINST(\"" + etQuerrySearch.getText().toString() + "\" IN NATURAL LANGUAGE MODE)");
  90. coq.execute();
  91. coq.setICarryOut(new CarryOutQuerry.OnCarryOutListener() {
  92.  
  93. @Override
  94. public void onCarryOut(JSONArray array, String querry)
  95. {
  96. if (array != null)
  97. {
  98. tech = Technique.getTechniques(array, photos, 0);
  99. adapter.setDataSet(tech);
  100. adapter.notifyDataSetChanged();
  101. }
  102. else
  103. {
  104. Toast.makeText(GoodsActivity.this, "Ничего нету(( попробуйте еще раз.", Toast.LENGTH_SHORT).show();
  105. etQuerrySearch.setText("");
  106. }
  107. }
  108. });
  109. pd.hide();
  110. }
  111. }
  112. break;
  113. case R.id.listactivitygoodsBtnCar : {
  114. if (!MainActivity.isEmptyCar)
  115. {
  116. if (MainActivity.idCustomer != -1 && MainActivity.idCustomer != 0)
  117. {
  118. goToCar();
  119. }
  120. else
  121. {
  122. CarryOutQuerry coq = new CarryOutQuerry(this, "SELECT customerId from Customers where idUser =" + MainActivity.idUser + ";");
  123. coq.execute();
  124. coq.setICarryOut(new CarryOutQuerry.OnCarryOutListener(){
  125.  
  126. @Override
  127. public void onCarryOut(JSONArray array, String querry)
  128. {
  129. try
  130. {
  131. MainActivity.idCustomer = array.getJSONObject(0).getInt("customerId");
  132. goToCar();
  133.  
  134. }
  135. catch (JSONException e)
  136. {}
  137. }
  138. });
  139. }
  140. }
  141. else
  142. {
  143. Toast.makeText(this, "Корзина пуста", Toast.LENGTH_LONG).show();
  144. }
  145. }
  146. break;
  147. }
  148. }
  149.  
  150. private void goToCar()
  151. {
  152. Intent intent = new Intent(this, CarActivity.class);
  153. Bills.InsertToBills(this, intent, null, null, null, null, 0);
  154. }
  155.  
  156. @Override
  157. public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4)
  158. {
  159. Toast.makeText(this, "AAAAA", Toast.LENGTH_LONG).show();
  160. Technique t = (Technique) p1.getItemAtPosition(p3);
  161. Intent intent = new Intent(this, GoodsItemResult.class);
  162. GoodsActivity.t = t;
  163. intent.putExtra("idT", t.getId_NummTechn());
  164. startActivity(intent);
  165. }
  166.  
  167. @Override
  168. public void onCarryOut(JSONArray array, String querry)
  169. {
  170. if (querry.equals("SELECT * FROM photos"))
  171. {
  172. pd.setMessage("Загружаем картиночки");
  173. pd.show();
  174. if (photos.size() == 0)
  175. photos.addAll(Photos.getPhotos(array, true));
  176.  
  177. carryOutQuerry = new CarryOutQuerry(this, techQuerry);
  178. carryOutQuerry.execute();
  179. carryOutQuerry.setICarryOut(this);
  180. }
  181. else if (querry.equals(techQuerry))
  182. {
  183. pd.setMessage("Выбираем технику");
  184. Log.i("mOLX", querry + "\n" + array.toString());
  185. tech = Technique.getTechniques(array, photos, 0);
  186.  
  187. adapter = new GoodsAdapter(this, tech);
  188. //adapter.setOnClickBtnChange(this);
  189. list.setAdapter(adapter);
  190. pd.hide();
  191. }
  192. }
  193.  
  194. }
  195.  
  196.  
  197.  
  198. /*
  199. "SELECT t.id_NummTechn, t.description, p.titleOfProd, t.model, t.guaranteec,
  200. t.nInStore, t.created, t.cost, ti.title
  201. FROM technique as t INNER JOIN Title as ti ON
  202. t.id_title = ti.id_title
  203. INNER JOIN Producer as p ON
  204. t.id_producer = p.id_producer"
  205.  
  206. ALTER TABLE Text ADD FULLTEXT (title,description);
  207.  
  208. ALTER TABLE Text ADD FULLTEXT (title);
  209.  
  210.  
  211. */
Add Comment
Please, Sign In to add comment