0% found this document useful (0 votes)
61 views3 pages

Pre Test Phase - Coding

The document describes an Android layout XML file for a pharmacy app. It includes edit texts, buttons, and other elements to display and manage medicine data. The layout allows users to view, add, update and delete medicine records in the app.

Uploaded by

Muhammad Afzaal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Pre Test Phase - Coding

The document describes an Android layout XML file for a pharmacy app. It includes edit texts, buttons, and other elements to display and manage medicine data. The layout allows users to view, add, update and delete medicine records in the app.

Uploaded by

Muhammad Afzaal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

<?xml version="1.0" encoding="utf-8"?

> android:layout_below="@id/edit_text_type"
<androidx.constraintlayout.widget.ConstraintLayout android:layout_marginTop="5dp"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_marginStart="20dp"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_marginEnd="20dp"
xmlns:tools="http://schemas.android.com/tools" />
android:layout_width="match_parent"
android:layout_height="match_parent" <EditText
tools:context=".MainActivity"> android:id="@+id/edit_text_generation"
android:layout_width="match_parent"
<ScrollView android:layout_height="wrap_content"
android:layout_width="match_parent" android:hint="@string/generation"
android:layout_height="match_parent"> android:inputType="text"

<RelativeLayout android:layout_below="@id/edit_text_category"
android:layout_width="fill_parent" android:layout_marginTop="5dp"
android:layout_height="wrap_content"> android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
<TextView />
android:id="@+id/tvtop"
android:layout_width="match_parent" <EditText
android:layout_height="wrap_content" android:id="@+id/edit_text_reaction"
android:layout_marginTop="10dp" android:layout_width="match_parent"
android:layout_marginStart="20dp" android:layout_height="wrap_content"
android:layout_marginEnd="20dp" android:hint="@string/reaction"
android:text="@string/medicine_info" android:inputType="text"
android:textSize="30sp"
android:gravity="center" /> android:layout_below="@id/edit_text_generation"
android:layout_marginTop="5dp"
<EditText android:layout_marginStart="20dp"
android:id="@+id/edit_text_id" android:layout_marginEnd="20dp"
android:layout_width="match_parent" />
android:layout_height="wrap_content"
android:hint="@string/id" <Button
android:inputType="number" android:id="@+id/btn_store_data"
android:layout_below="@id/tvtop" android:layout_width="60dp"
android:layout_marginTop="5dp" android:layout_height="40dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp" android:layout_below="@id/edit_text_reaction"
/> android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
<EditText android:text="@string/save"
android:id="@+id/edit_text_name" />
android:layout_width="match_parent"
android:layout_height="wrap_content" <Button
android:hint="@string/name" android:id="@+id/btn_view_data"
android:inputType="text" android:layout_width="60dp"
android:layout_below="@id/edit_text_id" android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_marginStart="20dp" android:layout_below="@id/edit_text_reaction"
android:layout_marginEnd="20dp" android:layout_toEndOf="@id/btn_store_data"
/> android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
<EditText android:text="@string/view"
android:id="@+id/edit_text_manufacturer" />
android:layout_width="match_parent"
android:layout_height="wrap_content" <Button
android:hint="@string/manufacturer" android:id="@+id/btn_update_data"
android:inputType="text" android:layout_width="80dp"
android:layout_below="@id/edit_text_name" android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_marginStart="20dp" android:layout_below="@id/edit_text_reaction"
android:layout_marginEnd="20dp" android:layout_toEndOf="@id/btn_view_data"
/> android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
<EditText android:text="@string/update"
android:id="@+id/edit_text_price" />
android:layout_width="match_parent"
android:layout_height="wrap_content" <Button
android:hint="@string/price" android:id="@+id/btn_delete_data"
android:inputType="number" android:layout_width="80dp"
android:layout_height="40dp"
android:layout_below="@id/edit_text_manufacturer"
android:layout_marginTop="5dp" android:layout_below="@id/edit_text_reaction"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp" android:layout_toEndOf="@id/btn_update_data"
/> android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
<EditText android:layout_marginEnd="20dp"
android:id="@+id/edit_text_disease" android:text="@string/delete"
android:layout_width="match_parent" />
android:layout_height="wrap_content"
android:hint="@string/disease"
android:inputType="text" </RelativeLayout>
android:layout_below="@id/edit_text_price"
android:layout_marginTop="5dp" </ScrollView>
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp" </androidx.constraintlayout.widget.ConstraintLayout>
/>

<EditText
android:id="@+id/edit_text_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/type"
android:inputType="text"

android:layout_below="@id/edit_text_disease"
android:layout_marginTop="5dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
/>

<TextView
android:id="@+id/edit_text_category"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/category"
android:textSize="25sp"
package com.example.abcpharmacy; }

import androidx.appcompat.app.AlertDialog; StringBuffer buffer = new StringBuffer();


import androidx.appcompat.app.AppCompatActivity; while (res.moveToNext()) {

import android.database.Cursor; buffer.append("ID :" +


import android.os.Bundle; res.getString(0)+"\n");
import android.view.View; buffer.append("Name :" +
import android.widget.Button; res.getString(1)+"\n");
import android.widget.EditText; buffer.append("Manufacturer :" +
import android.widget.Toast; res.getString(2)+"\n");
buffer.append("Price :" +
import com.example.abcpharmacy2.Database.DatabaseHelper; res.getString(3)+"\n");
buffer.append("Disease :" +
public class MainActivity extends AppCompatActivity { res.getString(4)+"\n");
buffer.append("Type :" +
DatabaseHelper db; res.getString(5)+"\n");
EditText buffer.append("Generation :" +
etid,etname,etmanufacturer,etprice,etdisease,ettype,etgener res.getString(6)+"\n");
ation,etreaction ; buffer.append("Reaction :" +
Button btnsave,btnview,btnupdate,btndelete; res.getString(7)+"\n\n");

}
@Override
protected void onCreate(Bundle savedInstanceState) { showMessage("Data",buffer.toString());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
db = new DatabaseHelper(this); });

etid = (EditText) findViewById(R.id.edit_text_id); public void showMessage (String title, String Message)
etname = (EditText) {
findViewById(R.id.edit_text_name);
etmanufacturer = (EditText) AlertDialog.Builder builder = new
findViewById(R.id.edit_text_manufacturer); AlertDialog.Builder(this);
etprice = (EditText) builder.setCancelable(true);
findViewById(R.id.edit_text_price); builder.setTitle(title);
etdisease = (EditText) builder.setMessage(Message);
findViewById(R.id.edit_text_disease); builder.show();
ettype = (EditText)
findViewById(R.id.edit_text_type); }
etgeneration = (EditText)
findViewById(R.id.edit_text_generation);
etreaction = (EditText)
findViewById(R.id.edit_text_reaction); public void updateData() {

btnsave = (Button) btnupdate.setOnClickListener(new


findViewById(R.id.btn_store_data); View.OnClickListener() {
btnview = (Button) @Override
findViewById(R.id.btn_view_data); public void onClick(View view) {
btnupdate = (Button) boolean isUpdated =
findViewById(R.id.btn_update_data); db.updateData(etid.getText().toString(),
btndelete = (Button) etname.getText().toString(),
findViewById(R.id.btn_delete_data); etprice.getText().toString(),

addData(); etmanufacturer.getText().toString(),
viewData(); etdisease.getText().toString(),
updateData(); etreaction.getText().toString(),
deleteData(); ettype.getText().toString(),
etgeneration.getText().toString());
}
if (isUpdated == true) {

public void addData() { Toast.makeText(MainActivity.this, "Data


Updated", Toast.LENGTH_SHORT).show();
btnsave.setOnClickListener(new }else
View.OnClickListener() { Toast.makeText(MainActivity.this, "Data
@Override not Updated", Toast.LENGTH_SHORT).show();
public void onClick(View view) {
}
boolean isInserted = });
db.insertData(etid.getText().toString(),
etname.getText().toString(), }

etmanufacturer.getText().toString(), public void deleteData() {


etprice.getText().toString(),
etdisease.getText().toString(), btndelete.setOnClickListener(new
ettype.getText().toString(), View.OnClickListener() {
etgeneration.getText().toString(), @Override
etreaction.getText().toString()); public void onClick(View view) {

if (isInserted == true) { Integer deleteRows =


Toast.makeText(MainActivity.this, "Data db.deleteData(etid.getText().toString());
Inserted", Toast.LENGTH_SHORT).show();
}else if (deleteRows > 0) {
Toast.makeText(MainActivity.this, "Data
not Inserted", Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "Data
Deleted", Toast.LENGTH_SHORT).show();
} }else
}); Toast.makeText(MainActivity.this, "Data
not Deleted", Toast.LENGTH_SHORT).show();
}
}
});
public void viewData() {
}
btnview.setOnClickListener(new
View.OnClickListener() {
@Override }
public void onClick(View view) {

Cursor res = db.getAllData();


if (res.getCount() == 0) {

showMessage("Error","No Data Found");


return;
package com.example.abcpharmacy2.Database;
}
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; }
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

public static final String Db_Name = "Medicine.db";


public static final String Table_Name =
"Medicine_Table";
public static final String Column_1 = "ID";
public static final String Column_2 = "Name";
public static final String Column_3 = "Manufacturer";
public static final String Column_4 = "Price";
public static final String Column_5 = "Disease";
public static final String Column_6 = "Type";
public static final String Column_7 = "Generation";
public static final String Column_8 = "Reaction";

public DatabaseHelper(Context context) {


super(context, Db_Name, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL("create table " + Table_Name + "(ID


INTEGER PRIMARY KEY, Name TEXT,Manufacturer TEXT, Price
INTEGER, Disease TEXT, Type TEXT, Generation TEXT, Reaction
TEXT)");

@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1)
{

db.execSQL("DROP TABLE IF EXISTS " + Table_Name);


onCreate(db);

public boolean insertData(String ID, String Name,


String Manufacturer, String Price, String Disease, String
Type, String Generation, String Reaction) {

SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(Column_1,ID);
contentValues.put(Column_2,Name);
contentValues.put(Column_3,Manufacturer);
contentValues.put(Column_4,Price);
contentValues.put(Column_5,Disease);
contentValues.put(Column_6,Type);
contentValues.put(Column_7,Generation);
contentValues.put(Column_8,Reaction);

long res = db.insert(Table_Name, null,


contentValues);

if (res == -1){

return false;

}else
return true;

public Cursor getAllData() {

SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from " +
Table_Name,null);
return res;

public boolean updateData(String ID, String Name,


String Manufacturer, String Price, String Disease, String
Type, String Generation, String Reaction) {

SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(Column_1,ID);
contentValues.put(Column_2,Name);
contentValues.put(Column_3,Manufacturer);
contentValues.put(Column_4,Price);
contentValues.put(Column_5,Disease);
contentValues.put(Column_6,Type);
contentValues.put(Column_7,Generation);
contentValues.put(Column_8,Reaction);
db.update(Table_Name,contentValues, "ID = ?",new
String[] { ID });
return true;

public Integer deleteData (String ID) {

SQLiteDatabase db = this.getWritableDatabase();
return db.delete(Table_Name,"ID = ?",new String[] {
ID });

You might also like