0
package symca.gescoe.com.sampleparseapp.payment_task;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;

import symca.gescoe.com.sampleparseapp.R;


import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseACL;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import com.parse.SaveCallback;

import java.util.List;


public class PayRent extends Activity {

    TextView ownerName, ownerEmail, ownerPropType, ownerLocation, ownerAccountNo, renterAccountNo;
    EditText propId;
    int confirmFlag = 0;
    int rentFinal = 0, mainFinal = 0, totalFinal = 0;

    int rent;
    int maintenance;
    String ownerNameStr;
    String ownerEmailStr;
    String ownerPropTypeStr;
    String ownerLocationStr;
    String ownerAccountNoStr;
    String renterAccountNoStr;
    String propIdStr;
    Button btnpayRent;
    ImageView btnConfirm;
    int payInterestFlag = 1;
    ProgressDialog progressDialog;

    String proType, location, email, fname, lname, ownerAccount, renterAccount;
    String ownerObjId,ownerAvlBal;
    int bhk;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_rent);

//        ParseACL defaultACL = new ParseACL();
//       defaultACL.setPublicWriteAccess(true);//------temp


        btnConfirm = (ImageView) findViewById(R.id.btnConfirmIDPay);
        btnpayRent = (Button) findViewById(R.id.btnPayRent);
        propId = (EditText) findViewById(R.id.tvPropIDPay);
        ownerName = (TextView) findViewById(R.id.tvNamePay);
        ownerEmail = (TextView) findViewById(R.id.tvEmailPay);
        ownerPropType = (TextView) findViewById(R.id.tvPropTypePay);
        ownerLocation = (TextView) findViewById(R.id.tvLocPay);
        ownerAccountNo = (TextView) findViewById(R.id.tvLandAccountNoPay);
        renterAccountNo = (TextView) findViewById(R.id.tvRenterAccountNoPay);


        final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLauPropertyPay);


        btnConfirm.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v) {
                confirmFlag = 1;
                progressDialog = ProgressDialog.show(PayRent.this, "Please Wait...", "Property Details Loading..");

                String propIdStr = propId.getText().toString();

                if (!propIdStr.equals(""))
                {


                    final ParseQuery<ParseObject> query = ParseQuery.getQuery("PostAdd");
                    query.whereEqualTo("objectId", propIdStr);

                    query.getFirstInBackground(new GetCallback<ParseObject>()
                    {
                        @Override
                        public void done(ParseObject object, ParseException e)
                        {

                            if (e == null)//-----from Post Add Table--------------
                            {

                                email = object.getString("PostEmail");
                                bhk = object.getInt("BHK");
                                proType = object.getString("PropType");
                                location = object.getString("Location");

                                rent = object.getInt("ERent");
                                maintenance = object.getInt("Emaintainance");



                                //-------------from User Table-------
                                ParseQuery query = ParseUser.getQuery();
                                query.whereEqualTo("email", email);

                                query.getFirstInBackground(new GetCallback()
                                {
                                    @Override
                                    public void done(ParseObject object, ParseException e)
                                    {
                                        String interest = object.getString("PaymentInterest");

                                        if (interest.equals("Interested"))
                                        {
                                            payInterestFlag = 0;
                                            fname = object.getString("FirstName");
                                            lname = object.getString("LastName");
                                            ownerAccount = object.getString("AccountNo");
                                            renterAccount = ParseUser.getCurrentUser().getString("AccountNo");


                                            ownerName.setText(fname + " " + lname);
                                            ownerAccountNo.setText(ownerAccount);
                                            renterAccountNo.setText(renterAccount);
                                            ownerEmail.setText(email);
                                            ownerLocation.setText(location);
                                            ownerPropType.setText(bhk + " " + "BHK " + proType);

                                            progressDialog.dismiss();
                                        } else
                                        {
                                            progressDialog.dismiss();
                                            payInterestFlag = 1;
                                            AlertDialog.Builder alertPayInterest = new AlertDialog.Builder(PayRent.this);
                                            alertPayInterest.setTitle("Not Interested!");
                                            alertPayInterest.setIcon(R.drawable.notonline);
                                            alertPayInterest.setMessage("Ohhh!!!\nSelected Add Owner Not Interested In Online Payment");
                                            alertPayInterest.show();


                                        }

                                    }
                                });


                            } else
                            {
                                progressDialog.dismiss();

                                propId.setError("Property Id is Not Valid!!!");

                            }

                        }
                    });

                }//if
                else {
                    progressDialog.dismiss();
                    propId.setError("Property Id Blank");
                }

            }
        });

//----------------------------------------------------------------------

        btnpayRent.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {

                Toast.makeText(getApplicationContext(), "Click Rent", Toast.LENGTH_SHORT).show();


                if ((!propId.getText().toString().equals("")) && (confirmFlag == 1))
                {


                    LayoutInflater factory = LayoutInflater.from(PayRent.this);
                    final View textEntryView = factory.inflate(R.layout.custom_dialogue_payrent, null);

                    final EditText inputRent = (EditText) textEntryView.findViewById(R.id.edtRentCustom);
                    inputRent.setEnabled(false);
                    final EditText inputMain = (EditText) textEntryView.findViewById(R.id.edtMainCustom);
                    inputMain.setEnabled(false);


                    ImageView imgRent = (ImageView) textEntryView.findViewById(R.id.edtImgRentPay);
                    ImageView imgMain = (ImageView) textEntryView.findViewById(R.id.edtImgMainPay);


                    // Toast.makeText(getApplicationContext(),"rent is "+rent,Toast.LENGTH_SHORT).show();
                    inputRent.setText("" + rent);
                    inputMain.setText("" + maintenance);

                    imgRent.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            inputRent.setEnabled(true);
                            //inputRent.requestFocus();

                        }
                    });

                    imgMain.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            inputMain.setEnabled(true);
                        }
                    });


                    final AlertDialog.Builder alert = new AlertDialog.Builder(PayRent.this);
                    alert.setIcon(R.drawable.donation);
                    alert.setTitle("Payment Details");
                    alert.setView(textEntryView);
                    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
                    {
                        public void onClick(DialogInterface dialog, int whichButton)
                        {
                            //-------------Positive Button

                            rentFinal = Integer.parseInt(inputRent.getText().toString());
                            mainFinal = Integer.parseInt(inputMain.getText().toString());
                            totalFinal = rentFinal + mainFinal;

                            //--transaction table-------
                            ParseObject objTrans = new ParseObject("Transactions");
                            objTrans.put("Debtor", renterAccount);//renter
                            objTrans.put("Creditor", ownerAccount);//owner
                            objTrans.put("TotalAmt", totalFinal);
                            objTrans.saveInBackground();
                            //--------------------------------


                            final ParseQuery<ParseObject> querypradip = ParseQuery.getQuery("Pay");
                            querypradip.whereEqualTo("AccountNo", ownerAccount);
                            querypradip.getFirstInBackground(new GetCallback<ParseObject>() {
                                public void done(ParseObject object, ParseException e) {
                                    if (object == null) {
                                        Log.d("score", "The getFirst request failed."+e.getMessage());
                                    } else {
                                        Log.d("score", "Retrieved the object.");

                                        ownerObjId=object.getObjectId();
                                        ownerAvlBal=object.getString("AvailableBal");

                                        Log.d("Oid", ownerObjId);
                                        Log.d("OBal", ownerAvlBal);
                                        Toast.makeText(getApplicationContext(), "ownerId"+ownerObjId+"\nAval Bal"+ownerAvlBal, Toast.LENGTH_LONG).show();



                                        //--------------------UPDATE--------------





                                      ParseQuery query = new ParseQuery("Pay");
                                        query.getInBackground(ownerObjId, new GetCallback()
                                        {
                                            public void done(final ParseObject object, ParseException e)
                                            {
                                                if (e == null)
                                                {

                                                    object.put("Bal", 5000);

                                                    object.saveInBackground();
                                                    Toast.makeText(getApplicationContext(), "After Save In Back", Toast.LENGTH_LONG).show();

                                                    object.saveInBackground(new SaveCallback()
                                                    {
                                                        public void done(ParseException e)
                                                        {

                                                            object.put("AvailableBal", 7000);
                                                            object.saveInBackground();

                                                        }
                                                    });

                                                }

                                                else
                                                {
                                                    e.printStackTrace();
                                                    Log.e("In Update",e.getMessage());
                                                }

                                            }
                                        });

                                    }
                                }
                            });



                            //---reter table---------------
                            ParseQuery<ParseObject> queryPay = new ParseQuery<ParseObject>("Pay");
                            queryPay.whereEqualTo("AccountNo", renterAccount);
                            queryPay.getFirstInBackground(new GetCallback<ParseObject>() {
                                @Override
                                public void done(ParseObject object, ParseException e) {
                                    String AvailBal = object.getString("AvailableBal");
                                    String renterID = object.getObjectId();

                                    final int remainsBal = Integer.parseInt(AvailBal) - totalFinal;

                                    Log.e("Renter", "************" + remainsBal);
                                    Log.e("RenterID", "************" + renterID);

                                    //----------------Update------------------
                                    ParseQuery queryUpdatePay = new ParseQuery("Pay");
                                    queryUpdatePay.getInBackground(renterID, new GetCallback() {
                                        @Override
                                        public void done(ParseObject Obj, ParseException e) {
                                            if (e == null) {

                                                Obj.put("AvailableBal", "" + remainsBal);
                                                Log.e("Update", "************" + remainsBal);
                                                Obj.saveInBackground();


                                            } else {
                                                // do something with the error...
                                            }
                                        }

                                    });
                                }//done


                            });





                        }
                     });//Ok






                    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                                    int whichButton) {



                                }
                            }

                    );
                    alert.show();

                } else
                if (propId.getText().toString().equals(""))
                {
                    propId.setError("Property Id Blank!");
                }

                if (confirmFlag == 0)
                {
                    Toast.makeText(getApplicationContext(), "Please Confirm Property Id before Pay", Toast.LENGTH_SHORT).show();
                }


            }
        });


    }//OnCreate


}

テーブルから取得するだけでなく、Payテーブルにデータを保存する(オブジェクトを使用して簡単に言えば)こともできますが、更新しようとしてもテーブルに変化が見られません........同じ私現在のユーザー(レンタルデータ)を申請しています すべてのデータを取得し、更新しましたが、現在のユーザー以外のユーザー データは更新されません

4

1 に答える 1

0

このような大きなコード ブロックを理解しようとはしません。将来的には、関連する部分を煮詰めてみてください。でも:

  1. 保存した直後にクエリを実行しているようです。saveInBackground() は非同期であるため、(名前が示すように) parse.com への接続を開始し、バックグラウンド スレッドに保存することに注意してください。クエリが保存されるオブジェクトに依存する場合は、SaveCallback パラメータを追加して完了するまで待機する必要があります。saveInBackground(new SaveCallback)
  2. 更新が失敗したことが原因である場合は、SaveCallback を再度実装して、スローされる例外を確認します。saveInBackground(new SaveCallback)
  3. 自分以外の User オブジェクトを更新することはできません。それはセキュリティ上の大きな問題になります。回避策として、を使用してクラウド関数を作成しuseMasterKey()、アプリからその関数を呼び出すことができます。
于 2015-05-12T07:09:13.603 に答える