package com.topsun.posclient.sales.dialog;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.topsun.posclient.common.POSException;
import com.topsun.posclient.common.ui.style.CommonCss;
import com.topsun.posclient.datamodel.Member;
import com.topsun.posclient.sales.MessageResources;
import com.topsun.posclient.sales.core.service.IPartSaleService;
import com.topsun.posclient.sales.core.service.impl.PartSaleServiceImpl;
/**
* @author Dong
*
*/
public class PasswordDialog extends Dialog{
private String cardNo;
protected PasswordDialog(Shell parentShell) {
super(parentShell);
}
protected void configureShell(Shell newShell) {
newShell.setText("密码确认");
super.configureShell(newShell);
}
public String getCardNo() {
return cardNo;
}
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
public Text password;
public Text getPassword() {
return password;
}
public void setPassword(Text password) {
this.password = password;
}
protected Control createContents(Composite parent) {
parent.setLayout(new GridLayout(1, false));
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2,false));
{
Label lable = new Label(composite,SWT.NONE);
GridData data = new GridData();
lable.setLayoutData(data);
lable.setText("确认会员卡密码:");
}
{
password = new Text(composite,SWT.BORDER | SWT.PASSWORD);
GridData data = CommonCss.getDefaultTextData();
password.setFont(CommonCss.getDefaultFont(parent.getDisplay()));
password.setLayoutData(data);
}
return super.createContents(parent);
}
protected void createButtonsForButtonBar(Composite parent) {
int buttonWidth = 80;
int buttonHight = 45;
parent.setLayout(new GridLayout(5,false));
Button okbtn = createButton(parent, IDialogConstants.OK_ID, "确定",true);
okbtn.setFont(CommonCss.getDefaultFont(parent.getDisplay()));
GridData btnLayout = new GridData();
btnLayout.widthHint = buttonWidth;
btnLayout.heightHint = buttonHight;
okbtn.setLayoutData(btnLayout);
Button cancelBtn = createButton(parent, IDialogConstants.CANCEL_ID, "取消", false);
cancelBtn.setFont(CommonCss.getDefaultFont(parent.getDisplay()));
cancelBtn.setLayoutData(btnLayout);
}
protected void okPressed() {
String inputPassword = password.getText();
if(null == inputPassword || "".equals(inputPassword.trim())){
MessageDialog.openInformation(this.getShell(), MessageResources.message_ui_tips, "【密码】不能为空");
password.setFocus();
return;
}
IPartSaleService partSalesService = new PartSaleServiceImpl();
Member member = null;
try {
member = partSalesService.checkMember(getCardNo(), null, inputPassword, null);
} catch (POSException e) {
MessageDialog.openError(this.getShell(), MessageResources.message_ui_tips, e.getErrorMessage());
return;
}
if(null == member){
MessageDialog.openError(this.getShell(), MessageResources.message_ui_tips, "密码错误");
return;
}else{
// try {
// partSalesService.writeCard(member);
// } catch (POSException e) {
// MessageDialog.openError(this.getShell(), MessageResources.message_ui_tips, e.getErrorMessage());
// return;
// }
}
super.okPressed();
}
protected Button createButton(Composite parent, int id, String label,
boolean defaultButton) {
return super.createButton(parent, id, label, defaultButton);
}
}