Android:点击“提交”按钮后将“等待”字符串数据发送到数据库

时间:2019-05-06 03:54:23

标签: java android mysql

根据我的问题,我想将用户填写的所有数据提交到名为"mysuggestion"的数据库表中。该表上的所有列均填充了用户的输入数据,但列"status""comment"除外,因为“状态”和“注释”均没有用户输入。这两列需要用单词“ waiting”填充。

该怎么办?下面是我的代码。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_confirm_suggestion);

    final ActionBar abar = getSupportActionBar();
    View viewActionBar = getLayoutInflater().inflate(R.layout.activity_new_suggestion, null);
    ActionBar.LayoutParams params = new ActionBar.LayoutParams(//Center the textview in the ActionBar !
            ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.MATCH_PARENT,
            Gravity.CENTER);
    TextView tvTitle = viewActionBar.findViewById(R.id.title);
    tvTitle.setText("CONFIRMATION");
    abar.setCustomView(viewActionBar, params);
    abar.setDisplayShowCustomEnabled(true);
    abar.setDisplayShowTitleEnabled(false);
    //abar.setDisplayHomeAsUpEnabled(true);
    abar.setHomeButtonEnabled(true);


    txtName = findViewById(R.id.txtName);
    txtBadgeID = findViewById(R.id.txtBadgeID);
    txtPosition = findViewById(R.id.txtPosition);
    txtDepartment = findViewById(R.id.txtDepartment);
    txtFactory = findViewById(R.id.txtFactory);

    //getting the current user
    User user = SharedPrefManager.getInstance(this).getUser();

    //setting the values to the textviews
    txtName.setText(user.getName());
    txtBadgeID.setText(user.getBadgeid());
    txtPosition.setText(user.getPosition());
    txtDepartment.setText(user.getDepartment());
    txtFactory.setText(user.getFactory());

    etReviewer = findViewById(R.id.etReviewer);
    etTitle = findViewById(R.id.etTitle);
    etYear = findViewById(R.id.etYear);
    etMonth = findViewById(R.id.etMonth);
    etSuggestWill = findViewById(R.id.etSuggestWill);
    etPresent = findViewById(R.id.etPresent);
    etDetails = findViewById(R.id.etDetails);
    etBenefit = findViewById(R.id.etBenefit);
    imgAttach = findViewById(R.id.imgAttach);

    SharedPreferences sharedPreferences = getSharedPreferences("MyData", MODE_PRIVATE);
    String reviewer =  sharedPreferences.getString("reviewer",DEFAULT);
    String title = sharedPreferences.getString("title",DEFAULT);
    String year = sharedPreferences.getString("year",DEFAULT);
    String month =  sharedPreferences.getString("month",DEFAULT);
    String suggestionwill =  sharedPreferences.getString("suggestionwill",DEFAULT);
    String present =  sharedPreferences.getString("present",DEFAULT);
    String details = sharedPreferences.getString("details",DEFAULT);
    String benefit =  sharedPreferences.getString("benefit",DEFAULT);
    String photo = sharedPreferences.getString("photo",DEFAULT);
    String status = sharedPreferences.getString("status",DEFAULT);
    String comment = sharedPreferences.getString("comments",DEFAULT);

    etReviewer.setText(reviewer);
    etTitle.setText(title);
    etYear.setText(year);
    etMonth.setText(month);
    etSuggestWill.setText(suggestionwill);
    etPresent.setText(present);
    etDetails.setText(details);
    etBenefit.setText(benefit);
    imgAttach.setImageBitmap(base64ToBitmap(photo));

}

public static Bitmap base64ToBitmap(String encodedString) {
    byte[] decodedString = Base64.decode(encodedString, Base64.DEFAULT);
    Bitmap bitmap= BitmapFactory.decodeByteArray(decodedString , 0,
            decodedString.length);
    return bitmap;
}

public void submit(View v ) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Submit");
    builder.setMessage("Do you want to submit this suggestion?");
    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {

            save();
            Intent intent = new Intent(ConfirmSuggestion.this, Submitted.class);
            startActivity(intent);
        }
    });
    builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.cancel();
        }
    });
    builder.show();
}

private void save() {
    final String name = txtName.getText().toString().trim();
    final String badgeid = txtBadgeID.getText().toString().trim();
    final String position = txtPosition.getText().toString().trim();
    final String department = txtDepartment.getText().toString().trim();
    final String factory = txtFactory.getText().toString().trim();
    String reviewer = etReviewer.getText().toString().trim();
    reviewer = reviewer.split("-")[0]; // 004
    final String title = etTitle.getText().toString().trim();
    final String year = etYear.getText().toString().trim();
    final String month = etMonth.getText().toString().trim();
    final String suggestionwill = etSuggestWill.getText().toString().trim();
    final String present = etPresent.getText().toString().trim();
    final String details = etDetails.getText().toString().trim();
    final String benefit = etBenefit.getText().toString().trim();

    BitmapDrawable drawable = (BitmapDrawable) imgAttach.getDrawable();
    final String photo = bitmapToBase64(drawable.getBitmap());

    save1(name, badgeid, position, department, factory, reviewer, title, year, month,
            suggestionwill, present, details, benefit,photo,status, comment);
}

public static String bitmapToBase64(Bitmap image) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    image.compress(Bitmap.CompressFormat.JPEG, 100, os);
    byte[] byteArray = os.toByteArray();
    String encodedImageString = Base64.encodeToString(byteArray, Base64.DEFAULT);
    return encodedImageString ;
}

private void save1(String name, String badgeid, String position, String department, String factory, String reviewer,
                      String title, String year, String month, String suggestionwill, String present, String details,
                      String benefit, String photo, String status, String comment) {

    User user = SharedPrefManager.getInstance(this).getUser();
    SharedPrefManager.getInstance(this).userLogin(new User(user.getId(),name, badgeid, position, department, factory, reviewer,
             title,  year,  month,  suggestionwill,  present,  details,
             benefit,  photo, status, comment));

    class saveSuggest extends AsyncTask<String, Void, String> {
        ProgressDialog loading;
        RequestHandler requestHandler = new RequestHandler();

        @Override
        protected String doInBackground(String... params) {

            HashMap<String, String> data = new HashMap<String, String>();
            data.put("name", params[0]);
            data.put("badgeid", params[1]);
            data.put("position", params[2]);
            data.put("department", params[3]);
            data.put("factory", params[4]);
            data.put("reviewer", params[5]);
            data.put("title", params[6]);
            data.put("year", params[7]);
            data.put("month", params[8]);
            data.put("suggestionwill", params[9]);
            data.put("present", params[10]);
            data.put("details", params[11]);
            data.put("benefit", params[12]);
            data.put("photo", params[13]);
            data.put("status", params[14]);
            data.put("comment", params[15]);

            String result = requestHandler.sendPostRequest(URLs.URL_SAVE, data);

            return result;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loading = ProgressDialog.show(ConfirmSuggestion.this, "Saving..", null, true, true);
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            loading.dismiss();
            Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
        }
    }

    saveSuggest sl1 = new saveSuggest();
    sl1.execute(name, badgeid, position, department, factory, reviewer, title, year, month,
            suggestionwill, present, details, benefit, photo, status, comment);
}

1 个答案:

答案 0 :(得分:0)

当您从#!/bin/sh trap 'stop' 2 stop() { kill -9 $pid1 $pid2 } JmeterFolder=$1 $JmeterFolder/bin/jmeter.bat -n -t one.jmx -j oneLog.log & pid1=$! & $JmeterFolder/bin/jmeter.bat -n -t two.jmx -j twoLog.log & pid2=$! & wait 获取状态评论数据时,将其默认值“ 正在等待”设置为-

SharedPreferences

希望它对您有用。谢谢