-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateAdv.java
More file actions
104 lines (94 loc) · 4.33 KB
/
UpdateAdv.java
File metadata and controls
104 lines (94 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.example.android.break2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class UpdateAdv extends AppCompatActivity {
Spinner AllAdsSpinner ; // items to be selected for being deleted
Controller c=new Controller();
EditText Title ;
EditText CompanyName ;
EditText StartDate,EndDate;
EditText Content,Price,Url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_adv);
try {
FillAdvSpinner();
} catch (SQLException e) {
e.printStackTrace();
}
}
protected void FillAdvSpinner()throws SQLException
{
AllAdsSpinner=findViewById(R.id.UpdataAdvSpinner);
ArrayList<String> arrayList = new ArrayList <String>();
ResultSet res = c.SelectAllAdvs();
while (res.next())
{
arrayList.add(res.getString("ad_title"));
}
String[] array = arrayList.toArray(new String[0]);
ArrayAdapter<String> adapter = new ArrayAdapter <String>(this,android.R.layout.simple_spinner_item,array);
AllAdsSpinner.setAdapter(adapter);
}
public void GetAdvDataClick(View view)throws SQLException
{
Title =findViewById(R.id.AdvTitleUpdate);
CompanyName =findViewById(R.id.CompanyNameUpdate);
StartDate=findViewById(R.id.StartDateAdvUpdate);
EndDate=findViewById(R.id.EndDateAdvUpdate);
Content=findViewById(R.id.AdvContentUpdate);
Price=findViewById(R.id.AdvPriceUpdate);
Url=findViewById(R.id.AdvUrlUpdate);
String AdvName= (String) AllAdsSpinner.getSelectedItem();
ResultSet DirectorData= c.SelectAdvByName(AdvName);
if(DirectorData.next()) {
Title.setText(DirectorData.getString("ad_title"),TextView.BufferType.EDITABLE);
CompanyName.setText(DirectorData.getString("company_name"),TextView.BufferType.EDITABLE);
StartDate.setText(DirectorData.getString("ad_start_date"),TextView.BufferType.EDITABLE);
EndDate.setText(DirectorData.getString("ad_end_date"),TextView.BufferType.EDITABLE);
Content.setText(DirectorData.getString("ad_content"),TextView.BufferType.EDITABLE);
Price.setText(DirectorData.getString("price"),TextView.BufferType.EDITABLE);
Url.setText(DirectorData.getString("url"),TextView.BufferType.EDITABLE);
}
}
public void UpdateAdvClick(View view)throws SQLException
{
Title =findViewById(R.id.AdvTitleUpdate);
CompanyName =findViewById(R.id.CompanyNameUpdate);
StartDate=findViewById(R.id.StartDateAdvUpdate);
EndDate=findViewById(R.id.EndDateAdvUpdate);
Content=findViewById(R.id.AdvContentUpdate);
Price=findViewById(R.id.AdvPriceUpdate);
Url=findViewById(R.id.AdvUrlUpdate);
String AdvIdentify= (String) AllAdsSpinner.getSelectedItem();
String title= Title.getText().toString();
String companyname= CompanyName.getText().toString();
String startdate= StartDate.getText().toString();
String enddate= EndDate.getText().toString();
String content= Content.getText().toString();
String price= Price.getText().toString();
String url= Url.getText().toString();
if(title.isEmpty() || companyname.isEmpty() || startdate.isEmpty() || enddate.isEmpty() ||content.isEmpty() || price.isEmpty() || url.isEmpty() )
Toast.makeText(UpdateAdv.this,"Please fill all data ",Toast.LENGTH_SHORT).show();
else
{
int res = c.UpdateAdv(title,companyname,startdate,enddate,content,price,url,AdvIdentify);
if (res==1) {
Toast.makeText(UpdateAdv.this, "Updated Successfully ", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(UpdateAdv.this,"Something gone wrong ",Toast.LENGTH_SHORT).show();
}
FillAdvSpinner();
}
}