
package nc.ui.hzctr.sellctr.action;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pub.beans.UIButton;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pub.beans.UILabel;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.pub.beans.UITextArea;
/**
* 批量输入日期窗口
*
* @author Yaolz
*/
public class BatchInputDateDialog extends UIDialog implements ActionListener {
// 交房通知书生效等待期(天)标签
private UILabel day;
// 天数输入框
private UITextArea dayField;
// 竣备实际获取时间标签
private UILabel time;
// 时间参照
private UIRefPane sjref = null;
// 确定
private UIButton ok_btn;
// 取消
private UIButton cancel_btn;
private boolean isCancle;
private int bat = 0;
@Override
public int showModal() {
super.show();
int bat = this.bat;
return bat;
}
public BatchInputDateDialog() {
setLayout(new BorderLayout());
// 标题
setTitle("批量输入日期框");
this.setCancle(true);
initUI();
}
public void setCancle(boolean isCancle) {
this.isCancle = isCancle;
}
private void initUI() {
// 窗体长宽
setSize(350, 200);
getContentPane().setLayout(null);
// 交房标签
getContentPane().add(getJfDay());
// 交房文本框
getContentPane().add(getJfText());
// 竣备标签
getContentPane().add(getJfTime());
// 竣备参照
getContentPane().add(getRqsj());
// 确定按钮
getContentPane().add(getbuttonOk());
// 取消按钮
getContentPane().add(getbuttonCancel());
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenWidth = screenSize.width / 2;
int screenHeight = screenSize.height / 2;
int height = getHeight();
int width = getWidth();
setLocation(screenWidth - width / 2, screenHeight - height / 2);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().getClass().getName()
.equals("nc.ui.pub.beans.UIButton")) {
nc.ui.pub.beans.UIButton btn = (nc.ui.pub.beans.UIButton) e
.getSource();
if (this.ok_btn.getName().equals(btn.getName())) {
onOk();
} else if (this.cancel_btn.getName().equals(btn.getName())) {
onCancel();
}
}
}
private void onOk() {
if ((getJfText().getText() == null || getJfText().getText().length() <= 0)
&& (getRqsj().getText() == null || getRqsj().getText().length() <= 0)) {
MessageDialog.showErrorDlg(null, "提示", "必须填写天数与时间!");
return;
}
this.bat = 1;
this.setCancle(false);
closeOK();
}
private UIButton getbuttonOk() {
this.ok_btn = new UIButton("确认");
this.ok_btn.setName("btn_ok");
this.ok_btn.setLocation(90, 140);
this.ok_btn.addActionListener(this);
return this.ok_btn;
}
private UIButton getbuttonCancel() {
this.cancel_btn = new UIButton("取消");
this.cancel_btn.setName("btn_cance");
this.cancel_btn.setLocation(190, getbuttonOk().getY());
this.cancel_btn.addActionListener(this);
return this.cancel_btn;
}
private UILabel getJfDay() {
if (this.day == null) {
this.day = new UILabel("交房通知书生效等待期(天):");
this.day.setFont(getFont());
this.day.setBackground(getBackground());
this.day.setForeground(getForeground());
this.day.setSize(200, 35);
this.day.setLocation(30, 30);
}
return this.day;
}
private UITextArea getJfText() {
if (this.dayField == null) {
this.dayField = new UITextArea();
this.dayField.setSize(100, 25);
this.dayField.setLocation(205, 35);
}
return this.dayField;
}
private UILabel getJfTime() {
if (this.time == null) {
this.time = new UILabel("竣备实际获取时间:");
this.time.setFont(getFont());
this.time.setBackground(getBackground());
this.time.setForeground(getForeground());
this.time.setSize(200, 35);
this.time.setLocation(30, 75);
}
return this.time;
}
private UIRefPane getRqsj() {
if (this.sjref == null) {
this.sjref = new UIRefPane();
this.sjref.setSize(165, 25);
this.sjref.setRefNodeName("日期");
this.sjref.setLocation(140, 80);
}
return this.sjref;
}
public HashMap<String, String> getData() {
HashMap rtnMap = new HashMap<String, String>();
rtnMap.put("day", getJfText().getFieldText());
rtnMap.put("time", getRqsj().getRefShowName());
return rtnMap;
}
private void onCancel() {
this.setCancle(true);
this.bat = 0;
closeCancel();
}
}
package nc.ui.hzctr.sellctr.action;
import java.awt.event.ActionEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import nc.bs.framework.common.NCLocator;
import nc.itf.uif.pub.IUifService;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pubapp.uif2app.view.ShowUpableBillForm;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.model.AbstractAppModel;
import nc.uif2.annoations.MethodType;
import nc.uif2.annoations.ModelMethod;
import nc.uif2.annoations.ModelType;
import nc.vo.hzctr.sellctr.AggSellctrVO;
import nc.vo.pub.lang.UFDate;
/**
* 批量输入日期按钮
*
* @author Yaolz
*/
public class BatchInputDateAction extends NCAction {
private AbstractAppModel model;
private ShowUpableBillForm editor;
public BatchInputDateAction() {
this.setBtnName("批量输入日期");
this.setCode("batInputAction");
}
@Override
public void doAction(ActionEvent e) throws Exception {
// 获取界面选择行数
Integer[] num = ((nc.ui.uif2.model.BillManageModel) model)
.getSelectedOperaRows();
// 获取选择的每行数据
Object[] headRow = ((nc.ui.uif2.model.BillManageModel) model)
.getSelectedOperaDatas();
if (num == null || num.length < 1) {
MessageDialog.showHintDlg(null, "提示", "请选择要批量输入日期的数据");
return;
}
int a = 0;
for (Object object : headRow) {
AggSellctrVO head = (AggSellctrVO) object;
if (head.getParentVO().getDbillstatus() != -1) {
a++;
}
}
if (a > 0) {
MessageDialog
.showHintDlg(null, "更新失败", "当前选择的数据中存在非自由态单据,请重新选择!!!");
return;
}
BatchInputDateDialog bat = new BatchInputDateDialog();
if (bat.showModal() == 0) {
return;
}
HashMap<String, String> data = bat.getData();
// 获取输入天数
String day = data.get("day");
// 获取输入日期
String time = data.get("time");
Date date = StrToDate(time);
int idate = Integer.parseInt(day);
UFDate ddate = new UFDate(date);
int b = 0;
for (Object object : headRow) {
// 遍历取出表头数据
AggSellctrVO head = (AggSellctrVO) object;
// 不是自由态的跳过单次循环
if (head.getParentVO().getDbillstatus() != -1) {
continue;
}
// 交房通知日期 delivernoticedate
UFDate delivernoticedate = (head.getParentVO()
.getDelivernoticedate()) != null ? head.getParentVO()
.getDelivernoticedate() : new UFDate("1900-01-01");
// 交房通知书生效天 effectwait_date
int effectwait_date = (head.getParentVO().getEffectwait_date()) != null ? head
.getParentVO().getEffectwait_date() : 0;
// 输入交房通知日期与交房通知书生效天,得到新日期
Date newDate = addDate(delivernoticedate.toDate(), effectwait_date);
// 转换成UFDate类型
UFDate newDates = new UFDate(newDate);
// 设置实际峻备完成时间
head.getParentVO().setCompleteddate(ddate);
// 实际峻备完成时间
UFDate completeddate = head.getParentVO().getCompleteddate();
// 新日期与实际峻备完成时间做比较,如果新日期大于实际峻备完成时间。则 设置实际峻备完成时间 为 新日期
if (newDates.compareTo(completeddate) > 0 && newDates.getDay() > 0){
head.getParentVO().setConfirmdate(newDates.toString().substring(0,7));
}else{
head.getParentVO().setConfirmdate(completeddate.toString().substring(0,7));
}
// 设置交房通知书生效等待期(天)
head.getParentVO().setEffectwait_date(idate);
// 设置Dr属性为0
head.getParentVO().setAttributeValue("dr", new Integer(0));
getUpdate().update(head.getParentVO());
b++;
}
MessageDialog.showHintDlg(null, "更新成功", "已成功更新" + b + "条记录,请刷新当前界面!!!");
}
/**
* 输入日期与天数,得到新日期
*/
public static Date addDate(Date date, long day) throws ParseException {
long time = date.getTime(); // 得到指定日期的毫秒数
day = day * 24 * 60 * 60 * 1000; // 要加上的天数转换成毫秒数
time += day; // 相加得到新的毫秒数
return new Date(time); // 将毫秒数转换成日期
}
private IUifService getUpdate() {
IUifService service = (IUifService) NCLocator.getInstance().lookup(
IUifService.class.getName());
return service;
}
/**
* 字符串转换成日期
*
* @param str
* @return date
*/
public static Date StrToDate(String str) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = (Date) format.parseObject(str);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
public ShowUpableBillForm getEditor() {
return editor;
}
public void setEditor(ShowUpableBillForm editor) {
this.editor = editor;
}
@ModelMethod(modelType = ModelType.AbstractAppModel, methodType = MethodType.GETTER)
public AbstractAppModel getModel() {
return this.model;
}
@ModelMethod(modelType = ModelType.AbstractAppModel, methodType = MethodType.SETTER)
public void setModel(AbstractAppModel model) {
this.model = model;
model.addAppEventListener(this);
}
}