Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何一次从数据库中获取不同的max id_Android_Sql Server_Database - Fatal编程技术网

Android 如何一次从数据库中获取不同的max id

Android 如何一次从数据库中获取不同的max id,android,sql-server,database,Android,Sql Server,Database,您好,我正在创建一个酒店应用程序,当我在数据库中插入订单时,我正在从数据库中获取最大订单ID,并在数据库中插入订单和订单ID。但我的问题是,当我在两个不同的设备上安装应用程序时,当我下订单时,它会将相同的orderid插入到不同的表中,并插入到数据库中,订单插入到一个表中,所以请给我任何解决方案 private void openAlert(View view) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.

您好,我正在创建一个酒店应用程序,当我在数据库中插入订单时,我正在从数据库中获取最大订单ID,并在数据库中插入订单和订单ID。但我的问题是,当我在两个不同的设备上安装应用程序时,当我下订单时,它会将相同的orderid插入到不同的表中,并插入到数据库中,订单插入到一个表中,所以请给我任何解决方案

    private void openAlert(View view) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DisplayActivity.this);
    new AsyncLoadOrderId().execute();
    alertDialogBuilder.setTitle("Restrosoft");
    alertDialogBuilder.setMessage("Are you sure?");
    // set positive button: Yes message
    alertDialogBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // go to a new activity of the app

            for (int i = 0; i < user_fName.size(); i++) {
                System.out.println(user_fName.get(i)); //prints element i
                menulists = user_fName.get(i);
                if (tabletypes.equals("A/C")) {

                    getAcrate(menulists);
                    getTotalamount(menulists, convertedvaluefororderid);
                    getmenuidofperticular(menulists);
                    getButtonfinalordertodb();
                    String conquantity = String.valueOf(quantity);
                    new AsyncInsertIntoTemp().execute(menulists, conquantity, OrderIdFromService, WaiterName, str1);
                } else if (tabletypes.equals("Non A/C")) {

                    getProfilesCount(menulists);
                    getTotalamount(menulists, convertedvaluefororderid);
                    getmenuidofperticular(menulists);
                    getButtonfinalordertodb();
                    String conquantity = String.valueOf(quantity);
                    new AsyncInsertIntoTemp().execute(menulists, conquantity, OrderIdFromService, WaiterName, str1);
                } else {
                    Toast.makeText(DisplayActivity.this, "Closed", Toast.LENGTH_SHORT).show();
                }
            }

            Insertingintotableorder inserttableorder = new Insertingintotableorder(OrderIdFromService, str1, currentDateTimeString, intentfromTwolistwid, ordertype, tablestatustblord, discvaluefortblord, discamount);
            new AsyncCreatetableOrder().execute(inserttableorder);
            new AsyncCreateTemporder().execute(OrderIdFromService, KOTIDFromTwolist, str1, "", "", WaiterName);
            ForupdateStatus updatestatushere = new ForupdateStatus(str1);
            new AsyncupdateStatus().execute(updatestatushere);
            Intent intents = new Intent(DisplayActivity.this, MainActivity.class);
            intents.putExtra("Uname", WaiterName);
            intents.putExtra("ForButton", cntforb);
            startActivity(intents);
            mHelper.remove();
            Toast.makeText(DisplayActivity.this, "Successfully inserted...", Toast.LENGTH_LONG).show();
        }
    });
    // set negative button: No message
    alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // cancel the alert box and put a Toast to the user
            dialog.cancel();

        }
    });
    // set neutral button: Exit the app message
    alertDialogBuilder.setNeutralButton("Exit the app", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // exit the app and go to the HOME
            DisplayActivity.this.finish();
        }
    });

    AlertDialog alertDialog = alertDialogBuilder.create();
    // show alert
    alertDialog.show();
}
private void openAlert(视图){
AlertDialog.Builder alertDialogBuilder=新建AlertDialog.Builder(DisplayActivity.this);
新建AsyncLoadOrderId().execute();
alertDialogBuilder.setTitle(“Restrosoft”);
setMessage(“您确定吗?”);
//设置积极按钮:是消息
alertDialogBuilder.setPositiveButton(“是”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
//转到应用程序的新活动
对于(int i=0;i
以下是异步任务:

 protected class AsyncLoadOrderId extends
            AsyncTask<String, String, JSONObject> {
        JSONObject jsonObj = null;
        //ArrayList<UserOrder> subTablea = null;

        @Override
        protected JSONObject doInBackground(String... args) {
            // TODO Auto-generated method stub

            RestAPI api = new RestAPI();
            try {

                jsonObj = api.GetOrdertopid();
                JSONParser parser = new JSONParser();


                //subTablea = parser.parsOrderid(jsonObj);


            } catch (Exception e) {
                // TODO Auto-generated catch block
                Log.d("AsyncLoadDeptDetails", e.getMessage());

            }
            return jsonObj;


        }

        @Override
        protected void onPostExecute(JSONObject json) {
            // TODO Auto-generated method stub
            try {
                JSONArray jsonArray = json.getJSONArray("Value");

                for (int i = 0; i < jsonArray.length(); i++) {
                    jsonObj = jsonArray.getJSONObject(i);

                }
                OrderIdFromService = jsonObj.getString("order_id");
                convertedorderid = Integer.parseInt(OrderIdFromService);
                orderidfortable.setText(OrderIdFromService);

                if (intentresponse.equals("Yes")) {

                     serveroid = String.valueOf(orderid);
                    orderidfortable.setText(serveroid);

                }
            } catch (Exception e) {

                e.printStackTrace();


            }


        }
受保护类AsyncLoadOrderId扩展
异步任务{
JSONObject jsonObj=null;
//ArrayList子表a=null;
@凌驾
受保护的JSONObject doInBackground(字符串…args){
//TODO自动生成的方法存根
RestAPI api=new RestAPI();
试一试{
jsonObj=api.GetOrdertopid();
JSONParser=新的JSONParser();
//subTablea=parser.parsOrderid(jsonObj);
}捕获(例外e){
//TODO自动生成的捕捉块
d(“AsyncLoadDeptDetails”,e.getMessage());
}
返回jsonObj;
}
@凌驾
受保护的void onPostExecute(JSONObject json){
//TODO自动生成的方法存根
试一试{
JSONArray JSONArray=json.getJSONArray(“值”);
for(int i=0;i
您的异步工作完全错误

例如,如果我打电话

new AsyncLoadOrderId().execute();
然后立即单击
AlertDialog
的“是”按钮,我将得到错误的结果,因为
OrderIdFromService
可以有上一个值。换句话说
OrderIdFromService
AsyncLoadOrderId()之后获取值
将完成其工作,但其他操作是同步的。如果internet连接速度慢/不好,则根本无法工作

所以这条线

new AsyncInsertIntoTemp().execute(menulists, conquantity, OrderIdFromService, WaiterName, str1);
不执行任何操作,因为
OrderIdFromService