基本信息
源码名称:android 加班统计与记录 应用源码下载
源码大小:2.39M
文件格式:.rar
开发语言:Java
更新时间:2015-06-19
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
可以记录每天的加班时间,和统计出加班费。
可以记录每天的加班时间,和统计出加班费。
package com.example.sqlite;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import javax.security.auth.PrivateCredentialPermission;
import cn.example.domain.Person;
import com.example.service.DBOpenHelper;
import com.example.service.PersonService;
import android.R.bool;
import android.R.integer;
import android.os.Bundle;
import android.animation.ArgbEvaluator;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.gesture.Prediction;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private DBOpenHelper dbOpenHelper;
private Person person;
private EditText date_edt, week_edt, content_edt, work_hour, month_edt;
private ListView show_list;
private float hour_workhour = 11.666f;
private int year, monthhow, day, weekhow, hour, minute;
private PersonService personservice;
private TextView show_text1_5,show_text2_0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//对象实例化
personservice=new PersonService(this);
dbOpenHelper = new DBOpenHelper(MainActivity.this);
dbOpenHelper.getWritableDatabase();
//获取控件的ID
date_edt = (EditText) findViewById(R.id.date_edt_id);
show_list = (ListView) findViewById(R.id.listview);
week_edt = (EditText) findViewById(R.id.week_edt_id);
content_edt = (EditText) findViewById(R.id.content_edt_id);
work_hour = (EditText) findViewById(R.id.work_hour_edt_id);
month_edt = (EditText) findViewById(R.id.month_edt_id);
show_text1_5=(TextView)findViewById(R.id.show_text1_5);
show_text2_0=(TextView)findViewById(R.id.show_text2_0);
// 获取当前时间
Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
monthhow = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
weekhow = c.get(Calendar.DAY_OF_WEEK);
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
}
// 下面是获取时间按钮事件
public void now_time(View v) {
String now_week = null;
//把日期与月份给对应的控件
date_edt.setText(String.valueOf(year) "-" String.valueOf(monthhow 1)
"-" String.valueOf(day));
month_edt.setText(String.valueOf(monthhow 1));
// 因为每个星期的第一天是从星期天开始的,所以要转换
switch (weekhow) { case 1: now_week="日";
break; case 2: now_week="一";
break; case 3: now_week="二";
break; case 4: now_week="三";
break; case 5: now_week="四";
break; case 6: now_week="五";
break; case 7: now_week="六";
break;
default: break; }
//把星期给对应的控件
week_edt.setText(now_week);
//下面是加班费倍数
if(weekhow==2||weekhow==3||weekhow==4||weekhow==5||weekhow==6) {
content_edt.setText("1.5"); } else { content_edt.setText("2"); }
Toast.makeText(getApplicationContext(), "今天日期已经填入", 1).show();
}
/**
* 添加记录并保存进数据库
*
* @param person
*/
public void add(View v) {
int n, workhour = 0;
boolean enabled = true, a = true, b = true, c = true, d = true, e = true;//标志位
// 获取输入框中的数据
String week = week_edt.getText().toString();
String date = date_edt.getText().toString();
String content = content_edt.getText().toString();
String month = month_edt.getText().toString();
// 先来个判断输入框不能为空
if (week.equals("")) {
a = false;
Toast.makeText(getApplicationContext(), "星期不能为空", 1).show();
}
if (date.equals("")) {
b = false;
Toast.makeText(getApplicationContext(), "日期不能为空", 1).show();
}
if (content.equals("1.5")||content.equals("2")) {
c =true;
}else {
c=false;
Toast.makeText(getApplicationContext(), "倍数只能为1.5或2", 1).show();
}
if ((work_hour.getText().toString()).equals("")) {
d = false;
Toast.makeText(getApplicationContext(), "加班时间不能为空", 1).show();
} else {
// 为什么要把下面这条件语句放这里,因为如果输入框为空后Integer.valueof()转换,系统就会出错,软件就会自动关闭,所以为空时不让转换。
workhour = Integer.valueOf(work_hour.getText().toString());
}
if (month.equals("")) {
e = false;
Toast.makeText(getApplicationContext(), "月份不能为空", 5).show();
}
if (a && b && c && d && e) {
// 先来个判断看数据表中已经存在该日期的了,有就不能写入了,只能更改
String now_date = date_edt.getText().toString();
SQLiteDatabase db1 = dbOpenHelper.getReadableDatabase();
// 下面是查找方法,第一个参数为表名,第二个参数为null表示所有的字段,第三个参数为条件,第四个为点位符参数,
Cursor cursor = db1.rawQuery("select * from person where date=?",
new String[] { now_date.toString() });
for (n = 0; n < cursor.getCount(); n )// 这里的getCount()获取的总记录数量,是指跟上面条件相等值的数量
{
if (cursor.moveToNext())// 用for来输出所有相等条件的值
{
String date1 = cursor.getString(cursor
.getColumnIndex("date"));
// 下判断从数据表中能否获取到输入框中的数据,如果有,就不能再次存入了。
if (date1.equals(now_date)) {
enabled = false;
}
}
}
if (enabled) {
// 引用Person类中的构造方法
person = new Person(date, week, content, workhour, month);
// 创建数据帮手对象再引用它的方法
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();// 这个是用来存放每个字段的值,第个字段是有相应的值的。
values.put("date", person.getdate());// 括号中,第一个参数为字段名称,
values.put("week", person.getweek());
values.put("content", person.getcontent());
values.put("workhour", person.getworkhour());
values.put("month", person.getMonth());
db.insert("person", null, values);// 括号中的第一个参数为表名,第二个参数为空值字段,也就是说如果那个字段的值为空,那就要用到第二个参数,
// 例如当amount字段的字为空时,就得这样写db.insert("person","amount",null);,第三个参数就字段相应的值。
if (weekhow == 1 || weekhow == 7) {
Toast.makeText(getApplicationContext(),"恭喜你今天赚了" workhour * hour_workhour * 2 "元", 1).show();
} else {
Toast.makeText(getApplicationContext(),"恭喜你今天赚了" workhour * hour_workhour * 1.5 "元", 1).show();
}
} else {
Toast.makeText(getApplicationContext(), "已经记录过了,不能再记录,只能更改", 1)
.show();
}
}
work_hour.setText("");
}
public void date_find(View v) {
int i;
int a, b = 0, c = 0, aa, bb = 0, cc = 0;
String time1_5 = "0", time2_0 = "0";
String month = month_edt.getText().toString();
if(!month.equals(""))
{
String content1_5 = "1.5";
String content2_0 = "2";
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
// 下面是查找方法,第一个参数为表名,第二个参数为null表示所有的字段,第三个参数为条件,第四个为点位符参数,
Cursor cursor = db.rawQuery(
"select * from person where month=? and content=?",
new String[] { month.toString(), content1_5.toString() });
for (i = 0; i < cursor.getCount(); i )// 这里的getCount()获取的总记录数量,是指跟上面条件相等值的数量
{
if (cursor.moveToNext())// 用for来输出所有相等条件的值
{
int content = cursor.getInt(cursor.getColumnIndex("content"));
int workhour = cursor.getInt(cursor.getColumnIndex("workhour"));
String week = cursor.getString(cursor.getColumnIndex("week"));
String date = cursor.getString(cursor.getColumnIndex("date"));
String month1 = cursor.getString(cursor.getColumnIndex("month"));
b = workhour;
}
a = c b;
c = a;
time1_5 = String.valueOf(c);
}
cursor.close();
show_text1_5.setText(month "月份,平常1.5倍的" time1_5 "小时" ",计:" c
* 1.5 * hour_workhour "元" "\n"
);
//
// 下面是查找方法,第一个参数为表名,第二个参数为null表示所有的字段,第三个参数为条件,第四个为点位符参数,
Cursor cursor2 = db.rawQuery(
"select * from person where month=? and content=?",
new String[] { month.toString(), content2_0.toString() });
for (i = 0; i < cursor2.getCount(); i )// 这里的getCount()获取的总记录数量,是指跟上面条件相等值的数量
{
if (cursor2.moveToNext())// 用for来输出所有相等条件的值
{
int content = cursor2.getInt(cursor2.getColumnIndex("content"));
int workhour = cursor2.getInt(cursor2
.getColumnIndex("workhour"));
String week = cursor2.getString(cursor2.getColumnIndex("week"));
String date = cursor2.getString(cursor2.getColumnIndex("date"));
bb = workhour;
}
aa = cc bb;
cc = aa;
time2_0 = String.valueOf(cc);
}
cursor.close();//关闭curson对象
//算出当天记录的时间与金额
show_text2_0.setText(month "月份,周末2倍的" time2_0 "小时" ",计:" cc * 2
* hour_workhour "元" );
}else {
Toast.makeText(getApplicationContext(), "统计时月份不能为空", 1).show();
}
}
// 下面为更改按钮事件
/**
* 更新记录
*
* @param person
*/
public void update(View v) {
boolean a = true, b = true, c = true, d = true, e = true;
int workhour = 0;
// 获取输入框中的数据
String week = week_edt.getText().toString();
String date = date_edt.getText().toString();
String content = content_edt.getText().toString();
String month = month_edt.getText().toString();
// 先来个判断输入框是否为空,不空就不能修改成功
if (week.equals("")) {
a = false;
Toast.makeText(getApplicationContext(), "星期不能为空", 1).show();
}
if (date.equals("")) {
b = false;
Toast.makeText(getApplicationContext(), "日期不能为空", 2).show();
}
if (content.equals("1.5")||content.equals("2")) {
c =true;
}else {
c=false;
Toast.makeText(getApplicationContext(), "倍数只能为1.5或2", 3).show();
}
if ((work_hour.getText().toString()).equals("")) {
d = false;
Toast.makeText(getApplicationContext(), "加班时间不能为空", 4).show();
} else {
// 为什么要把下面这条件语句放这里,因为如果输入框为空后Integer.valueof()转换,系统就会出错,软件就会自动关闭,所以为空时不让转换。
workhour = Integer.valueOf(work_hour.getText().toString());
}
if (month.equals("")) {
e = false;
Toast.makeText(getApplicationContext(), "月份不能为空", 5).show();
}
if (a && b && c && d && e) {
// 引用Person类中的构造方法
person = new Person(date, week, content, workhour, month);
SQLiteDatabase db = dbOpenHelper.getWritableDatabase();
db.execSQL(
"update person set month=?,week=?,content=?,workhour=? where date=?",
new Object[] { person.getMonth(), person.getweek(),
person.getcontent(), person.getworkhour(),
person.getdate() });
Toast.makeText(getApplicationContext(), "修改成功", 1).show();
}
work_hour.setText("");
}
//下面为显示出所有的记录
public void note_content(View v){
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
//下面是查找方法,第一个参数为表名,第二个参数为null表示所有的字段,第三个参数为条件,第四个为点位符参数,
Cursor cursor = db.query("person", null, null, null, null, null, null);
int maxlegth=cursor.getCount();//取得数据,总条数
List<Person> persons=personservice.getScrollData(0, maxlegth);
List<HashMap<String, Object>> data=new ArrayList<HashMap<String,Object>>();
for(Person person:persons)
{
HashMap<String, Object> item=new HashMap<String, Object>();
item.put("date", person.getdate());
item.put("week", person.getweek());
item.put("content", person.getcontent());
item.put("workhour", person.getworkhour());
item.put("month", person.getMonth());
data.add(item);
}
//下面第一个为上下文,第二个为数据集,第三个参数为listvist用的xml文件,后面的就是item对应键,所对应的TextView的ID
SimpleAdapter adapter=new SimpleAdapter(this, data, R.layout.data_item, new String[]{"date","week","content","workhour","month"}, new int[]{R.id.date_item,R.id.week_item,R.id.content_item,R.id.work_hour_item,R.id.month_item});
show_list.setAdapter(adapter);//显示出listview
}
}