lundi 9 mai 2016

Adding button which can create data

i just join my job and the ask me to create an POS app. i did about most of thing but i am stuck in database. and also how to create same pattern they want. and a also a button which can create another button which had multi field.

Application is slow after install on another pc

I have build a WPF application with SQLite. After create setup project in visual studio and install it on my developer machine, app works perfect. But when my client install it on another computer it's works very slow. I added project output and SQLite.Interop.dll for database to setup project. Also one of my .dll is COM dll.

This application communicate only with SQLite database.

I have noticed that application works fine but with admin rights on client computer.

What can be the reason of this?

Would this RESTful iOS login system be secure?

So I have been thinking about a way to make a secure restful API for ios logins.

This is what my teacher and I have come up with:

  1. The Client (swift program) initializes the connection with the server.
  2. The Server returns a "shared secret" (ex. +40) and a hash of a random string of letters and numbers.
  3. The Client then hashes the Username and Password (separate) and sends it back with the hash of: hash + "the shared secret".
  4. After the Server sends data (step 2) the server hashes [hash + "shared secret"] and then updates it in the db
  5. The Server then receives the hashed value from the Client and checks the db to see if it matches
  6. The db will also have a timestamp that if not updated frequently enough there will be a function that runs through the db and drops the items that are no longer used.
  7. For every request after the login the bearer token is sent.

The bearer token will follow this formula: Request verification token = hash [ (original hash) + (shared secret) * (# of requests) ]

Only fetch date from datetime value of db sqlite android? Compare with current date and the then display time of the saved value?

I am trying to fetch date from my db, where its stored with time. I want to compare the date with in my adapter, if the date is equal to the current date then adapter fetch time only of the corresponding date, and if date is not equal to the current date then adapter display the date of the corresponding value,

This is how I am inserting date+time in DB:

long date = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM-dd-yyyy h:mm:a");
String dateString = sdf.format(date);
s.setTime(dateString);
Log.i("result", s.getTime());
DatabaseHandler db = new DatabaseHandler(this);
db.creatScan(new Scan(s.getMsg().toString(), s.getTime().toString()));
db.close();

In my Adapter:

 TextView details = (TextView)convertView.findViewById(R.id.scandetails);

        TextView times = (TextView)convertView.findViewById(R.id.scanTime);

        times.setText(scan.getTime());

This is the Result:

enter image description here

What I want is: It should only display the time, if the date is equal to the current date, else it should only display the date.

I am trying this if/else statement but its not working, Your help would be very appreciated, thanks in advance

long date = System.currentTimeMillis();

SimpleDateFormat sdfDate = new SimpleDateFormat("MMM-dd-yyyy");

String dateString = sdfDate.format(date);

Log.i("date", dateString);

SimpleDateFormat sdfTime = new SimpleDateFormat("h:mm:a");

String timeString = sdfTime.format(date);

Log.i("date", timeString);

if(scan.getTime().equals(dateString)){

            times.setText(dateString);
    Log.i("data", timeString);
}else {
    String time =  scan.getTime().toString();
    Log.i("date", time);
    times.setText(scan.getTime());
}

Removing and creating PersistentStore and sqlite database

I'm working on an app that exchanges data with a server, and the mobile device has an option to wipe the database clean. I've looked around here and I found out I'm using the same code that's been suggested.

BOOL removedPS = [self.persistentStoreCoordinator removePersistentStore:store error:&error];
BOOL removedSqlite = [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];

I use the two BOOLs to check if the operations have been made correctly and everything seems to be working smooth. Even the double check

[[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]

says the file has been deleted. After that, I want to re-create Persistent Store and sqlite:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
{
   //ouch :/
}

but the addPersistentStoreWithType keeps on returning a "false" flag. Same goes with the sqlite: I try to copy a fresh .sqlite database, but I keep getting a "nil" for the NSString *param variable, and I can't understand why.

NSError* err = nil;
                NSBundle *bundle = [NSBundle mainBundle];
                NSString *path = @"BaseScope";
                NSString *type = @"sqlite";
                NSString *param = [bundle pathForResource:path ofType:type];

                //NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"BaseScope" ofType:@"sqlite"]];
                //NSURL *preloadURL = [NSURL fileURLWithPath:[bundle pathForResource:path ofType:type]];
                if (param != nil)
                {
                    NSURL *preloadURL = [NSURL fileURLWithPath:param isDirectory:false];

                    if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err])
                    {

                    }
                }

I always worked in the .NET environment and this is really puzzling me, but knocking the head against the monitor won't work. Any help appreciated. Thanks in advance.

Using multiple cursor OR using same cursor for multiple queries

I want to fetch data from multiple table in my activity having 2 Listviews and some EditTexts.

I want to fetch data in EditText from Table 1 And fetch data in ListView1 from Table 2 and data from Table 3 into ListView2.

Problem is : i can fetch data through cursor from table 1. But I can't fetch data from table2 using same cursor OR new Cursor.

Table have data but Cursor.MoveToFirst returns false.

public class Details extends AppCompatActivity {

TextView name,num,cty,det;
Button btn_debit,btn_credit;
SQLiteDatabase db;
Cursor c;
int id;
ListView dbList,crList;
private ArrayList<HashMap<String,String>> arrayList;

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

    id = Integer.parseInt(getIntent().getExtras().getString("name"));

    name = (TextView)findViewById(R.id.textView6);
    num = (TextView)findViewById(R.id.textView7);
    cty = (TextView)findViewById(R.id.textView8);
    det = (TextView)findViewById(R.id.textView9);

    btn_debit = (Button)findViewById(R.id.jama);
    btn_credit = (Button)findViewById(R.id.udhar);

    dbList = (ListView)findViewById(R.id.ListDebit);
    crList = (ListView)findViewById(R.id.ListCredit);

    arrayList = new ArrayList<HashMap<String, String>>();

    // tv = (TextView)findViewById(R.id.textView6);
    //tv.setText(getIntent().getExtras().getString("name"));
    db = openOrCreateDatabase("AccountsDB", Context.MODE_PRIVATE,null);

    c=db.rawQuery("SELECT c_name , c_mno , c_detail , c_city FROM customers where c_id="+id,null);
    try {
        if (c!=null){
            if (c.moveToFirst()){
                name.setText(c.getString(0));
                num.setText(c.getString(1));
                cty.setText(c.getString(3));
                det.setText(c.getString(2));
            }
        }
    }catch (Exception e){

    }finally {
        c.close();
    }

    Cursor cursor = db.rawQuery("SELECT * FROM debit_master",null);
    try{
        if (cursor!=null){
            if (cursor.moveToFirst()){
                Map<String,String> tem  = new HashMap<String ,String>();
                tem.clear();
                arrayList.clear();
                dbList.setAdapter(null);
                int cnt = cursor.getCount();
                Toast.makeText(getApplicationContext(),""+cnt,Toast.LENGTH_SHORT).show();
                do {

                    tem = new HashMap<String,String>();
                    tem.clear();

                    tem.put(FIRST_COLUMN, cursor.getString(0));
                    tem.put(SECOND_COLUMN,cursor.getString(1));
                    tem.put(THIRD_COLUMN,cursor.getString(2));
                    arrayList.add((HashMap<String, String>) tem);
                }while (cursor.moveToNext());
            }
        }

    }catch (Exception ex){
        Toast.makeText(getApplicationContext(),""+ex,Toast.LENGTH_LONG).show();
    }


    ListViewAdapter adapter = new ListViewAdapter(this,arrayList);
    dbList.setAdapter(adapter);


    btn_debit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Details.this,Debit.class);
            intent.putExtra("cid",id);
            Details.this.startActivity(intent);
        }
    });

}

}

What's meaning of this my code?

I hope your help the coding. Now i connect the android studio in database. But start a coding don't know error in my program. So I check a php file and check the programming coding isn't not error and Execute a program. enter image description here

Show the picture, Can you see the blue text code? Execute a program and writing a code in select part. But, alert a this word in my program

"05-09 13:32:44.533 325-333/? W/genymotion_audio: out_write() limiting sleep time 46802 to 39909".

What's meannig this code???